blob: 92fdc9787d0e32688028df554a02bff9f69b2bed [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 Kolb24915222011-02-24 11:38:49 -080026import android.content.pm.PackageManager;
Michael Kolbeb95db42011-03-03 10:38:40 -080027import android.graphics.Bitmap;
Michael Kolbac35bdc2011-01-17 17:06:04 -080028import android.os.Bundle;
Michael Kolbba238702011-03-08 10:40:50 -080029import android.os.Handler;
Michael Kolb376b5412010-12-15 11:52:57 -080030import android.util.Log;
Michael Kolb66706532010-12-12 19:50:22 -080031import android.view.ActionMode;
Michael Kolb376b5412010-12-15 11:52:57 -080032import android.view.Gravity;
Michael Kolba4183062011-01-16 10:43:21 -080033import android.view.KeyEvent;
Michael Kolb1acef692011-03-08 14:12:06 -080034import android.view.Menu;
John Reckd73c5a22010-12-22 10:22:50 -080035import android.view.View;
36import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb66706532010-12-12 19:50:22 -080037import android.webkit.WebView;
Michael Kolb2a56eca2011-02-25 09:45:06 -080038import android.widget.FrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080039
40import java.util.List;
41
42/**
43 * Ui for xlarge screen sizes
44 */
45public class XLargeUi extends BaseUi implements ScrollListener {
46
47 private static final String LOGTAG = "XLargeUi";
48
Michael Kolb376b5412010-12-15 11:52:57 -080049 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080050 private TabBar mTabBar;
51
52 private TitleBarXLarge mTitleBar;
John Recke5c21d92011-03-11 15:09:46 -080053 private Animator mTitleBarAnimator;
John Reck6e8d2e92011-03-14 11:29:56 -070054 private boolean mSkipTitleBarAnimations;
Michael Kolb66706532010-12-12 19:50:22 -080055
Michael Kolb376b5412010-12-15 11:52:57 -080056 private boolean mUseQuickControls;
57 private PieControl mPieControl;
Michael Kolbba238702011-03-08 10:40:50 -080058 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080059
Michael Kolb66706532010-12-12 19:50:22 -080060 /**
61 * @param browser
62 * @param controller
63 */
64 public XLargeUi(Activity browser, UiController controller) {
65 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080066 mHandler = new Handler();
Michael Kolb66706532010-12-12 19:50:22 -080067 mTitleBar = new TitleBarXLarge(mActivity, mUiController, this);
68 mTitleBar.setProgress(100);
Michael Kolb66706532010-12-12 19:50:22 -080069 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080070 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080071 setupActionBar();
72 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
73 }
74
75 private void setupActionBar() {
76 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080077 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
78 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080079 }
80
81 @Override
Michael Kolbac35bdc2011-01-17 17:06:04 -080082 public void showComboView(boolean startWithHistory, Bundle extras) {
83 super.showComboView(startWithHistory, extras);
84 if (mUseQuickControls) {
85 mActionBar.show();
86 }
87 }
88
89 @Override
John Reckb3417f02011-01-14 11:01:05 -080090 public void hideComboView() {
Michael Kolbba238702011-03-08 10:40:50 -080091 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 Kolb376b5412010-12-15 11:52:57 -080097 }
98
99 private void setUseQuickControls(boolean useQuickControls) {
100 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -0800101 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800102 if (useQuickControls) {
103 checkTabCount();
104 mPieControl = new PieControl(mActivity, mUiController, this);
105 mPieControl.attachToContainer(mContentView);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800106 Tab tab = getActiveTab();
107 if ((tab != null) && (tab.getWebView() != null)) {
108 tab.getWebView().setEmbeddedTitleBar(null);
Michael Kolb376b5412010-12-15 11:52:57 -0800109 }
110 } else {
111 mActivity.getActionBar().show();
112 if (mPieControl != null) {
113 mPieControl.removeFromContainer(mContentView);
114 }
Michael Kolb376b5412010-12-15 11:52:57 -0800115 WebView web = mTabControl.getCurrentWebView();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800116 if (web != null) {
Michael Kolb376b5412010-12-15 11:52:57 -0800117 web.setEmbeddedTitleBar(mTitleBar);
118 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700119 setTitleGravity(Gravity.NO_GRAVITY);
Michael Kolb376b5412010-12-15 11:52:57 -0800120 }
121 mTabBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800122 }
123
124 private void checkTabCount() {
125 if (mUseQuickControls) {
Michael Kolbeb95db42011-03-03 10:38:40 -0800126 mHandler.post(new Runnable() {
127 public void run() {
128 mActionBar.hide();
129 }
130 });
Michael Kolb376b5412010-12-15 11:52:57 -0800131 }
Michael Kolb66706532010-12-12 19:50:22 -0800132 }
133
134 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000135 public void onResume() {
136 super.onResume();
137 if (!BrowserSettings.getInstance().useInstant()) {
138 mTitleBar.clearCompletions();
139 }
140 }
141
142 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800143 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800144 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800145 }
146
147 // webview factory
148
149 @Override
150 public WebView createWebView(boolean privateBrowsing) {
151 // Create a new WebView
John Reckb9a051b2011-03-18 11:55:48 -0700152 BrowserWebView w = (BrowserWebView) super.createWebView(privateBrowsing);
Michael Kolb66706532010-12-12 19:50:22 -0800153 w.setScrollListener(this);
Michael Kolb66706532010-12-12 19:50:22 -0800154 return w;
155 }
156
157 @Override
158 public WebView createSubWebView(boolean privateBrowsing) {
John Reckb9a051b2011-03-18 11:55:48 -0700159 return super.createWebView(privateBrowsing);
Michael Kolb66706532010-12-12 19:50:22 -0800160 }
161
162 @Override
Michael Kolb5ee018e2011-02-18 15:47:21 -0800163 public void onScroll(int visibleTitleHeight, boolean userInitiated) {
164 mTabBar.onScroll(visibleTitleHeight, userInitiated);
Michael Kolb66706532010-12-12 19:50:22 -0800165 }
166
167 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700168 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Michael Kolb66706532010-12-12 19:50:22 -0800169 if (web != null) {
170 web.stopScroll();
171 }
172 }
173
174 // WebView callbacks
175
176 @Override
John Reck30c714c2010-12-16 17:30:34 -0800177 public void onProgressChanged(Tab tab) {
178 int progress = tab.getLoadProgress();
Michael Kolb66706532010-12-12 19:50:22 -0800179 mTabBar.onProgress(tab, progress);
180 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800181 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800182 if (progress == 100) {
Michael Kolb8a4c3822011-03-15 14:52:05 -0700183 if (!mTitleBar.isEditingUrl() && !mTitleBar.inAutoLogin()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800184 hideTitleBar();
Michael Kolbbd018d42010-12-15 15:43:39 -0800185 if (mUseQuickControls) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800186 mTitleBar.setShowProgressOnly(false);
Michael Kolbbd018d42010-12-15 15:43:39 -0800187 }
Michael Kolb376b5412010-12-15 11:52:57 -0800188 }
Michael Kolb66706532010-12-12 19:50:22 -0800189 } else {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800190 if (!isTitleBarShowing()) {
191 if (mUseQuickControls && !mTitleBar.isEditingUrl()) {
192 mTitleBar.setShowProgressOnly(true);
193 setTitleGravity(Gravity.TOP);
Michael Kolb376b5412010-12-15 11:52:57 -0800194 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800195 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800196 }
Michael Kolb66706532010-12-12 19:50:22 -0800197 }
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 Kolb8814d732011-01-26 11:22:30 -0800209 }
210
211 protected void onAddTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800212 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800213 }
214
215 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800216 public void setActiveTab(final Tab tab) {
John Reck6e8d2e92011-03-14 11:29:56 -0700217 cancelTitleBarAnimation(true);
218 mSkipTitleBarAnimations = true;
Michael Kolbeb95db42011-03-03 10:38:40 -0800219 if (mUseQuickControls) {
220 if (mActiveTab != null) {
221 captureTab(mActiveTab);
222 }
223 }
Michael Kolbf2628922011-03-09 17:15:28 -0800224 super.setActiveTab(tab, true);
225 setActiveTab(tab, true);
John Reck6e8d2e92011-03-14 11:29:56 -0700226 mSkipTitleBarAnimations = false;
Michael Kolb377ea312011-02-17 14:36:56 -0800227 }
228
229 @Override
230 void setActiveTab(Tab tab, boolean needsAttaching) {
John Reckb9a051b2011-03-18 11:55:48 -0700231 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800232 // 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 Kolb377ea312011-02-17 14:36:56 -0800244 // check if title bar is already attached by animation
245 if (mTitleBar.getParent() == null) {
246 view.setEmbeddedTitleBar(mTitleBar);
247 }
Michael Kolb376b5412010-12-15 11:52:57 -0800248 view.setScrollListener(this);
249 }
Michael Kolb66706532010-12-12 19:50:22 -0800250 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800251 if (tab.isInVoiceSearchMode()) {
252 showVoiceTitleBar(tab.getVoiceDisplayTitle());
253 } else {
254 revertVoiceTitleBar(tab);
255 }
Michael Kolb376b5412010-12-15 11:52:57 -0800256 updateLockIconToLatest(tab);
257 tab.getTopWindow().requestFocus();
Michael Kolb66706532010-12-12 19:50:22 -0800258 }
259
Michael Kolbeb95db42011-03-03 10:38:40 -0800260 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 Kolb66706532010-12-12 19:50:22 -0800269 @Override
270 public void updateTabs(List<Tab> tabs) {
271 mTabBar.updateTabs(tabs);
Michael Kolb376b5412010-12-15 11:52:57 -0800272 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800273 }
274
275 @Override
276 public void removeTab(Tab tab) {
John Reck6e8d2e92011-03-14 11:29:56 -0700277 cancelTitleBarAnimation(true);
278 mSkipTitleBarAnimations = true;
Michael Kolb66706532010-12-12 19:50:22 -0800279 super.removeTab(tab);
280 mTabBar.onRemoveTab(tab);
John Reck6e8d2e92011-03-14 11:29:56 -0700281 mSkipTitleBarAnimations = false;
Michael Kolb8814d732011-01-26 11:22:30 -0800282 }
283
284 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800285 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800286 }
287
Michael Kolb376b5412010-12-15 11:52:57 -0800288 int getContentWidth() {
289 if (mContentView != null) {
290 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800291 }
292 return 0;
293 }
294
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800295 @Override
296 public void editUrl(boolean clearInput) {
Michael Kolbd72ea3b2011-01-09 15:56:37 -0800297 if (mUiController.isInCustomActionMode()) {
298 mUiController.endActionMode();
299 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800300 showTitleBar();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800301 mTitleBar.startEditingUrl(clearInput);
Michael Kolb66706532010-12-12 19:50:22 -0800302 }
303
Michael Kolb7cdc4902011-02-03 17:54:40 -0800304 void showTitleBarAndEdit() {
305 mTitleBar.setShowProgressOnly(false);
306 showTitleBar();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800307 mTitleBar.startEditingUrl(false);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800308 }
309
310 void stopEditingUrl() {
311 mTitleBar.stopEditingUrl();
312 }
313
314 @Override
315 protected void showTitleBar() {
316 if (canShowTitleBar()) {
317 if (mUseQuickControls) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800318 mContentView.addView(mTitleBar);
319 } else {
John Reck6e8d2e92011-03-14 11:29:56 -0700320 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 Recke5c21d92011-03-11 15:09:46 -0800331 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800332 setTitleGravity(Gravity.TOP);
333 }
334 super.showTitleBar();
335 mTabBar.onShowTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800336 }
Michael Kolb376b5412010-12-15 11:52:57 -0800337 }
338
Michael Kolb66706532010-12-12 19:50:22 -0800339 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800340 protected void hideTitleBar() {
341 if (isTitleBarShowing()) {
Michael Kolb66706532010-12-12 19:50:22 -0800342 mTabBar.onHideTitleBar();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800343 if (mUseQuickControls) {
344 mContentView.removeView(mTitleBar);
Michael Kolb2a56eca2011-02-25 09:45:06 -0800345 } else {
John Reck6e8d2e92011-03-14 11:29:56 -0700346 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 Recke5c21d92011-03-11 15:09:46 -0800356 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800357 }
358 super.hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800359 }
360 }
361
John Reck6e8d2e92011-03-14 11:29:56 -0700362 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 Recke5c21d92011-03-11 15:09:46 -0800372 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 Recke5c21d92011-03-11 15:09:46 -0800393 }
John Reck6e8d2e92011-03-14 11:29:56 -0700394 setTitleGravity(Gravity.NO_GRAVITY);
John Recke5c21d92011-03-11 15:09:46 -0800395 }
396
397 @Override
398 public void onAnimationCancel(Animator animation) {
399 mWasCanceled = true;
400 }
401 };
402
Michael Kolb5ee018e2011-02-18 15:47:21 -0800403 public boolean isEditingUrl() {
404 return mTitleBar.isEditingUrl();
405 }
406
Michael Kolb66706532010-12-12 19:50:22 -0800407 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800408 protected TitleBarBase getTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800409 return mTitleBar;
410 }
411
Michael Kolb2a56eca2011-02-25 09:45:06 -0800412 @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 Kolb66706532010-12-12 19:50:22 -0800424 // action mode callbacks
425
426 @Override
427 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800428 if (!mTitleBar.isEditingUrl()) {
Michael Kolb66706532010-12-12 19:50:22 -0800429 // hide the fake title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800430 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800431 }
432 }
433
434 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800435 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 Kolb1544f3b2011-03-10 09:06:10 -0800440 if (mUseQuickControls) {
441 mTitleBar.setShowProgressOnly(true);
Michael Kolb376b5412010-12-15 11:52:57 -0800442 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800443 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800444 }
445 }
446
447 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800448 protected void updateNavigationState(Tab tab) {
449 mTitleBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800450 }
451
452 @Override
Patrick Scott92066772011-03-10 08:46:27 -0500453 protected void updateAutoLogin(Tab tab, boolean animate) {
454 mTitleBar.updateAutoLogin(tab, animate);
455 }
456
Michael Kolb2ba24b92011-03-17 10:59:10 -0700457 protected void refreshWebView() {
458 Tab tab = getActiveTab();
459 if ((tab != null) && (tab.getWebView() != null)) {
460 tab.getWebView().invalidate();
461 }
462 }
463
Patrick Scott92066772011-03-10 08:46:27 -0500464 @Override
John Reck30c714c2010-12-16 17:30:34 -0800465 public void setUrlTitle(Tab tab) {
466 super.setUrlTitle(tab);
467 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800468 }
469
470 // Set the favicon in the title bar.
471 @Override
John Reck30c714c2010-12-16 17:30:34 -0800472 public void setFavicon(Tab tab) {
473 super.setFavicon(tab);
474 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800475 }
476
Michael Kolbcfa3af52010-12-14 10:36:11 -0800477 @Override
478 public void showVoiceTitleBar(String title) {
479 List<String> vsresults = null;
480 if (getActiveTab() != null) {
481 vsresults = getActiveTab().getVoiceSearchResults();
482 }
Michael Kolb3a2a1642011-02-15 10:52:07 -0800483 mTitleBar.setInVoiceMode(true, vsresults);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800484 mTitleBar.setDisplayTitle(title);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800485 }
486
487 @Override
488 public void revertVoiceTitleBar(Tab tab) {
489 mTitleBar.setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800490 String url = tab.getUrl();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800491 mTitleBar.setDisplayTitle(url);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800492 }
493
John Reckd73c5a22010-12-22 10:22:50 -0800494 @Override
495 public void showCustomView(View view, CustomViewCallback callback) {
496 super.showCustomView(view, callback);
497 mActivity.getActionBar().hide();
498 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800499
John Reckd73c5a22010-12-22 10:22:50 -0800500 @Override
501 public void onHideCustomView() {
502 super.onHideCustomView();
503 if (mUseQuickControls) {
504 checkTabCount();
505 } else {
506 mActivity.getActionBar().show();
507 }
508 }
Michael Kolba4183062011-01-16 10:43:21 -0800509
510 @Override
511 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800512 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 Kolbdc2ee1b2011-02-14 14:34:40 -0800529 }
Michael Kolba4183062011-01-16 10:43:21 -0800530 }
531 return false;
532 }
533
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800534 private boolean isTypingKey(KeyEvent evt) {
535 return evt.getUnicodeChar() > 0;
536 }
537
538 TabBar getTabBar() {
539 return mTabBar;
540 }
541
Narayan Kamath5119edd2011-02-23 15:49:17 +0000542 @Override
543 public void registerDropdownChangeListener(DropdownChangeListener d) {
544 mTitleBar.registerDropdownChangeListener(d);
545 }
Michael Kolb0860d992011-03-07 15:26:33 -0800546
Michael Kolb1acef692011-03-08 14:12:06 -0800547 @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 Kolb66706532010-12-12 19:50:22 -0800557}