blob: a87b04515110d5ba63ae0a2992f632b7c8f56028 [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;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080034import org.codeaurora.swe.WebView;
35
Bijan Amirzada41242f22014-03-21 12:12:18 -070036import com.android.browser.R;
Michael Kolb66706532010-12-12 19:50:22 -080037
38import java.util.List;
39
40/**
41 * Ui for xlarge screen sizes
42 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070043public class XLargeUi extends BaseUi {
Michael Kolb66706532010-12-12 19:50:22 -080044
45 private static final String LOGTAG = "XLargeUi";
46
John Reck034637c2011-08-11 11:34:44 -070047 private PaintDrawable mFaviconBackground;
48
Michael Kolb376b5412010-12-15 11:52:57 -080049 private ActionBar mActionBar;
Michael Kolb66706532010-12-12 19:50:22 -080050 private TabBar mTabBar;
51
John Reck0f602f32011-07-07 15:38:43 -070052 private NavigationBarTablet mNavBar;
Michael Kolb66706532010-12-12 19:50:22 -080053
Michael Kolbba238702011-03-08 10:40:50 -080054 private Handler mHandler;
Michael Kolb376b5412010-12-15 11:52:57 -080055
Michael Kolb66706532010-12-12 19:50:22 -080056 /**
57 * @param browser
58 * @param controller
59 */
60 public XLargeUi(Activity browser, UiController controller) {
61 super(browser, controller);
Michael Kolbba238702011-03-08 10:40:50 -080062 mHandler = new Handler();
John Reck0f602f32011-07-07 15:38:43 -070063 mNavBar = (NavigationBarTablet) mTitleBar.getNavigationBar();
Michael Kolb66706532010-12-12 19:50:22 -080064 mTabBar = new TabBar(mActivity, mUiController, this);
Michael Kolb376b5412010-12-15 11:52:57 -080065 mActionBar = mActivity.getActionBar();
John Reckb3417f02011-01-14 11:01:05 -080066 setupActionBar();
John Reckb3417f02011-01-14 11:01:05 -080067 }
68
69 private void setupActionBar() {
70 mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
Michael Kolb376b5412010-12-15 11:52:57 -080071 mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
72 mActionBar.setCustomView(mTabBar);
John Reckb3417f02011-01-14 11:01:05 -080073 }
74
John Reck2bc80422011-06-30 15:11:49 -070075 public void showComboView(ComboViews startWith, Bundle extras) {
76 super.showComboView(startWith, extras);
Michael Kolb376b5412010-12-15 11:52:57 -080077 }
78
Michael Kolbda580632012-04-16 13:30:28 -070079 private void checkHideActionBar() {
Michael Kolb66706532010-12-12 19:50:22 -080080 }
81
82 @Override
Narayan Kamath67b8c1b2011-03-09 20:47:52 +000083 public void onResume() {
84 super.onResume();
Narayan Kamathf3174a52011-11-17 14:43:32 +000085 mNavBar.clearCompletions();
Michael Kolbda580632012-04-16 13:30:28 -070086 checkHideActionBar();
Narayan Kamath67b8c1b2011-03-09 20:47:52 +000087 }
88
89 @Override
Michael Kolb66706532010-12-12 19:50:22 -080090 public void onDestroy() {
Michael Kolb7cdc4902011-02-03 17:54:40 -080091 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -080092 }
93
Michael Kolb66706532010-12-12 19:50:22 -080094 void stopWebViewScrolling() {
John Reckb9a051b2011-03-18 11:55:48 -070095 BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080096 if (web != null) {
97 web.stopScroll();
Michael Kolb66706532010-12-12 19:50:22 -080098 }
99 }
100
Michael Kolb0d0245f2011-12-05 16:36:05 -0800101 @Override
102 public boolean onPrepareOptionsMenu(Menu menu) {
103 MenuItem bm = menu.findItem(R.id.bookmarks_menu_id);
104 if (bm != null) {
105 bm.setVisible(false);
106 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800107
108 menu.setGroupVisible(R.id.NAV_MENU, false);
109
Michael Kolb0d0245f2011-12-05 16:36:05 -0800110 return true;
111 }
112
113
Michael Kolb66706532010-12-12 19:50:22 -0800114 // WebView callbacks
115
116 @Override
Michael Kolb66706532010-12-12 19:50:22 -0800117 public void addTab(Tab tab) {
118 mTabBar.onNewTab(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800119 }
120
121 protected void onAddTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700122 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800123 }
124
125 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800126 public void setActiveTab(final Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700127 mTitleBar.cancelTitleBarAnimation(true);
128 mTitleBar.setSkipTitleBarAnimations(true);
John Reck5d43ce82011-06-21 17:16:51 -0700129 super.setActiveTab(tab);
John Reckb9a051b2011-03-18 11:55:48 -0700130 BrowserWebView view = (BrowserWebView) tab.getWebView();
Michael Kolb376b5412010-12-15 11:52:57 -0800131 // TabControl.setCurrentTab has been called before this,
132 // so the tab is guaranteed to have a webview
133 if (view == null) {
134 Log.e(LOGTAG, "active tab with no webview detected");
135 return;
136 }
Michael Kolb66706532010-12-12 19:50:22 -0800137 mTabBar.onSetActiveTab(tab);
Michael Kolb376b5412010-12-15 11:52:57 -0800138 updateLockIconToLatest(tab);
John Reck5d43ce82011-06-21 17:16:51 -0700139 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb66706532010-12-12 19:50:22 -0800140 }
141
142 @Override
143 public void updateTabs(List<Tab> tabs) {
144 mTabBar.updateTabs(tabs);
Michael Kolbda580632012-04-16 13:30:28 -0700145 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800146 }
147
148 @Override
149 public void removeTab(Tab tab) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700150 mTitleBar.cancelTitleBarAnimation(true);
151 mTitleBar.setSkipTitleBarAnimations(true);
Michael Kolb66706532010-12-12 19:50:22 -0800152 super.removeTab(tab);
153 mTabBar.onRemoveTab(tab);
Michael Kolb46f987e2011-04-05 10:39:10 -0700154 mTitleBar.setSkipTitleBarAnimations(false);
Michael Kolb8814d732011-01-26 11:22:30 -0800155 }
156
157 protected void onRemoveTabCompleted(Tab tab) {
Michael Kolbda580632012-04-16 13:30:28 -0700158 checkHideActionBar();
Michael Kolb66706532010-12-12 19:50:22 -0800159 }
160
Michael Kolb376b5412010-12-15 11:52:57 -0800161 int getContentWidth() {
162 if (mContentView != null) {
163 return mContentView.getWidth();
Michael Kolb66706532010-12-12 19:50:22 -0800164 }
165 return 0;
166 }
167
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800168 @Override
Michael Kolb1f9b3562012-04-24 14:38:34 -0700169 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700170 super.editUrl(clearInput, forceIME);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800171 }
172
Michael Kolb66706532010-12-12 19:50:22 -0800173 // action mode callbacks
174
175 @Override
176 public void onActionModeStarted(ActionMode mode) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800177 if (!mTitleBar.isEditingUrl()) {
Michael Kolbb2e91fd2011-07-14 13:47:29 -0700178 // hide the title bar when CAB is shown
Michael Kolb7cdc4902011-02-03 17:54:40 -0800179 hideTitleBar();
Michael Kolb66706532010-12-12 19:50:22 -0800180 }
181 }
182
183 @Override
Michael Kolb376b5412010-12-15 11:52:57 -0800184 public void onActionModeFinished(boolean inLoad) {
Michael Kolbda580632012-04-16 13:30:28 -0700185 checkHideActionBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800186 if (inLoad) {
187 // the titlebar was removed when the CAB was shown
188 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800189 showTitleBar();
Michael Kolb376b5412010-12-15 11:52:57 -0800190 }
191 }
192
193 @Override
Michael Kolb5a72f182011-01-13 20:35:06 -0800194 protected void updateNavigationState(Tab tab) {
John Reck0f602f32011-07-07 15:38:43 -0700195 mNavBar.updateNavigationState(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800196 }
197
198 @Override
John Reck30c714c2010-12-16 17:30:34 -0800199 public void setUrlTitle(Tab tab) {
200 super.setUrlTitle(tab);
201 mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle());
Michael Kolb66706532010-12-12 19:50:22 -0800202 }
203
204 // Set the favicon in the title bar.
205 @Override
John Reck30c714c2010-12-16 17:30:34 -0800206 public void setFavicon(Tab tab) {
207 super.setFavicon(tab);
208 mTabBar.onFavicon(tab, tab.getFavicon());
Michael Kolb66706532010-12-12 19:50:22 -0800209 }
210
Michael Kolbcfa3af52010-12-14 10:36:11 -0800211 @Override
John Reckd73c5a22010-12-22 10:22:50 -0800212 public void onHideCustomView() {
213 super.onHideCustomView();
Michael Kolbda580632012-04-16 13:30:28 -0700214 checkHideActionBar();
John Reckd73c5a22010-12-22 10:22:50 -0800215 }
Michael Kolba4183062011-01-16 10:43:21 -0800216
217 @Override
218 public boolean dispatchKey(int code, KeyEvent event) {
Michael Kolbdfe99a12011-03-08 11:45:40 -0800219 if (mActiveTab != null) {
220 WebView web = mActiveTab.getWebView();
221 if (event.getAction() == KeyEvent.ACTION_DOWN) {
222 switch (code) {
223 case KeyEvent.KEYCODE_TAB:
224 case KeyEvent.KEYCODE_DPAD_UP:
225 case KeyEvent.KEYCODE_DPAD_LEFT:
226 if ((web != null) && web.hasFocus() && !mTitleBar.hasFocus()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700227 editUrl(false, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800228 return true;
229 }
230 }
231 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
232 if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700233 editUrl(true, false);
Michael Kolbdfe99a12011-03-08 11:45:40 -0800234 return mContentView.dispatchKeyEvent(event);
235 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800236 }
Michael Kolba4183062011-01-16 10:43:21 -0800237 }
238 return false;
239 }
240
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800241 private boolean isTypingKey(KeyEvent evt) {
242 return evt.getUnicodeChar() > 0;
243 }
244
245 TabBar getTabBar() {
246 return mTabBar;
247 }
248
John Reck1cf4b792011-07-26 10:22:22 -0700249 @Override
250 public boolean shouldCaptureThumbnails() {
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700251 return false;
John Reck1cf4b792011-07-26 10:22:22 -0700252 }
253
John Reck034637c2011-08-11 11:34:44 -0700254 private Drawable getFaviconBackground() {
255 if (mFaviconBackground == null) {
256 mFaviconBackground = new PaintDrawable();
257 Resources res = mActivity.getResources();
258 mFaviconBackground.getPaint().setColor(
259 res.getColor(R.color.tabFaviconBackground));
260 mFaviconBackground.setCornerRadius(
261 res.getDimension(R.dimen.tab_favicon_corner_radius));
262 }
263 return mFaviconBackground;
264 }
265
266 @Override
267 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800268 if (ENABLE_BORDER_AROUND_FAVICON) {
269 Drawable[] array = new Drawable[2];
270 array[0] = getFaviconBackground();
271 if (icon == null) {
272 array[1] = getGenericFavicon();
273 } else {
274 array[1] = new BitmapDrawable(mActivity.getResources(), icon);
275 }
276 LayerDrawable d = new LayerDrawable(array);
277 d.setLayerInset(1, 2, 2, 2, 2);
278 return d;
John Reck034637c2011-08-11 11:34:44 -0700279 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800280 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
John Reck034637c2011-08-11 11:34:44 -0700281 }
282
Michael Kolb66706532010-12-12 19:50:22 -0800283}