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