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 |
| 179 | public boolean needsRestoreAllTabs() { |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void addTab(Tab tab) { |
| 185 | mTabBar.onNewTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | protected void onAddTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 189 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 193 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 194 | mTitleBar.cancelTitleBarAnimation(true); |
| 195 | mTitleBar.setSkipTitleBarAnimations(true); |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 196 | if (mUseQuickControls) { |
| 197 | if (mActiveTab != null) { |
| 198 | captureTab(mActiveTab); |
| 199 | } |
| 200 | } |
Michael Kolb | f262892 | 2011-03-09 17:15:28 -0800 | [diff] [blame] | 201 | super.setActiveTab(tab, true); |
| 202 | setActiveTab(tab, true); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 203 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | @Override |
| 207 | void setActiveTab(Tab tab, boolean needsAttaching) { |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 208 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 209 | // TabControl.setCurrentTab has been called before this, |
| 210 | // so the tab is guaranteed to have a webview |
| 211 | if (view == null) { |
| 212 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 213 | return; |
| 214 | } |
| 215 | // Request focus on the top window. |
| 216 | if (mUseQuickControls) { |
| 217 | mPieControl.forceToTop(mContentView); |
| 218 | view.setScrollListener(null); |
| 219 | mTabBar.showTitleBarIndicator(false); |
| 220 | } else { |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 221 | // check if title bar is already attached by animation |
| 222 | if (mTitleBar.getParent() == null) { |
| 223 | view.setEmbeddedTitleBar(mTitleBar); |
| 224 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 225 | view.setScrollListener(this); |
| 226 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 227 | mTabBar.onSetActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 228 | if (tab.isInVoiceSearchMode()) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 229 | showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 230 | } else { |
| 231 | revertVoiceTitleBar(tab); |
| 232 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 233 | updateLockIconToLatest(tab); |
| 234 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public void updateTabs(List<Tab> tabs) { |
| 239 | mTabBar.updateTabs(tabs); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 240 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void removeTab(Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 245 | mTitleBar.cancelTitleBarAnimation(true); |
| 246 | mTitleBar.setSkipTitleBarAnimations(true); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 247 | super.removeTab(tab); |
| 248 | mTabBar.onRemoveTab(tab); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 249 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | protected void onRemoveTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 253 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 256 | int getContentWidth() { |
| 257 | if (mContentView != null) { |
| 258 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 259 | } |
| 260 | return 0; |
| 261 | } |
| 262 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 263 | @Override |
| 264 | public void editUrl(boolean clearInput) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 265 | if (mUseQuickControls) { |
| 266 | getTitleBar().setShowProgressOnly(false); |
Michael Kolb | d72ea3b | 2011-01-09 15:56:37 -0800 | [diff] [blame] | 267 | } |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 268 | super.editUrl(clearInput); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | void stopEditingUrl() { |
| 272 | mTitleBar.stopEditingUrl(); |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | protected void showTitleBar() { |
| 277 | if (canShowTitleBar()) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 278 | mTitleBar.show(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 279 | mTabBar.onShowTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 280 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 283 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 284 | protected void hideTitleBar() { |
| 285 | if (isTitleBarShowing()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 286 | mTabBar.onHideTitleBar(); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 287 | mTitleBar.hide(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 291 | public boolean isEditingUrl() { |
| 292 | return mTitleBar.isEditingUrl(); |
| 293 | } |
| 294 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 295 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 296 | protected TitleBarBase getTitleBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 297 | return mTitleBar; |
| 298 | } |
| 299 | |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 300 | @Override |
| 301 | protected void setTitleGravity(int gravity) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 302 | if (!mUseQuickControls) { |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 303 | super.setTitleGravity(gravity); |
| 304 | } |
| 305 | } |
| 306 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 307 | // action mode callbacks |
| 308 | |
| 309 | @Override |
| 310 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 311 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 312 | // hide the fake title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 313 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| 317 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 318 | public void onActionModeFinished(boolean inLoad) { |
| 319 | checkTabCount(); |
| 320 | if (inLoad) { |
| 321 | // the titlebar was removed when the CAB was shown |
| 322 | // if the page is loading, show it again |
Michael Kolb | 1544f3b | 2011-03-10 09:06:10 -0800 | [diff] [blame] | 323 | if (mUseQuickControls) { |
| 324 | mTitleBar.setShowProgressOnly(true); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 325 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 326 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 331 | protected void updateNavigationState(Tab tab) { |
| 332 | mTitleBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 336 | public void setUrlTitle(Tab tab) { |
| 337 | super.setUrlTitle(tab); |
| 338 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | // Set the favicon in the title bar. |
| 342 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 343 | public void setFavicon(Tab tab) { |
| 344 | super.setFavicon(tab); |
| 345 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 348 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 349 | public void showVoiceTitleBar(String title, List<String> vsresults) { |
Michael Kolb | 3a2a164 | 2011-02-15 10:52:07 -0800 | [diff] [blame] | 350 | mTitleBar.setInVoiceMode(true, vsresults); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 351 | mTitleBar.setDisplayTitle(title); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public void revertVoiceTitleBar(Tab tab) { |
| 356 | mTitleBar.setInVoiceMode(false, null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 357 | String url = tab.getUrl(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 358 | mTitleBar.setDisplayTitle(url); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 359 | } |
| 360 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 361 | @Override |
| 362 | public void showCustomView(View view, CustomViewCallback callback) { |
| 363 | super.showCustomView(view, callback); |
| 364 | mActivity.getActionBar().hide(); |
| 365 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 366 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 367 | @Override |
| 368 | public void onHideCustomView() { |
| 369 | super.onHideCustomView(); |
| 370 | if (mUseQuickControls) { |
| 371 | checkTabCount(); |
| 372 | } else { |
| 373 | mActivity.getActionBar().show(); |
| 374 | } |
| 375 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 376 | |
| 377 | @Override |
| 378 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 379 | if (mActiveTab != null) { |
| 380 | WebView web = mActiveTab.getWebView(); |
| 381 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 382 | switch (code) { |
| 383 | case KeyEvent.KEYCODE_TAB: |
| 384 | case KeyEvent.KEYCODE_DPAD_UP: |
| 385 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 386 | if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) { |
| 387 | editUrl(false); |
| 388 | return true; |
| 389 | } |
| 390 | } |
| 391 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 392 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
| 393 | editUrl(true); |
| 394 | return mContentView.dispatchKeyEvent(event); |
| 395 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 396 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 397 | } |
| 398 | return false; |
| 399 | } |
| 400 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 401 | private boolean isTypingKey(KeyEvent evt) { |
| 402 | return evt.getUnicodeChar() > 0; |
| 403 | } |
| 404 | |
| 405 | TabBar getTabBar() { |
| 406 | return mTabBar; |
| 407 | } |
| 408 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 409 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 410 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 411 | if (mUseQuickControls) { |
| 412 | mPieControl.onMenuOpened(menu); |
| 413 | return false; |
| 414 | } else { |
| 415 | return true; |
| 416 | } |
| 417 | } |
| 418 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 419 | } |