|
@@ -48,8 +48,8 @@ public class DownloadNotification implements IDownloaderClient {
|
|
|
|
|
|
private IDownloaderClient mClientProxy;
|
|
|
final ICustomNotification mCustomNotification;
|
|
|
- private Notification mNotification;
|
|
|
- private Notification mCurrentNotification;
|
|
|
+ private Notification.Builder mNotificationBuilder;
|
|
|
+ private Notification.Builder mCurrentNotificationBuilder;
|
|
|
private CharSequence mLabel;
|
|
|
private String mCurrentText;
|
|
|
private PendingIntent mContentIntent;
|
|
@@ -132,17 +132,14 @@ public class DownloadNotification implements IDownloaderClient {
|
|
|
}
|
|
|
mCurrentText = mContext.getString(stringDownloadID);
|
|
|
mCurrentTitle = mLabel.toString();
|
|
|
- mCurrentNotification.tickerText = mLabel + ": " + mCurrentText;
|
|
|
- mCurrentNotification.icon = iconResource;
|
|
|
- mCurrentNotification.setLatestEventInfo(mContext, mCurrentTitle, mCurrentText,
|
|
|
- mContentIntent);
|
|
|
- if (ongoingEvent) {
|
|
|
- mCurrentNotification.flags |= Notification.FLAG_ONGOING_EVENT;
|
|
|
- } else {
|
|
|
- mCurrentNotification.flags &= ~Notification.FLAG_ONGOING_EVENT;
|
|
|
- mCurrentNotification.flags |= Notification.FLAG_AUTO_CANCEL;
|
|
|
- }
|
|
|
- mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
|
|
|
+ mCurrentNotificationBuilder.setTicker(mLabel + ": " + mCurrentText);
|
|
|
+ mCurrentNotificationBuilder.setSmallIcon(iconResource);
|
|
|
+ mCurrentNotificationBuilder.setContentTitle(mCurrentTitle);
|
|
|
+ mCurrentNotificationBuilder.setContentText(mCurrentText);
|
|
|
+ mCurrentNotificationBuilder.setContentIntent(mContentIntent);
|
|
|
+ mCurrentNotificationBuilder.setOngoing(ongoingEvent);
|
|
|
+ mCurrentNotificationBuilder.setAutoCancel(!ongoingEvent);
|
|
|
+ mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotificationBuilder.build());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -154,10 +151,12 @@ public class DownloadNotification implements IDownloaderClient {
|
|
|
}
|
|
|
if (progress.mOverallTotal <= 0) {
|
|
|
// we just show the text
|
|
|
- mNotification.tickerText = mCurrentTitle;
|
|
|
- mNotification.icon = android.R.drawable.stat_sys_download;
|
|
|
- mNotification.setLatestEventInfo(mContext, mLabel, mCurrentText, mContentIntent);
|
|
|
- mCurrentNotification = mNotification;
|
|
|
+ mNotificationBuilder.setTicker(mCurrentTitle);
|
|
|
+ mNotificationBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
|
|
|
+ mNotificationBuilder.setContentTitle(mCurrentTitle);
|
|
|
+ mNotificationBuilder.setContentText(mCurrentText);
|
|
|
+ mNotificationBuilder.setContentIntent(mContentIntent);
|
|
|
+ mCurrentNotificationBuilder = mNotificationBuilder;
|
|
|
} else {
|
|
|
mCustomNotification.setCurrentBytes(progress.mOverallProgress);
|
|
|
mCustomNotification.setTotalBytes(progress.mOverallTotal);
|
|
@@ -166,9 +165,9 @@ public class DownloadNotification implements IDownloaderClient {
|
|
|
mCustomNotification.setTicker(mLabel + ": " + mCurrentText);
|
|
|
mCustomNotification.setTitle(mLabel);
|
|
|
mCustomNotification.setTimeRemaining(progress.mTimeRemaining);
|
|
|
- mCurrentNotification = mCustomNotification.updateNotification(mContext);
|
|
|
+ mCurrentNotificationBuilder = mCustomNotification.updateNotification(mContext);
|
|
|
}
|
|
|
- mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
|
|
|
+ mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotificationBuilder.build());
|
|
|
}
|
|
|
|
|
|
public interface ICustomNotification {
|
|
@@ -186,7 +185,7 @@ public class DownloadNotification implements IDownloaderClient {
|
|
|
|
|
|
void setTimeRemaining(long timeRemaining);
|
|
|
|
|
|
- Notification updateNotification(Context c);
|
|
|
+ Notification.Builder updateNotification(Context c);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -219,8 +218,8 @@ public class DownloadNotification implements IDownloaderClient {
|
|
|
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
mCustomNotification = CustomNotificationFactory
|
|
|
.createCustomNotification();
|
|
|
- mNotification = new Notification();
|
|
|
- mCurrentNotification = mNotification;
|
|
|
+ mNotificationBuilder = new Notification.Builder(ctx);
|
|
|
+ mCurrentNotificationBuilder = mNotificationBuilder;
|
|
|
|
|
|
}
|
|
|
|