最高优先级任务功能实现,demo修改

pull/330/head
AriaLyy 8 years ago
parent 52a4f1e7ea
commit 1764f50258
  1. 9
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  2. 2
      Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java
  3. 18
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java
  4. 11
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  5. 9
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  6. 9
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  7. 1
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  8. 15
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  9. 23
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/CachePool.java
  10. 30
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
  11. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java
  12. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulerListener.java
  13. 2
      Aria/src/main/java/com/arialyy/aria/core/scheduler/UploadSchedulers.java
  14. 16
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTask.java
  15. 8
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  16. 20
      Aria/src/main/java/com/arialyy/aria/util/FileUtil.java
  17. 67
      Aria/src/main/java/com/arialyy/aria/window/AriaFileChangeActivity.java
  18. 92
      Aria/src/main/java/com/arialyy/aria/window/FileChangeAdapter.java
  19. 29
      Aria/src/main/java/com/arialyy/aria/window/FileEntity.java
  20. 2
      README.md
  21. 1
      app/src/main/AndroidManifest.xml
  22. 2
      app/src/main/assets/aria_config.xml
  23. 4
      app/src/main/java/com/arialyy/simple/MainActivity.java
  24. 41
      app/src/main/java/com/arialyy/simple/base/BaseActivity.java
  25. 38
      app/src/main/java/com/arialyy/simple/common/MsgDialog.java
  26. 8
      app/src/main/java/com/arialyy/simple/download/DownloadActivity.java
  27. 113
      app/src/main/java/com/arialyy/simple/download/DownloadModule.java
  28. 97
      app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java
  29. 24
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  30. 7
      app/src/main/java/com/arialyy/simple/download/multi_download/DownloadAdapter.java
  31. 7
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  32. 5
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  33. 5
      app/src/main/java/com/arialyy/simple/upload/UploadActivity.java
  34. 10
      app/src/main/res/layout/activity_highest_priority.xml
  35. 63
      app/src/main/res/layout/dialog_msg.xml
  36. 18
      app/src/main/res/layout/item_download.xml
  37. 21
      app/src/main/res/menu/menu_highest_priority.xml
  38. BIN
      app/src/main/res/mipmap-mdpi/ic_add_black_48dp.png
  39. BIN
      app/src/main/res/mipmap-mdpi/ic_help_black_48dp.png
  40. 12
      app/src/main/res/values/strings.xml

