合并 v_3.0代码
This commit is contained in:
@ -13,7 +13,6 @@
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<!--android:name=".activity.SingleTaskActivity"-->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
@ -24,10 +23,14 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".single_task.SingleTaskActivity"/>
|
||||
<activity android:name=".multi_task.MultiTaskActivity"/>
|
||||
<activity android:name=".fragment_task.FragmentActivity"/>
|
||||
<activity android:name=".multi_task.DownloadActivity"/>
|
||||
<activity android:name=".download.DownloadActivity"/>
|
||||
<activity android:name=".upload.UploadActivity"/>
|
||||
<activity android:name=".download.SingleTaskActivity"/>
|
||||
<activity android:name=".download.multi_download.MultiTaskActivity"/>
|
||||
<activity android:name=".download.fragment_download.FragmentActivity"/>
|
||||
<activity android:name=".download.multi_download.MultiDownloadActivity"/>
|
||||
|
||||
<service android:name=".download.service_download.DownloadService"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -16,99 +16,38 @@
|
||||
|
||||
package com.arialyy.simple;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.frame.permission.OnPermissionCallback;
|
||||
import com.arialyy.frame.permission.PermissionManager;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMainBinding;
|
||||
import com.arialyy.simple.dialog_task.DownloadDialog;
|
||||
import com.arialyy.simple.fragment_task.FragmentActivity;
|
||||
import com.arialyy.simple.multi_task.MultiTaskActivity;
|
||||
import com.arialyy.simple.notification.SimpleNotification;
|
||||
import com.arialyy.simple.pop_task.DownloadPopupWindow;
|
||||
import com.arialyy.simple.single_task.SingleTaskActivity;
|
||||
import com.arialyy.simple.download.DownloadActivity;
|
||||
import com.arialyy.simple.upload.UploadActivity;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/10/13.
|
||||
* Created by Aria.Lao on 2017/3/1.
|
||||
*/
|
||||
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.dialog_task) Button mDialogBt;
|
||||
@Bind(R.id.pop_task) Button mPopBt;
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mBar.setTitle("Aria Demo");
|
||||
}
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多线程多任务下载");
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
setEnable(true);
|
||||
} else { //6.0处理
|
||||
boolean hasPermission = PermissionManager.getInstance()
|
||||
.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (hasPermission) {
|
||||
setEnable(true);
|
||||
} else {
|
||||
setEnable(false);
|
||||
PermissionManager.getInstance().requestPermission(this, new OnPermissionCallback() {
|
||||
@Override public void onSuccess(String... permissions) {
|
||||
setEnable(true);
|
||||
}
|
||||
|
||||
@Override public void onFail(String... permissions) {
|
||||
T.showShort(MainActivity.this, "没有文件读写权限");
|
||||
setEnable(false);
|
||||
}
|
||||
}, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
}
|
||||
@OnClick(R.id.download) public void downloadDemo() {
|
||||
startActivity(new Intent(this, DownloadActivity.class));
|
||||
}
|
||||
|
||||
private void setEnable(boolean enable) {
|
||||
mSigleBt.setEnabled(enable);
|
||||
mMultiBt.setEnabled(enable);
|
||||
mDialogBt.setEnabled(enable);
|
||||
mPopBt.setEnabled(enable);
|
||||
@OnClick(R.id.upload) public void uploadDemo() {
|
||||
startActivity(new Intent(this, UploadActivity.class));
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.single_task:
|
||||
startActivity(new Intent(this, SingleTaskActivity.class));
|
||||
break;
|
||||
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;
|
||||
case R.id.pop_task:
|
||||
DownloadPopupWindow pop = new DownloadPopupWindow(this);
|
||||
//pop.showAsDropDown(mRootView);
|
||||
pop.showAtLocation(mRootView, Gravity.CENTER_VERTICAL, 0, 0);
|
||||
break;
|
||||
case R.id.fragment_task:
|
||||
startActivity(new Intent(this, FragmentActivity.class));
|
||||
break;
|
||||
case R.id.notification:
|
||||
SimpleNotification notification = new SimpleNotification(this);
|
||||
notification.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.arialyy.simple.base;
|
||||
|
||||
import android.app.Application;
|
||||
import com.arialyy.aria.core.DownloadManager;
|
||||
import com.arialyy.frame.core.AbsFrame;
|
||||
|
||||
/**
|
||||
@ -28,6 +26,5 @@ public class BaseApplication extends Application {
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
AbsFrame.init(this);
|
||||
//DownloadManager.init(this);
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.arialyy.simple.base;
|
||||
|
||||
import android.databinding.ViewDataBinding;
|
||||
@ -24,9 +23,9 @@ import com.arialyy.frame.core.AbsDialogFragment;
|
||||
/**
|
||||
* Created by “AriaLyy@outlook.com” on 2016/11/14.
|
||||
*/
|
||||
public abstract class BaseDialog<VB extends ViewDataBinding> extends AbsDialogFragment<VB>{
|
||||
public abstract class BaseDialog<VB extends ViewDataBinding> extends AbsDialogFragment<VB> {
|
||||
|
||||
protected BaseDialog(Object obj){
|
||||
protected BaseDialog(Object obj) {
|
||||
super(obj);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.arialyy.simple.base;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.frame.permission.OnPermissionCallback;
|
||||
import com.arialyy.frame.permission.PermissionManager;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityDownloadMeanBinding;
|
||||
import com.arialyy.simple.download.fragment_download.FragmentActivity;
|
||||
import com.arialyy.simple.download.multi_download.MultiTaskActivity;
|
||||
import com.arialyy.simple.download.service_download.DownloadService;
|
||||
|
||||
/**
|
||||
* Created by Lyy on 2016/10/13.
|
||||
*/
|
||||
public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding> {
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
@Bind(R.id.single_task) Button mSigleBt;
|
||||
@Bind(R.id.multi_task) Button mMultiBt;
|
||||
@Bind(R.id.dialog_task) Button mDialogBt;
|
||||
@Bind(R.id.pop_task) Button mPopBt;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_download_mean;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
setSupportActionBar(mBar);
|
||||
mBar.setTitle("多线程多任务下载");
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
setEnable(true);
|
||||
} else { //6.0处理
|
||||
boolean hasPermission = PermissionManager.getInstance()
|
||||
.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (hasPermission) {
|
||||
setEnable(true);
|
||||
} else {
|
||||
setEnable(false);
|
||||
PermissionManager.getInstance().requestPermission(this, new OnPermissionCallback() {
|
||||
@Override public void onSuccess(String... permissions) {
|
||||
setEnable(true);
|
||||
}
|
||||
|
||||
@Override public void onFail(String... permissions) {
|
||||
T.showShort(DownloadActivity.this, "没有文件读写权限");
|
||||
setEnable(false);
|
||||
}
|
||||
}, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setEnable(boolean enable) {
|
||||
mSigleBt.setEnabled(enable);
|
||||
mMultiBt.setEnabled(enable);
|
||||
mDialogBt.setEnabled(enable);
|
||||
mPopBt.setEnabled(enable);
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.service:
|
||||
startService(new Intent(this, DownloadService.class));
|
||||
break;
|
||||
case R.id.single_task:
|
||||
startActivity(new Intent(this, SingleTaskActivity.class));
|
||||
break;
|
||||
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;
|
||||
case R.id.pop_task:
|
||||
DownloadPopupWindow pop = new DownloadPopupWindow(this);
|
||||
//pop.showAsDropDown(mRootView);
|
||||
pop.showAtLocation(mRootView, Gravity.CENTER_VERTICAL, 0, 0);
|
||||
break;
|
||||
case R.id.fragment_task:
|
||||
startActivity(new Intent(this, FragmentActivity.class));
|
||||
break;
|
||||
case R.id.notification:
|
||||
SimpleNotification notification = new SimpleNotification(this);
|
||||
notification.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,20 @@
|
||||
package com.arialyy.simple.dialog_task;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
@ -7,10 +23,10 @@ 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.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.core.AbsDialog;
|
||||
import com.arialyy.simple.R;
|
||||
@ -21,11 +37,11 @@ import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
*/
|
||||
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;
|
||||
@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";
|
||||
@ -40,17 +56,17 @@ public class DownloadDialog extends AbsDialog {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
|
||||
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.whit(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
setBtState(state != DownloadEntity.STATE_DOWNLOAD_ING);
|
||||
setBtState(state != DownloadEntity.STATE_RUNNING);
|
||||
} else {
|
||||
setBtState(true);
|
||||
}
|
||||
@ -59,17 +75,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.whit(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -84,31 +99,31 @@ public class DownloadDialog extends AbsDialog {
|
||||
mStop.setEnabled(!startEnable);
|
||||
}
|
||||
|
||||
private class MyDialogDownloadCallback extends Aria.SimpleSchedulerListener {
|
||||
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onTaskPre(Task task) {
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
setBtState(true);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(Task task) {
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.arialyy.simple.module;
|
||||
package com.arialyy.simple.download;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -23,14 +23,13 @@ import android.content.IntentFilter;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.util.AndroidUtils;
|
||||
import com.arialyy.frame.util.StringUtil;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.multi_task.FileListEntity;
|
||||
import com.arialyy.simple.single_task.SingleTaskActivity;
|
||||
import com.arialyy.simple.download.multi_download.FileListEntity;
|
||||
import com.arialyy.simple.base.BaseModule;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -45,9 +44,12 @@ public class DownloadModule extends BaseModule {
|
||||
|
||||
public DownloadModule(Context context) {
|
||||
super(context);
|
||||
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
|
||||
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
|
||||
mTestDownloadUrl.add("http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
|
||||
mTestDownloadUrl.add(
|
||||
"http://static.gaoshouyou.com/d/e6/f5/4de6329f9cf5dc3a1d1e6bbcca0d003c.apk");
|
||||
mTestDownloadUrl.add(
|
||||
"http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.apk");
|
||||
mTestDownloadUrl.add(
|
||||
"http://static.gaoshouyou.com/d/36/69/2d3699acfa69e9632262442c46516ad8.apk");
|
||||
}
|
||||
|
||||
public String getRadomUrl() {
|
||||
@ -56,7 +58,7 @@ public class DownloadModule extends BaseModule {
|
||||
return mTestDownloadUrl.get(i);
|
||||
}
|
||||
|
||||
public DownloadEntity createRandomDownloadEntity(){
|
||||
public DownloadEntity createRandomDownloadEntity() {
|
||||
return createDownloadEntity(getRadomUrl());
|
||||
}
|
||||
|
||||
@ -86,7 +88,7 @@ public class DownloadModule extends BaseModule {
|
||||
String[] urls = getContext().getResources().getStringArray(R.array.test_apk_download_url);
|
||||
List<DownloadEntity> list = new ArrayList<>();
|
||||
for (String url : urls) {
|
||||
DownloadEntity entity = Aria.get(getContext()).getDownloadEntity(url);
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(url);
|
||||
if (entity == null) {
|
||||
entity = createDownloadEntity(url);
|
||||
}
|
@ -1,4 +1,20 @@
|
||||
package com.arialyy.simple.pop_task;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
@ -9,10 +25,10 @@ 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.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.core.AbsPopupWindow;
|
||||
import com.arialyy.simple.R;
|
||||
@ -23,11 +39,11 @@ import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
*/
|
||||
public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
@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;
|
||||
@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";
|
||||
@ -42,17 +58,17 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
|
||||
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
Aria.whit(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(this).addSchedulerListener(new MyDialogDownloadCallback());
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
setBtState(state != DownloadEntity.STATE_DOWNLOAD_ING);
|
||||
setBtState(state != DownloadEntity.STATE_RUNNING);
|
||||
} else {
|
||||
setBtState(true);
|
||||
}
|
||||
@ -61,17 +77,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.whit(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -86,31 +101,31 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
mStop.setEnabled(!startEnable);
|
||||
}
|
||||
|
||||
private class MyDialogDownloadCallback extends Aria.SimpleSchedulerListener {
|
||||
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onTaskPre(Task task) {
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
setBtState(true);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(Task task) {
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
@ -1,13 +1,27 @@
|
||||
package com.arialyy.simple.notification;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
/**
|
||||
@ -36,11 +50,11 @@ public class SimpleNotification {
|
||||
.setProgress(100, 0, false)
|
||||
.setSmallIcon(R.mipmap.ic_launcher);
|
||||
mManager.notify(mNotifiyId, mBuilder.build());
|
||||
Aria.whit(mContext).addSchedulerListener(new DownloadCallback(mBuilder, mManager));
|
||||
Aria.download(mContext).addSchedulerListener(new DownloadCallback(mBuilder, mManager));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Aria.whit(mContext)
|
||||
Aria.download(mContext)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadName("notification_test.apk")
|
||||
.setDownloadPath(
|
||||
@ -49,10 +63,10 @@ public class SimpleNotification {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Aria.whit(mContext).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(mContext).load(DOWNLOAD_URL).pause();
|
||||
}
|
||||
|
||||
private static class DownloadCallback extends Aria.SimpleSchedulerListener {
|
||||
private static class DownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
NotificationCompat.Builder mBuilder;
|
||||
NotificationManager mManager;
|
||||
|
||||
@ -61,19 +75,19 @@ public class SimpleNotification {
|
||||
mManager = manager;
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(Task task) {
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
super.onTaskStart(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskPre(Task task) {
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
long len = task.getFileSize();
|
||||
int p = (int) (task.getCurrentProgress() * 100 / len);
|
||||
@ -83,7 +97,7 @@ public class SimpleNotification {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(Task task) {
|
||||
@Override public void onTaskComplete(DownloadTask task) {
|
||||
super.onTaskComplete(task);
|
||||
if (mBuilder != null) {
|
||||
mBuilder.setProgress(100, 100, false);
|
||||
@ -91,7 +105,7 @@ public class SimpleNotification {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(Task task) {
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.arialyy.simple.single_task;
|
||||
package com.arialyy.simple.download;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@ -26,46 +26,47 @@ import android.os.Message;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.aria.core.AMTarget;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.DownloadUtil;
|
||||
import com.arialyy.aria.core.task.IDownloadListener;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.Speed;
|
||||
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;
|
||||
|
||||
public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
public static final int DOWNLOAD_PRE = 0x01;
|
||||
public static final int DOWNLOAD_STOP = 0x02;
|
||||
public static final int DOWNLOAD_FAILE = 0x03;
|
||||
public static final int DOWNLOAD_CANCEL = 0x04;
|
||||
public static final int DOWNLOAD_RESUME = 0x05;
|
||||
public static final int DOWNLOAD_COMPLETE = 0x06;
|
||||
public static final int DOWNLOAD_RUNNING = 0x07;
|
||||
public static final int DOWNLOAD_PRE = 0x01;
|
||||
public static final int DOWNLOAD_STOP = 0x02;
|
||||
public static final int DOWNLOAD_FAILE = 0x03;
|
||||
public static final int DOWNLOAD_CANCEL = 0x04;
|
||||
public static final int DOWNLOAD_RESUME = 0x05;
|
||||
public static final int DOWNLOAD_COMPLETE = 0x06;
|
||||
public static final int DOWNLOAD_RUNNING = 0x07;
|
||||
|
||||
private static final String DOWNLOAD_URL =
|
||||
private static final String DOWNLOAD_URL =
|
||||
//"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://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||
//"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk";
|
||||
//不支持断点的链接
|
||||
"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||
@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.toolbar) Toolbar toolbar;
|
||||
@Bind(R.id.speed) TextView mSpeed;
|
||||
@Bind(R.id.img) ImageView mImg;
|
||||
private DownloadEntity mEntity;
|
||||
@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.toolbar) Toolbar toolbar;
|
||||
@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();
|
||||
@ -80,7 +81,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case DOWNLOAD_RUNNING:
|
||||
Task task = (Task) msg.obj;
|
||||
DownloadTask task = (DownloadTask) msg.obj;
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
@ -143,7 +144,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
|
||||
}
|
||||
|
||||
@ -165,11 +166,38 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
|
||||
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
mRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
switch (checkedId) {
|
||||
case 1:
|
||||
Aria.get(this).setMaxSpeed(Speed.KB_256);
|
||||
break;
|
||||
case 2:
|
||||
Aria.get(this).setMaxSpeed(Speed.KB_512);
|
||||
break;
|
||||
case 3:
|
||||
Aria.get(this).setMaxSpeed(Speed.MB_1);
|
||||
break;
|
||||
case 4:
|
||||
Aria.get(this).setMaxSpeed(Speed.MB_2);
|
||||
break;
|
||||
case 5:
|
||||
Aria.get(this).setMaxSpeed(Speed.MAX);
|
||||
break;
|
||||
}
|
||||
stop();
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override public void run() {
|
||||
start();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
@ -192,53 +220,58 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
}
|
||||
|
||||
private void resume() {
|
||||
Aria.whit(this).load(DOWNLOAD_URL).resume();
|
||||
Aria.download(this).load(DOWNLOAD_URL).resume();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
Aria.whit(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
.setDownloadName("test.apk")
|
||||
.start();
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
}
|
||||
|
||||
private void cancel() {
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
|
||||
@Override public void onTaskStart(Task task) {
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
super.onNoSupportBreakPoint(task);
|
||||
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
|
||||
.sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(Task task) {
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
super.onTaskResume(task);
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getFileSize()).sendToTarget();
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(Task task) {
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
|
||||
}
|
||||
|
||||
@Override public void onTaskFail(Task task) {
|
||||
@Override public void onTaskFail(DownloadTask task) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(Task task) {
|
||||
@Override public void onTaskComplete(DownloadTask task) {
|
||||
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE);
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget();
|
||||
}
|
||||
}
|
@ -1,4 +1,20 @@
|
||||
package com.arialyy.simple.fragment_task;
|
||||
/*
|
||||
* 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.fragment_download;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
@ -7,10 +23,10 @@ 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.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.core.AbsFragment;
|
||||
import com.arialyy.simple.R;
|
||||
@ -32,16 +48,16 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
"http://static.gaoshouyou.com/d/3a/93/573ae1db9493a801c24bf66128b11e39.apk";
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
if (Aria.get(this).taskExists(DOWNLOAD_URL)) {
|
||||
AMTarget target = Aria.whit(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
}
|
||||
DownloadEntity entity = Aria.get(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
setBtState(state != DownloadEntity.STATE_DOWNLOAD_ING);
|
||||
setBtState(state != DownloadEntity.STATE_RUNNING);
|
||||
} else {
|
||||
setBtState(true);
|
||||
}
|
||||
@ -49,23 +65,23 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
|
||||
@Override public void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new DownloadFragment.MyDialogDownloadCallback());
|
||||
Aria.download(this).addSchedulerListener(new DownloadFragment.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(this)
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/daialog.apk")
|
||||
.setDownloadName("daialog.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).stop();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.whit(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -88,31 +104,31 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
mStop.setEnabled(!startEnable);
|
||||
}
|
||||
|
||||
private class MyDialogDownloadCallback extends Aria.SimpleSchedulerListener {
|
||||
private class MyDialogDownloadCallback extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onTaskPre(Task task) {
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
mSize.setText(CommonUtil.formatFileSize(task.getFileSize()));
|
||||
setBtState(false);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
setBtState(true);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(Task task) {
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(task);
|
||||
setBtState(true);
|
||||
mPb.setProgress(0);
|
||||
mSpeed.setText("0.0kb/s");
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
long current = task.getCurrentProgress();
|
||||
long len = task.getFileSize();
|
||||
long len = task.getFileSize();
|
||||
if (len == 0) {
|
||||
mPb.setProgress(0);
|
||||
} else {
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.fragment_download;
|
||||
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.FragmentDownloadBinding;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/4.
|
||||
*/
|
||||
|
||||
public class FragmentActivity extends BaseActivity<FragmentDownloadBinding> {
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_fragment;
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.arialyy.simple.multi_task;
|
||||
package com.arialyy.simple.download.multi_download;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
@ -25,7 +25,7 @@ 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.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
@ -39,8 +39,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* 下载列表适配器
|
||||
*/
|
||||
final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter.MyHolder> {
|
||||
private static final String TAG = "DownloadAdapter";
|
||||
private Map<String, Integer> mPositions = new ConcurrentHashMap<>();
|
||||
private static final String TAG = "DownloadAdapter";
|
||||
private Map<String, Integer> mPositions = new ConcurrentHashMap<>();
|
||||
|
||||
DownloadAdapter(Context context, List<DownloadEntity> data) {
|
||||
super(context, data);
|
||||
@ -125,7 +125,7 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
|
||||
break;
|
||||
case DownloadEntity.STATE_PRE:
|
||||
case DownloadEntity.STATE_POST_PRE:
|
||||
case DownloadEntity.STATE_DOWNLOAD_ING:
|
||||
case DownloadEntity.STATE_RUNNING:
|
||||
str = "暂停";
|
||||
color = android.R.color.holo_red_light;
|
||||
break;
|
||||
@ -142,7 +142,7 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
|
||||
@Override public void onClick(View v) {
|
||||
mData.remove(item);
|
||||
notifyDataSetChanged();
|
||||
Aria.whit(getContext()).load(item).cancel();
|
||||
Aria.download(getContext()).load(item).cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -176,30 +176,30 @@ final class DownloadAdapter extends AbsRVAdapter<DownloadEntity, DownloadAdapter
|
||||
case DownloadEntity.STATE_COMPLETE:
|
||||
start(entity);
|
||||
break;
|
||||
case DownloadEntity.STATE_DOWNLOAD_ING:
|
||||
case DownloadEntity.STATE_RUNNING:
|
||||
stop(entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void start(DownloadEntity entity) {
|
||||
Aria.whit(getContext()).load(entity).start();
|
||||
Aria.download(getContext()).load(entity).start();
|
||||
}
|
||||
|
||||
private void stop(DownloadEntity entity) {
|
||||
Aria.whit(getContext()).load(entity).stop();
|
||||
Aria.download(getContext()).load(entity).pause();
|
||||
}
|
||||
}
|
||||
|
||||
class MyHolder extends AbsHolder {
|
||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
|
||||
@Bind(R.id.bt) Button bt;
|
||||
@Bind(R.id.speed) TextView speed;
|
||||
@Bind(R.id.fileSize) TextView fileSize;
|
||||
@Bind(R.id.del) TextView cancel;
|
||||
@Bind(R.id.name) TextView name;
|
||||
@Bind(R.id.download_url) TextView url;
|
||||
@Bind(R.id.download_path) TextView path;
|
||||
@Bind(R.id.progressBar) HorizontalProgressBarWithNumber progress;
|
||||
@Bind(R.id.bt) Button bt;
|
||||
@Bind(R.id.speed) TextView speed;
|
||||
@Bind(R.id.fileSize) TextView fileSize;
|
||||
@Bind(R.id.del) TextView cancel;
|
||||
@Bind(R.id.name) TextView name;
|
||||
@Bind(R.id.download_url) TextView url;
|
||||
@Bind(R.id.download_path) TextView path;
|
||||
|
||||
MyHolder(View itemView) {
|
||||
super(itemView);
|
@ -14,8 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.arialyy.simple.multi_task;
|
||||
package com.arialyy.simple.download.multi_download;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
@ -1,7 +1,22 @@
|
||||
package com.arialyy.simple.multi_task;
|
||||
/*
|
||||
* 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.multi_download;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
@ -51,7 +66,7 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
|
||||
holder.bt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
Toast.makeText(getContext(), "开始下载:" + item.name, Toast.LENGTH_SHORT).show();
|
||||
Aria.whit(getContext())
|
||||
Aria.download(getContext())
|
||||
.load(item.downloadUrl)
|
||||
.setDownloadName(item.name)
|
||||
.setDownloadPath(item.downloadPath)
|
||||
@ -87,10 +102,10 @@ final class FileListAdapter extends AbsRVAdapter<FileListEntity, FileListAdapter
|
||||
}
|
||||
|
||||
class FileListHolder extends AbsHolder {
|
||||
@Bind(R.id.name) TextView name;
|
||||
@Bind(R.id.download_url) TextView url;
|
||||
@Bind(R.id.name) TextView name;
|
||||
@Bind(R.id.download_url) TextView url;
|
||||
@Bind(R.id.download_path) TextView path;
|
||||
@Bind(R.id.bt) Button bt;
|
||||
@Bind(R.id.bt) Button bt;
|
||||
|
||||
FileListHolder(View itemView) {
|
||||
super(itemView);
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.multi_download;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/1/6.
|
||||
*/
|
||||
|
||||
public class FileListEntity {
|
||||
public String name, downloadUrl, downloadPath;
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.multi_download;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMultiDownloadBinding;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/1/6.
|
||||
*/
|
||||
|
||||
public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
private DownloadAdapter mAdapter;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_multi_download;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mAdapter = new DownloadAdapter(this, Aria.download(this).getTaskList());
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
mBar.setTitle("多任务下载");
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
@Override public void onTaskPre(DownloadTask task) {
|
||||
super.onTaskPre(task);
|
||||
L.d(TAG, "download pre");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
super.onTaskStart(task);
|
||||
L.d(TAG, "download start");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
super.onTaskResume(task);
|
||||
L.d(TAG, "download resume");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
super.onTaskCancel(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");
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.arialyy.simple.multi_task;
|
||||
package com.arialyy.simple.download.multi_download;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@ -24,13 +24,11 @@ import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.DownloadEntity;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityMultiBinding;
|
||||
import com.arialyy.simple.module.DownloadModule;
|
||||
import com.arialyy.simple.download.DownloadModule;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -38,9 +36,9 @@ import java.util.List;
|
||||
* Created by Lyy on 2016/9/27.
|
||||
*/
|
||||
public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
private FileListAdapter mAdapter;
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
@Bind(R.id.toolbar) Toolbar mBar;
|
||||
private FileListAdapter mAdapter;
|
||||
List<FileListEntity> mData = new ArrayList<>();
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
@ -64,17 +62,17 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
dialog.show(getSupportFragmentManager(), "download_num");
|
||||
break;
|
||||
case R.id.stop_all:
|
||||
Aria.get(this).stopAllTask();
|
||||
Aria.download(this).stopAllTask();
|
||||
break;
|
||||
case R.id.turn:
|
||||
startActivity(new Intent(this, DownloadActivity.class));
|
||||
startActivity(new Intent(this, MultiDownloadActivity.class));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new DownloadListener());
|
||||
Aria.download(this).addSchedulerListener(new DownloadListener());
|
||||
}
|
||||
|
||||
@Override protected void onDestroy() {
|
||||
@ -89,28 +87,28 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
|
||||
}
|
||||
}
|
||||
|
||||
private class DownloadListener extends Aria.SimpleSchedulerListener {
|
||||
private class DownloadListener extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onTaskStart(Task task) {
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
super.onTaskStart(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), false);
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
@Override public void onTaskRunning(DownloadTask task) {
|
||||
super.onTaskRunning(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(Task task) {
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
super.onTaskResume(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), false);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
super.onTaskStop(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), true);
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(Task task) {
|
||||
@Override public void onTaskComplete(DownloadTask task) {
|
||||
super.onTaskComplete(task);
|
||||
mAdapter.updateBtState(task.getDownloadUrl(), true);
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.service_download;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/18.
|
||||
*/
|
||||
public class DownloadNotification {
|
||||
|
||||
private NotificationManager mManager;
|
||||
private Context mContext;
|
||||
private NotificationCompat.Builder mBuilder;
|
||||
private static final int mNotifiyId = 0;
|
||||
|
||||
public DownloadNotification(Context context) {
|
||||
mContext = context;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mBuilder = new NotificationCompat.Builder(mContext);
|
||||
mBuilder.setContentTitle("Aria Download Test")
|
||||
.setContentText("进度条")
|
||||
.setProgress(100, 0, false)
|
||||
.setSmallIcon(R.mipmap.ic_launcher);
|
||||
mManager.notify(mNotifiyId, mBuilder.build());
|
||||
}
|
||||
|
||||
public void upload(int progress){
|
||||
if (mBuilder != null) {
|
||||
mBuilder.setProgress(100, progress, false);
|
||||
mManager.notify(mNotifiyId, mBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.service_download;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/4/5.
|
||||
* 在服务中使用 Aria进行下载
|
||||
*/
|
||||
public class DownloadService extends Service {
|
||||
|
||||
private static final String DOWNLOAD_URL =
|
||||
//"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/21/e8/61218d78d0e8b79df68dbc18dd484c97.apk";
|
||||
//不支持断点的链接
|
||||
"http://ox.konsung.net:5555/ksdc-web/download/downloadFile/?fileName=ksdc_1.0.2.apk&rRange=0-";
|
||||
private DownloadNotification mNotify;
|
||||
|
||||
@Nullable @Override public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
mNotify = new DownloadNotification(getApplicationContext());
|
||||
Aria.download(this).addSchedulerListener(new MySchedulerListener());
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk")
|
||||
.start();
|
||||
}
|
||||
|
||||
@Override public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Aria.download(this).removeSchedulerListener();
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
|
||||
|
||||
@Override public void onNoSupportBreakPoint(DownloadTask task) {
|
||||
super.onNoSupportBreakPoint(task);
|
||||
T.showShort(getApplicationContext(), "该下载链接不支持断点");
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",开始下载");
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(DownloadTask task) {
|
||||
super.onTaskResume(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",停止下载");
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(DownloadTask task) {
|
||||
T.showShort(getApplicationContext(), task.getDownloadEntity().getFileName() + ",取消下载");
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.arialyy.simple.fragment_task;
|
||||
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.FragmentDownloadBinding;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/4.
|
||||
*/
|
||||
|
||||
public class FragmentActivity extends BaseActivity<FragmentDownloadBinding> {
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_fragment;
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package com.arialyy.simple.multi_task;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import butterknife.Bind;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.Task;
|
||||
import com.arialyy.frame.util.show.L;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityDownloadBinding;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/1/6.
|
||||
*/
|
||||
|
||||
public class DownloadActivity extends BaseActivity<ActivityDownloadBinding> {
|
||||
@Bind(R.id.list) RecyclerView mList;
|
||||
private DownloadAdapter mAdapter;
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_download;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
mAdapter = new DownloadAdapter(this, Aria.get(this).getDownloadList());
|
||||
mList.setLayoutManager(new LinearLayoutManager(this));
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override protected void dataCallback(int result, Object data) {
|
||||
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.whit(this).addSchedulerListener(new MySchedulerListener());
|
||||
}
|
||||
|
||||
private class MySchedulerListener extends Aria.SimpleSchedulerListener {
|
||||
@Override public void onTaskPre(Task task) {
|
||||
super.onTaskPre(task);
|
||||
L.d(TAG, "download pre");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(Task task) {
|
||||
super.onTaskStart(task);
|
||||
L.d(TAG, "download start");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskResume(Task task) {
|
||||
super.onTaskResume(task);
|
||||
L.d(TAG, "download resume");
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
super.onTaskRunning(task);
|
||||
mAdapter.setProgress(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
super.onTaskStop(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(Task task) {
|
||||
super.onTaskCancel(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(Task task) {
|
||||
super.onTaskComplete(task);
|
||||
mAdapter.updateState(task.getDownloadEntity());
|
||||
}
|
||||
|
||||
@Override public void onTaskFail(Task task) {
|
||||
super.onTaskFail(task);
|
||||
L.d(TAG, "download fail");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.arialyy.simple.multi_task;
|
||||
|
||||
/**
|
||||
* Created by AriaL on 2017/1/6.
|
||||
*/
|
||||
|
||||
public class FileListEntity {
|
||||
public String name, downloadUrl, downloadPath;
|
||||
}
|
134
app/src/main/java/com/arialyy/simple/upload/UploadActivity.java
Normal file
134
app/src/main/java/com/arialyy/simple/upload/UploadActivity.java
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.upload;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.upload.UploadTask;
|
||||
import com.arialyy.frame.util.FileUtil;
|
||||
import com.arialyy.frame.util.show.T;
|
||||
import com.arialyy.simple.R;
|
||||
import com.arialyy.simple.base.BaseActivity;
|
||||
import com.arialyy.simple.databinding.ActivityUploadMeanBinding;
|
||||
import com.arialyy.simple.widget.HorizontalProgressBarWithNumber;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/2/9.
|
||||
*/
|
||||
public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
|
||||
@Bind(R.id.pb) HorizontalProgressBarWithNumber mPb;
|
||||
private static final int START = 0;
|
||||
private static final int STOP = 1;
|
||||
private static final int CANCEL = 2;
|
||||
private static final int RUNNING = 3;
|
||||
private static final int COMPLETE = 4;
|
||||
|
||||
private static final String FILE_PATH = "/sdcard/Download/test.zip";
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
UploadTask task = (UploadTask) msg.obj;
|
||||
switch (msg.what) {
|
||||
case START:
|
||||
getBinding().setFileSize(FileUtil.formatFileSize(task.getFileSize()));
|
||||
break;
|
||||
case STOP:
|
||||
mPb.setProgress(0);
|
||||
break;
|
||||
case CANCEL:
|
||||
mPb.setProgress(0);
|
||||
break;
|
||||
case RUNNING:
|
||||
int p = (int) (task.getCurrentProgress() * 100 / task.getFileSize());
|
||||
mPb.setProgress(p);
|
||||
break;
|
||||
case COMPLETE:
|
||||
T.showShort(UploadActivity.this, "上传完成");
|
||||
mPb.setProgress(100);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override protected int setLayoutId() {
|
||||
return R.layout.activity_upload_mean;
|
||||
}
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
super.init(savedInstanceState);
|
||||
}
|
||||
|
||||
@OnClick(R.id.upload) void upload() {
|
||||
Aria.upload(this)
|
||||
.load(FILE_PATH)
|
||||
.setUploadUrl("http://172.18.104.50:8080/upload/sign_file")
|
||||
.setAttachment("file")
|
||||
.start();
|
||||
}
|
||||
|
||||
@OnClick(R.id.stop) void stop() {
|
||||
Aria.upload(this).load(FILE_PATH).cancel();
|
||||
}
|
||||
|
||||
@OnClick(R.id.remove) void remove() {
|
||||
Aria.upload(this).load(FILE_PATH).cancel();
|
||||
}
|
||||
|
||||
@Override protected void onResume() {
|
||||
super.onResume();
|
||||
Aria.upload(this).addSchedulerListener(new UploadListener(mHandler));
|
||||
}
|
||||
|
||||
static class UploadListener extends Aria.UploadSchedulerListener {
|
||||
WeakReference<Handler> handler;
|
||||
|
||||
UploadListener(Handler handler) {
|
||||
this.handler = new WeakReference<>(handler);
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(UploadTask task) {
|
||||
super.onTaskStart(task);
|
||||
handler.get().obtainMessage(START, 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package com.arialyy.simple.widget;
|
||||
|
||||
import android.content.Context;
|
||||
@ -27,53 +26,50 @@ import android.widget.ProgressBar;
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
public class HorizontalProgressBarWithNumber extends ProgressBar {
|
||||
private static final int DEFAULT_TEXT_SIZE = 10;
|
||||
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
|
||||
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
|
||||
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
|
||||
private static final int DEFAULT_TEXT_SIZE = 10;
|
||||
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
|
||||
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
|
||||
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
|
||||
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;
|
||||
/**
|
||||
* painter of all drawing things
|
||||
*/
|
||||
protected Paint mPaint = new Paint();
|
||||
protected Paint mPaint = new Paint();
|
||||
/**
|
||||
* color of progress number
|
||||
*/
|
||||
protected int mTextColor = DEFAULT_TEXT_COLOR;
|
||||
protected int mTextColor = DEFAULT_TEXT_COLOR;
|
||||
/**
|
||||
* size of text (sp)
|
||||
*/
|
||||
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
|
||||
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);
|
||||
/**
|
||||
* offset of draw progress
|
||||
*/
|
||||
protected int mTextOffset =
|
||||
dp2px(DEFAULT_SIZE_TEXT_OFFSET);
|
||||
protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET);
|
||||
/**
|
||||
* height of reached progress bar
|
||||
*/
|
||||
protected int mReachedProgressBarHeight =
|
||||
dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
||||
protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);
|
||||
/**
|
||||
* color of reached bar
|
||||
*/
|
||||
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
|
||||
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
|
||||
/**
|
||||
* color of unreached bar
|
||||
*/
|
||||
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
|
||||
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
|
||||
/**
|
||||
* height of unreached progress bar
|
||||
*/
|
||||
protected int mUnReachedProgressBarHeight =
|
||||
dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
||||
protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
|
||||
/**
|
||||
* view width except padding
|
||||
*/
|
||||
protected int mRealWidth;
|
||||
protected boolean mIfDrawText = true;
|
||||
protected static final int VISIBLE = 0;
|
||||
protected boolean mIfDrawText = true;
|
||||
protected static final int VISIBLE = 0;
|
||||
|
||||
public HorizontalProgressBarWithNumber(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
@ -87,14 +83,14 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
|
||||
}
|
||||
|
||||
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int height = measureHeight(heightMeasureSpec);
|
||||
setMeasuredDimension(width, height);
|
||||
mRealWidth = getMeasuredWidth() - getPaddingRight() - getPaddingLeft();
|
||||
}
|
||||
|
||||
private int measureHeight(int measureSpec) {
|
||||
int result = 0;
|
||||
int result = 0;
|
||||
int specMode = MeasureSpec.getMode(measureSpec);
|
||||
int specSize = MeasureSpec.getSize(measureSpec);
|
||||
if (specMode == MeasureSpec.EXACTLY) {
|
||||
@ -148,12 +144,12 @@ public class HorizontalProgressBarWithNumber extends ProgressBar {
|
||||
@Override protected synchronized void onDraw(Canvas canvas) {
|
||||
canvas.save();
|
||||
canvas.translate(getPaddingLeft(), getHeight() / 2);
|
||||
boolean noNeedBg = false;
|
||||
float radio = getProgress() * 1.0f / getMax();
|
||||
float progressPosX = (int) (mRealWidth * radio);
|
||||
String text = getProgress() + "%";
|
||||
boolean noNeedBg = false;
|
||||
float radio = getProgress() * 1.0f / getMax();
|
||||
float progressPosX = (int) (mRealWidth * radio);
|
||||
String text = getProgress() + "%";
|
||||
// mPaint.getTextBounds(text, 0, text.length(), mTextBound);
|
||||
float textWidth = mPaint.measureText(text);
|
||||
float textWidth = mPaint.measureText(text);
|
||||
float textHeight = (mPaint.descent() + mPaint.ascent()) / 2;
|
||||
if (progressPosX + textWidth > mRealWidth) {
|
||||
progressPosX = mRealWidth - textWidth;
|
||||
|
78
app/src/main/res/layout/activity_download_mean.xml
Normal file
78
app/src/main/res/layout/activity_download_mean.xml
Normal file
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/single_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="单任务下载"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/multi_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="多任务下载"
|
||||
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"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/pop_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="在popupwindow中使用"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/fragment_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="在Fragment中使用"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/notification"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="在Notification中使用"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/service"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="在Service中使用"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
@ -8,7 +8,7 @@
|
||||
>
|
||||
<fragment
|
||||
android:id="@+id/fragment1"
|
||||
android:name="com.arialyy.simple.fragment_task.DownloadFragment"
|
||||
android:name="com.arialyy.simple.download.fragment_download.DownloadFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
@ -1,69 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/single_task"
|
||||
android:id="@+id/download"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="单任务下载"
|
||||
android:text="下载 demo"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/multi_task"
|
||||
android:id="@+id/upload"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="多任务下载"
|
||||
android:text="上传 demo"
|
||||
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"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/pop_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="在popupwindow中使用"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/fragment_task"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="在Fragment中使用"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/notification"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onClick"
|
||||
android:text="在Notification中使用"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
@ -9,10 +9,13 @@
|
||||
tools:context="com.example.arial.test.MainActivity"
|
||||
>
|
||||
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/toolbar"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
@ -6,7 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.arialyy.simple.single_task.SingleTaskActivity"
|
||||
tools:context="com.arialyy.simple.download.SingleTaskActivity"
|
||||
>
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
|
97
app/src/main/res/layout/activity_upload_mean.xml
Normal file
97
app/src/main/res/layout/activity_upload_mean.xml
Normal file
@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<data>
|
||||
<variable
|
||||
name="fileSize"
|
||||
type="String"
|
||||
/>
|
||||
<variable
|
||||
name="speed"
|
||||
type="String"
|
||||
/>
|
||||
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<include layout="@layout/layout_bar"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/top_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/toolbar"
|
||||
>
|
||||
|
||||
<com.arialyy.simple.widget.HorizontalProgressBarWithNumber
|
||||
android:id="@+id/pb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_toLeftOf="@+id/size"
|
||||
android:max="100"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/size"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="16dp"
|
||||
android:text="@{fileSize}"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/speed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="@{speed}"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/upload"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="上传"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/stop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="停止"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/remove"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="删除"
|
||||
style="?buttonBarButtonStyle"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</layout>
|
@ -5,7 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="com.arialyy.simple.single_task.SingleTaskActivity"
|
||||
tools:context="com.arialyy.simple.download.SingleTaskActivity"
|
||||
tools:showIn="@layout/activity_single"
|
||||
>
|
||||
|
||||
@ -81,10 +81,55 @@
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
<TextView
|
||||
android:id="@+id/speed_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/handle_bar"
|
||||
/>
|
||||
|
||||
<RadioGroup
|
||||
android:visibility="gone"
|
||||
android:id="@+id/speeds"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/speed_hint"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="256kb"
|
||||
/>
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="512kb"
|
||||
/>
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="1mb"
|
||||
/>
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="2mb"
|
||||
/>
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="max"
|
||||
/>
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
</RelativeLayout>
|
||||
|
Reference in New Issue
Block a user