parent
							
								
									9cad84127d
								
							
						
					
					
						commit
						82f91eb56c
					
				@ -1,95 +1,99 @@ | 
				
			|||||||
/* | 
					///*
 | 
				
			||||||
 * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
 | 
					// * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
 | 
				
			||||||
 * | 
					// *
 | 
				
			||||||
 * Licensed under the Apache License, Version 2.0 (the "License"); | 
					// * Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 * you may not use this file except in compliance with the License. | 
					// * you may not use this file except in compliance with the License.
 | 
				
			||||||
 * You may obtain a copy of the License at | 
					// * You may obtain a copy of the License at
 | 
				
			||||||
 * | 
					// *
 | 
				
			||||||
 *      http://www.apache.org/licenses/LICENSE-2.0
 | 
					// *      http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 * | 
					// *
 | 
				
			||||||
 * Unless required by applicable law or agreed to in writing, software | 
					// * Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 * distributed under the License is distributed on an "AS IS" BASIS, | 
					// * distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
 * See the License for the specific language governing permissions and | 
					// * See the License for the specific language governing permissions and
 | 
				
			||||||
 * limitations under the License. | 
					// * limitations under the License.
 | 
				
			||||||
 */ | 
					// */
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
package com.arialyy.simple.download; | 
					//package com.arialyy.simple.download;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
import android.app.NotificationManager; | 
					//import android.app.NotificationManager;
 | 
				
			||||||
import android.content.Context; | 
					//import android.content.Context;
 | 
				
			||||||
import android.os.Environment; | 
					//import android.os.Environment;
 | 
				
			||||||
import android.support.v4.app.NotificationCompat; | 
					//import android.support.v4.app.NotificationCompat;
 | 
				
			||||||
import com.arialyy.annotations.Download; | 
					//import com.arialyy.annotations.Download;
 | 
				
			||||||
import com.arialyy.aria.core.Aria; | 
					//import com.arialyy.aria.core.Aria;
 | 
				
			||||||
import com.arialyy.aria.core.download.DownloadTask; | 
					//import com.arialyy.aria.core.download.DownloadTask;
 | 
				
			||||||
import com.arialyy.simple.R; | 
					//import com.arialyy.simple.R;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
/** | 
					///**
 | 
				
			||||||
 * Created by Aria.Lao on 2017/1/18. | 
					// * Created by Aria.Lao on 2017/1/18.
 | 
				
			||||||
 */ | 
					// */
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
public class SimpleNotification { | 
					//public class SimpleNotification {
 | 
				
			||||||
  private static final String DOWNLOAD_URL = | 
					//  private static final String DOWNLOAD_URL =
 | 
				
			||||||
      "http://static.gaoshouyou.com/d/cb/38/f0cb1b2c57388fe14342eecd64bbae65.apk"; | 
					//      "http://static.gaoshouyou.com/d/cb/38/f0cb1b2c57388fe14342eecd64bbae65.apk";
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
  private NotificationManager mManager; | 
					//  private NotificationManager mManager;
 | 
				
			||||||
  private Context mContext; | 
					//  private Context mContext;
 | 
				
			||||||
  private NotificationCompat.Builder mBuilder; | 
					//  private NotificationCompat.Builder mBuilder;
 | 
				
			||||||
  private static final int mNotifiyId = 0; | 
					//  private static final int mNotifiyId = 0;
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
  public SimpleNotification(Context context) { | 
					//  public SimpleNotification(Context context) {
 | 
				
			||||||
    mContext = context; | 
					//    mContext = context;
 | 
				
			||||||
    init(); | 
					//    init();
 | 
				
			||||||
  } | 
					//  }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
  private void init() { | 
					//  private void init() {
 | 
				
			||||||
    mManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); | 
					//    mManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
 | 
				
			||||||
    mBuilder = new NotificationCompat.Builder(mContext); | 
					//    mBuilder = new NotificationCompat.Builder(mContext);
 | 
				
			||||||
    mBuilder.setContentTitle("Aria Download Test") | 
					//    mBuilder.setContentTitle("Aria Download Test")
 | 
				
			||||||
        .setContentText("进度条") | 
					//        .setContentText("进度条")
 | 
				
			||||||
        .setProgress(100, 0, false) | 
					//        .setProgress(100, 0, false)
 | 
				
			||||||
        .setSmallIcon(R.mipmap.ic_launcher); | 
					//        .setSmallIcon(R.mipmap.ic_launcher);
 | 
				
