pull/4/head
AriaLyy 8 years ago
parent 9c428bcdb8
commit 0887cc8a4c
  1. 8
      Aria/src/main/java/com/arialyy/aria/core/Aria.java
  2. 11
      app/src/main/java/com/arialyy/simple/activity/MainActivity.java
  3. 88
      app/src/main/java/com/arialyy/simple/dialog/DownloadDialog.java
  4. 11
      app/src/main/res/layout/activity_main.xml

@ -148,6 +148,14 @@ import com.arialyy.aria.core.task.Task;
}
}
/**
* 处理Dialog的通用任务
*/
public static AMReceiver get(Dialog dialog) {
checkNull(dialog);
return AriaManager.getInstance(dialog.getContext()).get(dialog);
}
public static class SimpleSchedulerListener implements OnSchedulerListener {
@Override public void onTaskPre(Task task) {

@ -30,14 +30,15 @@ import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMainBinding;
import com.arialyy.simple.dialog.DownloadDialog;
/**
* Created by Lyy on 2016/10/13.
*/
public class MainActivity extends BaseActivity<ActivityMainBinding> {
@Bind(R.id.toolbar) Toolbar mBar;
@Bind(R.id.single_task) Button mSigleBt;
@Bind(R.id.multi_task) Button mMultiBt;
@Bind(R.id.toolbar) Toolbar mBar;
@Bind(R.id.single_task) Button mSigleBt;
@Bind(R.id.multi_task) Button mMultiBt;
@Override protected int setLayoutId() {
return R.layout.activity_main;
@ -83,6 +84,10 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
case R.id.multi_task:
startActivity(new Intent(this, MultiTaskActivity.class));
break;
case R.id.dialog_task:
DownloadDialog dialog = new DownloadDialog(this);
dialog.show();
break;
}
}
}

@ -0,0 +1,88 @@
package com.arialyy.simple.dialog;
import android.content.Context;
import android.os.Environment;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;
import com.arialyy.aria.core.AMTarget;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.task.Task;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.core.AbsDialog;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseDialog;
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
/**
* Created by AriaL on 2017/1/2.
*/
public class DownloadDialog extends AbsDialog {
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber mPb;
@Bind(R.id.start) Button mStart;
@Bind(R.id.stop) Button mStop;
@Bind(R.id.cancel) Button mCancel;
@Bind(R.id.size) TextView mSize;
@Bind(R.id.speed) TextView mSpeed;
private static final String DOWNLOAD_URL =
"http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk";
public DownloadDialog(Context context) {
super(context);
init();
}
@Override protected int setLayoutId() {
return R.layout.content_single;
}
private void init() {
if (Aria.get(getContext()).taskExists(DOWNLOAD_URL)) {
AMTarget target = Aria.whit(getContext()).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p);
}
Aria.whit(this).addSchedulerListener(new MyDialogDownloadCallback());
}
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
Aria.whit(getContext())
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
.setDownloadName("daialog.apk")
.start();
break;
case R.id.stop:
Aria.whit(getContext()).load(DOWNLOAD_URL).stop();
break;
case R.id.cancel:
Aria.whit(getContext()).load(DOWNLOAD_URL).cancel();
break;
}
}
@Override protected void dataCallback(int result, Object obj) {
}
private class MyDialogDownloadCallback extends Aria.SimpleSchedulerListener {
@Override public void onTaskRunning(Task 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(CommonUtil.formatFileSize(task.getSpeed()) + "/s");
}
}
}

@ -3,9 +3,9 @@
>
<LinearLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
>
@ -29,5 +29,14 @@
style="?buttonBarButtonStyle"
/>
<Button
android:id="@+id/dialog_task"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="在dialog中使用"
style="?buttonBarButtonStyle"
/>
</LinearLayout>
</layout>

Loading…
Cancel
Save