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