blob: 8455e743db33f355431dfbf058805d6a45da6bd1 [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
Michael Kolb66706532010-12-12 19:50:22 -080019import android.app.ActionBar;
20import android.app.Activity;
Michael Kolbac35bdc2011-01-17 17:06:04 -080021import android.os.Bundle;
Michael Kolbba238702011-03-08 10:40:50 -080022import android.os.Handler;
Michael Kolb376b5412010-12-15 11:52:57 -080023import android.util.Log;
Michael Kolb66706532010-12-12 19:50:22 -080024import android.view.ActionMode;
Michael Kolb376b5412010-12-15 11:52:57 -080025import android.view.Gravity;
Michael Kolba4183062011-01-16 10:43:21 -080026import android.view.KeyEvent;
John Reckd73c5a22010-12-22 10:22:50 -080027import android.view.View;
28import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb66706532010-12-12 19:50:22 -080029import android.webkit.WebView;
30
John Reckbf2ec202011-06-29 17:47:38 -070031import com.android.browser.BrowserWebView.ScrollListener;
32
Michael Kolb66706532010-12-12 19:50:22 -080033import java.util.List;
34
35/**
36 * Ui for xlarge screen sizes
37 */
John Reckbf2ec202011-06-29 17:47:38 -070038public class XLargeUi extends BaseUi implements ScrollListener {
Michael Kolb66706532010-12-12 19:50:22 -080039
40 private static final String LOGTAG = "XLargeUi";
41
Michael Kolb376b5412010-12-15 11:52:57 -080042 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080043 private TabBar mTabBar;
44
45 private TitleBarXLarge mTitleBar;
Michael Kolb66706532010-12-12 19:50:22 -080046
Michael Kolb376b5412010-12-15 11:52:57 -080047 private PieControl mPieControl;
Michael Kolbba238702011-03-08 10:40:50 -080048 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080049
Michael Kolb66706532010-12-12 19:50:22 -080050 /**
51 * @param browser
52 * @param controller
53 */
54 public XLargeUi(Activity browser, UiController controller) {
55 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080056 mHandler = new Handler();
Michael Kolb46f987e2011-04-05 10:39:10 -070057 mTitleBar = new TitleBarXLarge(mActivity, mUiController, this,
58 mContentView);
Michael Kolb66706532010-12-12 19:50:22 -080059 mTitleBar.setProgress(100);
Michael Kolb66706532010-12-12 19:50:22 -080060 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080061 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080062 setupActionBar();
63 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
64 }
65
66 private void setupActionBar() {
67 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080068 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
69 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080070 }
71
72 @Override
Michael Kolb14612442011-06-24 13:06:29 -070073 public void onSetWebView(Tab tab, WebView v) {
74 super.onSetWebView(tab, v);
75 if (v != null) {
76 ((BrowserWebView) v).setScrollListener(this);
77 }
78 }
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 Kolb46f987e2011-04-05 10:39:10 -0700105 WebView web = getWebView();
106 if (web != null) {
107 web.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 Kolb46f987e2011-04-05 10:39:10 -0700114 WebView web = getWebView();
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();
John Reck35e9dd62011-04-25 09:01:54 -0700136 if (!BrowserSettings.getInstance().useInstantSearch()) {
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000137 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
Michael Kolb66706532010-12-12 19:50:22 -0800146 @Override
Michael Kolb5ee018e2011-02-18 15:47:21 -0800147 public void onScroll(int visibleTitleHeight, boolean userInitiated) {
148 mTabBar.onScroll(visibleTitleHeight, userInitiated);
Michael Kolb66706532010-12-12 19:50:22 -0800149 }
150
151 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700152 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Michael Kolb66706532010-12-12 19:50:22 -0800153 if (web != null) {
154 web.stopScroll();
155 }
156 }
157
158 // WebView callbacks
159
160 @Override
John Reck30c714c2010-12-16 17:30:34 -0800161 public void onProgressChanged(Tab tab) {
162 int progress = tab.getLoadProgress();
Michael Kolb66706532010-12-12 19:50:22 -0800163 mTabBar.onProgress(tab, progress);
164 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800165 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800166 }
167 }
168
169 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800170 public void addTab(Tab tab) {
171 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800172 }
173
174 protected void onAddTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800175 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800176 }
177
178 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800179 public void setActiveTab(final Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700180 mTitleBar.cancelTitleBarAnimation(true);
181 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolbeb95db42011-03-03 10:38:40 -0800182 if (mUseQuickControls) {
183 if (mActiveTab != null) {
184 captureTab(mActiveTab);
185 }
186 }
John Reck5d43ce82011-06-21 17:16:51 -0700187 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700188 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800189 // TabControl.setCurrentTab has been called before this,
190 // so the tab is guaranteed to have a webview
191 if (view == null) {
192 Log.e(LOGTAG, "active tab with no webview detected");
193 return;
194 }
195 // Request focus on the top window.
196 if (mUseQuickControls) {
197 mPieControl.forceToTop(mContentView);
198 view.setScrollListener(null);
199 mTabBar.showTitleBarIndicator(false);
200 } else {
Michael Kolb377ea312011-02-17 14:36:56 -0800201 // check if title bar is already attached by animation
John Reck541f55a2011-06-07 16:34:43 -0700202 if (mTitleBar.getParent() == null && !tab.isSnapshot()) {
Michael Kolb377ea312011-02-17 14:36:56 -0800203 view.setEmbeddedTitleBar(mTitleBar);
204 }
Michael Kolb376b5412010-12-15 11:52:57 -0800205 view.setScrollListener(this);
206 }
Michael Kolb66706532010-12-12 19:50:22 -0800207 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800208 if (tab.isInVoiceSearchMode()) {
Michael Kolb11d19782011-03-20 10:17:40 -0700209 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
Michael Kolb376b5412010-12-15 11:52:57 -0800210 } else {
211 revertVoiceTitleBar(tab);
212 }
Michael Kolb376b5412010-12-15 11:52:57 -0800213 updateLockIconToLatest(tab);
214 tab.getTopWindow().requestFocus();
John Reck5d43ce82011-06-21 17:16:51 -0700215 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800216 }
217
218 @Override
219 public void updateTabs(List<Tab> tabs) {
220 mTabBar.updateTabs(tabs);
Michael Kolb376b5412010-12-15 11:52:57 -0800221 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800222 }
223
224 @Override
225 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700226 mTitleBar.cancelTitleBarAnimation(true);
227 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800228 super.removeTab(tab);
229 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700230 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800231 }
232
233 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800234 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800235 }
236
Michael Kolb376b5412010-12-15 11:52:57 -0800237 int getContentWidth() {
238 if (mContentView != null) {
239 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800240 }
241 return 0;
242 }
243
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800244 @Override
245 public void editUrl(boolean clearInput) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700246 if (mUseQuickControls) {
247 getTitleBar().setShowProgressOnly(false);
Michael Kolbd72ea3b2011-01-09 15:56:37 -0800248 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700249 super.editUrl(clearInput);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800250 }
251
252 void stopEditingUrl() {
253 mTitleBar.stopEditingUrl();
254 }
255
256 @Override
257 protected void showTitleBar() {
258 if (canShowTitleBar()) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700259 mTitleBar.show();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800260 mTabBar.onShowTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800261 }
Michael Kolb376b5412010-12-15 11:52:57 -0800262 }
263
Michael Kolb66706532010-12-12 19:50:22 -0800264 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800265 protected void hideTitleBar() {
266 if (isTitleBarShowing()) {
Michael Kolb66706532010-12-12 19:50:22 -0800267 mTabBar.onHideTitleBar();
Michael Kolb46f987e2011-04-05 10:39:10 -0700268 mTitleBar.hide();
Michael Kolb66706532010-12-12 19:50:22 -0800269 }
270 }
271
272 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800273 protected TitleBarBase getTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800274 return mTitleBar;
275 }
276
Michael Kolb2a56eca2011-02-25 09:45:06 -0800277 @Override
278 protected void setTitleGravity(int gravity) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700279 if (!mUseQuickControls) {
Michael Kolb2a56eca2011-02-25 09:45:06 -0800280 super.setTitleGravity(gravity);
281 }
282 }
283
Michael Kolb66706532010-12-12 19:50:22 -0800284 // action mode callbacks
285
286 @Override
287 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800288 if (!mTitleBar.isEditingUrl()) {
Michael Kolb66706532010-12-12 19:50:22 -0800289 // hide the fake title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800290 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800291 }
292 }
293
294 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800295 public void onActionModeFinished(boolean inLoad) {
296 checkTabCount();
297 if (inLoad) {
298 // the titlebar was removed when the CAB was shown
299 // if the page is loading, show it again
Michael Kolb1544f3b2011-03-10 09:06:10 -0800300 if (mUseQuickControls) {
301 mTitleBar.setShowProgressOnly(true);
Michael Kolb376b5412010-12-15 11:52:57 -0800302 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800303 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800304 }
305 }
306
307 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800308 protected void updateNavigationState(Tab tab) {
309 mTitleBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800310 }
311
312 @Override
John Reck30c714c2010-12-16 17:30:34 -0800313 public void setUrlTitle(Tab tab) {
314 super.setUrlTitle(tab);
315 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800316 }
317
318 // Set the favicon in the title bar.
319 @Override
John Reck30c714c2010-12-16 17:30:34 -0800320 public void setFavicon(Tab tab) {
321 super.setFavicon(tab);
322 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800323 }
324
Michael Kolbcfa3af52010-12-14 10:36:11 -0800325 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700326 public void showVoiceTitleBar(String title, List<String> vsresults) {
Michael Kolb3a2a1642011-02-15 10:52:07 -0800327 mTitleBar.setInVoiceMode(true, vsresults);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800328 mTitleBar.setDisplayTitle(title);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800329 }
330
331 @Override
332 public void revertVoiceTitleBar(Tab tab) {
333 mTitleBar.setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800334 String url = tab.getUrl();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800335 mTitleBar.setDisplayTitle(url);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800336 }
337
John Reckd73c5a22010-12-22 10:22:50 -0800338 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400339 public void showCustomView(View view, int requestedOrientation,
340 CustomViewCallback callback) {
341 super.showCustomView(view, requestedOrientation, callback);
John Reckd73c5a22010-12-22 10:22:50 -0800342 mActivity.getActionBar().hide();
343 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800344
John Reckd73c5a22010-12-22 10:22:50 -0800345 @Override
346 public void onHideCustomView() {
347 super.onHideCustomView();
348 if (mUseQuickControls) {
349 checkTabCount();
350 } else {
351 mActivity.getActionBar().show();
352 }
353 }
Michael Kolba4183062011-01-16 10:43:21 -0800354
355 @Override
356 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800357 if (mActiveTab != null) {
358 WebView web = mActiveTab.getWebView();
359 if (event.getAction() == KeyEvent.ACTION_DOWN) {
360 switch (code) {
361 case KeyEvent.KEYCODE_TAB:
362 case KeyEvent.KEYCODE_DPAD_UP:
363 case KeyEvent.KEYCODE_DPAD_LEFT:
364 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
365 editUrl(false);
366 return true;
367 }
368 }
369 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
370 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
371 editUrl(true);
372 return mContentView.dispatchKeyEvent(event);
373 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800374 }
Michael Kolba4183062011-01-16 10:43:21 -0800375 }
376 return false;
377 }
378
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800379 private boolean isTypingKey(KeyEvent evt) {
380 return evt.getUnicodeChar() > 0;
381 }
382
383 TabBar getTabBar() {
384 return mTabBar;
385 }
386
Michael Kolb66706532010-12-12 19:50:22 -0800387}