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