			||||||
    mManager.notify(mNotifiyId, mBuilder.build()); | 
					//    mManager.notify(mNotifiyId, mBuilder.build());
 | 
				
			||||||
    Aria.download(mContext).register(); | 
					//    Aria.download(this).register();
 | 
				
			||||||
  } | 
					//  }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
  public void start() { | 
					//  public void start() {
 | 
				
			||||||
    Aria.download(mContext) | 
					//    Aria.download(this)
 | 
				
			||||||
        .load(DOWNLOAD_URL) | 
					//        .load(DOWNLOAD_URL)
 | 
				
			||||||
        .setDownloadPath(Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk") | 
					//        .setFilePath(Environment.getExternalStorageDirectory() + "/Download/消灭星星.apk")
 | 
				
			||||||
        .start(); | 
					//        .start();
 | 
				
			||||||
  } | 
					//  }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
  public void stop() { | 
					//  public void stop() {
 | 
				
			||||||
    Aria.download(mContext).load(DOWNLOAD_URL).pause(); | 
					//    Aria.download(this).load(DOWNLOAD_URL).stop();
 | 
				
			||||||
  } | 
					//  }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
  @Download.onTaskStart public void onTaskStart(DownloadTask task) { | 
					//  public void destory() {
 | 
				
			||||||
  } | 
					//    Aria.download(this).unRegister();
 | 
				
			||||||
 | 
					//  }
 | 
				
			||||||
  @Download.onTaskPre public void onTaskPre(DownloadTask task) { | 
					//
 | 
				
			||||||
  } | 
					//  @Download.onTaskStart public void onTaskStart(DownloadTask task) {
 | 
				
			||||||
 | 
					//  }
 | 
				
			||||||
  @Download.onTaskStop public void onTaskStop(DownloadTask task) { | 
					//
 | 
				
			||||||
  } | 
					//  @Download.onTaskPre public void onTaskPre(DownloadTask task) {
 | 
				
			||||||
 | 
					//  }
 | 
				
			||||||
  @Download.onTaskRunning public void onTaskRunning(DownloadTask task) { | 
					//
 | 
				
			||||||
    long len = task.getFileSize(); | 
					//  @Download.onTaskStop public void onTaskStop(DownloadTask task) {
 | 
				
			||||||
    int p = (int) (task.getCurrentProgress() * 100 / len); | 
					//  }
 | 
				
			||||||
    if (mBuilder != null) { | 
					//
 | 
				
			||||||
      mBuilder.setProgress(100, p, false); | 
					//  @Download.onTaskRunning public void onTaskRunning(DownloadTask task) {
 | 
				
			||||||
      mManager.notify(mNotifiyId, mBuilder.build()); | 
					//    long len = task.getFileSize();
 | 
				
			||||||
    } | 
					//    int p = (int) (task.getCurrentProgress() * 100 / len);
 | 
				
			||||||
  } | 
					//    if (mBuilder != null) {
 | 
				
			||||||
 | 
					//      mBuilder.setProgress(100, p, false);
 | 
				
			||||||
  @Download.onTaskComplete public void onTaskComplete(DownloadTask task) { | 
					//      mManager.notify(mNotifiyId, mBuilder.build());
 | 
				
			||||||
    if (mBuilder != null) { | 
					//    }
 | 
				
			||||||
      mBuilder.setProgress(100, 100, false); | 
					//  }
 | 
				
			||||||
      mManager.notify(mNotifiyId, mBuilder.build()); | 
					//
 | 
				
			||||||
    } | 
					//  @Download.onTaskComplete public void onTaskComplete(DownloadTask task) {
 | 
				
			||||||
  } | 
					//    if (mBuilder != null) {
 | 
				
			||||||
 | 
					//      mBuilder.setProgress(100, 100, false);
 | 
				
			||||||
  @Download.onTaskCancel public void onTaskCancel(DownloadTask task) { | 
					//      mManager.notify(mNotifiyId, mBuilder.build());
 | 
				
			||||||
  } | 
					//    }
 | 
				
			||||||
} | 
					//  }
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					//  @Download.onTaskCancel public void onTaskCancel(DownloadTask task) {
 | 
				
			||||||
 | 
					//  }
 | 
				
			||||||
 | 
					//}
 | 
				
			||||||
 | 
				
			|||||||
					Loading…
					
					
				
		Reference in new issue