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