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 | |
| 19 | import com.android.browser.ScrollWebView.ScrollListener; |
| 20 | |
| 21 | import android.app.ActionBar; |
| 22 | import android.app.Activity; |
Michael Kolb | 2491522 | 2011-02-24 11:38:49 -0800 | [diff] [blame^] | 23 | import android.content.pm.PackageManager; |
Michael Kolb | ac35bdc | 2011-01-17 17:06:04 -0800 | [diff] [blame] | 24 | import android.os.Bundle; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 25 | import android.util.Log; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 26 | import android.view.ActionMode; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 27 | import android.view.Gravity; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 28 | import android.view.KeyEvent; |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 29 | import android.view.View; |
| 30 | import android.webkit.WebChromeClient.CustomViewCallback; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 31 | import android.webkit.WebView; |
| 32 | |
| 33 | import java.util.List; |
| 34 | |
| 35 | /** |
| 36 | * Ui for xlarge screen sizes |
| 37 | */ |
| 38 | public class XLargeUi extends BaseUi implements ScrollListener { |
| 39 | |
| 40 | private static final String LOGTAG = "XLargeUi"; |
| 41 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 42 | private ActionBar mActionBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 43 | private TabBar mTabBar; |
| 44 | |
| 45 | private TitleBarXLarge mTitleBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 46 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 47 | private boolean mUseQuickControls; |
| 48 | private PieControl mPieControl; |
| 49 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 50 | /** |
| 51 | * @param browser |
| 52 | * @param controller |
| 53 | */ |
| 54 | public XLargeUi(Activity browser, UiController controller) { |
| 55 | super(browser, controller); |
| 56 | mTitleBar = new TitleBarXLarge(mActivity, mUiController, this); |
| 57 | mTitleBar.setProgress(100); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 58 | mTabBar = new TabBar(mActivity, mUiController, this); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 59 | mActionBar = mActivity.getActionBar(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 60 | setupActionBar(); |
| 61 | setUseQuickControls(BrowserSettings.getInstance().useQuickControls()); |
| 62 | } |
| 63 | |
| 64 | private void setupActionBar() { |
| 65 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 66 | mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 67 | mActionBar.setCustomView(mTabBar); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Override |
Michael Kolb | ac35bdc | 2011-01-17 17:06:04 -0800 | [diff] [blame] | 71 | public void showComboView(boolean startWithHistory, Bundle extras) { |
| 72 | super.showComboView(startWithHistory, extras); |
| 73 | if (mUseQuickControls) { |
| 74 | mActionBar.show(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | @Override |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 79 | public void hideComboView() { |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 80 | checkTabCount(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 81 | super.hideComboView(); |
| 82 | // ComboView changes the action bar, set it back up to what we want |
| 83 | setupActionBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | private void setUseQuickControls(boolean useQuickControls) { |
| 87 | mUseQuickControls = useQuickControls; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 88 | mTitleBar.setUseQuickControls(mUseQuickControls); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 89 | if (useQuickControls) { |
| 90 | checkTabCount(); |
| 91 | mPieControl = new PieControl(mActivity, mUiController, this); |
| 92 | mPieControl.attachToContainer(mContentView); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 93 | Tab tab = getActiveTab(); |
| 94 | if ((tab != null) && (tab.getWebView() != null)) { |
| 95 | tab.getWebView().setEmbeddedTitleBar(null); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 96 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 97 | setTitleGravity(Gravity.BOTTOM); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 98 | } else { |
| 99 | mActivity.getActionBar().show(); |
| 100 | if (mPieControl != null) { |
| 101 | mPieControl.removeFromContainer(mContentView); |
| 102 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 103 | setTitleGravity(Gravity.TOP); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 104 | WebView web = mTabControl.getCurrentWebView(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 105 | if (web != null) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 106 | web.setEmbeddedTitleBar(mTitleBar); |
| 107 | } |
| 108 | } |
| 109 | mTabBar.setUseQuickControls(mUseQuickControls); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | private void checkTabCount() { |
| 113 | if (mUseQuickControls) { |
| 114 | int n = mTabBar.getTabCount(); |
| 115 | if (n >= 2) { |
| 116 | mActivity.getActionBar().show(); |
| 117 | } else if (n == 1) { |
| 118 | mActivity.getActionBar().hide(); |
| 119 | } |
| 120 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 125 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // webview factory |
| 129 | |
| 130 | @Override |
| 131 | public WebView createWebView(boolean privateBrowsing) { |
| 132 | // Create a new WebView |
| 133 | ScrollWebView w = new ScrollWebView(mActivity, null, |
| 134 | android.R.attr.webViewStyle, privateBrowsing); |
| 135 | initWebViewSettings(w); |
| 136 | w.setScrollListener(this); |
Michael Kolb | 2491522 | 2011-02-24 11:38:49 -0800 | [diff] [blame^] | 137 | boolean supportsMultiTouch = mActivity.getPackageManager() |
| 138 | .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH); |
| 139 | w.getSettings().setDisplayZoomControls(!supportsMultiTouch); |
Dave Burke | 20b6f1f | 2011-02-01 12:59:04 +0000 | [diff] [blame] | 140 | w.setExpandedTileBounds(true); // smoother scrolling |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 141 | return w; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public WebView createSubWebView(boolean privateBrowsing) { |
| 146 | ScrollWebView web = (ScrollWebView) createWebView(privateBrowsing); |
| 147 | // no scroll listener for subview |
| 148 | web.setScrollListener(null); |
| 149 | return web; |
| 150 | } |
| 151 | |
| 152 | @Override |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 153 | public void onScroll(int visibleTitleHeight, boolean userInitiated) { |
| 154 | mTabBar.onScroll(visibleTitleHeight, userInitiated); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void stopWebViewScrolling() { |
| 158 | ScrollWebView web = (ScrollWebView) mUiController.getCurrentWebView(); |
| 159 | if (web != null) { |
| 160 | web.stopScroll(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // WebView callbacks |
| 165 | |
| 166 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 167 | public void onProgressChanged(Tab tab) { |
| 168 | int progress = tab.getLoadProgress(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 169 | mTabBar.onProgress(tab, progress); |
| 170 | if (tab.inForeground()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 171 | mTitleBar.setProgress(progress); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 172 | if (progress == 100) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 173 | if (!mTitleBar.isEditingUrl()) { |
| 174 | hideTitleBar(); |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 175 | if (mUseQuickControls) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 176 | mTitleBar.setShowProgressOnly(false); |
| 177 | setTitleGravity(Gravity.BOTTOM); |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 178 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 179 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 180 | } else { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 181 | if (!isTitleBarShowing()) { |
| 182 | if (mUseQuickControls && !mTitleBar.isEditingUrl()) { |
| 183 | mTitleBar.setShowProgressOnly(true); |
| 184 | setTitleGravity(Gravity.TOP); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 185 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 186 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 187 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public boolean needsRestoreAllTabs() { |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void addTab(Tab tab) { |
| 199 | mTabBar.onNewTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | protected void onAddTabCompleted(Tab tab) { |
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 setActiveTab(Tab tab) { |
Michael Kolb | 36a1dc9 | 2011-02-22 16:14:59 -0800 | [diff] [blame] | 208 | if (mTitleBar.isEditingUrl()) { |
| 209 | mTitleBar.stopEditingUrl(); |
| 210 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 211 | super.setActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 212 | ScrollWebView view = (ScrollWebView) tab.getWebView(); |
| 213 | // TabControl.setCurrentTab has been called before this, |
| 214 | // so the tab is guaranteed to have a webview |
| 215 | if (view == null) { |
| 216 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 217 | return; |
| 218 | } |
| 219 | // Request focus on the top window. |
| 220 | if (mUseQuickControls) { |
| 221 | mPieControl.forceToTop(mContentView); |
| 222 | view.setScrollListener(null); |
| 223 | mTabBar.showTitleBarIndicator(false); |
| 224 | } else { |
| 225 | view.setEmbeddedTitleBar(mTitleBar); |
| 226 | view.setScrollListener(this); |
| 227 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 228 | mTabBar.onSetActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 229 | if (tab.isInVoiceSearchMode()) { |
| 230 | showVoiceTitleBar(tab.getVoiceDisplayTitle()); |
| 231 | } else { |
| 232 | revertVoiceTitleBar(tab); |
| 233 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 234 | updateLockIconToLatest(tab); |
| 235 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public void updateTabs(List<Tab> tabs) { |
| 240 | mTabBar.updateTabs(tabs); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 241 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public void removeTab(Tab tab) { |
| 246 | super.removeTab(tab); |
| 247 | mTabBar.onRemoveTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | protected void onRemoveTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 251 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 254 | int getContentWidth() { |
| 255 | if (mContentView != null) { |
| 256 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 257 | } |
| 258 | return 0; |
| 259 | } |
| 260 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 261 | @Override |
| 262 | public void editUrl(boolean clearInput) { |
Michael Kolb | d72ea3b | 2011-01-09 15:56:37 -0800 | [diff] [blame] | 263 | if (mUiController.isInCustomActionMode()) { |
| 264 | mUiController.endActionMode(); |
| 265 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 266 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 267 | mTitleBar.startEditingUrl(clearInput); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 270 | void showTitleBarAndEdit() { |
| 271 | mTitleBar.setShowProgressOnly(false); |
| 272 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 273 | mTitleBar.startEditingUrl(false); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void stopEditingUrl() { |
| 277 | mTitleBar.stopEditingUrl(); |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | protected void showTitleBar() { |
| 282 | if (canShowTitleBar()) { |
| 283 | if (mUseQuickControls) { |
| 284 | setTitleGravity(Gravity.BOTTOM); |
| 285 | mContentView.addView(mTitleBar); |
| 286 | } else { |
| 287 | setTitleGravity(Gravity.TOP); |
| 288 | } |
| 289 | super.showTitleBar(); |
| 290 | mTabBar.onShowTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 291 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 294 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 295 | protected void hideTitleBar() { |
| 296 | if (isTitleBarShowing()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 297 | mTabBar.onHideTitleBar(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 298 | setTitleGravity(Gravity.NO_GRAVITY); |
| 299 | if (mUseQuickControls) { |
| 300 | mContentView.removeView(mTitleBar); |
| 301 | } |
| 302 | super.hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 306 | public boolean isEditingUrl() { |
| 307 | return mTitleBar.isEditingUrl(); |
| 308 | } |
| 309 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 310 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 311 | protected TitleBarBase getTitleBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 312 | return mTitleBar; |
| 313 | } |
| 314 | |
| 315 | // action mode callbacks |
| 316 | |
| 317 | @Override |
| 318 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 319 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 320 | // hide the fake title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 321 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 326 | public void onActionModeFinished(boolean inLoad) { |
| 327 | checkTabCount(); |
| 328 | if (inLoad) { |
| 329 | // the titlebar was removed when the CAB was shown |
| 330 | // if the page is loading, show it again |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 331 | mTitleBar.setShowProgressOnly(true); |
| 332 | if (!isTitleBarShowing()) { |
| 333 | setTitleGravity(Gravity.TOP); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 334 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 335 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
| 339 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 340 | protected void updateNavigationState(Tab tab) { |
| 341 | mTitleBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 345 | public void setUrlTitle(Tab tab) { |
| 346 | super.setUrlTitle(tab); |
| 347 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | // Set the favicon in the title bar. |
| 351 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 352 | public void setFavicon(Tab tab) { |
| 353 | super.setFavicon(tab); |
| 354 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 357 | @Override |
| 358 | public void showVoiceTitleBar(String title) { |
| 359 | List<String> vsresults = null; |
| 360 | if (getActiveTab() != null) { |
| 361 | vsresults = getActiveTab().getVoiceSearchResults(); |
| 362 | } |
Michael Kolb | 3a2a164 | 2011-02-15 10:52:07 -0800 | [diff] [blame] | 363 | mTitleBar.setInVoiceMode(true, vsresults); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 364 | mTitleBar.setDisplayTitle(title); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public void revertVoiceTitleBar(Tab tab) { |
| 369 | mTitleBar.setInVoiceMode(false, null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 370 | String url = tab.getUrl(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 371 | mTitleBar.setDisplayTitle(url); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 372 | } |
| 373 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 374 | @Override |
| 375 | public void showCustomView(View view, CustomViewCallback callback) { |
| 376 | super.showCustomView(view, callback); |
| 377 | mActivity.getActionBar().hide(); |
| 378 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 379 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 380 | @Override |
| 381 | public void onHideCustomView() { |
| 382 | super.onHideCustomView(); |
| 383 | if (mUseQuickControls) { |
| 384 | checkTabCount(); |
| 385 | } else { |
| 386 | mActivity.getActionBar().show(); |
| 387 | } |
| 388 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 389 | |
| 390 | @Override |
| 391 | public boolean dispatchKey(int code, KeyEvent event) { |
| 392 | WebView web = getActiveTab().getWebView(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 393 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 394 | |
| 395 | switch (code) { |
| 396 | case KeyEvent.KEYCODE_TAB: |
| 397 | case KeyEvent.KEYCODE_DPAD_UP: |
| 398 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 399 | if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) { |
| 400 | editUrl(false); |
| 401 | return true; |
| 402 | } |
| 403 | } |
| 404 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 405 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
| 406 | editUrl(true); |
| 407 | return mContentView.dispatchKeyEvent(event); |
| 408 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 409 | } |
| 410 | return false; |
| 411 | } |
| 412 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 413 | private boolean isTypingKey(KeyEvent evt) { |
| 414 | return evt.getUnicodeChar() > 0; |
| 415 | } |
| 416 | |
| 417 | TabBar getTabBar() { |
| 418 | return mTabBar; |
| 419 | } |
| 420 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 421 | } |