@ -177,9 +177,9 @@ import com.arialyy.aria.core.upload.UploadTask;
/**
* 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态
*
* @param url 任务上传地址
* @param task 上传文物实体
*/
@Override public void onPre(String url) {
@Override public void onPre(UploadTask task) {
}
@ -223,10 +223,11 @@ import com.arialyy.aria.core.upload.UploadTask;
implements IDownloadSchedulerListener<DownloadTask> {
/**
* 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态
* 需要注意的是在该回调中是得不到文件长度的如果需要获取文件长度需要在onTaskPre中获取
*
* @param url 任务下载地址
* @param task 下载任务
*/
@Override public void onPre(String url) {
@Override public void onPre(DownloadTask task) {
}

@ -47,7 +47,7 @@ final class HighestPriorityCmd<T extends ITaskEntity> extends AbsCmd<T> {
if (!TextUtils.isEmpty(mTargetName)) {
task.setTargetName(mTargetName);
}
task.setHighestPriority(true);
mQueue.setTaskHighestPriority(task);
}
}
}

@ -76,7 +76,7 @@ public class DownloadTask implements ITask {
}
/**
* @return 返回转换单位后的速度需要你在配置文件中配置转换完成后为1b/s1k/s1m/s1g/s1t/s
* @return 返回转换单位后的速度需要你在配置文件中配置转换完成后为1b/s1kb/s1mb/s1gb/s1tb/s
* <pre>
* {@code
* <xml>
@ -118,11 +118,11 @@ public class DownloadTask implements ITask {
/**
* 转换单位后的文件长度
*
* @return 如果文件长度为0则返回0m否则返回转换后的长度1b1k1m1g1t
* @return 如果文件长度为0则返回0m否则返回转换后的长度1b1kb1mb1gb1tb
*/
@Override public String getConvertFileSize() {
if (mEntity.getFileSize() == 0) {
return "0m";
return "0mb";
}
return CommonUtil.formatFileSize(mEntity.getFileSize());
}
@ -134,6 +134,18 @@ public class DownloadTask implements ITask {
return mEntity.getCurrentProgress();
}
/**
* 获取单位转换后的进度
*
* @return 已经下载3mb的大小则返回{@code 3mb}
*/
@Override public String getConvertCurrentProgress() {
if (mEntity.getCurrentProgress() == 0) {
return "0b";
}
return CommonUtil.formatFileSize(mEntity.getCurrentProgress());
}
/**
* 获取当前下载任务的下载地址
*

@ -35,11 +35,20 @@ import java.util.Set;
/**
* Created by lyy on 2017/2/28.
*/
public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity> {
public abstract class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity> {
protected ENTITY entity;
protected TASK_ENTITY taskEntity;
protected String targetName;
/**
* 获取任务状态
*
* @return {@link IEntity}
*/
public int getTaskState() {
return entity.getState();
}
/**
* 将任务设置为最高优先级任务最高优先级任务有以下特点
* 1在下载队列中有且只有一个最高优先级任务

@ -0,0 +1,9 @@
package com.arialyy.aria.core.inf;
/**
* Created by lyy on 2017/6/3.
*/
public abstract class AbsTask implements ITask{
}

@ -81,8 +81,17 @@ public interface ITask {
*/
public String getConvertFileSize();
/**
* 获取当前进度
*/
public long getCurrentProgress();
/**
* 获取单位转换后的进度
* @return 返回 3mb
*/
public String getConvertCurrentProgress();
public void setTargetName(String targetName);
public void removeRecord();

@ -87,6 +87,7 @@ abstract class AbsTaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity,
@Override public void stopTask(TASK task) {
if (!task.isRunning()) Log.w(TAG, "停止任务失败,【任务已经停止】");
task.setHighestPriority(false);
if (mExecutePool.removeTask(task)) {
task.stop();
} else {

@ -26,6 +26,7 @@ import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.queue.pool.ExecutePool;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
/**
@ -52,6 +53,20 @@ public class DownloadTaskQueue
}
@Override public void setTaskHighestPriority(DownloadTask task) {
task.setHighestPriority(true);
Map<String, DownloadTask> exeTasks = mExecutePool.getAllTask();
if (exeTasks != null && !exeTasks.isEmpty()) {
Set<String> keys = exeTasks.keySet();
for (String key : keys) {
DownloadTask temp = exeTasks.get(key);
if (temp != null && temp.isRunning() && temp.isHighestPriorityTask() && !temp.getKey()
.equals(task.getKey())) {
Log.e(TAG, "设置最高优先级任务失败,失败原因【任务中已经有最高优先级任务,请等待上一个最高优先级任务完成,或手动暂停该任务】");
task.setHighestPriority(false);
return;
}
}
}
int maxSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
int currentSize = mExecutePool.size();
if (currentSize == 0 || currentSize < maxSize) {

@ -34,12 +34,19 @@ public class CachePool<TASK extends ITask> implements IPool<TASK> {
private static final Object LOCK = new Object();
private static final int MAX_NUM = Integer.MAX_VALUE; //最大下载任务数
private static final long TIME_OUT = 1000;
private Map<String, TASK> mCacheArray;
private Map<String, TASK> mCacheMap;
private LinkedBlockingQueue<TASK> mCacheQueue;
public CachePool() {
mCacheQueue = new LinkedBlockingQueue<>(MAX_NUM);
mCacheArray = new HashMap<>();
mCacheMap = new HashMap<>();
}
/**
* 获取所有正在执行的任务
*/
public Map<String, TASK> getAllTask() {
return mCacheMap;
}
@Override public boolean putTask(TASK task) {
@ -56,7 +63,7 @@ public class CachePool<TASK extends ITask> implements IPool<TASK> {
boolean s = mCacheQueue.offer(task);
Log.d(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】"));
if (s) {
mCacheArray.put(CommonUtil.keyToHashKey(url), task);
mCacheMap.put(CommonUtil.keyToHashKey(url), task);
}
return s;
}
@ -70,7 +77,7 @@ public class CachePool<TASK extends ITask> implements IPool<TASK> {
task = mCacheQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (task != null) {
String url = task.getKey();
mCacheArray.remove(CommonUtil.keyToHashKey(url));
mCacheMap.remove(CommonUtil.keyToHashKey(url));
}
return task;
} catch (InterruptedException e) {
@ -87,7 +94,7 @@ public class CachePool<TASK extends ITask> implements IPool<TASK> {
return null;
}
String key = CommonUtil.keyToHashKey(downloadUrl);
return mCacheArray.get(key);
return mCacheMap.get(key);
}
}
@ -98,7 +105,7 @@ public class CachePool<TASK extends ITask> implements IPool<TASK> {
return false;
} else {
String key = CommonUtil.keyToHashKey(task.getKey());
mCacheArray.remove(key);
mCacheMap.remove(key);
return mCacheQueue.remove(task);
}
}
@ -111,8 +118,8 @@ public class CachePool<TASK extends ITask> implements IPool<TASK> {
return false;
}
String key = CommonUtil.keyToHashKey(downloadUrl);
TASK task = mCacheArray.get(key);
mCacheArray.remove(key);
TASK task = mCacheMap.get(key);
mCacheMap.remove(key);
return mCacheQueue.remove(task);
}
}

@ -23,6 +23,7 @@ import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.util.CommonUtil;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
@ -35,7 +36,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
private static final Object LOCK = new Object();
private static final long TIME_OUT = 1000;
private ArrayBlockingQueue<TASK> mExecuteQueue;
private Map<String, TASK> mExecuteArray;
private Map<String, TASK> mExecuteMap;
private int mSize;
public ExecutePool(boolean isDownload) {
@ -45,7 +46,14 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
mSize = AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
}
mExecuteQueue = new ArrayBlockingQueue<>(mSize);
mExecuteArray = new HashMap<>();
mExecuteMap = new HashMap<>();
}
/**
* 获取所有正在执行的任务
*/
public Map<String, TASK> getAllTask() {
return mExecuteMap;
}
@Override public boolean putTask(TASK task) {
@ -60,6 +68,10 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
return false;
} else {
if (mExecuteQueue.size() >= mSize) {
Set<String> keys = mExecuteMap.keySet();
for (String key : keys) {
if (mExecuteMap.get(key).isHighestPriorityTask()) return false;
}
if (pollFirstTask()) {
return putNewTask(task);
}
@ -100,7 +112,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
boolean s = mExecuteQueue.offer(newTask);
Log.w(TAG, "任务添加" + (s ? "成功" : "失败,【" + url + "】"));
if (s) {
mExecuteArray.put(CommonUtil.keyToHashKey(url), newTask);
mExecuteMap.put(CommonUtil.keyToHashKey(url), newTask);
}
return s;
}
@ -120,7 +132,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
}
oldTask.stop();
String key = CommonUtil.keyToHashKey(oldTask.getKey());
mExecuteArray.remove(key);
mExecuteMap.remove(key);
} catch (InterruptedException e) {
e.printStackTrace();
return false;
@ -135,7 +147,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
task = mExecuteQueue.poll(TIME_OUT, TimeUnit.MICROSECONDS);
if (task != null) {
String url = task.getKey();
mExecuteArray.remove(CommonUtil.keyToHashKey(url));
mExecuteMap.remove(CommonUtil.keyToHashKey(url));
}
return task;
} catch (InterruptedException e) {
@ -152,7 +164,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
return null;
}
String key = CommonUtil.keyToHashKey(downloadUrl);
return mExecuteArray.get(key);
return mExecuteMap.get(key);
}
}
@ -163,7 +175,7 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
return false;
} else {
String key = CommonUtil.keyToHashKey(task.getKey());
mExecuteArray.remove(key);
mExecuteMap.remove(key);
return mExecuteQueue.remove(task);
}
}
@ -176,8 +188,8 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
return false;
}
String key = CommonUtil.keyToHashKey(downloadUrl);
TASK task = mExecuteArray.get(key);
mExecuteArray.remove(key);
TASK task = mExecuteMap.get(key);
mExecuteMap.remove(key);
return mExecuteQueue.remove(task);
}
}

