blob: addbf72bb0a9d6463ac0acffbb5e3178dd198375 [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
Michael Kolb66706532010-12-12 19:50:22 -0800144 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800145 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800146 }
147
Michael Kolb66706532010-12-12 19:50:22 -0800148 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700149 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800150 if (web != null) {
151 web.stopScroll();
Michael Kolb66706532010-12-12 19:50:22 -0800152 }
153 }
154
Michael Kolb0d0245f2011-12-05 16:36:05 -0800155 @Override
156 public boolean onPrepareOptionsMenu(Menu menu) {
157 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
158 if (bm != null) {
159 bm.setVisible(false);
160 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800161
162 menu.setGroupVisible(R.id.NAV_MENU, false);
163
Michael Kolb0d0245f2011-12-05 16:36:05 -0800164 return true;
165 }
166
167
Michael Kolb66706532010-12-12 19:50:22 -0800168 // WebView callbacks
169
170 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800171 public void addTab(Tab tab) {
172 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800173 }
174
175 protected void onAddTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700176 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800177 }
178
179 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800180 public void setActiveTab(final Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700181 mTitleBar.cancelTitleBarAnimation(true);
182 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700183 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700184 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800185 // TabControl.setCurrentTab has been called before this,
186 // so the tab is guaranteed to have a webview
187 if (view == null) {
188 Log.e(LOGTAG, "active tab with no webview detected");
189 return;
190 }
Michael Kolb66706532010-12-12 19:50:22 -0800191 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800192 updateLockIconToLatest(tab);
John Reck5d43ce82011-06-21 17:16:51 -0700193 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800194 }
195
196 @Override
197 public void updateTabs(List<Tab> tabs) {
198 mTabBar.updateTabs(tabs);
Michael Kolbda580632012-04-16 13:30:28 -0700199 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800200 }
201
202 @Override
203 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700204 mTitleBar.cancelTitleBarAnimation(true);
205 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800206 super.removeTab(tab);
207 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700208 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800209 }
210
Pankaj Garg16053b42014-12-17 15:23:01 -0800211 @Override
212 public void showCustomView(View view, int requestedOrientation,
213 WebChromeClient.CustomViewCallback callback) {
214 super.showCustomView(view, requestedOrientation, callback);
215 if (mActionBar != null)
216 mActionBar.hide();
217 }
218
Michael Kolb8814d732011-01-26 11:22:30 -0800219 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700220 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800221 }
222
Michael Kolb376b5412010-12-15 11:52:57 -0800223 int getContentWidth() {
224 if (mContentView != null) {
225 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800226 }
227 return 0;
228 }
229
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800230 @Override
Michael Kolb1f9b3562012-04-24 14:38:34 -0700231 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700232 super.editUrl(clearInput, forceIME);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800233 }
234
Michael Kolb66706532010-12-12 19:50:22 -0800235 // action mode callbacks
236
237 @Override
238 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800239 if (!mTitleBar.isEditingUrl()) {
Michael Kolbb2e91fd2011-07-14 13:47:29 -0700240 // hide the title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800241 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800242 }
243 }
244
245 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800246 public void onActionModeFinished(boolean inLoad) {
Michael Kolbda580632012-04-16 13:30:28 -0700247 checkHideActionBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800248 if (inLoad) {
249 // the titlebar was removed when the CAB was shown
250 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800251 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800252 }
253 }
254
255 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800256 protected void updateNavigationState(Tab tab) {
John Reck0f602f32011-07-07 15:38:43 -0700257 mNavBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800258 }
259
260 @Override
John Reck30c714c2010-12-16 17:30:34 -0800261 public void setUrlTitle(Tab tab) {
262 super.setUrlTitle(tab);
263 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800264 }
265
266 // Set the favicon in the title bar.
267 @Override
John Reck30c714c2010-12-16 17:30:34 -0800268 public void setFavicon(Tab tab) {
269 super.setFavicon(tab);
270 mTabBar.onFavicon(tab, tab.getFavicon());
Pankaj Garg32e1b942015-06-03 18:13:24 -0700271 if (mActiveTab == tab) {
272 int color = NavigationBarBase.getSiteIconColor(tab.getUrl());
273 if (tab.hasFavicon()) {
274 color = ColorUtils.getDominantColorForBitmap(tab.getFavicon());
275 }
276 mActionBar.setBackgroundDrawable(new ColorDrawable(color));
277 }
Michael Kolb66706532010-12-12 19:50:22 -0800278 }
279
Michael Kolbcfa3af52010-12-14 10:36:11 -0800280 @Override
John Reckd73c5a22010-12-22 10:22:50 -0800281 public void onHideCustomView() {
282 super.onHideCustomView();
Michael Kolbda580632012-04-16 13:30:28 -0700283 checkHideActionBar();
Pankaj Garg16053b42014-12-17 15:23:01 -0800284 if (mActionBar != null)
285 mActionBar.show();
John Reckd73c5a22010-12-22 10:22:50 -0800286 }
Michael Kolba4183062011-01-16 10:43:21 -0800287
288 @Override
289 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800290 if (mActiveTab != null) {
291 WebView web = mActiveTab.getWebView();
292 if (event.getAction() == KeyEvent.ACTION_DOWN) {
293 switch (code) {
294 case KeyEvent.KEYCODE_TAB:
295 case KeyEvent.KEYCODE_DPAD_UP:
296 case KeyEvent.KEYCODE_DPAD_LEFT:
297 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700298 editUrl(false, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800299 return true;
300 }
301 }
302 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
303 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700304 editUrl(true, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800305 return mContentView.dispatchKeyEvent(event);
306 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800307 }
Michael Kolba4183062011-01-16 10:43:21 -0800308 }
309 return false;
310 }
311
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800312 private boolean isTypingKey(KeyEvent evt) {
313 return evt.getUnicodeChar() > 0;
314 }
315
316 TabBar getTabBar() {
317 return mTabBar;
318 }
319
John Reck1cf4b792011-07-26 10:22:22 -0700320 @Override
321 public boolean shouldCaptureThumbnails() {
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700322 return false;
John Reck1cf4b792011-07-26 10:22:22 -0700323 }
324
John Reck034637c2011-08-11 11:34:44 -0700325 private Drawable getFaviconBackground() {
326 if (mFaviconBackground == null) {
327 mFaviconBackground = new PaintDrawable();
328 Resources res = mActivity.getResources();
329 mFaviconBackground.getPaint().setColor(
330 res.getColor(R.color.tabFaviconBackground));
331 mFaviconBackground.setCornerRadius(
332 res.getDimension(R.dimen.tab_favicon_corner_radius));
333 }
334 return mFaviconBackground;
335 }
336
337 @Override
338 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800339 if (ENABLE_BORDER_AROUND_FAVICON) {
340 Drawable[] array = new Drawable[2];
341 array[0] = getFaviconBackground();
342 if (icon == null) {
343 array[1] = getGenericFavicon();
344 } else {
345 array[1] = new BitmapDrawable(mActivity.getResources(), icon);
346 }
347 LayerDrawable d = new LayerDrawable(array);
348 d.setLayerInset(1, 2, 2, 2, 2);
349 return d;
John Reck034637c2011-08-11 11:34:44 -0700350 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800351 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
John Reck034637c2011-08-11 11:34:44 -0700352 }
353
Michael Kolb66706532010-12-12 19:50:22 -0800354}