blob: 6fcfab74e5ce4dbeb7e764e5f5b24537bf7b9eb1 [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
31import java.util.List;
32
33/**
34 * Ui for xlarge screen sizes
35 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070036public class XLargeUi extends BaseUi {
Michael Kolb66706532010-12-12 19:50:22 -080037
38 private static final String LOGTAG = "XLargeUi";
39
Michael Kolb376b5412010-12-15 11:52:57 -080040 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080041 private TabBar mTabBar;
42
43 private TitleBarXLarge mTitleBar;
Michael Kolb66706532010-12-12 19:50:22 -080044
Michael Kolb376b5412010-12-15 11:52:57 -080045 private PieControl mPieControl;
Michael Kolbba238702011-03-08 10:40:50 -080046 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080047
Michael Kolb66706532010-12-12 19:50:22 -080048 /**
49 * @param browser
50 * @param controller
51 */
52 public XLargeUi(Activity browser, UiController controller) {
53 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080054 mHandler = new Handler();
Michael Kolb46f987e2011-04-05 10:39:10 -070055 mTitleBar = new TitleBarXLarge(mActivity, mUiController, this,
56 mContentView);
Michael Kolb66706532010-12-12 19:50:22 -080057 mTitleBar.setProgress(100);
Michael Kolb66706532010-12-12 19:50:22 -080058 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080059 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080060 setupActionBar();
61 setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
62 }
63
64 private void setupActionBar() {
65 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080066 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
67 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080068 }
69
John Reck2bc80422011-06-30 15:11:49 -070070 public void showComboView(ComboViews startWith, Bundle extras) {
71 super.showComboView(startWith, extras);
Michael Kolbac35bdc2011-01-17 17:06:04 -080072 if (mUseQuickControls) {
73 mActionBar.show();
74 }
75 }
76
77 @Override
John Reckb3417f02011-01-14 11:01:05 -080078 public void hideComboView() {
Michael Kolbba238702011-03-08 10:40:50 -080079 if (isComboViewShowing()) {
80 super.hideComboView();
81 // ComboView changes the action bar, set it back up to what we want
82 setupActionBar();
83 checkTabCount();
84 }
Michael Kolb376b5412010-12-15 11:52:57 -080085 }
86
87 private void setUseQuickControls(boolean useQuickControls) {
88 mUseQuickControls = useQuickControls;
Michael Kolb7cdc4902011-02-03 17:54:40 -080089 mTitleBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -080090 if (useQuickControls) {
91 checkTabCount();
92 mPieControl = new PieControl(mActivity, mUiController, this);
93 mPieControl.attachToContainer(mContentView);
Michael Kolb46f987e2011-04-05 10:39:10 -070094 WebView web = getWebView();
95 if (web != null) {
96 web.setEmbeddedTitleBar(null);
Michael Kolb376b5412010-12-15 11:52:57 -080097 }
98 } else {
99 mActivity.getActionBar().show();
100 if (mPieControl != null) {
101 mPieControl.removeFromContainer(mContentView);
102 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700103 WebView web = getWebView();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800104 if (web != null) {
Michael Kolb376b5412010-12-15 11:52:57 -0800105 web.setEmbeddedTitleBar(mTitleBar);
106 }
Michael Kolb8a4c3822011-03-15 14:52:05 -0700107 setTitleGravity(Gravity.NO_GRAVITY);
Michael Kolb376b5412010-12-15 11:52:57 -0800108 }
109 mTabBar.setUseQuickControls(mUseQuickControls);
Michael Kolb376b5412010-12-15 11:52:57 -0800110 }
111
112 private void checkTabCount() {
113 if (mUseQuickControls) {
Michael Kolbeb95db42011-03-03 10:38:40 -0800114 mHandler.post(new Runnable() {
115 public void run() {
116 mActionBar.hide();
117 }
118 });
Michael Kolb376b5412010-12-15 11:52:57 -0800119 }
Michael Kolb66706532010-12-12 19:50:22 -0800120 }
121
122 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000123 public void onResume() {
124 super.onResume();
John Reck35e9dd62011-04-25 09:01:54 -0700125 if (!BrowserSettings.getInstance().useInstantSearch()) {
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000126 mTitleBar.clearCompletions();
127 }
128 }
129
130 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800131 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800132 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800133 }
134
Michael Kolb66706532010-12-12 19:50:22 -0800135 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700136 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Michael Kolb66706532010-12-12 19:50:22 -0800137 if (web != null) {
138 web.stopScroll();
139 }
140 }
141
142 // WebView callbacks
143
144 @Override
John Reck30c714c2010-12-16 17:30:34 -0800145 public void onProgressChanged(Tab tab) {
146 int progress = tab.getLoadProgress();
Michael Kolb66706532010-12-12 19:50:22 -0800147 mTabBar.onProgress(tab, progress);
148 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800149 mTitleBar.setProgress(progress);
Michael Kolb66706532010-12-12 19:50:22 -0800150 }
151 }
152
153 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800154 public void addTab(Tab tab) {
155 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800156 }
157
158 protected void onAddTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800159 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800160 }
161
162 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800163 public void setActiveTab(final Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700164 mTitleBar.cancelTitleBarAnimation(true);
165 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolbeb95db42011-03-03 10:38:40 -0800166 if (mUseQuickControls) {
167 if (mActiveTab != null) {
168 captureTab(mActiveTab);
169 }
170 }
John Reck5d43ce82011-06-21 17:16:51 -0700171 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700172 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800173 // TabControl.setCurrentTab has been called before this,
174 // so the tab is guaranteed to have a webview
175 if (view == null) {
176 Log.e(LOGTAG, "active tab with no webview detected");
177 return;
178 }
179 // Request focus on the top window.
180 if (mUseQuickControls) {
181 mPieControl.forceToTop(mContentView);
Michael Kolb376b5412010-12-15 11:52:57 -0800182 } else {
Michael Kolb377ea312011-02-17 14:36:56 -0800183 // check if title bar is already attached by animation
John Reck541f55a2011-06-07 16:34:43 -0700184 if (mTitleBar.getParent() == null && !tab.isSnapshot()) {
Michael Kolb377ea312011-02-17 14:36:56 -0800185 view.setEmbeddedTitleBar(mTitleBar);
186 }
Michael Kolb376b5412010-12-15 11:52:57 -0800187 }
Michael Kolb66706532010-12-12 19:50:22 -0800188 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800189 if (tab.isInVoiceSearchMode()) {
Michael Kolb11d19782011-03-20 10:17:40 -0700190 showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
Michael Kolb376b5412010-12-15 11:52:57 -0800191 } else {
192 revertVoiceTitleBar(tab);
193 }
Michael Kolb376b5412010-12-15 11:52:57 -0800194 updateLockIconToLatest(tab);
195 tab.getTopWindow().requestFocus();
John Reck5d43ce82011-06-21 17:16:51 -0700196 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800197 }
198
199 @Override
200 public void updateTabs(List<Tab> tabs) {
201 mTabBar.updateTabs(tabs);
Michael Kolb376b5412010-12-15 11:52:57 -0800202 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800203 }
204
205 @Override
206 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700207 mTitleBar.cancelTitleBarAnimation(true);
208 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800209 super.removeTab(tab);
210 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700211 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800212 }
213
214 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolb376b5412010-12-15 11:52:57 -0800215 checkTabCount();
Michael Kolb66706532010-12-12 19:50:22 -0800216 }
217
Michael Kolb376b5412010-12-15 11:52:57 -0800218 int getContentWidth() {
219 if (mContentView != null) {
220 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800221 }
222 return 0;
223 }
224
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800225 @Override
226 public void editUrl(boolean clearInput) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700227 if (mUseQuickControls) {
228 getTitleBar().setShowProgressOnly(false);
Michael Kolbd72ea3b2011-01-09 15:56:37 -0800229 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700230 super.editUrl(clearInput);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800231 }
232
233 void stopEditingUrl() {
234 mTitleBar.stopEditingUrl();
235 }
236
237 @Override
238 protected void showTitleBar() {
239 if (canShowTitleBar()) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700240 mTitleBar.show();
Michael Kolb376b5412010-12-15 11:52:57 -0800241 }
Michael Kolb376b5412010-12-15 11:52:57 -0800242 }
243
Michael Kolb66706532010-12-12 19:50:22 -0800244 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800245 protected void hideTitleBar() {
246 if (isTitleBarShowing()) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700247 mTitleBar.hide();
Michael Kolb66706532010-12-12 19:50:22 -0800248 }
249 }
250
251 @Override
Michael Kolb7cdc4902011-02-03 17:54:40 -0800252 protected TitleBarBase getTitleBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800253 return mTitleBar;
254 }
255
Michael Kolb2a56eca2011-02-25 09:45:06 -0800256 @Override
257 protected void setTitleGravity(int gravity) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700258 if (!mUseQuickControls) {
Michael Kolb2a56eca2011-02-25 09:45:06 -0800259 super.setTitleGravity(gravity);
260 }
261 }
262
Michael Kolb66706532010-12-12 19:50:22 -0800263 // action mode callbacks
264
265 @Override
266 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800267 if (!mTitleBar.isEditingUrl()) {
Michael Kolb66706532010-12-12 19:50:22 -0800268 // hide the fake title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800269 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800270 }
271 }
272
273 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800274 public void onActionModeFinished(boolean inLoad) {
275 checkTabCount();
276 if (inLoad) {
277 // the titlebar was removed when the CAB was shown
278 // if the page is loading, show it again
Michael Kolb1544f3b2011-03-10 09:06:10 -0800279 if (mUseQuickControls) {
280 mTitleBar.setShowProgressOnly(true);
Michael Kolb376b5412010-12-15 11:52:57 -0800281 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800282 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800283 }
284 }
285
286 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800287 protected void updateNavigationState(Tab tab) {
288 mTitleBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800289 }
290
291 @Override
John Reck30c714c2010-12-16 17:30:34 -0800292 public void setUrlTitle(Tab tab) {
293 super.setUrlTitle(tab);
294 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800295 }
296
297 // Set the favicon in the title bar.
298 @Override
John Reck30c714c2010-12-16 17:30:34 -0800299 public void setFavicon(Tab tab) {
300 super.setFavicon(tab);
301 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800302 }
303
Michael Kolbcfa3af52010-12-14 10:36:11 -0800304 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700305 public void showVoiceTitleBar(String title, List<String> vsresults) {
Michael Kolb3a2a1642011-02-15 10:52:07 -0800306 mTitleBar.setInVoiceMode(true, vsresults);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800307 mTitleBar.setDisplayTitle(title);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800308 }
309
310 @Override
311 public void revertVoiceTitleBar(Tab tab) {
312 mTitleBar.setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800313 String url = tab.getUrl();
Michael Kolbcfa3af52010-12-14 10:36:11 -0800314 mTitleBar.setDisplayTitle(url);
Michael Kolbcfa3af52010-12-14 10:36:11 -0800315 }
316
John Reckd73c5a22010-12-22 10:22:50 -0800317 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400318 public void showCustomView(View view, int requestedOrientation,
319 CustomViewCallback callback) {
320 super.showCustomView(view, requestedOrientation, callback);
John Reckd73c5a22010-12-22 10:22:50 -0800321 mActivity.getActionBar().hide();
322 }
Michael Kolbcfa3af52010-12-14 10:36:11 -0800323
John Reckd73c5a22010-12-22 10:22:50 -0800324 @Override
325 public void onHideCustomView() {
326 super.onHideCustomView();
327 if (mUseQuickControls) {
328 checkTabCount();
329 } else {
330 mActivity.getActionBar().show();
331 }
332 }
Michael Kolba4183062011-01-16 10:43:21 -0800333
334 @Override
335 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800336 if (mActiveTab != null) {
337 WebView web = mActiveTab.getWebView();
338 if (event.getAction() == KeyEvent.ACTION_DOWN) {
339 switch (code) {
340 case KeyEvent.KEYCODE_TAB:
341 case KeyEvent.KEYCODE_DPAD_UP:
342 case KeyEvent.KEYCODE_DPAD_LEFT:
343 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
344 editUrl(false);
345 return true;
346 }
347 }
348 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
349 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
350 editUrl(true);
351 return mContentView.dispatchKeyEvent(event);
352 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800353 }
Michael Kolba4183062011-01-16 10:43:21 -0800354 }
355 return false;
356 }
357
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800358 private boolean isTypingKey(KeyEvent evt) {
359 return evt.getUnicodeChar() > 0;
360 }
361
362 TabBar getTabBar() {
363 return mTabBar;
364 }
365
Michael Kolb66706532010-12-12 19:50:22 -0800366}