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