blob: c763bb07fdc4128519b9d8d589210eafcd9b9c81 [file] [log] [blame]
Michael Kolb66706532010-12-12 19:50:22 -08001/*
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
17package com.android.browser;
18
John Reckb9a051b2011-03-18 11:55:48 -070019import com.android.browser.BrowserWebView.ScrollListener;
Michael Kolb66706532010-12-12 19:50:22 -080020
John Recke5c21d92011-03-11 15:09:46 -080021import android.animation.Animator;
22import android.animation.Animator.AnimatorListener;
23import android.animation.ObjectAnimator;
Michael Kolb66706532010-12-12 19:50:22 -080024import android.app.ActionBar;
25import android.app.Activity;
Michael Kolbeb95db42011-03-03 10:38:40 -080026import android.graphics.Bitmap;
Michael Kolbac35bdc2011-01-17 17:06:04 -080027import android.os.Bundle;
Michael Kolbba238702011-03-08 10:40:50 -080028import android.os.Handler;
Michael Kolb376b5412010-12-15 11:52:57 -080029import android.util.Log;
Michael Kolb66706532010-12-12 19:50:22 -080030import android.view.ActionMode;
Michael Kolb376b5412010-12-15 11:52:57 -080031import android.view.Gravity;
Michael Kolba4183062011-01-16 10:43:21 -080032import android.view.KeyEvent;
Michael Kolb1acef692011-03-08 14:12:06 -080033import android.view.Menu;
John Reckd73c5a22010-12-22 10:22:50 -080034import android.view.View;
35import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb66706532010-12-12 19:50:22 -080036import android.webkit.WebView;
Michael Kolb2a56eca2011-02-25 09:45:06 -080037import android.widget.FrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080038
39import java.util.List;
40
41/**
42 * Ui for xlarge screen sizes
43 */
44public class XLargeUi extends BaseUi implements ScrollListener {
45
46 private static final String LOGTAG = "XLargeUi";
47
Michael Kolb376b5412010-12-15 11:52:57 -080048 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080049 private TabBar mTabBar;
50
51 private TitleBarXLarge mTitleBar;
John Recke5c21d92011-03-11 15:09:46 -080052 private Animator mTitleBarAnimator;
John Reck6e8d2e92011-03-14 11:29:56 -070053 private boolean mSkipTitleBarAnimations;
Michael Kolb66706532010-12-12 19:50:22 -080054
Michael Kolb376b5412010-12-15 11:52:57 -080055 private boolean mUseQuickControls;
56 private PieControl mPieControl;
Michael Kolbba238702011-03-08 10:40:50 -080057 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080058
Michael Kolb66706532010-12-12 19:50:22 -080059 /**
60 * @param browser
61 * @param controller
62 */
63 public XLargeUi(Activity browser, UiController controller) {
64 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080065 mHandler = new Handler();
Michael Kolb66706532010-12-12 19:50:22 -080066 mTitleBar = new TitleBarXLarge(mActivity, mUiController, this);
67 mTitleBar.setProgress(100);
Michael Kolb66706532010-12-12 19:50:22 -080068 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080069 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080070 setupActionBar();
71 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
72 }
73
74 private void setupActionBar() {
75 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080076 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
77 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080078 }
79
80 @Override
Michael Kolbac35bdc2011-01-17 17:06:04 -080081 public void showComboView(boolean startWithHistory, Bundle extras) {
82 super.showComboView(startWithHistory, extras);
83 if (mUseQuickControls) {
84 mActionBar.show();
85 }
86 }
87
88 @Override
John Reckb3417f02011-01-14 11:01:05 -080089 public void hideComboView() {
Michael Kolbba238702011-03-08 10:40:50 -080090 if (isComboViewShowing()) {
91 super.hideComboView();
92 // ComboView changes the action bar, set it back up to what we want
93 setupActionBar();
94 checkTabCount();
95 }
Michael Kolb376b5412010-12-15 11:52:57 -080096 }
97
98 private void setUseQuickControls(boolean useQuickControls) {
99 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800100 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800101 if (useQuickControls) {
102 checkTabCount();
103 mPieControl = new PieControl(mActivity, mUiController, this);
104 mPieControl.attachToContainer(mContentView);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800105 Tab tab = getActiveTab();
106 if ((tab != null) && (tab.getWebView() != null)) {
107 tab.getWebView().setEmbeddedTitleBar(null);
Michael Kolb376b5412010-12-15 11:52:57 -0800108 }
109 } else {
110 mActivity.getActionBar().show();
111 if (mPieControl != null) {
112 mPieControl.removeFromContainer(mContentView);
113 }
Michael Kolb376b5412010-12-15 11:52:57 -0800114 WebView web = mTabControl.getCurrentWebView();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800115 if (web != null) {
Michael Kolb376b5412010-12-15 11:52:57 -0800116 web.setEmbeddedTitleBar(mTitleBar);
117 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700118 setTitleGravity(Gravity.NO_GRAVITY);
Michael Kolb376b5412010-12-15 11:52:57 -0800119 }
120 mTabBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800121 }
122
123 private void checkTabCount() {
124 if (mUseQuickControls) {
Michael Kolbeb95db42011-03-03 10:38:40 -0800125 mHandler.post(new Runnable() {
126 public void run() {
127 mActionBar.hide();
128 }
129 });
Michael Kolb376b5412010-12-15 11:52:57 -0800130 }
Michael Kolb66706532010-12-12 19:50:22 -0800131 }
132
133 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000134 public void onResume() {
135 super.onResume();
136 if (!BrowserSettings.getInstance().useInstant()) {
137 mTitleBar.clearCompletions();
138 }
139 }
140
141 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800142 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800143 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800144 }
145
146 // webview factory
147
148 @Override
149 public WebView createWebView(boolean privateBrowsing) {
150 // Create a new WebView
John Reckb9a051b2011-03-18 11:55:48 -0700151 BrowserWebView w = (BrowserWebView) super.createWebView(privateBrowsing);
Michael Kolb66706532010-12-12 19:50:22 -0800152 w.setScrollListener(this);
Michael Kolb66706532010-12-12 19:50:22 -0800153 return w;
154 }
155
156 @Override
157 public WebView createSubWebView(boolean privateBrowsing) {
John Reckb9a051b2011-03-18 11:55:48 -0700158 return super.createWebView(privateBrowsing);
Michael Kolb66706532010-12-12 19:50:22 -0800159 }
160
161 @Override
Michael Kolb5ee018e2011-02-18 15:47:21 -0800162 public void onScroll(int visibleTitleHeight, boolean userInitiated) {
163 mTabBar.onScroll(visibleTitleHeight, userInitiated);
Michael Kolb66706532010-12-12 19:50:22 -0800164 }
165
166 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700167 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Michael Kolb66706532010-12-12 19:50:22 -0800168 if (web != null) {
169 web.stopScroll();
170 }
171 }
172
173 // WebView callbacks
174
175 @Override
John Reck30c714c2010-12-16 17:30:34 -0800176 public void onProgressChanged(Tab tab) {
177 int progress = tab.getLoadProgress();
Michael Kolb66706532010-12-12 19:50:22 -0800178 mTabBar.onProgress(tab, progress);
179 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800180 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800181 if (progress == 100) {
Michael Kolb8a4c3822011-03-15 14:52:05 -0700182 if (!mTitleBar.isEditingUrl() && !mTitleBar.inAutoLogin()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800183 hideTitleBar();
Michael Kolbbd018d42010-12-15 15:43:39 -0800184 if (mUseQuickControls) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800185 mTitleBar.setShowProgressOnly(false);
Michael Kolbbd018d42010-12-15 15:43:39 -0800186 }
Michael Kolb376b5412010-12-15 11:52:57 -0800187 }
Michael Kolb66706532010-12-12 19:50:22 -0800188 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800189 if (!isTitleBarShowing()) {
190 if (mUseQuickControls && !mTitleBar.isEditingUrl()) {
191 mTitleBar.setShowProgressOnly(true);
192 setTitleGravity(Gravity.TOP);
Michael Kolb376b5412010-12-15 11:52:57 -0800193 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800194 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800195 }
Michael Kolb66706532010-12-12 19:50:22 -0800196 }
197 }
198 }
199
200 @Override
201 public boolean needsRestoreAllTabs() {
202 return true;
203 }
204
205 @Override
206 public void addTab(Tab tab) {
207 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800208 }
209
210 protected void onAddTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800211 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800212 }
213
214 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800215 public void setActiveTab(final Tab tab) {
John Reck6e8d2e92011-03-14 11:29:56 -0700216 cancelTitleBarAnimation(true);
217 mSkipTitleBarAnimations = true;
Michael Kolbeb95db42011-03-03 10:38:40 -0800218 if (mUseQuickControls) {
219 if (mActiveTab != null) {
220 captureTab(mActiveTab);
221 }
222 }
Michael Kolbf2628922011-03-09 17:15:28 -0800223 super.setActiveTab(tab, true);
224 setActiveTab(tab, true);
John Reck6e8d2e92011-03-14 11:29:56 -0700225 mSkipTitleBarAnimations = false;
Michael Kolb377ea312011-02-17 14:36:56 -0800226 }
227
228 @Override
229 void setActiveTab(Tab tab, boolean needsAttaching) {
John Reckb9a051b2011-03-18 11:55:48 -0700230 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800231 // TabControl.setCurrentTab has been called before this,
232 // so the tab is guaranteed to have a webview
233 if (view == null) {
234 Log.e(LOGTAG, "active tab with no webview detected");
235 return;
236 }
237 // Request focus on the top window.
238 if (mUseQuickControls) {
239 mPieControl.forceToTop(mContentView);
240 view.setScrollListener(null);
241 mTabBar.showTitleBarIndicator(false);
242 } else {
Michael Kolb377ea312011-02-17 14:36:56 -0800243 // check if title bar is already attached by animation
244 if (mTitleBar.getParent() == null) {
245 view.setEmbeddedTitleBar(mTitleBar);
246 }
Michael Kolb376b5412010-12-15 11:52:57 -0800247 view.setScrollListener(this);
248 }
Michael Kolb66706532010-12-12 19:50:22 -0800249 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800250 if (tab.isInVoiceSearchMode()) {
Michael Kolb11d19782011-03-20 10:17:40 -0700251 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
Michael Kolb376b5412010-12-15 11:52:57 -0800252 } else {
253 revertVoiceTitleBar(tab);
254 }
Michael Kolb376b5412010-12-15 11:52:57 -0800255 updateLockIconToLatest(tab);
256 tab.getTopWindow().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800257 }
258
Michael Kolbeb95db42011-03-03 10:38:40 -0800259 public void captureTab(final Tab tab) {
260 Bitmap sshot = Controller.createScreenshot(tab,
261 (int) mActivity.getResources()
262 .getDimension(R.dimen.qc_thumb_width),
263 (int) mActivity.getResources()
264 .getDimension(R.dimen.qc_thumb_height));
265 tab.setScreenshot(sshot);
266 }
267
Michael Kolb66706532010-12-12 19:50:22 -0800268 @Override
269 public void updateTabs(List<Tab> tabs) {
270 mTabBar.updateTabs(tabs);
Michael Kolb376b5412010-12-15 11:52:57 -0800271 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800272 }
273
274 @Override
275 public void removeTab(Tab tab) {
John Reck6e8d2e92011-03-14 11:29:56 -0700276 cancelTitleBarAnimation(true);
277 mSkipTitleBarAnimations = true;
Michael Kolb66706532010-12-12 19:50:22 -0800278 super.removeTab(tab);
279 mTabBar.onRemoveTab(tab);
John Reck6e8d2e92011-03-14 11:29:56 -0700280 mSkipTitleBarAnimations = false;
Michael Kolb8814d732011-01-26 11:22:30 -0800281 }
282
283 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800284 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800285 }
286
Michael Kolb376b5412010-12-15 11:52:57 -0800287 int getContentWidth() {
288 if (mContentView != null) {
289 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800290 }
291 return 0;
292 }
293
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800294 @Override
295 public void editUrl(boolean clearInput) {
Michael Kolbd72ea3b2011-01-09 15:56:37 -0800296 if (mUiController.isInCustomActionMode()) {
297 mUiController.endActionMode();
298 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800299 showTitleBar();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800300 mTitleBar.startEditingUrl(clearInput);
Michael Kolb66706532010-12-12 19:50:22 -0800301 }
302
Michael Kolb7cdc4902011-02-03 17:54:40 -0800303 void showTitleBarAndEdit() {
304 mTitleBar.setShowProgressOnly(false);
305 showTitleBar();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800306 mTitleBar.startEditingUrl(false);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800307 }
308
309 void stopEditingUrl() {
310 mTitleBar.stopEditingUrl();
311 }
312
313 @Override
314 protected void showTitleBar() {
315 if (canShowTitleBar()) {
316 if (mUseQuickControls) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800317 mContentView.addView(mTitleBar);
318 } else {
John Reck6e8d2e92011-03-14 11:29:56 -0700319 if (!mSkipTitleBarAnimations) {
320 cancelTitleBarAnimation(false);
321 int visibleHeight = getVisibleTitleHeight();
322 float startPos = (-mTitleBar.getEmbeddedHeight() + visibleHeight);
323 if (mTitleBar.getTranslationY() != 0) {
324 startPos = Math.max(startPos, mTitleBar.getTranslationY());
325 }
326 mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar,
327 "translationY",
328 startPos, 0);
329 mTitleBarAnimator.start();
John Recke5c21d92011-03-11 15:09:46 -0800330 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800331 setTitleGravity(Gravity.TOP);
332 }
333 super.showTitleBar();
334 mTabBar.onShowTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800335 }
Michael Kolb376b5412010-12-15 11:52:57 -0800336 }
337
Michael Kolb66706532010-12-12 19:50:22 -0800338 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800339 protected void hideTitleBar() {
340 if (isTitleBarShowing()) {
Michael Kolb66706532010-12-12 19:50:22 -0800341 mTabBar.onHideTitleBar();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800342 if (mUseQuickControls) {
343 mContentView.removeView(mTitleBar);
Michael Kolb2a56eca2011-02-25 09:45:06 -0800344 } else {
John Reck6e8d2e92011-03-14 11:29:56 -0700345 if (!mSkipTitleBarAnimations) {
346 cancelTitleBarAnimation(false);
347 int visibleHeight = getVisibleTitleHeight();
348 mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar,
349 "translationY", mTitleBar.getTranslationY(),
350 (-mTitleBar.getEmbeddedHeight() + visibleHeight));
351 mTitleBarAnimator.addListener(mHideTileBarAnimatorListener);
352 mTitleBarAnimator.start();
353 } else {
354 setTitleGravity(Gravity.NO_GRAVITY);
John Recke5c21d92011-03-11 15:09:46 -0800355 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800356 }
357 super.hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800358 }
359 }
360
John Reck6e8d2e92011-03-14 11:29:56 -0700361 private void cancelTitleBarAnimation(boolean reset) {
362 if (mTitleBarAnimator != null) {
363 mTitleBarAnimator.cancel();
364 mTitleBarAnimator = null;
365 }
366 if (reset) {
367 mTitleBar.setTranslationY(0);
368 }
369 }
370
John Recke5c21d92011-03-11 15:09:46 -0800371 private int getVisibleTitleHeight() {
372 WebView webview = mActiveTab != null ? mActiveTab.getWebView() : null;
373 return webview != null ? webview.getVisibleTitleHeight() : 0;
374 }
375
376 private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() {
377
378 boolean mWasCanceled;
379 @Override
380 public void onAnimationStart(Animator animation) {
381 mWasCanceled = false;
382 }
383
384 @Override
385 public void onAnimationRepeat(Animator animation) {
386 }
387
388 @Override
389 public void onAnimationEnd(Animator animation) {
390 if (!mWasCanceled) {
391 mTitleBar.setTranslationY(0);
John Recke5c21d92011-03-11 15:09:46 -0800392 }
John Reck6e8d2e92011-03-14 11:29:56 -0700393 setTitleGravity(Gravity.NO_GRAVITY);
John Recke5c21d92011-03-11 15:09:46 -0800394 }
395
396 @Override
397 public void onAnimationCancel(Animator animation) {
398 mWasCanceled = true;
399 }
400 };
401
Michael Kolb5ee018e2011-02-18 15:47:21 -0800402 public boolean isEditingUrl() {
403 return mTitleBar.isEditingUrl();
404 }
405
Michael Kolb66706532010-12-12 19:50:22 -0800406 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800407 protected TitleBarBase getTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800408 return mTitleBar;
409 }
410
Michael Kolb2a56eca2011-02-25 09:45:06 -0800411 @Override
412 protected void setTitleGravity(int gravity) {
413 if (mUseQuickControls) {
414 FrameLayout.LayoutParams lp =
415 (FrameLayout.LayoutParams) mTitleBar.getLayoutParams();
416 lp.gravity = gravity;
417 mTitleBar.setLayoutParams(lp);
418 } else {
419 super.setTitleGravity(gravity);
420 }
421 }
422
Michael Kolb66706532010-12-12 19:50:22 -0800423 // action mode callbacks
424
425 @Override
426 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800427 if (!mTitleBar.isEditingUrl()) {
Michael Kolb66706532010-12-12 19:50:22 -0800428 // hide the fake title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800429 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800430 }
431 }
432
433 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800434 public void onActionModeFinished(boolean inLoad) {
435 checkTabCount();
436 if (inLoad) {
437 // the titlebar was removed when the CAB was shown
438 // if the page is loading, show it again
Michael Kolb1544f3b2011-03-10 09:06:10 -0800439 if (mUseQuickControls) {
440 mTitleBar.setShowProgressOnly(true);
Michael Kolb376b5412010-12-15 11:52:57 -0800441 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800442 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800443 }
444 }
445
446 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800447 protected void updateNavigationState(Tab tab) {
448 mTitleBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800449 }
450
451 @Override
John Reck30c714c2010-12-16 17:30:34 -0800452 public void setUrlTitle(Tab tab) {
453 super.setUrlTitle(tab);
454 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800455 }
456
457 // Set the favicon in the title bar.
458 @Override
John Reck30c714c2010-12-16 17:30:34 -0800459 public void setFavicon(Tab tab) {
460 super.setFavicon(tab);
461 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800462 }
463
Michael Kolbcfa3af52010-12-14 10:36:11 -0800464 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700465 public void showVoiceTitleBar(String title, List<String> vsresults) {
Michael Kolb3a2a1642011-02-15 10:52:07 -0800466 mTitleBar.setInVoiceMode(true, vsresults);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800467 mTitleBar.setDisplayTitle(title);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800468 }
469
470 @Override
471 public void revertVoiceTitleBar(Tab tab) {
472 mTitleBar.setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800473 String url = tab.getUrl();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800474 mTitleBar.setDisplayTitle(url);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800475 }
476
John Reckd73c5a22010-12-22 10:22:50 -0800477 @Override
478 public void showCustomView(View view, CustomViewCallback callback) {
479 super.showCustomView(view, callback);
480 mActivity.getActionBar().hide();
481 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800482
John Reckd73c5a22010-12-22 10:22:50 -0800483 @Override
484 public void onHideCustomView() {
485 super.onHideCustomView();
486 if (mUseQuickControls) {
487 checkTabCount();
488 } else {
489 mActivity.getActionBar().show();
490 }
491 }
Michael Kolba4183062011-01-16 10:43:21 -0800492
493 @Override
494 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800495 if (mActiveTab != null) {
496 WebView web = mActiveTab.getWebView();
497 if (event.getAction() == KeyEvent.ACTION_DOWN) {
498 switch (code) {
499 case KeyEvent.KEYCODE_TAB:
500 case KeyEvent.KEYCODE_DPAD_UP:
501 case KeyEvent.KEYCODE_DPAD_LEFT:
502 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
503 editUrl(false);
504 return true;
505 }
506 }
507 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
508 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
509 editUrl(true);
510 return mContentView.dispatchKeyEvent(event);
511 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800512 }
Michael Kolba4183062011-01-16 10:43:21 -0800513 }
514 return false;
515 }
516
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800517 private boolean isTypingKey(KeyEvent evt) {
518 return evt.getUnicodeChar() > 0;
519 }
520
521 TabBar getTabBar() {
522 return mTabBar;
523 }
524
Narayan Kamath5119edd2011-02-23 15:49:17 +0000525 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800526 public boolean onPrepareOptionsMenu(Menu menu) {
527 if (mUseQuickControls) {
528 mPieControl.onMenuOpened(menu);
529 return false;
530 } else {
531 return true;
532 }
533 }
534
Michael Kolb66706532010-12-12 19:50:22 -0800535}