hi 问几个问题
1. 如果在ProgressBar上显示数字,是否原生支持
2.
我有个下载的业务 在一个Activity中点下载的同时可以在另外一个Activity中显示现在进度:
我直接诶在Activity中new Thread来作的,这样好不好的,一般时用什么方法作? 这样性能是否过得去
看我红色标题部分,我是通过Thread while true,
- 我在已下载完毕的文件图标上放个勾勾,这个是图片合成作的,还是用android提供的工具做的?
[code="java"]
/**
- */ package com.alibaba.cloudspace;
import java.util.ArrayList;
import java.util.List;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
public class TransStatusActivity extends TabActivity implements OnTabChangeListener {
private GestureDetector gestureDetector;
private UpdateProgressBarHandler progressBarHandler;
private UpdateDownloadFilesHandler downloadFilesHandler;
private ProgressBarListAdapter adapter = null;
private DownloadCompleteListAdapter downloadCompleteAdapter = null;
private ListView listView = null;
private ListView listView2 = null;
private TabHost transTabhost;
private final String[] TAB_IDS = new String[] { "TRANS_TAB1",
"TRANS_TAB2" };
private static FileMap DOWNLOAD_FILES = new FileMap();
private String email = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO Get email.
// email = getIntent().getExtras().getString("");
gestureDetector = new GestureDetector(this, new CLGestureDetector(this));
transTabhost = this.getTabHost();
LayoutInflater.from(this).inflate(R.layout.trans_status, transTabhost.getTabContentView(),
true);
transTabhost.addTab(transTabhost.newTabSpec(TAB_IDS[0]).setIndicator(
createTabTextView(R.string.app_text_transfer)).setContent(R.id.transfer_tab));
transTabhost.addTab(transTabhost.newTabSpec(TAB_IDS[1]).setIndicator(
createTabTextView(R.string.app_text_transfer_finish)).setContent(
R.id.transfer_finish_tab));
// TODO 载入未完成的下载列表
progressBarHandler = new UpdateProgressBarHandler();
downloadFilesHandler = new UpdateDownloadFilesHandler();
adapter = new ProgressBarListAdapter(this, getTransStatusList());
listView = (ListView) findViewById(R.id.trans_status_list);
listView.setAdapter(adapter);
[color=red][b] new UpdateProgressBarThread().start();
new UpdateDownloadFileListThread().start();[/b][/color]
downloadCompleteAdapter = new DownloadCompleteListAdapter(this, DOWNLOAD_FILES.get(email));
listView2 = (ListView) findViewById(R.id.download_complete_list);
listView2.setAdapter(downloadCompleteAdapter);
transTabhost.setOnTabChangedListener(this);
}
。。。。
private List getTransStatusList() {
List transStatus = new ArrayList();
for (int i = 0; i < FileListActivity.downloading.size(); i++) {
FileDownloaderTask t = FileListActivity.downloading.get(i);
if (t.isCompleted()) {
DOWNLOAD_FILES.add(email, t.getFile());
downloadFilesHandler.sendMessage(new Message());
FileListActivity.downloading.remove(i--);
continue;
}
TransStatus s = new TransStatus();
s.setFid(t.getFile().getNodeId());
s.setTitle(t.getFile().getFileName());
s.setPercent(t.getPercent());
Log.d("DEBUG-TRANS-STATUS", "Percent:" + s.getPercent() + ", has read:"
+ t.getHasReadSize() + ", full size:" + t.getFile().getFullSize());
transStatus.add(s);
}
return transStatus;
}
class UpdateProgressBarThread extends Thread {
public void run() {
while (true) {
Message msg = new Message();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
progressBarHandler.sendMessage(msg);
int i = 0;
for (FileDownloaderTask f : FileListActivity.downloading) {
if (f.isCompleted())
i++;
}
Log.e("", "Completed:" + i + ", downloading size:"
+ FileListActivity.downloading.size());
if (i >= FileListActivity.downloading.size())
break;
}
};
}
class UpdateDownloadFileListThread extends Thread {
public void run() {
Message msg = new Message();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
downloadFilesHandler.sendMessage(msg);
};
}
class UpdateProgressBarHandler extends Handler {
@Override
public void handleMessage(Message msg) {
adapter = new ProgressBarListAdapter(TransStatusActivity.this, getTransStatusList());
listView = (ListView) findViewById(R.id.trans_status_list);
listView.setAdapter(adapter);
}
}
class UpdateDownloadFilesHandler extends Handler {
@Override
public void handleMessage(Message msg) {
downloadCompleteAdapter = new DownloadCompleteListAdapter(TransStatusActivity.this,
DOWNLOAD_FILES.get(email));
listView2 = (ListView) findViewById(R.id.download_complete_list);
listView2.setAdapter(downloadCompleteAdapter);
}
}
@Override
public void onTabChanged(String tabId) {
}
private TextView createTabTextView(int rid) {
TextView txtTabInfo = new TextView(this);
txtTabInfo.setText(getResources().getString(rid));
txtTabInfo.setPadding(0, 5, 0, 0);
txtTabInfo.setTextSize(11);
txtTabInfo.setBackgroundResource(R.drawable.tab_normal);
txtTabInfo.setTextColor(Color.DKGRAY);
txtTabInfo.setGravity(Gravity.CENTER);
txtTabInfo.setHeight(39);
return txtTabInfo;
}
}
[/code]