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 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 110 | setTitleGravity(Gravity.BOTTOM); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 111 | } else { |
| 112 | mActivity.getActionBar().show(); |
| 113 | if (mPieControl != null) { |
| 114 | mPieControl.removeFromContainer(mContentView); |
| 115 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 116 | setTitleGravity(Gravity.TOP); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 117 | WebView web = mTabControl.getCurrentWebView(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 118 | if (web != null) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 119 | web.setEmbeddedTitleBar(mTitleBar); |
| 120 | } |
| 121 | } |
| 122 | mTabBar.setUseQuickControls(mUseQuickControls); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | private void checkTabCount() { |
| 126 | if (mUseQuickControls) { |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 127 | mHandler.post(new Runnable() { |
| 128 | public void run() { |
| 129 | mActionBar.hide(); |
| 130 | } |
| 131 | }); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 132 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 136 | public void onResume() { |
| 137 | super.onResume(); |
| 138 | if (!BrowserSettings.getInstance().useInstant()) { |
| 139 | mTitleBar.clearCompletions(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 144 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 145 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // webview factory |
| 149 | |
| 150 | @Override |
| 151 | public WebView createWebView(boolean privateBrowsing) { |
| 152 | // Create a new WebView |
| 153 | ScrollWebView w = new ScrollWebView(mActivity, null, |
| 154 | android.R.attr.webViewStyle, privateBrowsing); |
| 155 | initWebViewSettings(w); |
| 156 | w.setScrollListener(this); |
Michael Kolb | 2491522 | 2011-02-24 11:38:49 -0800 | [diff] [blame] | 157 | boolean supportsMultiTouch = mActivity.getPackageManager() |
| 158 | .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH); |
| 159 | w.getSettings().setDisplayZoomControls(!supportsMultiTouch); |
Dave Burke | 20b6f1f | 2011-02-01 12:59:04 +0000 | [diff] [blame] | 160 | w.setExpandedTileBounds(true); // smoother scrolling |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 161 | return w; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public WebView createSubWebView(boolean privateBrowsing) { |
| 166 | ScrollWebView web = (ScrollWebView) createWebView(privateBrowsing); |
| 167 | // no scroll listener for subview |
| 168 | web.setScrollListener(null); |
| 169 | return web; |
| 170 | } |
| 171 | |
| 172 | @Override |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 173 | public void onScroll(int visibleTitleHeight, boolean userInitiated) { |
| 174 | mTabBar.onScroll(visibleTitleHeight, userInitiated); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void stopWebViewScrolling() { |
| 178 | ScrollWebView web = (ScrollWebView) mUiController.getCurrentWebView(); |
| 179 | if (web != null) { |
| 180 | web.stopScroll(); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // WebView callbacks |
| 185 | |
| 186 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 187 | public void onProgressChanged(Tab tab) { |
| 188 | int progress = tab.getLoadProgress(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 189 | mTabBar.onProgress(tab, progress); |
| 190 | if (tab.inForeground()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 191 | mTitleBar.setProgress(progress); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 192 | if (progress == 100) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 193 | if (!mTitleBar.isEditingUrl()) { |
| 194 | hideTitleBar(); |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 195 | if (mUseQuickControls) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 196 | mTitleBar.setShowProgressOnly(false); |
| 197 | setTitleGravity(Gravity.BOTTOM); |
Michael Kolb | bd018d4 | 2010-12-15 15:43:39 -0800 | [diff] [blame] | 198 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 199 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 200 | } else { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 201 | if (!isTitleBarShowing()) { |
| 202 | if (mUseQuickControls && !mTitleBar.isEditingUrl()) { |
| 203 | mTitleBar.setShowProgressOnly(true); |
| 204 | setTitleGravity(Gravity.TOP); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 205 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 206 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 207 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public boolean needsRestoreAllTabs() { |
| 214 | return true; |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public void addTab(Tab tab) { |
| 219 | mTabBar.onNewTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | protected void onAddTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 223 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 227 | public void setActiveTab(final Tab tab) { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 228 | cancelTitleBarAnimation(true); |
| 229 | mSkipTitleBarAnimations = true; |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 230 | if (mUseQuickControls) { |
| 231 | if (mActiveTab != null) { |
| 232 | captureTab(mActiveTab); |
| 233 | } |
| 234 | } |
Michael Kolb | f262892 | 2011-03-09 17:15:28 -0800 | [diff] [blame] | 235 | super.setActiveTab(tab, true); |
| 236 | setActiveTab(tab, true); |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 237 | mSkipTitleBarAnimations = false; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | void setActiveTab(Tab tab, boolean needsAttaching) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 242 | ScrollWebView view = (ScrollWebView) tab.getWebView(); |
| 243 | // TabControl.setCurrentTab has been called before this, |
| 244 | // so the tab is guaranteed to have a webview |
| 245 | if (view == null) { |
| 246 | Log.e(LOGTAG, "active tab with no webview detected"); |
| 247 | return; |
| 248 | } |
| 249 | // Request focus on the top window. |
| 250 | if (mUseQuickControls) { |
| 251 | mPieControl.forceToTop(mContentView); |
| 252 | view.setScrollListener(null); |
| 253 | mTabBar.showTitleBarIndicator(false); |
| 254 | } else { |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 255 | // check if title bar is already attached by animation |
| 256 | if (mTitleBar.getParent() == null) { |
| 257 | view.setEmbeddedTitleBar(mTitleBar); |
| 258 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 259 | view.setScrollListener(this); |
| 260 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 261 | mTabBar.onSetActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 262 | if (tab.isInVoiceSearchMode()) { |
| 263 | showVoiceTitleBar(tab.getVoiceDisplayTitle()); |
| 264 | } else { |
| 265 | revertVoiceTitleBar(tab); |
| 266 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 267 | updateLockIconToLatest(tab); |
| 268 | tab.getTopWindow().requestFocus(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 271 | public void captureTab(final Tab tab) { |
| 272 | Bitmap sshot = Controller.createScreenshot(tab, |
| 273 | (int) mActivity.getResources() |
| 274 | .getDimension(R.dimen.qc_thumb_width), |
| 275 | (int) mActivity.getResources() |
| 276 | .getDimension(R.dimen.qc_thumb_height)); |
| 277 | tab.setScreenshot(sshot); |
| 278 | } |
| 279 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 280 | @Override |
| 281 | public void updateTabs(List<Tab> tabs) { |
| 282 | mTabBar.updateTabs(tabs); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 283 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void removeTab(Tab tab) { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 288 | cancelTitleBarAnimation(true); |
| 289 | mSkipTitleBarAnimations = true; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 290 | super.removeTab(tab); |
| 291 | mTabBar.onRemoveTab(tab); |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 292 | mSkipTitleBarAnimations = false; |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | protected void onRemoveTabCompleted(Tab tab) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 296 | checkTabCount(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 299 | int getContentWidth() { |
| 300 | if (mContentView != null) { |
| 301 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 302 | } |
| 303 | return 0; |
| 304 | } |
| 305 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 306 | @Override |
| 307 | public void editUrl(boolean clearInput) { |
Michael Kolb | d72ea3b | 2011-01-09 15:56:37 -0800 | [diff] [blame] | 308 | if (mUiController.isInCustomActionMode()) { |
| 309 | mUiController.endActionMode(); |
| 310 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 311 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 312 | mTitleBar.startEditingUrl(clearInput); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 315 | void showTitleBarAndEdit() { |
| 316 | mTitleBar.setShowProgressOnly(false); |
| 317 | showTitleBar(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 318 | mTitleBar.startEditingUrl(false); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void stopEditingUrl() { |
| 322 | mTitleBar.stopEditingUrl(); |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | protected void showTitleBar() { |
| 327 | if (canShowTitleBar()) { |
| 328 | if (mUseQuickControls) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 329 | mContentView.addView(mTitleBar); |
| 330 | } else { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 331 | if (!mSkipTitleBarAnimations) { |
| 332 | cancelTitleBarAnimation(false); |
| 333 | int visibleHeight = getVisibleTitleHeight(); |
| 334 | float startPos = (-mTitleBar.getEmbeddedHeight() + visibleHeight); |
| 335 | if (mTitleBar.getTranslationY() != 0) { |
| 336 | startPos = Math.max(startPos, mTitleBar.getTranslationY()); |
| 337 | } |
| 338 | mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, |
| 339 | "translationY", |
| 340 | startPos, 0); |
| 341 | mTitleBarAnimator.start(); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 342 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 343 | setTitleGravity(Gravity.TOP); |
| 344 | } |
| 345 | super.showTitleBar(); |
| 346 | mTabBar.onShowTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 347 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 350 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 351 | protected void hideTitleBar() { |
| 352 | if (isTitleBarShowing()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 353 | mTabBar.onHideTitleBar(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 354 | if (mUseQuickControls) { |
| 355 | mContentView.removeView(mTitleBar); |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 356 | } else { |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 357 | if (!mSkipTitleBarAnimations) { |
| 358 | cancelTitleBarAnimation(false); |
| 359 | int visibleHeight = getVisibleTitleHeight(); |
| 360 | mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar, |
| 361 | "translationY", mTitleBar.getTranslationY(), |
| 362 | (-mTitleBar.getEmbeddedHeight() + visibleHeight)); |
| 363 | mTitleBarAnimator.addListener(mHideTileBarAnimatorListener); |
| 364 | mTitleBarAnimator.start(); |
| 365 | } else { |
| 366 | setTitleGravity(Gravity.NO_GRAVITY); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 367 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 368 | } |
| 369 | super.hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 373 | private void cancelTitleBarAnimation(boolean reset) { |
| 374 | if (mTitleBarAnimator != null) { |
| 375 | mTitleBarAnimator.cancel(); |
| 376 | mTitleBarAnimator = null; |
| 377 | } |
| 378 | if (reset) { |
| 379 | mTitleBar.setTranslationY(0); |
| 380 | } |
| 381 | } |
| 382 | |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 383 | private int getVisibleTitleHeight() { |
| 384 | WebView webview = mActiveTab != null ? mActiveTab.getWebView() : null; |
| 385 | return webview != null ? webview.getVisibleTitleHeight() : 0; |
| 386 | } |
| 387 | |
| 388 | private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() { |
| 389 | |
| 390 | boolean mWasCanceled; |
| 391 | @Override |
| 392 | public void onAnimationStart(Animator animation) { |
| 393 | mWasCanceled = false; |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public void onAnimationRepeat(Animator animation) { |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public void onAnimationEnd(Animator animation) { |
| 402 | if (!mWasCanceled) { |
| 403 | mTitleBar.setTranslationY(0); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 404 | } |
John Reck | 6e8d2e9 | 2011-03-14 11:29:56 -0700 | [diff] [blame^] | 405 | setTitleGravity(Gravity.NO_GRAVITY); |
John Reck | e5c21d9 | 2011-03-11 15:09:46 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | @Override |
| 409 | public void onAnimationCancel(Animator animation) { |
| 410 | mWasCanceled = true; |
| 411 | } |
| 412 | }; |
| 413 | |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 414 | public boolean isEditingUrl() { |
| 415 | return mTitleBar.isEditingUrl(); |
| 416 | } |
| 417 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 418 | @Override |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 419 | protected TitleBarBase getTitleBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 420 | return mTitleBar; |
| 421 | } |
| 422 | |
Michael Kolb | 2a56eca | 2011-02-25 09:45:06 -0800 | [diff] [blame] | 423 | @Override |
| 424 | protected void setTitleGravity(int gravity) { |
| 425 | if (mUseQuickControls) { |
| 426 | FrameLayout.LayoutParams lp = |
| 427 | (FrameLayout.LayoutParams) mTitleBar.getLayoutParams(); |
| 428 | lp.gravity = gravity; |
| 429 | mTitleBar.setLayoutParams(lp); |
| 430 | } else { |
| 431 | super.setTitleGravity(gravity); |
| 432 | } |
| 433 | } |
| 434 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 435 | // action mode callbacks |
| 436 | |
| 437 | @Override |
| 438 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 439 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 440 | // hide the fake title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 441 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
| 445 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 446 | public void onActionModeFinished(boolean inLoad) { |
| 447 | checkTabCount(); |
| 448 | if (inLoad) { |
| 449 | // the titlebar was removed when the CAB was shown |
| 450 | // if the page is loading, show it again |
Michael Kolb | 1544f3b | 2011-03-10 09:06:10 -0800 | [diff] [blame] | 451 | if (mUseQuickControls) { |
| 452 | mTitleBar.setShowProgressOnly(true); |
| 453 | if (!isTitleBarShowing()) { |
| 454 | setTitleGravity(Gravity.TOP); |
| 455 | } |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 456 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 457 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
| 461 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 462 | protected void updateNavigationState(Tab tab) { |
| 463 | mTitleBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 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 | } |