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 | |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.Animator.AnimatorListener; |
| 23 | import android.animation.ObjectAnimator; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 24 | import android.app.ActionBar; |
| 25 | import android.app.Activity; |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 26 | import android.graphics.Bitmap; |
Michael Kolb | ac35bdc | 2011-01-17 17:06:04 -0800 | [diff] [blame] | 27 | import android.os.Bundle; |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 28 | import android.os.Handler; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 30 | import android.view.ActionMode; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 31 | import android.view.Gravity; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 32 | import android.view.KeyEvent; |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 33 | import android.view.Menu; |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 34 | import android.view.View; |
| 35 | import android.webkit.WebChromeClient.CustomViewCallback; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 36 | import android.webkit.WebView; |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 37 | import android.widget.FrameLayout; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 38 | |
| 39 | import java.util.List; |
| 40 | |
| 41 | /** |
| 42 | * Ui for xlarge screen sizes |
| 43 | */ |
| 44 | public class XLargeUi extends BaseUi implements ScrollListener { |
| 45 | |
| 46 | private static final String LOGTAG = "XLargeUi"; |
| 47 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 48 | private ActionBar mActionBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 49 | private TabBar mTabBar; |
| 50 | |
| 51 | private TitleBarXLarge mTitleBar; |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 52 | private Animator mTitleBarAnimator; |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 53 | private boolean mSkipTitleBarAnimations; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 54 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 55 | private boolean mUseQuickControls; |
| 56 | private PieControl mPieControl; |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 57 | private Handler mHandler; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 58 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 59 | /** |
| 60 | * @param browser |
| 61 | * @param controller |
| 62 | */ |
| 63 | public XLargeUi(Activity browser, UiController controller) { |
| 64 | super(browser, controller); |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 65 | mHandler = new Handler(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 66 | mTitleBar = new TitleBarXLarge(mActivity, mUiController, this); |
| 67 | mTitleBar.setProgress(100); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 68 | mTabBar = new TabBar(mActivity, mUiController, this); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 69 | mActionBar = mActivity.getActionBar(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 70 | setupActionBar(); |
| 71 | setUseQuickControls(BrowserSettings.getInstance().useQuickControls()); |
| 72 | } |
| 73 | |
| 74 | private void setupActionBar() { |
| 75 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 76 | mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 77 | mActionBar.setCustomView(mTabBar); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Michael Kolb | ac35bdc | 2011-01-17 17:06:04 -0800 | [diff] [blame] | 81 | public void showComboView(boolean startWithHistory, Bundle extras) { |
| 82 | super.showComboView(startWithHistory, extras); |
| 83 | if (mUseQuickControls) { |
| 84 | mActionBar.show(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | @Override |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 89 | public void hideComboView() { |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 90 | if (isComboViewShowing()) { |
| 91 | super.hideComboView(); |
| 92 | // ComboView changes the action bar, set it back up to what we want |
| 93 | setupActionBar(); |
| 94 | checkTabCount(); |
| 95 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | private void setUseQuickControls(boolean useQuickControls) { |
| 99 | mUseQuickControls = useQuickControls; |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 100 | mTitleBar.setUseQuickControls(mUseQuickControls); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 101 | if (useQuickControls) { |
| 102 | checkTabCount(); |
| 103 | mPieControl = new PieControl(mActivity, mUiController, this); |
| 104 | mPieControl.attachToContainer(mContentView); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 105 | Tab tab = getActiveTab(); |
| 106 | if ((tab != null) && (tab.getWebView() != null)) { |
| 107 | tab.getWebView().setEmbeddedTitleBar(null); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 108 | } |
| 109 | } else { |
| 110 | mActivity.getActionBar().show(); |
| 111 | if (mPieControl != null) { |
| 112 | mPieControl.removeFromContainer(mContentView); |
| 113 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 114 | WebView web = mTabControl.getCurrentWebView(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 115 | if (web != null) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 116 | web.setEmbeddedTitleBar(mTitleBar); |
| 117 | } |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 118 | setTitleGravity(Gravity.NO_GRAVITY); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 119 | } |
| 120 | mTabBar.setUseQuickControls(mUseQuickControls); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | private void checkTabCount() { |
| 124 | if (mUseQuickControls) { |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 125 | mHandler.post(new Runnable() { |
| 126 | public void run() { |
| 127 | mActionBar.hide(); |
| 128 | } |
| 129 | }); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 130 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | @Override |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 134 | public void onResume() { |
| 135 | super.onResume(); |
| 136 | if (!BrowserSettings.getInstance().useInstant()) { |
| 137 | mTitleBar.clearCompletions(); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 142 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 143 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | // webview factory |
| 147 | |
| 148 | @Override |
| 149 | public WebView createWebView(boolean privateBrowsing) { |
| 150 | // Create a new WebView |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 151 | BrowserWebView w = (BrowserWebView) super.createWebView(privateBrowsing); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 152 | w.setScrollListener(this); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 153 | return w; |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public WebView createSubWebView(boolean privateBrowsing) { |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 158 | return super.createWebView(privateBrowsing); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 162 | public void onScroll(int visibleTitleHeight, boolean userInitiated) { |
| 163 | mTabBar.onScroll(visibleTitleHeight, userInitiated); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void stopWebViewScrolling() { |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 167 | BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 168 | if (web != null) { |
| 169 | web.stopScroll(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // WebView callbacks |
| 174 | |
| 175 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 176 | public void onProgressChanged(Tab tab) { |
| 177 | int progress = tab.getLoadProgress(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 178 | mTabBar.onProgress(tab, progress); |
| 179 | if (tab.inForeground()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 180 | mTitleBar.setProgress(progress); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 181 | if (progress == 100) { |
Michael Kolb | 8a4c382 | 2011-03-15 14:52:05 -0700 | [diff] [blame] | 182 | if (!mTitleBar.isEditingUrl() && !mTitleBar.inAutoLogin()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 183 | hideTitleBar(); |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 184 | if (mUseQuickControls) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 185 | mTitleBar.setShowProgressOnly(false); |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 186 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 187 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 188 | } else { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 189 | if (!isTitleBarShowing()) { |
| 190 | if (mUseQuickControls && !mTitleBar.isEditingUrl()) { |
| 191 | mTitleBar.setShowProgressOnly(true); |
| 192 | setTitleGravity(Gravity.TOP); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 193 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 194 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 195 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public boolean needsRestoreAllTabs() { |
| 202 | return true; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void addTab(Tab tab) { |
| 207 | mTabBar.onNewTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | protected void onAddTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 211 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 215 | public void setActiveTab(final Tab tab) { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 216 | cancelTitleBarAnimation(true); |
| 217 | mSkipTitleBarAnimations = true; |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 218 | if (mUseQuickControls) { |
| 219 | if (mActiveTab != null) { |
| 220 | captureTab(mActiveTab); |
| 221 | } |
| 222 | } |
Michael Kolb | f262892 | 2011-03-09 17:15:28 -0800 | [diff] [blame] | 223 | super.setActiveTab(tab, true); |
| 224 | setActiveTab(tab, true); |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 225 | mSkipTitleBarAnimations = false; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Override |
| 229 | void setActiveTab(Tab tab, boolean needsAttaching) { |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 230 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 231 | // TabControl.setCurrentTab has been called before this, |
| 232 | // so the tab is guaranteed to have a webview |
| 233 | if (view == null) { |
| 234 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 235 | return; |
| 236 | } |
| 237 | // Request focus on the top window. |
| 238 | if (mUseQuickControls) { |
| 239 | mPieControl.forceToTop(mContentView); |
| 240 | view.setScrollListener(null); |
| 241 | mTabBar.showTitleBarIndicator(false); |
| 242 | } else { |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 243 | // check if title bar is already attached by animation |
| 244 | if (mTitleBar.getParent() == null) { |
| 245 | view.setEmbeddedTitleBar(mTitleBar); |
| 246 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 247 | view.setScrollListener(this); |
| 248 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 249 | mTabBar.onSetActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 250 | if (tab.isInVoiceSearchMode()) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 251 | showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults()); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 252 | } else { |
| 253 | revertVoiceTitleBar(tab); |
| 254 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 255 | updateLockIconToLatest(tab); |
| 256 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 259 | public void captureTab(final Tab tab) { |
| 260 | Bitmap sshot = Controller.createScreenshot(tab, |
| 261 | (int) mActivity.getResources() |
| 262 | .getDimension(R.dimen.qc_thumb_width), |
| 263 | (int) mActivity.getResources() |
| 264 | .getDimension(R.dimen.qc_thumb_height)); |
| 265 | tab.setScreenshot(sshot); |
| 266 | } |
| 267 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 268 | @Override |
| 269 | public void updateTabs(List<Tab> tabs) { |
| 270 | mTabBar.updateTabs(tabs); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 271 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public void removeTab(Tab tab) { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 276 | cancelTitleBarAnimation(true); |
| 277 | mSkipTitleBarAnimations = true; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 278 | super.removeTab(tab); |
| 279 | mTabBar.onRemoveTab(tab); |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 280 | mSkipTitleBarAnimations = false; |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | protected void onRemoveTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 284 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 287 | int getContentWidth() { |
| 288 | if (mContentView != null) { |
| 289 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 290 | } |
| 291 | return 0; |
| 292 | } |
| 293 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 294 | @Override |
| 295 | public void editUrl(boolean clearInput) { |
Michael Kolb | d72ea3b | 2011-01-09 15:56:37 -0800 | [diff] [blame] | 296 | if (mUiController.isInCustomActionMode()) { |
| 297 | mUiController.endActionMode(); |
| 298 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 299 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 300 | mTitleBar.startEditingUrl(clearInput); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 303 | void showTitleBarAndEdit() { |
| 304 | mTitleBar.setShowProgressOnly(false); |
| 305 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 306 | mTitleBar.startEditingUrl(false); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void stopEditingUrl() { |
| 310 | mTitleBar.stopEditingUrl(); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | protected void showTitleBar() { |
| 315 | if (canShowTitleBar()) { |
| 316 | if (mUseQuickControls) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 317 | mContentView.addView(mTitleBar); |
| 318 | } else { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 319 | if (!mSkipTitleBarAnimations) { |
| 320 | cancelTitleBarAnimation(false); |
| 321 | int visibleHeight = getVisibleTitleHeight(); |
| 322 | float startPos = (-mTitleBar.getEmbeddedHeight() + visibleHeight); |
| 323 | if (mTitleBar.getTranslationY() != 0) { |
| 324 | startPos = Math.max(startPos, mTitleBar.getTranslationY()); |
| 325 | } |
| 326 | mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, |
| 327 | "translationY", |
| 328 | startPos, 0); |
| 329 | mTitleBarAnimator.start(); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 330 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 331 | setTitleGravity(Gravity.TOP); |
| 332 | } |
| 333 | super.showTitleBar(); |
| 334 | mTabBar.onShowTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 335 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 336 | } |
| 337 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 338 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 339 | protected void hideTitleBar() { |
| 340 | if (isTitleBarShowing()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 341 | mTabBar.onHideTitleBar(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 342 | if (mUseQuickControls) { |
| 343 | mContentView.removeView(mTitleBar); |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 344 | } else { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 345 | if (!mSkipTitleBarAnimations) { |
| 346 | cancelTitleBarAnimation(false); |
| 347 | int visibleHeight = getVisibleTitleHeight(); |
| 348 | mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, |
| 349 | "translationY", mTitleBar.getTranslationY(), |
| 350 | (-mTitleBar.getEmbeddedHeight() + visibleHeight)); |
| 351 | mTitleBarAnimator.addListener(mHideTileBarAnimatorListener); |
| 352 | mTitleBarAnimator.start(); |
| 353 | } else { |
| 354 | setTitleGravity(Gravity.NO_GRAVITY); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 355 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 356 | } |
| 357 | super.hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 361 | private void cancelTitleBarAnimation(boolean reset) { |
| 362 | if (mTitleBarAnimator != null) { |
| 363 | mTitleBarAnimator.cancel(); |
| 364 | mTitleBarAnimator = null; |
| 365 | } |
| 366 | if (reset) { |
| 367 | mTitleBar.setTranslationY(0); |
| 368 | } |
| 369 | } |
| 370 | |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 371 | private int getVisibleTitleHeight() { |
| 372 | WebView webview = mActiveTab != null ? mActiveTab.getWebView() : null; |
| 373 | return webview != null ? webview.getVisibleTitleHeight() : 0; |
| 374 | } |
| 375 | |
| 376 | private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() { |
| 377 | |
| 378 | boolean mWasCanceled; |
| 379 | @Override |
| 380 | public void onAnimationStart(Animator animation) { |
| 381 | mWasCanceled = false; |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public void onAnimationRepeat(Animator animation) { |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void onAnimationEnd(Animator animation) { |
| 390 | if (!mWasCanceled) { |
| 391 | mTitleBar.setTranslationY(0); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 392 | } |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 393 | setTitleGravity(Gravity.NO_GRAVITY); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public void onAnimationCancel(Animator animation) { |
| 398 | mWasCanceled = true; |
| 399 | } |
| 400 | }; |
| 401 | |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 402 | public boolean isEditingUrl() { |
| 403 | return mTitleBar.isEditingUrl(); |
| 404 | } |
| 405 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 406 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 407 | protected TitleBarBase getTitleBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 408 | return mTitleBar; |
| 409 | } |
| 410 | |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 411 | @Override |
| 412 | protected void setTitleGravity(int gravity) { |
| 413 | if (mUseQuickControls) { |
| 414 | FrameLayout.LayoutParams lp = |
| 415 | (FrameLayout.LayoutParams) mTitleBar.getLayoutParams(); |
| 416 | lp.gravity = gravity; |
| 417 | mTitleBar.setLayoutParams(lp); |
| 418 | } else { |
| 419 | super.setTitleGravity(gravity); |
| 420 | } |
| 421 | } |
| 422 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 423 | // action mode callbacks |
| 424 | |
| 425 | @Override |
| 426 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 427 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 428 | // hide the fake title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 429 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 434 | public void onActionModeFinished(boolean inLoad) { |
| 435 | checkTabCount(); |
| 436 | if (inLoad) { |
| 437 | // the titlebar was removed when the CAB was shown |
| 438 | // if the page is loading, show it again |
Michael Kolb | 1544f3b | 2011-03-10 09:06:10 -0800 | [diff] [blame] | 439 | if (mUseQuickControls) { |
| 440 | mTitleBar.setShowProgressOnly(true); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 441 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 442 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
| 446 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 447 | protected void updateNavigationState(Tab tab) { |
| 448 | mTitleBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 452 | public void setUrlTitle(Tab tab) { |
| 453 | super.setUrlTitle(tab); |
| 454 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | // Set the favicon in the title bar. |
| 458 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 459 | public void setFavicon(Tab tab) { |
| 460 | super.setFavicon(tab); |
| 461 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 464 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame^] | 465 | public void showVoiceTitleBar(String title, List<String> vsresults) { |
Michael Kolb | 3a2a164 | 2011-02-15 10:52:07 -0800 | [diff] [blame] | 466 | mTitleBar.setInVoiceMode(true, vsresults); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 467 | mTitleBar.setDisplayTitle(title); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | @Override |
| 471 | public void revertVoiceTitleBar(Tab tab) { |
| 472 | mTitleBar.setInVoiceMode(false, null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 473 | String url = tab.getUrl(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 474 | mTitleBar.setDisplayTitle(url); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 475 | } |
| 476 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 477 | @Override |
| 478 | public void showCustomView(View view, CustomViewCallback callback) { |
| 479 | super.showCustomView(view, callback); |
| 480 | mActivity.getActionBar().hide(); |
| 481 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 482 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 483 | @Override |
| 484 | public void onHideCustomView() { |
| 485 | super.onHideCustomView(); |
| 486 | if (mUseQuickControls) { |
| 487 | checkTabCount(); |
| 488 | } else { |
| 489 | mActivity.getActionBar().show(); |
| 490 | } |
| 491 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 492 | |
| 493 | @Override |
| 494 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 495 | if (mActiveTab != null) { |
| 496 | WebView web = mActiveTab.getWebView(); |
| 497 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 498 | switch (code) { |
| 499 | case KeyEvent.KEYCODE_TAB: |
| 500 | case KeyEvent.KEYCODE_DPAD_UP: |
| 501 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 502 | if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) { |
| 503 | editUrl(false); |
| 504 | return true; |
| 505 | } |
| 506 | } |
| 507 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 508 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
| 509 | editUrl(true); |
| 510 | return mContentView.dispatchKeyEvent(event); |
| 511 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 512 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 513 | } |
| 514 | return false; |
| 515 | } |
| 516 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 517 | private boolean isTypingKey(KeyEvent evt) { |
| 518 | return evt.getUnicodeChar() > 0; |
| 519 | } |
| 520 | |
| 521 | TabBar getTabBar() { |
| 522 | return mTabBar; |
| 523 | } |
| 524 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 525 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 526 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 527 | if (mUseQuickControls) { |
| 528 | mPieControl.onMenuOpened(menu); |
| 529 | return false; |
| 530 | } else { |
| 531 | return true; |
| 532 | } |
| 533 | } |
| 534 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 535 | } |