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