import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class Annulus extends View {
private Context context;
private Paint paint;
public Annulus(Context context) {
this(context, null);
}
public Annulus(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
this.paint = new Paint();
this.paint.setAntiAlias(true);
this.paint.setStyle(Paint.Style.STROKE);
}
@Override
public void onDraw(Canvas canvas) {
int center = getWidth() / 2;
int cennCricle = dip2px(context, Float.valueOf(MainActivity.mRadius));// 设置内圆半径
int cricleWith = dip2px(context, Float.valueOf(MainActivity.mWidth));// 设置圆环宽度
// 绘制内圆
this.paint.setARGB(155, 167, 190, 206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center, center, cennCricle, this.paint);
// 绘制圆环
this.paint.setARGB(255, 212, 225, 233);
this.paint.setStrokeWidth(cricleWith);
this.paint.setColor(Color.parseColor(MainActivity.hcolor));
canvas.drawCircle(center, center, cennCricle + cricleWith / 2,
this.paint);
// 绘制外圆
this.paint.setARGB(155, 167, 190, 206);
this.paint.setStrokeWidth(2);
canvas.drawCircle(center, center, cennCricle + cricleWith, this.paint);
super.onDraw(canvas);
}
private static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
}
***************************************************************************************************************************************************
package com.bwie.test;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.util.Xml;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends Activity {
private Annulus an;
public static String mRadius = "100";
public static String mWidth = "10";
public static String hcolor = "#ff0000";
private ListView listView;
private URL uu;
List<StudentBean>al=new ArrayList<StudentBean>();
private HttpURLConnection hc;
private StudentBean rr;
private Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
listView.setAdapter(new Myadapter());
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获得控件
Initview();
// 获得数据
Initdata();
}
/**
* 数据
*/
private void Initdata() {
new Thread() {
public void run() {
getStr();
};
}.start();
}
//适配器
class Myadapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return 20;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView==null) {
convertView=View.inflate(getApplicationContext(), R.layout.item, null);
}
TextView t1=(TextView)findViewById(R.id.textView1);
TextView t2=(TextView)findViewById(R.id.textView2);
TextView t3=(TextView)findViewById(R.id.textView3);
int i=1;
i++;
t1.setText("zx"+i);
t2.setText("hd");
t3.setText("bw");
return convertView;
}
}
// httputlconnection请求
protected void getStr() {
try {
uu = new URL(
"http://172.17.29.120/localuser/loupengfei/kaoshi/student.xml");
hc = (HttpURLConnection) uu.openConnection();
hc.setRequestMethod("GET");
hc.setConnectTimeout(5000);
int code = hc.getResponseCode();
if (code == 200) {
// xml解析
Xmlparse();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 解析
private void Xmlparse() throws Exception {
InputStream inputStream = hc.getInputStream();
XmlPullParser xp = Xml.newPullParser();
xp.setInput(inputStream, "utf-8");
int eventType = xp.getEventType();
String stagname = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_DOCUMENT:
break;
case XmlPullParser.START_TAG:
stagname = xp.getName();
if ("student".equals(stagname)) {
rr = new StudentBean();
}
break;
case XmlPullParser.TEXT:
if ("name".equals(stagname)) {
rr.name = xp.getText().trim();
} else if ("address".equals(stagname)) {
rr.address = xp.getText().trim();
} else if ("school".equals(stagname)) {
rr.school = xp.getText().trim();
}
break;
case XmlPullParser.END_TAG:
stagname = xp.getName();
if ("student".equals(stagname)) {
al.add(rr);
Message msg = Message.obtain();
msg.obj = al;
handler.sendMessage(msg);
rr = null;
}
stagname = "";
break;
case XmlPullParser.END_DOCUMENT:
break;
}
eventType = xp.next();
}
}
private void Initview() {
an = (Annulus) findViewById(R.id.ann);
listView = (ListView) findViewById(R.id.listview);
}
}