任意类使用aria
This commit is contained in:
@@ -57,8 +57,8 @@ public class DownloadDialog extends AbsDialog {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int p = (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
|
||||
@@ -73,16 +73,16 @@ public class DownloadDialog extends AbsDialog {
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/飞机大战.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import com.arialyy.simple.databinding.DialogFragmentDownloadBinding;
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
getBinding().setProgress((int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
|
||||
@@ -45,7 +45,7 @@ import com.arialyy.simple.databinding.DialogFragmentDownloadBinding;
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).unRegister();
|
||||
Aria.download(getContext()).unRegister();
|
||||
}
|
||||
|
||||
@Download.onPre(DOWNLOAD_URL) protected void onPre(DownloadTask task) {
|
||||
@@ -96,16 +96,16 @@ import com.arialyy.simple.databinding.DialogFragmentDownloadBinding;
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/放置江湖.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,13 +59,13 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
if (Aria.download(getContext()).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(getContext()).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
@@ -78,16 +78,16 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/消消乐.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
private static final String DOWNLOAD_URL = "https://res5.d.cn/2137e42d610b3488d9420c6421529386eee5bdbfd9be1fafe0a05d6dabaec8c156ddbd00581055bbaeac03904fb63310e80010680235d16bd4c040b50096a0c20dd1c4b0854529a1.apk";
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
if (Aria.download(getContext()).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(getContext()).load(DOWNLOAD_URL);
|
||||
getBinding().setProgress(target.getPercent());
|
||||
}
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
@@ -57,22 +57,22 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
} else {
|
||||
setBtState(true);
|
||||
}
|
||||
Aria.download(this).register();
|
||||
Aria.download(getContext()).register();
|
||||
}
|
||||
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this)
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/王者军团.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ import java.util.List;
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
Aria.download(this).register();
|
||||
Aria.download(getContext()).register();
|
||||
initWidget();
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).unRegister();
|
||||
Aria.download(getContext()).unRegister();
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
@@ -134,10 +134,10 @@ import java.util.List;
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(this).load(mUrls).getSubTaskManager().startSubTask(mChildEntity.getUrl());
|
||||
Aria.download(getContext()).load(mUrls).getSubTaskManager().startSubTask(mChildEntity.getUrl());
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(mUrls).getSubTaskManager().stopSubTask(mChildEntity.getUrl());
|
||||
Aria.download(getContext()).load(mUrls).getSubTaskManager().stopSubTask(mChildEntity.getUrl());
|
||||
break;
|
||||
//case R.id.cancel:
|
||||
// Aria.download(this).load(mUrls).getSubTaskManager().cancelSubTask(mChildEntity.getUrl());
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.arialyy.simple.test;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityTestBinding;
|
||||
|
||||
/**
|
||||
* Created by laoyuyu on 2018/4/13.
|
||||
*/
|
||||
|
||||
public class AnyRunActivity extends BaseActivity<ActivityTestBinding> {
|
||||
AnyRunnModule module;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_test;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mBar.setVisibility(View.GONE);
|
||||
module = new AnyRunnModule(this);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
module.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
module.stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
module.cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
module.unRegist();
|
||||
}
|
||||
}
|
||||
86
app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java
Normal file
86
app/src/main/java/com/arialyy/simple/test/AnyRunnModule.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.arialyy.simple.test;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.common.RequestEnum;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by laoyuyu on 2018/4/13.
|
||||
*/
|
||||
|
||||
public class AnyRunnModule {
|
||||
String TAG = "TestActivity";
|
||||
String URL = "http://58.210.9.131/tpk/sipgt//TDLYZTGH.tpk"; //chunked 下载
|
||||
private Context mContext;
|
||||
|
||||
public AnyRunnModule(Context context) {
|
||||
Aria.download(context, this).register();
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Download.onWait void onWait(DownloadTask task) {
|
||||
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
|
||||
}
|
||||
|
||||
@Download.onPre protected void onPre(DownloadTask task) {
|
||||
Log.d(TAG, "onPre");
|
||||
}
|
||||
|
||||
@Download.onTaskStart void taskStart(DownloadTask task) {
|
||||
Log.d(TAG, "onStart");
|
||||
}
|
||||
|
||||
@Download.onTaskRunning protected void running(DownloadTask task) {
|
||||
Log.d(TAG, "running");
|
||||
}
|
||||
|
||||
@Download.onTaskResume void taskResume(DownloadTask task) {
|
||||
Log.d(TAG, "resume");
|
||||
}
|
||||
|
||||
@Download.onTaskStop void taskStop(DownloadTask task) {
|
||||
Log.d(TAG, "stop");
|
||||
}
|
||||
|
||||
@Download.onTaskCancel void taskCancel(DownloadTask task) {
|
||||
Log.d(TAG, "cancel");
|
||||
}
|
||||
|
||||
@Download.onTaskFail void taskFail(DownloadTask task) {
|
||||
Log.d(TAG, "fail");
|
||||
}
|
||||
|
||||
@Download.onTaskComplete void taskComplete(DownloadTask task) {
|
||||
L.d(TAG, "path ==> " + task.getDownloadEntity().getDownloadPath());
|
||||
L.d(TAG, "md5Code ==> " + CommonUtil.getFileMD5(new File(task.getDownloadPath())));
|
||||
}
|
||||
|
||||
void start() {
|
||||
Aria.download(mContext, this)
|
||||
.load(URL)
|
||||
.addHeader("Accept-Encoding", "gzip, deflate")
|
||||
.setRequestMode(RequestEnum.GET)
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/ggsg1.apk")
|
||||
.resetState()
|
||||
.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
Aria.download(mContext, this).load(URL).stop();
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
Aria.download(mContext, this).load(URL).cancel();
|
||||
}
|
||||
|
||||
void unRegist() {
|
||||
Aria.download(mContext, this).unRegister();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user