2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -37,7 +37,7 @@
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -171,13 +171,10 @@ public class DownloadTaskQueue implements ITaskQueue {
|
||||
Task task = mExecutePool.getTask(entity.getDownloadUrl());
|
||||
if (task != null) {
|
||||
Log.d(TAG, "从执行池删除任务,删除" + (mExecutePool.removeTask(task) ? "成功" : "失败"));
|
||||
} else {
|
||||
task = mCachePool.getTask(entity.getDownloadUrl());
|
||||
}
|
||||
task = mCachePool.getTask(entity.getDownloadUrl());
|
||||
if (task != null) {
|
||||
Log.d(TAG, "从缓存池删除任务,删除" + (mCachePool.removeTask(task) ? "成功" : "失败"));
|
||||
} else {
|
||||
Log.w(TAG, "没有找到下载链接为【" + entity.getDownloadUrl() + "】的任务");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,15 +121,16 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
case STOP:
|
||||
case CANCEL:
|
||||
mQueue.removeTask(entity);
|
||||
mQueue.removeTask(entity);
|
||||
if (mQueue.size() != Configuration.getInstance().getDownloadNum()) {
|
||||
if (mQueue.size() < Configuration.getInstance().getDownloadNum()) {
|
||||
startNextTask(entity);
|
||||
}
|
||||
break;
|
||||
case COMPLETE:
|
||||
mQueue.removeTask(entity);
|
||||
startNextTask(entity);
|
||||
break;
|
||||
case FAIL:
|
||||
mQueue.removeTask(entity);
|
||||
handleFailTask(entity);
|
||||
break;
|
||||
}
|
||||
@ -223,7 +224,6 @@ public class DownloadSchedulers implements IDownloadSchedulers {
|
||||
* @param entity 通过Handler传递的下载实体
|
||||
*/
|
||||
@Override public void startNextTask(DownloadEntity entity) {
|
||||
mQueue.removeTask(entity);
|
||||
Task newTask = mQueue.getNextTask();
|
||||
if (newTask == null) {
|
||||
Log.w(TAG, "没有下一任务");
|
||||
|
@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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.aria.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
@ -38,7 +53,7 @@ public class SSLContextUtil {
|
||||
* @param caPath 保存在assets目录下的CA证书完整路径
|
||||
*/
|
||||
public static SSLContext getSSLContext(String caAlias, String caPath) {
|
||||
if (TextUtils.isEmpty(caAlias) || TextUtils.isEmpty(caPath)){
|
||||
if (TextUtils.isEmpty(caAlias) || TextUtils.isEmpty(caPath)) {
|
||||
return null;
|
||||
}
|
||||
// Load CAs from an InputStream
|
||||
|
@ -33,6 +33,7 @@ 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;
|
||||
|
||||
@ -104,6 +105,10 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
case R.id.fragment_task:
|
||||
startActivity(new Intent(this, FragmentActivity.class));
|
||||
break;
|
||||
case R.id.notification:
|
||||
SimpleNotification notification = new SimpleNotification(this);
|
||||
notification.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.arialyy.simple.notification;
|
||||
|
||||
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.simple.R;
|
||||
|
||||
/**
|
||||
* Created by Aria.Lao on 2017/1/18.
|
||||
*/
|
||||
|
||||
public class SimpleNotification {
|
||||
private static final String DOWNLOAD_URL =
|
||||
"http://static.gaoshouyou.com/d/6e/e5/ff6ecaaf45e532e6d07747af82357472.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.whit(mContext).addSchedulerListener(new DownloadCallback(mBuilder, mManager));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Aria.whit(mContext)
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadName("notification_test.apk")
|
||||
.setDownloadPath(
|
||||
Environment.getExternalStorageDirectory() + "/Download/notification_test.apk")
|
||||
.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Aria.whit(mContext).load(DOWNLOAD_URL).stop();
|
||||
}
|
||||
|
||||
private static class DownloadCallback extends Aria.SimpleSchedulerListener {
|
||||
NotificationCompat.Builder mBuilder;
|
||||
NotificationManager mManager;
|
||||
|
||||
private DownloadCallback(NotificationCompat.Builder builder, NotificationManager manager) {
|
||||
mBuilder = builder;
|
||||
mManager = manager;
|
||||
}
|
||||
|
||||
@Override public void onTaskStart(Task task) {
|
||||
super.onTaskStart(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskPre(Task task) {
|
||||
super.onTaskPre(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskStop(Task task) {
|
||||
super.onTaskStop(task);
|
||||
}
|
||||
|
||||
@Override public void onTaskRunning(Task task) {
|
||||
super.onTaskRunning(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());
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onTaskComplete(Task task) {
|
||||
super.onTaskComplete(task);
|
||||
if (mBuilder != null) {
|
||||
mBuilder.setProgress(100, 100, false);
|
||||
mManager.notify(mNotifiyId, mBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void onTaskCancel(Task task) {
|
||||
super.onTaskCancel(task);
|
||||
}
|
||||
}
|
||||
}
|
@ -89,7 +89,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
case DOWNLOAD_PRE:
|
||||
mSize.setText(CommonUtil.formatFileSize((Long) msg.obj));
|
||||
setBtState(false);
|
||||
mStart.setText("暂停");
|
||||
//mStart.setText("暂停");
|
||||
break;
|
||||
case DOWNLOAD_FAILE:
|
||||
Toast.makeText(SingleTaskActivity.this, "下载失败", Toast.LENGTH_SHORT).show();
|
||||
@ -119,11 +119,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
mStart.setText("重新开始?");
|
||||
mCancel.setEnabled(false);
|
||||
setBtState(true);
|
||||
|
||||
//String path = Environment.getExternalStorageDirectory().getPath() + "/test.jpg";
|
||||
//Bitmap bm = BitmapFactory.decodeFile(path);
|
||||
//mImg.setImageBitmap(bm);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -201,8 +196,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
|
||||
.load(DOWNLOAD_URL)
|
||||
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
|
||||
.setDownloadName("test.apk")
|
||||
//.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.jpg")
|
||||
//.setDownloadName("test.jpg")
|
||||
.start();
|
||||
}
|
||||
|
||||
|
@ -56,5 +56,14 @@
|
||||
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>
|
||||
|
Reference in New Issue
Block a user