OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.history; | 5 package org.chromium.chrome.browser.history; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.ActivityManager; | 8 import android.app.ActivityManager; |
9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.graphics.Rect; | 12 import android.graphics.Rect; |
13 import android.net.Uri; | 13 import android.net.Uri; |
14 import android.provider.Browser; | 14 import android.provider.Browser; |
15 import android.support.annotation.Nullable; | |
16 import android.support.annotation.VisibleForTesting; | 15 import android.support.annotation.VisibleForTesting; |
17 import android.support.graphics.drawable.VectorDrawableCompat; | 16 import android.support.graphics.drawable.VectorDrawableCompat; |
18 import android.support.v7.widget.LinearLayoutManager; | 17 import android.support.v7.widget.LinearLayoutManager; |
19 import android.support.v7.widget.RecyclerView; | 18 import android.support.v7.widget.RecyclerView; |
20 import android.support.v7.widget.RecyclerView.OnScrollListener; | 19 import android.support.v7.widget.RecyclerView.OnScrollListener; |
| 20 import android.support.v7.widget.Toolbar; |
21 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; | 21 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; |
22 import android.view.LayoutInflater; | 22 import android.view.LayoutInflater; |
23 import android.view.MenuItem; | 23 import android.view.MenuItem; |
24 import android.view.View; | |
25 import android.view.ViewGroup; | 24 import android.view.ViewGroup; |
26 import android.widget.TextView; | 25 import android.widget.TextView; |
27 | 26 |
28 import org.chromium.base.ApiCompatibilityUtils; | 27 import org.chromium.base.ApiCompatibilityUtils; |
29 import org.chromium.base.ContextUtils; | 28 import org.chromium.base.ContextUtils; |
30 import org.chromium.base.metrics.RecordHistogram; | 29 import org.chromium.base.metrics.RecordHistogram; |
31 import org.chromium.base.metrics.RecordUserAction; | 30 import org.chromium.base.metrics.RecordUserAction; |
32 import org.chromium.chrome.R; | 31 import org.chromium.chrome.R; |
33 import org.chromium.chrome.browser.IntentHandler; | 32 import org.chromium.chrome.browser.IntentHandler; |
34 import org.chromium.chrome.browser.NativePage; | |
35 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 33 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
36 import org.chromium.chrome.browser.favicon.LargeIconBridge; | 34 import org.chromium.chrome.browser.favicon.LargeIconBridge; |
37 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | 35 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
38 import org.chromium.chrome.browser.profiles.Profile; | 36 import org.chromium.chrome.browser.profiles.Profile; |
39 import org.chromium.chrome.browser.signin.SigninManager; | 37 import org.chromium.chrome.browser.signin.SigninManager; |
40 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 38 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
41 import org.chromium.chrome.browser.snackbar.Snackbar; | 39 import org.chromium.chrome.browser.snackbar.Snackbar; |
42 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; | 40 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; |
43 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; | 41 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; |
44 import org.chromium.chrome.browser.util.IntentUtils; | 42 import org.chromium.chrome.browser.util.IntentUtils; |
(...skipping 14 matching lines...) Expand all Loading... |
59 SnackbarController { | 57 SnackbarController { |
60 private static final int FAVICON_MAX_CACHE_SIZE_BYTES = 10 * 1024 * 1024; //
10MB | 58 private static final int FAVICON_MAX_CACHE_SIZE_BYTES = 10 * 1024 * 1024; //
10MB |
61 private static final int MEGABYTES_TO_BYTES = 1024 * 1024; | 59 private static final int MEGABYTES_TO_BYTES = 1024 * 1024; |
62 private static final String METRICS_PREFIX = "Android.HistoryPage."; | 60 private static final String METRICS_PREFIX = "Android.HistoryPage."; |
63 | 61 |
64 private static HistoryProvider sProviderForTests; | 62 private static HistoryProvider sProviderForTests; |
65 | 63 |
66 private final int mListItemLateralShadowSizePx; | 64 private final int mListItemLateralShadowSizePx; |
67 | 65 |
68 private final Activity mActivity; | 66 private final Activity mActivity; |
69 private final boolean mIsDisplayedInNativePage; | 67 private final boolean mIsSeparateActivity; |
70 private final SelectableListLayout<HistoryItem> mSelectableListLayout; | 68 private final SelectableListLayout<HistoryItem> mSelectableListLayout; |
71 private final HistoryAdapter mHistoryAdapter; | 69 private final HistoryAdapter mHistoryAdapter; |
72 private final SelectionDelegate<HistoryItem> mSelectionDelegate; | 70 private final SelectionDelegate<HistoryItem> mSelectionDelegate; |
73 private final HistoryManagerToolbar mToolbar; | 71 private final HistoryManagerToolbar mToolbar; |
74 private final TextView mEmptyView; | 72 private final TextView mEmptyView; |
75 private final RecyclerView mRecyclerView; | 73 private final RecyclerView mRecyclerView; |
76 private LargeIconBridge mLargeIconBridge; | 74 private LargeIconBridge mLargeIconBridge; |
77 | 75 |
78 private boolean mIsSearching; | 76 private boolean mIsSearching; |
79 | 77 |
80 /** | 78 /** |
81 * Creates a new HistoryManager. | 79 * Creates a new HistoryManager. |
82 * @param activity The Activity associated with the HistoryManager. | 80 * @param activity The Activity associated with the HistoryManager. |
| 81 * @param isSeparateActivity Whether the history UI will be shown in a separ
ate activity than |
| 82 * the main Chrome activity. |
83 */ | 83 */ |
84 @SuppressWarnings("unchecked") // mSelectableListLayout | 84 @SuppressWarnings("unchecked") // mSelectableListLayout |
85 public HistoryManager(Activity activity, @Nullable NativePage nativePage) { | 85 public HistoryManager(Activity activity, boolean isSeparateActivity) { |
86 mActivity = activity; | 86 mActivity = activity; |
87 mIsDisplayedInNativePage = nativePage != null; | 87 mIsSeparateActivity = isSeparateActivity; |
88 | 88 |
89 mSelectionDelegate = new SelectionDelegate<>(); | 89 mSelectionDelegate = new SelectionDelegate<>(); |
90 mSelectionDelegate.addObserver(this); | 90 mSelectionDelegate.addObserver(this); |
91 mHistoryAdapter = new HistoryAdapter(mSelectionDelegate, this, | 91 mHistoryAdapter = new HistoryAdapter(mSelectionDelegate, this, |
92 sProviderForTests != null ? sProviderForTests : new BrowsingHist
oryBridge()); | 92 sProviderForTests != null ? sProviderForTests : new BrowsingHist
oryBridge()); |
93 | 93 |
94 // 1. Create SelectableListLayout. | 94 // 1. Create SelectableListLayout. |
95 mSelectableListLayout = | 95 mSelectableListLayout = |
96 (SelectableListLayout<HistoryItem>) LayoutInflater.from(activity
).inflate( | 96 (SelectableListLayout<HistoryItem>) LayoutInflater.from(activity
).inflate( |
97 R.layout.history_main, null); | 97 R.layout.history_main, null); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 }}); | 159 }}); |
160 | 160 |
161 // 9. Listen to changes in sign in state. | 161 // 9. Listen to changes in sign in state. |
162 SigninManager.get(mActivity).addSignInStateObserver(this); | 162 SigninManager.get(mActivity).addSignInStateObserver(this); |
163 | 163 |
164 recordUserAction("Show"); | 164 recordUserAction("Show"); |
165 } | 165 } |
166 | 166 |
167 /** | 167 /** |
168 * @return Whether the history manager UI is displayed in a native page. | 168 * @return Whether the history manager UI is displayed in a separate activit
y than the main |
| 169 * Chrome activity. |
169 */ | 170 */ |
170 public boolean isDisplayedInNativePage() { | 171 public boolean isDisplayedInSeparateActivity() { |
171 return mIsDisplayedInNativePage; | 172 return mIsSeparateActivity; |
172 } | 173 } |
173 | 174 |
174 @Override | 175 @Override |
175 public boolean onMenuItemClick(MenuItem item) { | 176 public boolean onMenuItemClick(MenuItem item) { |
176 mToolbar.hideOverflowMenu(); | 177 mToolbar.hideOverflowMenu(); |
177 | 178 |
178 if (item.getItemId() == R.id.close_menu_id && !isDisplayedInNativePage()
) { | 179 if (item.getItemId() == R.id.close_menu_id && isDisplayedInSeparateActiv
ity()) { |
179 mActivity.finish(); | 180 mActivity.finish(); |
180 return true; | 181 return true; |
181 } else if (item.getItemId() == R.id.selection_mode_open_in_new_tab) { | 182 } else if (item.getItemId() == R.id.selection_mode_open_in_new_tab) { |
182 openItemsInNewTabs(mSelectionDelegate.getSelectedItems(), false); | 183 openItemsInNewTabs(mSelectionDelegate.getSelectedItems(), false); |
183 mSelectionDelegate.clearSelection(); | 184 mSelectionDelegate.clearSelection(); |
184 return true; | 185 return true; |
185 } else if (item.getItemId() == R.id.selection_mode_copy_link) { | 186 } else if (item.getItemId() == R.id.selection_mode_copy_link) { |
186 recordUserActionWithOptionalSearch("CopyLink"); | 187 recordUserActionWithOptionalSearch("CopyLink"); |
187 Clipboard clipboard = new Clipboard(mActivity); | 188 Clipboard clipboard = new Clipboard(mActivity); |
188 clipboard.setText(mSelectionDelegate.getSelectedItems().get(0).getUr
l()); | 189 clipboard.setText(mSelectionDelegate.getSelectedItems().get(0).getUr
l()); |
(...skipping 28 matching lines...) Expand all Loading... |
217 } | 218 } |
218 | 219 |
219 /** | 220 /** |
220 * @return The view that shows the main browsing history UI. | 221 * @return The view that shows the main browsing history UI. |
221 */ | 222 */ |
222 public ViewGroup getView() { | 223 public ViewGroup getView() { |
223 return mSelectableListLayout; | 224 return mSelectableListLayout; |
224 } | 225 } |
225 | 226 |
226 /** | 227 /** |
227 * See {@link SelectableListLayout#detachContentView()}. | 228 * See {@link SelectableListLayout#detachToolbarView()}. |
228 */ | 229 */ |
229 public View detachContentView() { | 230 public Toolbar detachToolbarView() { |
230 return mSelectableListLayout.detachContentView(); | 231 return mSelectableListLayout.detachToolbarView(); |
231 } | 232 } |
232 | 233 |
233 /** | 234 /** |
234 * @return The vertical scroll offset of the content view. | 235 * @return The vertical scroll offset of the content view. |
235 */ | 236 */ |
236 public int getVerticalScrollOffset() { | 237 public int getVerticalScrollOffset() { |
237 return mRecyclerView.computeVerticalScrollOffset(); | 238 return mRecyclerView.computeVerticalScrollOffset(); |
238 } | 239 } |
239 | 240 |
240 /** | 241 /** |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 @Override | 432 @Override |
432 public void onAction(Object actionData) { | 433 public void onAction(Object actionData) { |
433 // Handler for the link copied snackbar. Do nothing. | 434 // Handler for the link copied snackbar. Do nothing. |
434 } | 435 } |
435 | 436 |
436 @Override | 437 @Override |
437 public void onDismissNoAction(Object actionData) { | 438 public void onDismissNoAction(Object actionData) { |
438 // Handler for the link copied snackbar. Do nothing. | 439 // Handler for the link copied snackbar. Do nothing. |
439 } | 440 } |
440 } | 441 } |
OLD | NEW |