Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 18 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 19 | import android.app.ActionBar; |
| 20 | import android.app.Activity; |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 21 | import android.content.res.Resources; |
| 22 | import android.graphics.Bitmap; |
| 23 | import android.graphics.drawable.BitmapDrawable; |
| 24 | import android.graphics.drawable.Drawable; |
| 25 | import android.graphics.drawable.LayerDrawable; |
| 26 | import android.graphics.drawable.PaintDrawable; |
Michael Kolb | ac35bdc | 2011-01-17 17:06:04 -0800 | [diff] [blame] | 27 | import android.os.Bundle; |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 28 | import android.os.Handler; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 30 | import android.view.ActionMode; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 31 | import android.view.KeyEvent; |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 32 | import android.view.Menu; |
| 33 | import android.view.MenuItem; |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 34 | import android.view.View; |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 35 | import android.view.ViewStub; |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 36 | import android.webkit.WebChromeClient; |
| 37 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 38 | import org.codeaurora.swe.WebView; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 39 | |
| 40 | import java.util.List; |
| 41 | |
| 42 | /** |
| 43 | * Ui for xlarge screen sizes |
| 44 | */ |
Michael Kolb | b14ff2f | 2011-07-01 15:33:56 -0700 | [diff] [blame] | 45 | public class XLargeUi extends BaseUi { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 46 | |
| 47 | private static final String LOGTAG = "XLargeUi"; |
| 48 | |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 49 | private PaintDrawable mFaviconBackground; |
| 50 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 51 | private ActionBar mActionBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 52 | private TabBar mTabBar; |
| 53 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 54 | private NavigationBarTablet mNavBar; |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 55 | private ComboView mComboView; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 56 | |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 57 | private Handler mHandler; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 58 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 59 | /** |
| 60 | * @param browser |
| 61 | * @param controller |
| 62 | */ |
| 63 | public XLargeUi(Activity browser, UiController controller) { |
| 64 | super(browser, controller); |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 65 | mHandler = new Handler(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 66 | mNavBar = (NavigationBarTablet) mTitleBar.getNavigationBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 67 | mTabBar = new TabBar(mActivity, mUiController, this); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 68 | mActionBar = mActivity.getActionBar(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 69 | setupActionBar(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private void setupActionBar() { |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 73 | mActionBar.setHomeButtonEnabled(false); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 74 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 75 | mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 76 | mActionBar.setCustomView(mTabBar); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 77 | } |
| 78 | |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 79 | public void showComboView(ComboViews startWith, Bundle extras) { |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 80 | if (mComboView == null) { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 81 | ViewStub stub = (ViewStub) mActivity.getWindow().getDecorView(). |
| 82 | findViewById(R.id.combo_view_stub); |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 83 | mComboView = (ComboView) stub.inflate(); |
| 84 | mComboView.setVisibility(View.GONE); |
| 85 | mComboView.setupViews(mActivity); |
| 86 | } |
| 87 | mNavBar.setVisibility(View.GONE); |
| 88 | if (mActionBar != null) |
| 89 | mActionBar.hide(); |
| 90 | Bundle b = new Bundle(); |
| 91 | b.putString(ComboViewActivity.EXTRA_INITIAL_VIEW, startWith.name()); |
| 92 | b.putBundle(ComboViewActivity.EXTRA_COMBO_ARGS, extras); |
| 93 | Tab t = getActiveTab(); |
| 94 | if (t != null) { |
| 95 | b.putString(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl()); |
| 96 | } |
| 97 | mComboView.showViews(mActivity, b); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void hideComboView() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 102 | if (isComboViewShowing()) { |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 103 | mComboView.hideViews(); |
| 104 | mActionBar = mActivity.getActionBar(); |
| 105 | setupActionBar(); |
| 106 | if (mActionBar != null) |
| 107 | mActionBar.show(); |
| 108 | mNavBar.setVisibility(View.VISIBLE); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public boolean onBackKey() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 114 | if (isComboViewShowing()) { |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 115 | hideComboView(); |
| 116 | return true; |
| 117 | } |
| 118 | return super.onBackKey(); |
| 119 | } |
| 120 | |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 121 | @Override |
| 122 | public boolean isComboViewShowing() { |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 123 | return mComboView != null && mComboView.getVisibility() == View.VISIBLE; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 127 | public void onResume() { |
| 128 | super.onResume(); |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 129 | mNavBar.clearCompletions(); |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
Pankaj Garg | 68faf1c | 2015-06-26 17:07:37 -0700 | [diff] [blame] | 133 | public void onProgressChanged(Tab tab) { |
| 134 | super.onProgressChanged(tab); |
| 135 | if (mComboView != null && !mComboView.isShowing()) { |
| 136 | mActionBar = mActivity.getActionBar(); |
| 137 | setupActionBar(); |
| 138 | if (mActionBar != null) |
| 139 | mActionBar.show(); |
| 140 | if (mNavBar != null) |
| 141 | mNavBar.setVisibility(View.VISIBLE); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 146 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 147 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 150 | void stopWebViewScrolling() { |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 151 | BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 152 | if (web != null) { |
| 153 | web.stopScroll(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 157 | @Override |
| 158 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 159 | MenuItem bm = menu.findItem(R.id.bookmarks_menu_id); |
| 160 | if (bm != null) { |
| 161 | bm.setVisible(false); |
| 162 | } |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 163 | |
| 164 | menu.setGroupVisible(R.id.NAV_MENU, false); |
| 165 | |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 166 | return true; |
| 167 | } |
| 168 | |
| 169 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 170 | // WebView callbacks |
| 171 | |
| 172 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 173 | public void addTab(Tab tab) { |
| 174 | mTabBar.onNewTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 177 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 178 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 179 | mTitleBar.cancelTitleBarAnimation(true); |
| 180 | mTitleBar.setSkipTitleBarAnimations(true); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 181 | super.setActiveTab(tab); |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 182 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 183 | // TabControl.setCurrentTab has been called before this, |
| 184 | // so the tab is guaranteed to have a webview |
| 185 | if (view == null) { |
| 186 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 187 | return; |
| 188 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 189 | mTabBar.onSetActiveTab(tab); |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public void updateTabs(List<Tab> tabs) { |
| 194 | mTabBar.updateTabs(tabs); |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void removeTab(Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 199 | mTitleBar.cancelTitleBarAnimation(true); |
| 200 | mTitleBar.setSkipTitleBarAnimations(true); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 201 | super.removeTab(tab); |
| 202 | mTabBar.onRemoveTab(tab); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 203 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 206 | @Override |
| 207 | public void showCustomView(View view, int requestedOrientation, |
| 208 | WebChromeClient.CustomViewCallback callback) { |
| 209 | super.showCustomView(view, requestedOrientation, callback); |
| 210 | if (mActionBar != null) |
| 211 | mActionBar.hide(); |
| 212 | } |
| 213 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 214 | int getContentWidth() { |
| 215 | if (mContentView != null) { |
| 216 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 217 | } |
| 218 | return 0; |
| 219 | } |
| 220 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 221 | @Override |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 222 | public void editUrl(boolean clearInput, boolean forceIME) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 223 | super.editUrl(clearInput, forceIME); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 226 | // action mode callbacks |
| 227 | |
| 228 | @Override |
| 229 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 230 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | b2e91fd | 2011-07-14 13:47:29 -0700 | [diff] [blame] | 231 | // hide the title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 232 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 237 | public void onActionModeFinished(boolean inLoad) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 238 | if (inLoad) { |
| 239 | // the titlebar was removed when the CAB was shown |
| 240 | // if the page is loading, show it again |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 241 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 246 | protected void updateNavigationState(Tab tab) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 247 | mNavBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 251 | public void setUrlTitle(Tab tab) { |
| 252 | super.setUrlTitle(tab); |
| 253 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | // Set the favicon in the title bar. |
| 257 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 258 | public void setFavicon(Tab tab) { |
| 259 | super.setFavicon(tab); |
| 260 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Pankaj Garg | 68faf1c | 2015-06-26 17:07:37 -0700 | [diff] [blame] | 261 | /* |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 262 | if (mActiveTab == tab) { |
| 263 | int color = NavigationBarBase.getSiteIconColor(tab.getUrl()); |
| 264 | if (tab.hasFavicon()) { |
| 265 | color = ColorUtils.getDominantColorForBitmap(tab.getFavicon()); |
| 266 | } |
| 267 | mActionBar.setBackgroundDrawable(new ColorDrawable(color)); |
| 268 | } |
Pankaj Garg | 68faf1c | 2015-06-26 17:07:37 -0700 | [diff] [blame] | 269 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 272 | @Override |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 273 | public void onHideCustomView() { |
| 274 | super.onHideCustomView(); |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 275 | if (mActionBar != null) |
| 276 | mActionBar.show(); |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 277 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 278 | |
| 279 | @Override |
| 280 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 281 | if (mActiveTab != null) { |
| 282 | WebView web = mActiveTab.getWebView(); |
| 283 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 284 | switch (code) { |
| 285 | case KeyEvent.KEYCODE_TAB: |
| 286 | case KeyEvent.KEYCODE_DPAD_UP: |
| 287 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 288 | if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 289 | editUrl(false, false); |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 290 | return true; |
| 291 | } |
| 292 | } |
| 293 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 294 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 295 | editUrl(true, false); |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 296 | return mContentView.dispatchKeyEvent(event); |
| 297 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 298 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 299 | } |
| 300 | return false; |
| 301 | } |
| 302 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 303 | private boolean isTypingKey(KeyEvent evt) { |
| 304 | return evt.getUnicodeChar() > 0; |
| 305 | } |
| 306 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 307 | @Override |
| 308 | public boolean shouldCaptureThumbnails() { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 309 | return false; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 310 | } |
| 311 | |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 312 | private Drawable getFaviconBackground() { |
| 313 | if (mFaviconBackground == null) { |
| 314 | mFaviconBackground = new PaintDrawable(); |
| 315 | Resources res = mActivity.getResources(); |
| 316 | mFaviconBackground.getPaint().setColor( |
| 317 | res.getColor(R.color.tabFaviconBackground)); |
| 318 | mFaviconBackground.setCornerRadius( |
| 319 | res.getDimension(R.dimen.tab_favicon_corner_radius)); |
| 320 | } |
| 321 | return mFaviconBackground; |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public Drawable getFaviconDrawable(Bitmap icon) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 326 | if (ENABLE_BORDER_AROUND_FAVICON) { |
| 327 | Drawable[] array = new Drawable[2]; |
| 328 | array[0] = getFaviconBackground(); |
| 329 | if (icon == null) { |
| 330 | array[1] = getGenericFavicon(); |
| 331 | } else { |
| 332 | array[1] = new BitmapDrawable(mActivity.getResources(), icon); |
| 333 | } |
| 334 | LayerDrawable d = new LayerDrawable(array); |
| 335 | d.setLayerInset(1, 2, 2, 2, 2); |
| 336 | return d; |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 337 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame^] | 338 | return icon == null ? getGenericFavicon() : |
| 339 | new BitmapDrawable(mActivity.getResources(), icon); |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 342 | } |