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