子任务管理器
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.simple.download.group;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseDialog;
|
||||
import com.arialyy.simple.databinding.DialogSubTaskHandlerBinding;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/9/5.
|
||||
*/
|
||||
@SuppressLint("ValidFragment") public class ChildHandleDialog
|
||||
extends BaseDialog<DialogSubTaskHandlerBinding> {
|
||||
@Bind(R.id.sub_task) TextView mSub;
|
||||
@Bind(R.id.task_group) TextView mGroup;
|
||||
@Bind(R.id.pb) HorizontalProgressBarWithNumber mPb;
|
||||
private String mGroupName;
|
||||
private String mChildName;
|
||||
private DownloadEntity mChildEntity;
|
||||
|
||||
public ChildHandleDialog(Context context, String groupAliaName, DownloadEntity childEntity) {
|
||||
super(context);
|
||||
setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog);
|
||||
mChildEntity = childEntity;
|
||||
mGroupName = groupAliaName;
|
||||
mChildName = childEntity.getFileName();
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
initWidget();
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).unRegister();
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
mGroup.setText("任务组:" + mGroupName);
|
||||
mSub.setText("子任务:" + mChildName);
|
||||
mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize()));
|
||||
|
||||
Window window = getDialog().getWindow();
|
||||
window.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
|
||||
WindowManager.LayoutParams p = window.getAttributes();
|
||||
p.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
window.setAttributes(p);
|
||||
window.setWindowAnimations(R.style.dialogStyle);
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskResume void onTaskResume(DownloadGroupTask task) {
|
||||
mSub.setText("子任务:" + mChildName + ",状态:下载中");
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskCancel void onTaskCancel(DownloadGroupTask task) {
|
||||
mSub.setText("子任务:" + mChildName + ",状态:取消下载");
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskRunning void onTaskRunning(DownloadGroupTask task) {
|
||||
mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize()));
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskStop void onTaskStop(DownloadGroupTask task) {
|
||||
mSub.setText("子任务:" + mChildName + ",状态:任务停止");
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskComplete void onTaskComplete(DownloadGroupTask task) {
|
||||
mSub.setText("子任务:" + mChildName + ",状态:任务完成");
|
||||
mPb.setProgress(100);
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.dialog_sub_task_handler;
|
||||
}
|
||||
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
break;
|
||||
case R.id.stop:
|
||||
break;
|
||||
case R.id.cancel:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object obj) {
|
||||
|
||||
}
|
||||
}
|
@@ -17,17 +17,15 @@ package com.arialyy.simple.download.group;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.annotations.DownloadGroup;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DownloadGroupEntity;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTask;
|
||||
import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
|
||||
import com.arialyy.frame.util.AndroidUtils;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.simple.R;
|
||||
@@ -62,6 +60,18 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
: (int) (groupEntity.getCurrentProgress() * 100 / groupEntity.getFileSize()));
|
||||
}
|
||||
}
|
||||
|
||||
mChildList.setOnItemClickListener(new SubStateLinearLayout.OnItemClickListener() {
|
||||
@Override public void onItemClick(int position, View view) {
|
||||
showPopupWindow(position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showPopupWindow(int position) {
|
||||
ChildHandleDialog dialog =
|
||||
new ChildHandleDialog(this, "任务组测试", mChildList.getSubData().get(position));
|
||||
dialog.show(getSupportFragmentManager(), "sub_dialog");
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
@@ -77,7 +87,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
Environment.getExternalStorageDirectory().getPath() + "/Download/group_test_3")
|
||||
.setGroupAlias("任务组测试")
|
||||
.setSubFileName(getModule(GroupModule.class).getSubName())
|
||||
.setFileSize(32895492)
|
||||
//.setFileSize(32895492)
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
@@ -99,7 +109,7 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
}
|
||||
L.d(TAG, "group task pre");
|
||||
getBinding().setFileSize(task.getConvertFileSize());
|
||||
if (mChildList.getSubData().size() <= 0){
|
||||
if (mChildList.getSubData().size() <= 0) {
|
||||
mChildList.addData(task.getEntity().getSubTask());
|
||||
}
|
||||
}
|
||||
@@ -109,7 +119,6 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
|
||||
}
|
||||
|
||||
@DownloadGroup.onTaskRunning() protected void running(DownloadGroupTask task) {
|
||||
L.d(TAG, "P ==> " + task.getPercent());
|
||||
getBinding().setProgress(task.getPercent());
|
||||
getBinding().setSpeed(task.getConvertSpeed());
|
||||
mChildList.updateChildProgress(task.getEntity().getSubTask());
|
||||
|
@@ -1,8 +1,24 @@
|
||||
/*
|
||||
* 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.simple.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -17,16 +33,22 @@ import java.util.WeakHashMap;
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/7/17.
|
||||
*/
|
||||
public class SubStateLinearLayout extends LinearLayout {
|
||||
public class SubStateLinearLayout extends LinearLayout implements View.OnClickListener {
|
||||
|
||||
interface OnShowCallback {
|
||||
void onShow(boolean visibility);
|
||||
}
|
||||
|
||||
OnShowCallback callback;
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(int position, View view);
|
||||
}
|
||||
|
||||
OnShowCallback mShowCallback;
|
||||
OnItemClickListener mItemClickListener;
|
||||
|
||||
List<DownloadEntity> mSubData = new LinkedList<>();
|
||||
Map<String, Integer> mPosition = new WeakHashMap<>();
|
||||
SparseArray<View> mViews = new SparseArray<>();
|
||||
|
||||
public SubStateLinearLayout(Context context) {
|
||||
super(context);
|
||||
@@ -50,15 +72,25 @@ public class SubStateLinearLayout extends LinearLayout {
|
||||
createShowView();
|
||||
int i = 1;
|
||||
for (DownloadEntity entity : datas) {
|
||||
TextView view = createView(entity);
|
||||
TextView view = createView(i - 1, entity);
|
||||
mPosition.put(entity.getDownloadPath(), i);
|
||||
addView(view, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onClick(View v) {
|
||||
if (mItemClickListener != null) {
|
||||
mItemClickListener.onItemClick(mViews.indexOfValue(v), v);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnShowCallback(OnShowCallback callback) {
|
||||
this.callback = callback;
|
||||
this.mShowCallback = callback;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.mItemClickListener = listener;
|
||||
}
|
||||
|
||||
public List<DownloadEntity> getSubData() {
|
||||
@@ -79,10 +111,12 @@ public class SubStateLinearLayout extends LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private TextView createView(DownloadEntity entity) {
|
||||
private TextView createView(int position, DownloadEntity entity) {
|
||||
TextView view =
|
||||
(TextView) LayoutInflater.from(getContext()).inflate(R.layout.layout_child_state, null);
|
||||
view.setText(entity.getFileName() + ": " + getPercent(entity) + "%");
|
||||
view.setOnClickListener(this);
|
||||
mViews.append(position, view);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
5
app/src/main/res/anim/dialog_enter.xml
Normal file
5
app/src/main/res/anim/dialog_enter.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromYDelta="100%"
|
||||
android:duration="100"/>
|
||||
</set>
|
6
app/src/main/res/anim/dialog_exit.xml
Normal file
6
app/src/main/res/anim/dialog_exit.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate
|
||||
android:duration="100"
|
||||
android:toYDelta="100%"/>
|
||||
</set>
|
@@ -17,7 +17,7 @@
|
||||
/>
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
@@ -27,18 +27,24 @@
|
||||
|
||||
<include
|
||||
layout="@layout/content_single"
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/toolbar"
|
||||
bind:fileSize="@{fileSize}"
|
||||
bind:progress="@{progress}"
|
||||
bind:speed="@{speed}"
|
||||
/>
|
||||
|
||||
<com.arialyy.simple.widget.SubStateLinearLayout
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:id="@+id/child_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_above="@+id/temp"
|
||||
android:layout_below="@+id/content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</layout>
|
||||
|
76
app/src/main/res/layout/dialog_sub_task_handler.xml
Normal file
76
app/src/main/res/layout/dialog_sub_task_handler.xml
Normal file
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
android:padding="16dp"
|
||||
>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="任务组:"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sub_task"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/task_group"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="子任务:"
|
||||
/>
|
||||
|
||||
<com.arialyy.simple.widget.HorizontalProgressBarWithNumber
|
||||
android:id="@+id/pb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/sub_task"
|
||||
android:layout_marginTop="10dp"
|
||||
android:max="100"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/pb"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<Button
|
||||
android:id="@+id/start"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="开始"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/stop"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="停止"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="删除"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</layout>
|
@@ -10,13 +10,13 @@
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
<Button
|
||||
android:onClick="onClick"
|
||||
android:id="@+id/download"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="多任务同时下载"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
android:onClick="onClick"
|
||||
android:id="@+id/download"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="多任务同时下载"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
@@ -49,7 +49,7 @@
|
||||
<string-array name="group_urls">
|
||||
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a65d84b914e6a6fef697637578b6db2eb1056d50b09cf1dcf289d4045df7ef95746e498e3d6a848ab84c89b77aa60194e2c48e5a7cb748265.apk</item>-->
|
||||
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a52034c72752e8475414630ebc69318b84ef584115ebf5eaaab945ae07b7fe3596afc72a7940ff328d4a9553f6ae92d6c09ba4bfb533137f6.apk</item>-->
|
||||
<!--<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>-->
|
||||
<item>https://res5.d.cn/5a6a3384c1b2be1a426f06bfc69034d69c44ae1a01da180cab8e59bd1a5e1a784bac46ba0c64579d14f0e80a4ce4f068af89b0369a393456f4f449a8829cad5c.apk</item>
|
||||
<item>http://static.gaoshouyou.com/d/12/0d/7f120f50c80d2e7b8c4ba24ece4f9cdd.apk</item>
|
||||
<item>http://static.ilongyuan.cn/rayark/RayarkFZ_2.0.7.apk</item>
|
||||
</string-array>
|
||||
@@ -72,7 +72,7 @@
|
||||
<string-array name="group_names">
|
||||
<item>王者荣耀.apk</item>
|
||||
<item>战斗吧剑灵.apk</item>
|
||||
<!--<item>天魔幻想.apk</item>-->
|
||||
<item>天魔幻想.apk</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="group_names_1">
|
||||
|
@@ -22,4 +22,21 @@
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
||||
|
||||
<style name="dialogStyle" parent="@android:style/Animation.Dialog">
|
||||
<item name="@android:windowEnterAnimation">@anim/dialog_enter</item>
|
||||
<!-- 进入时的动画 -->
|
||||
<item name="@android:windowExitAnimation">@anim/dialog_exit</item>
|
||||
<!-- 退出时的动画 -->
|
||||
</style>
|
||||
|
||||
<!-- 对话框样式 -->
|
||||
<style name="Theme.Light.Dialog" parent="android:style/Theme.Dialog">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:scrollHorizontally">true</item>
|
||||
</style>
|
||||
|
||||
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user