public
class
MainActivity
extends
Activity
implements
TaskStateListener,RunnableStateListener {
private
TextView mProgressShow;
private
ProgressBar mProgressBar;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgressShow = (TextView)findViewById(R.id.TextShow);
mProgressBar = (ProgressBar)findViewById(R.id.ProgressBar);
}
public
void
onClickDownLoad(View v) {
new
Thread(
new
DownloadRunnable(
this
,
"blog.ticktick.51cto.com"
)).start();
}
@Override
public
void
onTaskUpdate(
int
progress) {
mProgressShow.setText(progress+
"%"
);
mProgressBar.setProgress(progress);
}
@Override
public
void
onTaskComplete(
boolean
isSuccess) {
if
( isSuccess ) {
Toast.makeText(
this
,
"Download Complete"
,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(
this
,
"Download Failed"
,Toast.LENGTH_LONG).show();
}
}
@Override
public
void
onRunnableUpdate(
final
int
progress) {
this
.runOnUiThread(
new
Runnable() {
@Override
public
void
run() {
mProgressShow.setText(progress+
"%"
);
mProgressBar.setProgress(progress);
}
});
}
@Override
public
void
onRunnableComplete(
final
boolean
isSuccess) {
this
.runOnUiThread(
new
Runnable() {
@Override
public
void
run() {
if
( isSuccess ) {
Toast.makeText(MainActivity.
this
,
"Download Complete"
,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(MainActivity.
this
,
"Download Failed"
,Toast.LENGTH_LONG).show();
}
}
});
}
}