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 | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 228 | if (mUseQuickControls) { |
| 229 | if (mActiveTab != null) { |
| 230 | captureTab(mActiveTab); |
| 231 | } |
| 232 | } |
Michael Kolb | f262892 | 2011-03-09 17:15:28 -0800 | [diff] [blame] | 233 | super.setActiveTab(tab, true); |
| 234 | setActiveTab(tab, true); |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 235 | mSkipTitleBarAnimations = false; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Override |
| 239 | void setActiveTab(Tab tab, boolean needsAttaching) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 240 | ScrollWebView view = (ScrollWebView) tab.getWebView(); |
| 241 | // TabControl.setCurrentTab has been called before this, |
| 242 | // so the tab is guaranteed to have a webview |
| 243 | if (view == null) { |
| 244 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 245 | return; |
| 246 | } |
| 247 | // Request focus on the top window. |
| 248 | if (mUseQuickControls) { |
| 249 | mPieControl.forceToTop(mContentView); |
| 250 | view.setScrollListener(null); |
| 251 | mTabBar.showTitleBarIndicator(false); |
| 252 | } else { |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 253 | // check if title bar is already attached by animation |
| 254 | if (mTitleBar.getParent() == null) { |
| 255 | view.setEmbeddedTitleBar(mTitleBar); |
| 256 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 257 | view.setScrollListener(this); |
| 258 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 259 | mTabBar.onSetActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 260 | if (tab.isInVoiceSearchMode()) { |
| 261 | showVoiceTitleBar(tab.getVoiceDisplayTitle()); |
| 262 | } else { |
| 263 | revertVoiceTitleBar(tab); |
| 264 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 265 | updateLockIconToLatest(tab); |
| 266 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 269 | public void captureTab(final Tab tab) { |
| 270 | Bitmap sshot = Controller.createScreenshot(tab, |
| 271 | (int) mActivity.getResources() |
| 272 | .getDimension(R.dimen.qc_thumb_width), |
| 273 | (int) mActivity.getResources() |
| 274 | .getDimension(R.dimen.qc_thumb_height)); |
| 275 | tab.setScreenshot(sshot); |
| 276 | } |
| 277 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 278 | @Override |
| 279 | public void updateTabs(List<Tab> tabs) { |
| 280 | mTabBar.updateTabs(tabs); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 281 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public void removeTab(Tab tab) { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 286 | cancelTitleBarAnimation(true); |
| 287 | mSkipTitleBarAnimations = true; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 288 | super.removeTab(tab); |
| 289 | mTabBar.onRemoveTab(tab); |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 290 | mSkipTitleBarAnimations = false; |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | protected void onRemoveTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 294 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 297 | int getContentWidth() { |
| 298 | if (mContentView != null) { |
| 299 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 300 | } |
| 301 | return 0; |
| 302 | } |
| 303 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 304 | @Override |
| 305 | public void editUrl(boolean clearInput) { |
Michael Kolb | d72ea3b | 2011-01-09 15:56:37 -0800 | [diff] [blame] | 306 | if (mUiController.isInCustomActionMode()) { |
| 307 | mUiController.endActionMode(); |
| 308 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 309 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 310 | mTitleBar.startEditingUrl(clearInput); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 313 | void showTitleBarAndEdit() { |
| 314 | mTitleBar.setShowProgressOnly(false); |
| 315 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 316 | mTitleBar.startEditingUrl(false); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void stopEditingUrl() { |
| 320 | mTitleBar.stopEditingUrl(); |
| 321 | } |
| 322 | |
| 323 | @Override |
| 324 | protected void showTitleBar() { |
| 325 | if (canShowTitleBar()) { |
| 326 | if (mUseQuickControls) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 327 | mContentView.addView(mTitleBar); |
| 328 | } else { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 329 | if (!mSkipTitleBarAnimations) { |
| 330 | cancelTitleBarAnimation(false); |
| 331 | int visibleHeight = getVisibleTitleHeight(); |
| 332 | float startPos = (-mTitleBar.getEmbeddedHeight() + visibleHeight); |
| 333 | if (mTitleBar.getTranslationY() != 0) { |
| 334 | startPos = Math.max(startPos, mTitleBar.getTranslationY()); |
| 335 | } |
| 336 | mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, |
| 337 | "translationY", |
| 338 | startPos, 0); |
| 339 | mTitleBarAnimator.start(); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 340 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 341 | setTitleGravity(Gravity.TOP); |
| 342 | } |
| 343 | super.showTitleBar(); |
| 344 | mTabBar.onShowTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 345 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 348 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 349 | protected void hideTitleBar() { |
| 350 | if (isTitleBarShowing()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 351 | mTabBar.onHideTitleBar(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 352 | if (mUseQuickControls) { |
| 353 | mContentView.removeView(mTitleBar); |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 354 | } else { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 355 | if (!mSkipTitleBarAnimations) { |
| 356 | cancelTitleBarAnimation(false); |
| 357 | int visibleHeight = getVisibleTitleHeight(); |
| 358 | mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, |
| 359 | "translationY", mTitleBar.getTranslationY(), |
| 360 | (-mTitleBar.getEmbeddedHeight() + visibleHeight)); |
| 361 | mTitleBarAnimator.addListener(mHideTileBarAnimatorListener); |
| 362 | mTitleBarAnimator.start(); |
| 363 | } else { |
| 364 | setTitleGravity(Gravity.NO_GRAVITY); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 365 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 366 | } |
| 367 | super.hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 371 | private void cancelTitleBarAnimation(boolean reset) { |
| 372 | if (mTitleBarAnimator != null) { |
| 373 | mTitleBarAnimator.cancel(); |
| 374 | mTitleBarAnimator = null; |
| 375 | } |
| 376 | if (reset) { |
| 377 | mTitleBar.setTranslationY(0); |
| 378 | } |
| 379 | } |
| 380 | |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 381 | private int getVisibleTitleHeight() { |
| 382 | WebView webview = mActiveTab != null ? mActiveTab.getWebView() : null; |
| 383 | return webview != null ? webview.getVisibleTitleHeight() : 0; |
| 384 | } |
| 385 | |
| 386 | private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() { |
| 387 | |
| 388 | boolean mWasCanceled; |
| 389 | @Override |
| 390 | public void onAnimationStart(Animator animation) { |
| 391 | mWasCanceled = false; |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public void onAnimationRepeat(Animator animation) { |
| 396 | } |
| 397 | |
| 398 | @Override |
| 399 | public void onAnimationEnd(Animator animation) { |
| 400 | if (!mWasCanceled) { |
| 401 | mTitleBar.setTranslationY(0); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 402 | } |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame] | 403 | setTitleGravity(Gravity.NO_GRAVITY); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | @Override |
| 407 | public void onAnimationCancel(Animator animation) { |
| 408 | mWasCanceled = true; |
| 409 | } |
| 410 | }; |
| 411 | |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 412 | public boolean isEditingUrl() { |
| 413 | return mTitleBar.isEditingUrl(); |
| 414 | } |
| 415 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 416 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 417 | protected TitleBarBase getTitleBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 418 | return mTitleBar; |
| 419 | } |
| 420 | |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 421 | @Override |
| 422 | protected void setTitleGravity(int gravity) { |
| 423 | if (mUseQuickControls) { |
| 424 | FrameLayout.LayoutParams lp = |
| 425 | (FrameLayout.LayoutParams) mTitleBar.getLayoutParams(); |
| 426 | lp.gravity = gravity; |
| 427 | mTitleBar.setLayoutParams(lp); |
| 428 | } else { |
| 429 | super.setTitleGravity(gravity); |
| 430 | } |
| 431 | } |
| 432 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 433 | // action mode callbacks |
| 434 | |
| 435 | @Override |
| 436 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 437 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 438 | // hide the fake title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 439 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
| 443 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 444 | public void onActionModeFinished(boolean inLoad) { |
| 445 | checkTabCount(); |
| 446 | if (inLoad) { |
| 447 | // the titlebar was removed when the CAB was shown |
| 448 | // if the page is loading, show it again |
Michael Kolb | 1544f3b | 2011-03-10 09:06:10 -0800 | [diff] [blame] | 449 | if (mUseQuickControls) { |
| 450 | mTitleBar.setShowProgressOnly(true); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 451 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 452 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 457 | protected void updateNavigationState(Tab tab) { |
| 458 | mTitleBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | @Override |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 462 | protected void updateAutoLogin(Tab tab, boolean animate) { |
| 463 | mTitleBar.updateAutoLogin(tab, animate); |
| 464 | } |
| 465 | |
| 466 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 467 | public void setUrlTitle(Tab tab) { |
| 468 | super.setUrlTitle(tab); |
| 469 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | // Set the favicon in the title bar. |
| 473 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 474 | public void setFavicon(Tab tab) { |
| 475 | super.setFavicon(tab); |
| 476 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 479 | @Override |
| 480 | public void showVoiceTitleBar(String title) { |
| 481 | List<String> vsresults = null; |
| 482 | if (getActiveTab() != null) { |
| 483 | vsresults = getActiveTab().getVoiceSearchResults(); |
| 484 | } |
Michael Kolb | 3a2a164 | 2011-02-15 10:52:07 -0800 | [diff] [blame] | 485 | mTitleBar.setInVoiceMode(true, vsresults); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 486 | mTitleBar.setDisplayTitle(title); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public void revertVoiceTitleBar(Tab tab) { |
| 491 | mTitleBar.setInVoiceMode(false, null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 492 | String url = tab.getUrl(); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 493 | mTitleBar.setDisplayTitle(url); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 494 | } |
| 495 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 496 | @Override |
| 497 | public void showCustomView(View view, CustomViewCallback callback) { |
| 498 | super.showCustomView(view, callback); |
| 499 | mActivity.getActionBar().hide(); |
| 500 | } |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 501 | |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 502 | @Override |
| 503 | public void onHideCustomView() { |
| 504 | super.onHideCustomView(); |
| 505 | if (mUseQuickControls) { |
| 506 | checkTabCount(); |
| 507 | } else { |
| 508 | mActivity.getActionBar().show(); |
| 509 | } |
| 510 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 511 | |
| 512 | @Override |
| 513 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 514 | if (mActiveTab != null) { |
| 515 | WebView web = mActiveTab.getWebView(); |
| 516 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 517 | switch (code) { |
| 518 | case KeyEvent.KEYCODE_TAB: |
| 519 | case KeyEvent.KEYCODE_DPAD_UP: |
| 520 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 521 | if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) { |
| 522 | editUrl(false); |
| 523 | return true; |
| 524 | } |
| 525 | } |
| 526 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 527 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
| 528 | editUrl(true); |
| 529 | return mContentView.dispatchKeyEvent(event); |
| 530 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 531 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 532 | } |
| 533 | return false; |
| 534 | } |
| 535 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 536 | private boolean isTypingKey(KeyEvent evt) { |
| 537 | return evt.getUnicodeChar() > 0; |
| 538 | } |
| 539 | |
| 540 | TabBar getTabBar() { |
| 541 | return mTabBar; |
| 542 | } |
| 543 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 544 | @Override |
| 545 | public void registerDropdownChangeListener(DropdownChangeListener d) { |
| 546 | mTitleBar.registerDropdownChangeListener(d); |
| 547 | } |
Michael Kolb | 0860d99 | 2011-03-07 15:26:33 -0800 | [diff] [blame] | 548 | |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 549 | @Override |
| 550 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 551 | if (mUseQuickControls) { |
| 552 | mPieControl.onMenuOpened(menu); |
| 553 | return false; |
| 554 | } else { |
| 555 | return true; |
| 556 | } |
| 557 | } |
| 558 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 559 | } |