From c8707f772d3414a71b4b458d688c87841cdf2a30 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 6 Dec 2016 20:49:01 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix=20,=E4=BF=AE=E5=A4=8D=E5=A4=9A?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=99=A8=E5=AF=BC=E8=87=B4=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simple/activity/SingleTaskActivity.java | 52 +++++++++------- app/src/main/res/layout/content_single.xml | 22 +++++-- .../arialyy/downloadutil/core/AMReceiver.java | 6 +- .../arialyy/downloadutil/core/AMTarget.java | 15 +++-- .../downloadutil/core/command/AddCmd.java | 7 ++- .../downloadutil/core/command/CancelCmd.java | 6 +- .../downloadutil/core/command/CmdFactory.java | 62 ++++++++++++++++++- .../core/command/IDownloadCmd.java | 10 ++- .../downloadutil/core/command/SingleCmd.java | 6 +- .../downloadutil/core/command/StartCmd.java | 7 ++- .../downloadutil/core/command/StopCmd.java | 6 +- .../core/queue/DownloadTaskQueue.java | 13 ++-- .../downloadutil/core/queue/ITaskQueue.java | 3 +- .../core/scheduler/DownloadSchedulers.java | 54 +++++++++------- .../core/scheduler/IDownloadSchedulers.java | 9 ++- .../arialyy/downloadutil/core/task/Task.java | 46 +++++++++----- .../downloadutil/core/task/TaskFactory.java | 8 ++- .../arialyy/downloadutil/util/CommonUtil.java | 8 ++- 18 files changed, 241 insertions(+), 99 deletions(-) diff --git a/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java index c8e52ede..a015f092 100644 --- a/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/activity/SingleTaskActivity.java @@ -37,32 +37,42 @@ import com.arialyy.downloadutil.util.CommonUtil; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivitySingleBinding; +import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; public class SingleTaskActivity extends BaseActivity { - public static final int DOWNLOAD_PRE = 0x01; - public static final int DOWNLOAD_STOP = 0x02; - public static final int DOWNLOAD_FAILE = 0x03; - public static final int DOWNLOAD_CANCEL = 0x04; - public static final int DOWNLOAD_RESUME = 0x05; - public static final int DOWNLOAD_COMPLETE = 0x06; - public static final int DOWNLOAD_RUNNING = 0x07; - private static final String DOWNLOAD_URL = + public static final int DOWNLOAD_PRE = 0x01; + public static final int DOWNLOAD_STOP = 0x02; + public static final int DOWNLOAD_FAILE = 0x03; + public static final int DOWNLOAD_CANCEL = 0x04; + public static final int DOWNLOAD_RESUME = 0x05; + public static final int DOWNLOAD_COMPLETE = 0x06; + public static final int DOWNLOAD_RUNNING = 0x07; + private static final String DOWNLOAD_URL = "http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk"; - @Bind(R.id.progressBar) ProgressBar mPb; - @Bind(R.id.start) Button mStart; - @Bind(R.id.stop) Button mStop; - @Bind(R.id.cancel) Button mCancel; - @Bind(R.id.size) TextView mSize; - @Bind(R.id.toolbar) Toolbar toolbar; - private DownloadEntity mEntity; - private BroadcastReceiver mReceiver; + @Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb; + @Bind(R.id.start) Button mStart; + @Bind(R.id.stop) Button mStop; + @Bind(R.id.cancel) Button mCancel; + @Bind(R.id.size) TextView mSize; + @Bind(R.id.toolbar) Toolbar toolbar; + @Bind(R.id.speed) TextView mSpeed; + private DownloadEntity mEntity; + private BroadcastReceiver mReceiver; private Handler mUpdateHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case DOWNLOAD_RUNNING: - mPb.setProgress((Integer) msg.obj); + Task task = (Task) msg.obj; + long current = task.getDownloadEntity().getCurrentProgress(); + long len = task.getDownloadEntity().getFileSize(); + if (len == 0) { + mPb.setProgress(0); + } else { + mPb.setProgress((int) ((current * 100) / len)); + } + mSpeed.setText(CommonUtil.formatFileSize(task.getDownloadEntity().getSpeed()) + "/s"); break; case DOWNLOAD_PRE: mSize.setText(CommonUtil.formatFileSize((Long) msg.obj)); @@ -218,13 +228,7 @@ public class SingleTaskActivity extends BaseActivity { } @Override public void onTaskRunning(Task task) { - long current = task.getDownloadEntity().getCurrentProgress(); - long len = task.getDownloadEntity().getFileSize(); - if (len == 0) { - mPb.setProgress(0); - } else { - mPb.setProgress((int) ((current * 100) / len)); - } + mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget(); } } } \ No newline at end of file diff --git a/app/src/main/res/layout/content_single.xml b/app/src/main/res/layout/content_single.xml index c0029e03..8a620180 100644 --- a/app/src/main/res/layout/content_single.xml +++ b/app/src/main/res/layout/content_single.xml @@ -9,9 +9,8 @@ tools:showIn="@layout/activity_single" > - + +