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