fix bug
This commit is contained in:
@@ -19,6 +19,7 @@ package com.arialyy.simple.base;
|
||||
import android.app.Application;
|
||||
import android.os.Build;
|
||||
import android.os.StrictMode;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.frame.core.AbsFrame;
|
||||
import com.arialyy.simple.BuildConfig;
|
||||
|
||||
@@ -29,7 +30,7 @@ public class BaseApplication extends Application {
|
||||
@Override public void onCreate() {
|
||||
super.onCreate();
|
||||
AbsFrame.init(this);
|
||||
|
||||
//Aria.init(this);
|
||||
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
|
||||
StrictMode.setThreadPolicy(
|
||||
new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
|
||||
|
||||
@@ -20,7 +20,6 @@ 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;
|
||||
@@ -97,6 +96,7 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
|
||||
break;
|
||||
case R.id.dialog_task:
|
||||
DownloadDialog dialog = new DownloadDialog(this);
|
||||
|
||||
dialog.show();
|
||||
//DownloadDialogFragment dialog = new DownloadDialogFragment(this);
|
||||
//dialog.show(getSupportFragmentManager(), "dialog");
|
||||
@@ -109,8 +109,8 @@ public class DownloadActivity extends BaseActivity<ActivityDownloadMeanBinding>
|
||||
startActivity(new Intent(this, FragmentActivity.class));
|
||||
break;
|
||||
case R.id.notification:
|
||||
SimpleNotification notification = new SimpleNotification(this);
|
||||
notification.start();
|
||||
//SimpleNotification notification = new SimpleNotification(this);
|
||||
//notification.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ public class DownloadDialog extends AbsDialog {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Aria.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int p = (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
|
||||
@@ -73,16 +73,16 @@ public class DownloadDialog extends AbsDialog {
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(getContext())
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/飞机大战.apk")
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/飞机大战.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ import com.arialyy.simple.databinding.DialogFragmentDownloadBinding;
|
||||
case R.id.start:
|
||||
Aria.download(getContext())
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/放置江湖.apk")
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/放置江湖.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
|
||||
@@ -26,9 +26,9 @@ import android.widget.TextView;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.download.DownloadTarget;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.frame.core.AbsPopupWindow;
|
||||
@@ -59,13 +59,13 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
}
|
||||
|
||||
private void initWidget() {
|
||||
if (Aria.download(getContext()).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(getContext()).load(DOWNLOAD_URL);
|
||||
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.download(getContext()).register();
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
Aria.download(this).register();
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
mSize.setText(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
@@ -78,16 +78,16 @@ public class DownloadPopupWindow extends AbsPopupWindow {
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(getContext())
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/消消乐.apk")
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/消消乐.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +1,99 @@
|
||||
/*
|
||||
* 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.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.download.DownloadTask;
|
||||
import com.arialyy.simple.R;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/18.
|
||||
*/
|
||||
|
||||
public class SimpleNotification {
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://static.gaoshouyou.com/d/cb/38/f0cb1b2c57388fe14342eecd64bbae65.apk";
|
||||
|
||||
private NotificationManager mManager;
|
||||
private Context mContext;
|
||||
private NotificationCompat.Builder mBuilder;
|
||||
private static final int mNotifiyId = 0;
|
||||
|
||||
public SimpleNotification(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());
|
||||
Aria.download(mContext).register();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Aria.download(mContext)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk")
|
||||
.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Aria.download(mContext).load(DOWNLOAD_URL).pause();
|
||||
}
|
||||
|
||||
@Download.onTaskStart public void onTaskStart(DownloadTask task) {
|
||||
}
|
||||
|
||||
@Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||
}
|
||||
|
||||
@Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
}
|
||||
|
||||
@Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
long len = task.getFileSize();
|
||||
int p = (int) (task.getCurrentProgress() * 100 / len);
|
||||
if (mBuilder != null) {
|
||||
mBuilder.setProgress(100, p, false);
|
||||
mManager.notify(mNotifiyId, mBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
|
||||
if (mBuilder != null) {
|
||||
mBuilder.setProgress(100, 100, false);
|
||||
mManager.notify(mNotifiyId, mBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Download.onTaskCancel public void onTaskCancel(DownloadTask 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.app.NotificationManager;
|
||||
//import android.content.Context;
|
||||
//import android.os.Environment;
|
||||
//import android.support.v4.app.NotificationCompat;
|
||||
//import com.arialyy.annotations.Download;
|
||||
//import com.arialyy.aria.core.Aria;
|
||||
//import com.arialyy.aria.core.download.DownloadTask;
|
||||
//import com.arialyy.simple.R;
|
||||
//
|
||||
///**
|
||||
// * Created by Aria.Lao on 2017/1/18.
|
||||
// */
|
||||
//
|
||||
//public class SimpleNotification {
|
||||
// private static final String DOWNLOAD_URL =
|
||||
// "http://static.gaoshouyou.com/d/cb/38/f0cb1b2c57388fe14342eecd64bbae65.apk";
|
||||
//
|
||||
// private NotificationManager mManager;
|
||||
// private Context mContext;
|
||||
// private NotificationCompat.Builder mBuilder;
|
||||
// private static final int mNotifiyId = 0;
|
||||
//
|
||||
// public SimpleNotification(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());
|
||||
// Aria.download(this).register();
|
||||
// }
|
||||
//
|
||||
// public void start() {
|
||||
// Aria.download(this)
|
||||
// .load(DOWNLOAD_URL)
|
||||
// .setFilePath(Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk")
|
||||
// .start();
|
||||
// }
|
||||
//
|
||||
// public void stop() {
|
||||
// Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
// }
|
||||
//
|
||||
// public void destory() {
|
||||
// Aria.download(this).unRegister();
|
||||
// }
|
||||
//
|
||||
// @Download.onTaskStart public void onTaskStart(DownloadTask task) {
|
||||
// }
|
||||
//
|
||||
// @Download.onTaskPre public void onTaskPre(DownloadTask task) {
|
||||
// }
|
||||
//
|
||||
// @Download.onTaskStop public void onTaskStop(DownloadTask task) {
|
||||
// }
|
||||
//
|
||||
// @Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
|
||||
// long len = task.getFileSize();
|
||||
// int p = (int) (task.getCurrentProgress() * 100 / len);
|
||||
// if (mBuilder != null) {
|
||||
// mBuilder.setProgress(100, p, false);
|
||||
// mManager.notify(mNotifiyId, mBuilder.build());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
|
||||
// if (mBuilder != null) {
|
||||
// mBuilder.setProgress(100, 100, false);
|
||||
// mManager.notify(mNotifiyId, mBuilder.build());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.arialyy.simple.download;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
@@ -219,13 +220,13 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
startD();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
//startActivity(new Intent(this, SingleTaskActivity.class));
|
||||
//Aria.download(this).load(DOWNLOAD_URL).stop();
|
||||
startActivity(new Intent(this, SingleTaskActivity.class));
|
||||
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||
//Aria.download(this).load(DOWNLOAD_URL).removeRecord();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -254,6 +255,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
|
||||
@Override protected void onStop() {
|
||||
super.onStop();
|
||||
Aria.download(this).unRegister();
|
||||
//Aria.download(this).unRegister();
|
||||
}
|
||||
}
|
||||
@@ -45,11 +45,11 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
private static final String DOWNLOAD_URL = "https://res5.d.cn/2137e42d610b3488d9420c6421529386eee5bdbfd9be1fafe0a05d6dabaec8c156ddbd00581055bbaeac03904fb63310e80010680235d16bd4c040b50096a0c20dd1c4b0854529a1.apk";
|
||||
|
||||
@Override protected void init(Bundle savedInstanceState) {
|
||||
if (Aria.download(getContext()).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(getContext()).load(DOWNLOAD_URL);
|
||||
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
|
||||
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
|
||||
getBinding().setProgress(target.getPercent());
|
||||
}
|
||||
DownloadEntity entity = Aria.download(getContext()).getDownloadEntity(DOWNLOAD_URL);
|
||||
DownloadEntity entity = Aria.download(this).getDownloadEntity(DOWNLOAD_URL);
|
||||
if (entity != null) {
|
||||
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
|
||||
int state = entity.getState();
|
||||
@@ -57,22 +57,22 @@ public class DownloadFragment extends AbsFragment<FragmentDownloadBinding> {
|
||||
} else {
|
||||
setBtState(true);
|
||||
}
|
||||
Aria.download(getContext()).register();
|
||||
Aria.download(this).register();
|
||||
}
|
||||
|
||||
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.start:
|
||||
Aria.download(getContext())
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/王者军团.apk")
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/王者军团.apk")
|
||||
.start();
|
||||
break;
|
||||
case R.id.stop:
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).pause();
|
||||
Aria.download(this).load(DOWNLOAD_URL).pause();
|
||||
break;
|
||||
case R.id.cancel:
|
||||
Aria.download(getContext()).load(DOWNLOAD_URL).cancel();
|
||||
Aria.download(this).load(DOWNLOAD_URL).cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class DownloadService extends Service {
|
||||
Aria.download(this).register();
|
||||
Aria.download(this)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk")
|
||||
.setFilePath(Environment.getExternalStorageDirectory().getPath() + "/service_task.apk")
|
||||
.start();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user