Chromium Code Reviews| 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.Activity; | 7 import android.app.Activity; |
| 8 import android.app.NotificationManager; | 8 import android.app.NotificationManager; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 | 10 |
| 11 import org.chromium.base.ApplicationStatus; | 11 import org.chromium.base.ApplicationStatus; |
| 12 import org.chromium.base.BuildInfo; | |
| 12 import org.chromium.chrome.R; | 13 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | |
| 13 import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadBri dge; | 15 import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadBri dge; |
| 14 import org.chromium.chrome.browser.snackbar.Snackbar; | 16 import org.chromium.chrome.browser.snackbar.Snackbar; |
| 15 import org.chromium.chrome.browser.snackbar.SnackbarManager; | 17 import org.chromium.chrome.browser.snackbar.SnackbarManager; |
| 16 | 18 |
| 17 /** | 19 /** |
| 18 * Class for displaying a snackbar when a download completes. | 20 * Class for displaying a snackbar when a download completes. |
| 19 */ | 21 */ |
| 20 public class DownloadSnackbarController implements SnackbarManager.SnackbarContr oller { | 22 public class DownloadSnackbarController implements SnackbarManager.SnackbarContr oller { |
| 21 public static final int INVALID_NOTIFICATION_ID = -1; | 23 public static final int INVALID_NOTIFICATION_ID = -1; |
| 22 private static final int SNACKBAR_DURATION_IN_MILLISECONDS = 5000; | 24 private static final int SNACKBAR_DURATION_IN_MILLISECONDS = 5000; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 * Called to display the download succeeded snackbar. | 69 * Called to display the download succeeded snackbar. |
| 68 * | 70 * |
| 69 * @param downloadInfo Info of the download. | 71 * @param downloadInfo Info of the download. |
| 70 * @param notificationId Notification Id of the successful download. | 72 * @param notificationId Notification Id of the successful download. |
| 71 * @param downloadId Id of the download from Android DownloadManager. | 73 * @param downloadId Id of the download from Android DownloadManager. |
| 72 * @param canBeResolved Whether the download can be resolved to any activity . | 74 * @param canBeResolved Whether the download can be resolved to any activity . |
| 73 */ | 75 */ |
| 74 public void onDownloadSucceeded( | 76 public void onDownloadSucceeded( |
| 75 DownloadInfo downloadInfo, int notificationId, long downloadId, bool ean canBeResolved) { | 77 DownloadInfo downloadInfo, int notificationId, long downloadId, bool ean canBeResolved) { |
| 76 if (getSnackbarManager() == null) return; | 78 if (getSnackbarManager() == null) return; |
| 77 Snackbar snackbar = Snackbar.make( | 79 Snackbar snackbar; |
| 78 mContext.getString(R.string.download_succeeded_message, download Info.getFileName()), | 80 if (getLastTrackedFocusedActivity() instanceof CustomTabActivity) { |
| 79 this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCCEEDE D); | 81 String packageLabel = BuildInfo.getPackageLabel(getLastTrackedFocuse dActivity()); |
| 82 snackbar = Snackbar.make(mContext.getString(R.string.download_succee ded_message, | |
| 83 downloadInfo.getFileName(), package Label), | |
| 84 this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCC EEDED); | |
| 85 } else { | |
| 86 snackbar = Snackbar.make(mContext.getString(R.string.download_succee ded_message_default, | |
| 87 downloadInfo.getFileName()), | |
| 88 this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCC EEDED); | |
| 89 } | |
| 80 // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time. | 90 // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time. |
| 81 snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(fa lse); | 91 snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(fa lse); |
| 82 ActionDataInfo info = null; | 92 ActionDataInfo info = null; |
| 83 if (canBeResolved || downloadInfo.isOfflinePage()) { | 93 if (canBeResolved || downloadInfo.isOfflinePage()) { |
| 84 info = new ActionDataInfo(downloadInfo, notificationId, downloadId); | 94 info = new ActionDataInfo(downloadInfo, notificationId, downloadId); |
| 85 } | 95 } |
| 86 // Show downloads app if the download cannot be resolved to any activity . | 96 // Show downloads app if the download cannot be resolved to any activity . |
| 87 snackbar.setAction( | 97 snackbar.setAction( |
| 88 mContext.getString(R.string.open_downloaded_label), info); | 98 mContext.getString(R.string.open_downloaded_label), info); |
| 89 getSnackbarManager().showSnackbar(snackbar); | 99 getSnackbarManager().showSnackbar(snackbar); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 104 .setSingleLine(false) | 114 .setSingleLine(false) |
| 105 .setDuration(SNACKBAR_DURATION_IN_MILLISECONDS); | 115 .setDuration(SNACKBAR_DURATION_IN_MILLISECONDS); |
| 106 if (showAllDownloads) { | 116 if (showAllDownloads) { |
| 107 snackbar.setAction( | 117 snackbar.setAction( |
| 108 mContext.getString(R.string.open_downloaded_label), | 118 mContext.getString(R.string.open_downloaded_label), |
| 109 null); | 119 null); |
| 110 } | 120 } |
| 111 getSnackbarManager().showSnackbar(snackbar); | 121 getSnackbarManager().showSnackbar(snackbar); |
| 112 } | 122 } |
| 113 | 123 |
| 124 public Activity getLastTrackedFocusedActivity() { | |
|
Ted C
2016/12/28 00:53:47
I would just call this getActivity() and I think i
ltian
2016/12/29 16:31:56
Done.
| |
| 125 return ApplicationStatus.getLastTrackedFocusedActivity(); | |
| 126 } | |
| 127 | |
| 114 public SnackbarManager getSnackbarManager() { | 128 public SnackbarManager getSnackbarManager() { |
| 115 Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); | 129 Activity activity = getLastTrackedFocusedActivity(); |
| 116 if (activity != null && ApplicationStatus.hasVisibleActivities() | 130 if (activity != null && ApplicationStatus.hasVisibleActivities() |
| 117 && activity instanceof SnackbarManager.SnackbarManageable) { | 131 && activity instanceof SnackbarManager.SnackbarManageable) { |
| 118 return ((SnackbarManager.SnackbarManageable) activity).getSnackbarMa nager(); | 132 return ((SnackbarManager.SnackbarManageable) activity).getSnackbarMa nager(); |
| 119 } | 133 } |
| 120 return null; | 134 return null; |
| 121 } | 135 } |
| 122 } | 136 } |
| OLD | NEW |