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