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