@ -129,7 +129,7 @@ public class DownloadSchedulers implements ISchedulers<DownloadTask> {
}
switch (state) {
case PRE:
listener.onPre(task.getKey());
listener.onPre(task);
break;
case POST_PRE:
listener.onTaskPre(task);

@ -25,7 +25,7 @@ public interface ISchedulerListener<TASK extends ITask> {
* 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态
* 在这个回调中任务是获取不到文件大小下载速度等参数
*/
public void onPre(String url);
public void onPre(TASK task);
/**
* 任务预加载完成

@ -132,7 +132,7 @@ public class UploadSchedulers implements ISchedulers<UploadTask> {
}
switch (state) {
case PRE:
listener.onPre(task.getKey());
listener.onPre(task);
break;
case POST_PRE:
listener.onTaskPre(task);

@ -139,7 +139,7 @@ public class UploadTask implements ITask {
}
/**
* @return 返回转换单位后的速度需要你在配置文件中配置转换完成后为1b/s1k/s1m/s1g/s1t/s
* @return 返回转换单位后的速度需要你在配置文件中配置转换完成后为1b/s1kb/s1mb/s1gb/s1tb/s
* <pre>
* {@code
* <xml>
@ -175,7 +175,7 @@ public class UploadTask implements ITask {
/**
* 转换单位后的文件长度
*
* @return 如果文件长度为0则返回0m否则返回转换后的长度1b1k1m1g1t
* @return 如果文件长度为0则返回0m否则返回转换后的长度1b1kb1mb1gb1tb
*/
@Override public String getConvertFileSize() {
if (mUploadEntity.getFileSize() == 0) {
@ -192,6 +192,18 @@ public class UploadTask implements ITask {
return mUploadEntity.getCurrentProgress();
}
/**
* 获取单位转换后的进度
*
* @return 已经下载3mb的大小则返回{@code 3mb}
*/
@Override public String getConvertCurrentProgress() {
if (mUploadEntity.getCurrentProgress() == 0) {
return "0b";
}
return CommonUtil.formatFileSize(mUploadEntity.getCurrentProgress());
}
private static class UListener extends UploadListener {
WeakReference<Handler> outHandler;
WeakReference<UploadTask> task;

@ -207,22 +207,22 @@ public class CommonUtil {
double megaByte = kiloByte / 1024;
if (megaByte < 1) {
BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "k";
return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "kb";
}
double gigaByte = megaByte / 1024;
if (gigaByte < 1) {
BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "m";
return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "mb";
}
double teraBytes = gigaByte / 1024;
if (teraBytes < 1) {
BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "g";
return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "gb";
}
BigDecimal result4 = new BigDecimal(teraBytes);
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "t";
return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "tb";
}
/**

@ -17,7 +17,6 @@ package com.arialyy.aria.util;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.window.FileEntity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -27,8 +26,6 @@ import java.io.InputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by lyy on 2017/3/21.
@ -138,21 +135,4 @@ public class FileUtil {
}
}
}
/**
* 文件列表
*/
public List<FileEntity> loadFiles(String path) {
File file = new File(path);
File[] files = file.listFiles();
List<FileEntity> list = new ArrayList<>();
for (File f : files) {
FileEntity entity = new FileEntity();
entity.fileName = f.getName();
//entity.fileInfo = getFileType(f.getPath());
//entity.fileDrawable = getApkIcon(mContext, f.getPath());
list.add(entity);
}
return list;
}
}

@ -1,67 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.window;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.widget.AbsListView;
import android.widget.ListView;
import com.arialyy.aria.R;
import com.arialyy.aria.util.FileUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by lyy on 2017/3/21.
* 文件选择
*/
class AriaFileChangeActivity extends FragmentActivity {
final String ROOT_PAT = Environment.getExternalStorageDirectory().getPath();
ListView mList;
FileChangeAdapter mAdapter;
Map<String, List<FileEntity>> mData = new HashMap<>();
private String mCurrentPath = ROOT_PAT;
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aria_file_shange);
mList = (ListView) findViewById(R.id.list);
mList.setOnScrollListener(new AbsListView.OnScrollListener() {
int state;
@Override public void onScrollStateChanged(AbsListView view, int scrollState) {
state = scrollState;
}
@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
if (state == AbsListView.OnScrollListener.SCROLL_STATE_IDLE
&& firstVisibleItem + visibleItemCount == totalItemCount) {
loadMore();
}
}
});
}
private void loadMore() {
}
}

@ -1,92 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.window;
import android.content.Context;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.arialyy.aria.R;
import java.util.ArrayList;
import java.util.List;
/**
* Created by lyy on 2017/3/21.
*/
final class FileChangeAdapter extends BaseAdapter {
List<FileEntity> mData = new ArrayList<>();
SparseBooleanArray mCheck = new SparseBooleanArray();
Context mContext;
public FileChangeAdapter(Context context, List<FileEntity> list) {
mContext = context;
mData.addAll(list);
for (int i = 0, len = mData.size(); i < len; i++) {
mCheck.append(i, false);
}
}
@Override public int getCount() {
return mData.size();
}
@Override public Object getItem(int position) {
return null;
}
@Override public long getItemId(int position) {
return 0;
}
@Override public View getView(int position, View convertView, ViewGroup parent) {
FileChangeHolder holder = null;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_file, null);
holder = new FileChangeHolder(convertView);
convertView.setTag(holder);
} else {
holder = (FileChangeHolder) convertView.getTag();
}
holder.checkBox.setChecked(mCheck.get(position, false));
return convertView;
}
public void setCheck(int position, boolean check) {
if (position >= mData.size()) return;
mCheck.put(position, check);
notifyDataSetChanged();
}
private static class FileChangeHolder {
TextView title, info;
ImageView icon;
CheckBox checkBox;
FileChangeHolder(View view) {
title = (TextView) view.findViewById(R.id.title);
info = (TextView) view.findViewById(R.id.info);
icon = (ImageView) view.findViewById(R.id.icon);
checkBox = (CheckBox) view.findViewById(R.id.checkbox);
}
}
}

