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 | |
| 17 | package com.android.browser; |
| 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 | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 31 | import android.view.Gravity; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 32 | import android.view.KeyEvent; |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 33 | import android.view.View; |
Michael Kolb | 52051eb | 2011-08-02 13:06:43 -0700 | [diff] [blame] | 34 | import android.view.ViewGroup; |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 35 | import android.webkit.WebChromeClient.CustomViewCallback; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 36 | import android.webkit.WebView; |
| 37 | |
| 38 | import java.util.List; |
| 39 | |
| 40 | /** |
| 41 | * Ui for xlarge screen sizes |
| 42 | */ |
Michael Kolb | b14ff2f | 2011-07-01 15:33:56 -0700 | [diff] [blame] | 43 | public class XLargeUi extends BaseUi { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 44 | |
| 45 | private static final String LOGTAG = "XLargeUi"; |
| 46 | |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 47 | private PaintDrawable mFaviconBackground; |
| 48 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 49 | private ActionBar mActionBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 50 | private TabBar mTabBar; |
| 51 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 52 | private NavigationBarTablet mNavBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 53 | |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 54 | private PieControlXLarge mPieControl; |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 55 | private Handler mHandler; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 56 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 57 | /** |
| 58 | * @param browser |
| 59 | * @param controller |
| 60 | */ |
| 61 | public XLargeUi(Activity browser, UiController controller) { |
| 62 | super(browser, controller); |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 63 | mHandler = new Handler(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 64 | mNavBar = (NavigationBarTablet) mTitleBar.getNavigationBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 65 | mTabBar = new TabBar(mActivity, mUiController, this); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 66 | mActionBar = mActivity.getActionBar(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 67 | setupActionBar(); |
| 68 | setUseQuickControls(BrowserSettings.getInstance().useQuickControls()); |
| 69 | } |
| 70 | |
| 71 | private void setupActionBar() { |
| 72 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 73 | mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 74 | mActionBar.setCustomView(mTabBar); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 75 | } |
| 76 | |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 77 | public void showComboView(ComboViews startWith, Bundle extras) { |
| 78 | super.showComboView(startWith, extras); |
Michael Kolb | ac35bdc | 2011-01-17 17:06:04 -0800 | [diff] [blame] | 79 | if (mUseQuickControls) { |
| 80 | mActionBar.show(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | @Override |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 85 | public void setUseQuickControls(boolean useQuickControls) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 86 | mUseQuickControls = useQuickControls; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 87 | mTitleBar.setUseQuickControls(mUseQuickControls); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 88 | if (useQuickControls) { |
| 89 | checkTabCount(); |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 90 | mPieControl = new PieControlXLarge(mActivity, mUiController, this); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 91 | mPieControl.attachToContainer(mContentView); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 92 | WebView web = getWebView(); |
| 93 | if (web != null) { |
| 94 | web.setEmbeddedTitleBar(null); |
Michael Kolb | 0241e75 | 2011-07-07 14:58:50 -0700 | [diff] [blame] | 95 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 96 | } |
| 97 | } else { |
| 98 | mActivity.getActionBar().show(); |
| 99 | if (mPieControl != null) { |
| 100 | mPieControl.removeFromContainer(mContentView); |
| 101 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 102 | WebView web = getWebView(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 103 | if (web != null) { |
Michael Kolb | 52051eb | 2011-08-02 13:06:43 -0700 | [diff] [blame] | 104 | if (mTitleBar.getParent() != null) { |
| 105 | ViewGroup p = (ViewGroup) mTitleBar.getParent(); |
| 106 | p.removeView(mTitleBar); |
| 107 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 108 | web.setEmbeddedTitleBar(mTitleBar); |
| 109 | } |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 110 | setTitleGravity(Gravity.NO_GRAVITY); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 111 | } |
| 112 | mTabBar.setUseQuickControls(mUseQuickControls); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 113 | // We need to update the tabs with this change |
| 114 | for (Tab t : mTabControl.getTabs()) { |
| 115 | t.updateShouldCaptureThumbnails(); |
| 116 | } |
John Reck | 718a24d | 2011-08-12 11:08:30 -0700 | [diff] [blame] | 117 | updateUrlBarAutoShowManagerTarget(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | private void checkTabCount() { |
| 121 | if (mUseQuickControls) { |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 122 | mHandler.post(new Runnable() { |
| 123 | public void run() { |
| 124 | mActionBar.hide(); |
| 125 | } |
| 126 | }); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 127 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | @Override |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 131 | public void onResume() { |
| 132 | super.onResume(); |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame^] | 133 | mNavBar.clearCompletions(); |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 137 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 138 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 141 | void stopWebViewScrolling() { |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 142 | BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 143 | if (web != null) { |
| 144 | web.stopScroll(); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // WebView callbacks |
| 149 | |
| 150 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 151 | public void onProgressChanged(Tab tab) { |
| 152 | int progress = tab.getLoadProgress(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 153 | mTabBar.onProgress(tab, progress); |
| 154 | if (tab.inForeground()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 155 | mTitleBar.setProgress(progress); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
| 159 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 160 | public void addTab(Tab tab) { |
| 161 | mTabBar.onNewTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | protected void onAddTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 165 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 169 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 170 | mTitleBar.cancelTitleBarAnimation(true); |
| 171 | mTitleBar.setSkipTitleBarAnimations(true); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 172 | super.setActiveTab(tab); |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 173 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 174 | // TabControl.setCurrentTab has been called before this, |
| 175 | // so the tab is guaranteed to have a webview |
| 176 | if (view == null) { |
| 177 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 178 | return; |
| 179 | } |
| 180 | // Request focus on the top window. |
| 181 | if (mUseQuickControls) { |
| 182 | mPieControl.forceToTop(mContentView); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 183 | } else { |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 184 | // check if title bar is already attached by animation |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 185 | if (mTitleBar.getParent() == null) { |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 186 | view.setEmbeddedTitleBar(mTitleBar); |
| 187 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 188 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 189 | mTabBar.onSetActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 190 | if (tab.isInVoiceSearchMode()) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 191 | showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 192 | } else { |
| 193 | revertVoiceTitleBar(tab); |
| 194 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 195 | updateLockIconToLatest(tab); |
| 196 | tab.getTopWindow().requestFocus(); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 197 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void updateTabs(List<Tab> tabs) { |
| 202 | mTabBar.updateTabs(tabs); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 203 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public void removeTab(Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 208 | mTitleBar.cancelTitleBarAnimation(true); |
| 209 | mTitleBar.setSkipTitleBarAnimations(true); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 210 | super.removeTab(tab); |
| 211 | mTabBar.onRemoveTab(tab); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 212 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | protected void onRemoveTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 216 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 219 | int getContentWidth() { |
| 220 | if (mContentView != null) { |
| 221 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 222 | } |
| 223 | return 0; |
| 224 | } |
| 225 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 226 | @Override |
| 227 | public void editUrl(boolean clearInput) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 228 | if (mUseQuickControls) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 229 | mTitleBar.setShowProgressOnly(false); |
Michael Kolb | d72ea3b | 2011-01-09 15:56:37 -0800 | [diff] [blame] | 230 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 231 | super.editUrl(clearInput); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void stopEditingUrl() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 235 | mTitleBar.getNavigationBar().stopEditingUrl(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Override |
| 239 | protected void showTitleBar() { |
| 240 | if (canShowTitleBar()) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 241 | mTitleBar.show(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 242 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 245 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 246 | protected void hideTitleBar() { |
| 247 | if (isTitleBarShowing()) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 248 | mTitleBar.hide(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
| 252 | @Override |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 253 | protected void setTitleGravity(int gravity) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 254 | if (!mUseQuickControls) { |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 255 | super.setTitleGravity(gravity); |
| 256 | } |
| 257 | } |
| 258 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 259 | // action mode callbacks |
| 260 | |
| 261 | @Override |
| 262 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 263 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | b2e91fd | 2011-07-14 13:47:29 -0700 | [diff] [blame] | 264 | // hide the title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 265 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 270 | public void onActionModeFinished(boolean inLoad) { |
| 271 | checkTabCount(); |
| 272 | if (inLoad) { |
| 273 | // the titlebar was removed when the CAB was shown |
| 274 | // if the page is loading, show it again |
Michael Kolb | 1544f3b | 2011-03-10 09:06:10 -0800 | [diff] [blame] | 275 | if (mUseQuickControls) { |
| 276 | mTitleBar.setShowProgressOnly(true); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 277 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 278 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
| 282 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 283 | protected void updateNavigationState(Tab tab) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 284 | mNavBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 288 | public void setUrlTitle(Tab tab) { |
| 289 | super.setUrlTitle(tab); |
| 290 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | // Set the favicon in the title bar. |
| 294 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 295 | public void setFavicon(Tab tab) { |
| 296 | super.setFavicon(tab); |
| 297 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 300 | @Override |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 301 | public void onHideCustomView() { |
| 302 | super.onHideCustomView(); |
| 303 | if (mUseQuickControls) { |
| 304 | checkTabCount(); |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 305 | } |
| 306 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 307 | |
| 308 | @Override |
| 309 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 310 | if (mActiveTab != null) { |
| 311 | WebView web = mActiveTab.getWebView(); |
| 312 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 313 | switch (code) { |
| 314 | case KeyEvent.KEYCODE_TAB: |
| 315 | case KeyEvent.KEYCODE_DPAD_UP: |
| 316 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 317 | if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) { |
| 318 | editUrl(false); |
| 319 | return true; |
| 320 | } |
| 321 | } |
| 322 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 323 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
| 324 | editUrl(true); |
| 325 | return mContentView.dispatchKeyEvent(event); |
| 326 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 327 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 328 | } |
| 329 | return false; |
| 330 | } |
| 331 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 332 | private boolean isTypingKey(KeyEvent evt) { |
| 333 | return evt.getUnicodeChar() > 0; |
| 334 | } |
| 335 | |
| 336 | TabBar getTabBar() { |
| 337 | return mTabBar; |
| 338 | } |
| 339 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 340 | @Override |
| 341 | public boolean shouldCaptureThumbnails() { |
| 342 | return mUseQuickControls; |
| 343 | } |
| 344 | |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 345 | private Drawable getFaviconBackground() { |
| 346 | if (mFaviconBackground == null) { |
| 347 | mFaviconBackground = new PaintDrawable(); |
| 348 | Resources res = mActivity.getResources(); |
| 349 | mFaviconBackground.getPaint().setColor( |
| 350 | res.getColor(R.color.tabFaviconBackground)); |
| 351 | mFaviconBackground.setCornerRadius( |
| 352 | res.getDimension(R.dimen.tab_favicon_corner_radius)); |
| 353 | } |
| 354 | return mFaviconBackground; |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public Drawable getFaviconDrawable(Bitmap icon) { |
| 359 | Drawable[] array = new Drawable[2]; |
| 360 | array[0] = getFaviconBackground(); |
| 361 | if (icon == null) { |
| 362 | array[1] = mGenericFavicon; |
| 363 | } else { |
| 364 | array[1] = new BitmapDrawable(mActivity.getResources(), icon); |
| 365 | } |
| 366 | LayerDrawable d = new LayerDrawable(array); |
| 367 | d.setLayerInset(1, 2, 2, 2, 2); |
| 368 | return d; |
| 369 | } |
| 370 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 371 | } |