Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadSnackbarController.java

Issue 2772343003: Android: Remove GetApplicationContext part 1 (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 public void onAction(Object actionData) { 44 public void onAction(Object actionData) {
45 if (!(actionData instanceof ActionDataInfo)) { 45 if (!(actionData instanceof ActionDataInfo)) {
46 DownloadManagerService.openDownloadsPage(mContext); 46 DownloadManagerService.openDownloadsPage(mContext);
47 return; 47 return;
48 } 48 }
49 final ActionDataInfo download = (ActionDataInfo) actionData; 49 final ActionDataInfo download = (ActionDataInfo) actionData;
50 if (download.downloadInfo.isOfflinePage()) { 50 if (download.downloadInfo.isOfflinePage()) {
51 OfflinePageDownloadBridge.openDownloadedPage(download.downloadInfo.g etContentId()); 51 OfflinePageDownloadBridge.openDownloadedPage(download.downloadInfo.g etContentId());
52 return; 52 return;
53 } 53 }
54 DownloadManagerService manager = DownloadManagerService.getDownloadManag erService(mContext); 54 DownloadManagerService manager = DownloadManagerService.getDownloadManag erService();
55 manager.openDownloadedContent(download.downloadInfo, download.systemDown loadId); 55 manager.openDownloadedContent(download.downloadInfo, download.systemDown loadId);
56 if (download.notificationId != INVALID_NOTIFICATION_ID) { 56 if (download.notificationId != INVALID_NOTIFICATION_ID) {
57 NotificationManager notificationManager = 57 NotificationManager notificationManager =
58 (NotificationManager) mContext.getSystemService(Context.NOTI FICATION_SERVICE); 58 (NotificationManager) mContext.getSystemService(Context.NOTI FICATION_SERVICE);
59 notificationManager.cancel( 59 notificationManager.cancel(
60 DownloadNotificationService.NOTIFICATION_NAMESPACE, download .notificationId); 60 DownloadNotificationService.NOTIFICATION_NAMESPACE, download .notificationId);
61 } 61 }
62 } 62 }
63 63
64 @Override 64 @Override
65 public void onDismissNoAction(Object actionData) { 65 public void onDismissNoAction(Object actionData) {
66 } 66 }
67 67
68 /** 68 /**
69 * Called to display the download succeeded snackbar. 69 * Called to display the download succeeded snackbar.
70 * 70 *
71 * @param downloadInfo Info of the download. 71 * @param downloadInfo Info of the download.
72 * @param notificationId Notification Id of the successful download. 72 * @param notificationId Notification Id of the successful download.
73 * @param downloadId Id of the download from Android DownloadManager. 73 * @param downloadId Id of the download from Android DownloadManager.
74 * @param canBeResolved Whether the download can be resolved to any activity . 74 * @param canBeResolved Whether the download can be resolved to any activity .
75 */ 75 */
76 public void onDownloadSucceeded( 76 public void onDownloadSucceeded(
77 DownloadInfo downloadInfo, int notificationId, long downloadId, bool ean canBeResolved) { 77 DownloadInfo downloadInfo, int notificationId, long downloadId, bool ean canBeResolved) {
78 if (getSnackbarManager() == null) return; 78 if (getSnackbarManager() == null) return;
79 Snackbar snackbar; 79 Snackbar snackbar;
80 if (getActivity() instanceof CustomTabActivity) { 80 if (getActivity() instanceof CustomTabActivity) {
81 String packageLabel = BuildInfo.getPackageLabel(getActivity()); 81 String packageLabel = BuildInfo.getPackageLabel();
82 snackbar = Snackbar.make(mContext.getString(R.string.download_succee ded_message, 82 snackbar = Snackbar.make(mContext.getString(R.string.download_succee ded_message,
83 downloadInfo.getFileName(), packageLabel), 83 downloadInfo.getFileName(), packageLabel),
84 this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCC EEDED); 84 this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCC EEDED);
85 } else { 85 } else {
86 snackbar = Snackbar.make(mContext.getString(R.string.download_succee ded_message_default, 86 snackbar = Snackbar.make(mContext.getString(R.string.download_succee ded_message_default,
87 downloadInfo.getFileName()), 87 downloadInfo.getFileName()),
88 this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCC EEDED); 88 this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCC EEDED);
89 } 89 }
90 // 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.
91 snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(fa lse); 91 snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(fa lse);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 public SnackbarManager getSnackbarManager() { 132 public SnackbarManager getSnackbarManager() {
133 Activity activity = getActivity(); 133 Activity activity = getActivity();
134 if (activity != null && activity instanceof SnackbarManager.SnackbarMana geable) { 134 if (activity != null && activity instanceof SnackbarManager.SnackbarMana geable) {
135 return ((SnackbarManager.SnackbarManageable) activity).getSnackbarMa nager(); 135 return ((SnackbarManager.SnackbarManageable) activity).getSnackbarMa nager();
136 } 136 }
137 return null; 137 return null;
138 } 138 }
139 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698