@ -1,29 +0,0 @@
/*
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arialyy.aria.window;
import android.graphics.drawable.Drawable;
/**
* Created by lyy on 2017/3/21.
*/
class FileEntity {
public String fileName;
public String fileInfo;
public int fileIcon;
public Drawable fileDrawable;
}

@ -158,7 +158,7 @@ compile 'com.arialyy.aria:Aria:3.1.4'
<!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
<ca name="" path=""/>
<!--是否需要转换速度单位,转换完成后为:1b/s、1k/s、1m/s、1g/s、1t/s,如果不需要将返回byte长度-->
<!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
<cnvertSpeed value="false"/>
</download>

@ -29,6 +29,7 @@
<activity android:name=".download.multi_download.MultiTaskActivity"/>
<activity android:name=".download.fragment_download.FragmentActivity"/>
<activity android:name=".download.multi_download.MultiDownloadActivity"/>
<activity android:name=".download.HighestPriorityActivity"/>
<service android:name=".download.service_download.DownloadService"/>
</application>

@ -31,7 +31,7 @@
<!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
<ca name="" path=""/>
<!--是否需要转换速度单位,转换完成后为:1b/s、1k/s、1m/s、1g/s、1t/s,如果不需要将返回byte长度-->
<!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
<convertSpeed value="true"/>
</download>

