blob: 254e73d9aff296a36d6b9920adb96b34d9edc3f6 [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
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb66706532010-12-12 19:50:22 -080018
Michael Kolb66706532010-12-12 19:50:22 -080019import android.app.ActionBar;
20import android.app.Activity;
John Reck034637c2011-08-11 11:34:44 -070021import android.content.res.Resources;
22import android.graphics.Bitmap;
23import android.graphics.drawable.BitmapDrawable;
Pankaj Garg32e1b942015-06-03 18:13:24 -070024import android.graphics.drawable.ColorDrawable;
John Reck034637c2011-08-11 11:34:44 -070025import android.graphics.drawable.Drawable;
26import android.graphics.drawable.LayerDrawable;
27import android.graphics.drawable.PaintDrawable;
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 Kolba4183062011-01-16 10:43:21 -080032import android.view.KeyEvent;
Michael Kolb0d0245f2011-12-05 16:36:05 -080033import android.view.Menu;
34import android.view.MenuItem;
Pankaj Garg16053b42014-12-17 15:23:01 -080035import android.view.View;
Tarun Nainani87a86682015-02-05 11:47:35 -080036import android.view.ViewStub;
Pankaj Garg16053b42014-12-17 15:23:01 -080037import android.webkit.WebChromeClient;
38
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080039import org.codeaurora.swe.WebView;
Pankaj Garg32e1b942015-06-03 18:13:24 -070040import org.codeaurora.swe.util.ColorUtils;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080041
Bijan Amirzada41242f22014-03-21 12:12:18 -070042import com.android.browser.R;
Michael Kolb66706532010-12-12 19:50:22 -080043
44import java.util.List;
45
46/**
47 * Ui for xlarge screen sizes
48 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070049public class XLargeUi extends BaseUi {
Michael Kolb66706532010-12-12 19:50:22 -080050
51 private static final String LOGTAG = "XLargeUi";
52
John Reck034637c2011-08-11 11:34:44 -070053 private PaintDrawable mFaviconBackground;
54
Michael Kolb376b5412010-12-15 11:52:57 -080055 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080056 private TabBar mTabBar;
57
John Reck0f602f32011-07-07 15:38:43 -070058 private NavigationBarTablet mNavBar;
Tarun Nainani87a86682015-02-05 11:47:35 -080059 private ComboView mComboView;
Michael Kolb66706532010-12-12 19:50:22 -080060
Michael Kolbba238702011-03-08 10:40:50 -080061 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080062
Michael Kolb66706532010-12-12 19:50:22 -080063 /**
64 * @param browser
65 * @param controller
66 */
67 public XLargeUi(Activity browser, UiController controller) {
68 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080069 mHandler = new Handler();
John Reck0f602f32011-07-07 15:38:43 -070070 mNavBar = (NavigationBarTablet) mTitleBar.getNavigationBar();
Michael Kolb66706532010-12-12 19:50:22 -080071 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080072 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080073 setupActionBar();
John Reckb3417f02011-01-14 11:01:05 -080074 }
75
76 private void setupActionBar() {
Tarun Nainani87a86682015-02-05 11:47:35 -080077 mActionBar.setHomeButtonEnabled(false);
John Reckb3417f02011-01-14 11:01:05 -080078 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080079 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
80 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080081 }
82
John Reck2bc80422011-06-30 15:11:49 -070083 public void showComboView(ComboViews startWith, Bundle extras) {
Tarun Nainani87a86682015-02-05 11:47:35 -080084 if (mComboView == null) {
85 ViewStub stub = (ViewStub) mActivity.getWindow().getDecorView().findViewById(R.id.combo_view_stub);
86 mComboView = (ComboView) stub.inflate();
87 mComboView.setVisibility(View.GONE);
88 mComboView.setupViews(mActivity);
89 }
90 mNavBar.setVisibility(View.GONE);
91 if (mActionBar != null)
92 mActionBar.hide();
93 Bundle b = new Bundle();
94 b.putString(ComboViewActivity.EXTRA_INITIAL_VIEW, startWith.name());
95 b.putBundle(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
96 Tab t = getActiveTab();
97 if (t != null) {
98 b.putString(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
99 }
100 mComboView.showViews(mActivity, b);
101 }
102
103 @Override
104 public void hideComboView() {
105 if (showingComboView()) {
106 mComboView.hideViews();
107 mActionBar = mActivity.getActionBar();
108 setupActionBar();
109 if (mActionBar != null)
110 mActionBar.show();
111 mNavBar.setVisibility(View.VISIBLE);
112 }
113 }
114
115 @Override
116 public boolean onBackKey() {
117 if (showingComboView()) {
118 hideComboView();
119 return true;
120 }
121 return super.onBackKey();
122 }
123
124 private boolean showingComboView() {
125 return mComboView != null && mComboView.getVisibility() == View.VISIBLE;
126 }
127
128 @Override
129 public boolean isComboViewShowing() {
130 return showingComboView();
Michael Kolb376b5412010-12-15 11:52:57 -0800131 }
132
Michael Kolbda580632012-04-16 13:30:28 -0700133 private void checkHideActionBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800134 }
135
136 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000137 public void onResume() {
138 super.onResume();
Narayan Kamathf3174a52011-11-17 14:43:32 +0000139 mNavBar.clearCompletions();
Michael Kolbda580632012-04-16 13:30:28 -0700140 checkHideActionBar();
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000141 }
142
143 @Override
Pankaj Garg68faf1c2015-06-26 17:07:37 -0700144 public void onProgressChanged(Tab tab) {
145 super.onProgressChanged(tab);
146 if (mComboView != null && !mComboView.isShowing()) {
147 mActionBar = mActivity.getActionBar();
148 setupActionBar();
149 if (mActionBar != null)
150 mActionBar.show();
151 if (mNavBar != null)
152 mNavBar.setVisibility(View.VISIBLE);
153 }
154 }
155
156 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800157 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800158 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800159 }
160
Michael Kolb66706532010-12-12 19:50:22 -0800161 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700162 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800163 if (web != null) {
164 web.stopScroll();
Michael Kolb66706532010-12-12 19:50:22 -0800165 }
166 }
167
Michael Kolb0d0245f2011-12-05 16:36:05 -0800168 @Override
169 public boolean onPrepareOptionsMenu(Menu menu) {
170 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
171 if (bm != null) {
172 bm.setVisible(false);
173 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800174
175 menu.setGroupVisible(R.id.NAV_MENU, false);
176
Michael Kolb0d0245f2011-12-05 16:36:05 -0800177 return true;
178 }
179
180
Michael Kolb66706532010-12-12 19:50:22 -0800181 // WebView callbacks
182
183 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800184 public void addTab(Tab tab) {
185 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800186 }
187
188 protected void onAddTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700189 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800190 }
191
192 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800193 public void setActiveTab(final Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700194 mTitleBar.cancelTitleBarAnimation(true);
195 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700196 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700197 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800198 // TabControl.setCurrentTab has been called before this,
199 // so the tab is guaranteed to have a webview
200 if (view == null) {
201 Log.e(LOGTAG, "active tab with no webview detected");
202 return;
203 }
Michael Kolb66706532010-12-12 19:50:22 -0800204 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800205 updateLockIconToLatest(tab);
John Reck5d43ce82011-06-21 17:16:51 -0700206 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800207 }
208
209 @Override
210 public void updateTabs(List<Tab> tabs) {
211 mTabBar.updateTabs(tabs);
Michael Kolbda580632012-04-16 13:30:28 -0700212 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800213 }
214
215 @Override
216 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700217 mTitleBar.cancelTitleBarAnimation(true);
218 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800219 super.removeTab(tab);
220 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700221 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800222 }
223
Pankaj Garg16053b42014-12-17 15:23:01 -0800224 @Override
225 public void showCustomView(View view, int requestedOrientation,
226 WebChromeClient.CustomViewCallback callback) {
227 super.showCustomView(view, requestedOrientation, callback);
228 if (mActionBar != null)
229 mActionBar.hide();
230 }
231
Michael Kolb8814d732011-01-26 11:22:30 -0800232 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700233 checkHideActionBar();
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
Michael Kolb1f9b3562012-04-24 14:38:34 -0700244 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700245 super.editUrl(clearInput, forceIME);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800246 }
247
Michael Kolb66706532010-12-12 19:50:22 -0800248 // action mode callbacks
249
250 @Override
251 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800252 if (!mTitleBar.isEditingUrl()) {
Michael Kolbb2e91fd2011-07-14 13:47:29 -0700253 // hide the title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800254 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800255 }
256 }
257
258 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800259 public void onActionModeFinished(boolean inLoad) {
Michael Kolbda580632012-04-16 13:30:28 -0700260 checkHideActionBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800261 if (inLoad) {
262 // the titlebar was removed when the CAB was shown
263 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800264 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800265 }
266 }
267
268 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800269 protected void updateNavigationState(Tab tab) {
John Reck0f602f32011-07-07 15:38:43 -0700270 mNavBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800271 }
272
273 @Override
John Reck30c714c2010-12-16 17:30:34 -0800274 public void setUrlTitle(Tab tab) {
275 super.setUrlTitle(tab);
276 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800277 }
278
279 // Set the favicon in the title bar.
280 @Override
John Reck30c714c2010-12-16 17:30:34 -0800281 public void setFavicon(Tab tab) {
282 super.setFavicon(tab);
283 mTabBar.onFavicon(tab, tab.getFavicon());
Pankaj Garg68faf1c2015-06-26 17:07:37 -0700284/*
Pankaj Garg32e1b942015-06-03 18:13:24 -0700285 if (mActiveTab == tab) {
286 int color = NavigationBarBase.getSiteIconColor(tab.getUrl());
287 if (tab.hasFavicon()) {
288 color = ColorUtils.getDominantColorForBitmap(tab.getFavicon());
289 }
290 mActionBar.setBackgroundDrawable(new ColorDrawable(color));
291 }
Pankaj Garg68faf1c2015-06-26 17:07:37 -0700292*/
Michael Kolb66706532010-12-12 19:50:22 -0800293 }
294
Michael Kolbcfa3af52010-12-14 10:36:11 -0800295 @Override
John Reckd73c5a22010-12-22 10:22:50 -0800296 public void onHideCustomView() {
297 super.onHideCustomView();
Michael Kolbda580632012-04-16 13:30:28 -0700298 checkHideActionBar();
Pankaj Garg16053b42014-12-17 15:23:01 -0800299 if (mActionBar != null)
300 mActionBar.show();
John Reckd73c5a22010-12-22 10:22:50 -0800301 }
Michael Kolba4183062011-01-16 10:43:21 -0800302
303 @Override
304 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800305 if (mActiveTab != null) {
306 WebView web = mActiveTab.getWebView();
307 if (event.getAction() == KeyEvent.ACTION_DOWN) {
308 switch (code) {
309 case KeyEvent.KEYCODE_TAB:
310 case KeyEvent.KEYCODE_DPAD_UP:
311 case KeyEvent.KEYCODE_DPAD_LEFT:
312 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700313 editUrl(false, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800314 return true;
315 }
316 }
317 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
318 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700319 editUrl(true, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800320 return mContentView.dispatchKeyEvent(event);
321 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800322 }
Michael Kolba4183062011-01-16 10:43:21 -0800323 }
324 return false;
325 }
326
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800327 private boolean isTypingKey(KeyEvent evt) {
328 return evt.getUnicodeChar() > 0;
329 }
330
331 TabBar getTabBar() {
332 return mTabBar;
333 }
334
John Reck1cf4b792011-07-26 10:22:22 -0700335 @Override
336 public boolean shouldCaptureThumbnails() {
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700337 return false;
John Reck1cf4b792011-07-26 10:22:22 -0700338 }
339
John Reck034637c2011-08-11 11:34:44 -0700340 private Drawable getFaviconBackground() {
341 if (mFaviconBackground == null) {
342 mFaviconBackground = new PaintDrawable();
343 Resources res = mActivity.getResources();
344 mFaviconBackground.getPaint().setColor(
345 res.getColor(R.color.tabFaviconBackground));
346 mFaviconBackground.setCornerRadius(
347 res.getDimension(R.dimen.tab_favicon_corner_radius));
348 }
349 return mFaviconBackground;
350 }
351
352 @Override
353 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800354 if (ENABLE_BORDER_AROUND_FAVICON) {
355 Drawable[] array = new Drawable[2];
356 array[0] = getFaviconBackground();
357 if (icon == null) {
358 array[1] = getGenericFavicon();
359 } else {
360 array[1] = new BitmapDrawable(mActivity.getResources(), icon);
361 }
362 LayerDrawable d = new LayerDrawable(array);
363 d.setLayerInset(1, 2, 2, 2, 2);
364 return d;
John Reck034637c2011-08-11 11:34:44 -0700365 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800366 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
John Reck034637c2011-08-11 11:34:44 -0700367 }
368
Michael Kolb66706532010-12-12 19:50:22 -0800369}