parent
1e5f01cbd8
commit
618db821ed
@ -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(); |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
Loading…
Reference in new issue