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