merge v_3.0
This commit is contained in:
@ -25,6 +25,11 @@ android {
|
||||
packagingOptions {
|
||||
exclude 'META-INF/services/javax.annotation.processing.Processor'
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -36,7 +41,8 @@ dependencies {
|
||||
compile 'com.google.code.gson:gson:2.7'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.2.0'
|
||||
compile 'com.arialyy.frame:MVVM2:2.2.0'
|
||||
compile 'com.arialyy.absadapter:AbsAdapter:1.1.2'
|
||||
compile project(':Aria')
|
||||
// compile 'com.arialyy.aria:Aria:3.0.0'
|
||||
// compile 'com.arialyy.aria:aria-core:3.1.7'
|
||||
// annotationProcessor 'com.arialyy.aria:aria-compiler:3.1.7'
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
<!--设置下载线程,线程下载数改变后,新的下载任务才会生效-->
|
||||
<threadNum value="4"/>
|
||||
|
||||
<!--是否打开下载广播,默认为false-->
|
||||
<!--是否打开下载广播,默认为false,不建议使用广播,你可以使用Download注解来实现事件回调-->
|
||||
<openBroadcast value="false"/>
|
||||
|
||||
<!--设置下载队列最大任务数, 默认为2-->
|
||||
@ -37,7 +37,7 @@
|
||||
</download>
|
||||
|
||||
<upload>
|
||||
<!--是否打开上传广播,默认为false-->
|
||||
<!--是否打开上传广播,默认为false,不建议使用广播,你可以使用Upload注解来实现事件回调-->
|
||||
<openBroadcast value="false"/>
|
||||
|
||||
<!--设置上传队列最大任务数, 默认为2-->
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.base.adapter;
|
||||
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2015/12/3.
|
||||
* 通用Holder
|
||||
*/
|
||||
public class AbsHolder extends RecyclerView.ViewHolder {
|
||||
View mView;
|
||||
private SparseArray<View> mViews = new SparseArray<>();
|
||||
|
||||
public AbsHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends View> T getView(@IdRes int id) {
|
||||
View view = mViews.get(id);
|
||||
if (view == null) {
|
||||
view = mView.findViewById(id);
|
||||
mViews.put(id, view);
|
||||
}
|
||||
return (T) view;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.base.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by lyy on 2015/12/3.
|
||||
* RecyclerView 通用Adapter
|
||||
*/
|
||||
public abstract class AbsRVAdapter<T, Holder extends AbsHolder>
|
||||
extends RecyclerView.Adapter<Holder> {
|
||||
protected String TAG;
|
||||
protected List<T> mData = new ArrayList<>();
|
||||
protected Context mContext;
|
||||
Holder holder;
|
||||
|
||||
public AbsRVAdapter(Context context, List<T> data) {
|
||||
mData = data;
|
||||
mContext = context;
|
||||
String arrays[] = getClass().getName().split("\\.");
|
||||
TAG = arrays[arrays.length - 1];
|
||||
}
|
||||
|
||||
@Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view =
|
||||
LayoutInflater.from(parent.getContext()).inflate(setLayoutId(viewType), parent, false);
|
||||
holder = getViewHolder(view, viewType);
|
||||
return holder;
|
||||
}
|
||||
|
||||
protected abstract Holder getViewHolder(View convertView, int viewType);
|
||||
|
||||
@Override public void onBindViewHolder(Holder holder, int position) {
|
||||
bindData(holder, position, mData.get(position));
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
@Override public int getItemCount() {
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* item 的type
|
||||
*/
|
||||
protected abstract int setLayoutId(int type);
|
||||
|
||||
protected abstract void bindData(Holder holder, int position, T item);
|
||||
}
|
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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.base.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
/*
|
||||
* RecyclerView item 事件监听帮助类
|
||||
* RvItemClickSupport.addTo(recyclerView).setOnItemClickListener(new RvItemClickSupport.OnItemClickListener() {
|
||||
*
|
||||
* @Override
|
||||
* public void onItemClicked(RecyclerView recyclerView, int position, View v) {
|
||||
* //处理你的事件
|
||||
* });
|
||||
*/
|
||||
public class RvItemClickSupport {
|
||||
private final RecyclerView mRecyclerView;
|
||||
private OnItemClickListener mOnItemClickListener;
|
||||
private OnItemLongClickListener mOnItemLongClickListener;
|
||||
private OnItemTouchListener mOnItemTouchListener;
|
||||
private OnItemFocusChangeListener mOnItemFocusChangeListener;
|
||||
private OnItemKeyListener mOnItemKeyListener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClicked(RecyclerView recyclerView, int position, View v);
|
||||
}
|
||||
|
||||
public interface OnItemLongClickListener {
|
||||
boolean onItemLongClicked(RecyclerView recyclerView, int position, View v);
|
||||
}
|
||||
|
||||
public interface OnItemTouchListener {
|
||||
public void onTouchEvent(RecyclerView rv, MotionEvent e, int position, View v);
|
||||
}
|
||||
|
||||
public interface OnItemFocusChangeListener {
|
||||
public void onFocusChange(View v, int position, boolean hasFocus);
|
||||
}
|
||||
|
||||
public interface OnItemKeyListener {
|
||||
public boolean onKey(View v, int keyCode, int position, KeyEvent event);
|
||||
}
|
||||
|
||||
private View.OnFocusChangeListener mOnFocusChangeListener = new View.OnFocusChangeListener() {
|
||||
|
||||
@Override public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (mOnItemFocusChangeListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
mOnItemFocusChangeListener.onFocusChange(v, holder.getAdapterPosition(),
|
||||
holder.itemView.hasFocus());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
if (mOnItemClickListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
mOnItemClickListener.onItemClicked(mRecyclerView, holder.getAdapterPosition(), v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnLongClickListener mOnLongClickListener = new View.OnLongClickListener() {
|
||||
@Override public boolean onLongClick(View v) {
|
||||
if (mOnItemLongClickListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
return mOnItemLongClickListener.onItemLongClicked(mRecyclerView,
|
||||
holder.getAdapterPosition(), v);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnTouchListener mOnTouchListener = new View.OnTouchListener() {
|
||||
@Override public boolean onTouch(View v, MotionEvent event) {
|
||||
if (mOnItemTouchListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
mOnItemTouchListener.onTouchEvent(mRecyclerView, event, holder.getAdapterPosition(), v);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnKeyListener mOnKeyListener = new View.OnKeyListener() {
|
||||
@Override public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (mOnItemKeyListener != null) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
return mOnItemKeyListener.onKey(v, keyCode, holder.getAdapterPosition(), event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private RecyclerView.OnChildAttachStateChangeListener mAttachListener =
|
||||
new RecyclerView.OnChildAttachStateChangeListener() {
|
||||
@Override public void onChildViewAttachedToWindow(View view) {
|
||||
if (mOnItemClickListener != null) {
|
||||
view.setOnClickListener(mOnClickListener);
|
||||
}
|
||||
if (mOnItemLongClickListener != null) {
|
||||
view.setOnLongClickListener(mOnLongClickListener);
|
||||
}
|
||||
if (mOnItemTouchListener != null) {
|
||||
view.setOnTouchListener(mOnTouchListener);
|
||||
}
|
||||
if (mOnItemFocusChangeListener != null) {
|
||||
view.setOnFocusChangeListener(mOnFocusChangeListener);
|
||||
}
|
||||
if (mOnItemKeyListener != null) {
|
||||
view.setOnKeyListener(mOnKeyListener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onChildViewDetachedFromWindow(View view) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private RvItemClickSupport(RecyclerView recyclerView) {
|
||||
mRecyclerView = recyclerView;
|
||||
mRecyclerView.setTag(R.id.item_click_support, this);
|
||||
mRecyclerView.addOnChildAttachStateChangeListener(mAttachListener);
|
||||
}
|
||||
|
||||
public static RvItemClickSupport addTo(RecyclerView view) {
|
||||
RvItemClickSupport support = (RvItemClickSupport) view.getTag(R.id.item_click_support);
|
||||
if (support == null) {
|
||||
support = new RvItemClickSupport(view);
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
public static RvItemClickSupport removeFrom(RecyclerView view) {
|
||||
RvItemClickSupport support = (RvItemClickSupport) view.getTag(R.id.item_click_support);
|
||||
if (support != null) {
|
||||
support.detach(view);
|
||||
}
|
||||
return support;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置按键监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemKeyListenr(OnItemKeyListener onItemKeyListener) {
|
||||
mOnItemKeyListener = onItemKeyListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置焦点监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemFocusChangeListener(
|
||||
OnItemFocusChangeListener onItemFocusChangeListener) {
|
||||
mOnItemFocusChangeListener = onItemFocusChangeListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置触摸监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemTouchListener(OnItemTouchListener onItemTouchListener) {
|
||||
mOnItemTouchListener = onItemTouchListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置点击监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemClickListener(OnItemClickListener listener) {
|
||||
mOnItemClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置长按监听
|
||||
*/
|
||||
public RvItemClickSupport setOnItemLongClickListener(OnItemLongClickListener listener) {
|
||||
mOnItemLongClickListener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void detach(RecyclerView view) {
|
||||
view.removeOnChildAttachStateChangeListener(mAttachListener);
|
||||
view.setTag(R.id.item_click_support, null);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@ -61,7 +62,7 @@ public class DownloadDialog extends AbsDialog {
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
@ -89,6 +90,29 @@ public class DownloadDialog extends AbsDialog {
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
setBtState(true);
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(task.getPercent());
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object obj) {
|
||||
|
||||
}
|
||||
@ -98,34 +122,4 @@ public class DownloadDialog extends AbsDialog {
|
||||
mCancel.setEnabled(!startEnable);
|
||||
mStop.setEnabled(!startEnable);
|
||||
}
|
||||
|
||||
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
setBtState(true);
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mPb.setProgress(task.getPercent());
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@ -63,7 +64,7 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
@ -101,37 +102,30 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
mStop.setEnabled(!startEnable);
|
||||
}
|
||||
|
||||
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
setBtState(true);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
setBtState(true);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
setBtState(true);
|
||||
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
||||
mPb.setProgress((int) ((current * 100) / len));
|
||||
}
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
} else {
|
||||
mPb.setProgress((int) ((current * 100) / len));
|
||||
}
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
}
|
||||
|
@ -33,18 +33,21 @@ import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.annotations.Download;
|
||||
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.frame.util.FileUtil;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivitySingleBinding;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
import java.io.File;
|
||||
|
||||
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
public static final int DOWNLOAD_PRE = 0x01;
|
||||
@ -60,7 +63,10 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
//"http://kotlinlang.org/docs/kotlin-docs.pdf";
|
||||
//"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe";
|
||||
"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
|
||||
//"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815";
|
||||
//"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk";
|
||||
//"http://oqcpqqvuf.bkt.clouddn.com/ceshi.txt";
|
||||
//"http://down8.androidgame-store.com/201706122321/97967927DD4E53D9905ECAA7874C8128/new/game1/19/45319/com.neuralprisma-2.5.2.174-2000174_1494784835.apk?f=web_1";
|
||||
//不支持断点的链接
|
||||
//"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||
//"http://172.18.104.50:8080/download/_302turn";
|
||||
@ -71,15 +77,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
@Bind(R.id.size) TextView mSize;
|
||||
@Bind(R.id.speed) TextView mSpeed;
|
||||
@Bind(R.id.speeds) RadioGroup mRg;
|
||||
private DownloadEntity mEntity;
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(Aria.ACTION_START)) {
|
||||
L.d("START");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Handler mUpdateHandler = new Handler() {
|
||||
@Override public void handleMessage(Message msg) {
|
||||
@ -132,6 +129,11 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
};
|
||||
|
||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置start 和 stop 按钮状态
|
||||
*/
|
||||
@ -140,28 +142,105 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
mStop.setEnabled(!state);
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
//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);
|
||||
double speed = -1;
|
||||
String msg = "";
|
||||
switch (item.getItemId()) {
|
||||
case R.id.help:
|
||||
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);
|
||||
break;
|
||||
case R.id.speed_0:
|
||||
speed = 0.0;
|
||||
break;
|
||||
case R.id.speed_128:
|
||||
speed = 128.0;
|
||||
break;
|
||||
case R.id.speed_256:
|
||||
speed = 256.0;
|
||||
break;
|
||||
case R.id.speed_512:
|
||||
speed = 512.0;
|
||||
break;
|
||||
case R.id.speed_1m:
|
||||
speed = 1024.0;
|
||||
break;
|
||||
}
|
||||
if (speed > -1) {
|
||||
msg = item.getTitle().toString();
|
||||
Aria.download(this).setMaxSpeed(speed);
|
||||
T.showShort(this, msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Download.onPre protected void onPre(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
//通过下载地址可以判断任务是否是你指定的任务
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getDownloadEntity().getFileSize())
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskRunning protected void running(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getFileSize()).sendToTarget();
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
|
||||
L.d(TAG, "task__stop");
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
|
||||
L.d(TAG, "task__cancel");
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
if (task.getKey().equals(DOWNLOAD_URL)) {
|
||||
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_single;
|
||||
}
|
||||
@ -203,6 +282,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@ -263,4 +343,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
}
|
||||
}
|
||||
=======
|
||||
>>>>>>> v_3.0
|
||||
}
|
@ -23,6 +23,7 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
@ -61,11 +62,7 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
} else {
|
||||
setBtState(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onResume() {
|
||||
super.onResume();
|
||||
Aria.download(this).addSchedulerListener(new DownloadFragment.MyDialogDownloadCallback());
|
||||
Aria.download(this).register();
|
||||
}
|
||||
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
@ -85,6 +82,33 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
setBtState(true);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
||||
mPb.setProgress((int) ((current * 100) / len));
|
||||
}
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
|
||||
@Override protected void onDelayLoad() {
|
||||
|
||||
}
|
||||
@ -102,38 +126,4 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
mCancel.setEnabled(!startEnable);
|
||||
mStop.setEnabled(!startEnable);
|
||||
}
|
||||
|
||||
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
setBtState(true);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
||||
mPb.setProgress((int) ((current * 100) / len));
|
||||
}
|
||||
mSpeed.setText(task.getConvertSpeed());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.absadapter.common.AbsHolder;
|
||||
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.adapter.AbsHolder;
|
||||
import com.arialyy.simple.base.adapter.AbsRVAdapter;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -22,10 +22,10 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.absadapter.common.AbsHolder;
|
||||
import com.arialyy.absadapter.recycler_view.AbsRVAdapter;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.adapter.AbsHolder;
|
||||
import com.arialyy.simple.base.adapter.AbsRVAdapter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -21,6 +21,7 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
@ -46,6 +47,7 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
setTitle("下载列表");
|
||||
List<DownloadEntity> temps = Aria.download(this).getTaskList();
|
||||
if (temps != null && !temps.isEmpty()) {
|
||||
@ -56,53 +58,38 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
@Download.onPre void onPre(DownloadTask task) {
|
||||
L.d(TAG, "download onPre");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
L.d(TAG, "download onPre");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
L.d(TAG, "download start");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
super.onTaskStart(task);
|
||||
L.d(TAG, "download start");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
L.d(TAG, "download resume");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
super.onTaskResume(task);
|
||||
L.d(TAG, "download resume");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
L.d(TAG, "download fail");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(DownloadTask task) {
|
||||
super.onTaskComplete(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskFail(DownloadTask task) {
|
||||
super.onTaskFail(task);
|
||||
L.d(TAG, "download fail");
|
||||
}
|
||||
@Download.onTaskRunning void taskRunning(DownloadTask task) {
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,15 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
||||
import com.arialyy.simple.download.DownloadModule;
|
||||
import com.arialyy.simple.download.SingleTaskActivity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -47,6 +50,7 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
setTitle("多任务下载");
|
||||
mData.addAll(getModule(DownloadModule.class).createMultiTestList());
|
||||
mAdapter = new FileListAdapter(this, mData);
|
||||
@ -69,14 +73,28 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.download(this).addSchedulerListener(new DownloadListener());
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//unregisterReceiver(mReceiver);
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), false);
|
||||
}
|
||||
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
mAdapter.updateBtState(task.getKey(), true);
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
@ -85,31 +103,4 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(Integer.parseInt(data + ""));
|
||||
}
|
||||
}
|
||||
|
||||
private class DownloadListener extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
super.onTaskStart(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), false);
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
super.onTaskResume(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), false);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), true);
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(DownloadTask task) {
|
||||
super.onTaskComplete(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), true);
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import android.content.Intent;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
@ -45,7 +46,7 @@ public class DownloadService extends Service {
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
mNotify = new DownloadNotification(getApplicationContext());
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
Aria.download(this).register();
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk")
|
||||
@ -54,45 +55,37 @@ public class DownloadService extends Service {
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).removeSchedulerListener();
|
||||
Aria.download(this).unRegister();
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
@Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), "该下载链接不支持断点");
|
||||
}
|
||||
|
||||
@Override public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
super.onNoSupportBreakPoint(task);
|
||||
T.showShort(getApplicationContext(), "该下载链接不支持断点");
|
||||
}
|
||||
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载");
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载");
|
||||
}
|
||||
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载");
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
super.onTaskResume(task);
|
||||
}
|
||||
@Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载");
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载");
|
||||
}
|
||||
@Download.onTaskFail public void onTaskFail(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载");
|
||||
}
|
||||
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成");
|
||||
mNotify.upload(100);
|
||||
}
|
||||
|
||||
@Override public void onTaskFail(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载失败");
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",下载完成");
|
||||
mNotify.upload(100);
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
long len = task.getFileSize();
|
||||
int p = (int) (task.getCurrentProgress() * 100 / len);
|
||||
mNotify.upload(p);
|
||||
}
|
||||
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
long len = task.getFileSize();
|
||||
int p = (int) (task.getCurrentProgress() * 100 / len);
|
||||
mNotify.upload(p);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.annotations.Upload;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.frame.util.FileUtil;
|
||||
@ -78,6 +79,7 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.upload(this).register();
|
||||
}
|
||||
|
||||
@OnClick(R.id.upload) void upload() {
|
||||
@ -96,50 +98,30 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
|
||||
Aria.upload(this).load(FILE_PATH).cancel();
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.upload(this).addSchedulerListener(new UploadListener(mHandler));
|
||||
@Upload.onPre public void onPre(UploadTask task) {
|
||||
}
|
||||
|
||||
static class UploadListener extends Aria.UploadSchedulerListener {
|
||||
WeakReference<Handler> handler;
|
||||
@Upload.onTaskPre public void taskPre(UploadTask task) {
|
||||
L.d(TAG, "fileSize = " + task.getConvertFileSize());
|
||||
}
|
||||
|
||||
UploadListener(Handler handler) {
|
||||
this.handler = new WeakReference<>(handler);
|
||||
}
|
||||
@Upload.onTaskStart public void taskStart(UploadTask task) {
|
||||
mHandler.obtainMessage(START, task).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onPre(UploadTask task) {
|
||||
super.onPre(task);
|
||||
}
|
||||
@Upload.onTaskStop public void taskStop(UploadTask task) {
|
||||
mHandler.obtainMessage(STOP, task).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskPre(UploadTask task) {
|
||||
super.onTaskPre(task);
|
||||
L.d(TAG, "fileSize = " + task.getConvertFileSize());
|
||||
}
|
||||
@Upload.onTaskCancel public void taskCancel(UploadTask task) {
|
||||
mHandler.obtainMessage(CANCEL, task).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(UploadTask task) {
|
||||
super.onTaskStart(task);
|
||||
handler.get().obtainMessage(START, task).sendToTarget();
|
||||
}
|
||||
@Upload.onTaskRunning public void taskRunning(UploadTask task) {
|
||||
mHandler.obtainMessage(RUNNING, task).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(UploadTask task) {
|
||||
super.onTaskStop(task);
|
||||
handler.get().obtainMessage(STOP, task).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(UploadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
handler.get().obtainMessage(CANCEL, task).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(UploadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
handler.get().obtainMessage(RUNNING, task).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(UploadTask task) {
|
||||
super.onTaskComplete(task);
|
||||
handler.get().obtainMessage(COMPLETE, task).sendToTarget();
|
||||
}
|
||||
@Upload.onTaskComplete public void taskComplete(UploadTask task) {
|
||||
mHandler.obtainMessage(COMPLETE, task).sendToTarget();
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,26 @@
|
||||
android:title="tip"
|
||||
app:showAsAction="ifRoom"
|
||||
/>
|
||||
<item
|
||||
android:id="@+id/speed_0"
|
||||
android:title="不限速"
|
||||
/>
|
||||
<item
|
||||
android:id="@+id/speed_128"
|
||||
android:title="最大速度(128kb)"
|
||||
/>
|
||||
<item
|
||||
android:id="@+id/speed_256"
|
||||
android:title="最大速度(256kb)"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/speed_512"
|
||||
android:title="最大速度(512kb)"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/speed_1m"
|
||||
android:title="最大速度(1mb)"
|
||||
/>
|
||||
</menu>
|
19
app/src/main/res/values/ids.xml
Normal file
19
app/src/main/res/values/ids.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright (C) 2014 Lucas Rocha
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<item name="item_click_support" type="id" />
|
||||
</resources>
|
Reference in New Issue
Block a user