优化代码,优化demo

pull/330/head
AriaLyy 8 years ago
parent 1764f50258
commit 59b983eaec
  1. 15
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  2. 7
      Aria/src/main/java/com/arialyy/aria/core/download/SingleThreadTask.java
  3. 54
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  4. 24
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  5. 11
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  6. 26
      app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java
  7. 74
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  8. 6
      app/src/main/res/layout/dialog_msg.xml
  9. 12
      app/src/main/res/menu/menu_single_task_activity.xml

@ -21,7 +21,6 @@ import android.util.Log;
import com.arialyy.aria.core.RequestEnum; import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.util.CheckUtil;
import java.io.File; import java.io.File;
import java.util.Map; import java.util.Map;
@ -67,8 +66,6 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
} }
@Override public int getPercent() { @Override public int getPercent() {
DownloadEntity entity = DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?",
this.entity.getDownloadUrl());
if (entity == null) { if (entity == null) {
Log.e("DownloadTarget", "下载管理器中没有该任务"); Log.e("DownloadTarget", "下载管理器中没有该任务");
return 0; return 0;
@ -103,8 +100,8 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
/** /**
* 下载任务是否存在 * 下载任务是否存在
*/ */
@Override public boolean taskExists(String downloadUrl) { @Override public boolean taskExists() {
return DownloadTaskQueue.getInstance().getTask(downloadUrl) != null; return DownloadTaskQueue.getInstance().getTask(entity.getDownloadUrl()) != null;
} }
/** /**
@ -141,15 +138,15 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
return this; return this;
} }
private DownloadEntity getDownloadEntity(String downloadUrl) { private DownloadEntity getDownloadEntity() {
CheckUtil.checkDownloadUrl(downloadUrl); return entity;
return DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl);
} }
/** /**
* 是否在下载 * 是否在下载
*/ */
public boolean isDownloading() { public boolean isDownloading() {
return DownloadTaskQueue.getInstance().getTask(entity).isRunning(); DownloadTask task = DownloadTaskQueue.getInstance().getTask(entity);
return task != null && task.isRunning();
} }
} }

@ -112,7 +112,8 @@ final class SingleThreadTask implements Runnable {
} }
//支持断点的处理 //支持断点的处理
if (mConfigEntity.isSupportBreakpoint) { if (mConfigEntity.isSupportBreakpoint) {
Log.i(TAG, "线程【" + mConfigEntity.THREAD_ID + "】下载完毕"); Log.i(TAG,
"任务【" + mConfigEntity.TEMP_FILE.getName() + "】线程【" + mConfigEntity.THREAD_ID + "】下载完毕");
writeConfig(mConfigEntity.TEMP_FILE.getName() + "_state_" + mConfigEntity.THREAD_ID, 1); writeConfig(mConfigEntity.TEMP_FILE.getName() + "_state_" + mConfigEntity.THREAD_ID, 1);
mListener.onChildComplete(mConfigEntity.END_LOCATION); mListener.onChildComplete(mConfigEntity.END_LOCATION);
CONSTANCE.COMPLETE_THREAD_NUM++; CONSTANCE.COMPLETE_THREAD_NUM++;
@ -130,14 +131,11 @@ final class SingleThreadTask implements Runnable {
mListener.onComplete(); mListener.onComplete();
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
CONSTANCE.FAIL_NUM++;
failDownload(mConfigEntity, mChildCurrentLocation, "下载链接异常", e); failDownload(mConfigEntity, mChildCurrentLocation, "下载链接异常", e);
} catch (IOException e) { } catch (IOException e) {
CONSTANCE.FAIL_NUM++;
failDownload(mConfigEntity, mChildCurrentLocation, "下载失败【" + mConfigEntity.DOWNLOAD_URL + "】", failDownload(mConfigEntity, mChildCurrentLocation, "下载失败【" + mConfigEntity.DOWNLOAD_URL + "】",
e); e);
} catch (Exception e) { } catch (Exception e) {
CONSTANCE.FAIL_NUM++;
failDownload(mConfigEntity, mChildCurrentLocation, "获取流失败", e); failDownload(mConfigEntity, mChildCurrentLocation, "获取流失败", e);
} }
} }
@ -218,6 +216,7 @@ final class SingleThreadTask implements Runnable {
Exception ex) { Exception ex) {
synchronized (LOCK) { synchronized (LOCK) {
try { try {
CONSTANCE.FAIL_NUM++;
CONSTANCE.isDownloading = false; CONSTANCE.isDownloading = false;
CONSTANCE.isStop = true; CONSTANCE.isStop = true;
if (ex != null) { if (ex != null) {

@ -23,9 +23,7 @@ import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -89,31 +87,39 @@ public abstract class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITas
/** /**
* 获取任务文件大小 * 获取任务文件大小
* *
* @return -1没有找到该任务 * @return 文件大小
*/ */
public long getFileSize() { public long getFileSize() {
if (entity instanceof DownloadEntity) { if (entity instanceof DownloadEntity) {
DownloadEntity entity = DbEntity.findData(DownloadEntity.class, "downloadUrl=?", DownloadEntity entity = (DownloadEntity) this.entity;
((DownloadEntity) this.entity).getDownloadUrl());
if (entity == null) {
throw new NullPointerException("没有找到该任务");
}
return entity.getFileSize(); return entity.getFileSize();
} else if (entity instanceof UploadEntity) { } else if (entity instanceof UploadEntity) {
UploadEntity entity = DbEntity.findData(UploadEntity.class, "filePath=?", UploadEntity entity = (UploadEntity) this.entity;
((UploadEntity) this.entity).getFilePath());
if (entity == null) {
throw new NullPointerException("没有找到该任务");
}
return entity.getFileSize(); return entity.getFileSize();
} }
return -1; return 0;
}
/**
* 获取单位转换后的文件大小
*
* @return 文件大小{@code xxx mb}
*/
public String getConvertFileSize() {
if (entity instanceof DownloadEntity) {
DownloadEntity entity = (DownloadEntity) this.entity;
return CommonUtil.formatFileSize(entity.getFileSize());
} else if (entity instanceof UploadEntity) {
UploadEntity entity = (UploadEntity) this.entity;
return CommonUtil.formatFileSize(entity.getFileSize());
}
return "0b";
} }
/** /**
* 下载任务是否存在 * 下载任务是否存在
*/ */
public boolean taskExists(String downloadUrl) { public boolean taskExists() {
return false; return false;
} }
@ -127,26 +133,16 @@ public abstract class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITas
} }
/** /**
* 获取当前任务进度如果任务存在则返回当前进度 * 获取任务进度如果任务存在则返回当前进度
* *
* @return -1没有找到该任务 * @return 该任务进度
*/ */
public long getCurrentProgress() { public long getCurrentProgress() {
if (entity instanceof DownloadEntity) { if (entity instanceof DownloadEntity) {
DownloadEntity entity = DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", DownloadEntity entity = (DownloadEntity) this.entity;
((DownloadEntity) this.entity).getDownloadUrl());
if (entity == null) {
Log.e("DownloadTarget", "下载管理器中没有该任务");
return -1;
}
return entity.getCurrentProgress(); return entity.getCurrentProgress();
} else if (entity instanceof UploadEntity) { } else if (entity instanceof UploadEntity) {
UploadEntity entity = DbEntity.findData(UploadEntity.class, "filePath=?", UploadEntity entity = (UploadEntity) this.entity;
((UploadEntity) this.entity).getFilePath());
if (entity == null) {
Log.e("DownloadTarget", "下载管理器中没有该任务");
return -1;
}
return entity.getCurrentProgress(); return entity.getCurrentProgress();
} }
return -1; return -1;

@ -59,7 +59,7 @@ public class DownloadTaskQueue
Set<String> keys = exeTasks.keySet(); Set<String> keys = exeTasks.keySet();
for (String key : keys) { for (String key : keys) {
DownloadTask temp = exeTasks.get(key); DownloadTask temp = exeTasks.get(key);
if (temp != null && temp.isRunning() && temp.isHighestPriorityTask() && !temp.getKey() if (temp != null && temp.isRunning() && temp.isHighestPriorityTask() && !temp.getKey()
.equals(task.getKey())) { .equals(task.getKey())) {
Log.e(TAG, "设置最高优先级任务失败,失败原因【任务中已经有最高优先级任务,请等待上一个最高优先级任务完成,或手动暂停该任务】"); Log.e(TAG, "设置最高优先级任务失败,失败原因【任务中已经有最高优先级任务,请等待上一个最高优先级任务完成,或手动暂停该任务】");
task.setHighestPriority(false); task.setHighestPriority(false);
@ -76,18 +76,26 @@ public class DownloadTaskQueue
for (int i = 0; i < maxSize; i++) { for (int i = 0; i < maxSize; i++) {
DownloadTask oldTsk = mExecutePool.pollTask(); DownloadTask oldTsk = mExecutePool.pollTask();
if (oldTsk != null && oldTsk.isRunning()) { if (oldTsk != null && oldTsk.isRunning()) {
oldTsk.stop(); if (i == maxSize - 1) {
oldTsk.stop();
break;
}
tempTasks.add(oldTsk); tempTasks.add(oldTsk);
} }
} }
startTask(task); startTask(task);
int i = 0, len = tempTasks.size() - 1;
for (DownloadTask oldTask : tempTasks) { for (DownloadTask temp : tempTasks){
if (i < len) { mExecutePool.putTask(temp);
startTask(oldTask);
}
i++;
} }
//int i = 0, len = tempTasks.size() - 1;
//for (DownloadTask oldTask : tempTasks) {
// if (i < len) {
// startTask(oldTask);
// }
// i++;
//}
} }
} }

@ -103,8 +103,8 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
/** /**
* 下载任务是否存在 * 下载任务是否存在
*/ */
@Override public boolean taskExists(String downloadUrl) { @Override public boolean taskExists() {
return UploadTaskQueue.getInstance().getTask(downloadUrl) != null; return UploadTaskQueue.getInstance().getTask(entity.getFilePath()) != null;
} }
/** /**
@ -117,14 +117,15 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
return this; return this;
} }
private UploadEntity getDownloadEntity(@NonNull String filePath) { private UploadEntity getDownloadEntity() {
return DbEntity.findData(UploadEntity.class, "filePath=?", filePath); return entity;
} }
/** /**
* 是否在下载 * 是否在下载
*/ */
public boolean isUploading() { public boolean isUploading() {
return UploadTaskQueue.getInstance().getTask(entity).isRunning(); UploadTask task = UploadTaskQueue.getInstance().getTask(entity);
return task != null && task.isRunning();
} }
} }

@ -13,6 +13,7 @@ import android.widget.TextView;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.L;
@ -52,18 +53,22 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
setTitle("最高优先级任务演示"); setTitle("最高优先级任务");
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)"); getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
initWidget(); initWidget();
} }
private void initWidget() { private void initWidget() {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) { DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent()); mPb.setProgress(target.getPercent());
if (Aria.download(this).load(DOWNLOAD_URL).getTaskState() == IEntity.STATE_STOP) { if (target.getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复"); mStart.setText("恢复");
} mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
setBtState(true);
}else if (target.isDownloading()){
setBtState(false);
} }
mSize.setText(target.getConvertFileSize());
List<DownloadEntity> temp = Aria.download(this).getTaskList(); List<DownloadEntity> temp = Aria.download(this).getTaskList();
if (temp != null && !temp.isEmpty()) { if (temp != null && !temp.isEmpty()) {
for (DownloadEntity entity : temp) { for (DownloadEntity entity : temp) {
@ -83,8 +88,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
} }
@Override public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); getMenuInflater().inflate(R.menu.menu_highest_priority, menu);
inflater.inflate(R.menu.menu_highest_priority, menu);
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }
@ -183,6 +187,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("恢复"); mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
} }
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@ -190,6 +195,8 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
@Override public void onTaskCancel(DownloadTask task) { @Override public void onTaskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("开始");
mPb.setProgress(0);
} }
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }
@ -205,6 +212,9 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
@Override public void onTaskComplete(DownloadTask task) { @Override public void onTaskComplete(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true); setBtState(true);
mStart.setText("重新开始");
mStart.setTextColor(getResources().getColor(android.R.color.holo_green_light));
mPb.setProgress(100);
} }
mAdapter.updateState(task.getDownloadEntity()); mAdapter.updateState(task.getDownloadEntity());
} }

