blob: 81a6edb75758ce612baed7215d8fde57e878874f [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
John Reck2bc80422011-06-30 15:11:49 -070080 public void showComboView(ComboViews startWith, Bundle extras) {
81 super.showComboView(startWith, extras);
Michael Kolbac35bdc2011-01-17 17:06:04 -080082 if (mUseQuickControls) {
83 mActionBar.show();
84 }
85 }
86
87 @Override
John Reckb3417f02011-01-14 11:01:05 -080088 public void hideComboView() {
Michael Kolbba238702011-03-08 10:40:50 -080089 if (isComboViewShowing()) {
90 super.hideComboView();
91 // ComboView changes the action bar, set it back up to what we want
92 setupActionBar();
93 checkTabCount();
94 }
Michael Kolb376b5412010-12-15 11:52:57 -080095 }
96
97 private void setUseQuickControls(boolean useQuickControls) {
98 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -080099 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800100 if (useQuickControls) {
101 checkTabCount();
102 mPieControl = new PieControl(mActivity, mUiController, this);
103 mPieControl.attachToContainer(mContentView);
Michael Kolb46f987e2011-04-05 10:39:10 -0700104 WebView web = getWebView();
105 if (web != null) {
106 web.setEmbeddedTitleBar(null);
Michael Kolb376b5412010-12-15 11:52:57 -0800107 }
108 } else {
109 mActivity.getActionBar().show();
110 if (mPieControl != null) {
111 mPieControl.removeFromContainer(mContentView);
112 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700113 WebView web = getWebView();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800114 if (web != null) {
Michael Kolb376b5412010-12-15 11:52:57 -0800115 web.setEmbeddedTitleBar(mTitleBar);
116 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700117 setTitleGravity(Gravity.NO_GRAVITY);
Michael Kolb376b5412010-12-15 11:52:57 -0800118 }
119 mTabBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800120 }
121
122 private void checkTabCount() {
123 if (mUseQuickControls) {
Michael Kolbeb95db42011-03-03 10:38:40 -0800124 mHandler.post(new Runnable() {
125 public void run() {
126 mActionBar.hide();
127 }
128 });
Michael Kolb376b5412010-12-15 11:52:57 -0800129 }
Michael Kolb66706532010-12-12 19:50:22 -0800130 }
131
132 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000133 public void onResume() {
134 super.onResume();
John Reck35e9dd62011-04-25 09:01:54 -0700135 if (!BrowserSettings.getInstance().useInstantSearch()) {
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000136 mTitleBar.clearCompletions();
137 }
138 }
139
140 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800141 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800142 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800143 }
144
Michael Kolb66706532010-12-12 19:50:22 -0800145 @Override
Michael Kolb5ee018e2011-02-18 15:47:21 -0800146 public void onScroll(int visibleTitleHeight, boolean userInitiated) {
147 mTabBar.onScroll(visibleTitleHeight, userInitiated);
Michael Kolb66706532010-12-12 19:50:22 -0800148 }
149
150 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700151 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Michael Kolb66706532010-12-12 19:50:22 -0800152 if (web != null) {
153 web.stopScroll();
154 }
155 }
156
157 // WebView callbacks
158
159 @Override
John Reck30c714c2010-12-16 17:30:34 -0800160 public void onProgressChanged(Tab tab) {
161 int progress = tab.getLoadProgress();
Michael Kolb66706532010-12-12 19:50:22 -0800162 mTabBar.onProgress(tab, progress);
163 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800164 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800165 }
166 }
167
168 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800169 public void addTab(Tab tab) {
170 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800171 }
172
173 protected void onAddTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800174 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800175 }
176
177 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800178 public void setActiveTab(final Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700179 mTitleBar.cancelTitleBarAnimation(true);
180 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolbeb95db42011-03-03 10:38:40 -0800181 if (mUseQuickControls) {
182 if (mActiveTab != null) {
183 captureTab(mActiveTab);
184 }
185 }
John Reck5d43ce82011-06-21 17:16:51 -0700186 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700187 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800188 // TabControl.setCurrentTab has been called before this,
189 // so the tab is guaranteed to have a webview
190 if (view == null) {
191 Log.e(LOGTAG, "active tab with no webview detected");
192 return;
193 }
194 // Request focus on the top window.
195 if (mUseQuickControls) {
196 mPieControl.forceToTop(mContentView);
197 view.setScrollListener(null);
198 mTabBar.showTitleBarIndicator(false);
199 } else {
Michael Kolb377ea312011-02-17 14:36:56 -0800200 // check if title bar is already attached by animation
John Reck541f55a2011-06-07 16:34:43 -0700201 if (mTitleBar.getParent() == null && !tab.isSnapshot()) {
Michael Kolb377ea312011-02-17 14:36:56 -0800202 view.setEmbeddedTitleBar(mTitleBar);
203 }
Michael Kolb376b5412010-12-15 11:52:57 -0800204 view.setScrollListener(this);
205 }
Michael Kolb66706532010-12-12 19:50:22 -0800206 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800207 if (tab.isInVoiceSearchMode()) {
Michael Kolb11d19782011-03-20 10:17:40 -0700208 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
Michael Kolb376b5412010-12-15 11:52:57 -0800209 } else {
210 revertVoiceTitleBar(tab);
211 }
Michael Kolb376b5412010-12-15 11:52:57 -0800212 updateLockIconToLatest(tab);
213 tab.getTopWindow().requestFocus();
John Reck5d43ce82011-06-21 17:16:51 -0700214 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800215 }
216
217 @Override
218 public void updateTabs(List<Tab> tabs) {
219 mTabBar.updateTabs(tabs);
Michael Kolb376b5412010-12-15 11:52:57 -0800220 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800221 }
222
223 @Override
224 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700225 mTitleBar.cancelTitleBarAnimation(true);
226 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800227 super.removeTab(tab);
228 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700229 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800230 }
231
232 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800233 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800234 }
235
Michael Kolb376b5412010-12-15 11:52:57 -0800236 int getContentWidth() {
237 if (mContentView != null) {
238 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800239 }
240 return 0;
241 }
242
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800243 @Override
244 public void editUrl(boolean clearInput) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700245 if (mUseQuickControls) {
246 getTitleBar().setShowProgressOnly(false);
Michael Kolbd72ea3b2011-01-09 15:56:37 -0800247 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700248 super.editUrl(clearInput);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800249 }
250
251 void stopEditingUrl() {
252 mTitleBar.stopEditingUrl();
253 }
254
255 @Override
256 protected void showTitleBar() {
257 if (canShowTitleBar()) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700258 mTitleBar.show();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800259 mTabBar.onShowTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800260 }
Michael Kolb376b5412010-12-15 11:52:57 -0800261 }
262
Michael Kolb66706532010-12-12 19:50:22 -0800263 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800264 protected void hideTitleBar() {
265 if (isTitleBarShowing()) {
Michael Kolb66706532010-12-12 19:50:22 -0800266 mTabBar.onHideTitleBar();
Michael Kolb46f987e2011-04-05 10:39:10 -0700267 mTitleBar.hide();
Michael Kolb66706532010-12-12 19:50:22 -0800268 }
269 }
270
271 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800272 protected TitleBarBase getTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800273 return mTitleBar;
274 }
275
Michael Kolb2a56eca2011-02-25 09:45:06 -0800276 @Override
277 protected void setTitleGravity(int gravity) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700278 if (!mUseQuickControls) {
Michael Kolb2a56eca2011-02-25 09:45:06 -0800279 super.setTitleGravity(gravity);
280 }
281 }
282
Michael Kolb66706532010-12-12 19:50:22 -0800283 // action mode callbacks
284
285 @Override
286 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800287 if (!mTitleBar.isEditingUrl()) {
Michael Kolb66706532010-12-12 19:50:22 -0800288 // hide the fake title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800289 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800290 }
291 }
292
293 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800294 public void onActionModeFinished(boolean inLoad) {
295 checkTabCount();
296 if (inLoad) {
297 // the titlebar was removed when the CAB was shown
298 // if the page is loading, show it again
Michael Kolb1544f3b2011-03-10 09:06:10 -0800299 if (mUseQuickControls) {
300 mTitleBar.setShowProgressOnly(true);
Michael Kolb376b5412010-12-15 11:52:57 -0800301 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800302 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800303 }
304 }
305
306 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800307 protected void updateNavigationState(Tab tab) {
308 mTitleBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800309 }
310
311 @Override
John Reck30c714c2010-12-16 17:30:34 -0800312 public void setUrlTitle(Tab tab) {
313 super.setUrlTitle(tab);
314 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800315 }
316
317 // Set the favicon in the title bar.
318 @Override
John Reck30c714c2010-12-16 17:30:34 -0800319 public void setFavicon(Tab tab) {
320 super.setFavicon(tab);
321 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800322 }
323
Michael Kolbcfa3af52010-12-14 10:36:11 -0800324 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700325 public void showVoiceTitleBar(String title, List<String> vsresults) {
Michael Kolb3a2a1642011-02-15 10:52:07 -0800326 mTitleBar.setInVoiceMode(true, vsresults);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800327 mTitleBar.setDisplayTitle(title);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800328 }
329
330 @Override
331 public void revertVoiceTitleBar(Tab tab) {
332 mTitleBar.setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800333 String url = tab.getUrl();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800334 mTitleBar.setDisplayTitle(url);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800335 }
336
John Reckd73c5a22010-12-22 10:22:50 -0800337 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400338 public void showCustomView(View view, int requestedOrientation,
339 CustomViewCallback callback) {
340 super.showCustomView(view, requestedOrientation, callback);
John Reckd73c5a22010-12-22 10:22:50 -0800341 mActivity.getActionBar().hide();
342 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800343
John Reckd73c5a22010-12-22 10:22:50 -0800344 @Override
345 public void onHideCustomView() {
346 super.onHideCustomView();
347 if (mUseQuickControls) {
348 checkTabCount();
349 } else {
350 mActivity.getActionBar().show();
351 }
352 }
Michael Kolba4183062011-01-16 10:43:21 -0800353
354 @Override
355 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800356 if (mActiveTab != null) {
357 WebView web = mActiveTab.getWebView();
358 if (event.getAction() == KeyEvent.ACTION_DOWN) {
359 switch (code) {
360 case KeyEvent.KEYCODE_TAB:
361 case KeyEvent.KEYCODE_DPAD_UP:
362 case KeyEvent.KEYCODE_DPAD_LEFT:
363 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
364 editUrl(false);
365 return true;
366 }
367 }
368 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
369 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
370 editUrl(true);
371 return mContentView.dispatchKeyEvent(event);
372 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800373 }
Michael Kolba4183062011-01-16 10:43:21 -0800374 }
375 return false;
376 }
377
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800378 private boolean isTypingKey(KeyEvent evt) {
379 return evt.getUnicodeChar() > 0;
380 }
381
382 TabBar getTabBar() {
383 return mTabBar;
384 }
385
Michael Kolb66706532010-12-12 19:50:22 -0800386}