blob: ec62a23e3429d78cbb3d5277338a9202fc9483d6 [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;
39
Bijan Amirzada41242f22014-03-21 12:12:18 -070040import com.android.browser.R;
Michael Kolb66706532010-12-12 19:50:22 -080041
42import java.util.List;
43
44/**
45 * Ui for xlarge screen sizes
46 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070047public class XLargeUi extends BaseUi {
Michael Kolb66706532010-12-12 19:50:22 -080048
49 private static final String LOGTAG = "XLargeUi";
50
John Reck034637c2011-08-11 11:34:44 -070051 private PaintDrawable mFaviconBackground;
52
Michael Kolb376b5412010-12-15 11:52:57 -080053 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080054 private TabBar mTabBar;
55
John Reck0f602f32011-07-07 15:38:43 -070056 private NavigationBarTablet mNavBar;
Tarun Nainani87a86682015-02-05 11:47:35 -080057 private ComboView mComboView;
Michael Kolb66706532010-12-12 19:50:22 -080058
Michael Kolbba238702011-03-08 10:40:50 -080059 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080060
Michael Kolb66706532010-12-12 19:50:22 -080061 /**
62 * @param browser
63 * @param controller
64 */
65 public XLargeUi(Activity browser, UiController controller) {
66 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080067 mHandler = new Handler();
John Reck0f602f32011-07-07 15:38:43 -070068 mNavBar = (NavigationBarTablet) mTitleBar.getNavigationBar();
Michael Kolb66706532010-12-12 19:50:22 -080069 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080070 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080071 setupActionBar();
John Reckb3417f02011-01-14 11:01:05 -080072 }
73
74 private void setupActionBar() {
Tarun Nainani87a86682015-02-05 11:47:35 -080075 mActionBar.setHomeButtonEnabled(false);
John Reckb3417f02011-01-14 11:01:05 -080076 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080077 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
78 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080079 }
80
John Reck2bc80422011-06-30 15:11:49 -070081 public void showComboView(ComboViews startWith, Bundle extras) {
Tarun Nainani87a86682015-02-05 11:47:35 -080082 if (mComboView == null) {
83 ViewStub stub = (ViewStub) mActivity.getWindow().getDecorView().findViewById(R.id.combo_view_stub);
84 mComboView = (ComboView) stub.inflate();
85 mComboView.setVisibility(View.GONE);
86 mComboView.setupViews(mActivity);
87 }
88 mNavBar.setVisibility(View.GONE);
89 if (mActionBar != null)
90 mActionBar.hide();
91 Bundle b = new Bundle();
92 b.putString(ComboViewActivity.EXTRA_INITIAL_VIEW, startWith.name());
93 b.putBundle(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
94 Tab t = getActiveTab();
95 if (t != null) {
96 b.putString(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
97 }
98 mComboView.showViews(mActivity, b);
99 }
100
101 @Override
102 public void hideComboView() {
103 if (showingComboView()) {
104 mComboView.hideViews();
105 mActionBar = mActivity.getActionBar();
106 setupActionBar();
107 if (mActionBar != null)
108 mActionBar.show();
109 mNavBar.setVisibility(View.VISIBLE);
110 }
111 }
112
113 @Override
114 public boolean onBackKey() {
115 if (showingComboView()) {
116 hideComboView();
117 return true;
118 }
119 return super.onBackKey();
120 }
121
122 private boolean showingComboView() {
123 return mComboView != null && mComboView.getVisibility() == View.VISIBLE;
124 }
125
126 @Override
127 public boolean isComboViewShowing() {
128 return showingComboView();
Michael Kolb376b5412010-12-15 11:52:57 -0800129 }
130
Michael Kolbda580632012-04-16 13:30:28 -0700131 private void checkHideActionBar() {
Michael Kolb66706532010-12-12 19:50:22 -0800132 }
133
134 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000135 public void onResume() {
136 super.onResume();
Narayan Kamathf3174a52011-11-17 14:43:32 +0000137 mNavBar.clearCompletions();
Michael Kolbda580632012-04-16 13:30:28 -0700138 checkHideActionBar();
Narayan Kamath67b8c1b2011-03-09 20:47:52 +0000139 }
140
141 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800142 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800143 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800144 }
145
Michael Kolb66706532010-12-12 19:50:22 -0800146 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -0700147 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800148 if (web != null) {
149 web.stopScroll();
Michael Kolb66706532010-12-12 19:50:22 -0800150 }
151 }
152
Michael Kolb0d0245f2011-12-05 16:36:05 -0800153 @Override
154 public boolean onPrepareOptionsMenu(Menu menu) {
155 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
156 if (bm != null) {
157 bm.setVisible(false);
158 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800159
160 menu.setGroupVisible(R.id.NAV_MENU, false);
161
Michael Kolb0d0245f2011-12-05 16:36:05 -0800162 return true;
163 }
164
165
Michael Kolb66706532010-12-12 19:50:22 -0800166 // WebView callbacks
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 Kolbda580632012-04-16 13:30:28 -0700174 checkHideActionBar();
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);
John Reck5d43ce82011-06-21 17:16:51 -0700181 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700182 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800183 // TabControl.setCurrentTab has been called before this,
184 // so the tab is guaranteed to have a webview
185 if (view == null) {
186 Log.e(LOGTAG, "active tab with no webview detected");
187 return;
188 }
Michael Kolb66706532010-12-12 19:50:22 -0800189 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800190 updateLockIconToLatest(tab);
John Reck5d43ce82011-06-21 17:16:51 -0700191 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800192 }
193
194 @Override
195 public void updateTabs(List<Tab> tabs) {
196 mTabBar.updateTabs(tabs);
Michael Kolbda580632012-04-16 13:30:28 -0700197 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800198 }
199
200 @Override
201 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700202 mTitleBar.cancelTitleBarAnimation(true);
203 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800204 super.removeTab(tab);
205 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700206 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800207 }
208
Pankaj Garg16053b42014-12-17 15:23:01 -0800209 @Override
210 public void showCustomView(View view, int requestedOrientation,
211 WebChromeClient.CustomViewCallback callback) {
212 super.showCustomView(view, requestedOrientation, callback);
213 if (mActionBar != null)
214 mActionBar.hide();
215 }
216
Michael Kolb8814d732011-01-26 11:22:30 -0800217 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700218 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800219 }
220
Michael Kolb376b5412010-12-15 11:52:57 -0800221 int getContentWidth() {
222 if (mContentView != null) {
223 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800224 }
225 return 0;
226 }
227
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800228 @Override
Michael Kolb1f9b3562012-04-24 14:38:34 -0700229 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700230 super.editUrl(clearInput, forceIME);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800231 }
232
Michael Kolb66706532010-12-12 19:50:22 -0800233 // action mode callbacks
234
235 @Override
236 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800237 if (!mTitleBar.isEditingUrl()) {
Michael Kolbb2e91fd2011-07-14 13:47:29 -0700238 // hide the title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800239 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800240 }
241 }
242
243 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800244 public void onActionModeFinished(boolean inLoad) {
Michael Kolbda580632012-04-16 13:30:28 -0700245 checkHideActionBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800246 if (inLoad) {
247 // the titlebar was removed when the CAB was shown
248 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800249 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800250 }
251 }
252
253 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800254 protected void updateNavigationState(Tab tab) {
John Reck0f602f32011-07-07 15:38:43 -0700255 mNavBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800256 }
257
258 @Override
John Reck30c714c2010-12-16 17:30:34 -0800259 public void setUrlTitle(Tab tab) {
260 super.setUrlTitle(tab);
261 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800262 }
263
264 // Set the favicon in the title bar.
265 @Override
John Reck30c714c2010-12-16 17:30:34 -0800266 public void setFavicon(Tab tab) {
267 super.setFavicon(tab);
268 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800269 }
270
Michael Kolbcfa3af52010-12-14 10:36:11 -0800271 @Override
John Reckd73c5a22010-12-22 10:22:50 -0800272 public void onHideCustomView() {
273 super.onHideCustomView();
Michael Kolbda580632012-04-16 13:30:28 -0700274 checkHideActionBar();
Pankaj Garg16053b42014-12-17 15:23:01 -0800275 if (mActionBar != null)
276 mActionBar.show();
John Reckd73c5a22010-12-22 10:22:50 -0800277 }
Michael Kolba4183062011-01-16 10:43:21 -0800278
279 @Override
280 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800281 if (mActiveTab != null) {
282 WebView web = mActiveTab.getWebView();
283 if (event.getAction() == KeyEvent.ACTION_DOWN) {
284 switch (code) {
285 case KeyEvent.KEYCODE_TAB:
286 case KeyEvent.KEYCODE_DPAD_UP:
287 case KeyEvent.KEYCODE_DPAD_LEFT:
288 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700289 editUrl(false, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800290 return true;
291 }
292 }
293 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
294 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700295 editUrl(true, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800296 return mContentView.dispatchKeyEvent(event);
297 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800298 }
Michael Kolba4183062011-01-16 10:43:21 -0800299 }
300 return false;
301 }
302
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800303 private boolean isTypingKey(KeyEvent evt) {
304 return evt.getUnicodeChar() > 0;
305 }
306
307 TabBar getTabBar() {
308 return mTabBar;
309 }
310
John Reck1cf4b792011-07-26 10:22:22 -0700311 @Override
312 public boolean shouldCaptureThumbnails() {
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700313 return false;
John Reck1cf4b792011-07-26 10:22:22 -0700314 }
315
John Reck034637c2011-08-11 11:34:44 -0700316 private Drawable getFaviconBackground() {
317 if (mFaviconBackground == null) {
318 mFaviconBackground = new PaintDrawable();
319 Resources res = mActivity.getResources();
320 mFaviconBackground.getPaint().setColor(
321 res.getColor(R.color.tabFaviconBackground));
322 mFaviconBackground.setCornerRadius(
323 res.getDimension(R.dimen.tab_favicon_corner_radius));
324 }
325 return mFaviconBackground;
326 }
327
328 @Override
329 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800330 if (ENABLE_BORDER_AROUND_FAVICON) {
331 Drawable[] array = new Drawable[2];
332 array[0] = getFaviconBackground();
333 if (icon == null) {
334 array[1] = getGenericFavicon();
335 } else {
336 array[1] = new BitmapDrawable(mActivity.getResources(), icon);
337 }
338 LayerDrawable d = new LayerDrawable(array);
339 d.setLayerInset(1, 2, 2, 2, 2);
340 return d;
John Reck034637c2011-08-11 11:34:44 -0700341 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800342 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
John Reck034637c2011-08-11 11:34:44 -0700343 }
344
Michael Kolb66706532010-12-12 19:50:22 -0800345}