@ -25,6 +25,8 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.RadioGroup; import android.widget.RadioGroup;
@ -42,6 +44,7 @@ import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T; import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.common.MsgDialog;
import com.arialyy.simple.databinding.ActivitySingleBinding; import com.arialyy.simple.databinding.ActivitySingleBinding;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
@ -53,6 +56,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
public static final int DOWNLOAD_RESUME = 0x05; public static final int DOWNLOAD_RESUME = 0x05;
public static final int DOWNLOAD_COMPLETE = 0x06; public static final int DOWNLOAD_COMPLETE = 0x06;
public static final int DOWNLOAD_RUNNING = 0x07; public static final int DOWNLOAD_RUNNING = 0x07;
public static final int DOWNLOAD_START = 0x08;
private static final String DOWNLOAD_URL = private static final String DOWNLOAD_URL =
//"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"http://kotlinlang.org/docs/kotlin-docs.pdf";
@ -95,9 +99,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
mSpeed.setText(task.getConvertSpeed()); mSpeed.setText(task.getConvertSpeed());
break; break;
case DOWNLOAD_PRE: case DOWNLOAD_PRE:
mSize.setText(CommonUtil.formatFileSize((Long) msg.obj));
setBtState(false); setBtState(false);
//mStart.setText("暂停"); break;
case DOWNLOAD_START:
mSize.setText(CommonUtil.formatFileSize((Long) msg.obj));
break; break;
case DOWNLOAD_FAILE: case DOWNLOAD_FAILE:
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show(); Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
@ -115,9 +120,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
setBtState(true); setBtState(true);
break; break;
case DOWNLOAD_RESUME: case DOWNLOAD_RESUME:
//Toast.makeText(SingleTaskActivity.this,
// "恢复下载,恢复位置 ==> " + CommonUtil.formatFileSize((Long) msg.obj), Toast.LENGTH_SHORT)
// .show();
mStart.setText("暂停"); mStart.setText("暂停");
setBtState(false); setBtState(false);
break; break;
@ -146,6 +148,22 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter()); //registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
} }
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_single_task_activity, menu);
return super.onCreateOptionsMenu(menu);
}
@Override public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.help) {
String msg = "一些小知识点:\n"
+ "1、你可以通过task.getKey().equals(DOWNLOAD_URL)判断是否是当前页面的下载,以防止progress乱跳\n"
+ "2、当遇到网络慢的情况时,你可以先使用onPre()更新UI界面,待连接成功时,再在onTaskPre()获取完整的task数据,然后给UI界面设置正确的数据\n"
+ "3、你可以在界面初始化时通过Aria.download(this).load(DOWNLOAD_URL).getPercent()等方法快速获取相关任务的一些数据";
showMsgDialog("tip", msg);
}
return true;
}
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
return R.layout.activity_single; return R.layout.activity_single;
} }
@ -153,12 +171,16 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override protected void init(Bundle savedInstanceState) { @Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState); super.init(savedInstanceState);
setTitle("单任务下载"); setTitle("单任务下载");
if (Aria.download(this).taskExists(DOWNLOAD_URL)) { DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent()); mPb.setProgress(target.getPercent());
if (Aria.download(this).load(DOWNLOAD_URL).getTaskState() == IEntity.STATE_STOP) { if (target.getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复"); mStart.setText("恢复");
} mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
setBtState(true);
} else if (target.isDownloading()) {
setBtState(false);
} }
mSize.setText(target.getConvertFileSize());
Aria.get(this).getDownloadConfig().setOpenBreadCast(true); Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
} }
@ -187,7 +209,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private class MySchedulerListener extends Aria.DownloadSchedulerListener { private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onPre(DownloadTask task) { @Override public void onPre(DownloadTask task) {
super.onPre(task); if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
.sendToTarget();
}
} }
@Override public void onNoSupportBreakPoint(DownloadTask task) { @Override public void onNoSupportBreakPoint(DownloadTask task) {
@ -198,34 +223,45 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override public void onTaskStart(DownloadTask task) { @Override public void onTaskStart(DownloadTask task) {
//通过下载地址可以判断任务是否是你指定的任务 //通过下载地址可以判断任务是否是你指定的任务
if (task.getKey().equals(DOWNLOAD_URL)) { if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize()) mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getDownloadEntity().getFileSize())
.sendToTarget(); .sendToTarget();
} }
} }
@Override public void onTaskResume(DownloadTask task) { @Override public void onTaskResume(DownloadTask task) {
super.onTaskResume(task); if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getFileSize()).sendToTarget(); mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getFileSize()).sendToTarget();
}
} }
@Override public void onTaskStop(DownloadTask task) { @Override public void onTaskStop(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP); if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
}
} }
@Override public void onTaskCancel(DownloadTask task) { @Override public void onTaskCancel(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL); if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
}
} }
@Override public void onTaskFail(DownloadTask task) { @Override public void onTaskFail(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE); if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
}
} }
@Override public void onTaskComplete(DownloadTask task) { @Override public void onTaskComplete(DownloadTask task) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE); if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE);
}
} }
@Override public void onTaskRunning(DownloadTask task) { @Override public void onTaskRunning(DownloadTask task) {
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget(); if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget();
}
} }
} }
} }

@ -17,14 +17,16 @@
android:orientation="vertical" android:orientation="vertical"
> >
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/background_color" android:background="@color/background_color"
android:gravity="center|left" android:gravity="center|left"
android:maxHeight="400dp" android:maxHeight="400dp"
android:padding="8dp" android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="@{title}" android:text="@{title}"
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:textSize="22sp" android:textSize="22sp"

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/help"
android:icon="@mipmap/ic_help_black_48dp"
android:orderInCategory="90"
android:title="tip"
app:showAsAction="ifRoom"
/>
</menu>
Loading…
Cancel
Save