@ -33,11 +33,11 @@ import com.arialyy.simple.upload.UploadActivity;
*/
public class MainActivity extends BaseActivity<ActivityMainBinding> {
@Bind(R.id.toolbar) Toolbar mBar;
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(mBar);
mBar.setTitle("Aria Demo");
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
@Override protected int setLayoutId() {

@ -18,15 +18,21 @@ package com.arialyy.simple.base;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import butterknife.Bind;
import com.arialyy.frame.core.AbsActivity;
import com.arialyy.frame.util.AndroidVersionUtil;
import com.arialyy.simple.R;
import com.arialyy.simple.common.MsgDialog;
/**
* Created by Lyy on 2016/9/27.
*/
public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivity<VB> {
public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivity<VB>
implements Toolbar.OnMenuItemClickListener {
@Bind(R.id.toolbar) protected Toolbar mBar;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -35,11 +41,36 @@ public abstract class BaseActivity<VB extends ViewDataBinding> extends AbsActivi
}
}
@Override protected void dataCallback(int result, Object data) {
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(mBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mBar.setOnMenuItemClickListener(this);
}
protected void setTile(String title){
mBar.setTitle(title);
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
protected void showMsgDialog(String title, String msg){
MsgDialog dialog = new MsgDialog(this, title, msg);
dialog.show(getSupportFragmentManager(), "msg_dialog");
}
@Override public boolean onMenuItemClick(MenuItem item) {
return false;
}
@Override public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override protected void dataCallback(int result, Object data) {
}
}

@ -0,0 +1,38 @@
package com.arialyy.simple.common;
import android.annotation.SuppressLint;
import android.os.Bundle;
import butterknife.OnClick;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseDialog;
import com.arialyy.simple.databinding.DialogMsgBinding;
/**
* Created by AriaL on 2017/6/3.
*/
@SuppressLint("ValidFragment") public class MsgDialog extends BaseDialog<DialogMsgBinding> {
private String mTitle, mMsg;
public MsgDialog(Object obj, String title, String msg) {
super(obj);
mTitle = title;
mMsg = msg;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
getBinding().setTitle(mTitle);
getBinding().setMsg(mMsg);
}
@Override protected int setLayoutId() {
return R.layout.dialog_msg;
}
@OnClick(R.id.enter)
public void close(){
dismiss();
}
}

@ -39,7 +39,6 @@ import com.arialyy.simple.download.service_download.DownloadService;
* Created by Lyy on 2016/10/13.
*/
public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding> {
@Bind(R.id.toolbar) Toolbar mBar;
@Bind(R.id.single_task) Button mSigleBt;
@Bind(R.id.multi_task) Button mMultiBt;
@Bind(R.id.dialog_task) Button mDialogBt;
@ -51,8 +50,7 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(mBar);
mBar.setTitle("多线程多任务下载");
setTitle("Aria下载");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
setEnable(true);
} else { //6.0处理
@ -85,6 +83,9 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
public void onClick(View view) {
switch (view.getId()) {
case R.id.highest_priority:
startActivity(new Intent(this, HighestPriorityActivity.class));
break;
case R.id.service:
startService(new Intent(this, DownloadService.class));
break;
@ -100,7 +101,6 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
break;
case R.id.pop_task:
DownloadPopupWindow pop = new DownloadPopupWindow(this);
//pop.showAsDropDown(mRootView);
pop.showAtLocation(mRootView, Gravity.CENTER_VERTICAL, 0, 0);
break;
case R.id.fragment_task:

@ -20,6 +20,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.Environment;
import android.os.Handler;
import com.arialyy.aria.core.Aria;
@ -33,6 +34,7 @@ import com.arialyy.simple.download.multi_download.FileListEntity;
import com.arialyy.simple.base.BaseModule;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
@ -40,39 +42,29 @@ import java.util.Random;
* Created by Lyy on 2016/9/27.
*/
public class DownloadModule extends BaseModule {
private List<String> mTestDownloadUrl = new ArrayList<>();
public DownloadModule(Context context) {
super(context);
mTestDownloadUrl.add(
"http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
mTestDownloadUrl.add(
"http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
mTestDownloadUrl.add(
"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
}
/**
* 获取下载列表
* 最高优先级任务测试列表
*/
public List<DownloadEntity> getDownloadTaskList() {
return Aria.download(getContext()).getTaskList();
}
public String getRadomUrl() {
Random random = new Random();
int i = random.nextInt(2);
return mTestDownloadUrl.get(i);
}
public DownloadEntity createRandomDownloadEntity() {
return createDownloadEntity(getRadomUrl());
public List<DownloadEntity> getHighestTestList() {
List<DownloadEntity> list = new LinkedList<>();
Resources res = getContext().getResources();
String[] urls = res.getStringArray(R.array.highest_urls);
String[] names = res.getStringArray(R.array.highest_names);
for (int i = 0, len = urls.length; i < len; i++) {
list.add(createDownloadEntity(urls[i], names[i]));
}
return list;
}
/**
* 创建下载地址
*/
public List<FileListEntity> createFileList() {
public List<FileListEntity> createMultiTestList() {
String[] names = getContext().getResources().getStringArray(R.array.file_nams);
String[] downloadUrl = getContext().getResources().getStringArray(R.array.download_url);
List<FileListEntity> list = new ArrayList<>();
@ -89,70 +81,17 @@ public class DownloadModule extends BaseModule {
}
/**
* 设置下载数据
* 创建下载实体Aria也可以通过下载实体启动下载
*/
public List<DownloadEntity> getDownloadData() {
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
List<DownloadEntity> list = new ArrayList<>();
for (String url : urls) {
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(url);
if (entity == null) {
entity = createDownloadEntity(url);
}
list.add(entity);
}
return list;
}
/**
* 过滤任务
*
* @param sqlEntity 数据库的下载实体
* @param createdEntity 通过下载链接生成的下载实体
*/
private List<DownloadEntity> filter(List<DownloadEntity> sqlEntity,
List<DownloadEntity> createdEntity) {
List<DownloadEntity> list = new ArrayList<>();
list.addAll(sqlEntity);
for (DownloadEntity cEntity : createdEntity) {
int count = 0;
for (DownloadEntity sEntity : sqlEntity) {
if (cEntity.getDownloadUrl().equals(sEntity.getDownloadUrl())) {
break;
}
count++;
if (count == createdEntity.size()) {
list.add(cEntity);
}
}
}
return list;
}
private DownloadEntity createDownloadEntity(String url) {
String fileName = CommonUtil.keyToHashCode(url) + ".apk";
private DownloadEntity createDownloadEntity(String downloadUrl, String name) {
String path = Environment.getExternalStorageDirectory() + "/download/" + name + ".apk";
DownloadEntity entity = new DownloadEntity();
entity.setDownloadUrl(url);
entity.setDownloadPath(getDownloadPath(url));
entity.setFileName(fileName);
//entity.setFileName("taskName_________" + i);
entity.setFileName(name);
entity.setDownloadUrl(downloadUrl);
entity.setDownloadPath(path);
return entity;
}
/**
* 创建下载列表
*/
private List<DownloadEntity> createNewDownload() {
List<DownloadEntity> list = new ArrayList<>();
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
int i = 0;
for (String url : urls) {
list.add(createDownloadEntity(url));
i++;
}
return list;
}
/**
* 下载广播过滤器
*/
@ -218,18 +157,4 @@ public class DownloadModule extends BaseModule {
}
};
}
/**
* 设置下载队列
*/
private String getDownloadPath(String url) {
String path =
Environment.getExternalStorageDirectory().getPath() + "/" + AndroidUtils.getAppName(
getContext()) + "downloads/" + StringUtil.keyToHashKey(url) + ".apk";
File file = new File(path);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
return path;
}
}

@ -4,20 +4,27 @@ import android.os.Bundle;
import android.os.Environment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import butterknife.Bind;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityHighestPriorityBinding;
import com.arialyy.simple.download.multi_download.DownloadAdapter;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by lyy on 2017/6/2.
@ -29,14 +36,15 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
@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;
@Bind(R.id.list) RecyclerView mList;
private String mTaskName = "狂野飙车8";
private String mTaskName = "光明大陆";
private static final String DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/82/ff/df82ed0af4ff4c1746cb191cf765aa8f.apk";
"https://res5.d.cn/6f78ee3bcfdd033e64892a8553a95814cf5b4a62b12a76d9eb2a694905f0dc30fa5c7f728806a4ee0b3479e7b26a38707dac92b136add91191ac1219aadb4a3aa70bfa6d06d2d8db.apk";
private DownloadAdapter mAdapter;
private List<DownloadEntity> mData = new ArrayList<>();
private Set<String> mRecord = new HashSet<>();
@Override protected int setLayoutId() {
return R.layout.activity_highest_priority;
@ -44,17 +52,27 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(toolbar);
toolbar.setTitle("最高优先级任务演示");
getBinding().setTaskName("任务名:" + mTaskName + " (该任务是最高优先级任务)");
setTitle("最高优先级任务演示");
getBinding().setTaskName("任务名:" + mTaskName + " (最高优先级任务)");
initWidget();
}
private void initWidget() {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent());
if (Aria.download(this).load(DOWNLOAD_URL).getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复");
}
}
List<DownloadEntity> temp = Aria.download(this).getTaskList();
if (temp != null && !temp.isEmpty()) {
for (DownloadEntity entity : temp) {
if (entity.getDownloadUrl().equals(DOWNLOAD_URL)) continue;
mData.add(entity);
mRecord.add(entity.getDownloadUrl());
}
}
mAdapter = new DownloadAdapter(this, getModule(DownloadModule.class).getDownloadTaskList());
mAdapter = new DownloadAdapter(this, mData);
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);
}
@ -64,6 +82,41 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
Aria.download(this).addSchedulerListener(new MySchedulerListener());
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_highest_priority, menu);
return super.onCreateOptionsMenu(menu);
}
@Override public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.add_task:
List<DownloadEntity> temp = getModule(DownloadModule.class).getHighestTestList();
for (DownloadEntity entity : temp) {
String url = entity.getDownloadUrl();
if (mRecord.contains(url)) {
continue;
}
mAdapter.addDownloadEntity(entity);
mRecord.add(url);
}
mAdapter.notifyDataSetChanged();
break;
case R.id.help:
String title = "最高优先级任务介绍";
String msg = " 将任务设置为最高优先级任务,最高优先级任务有以下特点:\n"
+ " 1、在下载队列中,有且只有一个最高优先级任务\n"
+ " 2、最高优先级任务会一直存在,直到用户手动暂停或任务完成\n"
+ " 3、任务调度器不会暂停最高优先级任务\n"
+ " 4、用户手动暂停或任务完成后,第二次重新执行该任务,该命令将失效\n"
+ " 5、如果下载队列中已经满了,则会停止队尾的任务\n"
+ " 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务";
showMsgDialog(title, msg);
break;
}
return true;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
@ -99,45 +152,46 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onPre(DownloadTask task) {
super.onPre(task);
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
if (task.getKey().equals(DOWNLOAD_URL)) {
mSize.setText(task.getConvertFileSize());
} else {
mAdapter.updateState(task.getDownloadEntity());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStart(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
} else {
mAdapter.updateState(task.getDownloadEntity());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskResume(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(false);
} else {
mAdapter.updateState(task.getDownloadEntity());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
} else {
mAdapter.updateState(task.getDownloadEntity());
mStart.setText("恢复");
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
} else {
mAdapter.updateState(task.getDownloadEntity());
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskFail(DownloadTask task) {
@ -152,16 +206,15 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
}
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskRunning(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
setBtState(true);
mPb.setProgress(task.getPercent());
mSpeed.setText(task.getConvertSpeed());
} else {
mAdapter.setProgress(task.getDownloadEntity());
}
mAdapter.setProgress(task.getDownloadEntity());
}
}
}

@ -35,6 +35,7 @@ import com.arialyy.aria.core.download.DownloadTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.Speed;
import com.arialyy.frame.util.show.L;
@ -66,7 +67,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@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;
@Bind(R.id.speeds) RadioGroup mRg;
private DownloadEntity mEntity;
@ -140,11 +140,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
mStop.setEnabled(!state);
}
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
@Override protected void onResume() {
super.onResume();
Aria.download(this).addSchedulerListener(new MySchedulerListener());
@ -157,16 +152,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(toolbar);
toolbar.setTitle("单任务下载");
init();
Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
}
private void init() {
setTitle("单任务下载");
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent());
if (Aria.download(this).load(DOWNLOAD_URL).getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复");
}
}
Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
}
public void onClick(View view) {
@ -193,9 +186,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onPre(String url) {
super.onPre(url);
Log.d(TAG, "url ==> " + url);
@Override public void onPre(DownloadTask task) {
super.onPre(task);
}
@Override public void onNoSupportBreakPoint(DownloadTask task) {

@ -55,6 +55,11 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
return new MyHolder(convertView);
}
public void addDownloadEntity(DownloadEntity entity) {
mData.add(entity);
mPositions.put(entity.getDownloadUrl(), mPositions.size());
}
@Override protected int setLayoutId(int type) {
return R.layout.item_download;
}
@ -148,7 +153,7 @@ public class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapte
private String covertCurrentSize(long currentSize) {
String size = CommonUtil.formatFileSize(currentSize);
return size.substring(0, size.length() - 1);
return size.substring(0, size.length() - 2);
}
private int getColor(int color) {

@ -34,7 +34,6 @@ import com.arialyy.simple.databinding.ActivityMultiDownloadBinding;
public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> {
@Bind(R.id.list) RecyclerView mList;
@Bind(R.id.toolbar) Toolbar mBar;
private DownloadAdapter mAdapter;
@Override protected int setLayoutId() {
@ -43,14 +42,10 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setTitle("下载列表");
mAdapter = new DownloadAdapter(this, Aria.download(this).getTaskList());
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);
mBar.setTitle("多任务下载");
}
@Override protected void dataCallback(int result, Object data) {
}
@Override protected void onResume() {

@ -47,9 +47,8 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setSupportActionBar(mBar);
mBar.setTitle("多任务下载");
mData.addAll(getModule(DownloadModule.class).createFileList());
setTitle("多任务下载");
mData.addAll(getModule(DownloadModule.class).createMultiTestList());
mAdapter = new FileListAdapter(this, mData);
mList.setLayoutManager(new LinearLayoutManager(this));
mList.setAdapter(mAdapter);

@ -108,9 +108,8 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
this.handler = new WeakReference<>(handler);
}
@Override public void onPre(String url) {
super.onPre(url);
L.e(TAG, "url ==> " + url);
@Override public void onPre(UploadTask task) {
super.onPre(task);
}
@Override public void onTaskPre(UploadTask task) {

@ -35,12 +35,18 @@
android:layout_below="@+id/name"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/task"
android:background="@android:color/darker_gray"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_below="@+id/task"
android:layout_margin="16dp"
/>
</RelativeLayout>

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="title"
type="java.lang.String"
/>
<variable
name="msg"
type="java.lang.String"
/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color"
android:gravity="center|left"
android:maxHeight="400dp"
android:padding="8dp"
android:text="@{title}"
android:textColor="@android:color/black"
android:textSize="22sp"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="400dp"
>
<TextView
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:gravity="center_vertical|left"
android:lineSpacingMultiplier="1.2"
android:text="@{msg}"
android:textColor="#000"
android:textSize="16sp"
/>
</ScrollView>
<Button
android:id="@+id/enter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="确定"
style="?buttonBarButtonStyle"
/>
</LinearLayout>
</layout>

@ -2,7 +2,10 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
>
<RelativeLayout
@ -45,8 +48,8 @@
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/progressBar"
android:layout_alignTop="@+id/fileSize"
android:layout_centerHorizontal="true"
android:text="0kb/s"
android:textColor="@color/black"
/>
@ -55,8 +58,9 @@
android:id="@+id/del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/progressBar"
android:layout_alignTop="@+id/fileSize"
android:layout_marginLeft="18dp"
android:layout_toRightOf="@+id/progressBar"
android:text="删除"
android:textColor="@color/bt_selector_cancel"
/>
@ -67,7 +71,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bar"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:text="name"
/>
@ -76,7 +80,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:maxLines="2"
/>
<TextView
@ -84,7 +90,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/download_url"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
/>
</RelativeLayout>

@ -0,0 +1,21 @@
<?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/add_task"
android:icon="@mipmap/ic_add_black_48dp"
android:orderInCategory="80"
android:title="添加一组任务"
app:showAsAction="ifRoom"
/>
<item
android:id="@+id/help"
android:icon="@mipmap/ic_help_black_48dp"
android:orderInCategory="90"
android:title="最高优先级任务介绍"
app:showAsAction="ifRoom"
/>
</menu>

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

@ -32,4 +32,16 @@
<item>http://rs.0.gaoshouyou.com/d/e7/3d/73e716d3353de5b479fcf7da8d36a5ef.apk</item>
</string-array>
<string-array name="highest_names">
<item>豪门足球风云</item>
<item>碧蓝航线</item>
<item>天龙八部手游</item>
</string-array>
<string-array name="highest_urls">
<item>https://res5.d.cn/6f78ee3bcfdd033e0193c05c74acd280a32d5c1d8da7a68963da81a1403751e88e8f115ea475566c54456b74d82098c836577f54711a35bbb149e0bd88dc15c48845327fae8652cc.apk</item>
<item>https://res5.d.cn/6f78ee3bcfdd033e1861859eaef45235b089f60f2e08c0e0e4fc8959d94de1e358a5149b4bec8519eabc62a53eebea280a05ef2d902d3153ae1dec4cb07b505e90a9f50af7dd14c4.apk</item>
<item>https://res5.d.cn/6f78ee3bcfdd033ef8e38596afb298d87de07e5f0f1f91f22acd57750f8ae68270531e2b266ea41c86cd196da839a0afef1952dde89773c7e26b9019249503174ca0513fa0a36a6472c4202bbf94da382964a0478471b753ebd95b67aac7ad89.apk</item>
</string-array>
</resources>

Loading…
Cancel
Save