OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.enhancedbookmarks; |
| 6 |
| 7 import android.app.Activity; |
| 8 import android.content.res.Resources; |
| 9 import android.view.View; |
| 10 |
| 11 import com.google.android.apps.chrome.R; |
| 12 |
| 13 import org.chromium.chrome.browser.NativePage; |
| 14 import org.chromium.chrome.browser.Tab; |
| 15 import org.chromium.chrome.browser.UrlConstants; |
| 16 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkDelegate.En
hancedBookmarkStateChangeListener; |
| 17 import org.chromium.content_public.browser.LoadUrlParams; |
| 18 import org.chromium.ui.base.DeviceFormFactor; |
| 19 |
| 20 /** |
| 21 * A native page holding a {@link EnhancedBookmarkManager} on _tablet_. |
| 22 */ |
| 23 public class EnhancedBookmarkPage implements NativePage, EnhancedBookmarkStateCh
angeListener { |
| 24 private final Activity mActivity; |
| 25 private final Tab mTab; |
| 26 private final String mTitle; |
| 27 private final int mBackgroundColor; |
| 28 private final EnhancedBookmarkManager mManager; |
| 29 |
| 30 /** |
| 31 * Create a new instance of an enhanced bookmark page. |
| 32 * @param activity The activity to get context and manage fragments. |
| 33 * @param tab The tab to load urls. |
| 34 * @return Null if this method is called on phone. Otherwise, return a new e
nhanced bookmark |
| 35 * native page for tablet. |
| 36 */ |
| 37 public static EnhancedBookmarkPage buildPage(Activity activity, Tab tab) { |
| 38 if (DeviceFormFactor.isTablet(activity)) return new EnhancedBookmarkPage
(activity, tab); |
| 39 else return null; |
| 40 } |
| 41 |
| 42 private EnhancedBookmarkPage(Activity activity, Tab tab) { |
| 43 mActivity = activity; |
| 44 mTab = tab; |
| 45 mTitle = activity.getString(R.string.bookmarks); |
| 46 mBackgroundColor = activity.getResources().getColor(R.color.default_prim
ary_color); |
| 47 |
| 48 mManager = new EnhancedBookmarkManager(mActivity); |
| 49 Resources res = mActivity.getResources(); |
| 50 mManager.getView().setPadding(0, res.getDimensionPixelSize(R.dimen.tab_s
trip_height) |
| 51 + res.getDimensionPixelSize(R.dimen.toolbar_height_no_shadow), 0
, 0); |
| 52 mManager.setUrlChangeListener(this); |
| 53 } |
| 54 |
| 55 @Override |
| 56 public View getView() { |
| 57 return mManager.getView(); |
| 58 } |
| 59 |
| 60 @Override |
| 61 public String getTitle() { |
| 62 return mTitle; |
| 63 } |
| 64 |
| 65 @Override |
| 66 public String getUrl() { |
| 67 return mManager.getCurrentUrl(); |
| 68 } |
| 69 |
| 70 @Override |
| 71 public String getHost() { |
| 72 return UrlConstants.BOOKMARKS_HOST; |
| 73 } |
| 74 |
| 75 @Override |
| 76 public int getBackgroundColor() { |
| 77 return mBackgroundColor; |
| 78 } |
| 79 |
| 80 @Override |
| 81 public void updateForUrl(String url) { |
| 82 mManager.updateForUrl(url); |
| 83 } |
| 84 |
| 85 @Override |
| 86 public void destroy() { |
| 87 mManager.destroy(); |
| 88 } |
| 89 |
| 90 @Override |
| 91 public void onBookmarkUIStateChange(String url) { |
| 92 mTab.loadUrl(new LoadUrlParams(url)); |
| 93 } |
| 94 } |
OLD | NEW |