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.enhancedbookmarks; | 5 package org.chromium.chrome.browser.enhancedbookmarks; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.ActivityOptions; | 9 import android.app.ActivityOptions; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.os.Build; | 11 import android.os.Build; |
12 import android.preference.PreferenceManager; | 12 import android.preference.PreferenceManager; |
13 import android.support.v4.widget.DrawerLayout; | 13 import android.support.v4.widget.DrawerLayout; |
14 import android.util.Log; | 14 import android.util.Log; |
15 import android.view.Gravity; | 15 import android.view.Gravity; |
16 import android.view.View; | 16 import android.view.View; |
17 import android.view.ViewGroup; | 17 import android.view.ViewGroup; |
18 import android.widget.ViewSwitcher; | 18 import android.widget.ViewSwitcher; |
19 | 19 |
20 import com.google.android.apps.chrome.R; | 20 import com.google.android.apps.chrome.R; |
21 | 21 |
22 import org.chromium.base.ObserverList; | 22 import org.chromium.base.ObserverList; |
23 import org.chromium.base.metrics.RecordHistogram; | 23 import org.chromium.base.metrics.RecordHistogram; |
24 import org.chromium.chrome.browser.BookmarksBridge.BookmarkItem; | 24 import org.chromium.chrome.browser.BookmarksBridge.BookmarkItem; |
25 import org.chromium.chrome.browser.BookmarksBridge.BookmarkModelObserver; | 25 import org.chromium.chrome.browser.BookmarksBridge.BookmarkModelObserver; |
26 import org.chromium.chrome.browser.UrlConstants; | 26 import org.chromium.chrome.browser.UrlConstants; |
| 27 import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksBridge; |
27 import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksBridge.Fi
ltersObserver; | 28 import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksBridge.Fi
ltersObserver; |
28 import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksModel; | 29 import org.chromium.chrome.browser.enhanced_bookmarks.EnhancedBookmarksModel; |
29 import org.chromium.chrome.browser.enhanced_bookmarks.LaunchLocation; | 30 import org.chromium.chrome.browser.enhanced_bookmarks.LaunchLocation; |
| 31 import org.chromium.chrome.browser.enhanced_bookmarks.ViewMode; |
30 import org.chromium.chrome.browser.ntp.NewTabPageUma; | 32 import org.chromium.chrome.browser.ntp.NewTabPageUma; |
31 import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim; | 33 import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim; |
32 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; | 34 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; |
33 import org.chromium.components.bookmarks.BookmarkId; | 35 import org.chromium.components.bookmarks.BookmarkId; |
34 import org.chromium.ui.base.DeviceFormFactor; | 36 import org.chromium.ui.base.DeviceFormFactor; |
35 | 37 |
36 import java.io.UnsupportedEncodingException; | 38 import java.io.UnsupportedEncodingException; |
37 import java.net.URLDecoder; | 39 import java.net.URLDecoder; |
38 import java.net.URLEncoder; | 40 import java.net.URLEncoder; |
39 import java.util.ArrayList; | 41 import java.util.ArrayList; |
40 import java.util.HashSet; | 42 import java.util.HashSet; |
41 import java.util.List; | 43 import java.util.List; |
42 import java.util.Set; | 44 import java.util.Set; |
43 import java.util.Stack; | 45 import java.util.Stack; |
44 | 46 |
45 /** | 47 /** |
46 * The new bookmark manager that is planned to replace the existing bookmark man
ager. It holds all | 48 * The new bookmark manager that is planned to replace the existing bookmark man
ager. It holds all |
47 * views and shared logics between tablet and phone. For tablet/phone specific l
ogics, see | 49 * views and shared logics between tablet and phone. For tablet/phone specific l
ogics, see |
48 * {@link EnhancedBookmarkActivity} (phone) and {@link EnhancedBookmarkPage} (ta
blet). | 50 * {@link EnhancedBookmarkActivity} (phone) and {@link EnhancedBookmarkPage} (ta
blet). |
49 */ | 51 */ |
50 public class EnhancedBookmarkManager implements EnhancedBookmarkDelegate { | 52 public class EnhancedBookmarkManager implements EnhancedBookmarkDelegate { |
51 private static final String PREF_LAST_USED_URL = "enhanced_bookmark_last_use
d_url"; | 53 private static final String PREF_LAST_USED_URL = "enhanced_bookmark_last_use
d_url"; |
52 static final String PREF_WAS_IN_LIST_MODE = "enhanced_bookmark_list_mode_cho
ice"; | 54 static final String PREF_WAS_IN_LIST_MODE = "enhanced_bookmark_list_mode_cho
ice"; |
53 // TODO(ianwen): upstream these metrics upstream. | |
54 // UI modes for bookmarks presentation. Default option is grid mode. | |
55 static final int DEFAULT_MODE = 0; | |
56 static final int LIST_MODE = 1; | |
57 static final int GRID_MODE = 2; | |
58 | 55 |
59 private Activity mActivity; | 56 private Activity mActivity; |
60 private ViewGroup mMainView; | 57 private ViewGroup mMainView; |
61 private EnhancedBookmarksModel mEnhancedBookmarksModel; | 58 private EnhancedBookmarksModel mEnhancedBookmarksModel; |
62 private EnhancedBookmarkUndoController mUndoController; | 59 private EnhancedBookmarkUndoController mUndoController; |
63 private final ObserverList<EnhancedBookmarkUIObserver> mUIObservers = | 60 private final ObserverList<EnhancedBookmarkUIObserver> mUIObservers = |
64 new ObserverList<EnhancedBookmarkUIObserver>(); | 61 new ObserverList<EnhancedBookmarkUIObserver>(); |
65 private Set<BookmarkId> mSelectedBookmarks = new HashSet<>(); | 62 private Set<BookmarkId> mSelectedBookmarks = new HashSet<>(); |
66 private boolean mListModeEnabled; | 63 private boolean mListModeEnabled; |
67 private EnhancedBookmarkStateChangeListener mUrlChangeListener; | 64 private EnhancedBookmarkStateChangeListener mUrlChangeListener; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 * Fetches url to preference. Note this method should be used after the main
view is attached to | 279 * Fetches url to preference. Note this method should be used after the main
view is attached to |
283 * an activity. | 280 * an activity. |
284 */ | 281 */ |
285 private String getUrlFromPreference() { | 282 private String getUrlFromPreference() { |
286 return PreferenceManager.getDefaultSharedPreferences(mActivity).getStrin
g( | 283 return PreferenceManager.getDefaultSharedPreferences(mActivity).getStrin
g( |
287 PREF_LAST_USED_URL, UrlConstants.BOOKMARKS_URL); | 284 PREF_LAST_USED_URL, UrlConstants.BOOKMARKS_URL); |
288 } | 285 } |
289 | 286 |
290 private void saveListModePreference() { | 287 private void saveListModePreference() { |
291 PreferenceManager.getDefaultSharedPreferences(mActivity).edit() | 288 PreferenceManager.getDefaultSharedPreferences(mActivity).edit() |
292 .putInt(PREF_WAS_IN_LIST_MODE, mListModeEnabled ? LIST_MODE : GR
ID_MODE).apply(); | 289 .putInt(PREF_WAS_IN_LIST_MODE, mListModeEnabled ? ViewMode.LIST
: ViewMode.GRID) |
| 290 .apply(); |
293 } | 291 } |
294 | 292 |
295 private boolean getListModePreference() { | 293 private boolean getListModePreference() { |
296 int mode = PreferenceManager.getDefaultSharedPreferences(mActivity).getI
nt( | 294 int mode = PreferenceManager.getDefaultSharedPreferences(mActivity).getI
nt( |
297 PREF_WAS_IN_LIST_MODE, DEFAULT_MODE); | 295 PREF_WAS_IN_LIST_MODE, ViewMode.DEFAULT); |
298 return mode == LIST_MODE ? true : false; | 296 |
| 297 if (mode == ViewMode.DEFAULT) mode = EnhancedBookmarksBridge.getDefaultV
iewMode(); |
| 298 |
| 299 return mode == ViewMode.LIST ? true : false; |
299 } | 300 } |
300 | 301 |
301 private void initListModeOptionTo(boolean isListModeEnabled) { | 302 private void initListModeOptionTo(boolean isListModeEnabled) { |
302 mListModeEnabled = isListModeEnabled; | 303 mListModeEnabled = isListModeEnabled; |
303 for (EnhancedBookmarkUIObserver observer: mUIObservers) { | 304 for (EnhancedBookmarkUIObserver observer: mUIObservers) { |
304 observer.onListModeChange(isListModeEnabled); | 305 observer.onListModeChange(isListModeEnabled); |
305 } | 306 } |
306 // Every time the enhanced bookmark manager launches or the user clicks
the list-mode | 307 // Every time the enhanced bookmark manager launches or the user clicks
the list-mode |
307 // toggle, we record the list view state. | 308 // toggle, we record the list view state. |
308 int listViewstate = PreferenceManager.getDefaultSharedPreferences(getVie
w().getContext()) | 309 int listViewstate = PreferenceManager.getDefaultSharedPreferences(getVie
w().getContext()) |
309 .getInt(EnhancedBookmarkManager.PREF_WAS_IN_LIST_MODE, | 310 .getInt(EnhancedBookmarkManager.PREF_WAS_IN_LIST_MODE, |
310 EnhancedBookmarkManager.DEFAULT_MODE); | 311 ViewMode.DEFAULT); |
311 RecordHistogram.recordEnumeratedHistogram("EnhancedBookmarks.ViewMode",
listViewstate, 3); | 312 RecordHistogram.recordEnumeratedHistogram("EnhancedBookmarks.ViewMode",
listViewstate, 3); |
312 } | 313 } |
313 | 314 |
314 /** | 315 /** |
315 * This is the ultimate internal method that updates UI and controls backsta
ck. And it is the | 316 * This is the ultimate internal method that updates UI and controls backsta
ck. And it is the |
316 * only method that pushes states to {@link #mStateStack}. | 317 * only method that pushes states to {@link #mStateStack}. |
317 * <p> | 318 * <p> |
318 * If the given state is not valid, all_bookmark state will be shown. Afterw
ards, this method | 319 * If the given state is not valid, all_bookmark state will be shown. Afterw
ards, this method |
319 * checks the current state: if currently in loading state, it pops it out a
nd adds the new | 320 * checks the current state: if currently in loading state, it pops it out a
nd adds the new |
320 * state to the back stack. It also notifies the {@link #mUrlChangeListener}
(if any) that the | 321 * state to the back stack. It also notifies the {@link #mUrlChangeListener}
(if any) that the |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 } | 640 } |
640 | 641 |
641 @Override | 642 @Override |
642 public boolean equals(Object obj) { | 643 public boolean equals(Object obj) { |
643 if (!(obj instanceof UIState)) return false; | 644 if (!(obj instanceof UIState)) return false; |
644 UIState other = (UIState) obj; | 645 UIState other = (UIState) obj; |
645 return mState == other.mState && mUrl.equals(other.mUrl); | 646 return mState == other.mState && mUrl.equals(other.mUrl); |
646 } | 647 } |
647 } | 648 } |
648 } | 649 } |
OLD | NEW |