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) { |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 179 | super.setActiveTab(tab); |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 180 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 181 | // TabControl.setCurrentTab has been called before this, |
| 182 | // so the tab is guaranteed to have a webview |
| 183 | if (view == null) { |
| 184 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 185 | return; |
| 186 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 187 | mTabBar.onSetActiveTab(tab); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void updateTabs(List<Tab> tabs) { |
| 192 | mTabBar.updateTabs(tabs); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void removeTab(Tab tab) { |
| 197 | super.removeTab(tab); |
| 198 | mTabBar.onRemoveTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 201 | @Override |
| 202 | public void showCustomView(View view, int requestedOrientation, |
| 203 | WebChromeClient.CustomViewCallback callback) { |
| 204 | super.showCustomView(view, requestedOrientation, callback); |
Sagar Dhawan | f5e6af6 | 2015-09-14 19:50:50 -0700 | [diff] [blame] | 205 | mTitleBar.setTranslationY( |
| 206 | -mActivity.getResources().getDimensionPixelSize(R.dimen.toolbar_height)); |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 207 | if (mActionBar != null) |
| 208 | mActionBar.hide(); |
| 209 | } |
| 210 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 211 | int getContentWidth() { |
| 212 | if (mContentView != null) { |
| 213 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 214 | } |
| 215 | return 0; |
| 216 | } |
| 217 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 218 | @Override |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 219 | public void editUrl(boolean clearInput, boolean forceIME) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 220 | super.editUrl(clearInput, forceIME); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 223 | // action mode callbacks |
| 224 | |
| 225 | @Override |
| 226 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 227 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | b2e91fd | 2011-07-14 13:47:29 -0700 | [diff] [blame] | 228 | // hide the title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 229 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 234 | public void onActionModeFinished(boolean inLoad) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 235 | if (inLoad) { |
| 236 | // the titlebar was removed when the CAB was shown |
| 237 | // if the page is loading, show it again |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 238 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 243 | protected void updateNavigationState(Tab tab) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 244 | mNavBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 248 | public void setUrlTitle(Tab tab) { |
| 249 | super.setUrlTitle(tab); |
| 250 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | // Set the favicon in the title bar. |
| 254 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 255 | public void setFavicon(Tab tab) { |
| 256 | super.setFavicon(tab); |
| 257 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Pankaj Garg | 68faf1c | 2015-06-26 17:07:37 -0700 | [diff] [blame] | 258 | /* |
Pankaj Garg | 32e1b94 | 2015-06-03 18:13:24 -0700 | [diff] [blame] | 259 | if (mActiveTab == tab) { |
| 260 | int color = NavigationBarBase.getSiteIconColor(tab.getUrl()); |
| 261 | if (tab.hasFavicon()) { |
| 262 | color = ColorUtils.getDominantColorForBitmap(tab.getFavicon()); |
| 263 | } |
| 264 | mActionBar.setBackgroundDrawable(new ColorDrawable(color)); |
| 265 | } |
Pankaj Garg | 68faf1c | 2015-06-26 17:07:37 -0700 | [diff] [blame] | 266 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 269 | @Override |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 270 | public void onHideCustomView() { |
| 271 | super.onHideCustomView(); |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame] | 272 | if (mActionBar != null) |
| 273 | mActionBar.show(); |
Sagar Dhawan | f5e6af6 | 2015-09-14 19:50:50 -0700 | [diff] [blame] | 274 | mTitleBar.setTranslationY(0); |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 275 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 276 | |
| 277 | @Override |
| 278 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 279 | if (mActiveTab != null) { |
| 280 | WebView web = mActiveTab.getWebView(); |
| 281 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 282 | switch (code) { |
| 283 | case KeyEvent.KEYCODE_TAB: |
| 284 | case KeyEvent.KEYCODE_DPAD_UP: |
| 285 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 286 | if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 287 | editUrl(false, false); |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 288 | return true; |
| 289 | } |
| 290 | } |
| 291 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 292 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 293 | editUrl(true, false); |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 294 | return mContentView.dispatchKeyEvent(event); |
| 295 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 296 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 297 | } |
| 298 | return false; |
| 299 | } |
| 300 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 301 | private boolean isTypingKey(KeyEvent evt) { |
| 302 | return evt.getUnicodeChar() > 0; |
| 303 | } |
| 304 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 305 | @Override |
| 306 | public boolean shouldCaptureThumbnails() { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 307 | return false; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 308 | } |
| 309 | |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 310 | private Drawable getFaviconBackground() { |
| 311 | if (mFaviconBackground == null) { |
| 312 | mFaviconBackground = new PaintDrawable(); |
| 313 | Resources res = mActivity.getResources(); |
| 314 | mFaviconBackground.getPaint().setColor( |
| 315 | res.getColor(R.color.tabFaviconBackground)); |
| 316 | mFaviconBackground.setCornerRadius( |
| 317 | res.getDimension(R.dimen.tab_favicon_corner_radius)); |
| 318 | } |
| 319 | return mFaviconBackground; |
| 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public Drawable getFaviconDrawable(Bitmap icon) { |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 324 | if (ENABLE_BORDER_AROUND_FAVICON) { |
| 325 | Drawable[] array = new Drawable[2]; |
| 326 | array[0] = getFaviconBackground(); |
| 327 | if (icon == null) { |
| 328 | array[1] = getGenericFavicon(); |
| 329 | } else { |
| 330 | array[1] = new BitmapDrawable(mActivity.getResources(), icon); |
| 331 | } |
| 332 | LayerDrawable d = new LayerDrawable(array); |
| 333 | d.setLayerInset(1, 2, 2, 2, 2); |
| 334 | return d; |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 335 | } |
Pankaj Garg | 66f8cef | 2015-07-07 17:29:03 -0700 | [diff] [blame] | 336 | return icon == null ? getGenericFavicon() : |
| 337 | new BitmapDrawable(mActivity.getResources(), icon); |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 340 | } |