blob: 603ce086b8672cb63239b09be22a9fe6e870bfc5 [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;
35import android.webkit.WebChromeClient;
36
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080037import org.codeaurora.swe.WebView;
38
Bijan Amirzada41242f22014-03-21 12:12:18 -070039import com.android.browser.R;
Michael Kolb66706532010-12-12 19:50:22 -080040
41import java.util.List;
42
43/**
44 * Ui for xlarge screen sizes
45 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070046public class XLargeUi extends BaseUi {
Michael Kolb66706532010-12-12 19:50:22 -080047
48 private static final String LOGTAG = "XLargeUi";
49
John Reck034637c2011-08-11 11:34:44 -070050 private PaintDrawable mFaviconBackground;
51
Michael Kolb376b5412010-12-15 11:52:57 -080052 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080053 private TabBar mTabBar;
54
John Reck0f602f32011-07-07 15:38:43 -070055 private NavigationBarTablet mNavBar;
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() {
73 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080074 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
75 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080076 }
77
John Reck2bc80422011-06-30 15:11:49 -070078 public void showComboView(ComboViews startWith, Bundle extras) {
79 super.showComboView(startWith, extras);
Michael Kolb376b5412010-12-15 11:52:57 -080080 }
81
Michael Kolbda580632012-04-16 13:30:28 -070082 private void checkHideActionBar() {
Michael Kolb66706532010-12-12 19:50:22 -080083 }
84
85 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +000086 public void onResume() {
87 super.onResume();
Narayan Kamathf3174a52011-11-17 14:43:32 +000088 mNavBar.clearCompletions();
Michael Kolbda580632012-04-16 13:30:28 -070089 checkHideActionBar();
Narayan Kamath67b8c1b2011-03-09 20:47:52 +000090 }
91
92 @Override
Michael Kolb66706532010-12-12 19:50:22 -080093 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080094 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080095 }
96
Michael Kolb66706532010-12-12 19:50:22 -080097 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -070098 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080099 if (web != null) {
100 web.stopScroll();
Michael Kolb66706532010-12-12 19:50:22 -0800101 }
102 }
103
Michael Kolb0d0245f2011-12-05 16:36:05 -0800104 @Override
105 public boolean onPrepareOptionsMenu(Menu menu) {
106 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
107 if (bm != null) {
108 bm.setVisible(false);
109 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800110
111 menu.setGroupVisible(R.id.NAV_MENU, false);
112
Michael Kolb0d0245f2011-12-05 16:36:05 -0800113 return true;
114 }
115
116
Michael Kolb66706532010-12-12 19:50:22 -0800117 // WebView callbacks
118
119 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800120 public void addTab(Tab tab) {
121 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800122 }
123
124 protected void onAddTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700125 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800126 }
127
128 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800129 public void setActiveTab(final Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700130 mTitleBar.cancelTitleBarAnimation(true);
131 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700132 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700133 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800134 // TabControl.setCurrentTab has been called before this,
135 // so the tab is guaranteed to have a webview
136 if (view == null) {
137 Log.e(LOGTAG, "active tab with no webview detected");
138 return;
139 }
Michael Kolb66706532010-12-12 19:50:22 -0800140 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800141 updateLockIconToLatest(tab);
John Reck5d43ce82011-06-21 17:16:51 -0700142 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800143 }
144
145 @Override
146 public void updateTabs(List<Tab> tabs) {
147 mTabBar.updateTabs(tabs);
Michael Kolbda580632012-04-16 13:30:28 -0700148 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800149 }
150
151 @Override
152 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700153 mTitleBar.cancelTitleBarAnimation(true);
154 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800155 super.removeTab(tab);
156 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700157 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800158 }
159
Pankaj Garg16053b42014-12-17 15:23:01 -0800160 @Override
161 public void showCustomView(View view, int requestedOrientation,
162 WebChromeClient.CustomViewCallback callback) {
163 super.showCustomView(view, requestedOrientation, callback);
164 if (mActionBar != null)
165 mActionBar.hide();
166 }
167
Michael Kolb8814d732011-01-26 11:22:30 -0800168 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700169 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800170 }
171
Michael Kolb376b5412010-12-15 11:52:57 -0800172 int getContentWidth() {
173 if (mContentView != null) {
174 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800175 }
176 return 0;
177 }
178
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800179 @Override
Michael Kolb1f9b3562012-04-24 14:38:34 -0700180 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700181 super.editUrl(clearInput, forceIME);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800182 }
183
Michael Kolb66706532010-12-12 19:50:22 -0800184 // action mode callbacks
185
186 @Override
187 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800188 if (!mTitleBar.isEditingUrl()) {
Michael Kolbb2e91fd2011-07-14 13:47:29 -0700189 // hide the title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800190 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800191 }
192 }
193
194 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800195 public void onActionModeFinished(boolean inLoad) {
Michael Kolbda580632012-04-16 13:30:28 -0700196 checkHideActionBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800197 if (inLoad) {
198 // the titlebar was removed when the CAB was shown
199 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800200 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800201 }
202 }
203
204 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800205 protected void updateNavigationState(Tab tab) {
John Reck0f602f32011-07-07 15:38:43 -0700206 mNavBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800207 }
208
209 @Override
John Reck30c714c2010-12-16 17:30:34 -0800210 public void setUrlTitle(Tab tab) {
211 super.setUrlTitle(tab);
212 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800213 }
214
215 // Set the favicon in the title bar.
216 @Override
John Reck30c714c2010-12-16 17:30:34 -0800217 public void setFavicon(Tab tab) {
218 super.setFavicon(tab);
219 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800220 }
221
Michael Kolbcfa3af52010-12-14 10:36:11 -0800222 @Override
John Reckd73c5a22010-12-22 10:22:50 -0800223 public void onHideCustomView() {
224 super.onHideCustomView();
Michael Kolbda580632012-04-16 13:30:28 -0700225 checkHideActionBar();
Pankaj Garg16053b42014-12-17 15:23:01 -0800226 if (mActionBar != null)
227 mActionBar.show();
John Reckd73c5a22010-12-22 10:22:50 -0800228 }
Michael Kolba4183062011-01-16 10:43:21 -0800229
230 @Override
231 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800232 if (mActiveTab != null) {
233 WebView web = mActiveTab.getWebView();
234 if (event.getAction() == KeyEvent.ACTION_DOWN) {
235 switch (code) {
236 case KeyEvent.KEYCODE_TAB:
237 case KeyEvent.KEYCODE_DPAD_UP:
238 case KeyEvent.KEYCODE_DPAD_LEFT:
239 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700240 editUrl(false, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800241 return true;
242 }
243 }
244 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
245 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700246 editUrl(true, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800247 return mContentView.dispatchKeyEvent(event);
248 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800249 }
Michael Kolba4183062011-01-16 10:43:21 -0800250 }
251 return false;
252 }
253
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800254 private boolean isTypingKey(KeyEvent evt) {
255 return evt.getUnicodeChar() > 0;
256 }
257
258 TabBar getTabBar() {
259 return mTabBar;
260 }
261
John Reck1cf4b792011-07-26 10:22:22 -0700262 @Override
263 public boolean shouldCaptureThumbnails() {
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700264 return false;
John Reck1cf4b792011-07-26 10:22:22 -0700265 }
266
John Reck034637c2011-08-11 11:34:44 -0700267 private Drawable getFaviconBackground() {
268 if (mFaviconBackground == null) {
269 mFaviconBackground = new PaintDrawable();
270 Resources res = mActivity.getResources();
271 mFaviconBackground.getPaint().setColor(
272 res.getColor(R.color.tabFaviconBackground));
273 mFaviconBackground.setCornerRadius(
274 res.getDimension(R.dimen.tab_favicon_corner_radius));
275 }
276 return mFaviconBackground;
277 }
278
279 @Override
280 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800281 if (ENABLE_BORDER_AROUND_FAVICON) {
282 Drawable[] array = new Drawable[2];
283 array[0] = getFaviconBackground();
284 if (icon == null) {
285 array[1] = getGenericFavicon();
286 } else {
287 array[1] = new BitmapDrawable(mActivity.getResources(), icon);
288 }
289 LayerDrawable d = new LayerDrawable(array);
290 d.setLayerInset(1, 2, 2, 2, 2);
291 return d;
John Reck034637c2011-08-11 11:34:44 -0700292 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800293 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
John Reck034637c2011-08-11 11:34:44 -0700294 }
295
Michael Kolb66706532010-12-12 19:50:22 -0800296}