DevStore首页 > DEV资源 > 源码下载 > 源码详情

Android例子源码--炫酷的仪表盘网速测试

 
xworker | 2014-08-23 17:55    浏览量(15238)    评论(15)    收藏(10)
功能分类:工具 支持平台:Android 运行环境:Android
开发语言:Java 开发工具:Eclipse 源码大小:2.31MB
下载源码 1835 人下载

源码简介

本项目是一个仪表盘网速测试的安卓版本,原理就是下载一个固定大小的文件来进行测试,可以测试当前速度,和平均速度,跟电脑上的测速差不多,有一个很精美的仪表盘效果。本项目编码UTF-8默认编译版本4.2.2。

源码截图

  • 仪表盘网速测试运行截图1
  • 仪表盘网速测试运行截图2
  • 仪表盘网速测试运行截图3
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

public class MainActivity extends Activity {
	private String url = "http://www.51eoc.com:8080/itravel/36.7-1.7.8.apk";

	byte[] imageData = null;
	Button b;
	NetWorkSpeedInfo netWorkSpeedInfo = null;
	private final int UPDATE_SPEED = 1;// 进行中
	private final int UPDATE_DNOE = 0;// 完成下载
	private ImageView imageView;
	private long begin = 0;
	private Button startButton;
	private TextView connectionType, nowSpeed, avageSpeed;
	long tem = 0;
	long falg = 0;
	long numberTotal = 0;
	List list = new ArrayList();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.equipment);
		imageView = (ImageView) findViewById(R.id.iv_needle);
		startButton = (Button) findViewById(R.id.start_button);
		connectionType = (TextView) findViewById(R.id.connection_type);
		nowSpeed = (TextView) findViewById(R.id.now_speed);
		avageSpeed = (TextView) findViewById(R.id.average_speed);
		// timer.schedule(task, 1000, 1000);
		netWorkSpeedInfo = new NetWorkSpeedInfo();
		
		startButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				
				list.clear();
				tem = 0;
				falg = 0;
				numberTotal = 0;
				
				new Thread() {
					@Override
					public void run() {
						Log.i("开始", "**********开始  ReadFile*******");
						imageData = ReadFile.getFileFromUrl(url, netWorkSpeedInfo);
					}
				}.start();

				new Thread() {
					@Override
					public void run() {
						Log.i("开始", "**********开始  netWorkSpeedInfo1*******");
						while (netWorkSpeedInfo.hadFinishedBytes < netWorkSpeedInfo.totalBytes) {
							try {
								sleep(1000);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
							handler.sendEmptyMessage(UPDATE_SPEED);
						}
						if (netWorkSpeedInfo.hadFinishedBytes == netWorkSpeedInfo.totalBytes) {
							handler.sendEmptyMessage(UPDATE_SPEED);
							netWorkSpeedInfo.hadFinishedBytes = 0;
						}

					}
				}.start();
			}
		});
	}

	protected void startAnimation(double d) {
		AnimationSet animationSet = new AnimationSet(true);
		/**
		 * 前两个参数定义旋转的起始和结束的度数,后两个参数定义圆心的位置
		 */
		// Random random = new Random();
		int end = getDuShu(d);

		Log.i("", "********************begin:" + begin + "***end:" + end);
		RotateAnimation rotateAnimation = new RotateAnimation(begin, end, Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f);
		rotateAnimation.setDuration(1000);
		animationSet.addAnimation(rotateAnimation);
		imageView.startAnimation(animationSet);
		begin = end;
	}

	public int getDuShu(double number) {
		double a = 0;
		if (number >= 0 && number <= 512) {
			a = number / 128 * 15;
		} else if (number > 521 && number <= 1024) {
			a = number / 256 * 15 + 30;
		} else if (number > 1024 && number <= 10 * 1024) {
			a = number / 512 * 5 + 80;
		} else {
			a = 180;
		}
		return (int) a;
	}

	private Handler handler = new Handler() {
		long tem = 0;
		long falg = 0;
		long numberTotal = 0;
		List list = new ArrayList();

		@Override
		public void handleMessage(Message msg) {
			int value = msg.what;
			switch (value) {
			case UPDATE_SPEED:
				tem = netWorkSpeedInfo.speed / 1024;
				list.add(tem);
				Log.i("a", "tem****" + tem);
				for (Long numberLong : list) {
					numberTotal += numberLong;
				}
				falg = numberTotal / list.size();
				numberTotal = 0;
				nowSpeed.setText(tem + "kb/s");
				avageSpeed.setText(falg + "kb/s");
				startAnimation(Double.parseDouble(tem+""));
				break;
			default:
				break;
			}
		}
	};

}
  •   赞(2) 赞 +1 赞(2) 已赞
  •   收藏(10) 收藏 +1 已收藏 取消
  •   下载(1835)
评论(15)
liaoyong

liaoyong 2016-03-24 17:09:12

我去,居然是背景图。。。。
回复(0) 赞(0) 赞(1)
luyang7415445

luyang7415445 2015-06-18 10:28:30

是放的图片吗,还是自定义的
回复(0) 赞(0) 赞(1)
luyang7415445

luyang7415445 2015-06-17 16:05:42

这个看着很炫
回复(0) 赞(0) 赞(1)
阿泰2015

阿泰2015 2015-03-30 13:41:09

效果不错的源码,下载!
回复(0) 赞(0) 赞(1)
Terry

Terry 2015-03-26 14:47:01

我去 我以为是自定义View ,谁知道是放的图片。。
回复(0) 赞(0) 赞(1)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 8 能力值
  • 4 源码
  • 0 评测
  • 0 资料

热门源码