blob: f444e9b0e5477a2867973f216c117592646b6186 [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;
24import android.graphics.drawable.Drawable;
25import android.graphics.drawable.LayerDrawable;
26import android.graphics.drawable.PaintDrawable;
Michael Kolbac35bdc2011-01-17 17:06:04 -080027import android.os.Bundle;
Michael Kolbba238702011-03-08 10:40:50 -080028import android.os.Handler;
Michael Kolb376b5412010-12-15 11:52:57 -080029import android.util.Log;
Michael Kolb66706532010-12-12 19:50:22 -080030import android.view.ActionMode;
Michael Kolba4183062011-01-16 10:43:21 -080031import android.view.KeyEvent;
Michael Kolb0d0245f2011-12-05 16:36:05 -080032import android.view.Menu;
33import android.view.MenuItem;
Pankaj Garg16053b42014-12-17 15:23:01 -080034import android.view.View;
Tarun Nainani87a86682015-02-05 11:47:35 -080035import android.view.ViewStub;
Pankaj Garg16053b42014-12-17 15:23:01 -080036import android.webkit.WebChromeClient;
37
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080038import org.codeaurora.swe.WebView;
Michael Kolb66706532010-12-12 19:50:22 -080039
40import java.util.List;
41
42/**
43 * Ui for xlarge screen sizes
44 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070045public class XLargeUi extends BaseUi {
Michael Kolb66706532010-12-12 19:50:22 -080046
47 private static final String LOGTAG = "XLargeUi";
48
John Reck034637c2011-08-11 11:34:44 -070049 private PaintDrawable mFaviconBackground;
50
Michael Kolb376b5412010-12-15 11:52:57 -080051 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080052 private TabBar mTabBar;
53
John Reck0f602f32011-07-07 15:38:43 -070054 private NavigationBarTablet mNavBar;
Tarun Nainani87a86682015-02-05 11:47:35 -080055 private ComboView mComboView;
Michael Kolb66706532010-12-12 19:50:22 -080056
Michael Kolbba238702011-03-08 10:40:50 -080057 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080058
Michael Kolb66706532010-12-12 19:50:22 -080059 /**
60 * @param browser
61 * @param controller
62 */
63 public XLargeUi(Activity browser, UiController controller) {
64 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080065 mHandler = new Handler();
John Reck0f602f32011-07-07 15:38:43 -070066 mNavBar = (NavigationBarTablet) mTitleBar.getNavigationBar();
Michael Kolb66706532010-12-12 19:50:22 -080067 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080068 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080069 setupActionBar();
John Reckb3417f02011-01-14 11:01:05 -080070 }
71
72 private void setupActionBar() {
Tarun Nainani87a86682015-02-05 11:47:35 -080073 mActionBar.setHomeButtonEnabled(false);
John Reckb3417f02011-01-14 11:01:05 -080074 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080075 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
76 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080077 }
78
John Reck2bc80422011-06-30 15:11:49 -070079 public void showComboView(ComboViews startWith, Bundle extras) {
Tarun Nainani87a86682015-02-05 11:47:35 -080080 if (mComboView == null) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070081 ViewStub stub = (ViewStub) mActivity.getWindow().getDecorView().
82 findViewById(R.id.combo_view_stub);
Tarun Nainani87a86682015-02-05 11:47:35 -080083 mComboView = (ComboView) stub.inflate();
84 mComboView.setVisibility(View.GONE);
85 mComboView.setupViews(mActivity);
86 }
87 mNavBar.setVisibility(View.GONE);
88 if (mActionBar != null)
89 mActionBar.hide();
90 Bundle b = new Bundle();
91 b.putString(ComboViewActivity.EXTRA_INITIAL_VIEW, startWith.name());
92 b.putBundle(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
93 Tab t = getActiveTab();
94 if (t != null) {
95 b.putString(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
96 }
97 mComboView.showViews(mActivity, b);
98 }
99
100 @Override
101 public void hideComboView() {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700102 if (isComboViewShowing()) {
Tarun Nainani87a86682015-02-05 11:47:35 -0800103 mComboView.hideViews();
104 mActionBar = mActivity.getActionBar();
105 setupActionBar();
106 if (mActionBar != null)
107 mActionBar.show();
108 mNavBar.setVisibility(View.VISIBLE);
109 }
110 }
111
112 @Override
113 public boolean onBackKey() {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700114 if (isComboViewShowing()) {
Tarun Nainani87a86682015-02-05 11:47:35 -0800115 hideComboView();
116 return true;
117 }
118 return super.onBackKey();
119 }
120
Tarun Nainani87a86682015-02-05 11:47:35 -0800121 @Override
122 public boolean isComboViewShowing() {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700123 return mComboView != null && mComboView.getVisibility() == View.VISIBLE;
Michael Kolb66706532010-12-12 19:50:22 -0800124 }
125
126 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000127 public void onResume() {
128 super.onResume();
Narayan Kamathf3174a52011-11-17 14:43:32 +0000129 mNavBar.clearCompletions();
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000130 }
131
132 @Override
Pankaj Garg68faf1c2015-06-26 17:07:37 -0700133 public void onProgressChanged(Tab tab) {
134 super.onProgressChanged(tab);
135 if (mComboView != null && !mComboView.isShowing()) {
136 mActionBar = mActivity.getActionBar();
137 setupActionBar();
138 if (mActionBar != null)
139 mActionBar.show();
140 if (mNavBar != null)
141 mNavBar.setVisibility(View.VISIBLE);
142 }
143 }
144
145 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800146 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800147 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800148 }
149
Michael Kolb66706532010-12-12 19:50:22 -0800150 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700151 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800152 if (web != null) {
153 web.stopScroll();
Michael Kolb66706532010-12-12 19:50:22 -0800154 }
155 }
156
Michael Kolb0d0245f2011-12-05 16:36:05 -0800157 @Override
158 public boolean onPrepareOptionsMenu(Menu menu) {
159 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
160 if (bm != null) {
161 bm.setVisible(false);
162 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800163
164 menu.setGroupVisible(R.id.NAV_MENU, false);
165
Michael Kolb0d0245f2011-12-05 16:36:05 -0800166 return true;
167 }
168
169
Michael Kolb66706532010-12-12 19:50:22 -0800170 // WebView callbacks
171
172 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800173 public void addTab(Tab tab) {
174 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800175 }
176
Michael Kolb66706532010-12-12 19:50:22 -0800177 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800178 public void setActiveTab(final Tab tab) {
John Reck5d43ce82011-06-21 17:16:51 -0700179 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700180 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800181 // TabControl.setCurrentTab has been called before this,
182 // so the tab is guaranteed to have a webview
183 if (view == null) {
184 Log.e(LOGTAG, "active tab with no webview detected");
185 return;
186 }
Michael Kolb66706532010-12-12 19:50:22 -0800187 mTabBar.onSetActiveTab(tab);
188 }
189
190 @Override
191 public void updateTabs(List<Tab> tabs) {
192 mTabBar.updateTabs(tabs);
193 }
194
195 @Override
196 public void removeTab(Tab tab) {
197 super.removeTab(tab);
198 mTabBar.onRemoveTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800199 }
200
Pankaj Garg16053b42014-12-17 15:23:01 -0800201 @Override
202 public void showCustomView(View view, int requestedOrientation,
203 WebChromeClient.CustomViewCallback callback) {
204 super.showCustomView(view, requestedOrientation, callback);
Sagar Dhawanf5e6af62015-09-14 19:50:50 -0700205 mTitleBar.setTranslationY(
206 -mActivity.getResources().getDimensionPixelSize(R.dimen.toolbar_height));
Pankaj Garg16053b42014-12-17 15:23:01 -0800207 if (mActionBar != null)
208 mActionBar.hide();
209 }
210
Michael Kolb376b5412010-12-15 11:52:57 -0800211 int getContentWidth() {
212 if (mContentView != null) {
213 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800214 }
215 return 0;
216 }
217
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800218 @Override
Michael Kolb1f9b3562012-04-24 14:38:34 -0700219 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700220 super.editUrl(clearInput, forceIME);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800221 }
222
Michael Kolb66706532010-12-12 19:50:22 -0800223 // action mode callbacks
224
225 @Override
226 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800227 if (!mTitleBar.isEditingUrl()) {
Michael Kolbb2e91fd2011-07-14 13:47:29 -0700228 // hide the title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800229 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800230 }
231 }
232
233 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800234 public void onActionModeFinished(boolean inLoad) {
Michael Kolb376b5412010-12-15 11:52:57 -0800235 if (inLoad) {
236 // the titlebar was removed when the CAB was shown
237 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800238 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800239 }
240 }
241
242 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800243 protected void updateNavigationState(Tab tab) {
John Reck0f602f32011-07-07 15:38:43 -0700244 mNavBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800245 }
246
247 @Override
John Reck30c714c2010-12-16 17:30:34 -0800248 public void setUrlTitle(Tab tab) {
249 super.setUrlTitle(tab);
250 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800251 }
252
253 // Set the favicon in the title bar.
254 @Override
John Reck30c714c2010-12-16 17:30:34 -0800255 public void setFavicon(Tab tab) {
256 super.setFavicon(tab);
257 mTabBar.onFavicon(tab, tab.getFavicon());
Pankaj Garg68faf1c2015-06-26 17:07:37 -0700258/*
Pankaj Garg32e1b942015-06-03 18:13:24 -0700259 if (mActiveTab == tab) {
260 int color = NavigationBarBase.getSiteIconColor(tab.getUrl());
261 if (tab.hasFavicon()) {
262 color = ColorUtils.getDominantColorForBitmap(tab.getFavicon());
263 }
264 mActionBar.setBackgroundDrawable(new ColorDrawable(color));
265 }
Pankaj Garg68faf1c2015-06-26 17:07:37 -0700266*/
Michael Kolb66706532010-12-12 19:50:22 -0800267 }
268
Michael Kolbcfa3af52010-12-14 10:36:11 -0800269 @Override
John Reckd73c5a22010-12-22 10:22:50 -0800270 public void onHideCustomView() {
271 super.onHideCustomView();
Pankaj Garg16053b42014-12-17 15:23:01 -0800272 if (mActionBar != null)
273 mActionBar.show();
Sagar Dhawanf5e6af62015-09-14 19:50:50 -0700274 mTitleBar.setTranslationY(0);
John Reckd73c5a22010-12-22 10:22:50 -0800275 }
Michael Kolba4183062011-01-16 10:43:21 -0800276
277 @Override
278 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800279 if (mActiveTab != null) {
280 WebView web = mActiveTab.getWebView();
281 if (event.getAction() == KeyEvent.ACTION_DOWN) {
282 switch (code) {
283 case KeyEvent.KEYCODE_TAB:
284 case KeyEvent.KEYCODE_DPAD_UP:
285 case KeyEvent.KEYCODE_DPAD_LEFT:
286 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700287 editUrl(false, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800288 return true;
289 }
290 }
291 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
292 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700293 editUrl(true, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800294 return mContentView.dispatchKeyEvent(event);
295 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800296 }
Michael Kolba4183062011-01-16 10:43:21 -0800297 }
298 return false;
299 }
300
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800301 private boolean isTypingKey(KeyEvent evt) {
302 return evt.getUnicodeChar() > 0;
303 }
304
John Reck1cf4b792011-07-26 10:22:22 -0700305 @Override
306 public boolean shouldCaptureThumbnails() {
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700307 return false;
John Reck1cf4b792011-07-26 10:22:22 -0700308 }
309
John Reck034637c2011-08-11 11:34:44 -0700310 private Drawable getFaviconBackground() {
311 if (mFaviconBackground == null) {
312 mFaviconBackground = new PaintDrawable();
313 Resources res = mActivity.getResources();
314 mFaviconBackground.getPaint().setColor(
315 res.getColor(R.color.tabFaviconBackground));
316 mFaviconBackground.setCornerRadius(
317 res.getDimension(R.dimen.tab_favicon_corner_radius));
318 }
319 return mFaviconBackground;
320 }
321
322 @Override
323 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800324 if (ENABLE_BORDER_AROUND_FAVICON) {
325 Drawable[] array = new Drawable[2];
326 array[0] = getFaviconBackground();
327 if (icon == null) {
328 array[1] = getGenericFavicon();
329 } else {
330 array[1] = new BitmapDrawable(mActivity.getResources(), icon);
331 }
332 LayerDrawable d = new LayerDrawable(array);
333 d.setLayerInset(1, 2, 2, 2, 2);
334 return d;
John Reck034637c2011-08-11 11:34:44 -0700335 }
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700336 return icon == null ? getGenericFavicon() :
337 new BitmapDrawable(mActivity.getResources(), icon);
John Reck034637c2011-08-11 11:34:44 -0700338 }
339
Michael Kolb66706532010-12-12 19:50:22 -0800340}