| 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 import android.view.ViewGroup.MarginLayoutParams; | |
| 11 | |
| 12 import org.chromium.base.ApiCompatibilityUtils; | |
| 13 import org.chromium.chrome.R; | |
| 14 import org.chromium.chrome.browser.NativePage; | |
| 15 import org.chromium.chrome.browser.UrlConstants; | |
| 16 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkDelegate.En
hancedBookmarkStateChangeListener; | |
| 17 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; | |
| 18 import org.chromium.chrome.browser.tab.Tab; | |
| 19 import org.chromium.content_public.browser.LoadUrlParams; | |
| 20 | |
| 21 /** | |
| 22 * A native page holding a {@link EnhancedBookmarkManager} on _tablet_. | |
| 23 */ | |
| 24 public class EnhancedBookmarkPage implements NativePage, EnhancedBookmarkStateCh
angeListener { | |
| 25 private final Activity mActivity; | |
| 26 private final Tab mTab; | |
| 27 private final String mTitle; | |
| 28 private final int mBackgroundColor; | |
| 29 private final int mThemeColor; | |
| 30 private EnhancedBookmarkManager mManager; | |
| 31 private String mCurrentUrl; | |
| 32 | |
| 33 /** | |
| 34 * Create a new instance of an enhanced bookmark page. | |
| 35 * @param activity The activity to get context and manage fragments. | |
| 36 * @param tab The tab to load urls. | |
| 37 */ | |
| 38 public EnhancedBookmarkPage(Activity activity, Tab tab) { | |
| 39 mActivity = activity; | |
| 40 mTab = tab; | |
| 41 mTitle = activity.getString(OfflinePageUtils.getStringId(R.string.bookma
rks)); | |
| 42 mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources(
), | |
| 43 R.color.default_primary_color); | |
| 44 mThemeColor = ApiCompatibilityUtils.getColor( | |
| 45 activity.getResources(), R.color.default_primary_color); | |
| 46 | |
| 47 mManager = new EnhancedBookmarkManager(mActivity, false); | |
| 48 Resources res = mActivity.getResources(); | |
| 49 | |
| 50 MarginLayoutParams layoutParams = new MarginLayoutParams( | |
| 51 MarginLayoutParams.MATCH_PARENT, MarginLayoutParams.MATCH_PARENT
); | |
| 52 layoutParams.setMargins(0, | |
| 53 res.getDimensionPixelSize(R.dimen.tab_strip_height) | |
| 54 + res.getDimensionPixelSize(R.dimen.toolbar_height_no_shadow), | |
| 55 0, 0); | |
| 56 mManager.getView().setLayoutParams(layoutParams); | |
| 57 mManager.setUrlChangeListener(this); | |
| 58 } | |
| 59 | |
| 60 @Override | |
| 61 public View getView() { | |
| 62 return mManager.getView(); | |
| 63 } | |
| 64 | |
| 65 @Override | |
| 66 public String getTitle() { | |
| 67 return mTitle; | |
| 68 } | |
| 69 | |
| 70 @Override | |
| 71 public String getUrl() { | |
| 72 return mManager.getCurrentUrl(); | |
| 73 } | |
| 74 | |
| 75 @Override | |
| 76 public String getHost() { | |
| 77 return UrlConstants.BOOKMARKS_HOST; | |
| 78 } | |
| 79 | |
| 80 @Override | |
| 81 public int getBackgroundColor() { | |
| 82 return mBackgroundColor; | |
| 83 } | |
| 84 | |
| 85 @Override | |
| 86 public int getThemeColor() { | |
| 87 return mThemeColor; | |
| 88 } | |
| 89 | |
| 90 @Override | |
| 91 public void updateForUrl(String url) { | |
| 92 mCurrentUrl = url; | |
| 93 mManager.updateForUrl(url); | |
| 94 } | |
| 95 | |
| 96 @Override | |
| 97 public void destroy() { | |
| 98 mManager.destroy(); | |
| 99 mManager = null; | |
| 100 } | |
| 101 | |
| 102 @Override | |
| 103 public void onBookmarkUIStateChange(String url) { | |
| 104 if (url.equals(mCurrentUrl)) return; | |
| 105 mTab.loadUrl(new LoadUrlParams(url)); | |
| 106 } | |
| 107 } | |
| OLD | NEW |