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.content.Context; | 8 import android.content.Context; |
9 import android.util.Pair; | 9 import android.util.Pair; |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 /** | 45 /** |
46 * Called to display the download succeeded snackbar. | 46 * Called to display the download succeeded snackbar. |
47 * | 47 * |
48 * @param downloadInfo Info of the download. | 48 * @param downloadInfo Info of the download. |
49 * @param downloadId Id of the download. | 49 * @param downloadId Id of the download. |
50 * @param canBeResolved Whether the download can be resolved to any activity
. | 50 * @param canBeResolved Whether the download can be resolved to any activity
. |
51 */ | 51 */ |
52 public void onDownloadSucceeded( | 52 public void onDownloadSucceeded( |
53 DownloadInfo downloadInfo, final long downloadId, boolean canBeResol
ved) { | 53 DownloadInfo downloadInfo, final long downloadId, boolean canBeResol
ved) { |
54 if (getSnackbarManager() == null) return; | 54 if (getSnackbarManager() == null) return; |
55 Snackbar snackbar = Snackbar.make(mContext.getString( | 55 Snackbar snackbar = Snackbar.make( |
56 R.string.download_succeeded_message, downloadInfo.getFileName())
, this); | 56 mContext.getString(R.string.download_succeeded_message, download
Info.getFileName()), |
| 57 this, Snackbar.TYPE_NOTIFICATION); |
57 // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the
same time. | 58 // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the
same time. |
58 snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(fa
lse); | 59 snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(fa
lse); |
59 Pair<DownloadInfo, Long> actionData = null; | 60 Pair<DownloadInfo, Long> actionData = null; |
60 if (canBeResolved) { | 61 if (canBeResolved) { |
61 actionData = Pair.create(downloadInfo, downloadId); | 62 actionData = Pair.create(downloadInfo, downloadId); |
62 } | 63 } |
63 // Show downloads app if the download cannot be resolved to any activity
. | 64 // Show downloads app if the download cannot be resolved to any activity
. |
64 snackbar.setAction( | 65 snackbar.setAction( |
65 mContext.getString(R.string.open_downloaded_label), actionData); | 66 mContext.getString(R.string.open_downloaded_label), actionData); |
66 getSnackbarManager().showSnackbar(snackbar); | 67 getSnackbarManager().showSnackbar(snackbar); |
67 } | 68 } |
68 | 69 |
69 /** | 70 /** |
70 * Called to display the download failed snackbar. | 71 * Called to display the download failed snackbar. |
71 * | 72 * |
72 * @param filename File name of the failed download. | 73 * @param filename File name of the failed download. |
73 * @param whether to show all downloads in case the failure is caused by dup
licated files. | 74 * @param whether to show all downloads in case the failure is caused by dup
licated files. |
74 */ | 75 */ |
75 public void onDownloadFailed(String errorMessage, boolean showAllDownloads)
{ | 76 public void onDownloadFailed(String errorMessage, boolean showAllDownloads)
{ |
76 if (getSnackbarManager() == null) return; | 77 if (getSnackbarManager() == null) return; |
77 // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the
same time. | 78 // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the
same time. |
78 Snackbar snackbar = Snackbar.make(errorMessage, this) | 79 Snackbar snackbar = Snackbar.make(errorMessage, this, Snackbar.TYPE_NOTI
FICATION) |
79 .setSingleLine(false) | 80 .setSingleLine(false) |
80 .setDuration(SNACKBAR_DURATION_IN_MILLISECONDS); | 81 .setDuration(SNACKBAR_DURATION_IN_MILLISECONDS); |
81 if (showAllDownloads) { | 82 if (showAllDownloads) { |
82 snackbar.setAction( | 83 snackbar.setAction( |
83 mContext.getString(R.string.open_downloaded_label), | 84 mContext.getString(R.string.open_downloaded_label), |
84 null); | 85 null); |
85 } | 86 } |
86 getSnackbarManager().showSnackbar(snackbar); | 87 getSnackbarManager().showSnackbar(snackbar); |
87 } | 88 } |
88 | 89 |
89 public SnackbarManager getSnackbarManager() { | 90 public SnackbarManager getSnackbarManager() { |
90 Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); | 91 Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); |
91 if (activity != null && ApplicationStatus.hasVisibleActivities() | 92 if (activity != null && ApplicationStatus.hasVisibleActivities() |
92 && activity instanceof SnackbarManager.SnackbarManageable) { | 93 && activity instanceof SnackbarManager.SnackbarManageable) { |
93 return ((SnackbarManager.SnackbarManageable) activity).getSnackbarMa
nager(); | 94 return ((SnackbarManager.SnackbarManageable) activity).getSnackbarMa
nager(); |
94 } | 95 } |
95 return null; | 96 return null; |
96 } | 97 } |
97 } | 98 } |
OLD | NEW |