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