| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
| 6 | 6 |
| 7 import android.app.DownloadManager; | 7 import android.app.DownloadManager; |
| 8 import android.app.Notification; | 8 import android.app.Notification; |
| 9 import android.app.NotificationManager; | 9 import android.app.NotificationManager; |
| 10 import android.app.PendingIntent; | 10 import android.app.PendingIntent; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 String duration = formatRemainingTime(mContext, timeRemainingInMilli
s); | 212 String duration = formatRemainingTime(mContext, timeRemainingInMilli
s); |
| 213 builder.setContentText(duration); | 213 builder.setContentText(duration); |
| 214 if (Build.VERSION.CODENAME.equals("N") | 214 if (Build.VERSION.CODENAME.equals("N") |
| 215 || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { | 215 || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { |
| 216 builder.setSubText(percentText); | 216 builder.setSubText(percentText); |
| 217 } else { | 217 } else { |
| 218 builder.setContentInfo(percentText); | 218 builder.setContentInfo(percentText); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 int notificationId = getNotificationId(downloadGuid); | 221 int notificationId = getNotificationId(downloadGuid); |
| 222 addOrReplaceSharedPreferenceEntry(new DownloadSharedPreferenceEntry( | 222 addOrReplaceSharedPreferenceEntry(new DownloadSharedPreferenceEntry(noti
ficationId, |
| 223 notificationId, isOffTheRecord, canDownloadWhileMetered, downloa
dGuid, fileName)); | 223 isOffTheRecord, canDownloadWhileMetered, downloadGuid, fileName, |
| 224 DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD)); |
| 224 if (startTime > 0) builder.setWhen(startTime); | 225 if (startTime > 0) builder.setWhen(startTime); |
| 225 Intent cancelIntent = buildActionIntent( | 226 Intent cancelIntent = buildActionIntent( |
| 226 ACTION_DOWNLOAD_CANCEL, notificationId, downloadGuid, fileName); | 227 ACTION_DOWNLOAD_CANCEL, notificationId, downloadGuid, fileName); |
| 227 builder.addAction(R.drawable.bookmark_cancel_active, | 228 builder.addAction(R.drawable.bookmark_cancel_active, |
| 228 mContext.getResources().getString(R.string.download_notification
_cancel_button), | 229 mContext.getResources().getString(R.string.download_notification
_cancel_button), |
| 229 buildPendingIntent(cancelIntent, notificationId)); | 230 buildPendingIntent(cancelIntent, notificationId)); |
| 230 Intent pauseIntent = buildActionIntent( | 231 Intent pauseIntent = buildActionIntent( |
| 231 ACTION_DOWNLOAD_PAUSE, notificationId, downloadGuid, fileName); | 232 ACTION_DOWNLOAD_PAUSE, notificationId, downloadGuid, fileName); |
| 232 builder.addAction(R.drawable.ic_vidcontrol_pause, | 233 builder.addAction(R.drawable.ic_vidcontrol_pause, |
| 233 mContext.getResources().getString(R.string.download_notification
_pause_button), | 234 mContext.getResources().getString(R.string.download_notification
_pause_button), |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (intent.getAction() == ACTION_DOWNLOAD_RESUME_ALL) return null; | 417 if (intent.getAction() == ACTION_DOWNLOAD_RESUME_ALL) return null; |
| 417 String guid = IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNLOAD_GUID
); | 418 String guid = IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNLOAD_GUID
); |
| 418 DownloadSharedPreferenceEntry entry = getDownloadSharedPreferenceEntry(g
uid); | 419 DownloadSharedPreferenceEntry entry = getDownloadSharedPreferenceEntry(g
uid); |
| 419 if (entry != null) return entry; | 420 if (entry != null) return entry; |
| 420 int notificationId = IntentUtils.safeGetIntExtra( | 421 int notificationId = IntentUtils.safeGetIntExtra( |
| 421 intent, EXTRA_DOWNLOAD_NOTIFICATION_ID, -1); | 422 intent, EXTRA_DOWNLOAD_NOTIFICATION_ID, -1); |
| 422 String fileName = IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNLOAD_
FILE_NAME); | 423 String fileName = IntentUtils.safeGetStringExtra(intent, EXTRA_DOWNLOAD_
FILE_NAME); |
| 423 boolean metered = DownloadManagerService.isActiveNetworkMetered(mContext
); | 424 boolean metered = DownloadManagerService.isActiveNetworkMetered(mContext
); |
| 424 boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra( | 425 boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra( |
| 425 intent, EXTRA_DOWNLOAD_IS_OFF_THE_RECORD, false); | 426 intent, EXTRA_DOWNLOAD_IS_OFF_THE_RECORD, false); |
| 426 return new DownloadSharedPreferenceEntry( | 427 return new DownloadSharedPreferenceEntry(notificationId, isOffTheRecord,
metered, guid, |
| 427 notificationId, isOffTheRecord, metered, guid, fileName); | 428 fileName, DownloadSharedPreferenceEntry.ITEM_TYPE_DOWNLOAD); |
| 428 } | 429 } |
| 429 | 430 |
| 430 /** | 431 /** |
| 431 * Helper method to launch the browser process and handle a download operati
on that is included | 432 * Helper method to launch the browser process and handle a download operati
on that is included |
| 432 * in the given intent. | 433 * in the given intent. |
| 433 * @param intent Intent with the download operation. | 434 * @param intent Intent with the download operation. |
| 434 */ | 435 */ |
| 435 private void handleDownloadOperation(final Intent intent) { | 436 private void handleDownloadOperation(final Intent intent) { |
| 436 final DownloadSharedPreferenceEntry entry = getDownloadEntryFromIntent(i
ntent); | 437 final DownloadSharedPreferenceEntry entry = getDownloadEntryFromIntent(i
ntent); |
| 437 if (intent.getAction() == ACTION_DOWNLOAD_PAUSE) { | 438 if (intent.getAction() == ACTION_DOWNLOAD_PAUSE) { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 return context.getString(R.string.remaining_duration_minutes, minute
s); | 710 return context.getString(R.string.remaining_duration_minutes, minute
s); |
| 710 } else if (minutes > 0) { | 711 } else if (minutes > 0) { |
| 711 return context.getString(R.string.remaining_duration_one_minute); | 712 return context.getString(R.string.remaining_duration_one_minute); |
| 712 } else if (seconds == 1) { | 713 } else if (seconds == 1) { |
| 713 return context.getString(R.string.remaining_duration_one_second); | 714 return context.getString(R.string.remaining_duration_one_second); |
| 714 } else { | 715 } else { |
| 715 return context.getString(R.string.remaining_duration_seconds, second
s); | 716 return context.getString(R.string.remaining_duration_seconds, second
s); |
| 716 } | 717 } |
| 717 } | 718 } |
| 718 } | 719 } |
| OLD | NEW |