Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 1 | /* |
| 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 Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 18 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 19 | import android.app.ActionBar; |
| 20 | import android.app.Activity; |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 21 | import android.content.res.Resources; |
| 22 | import android.graphics.Bitmap; |
| 23 | import android.graphics.drawable.BitmapDrawable; |
| 24 | import android.graphics.drawable.Drawable; |
| 25 | import android.graphics.drawable.LayerDrawable; |
| 26 | import android.graphics.drawable.PaintDrawable; |
Michael Kolb | ac35bdc | 2011-01-17 17:06:04 -0800 | [diff] [blame] | 27 | import android.os.Bundle; |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 28 | import android.os.Handler; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 30 | import android.view.ActionMode; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 31 | import android.view.KeyEvent; |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 32 | import android.view.Menu; |
| 33 | import android.view.MenuItem; |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame^] | 34 | import android.view.View; |
| 35 | import android.webkit.WebChromeClient; |
| 36 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 37 | import org.codeaurora.swe.WebView; |
| 38 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 39 | import com.android.browser.R; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 40 | |
| 41 | import java.util.List; |
| 42 | |
| 43 | /** |
| 44 | * Ui for xlarge screen sizes |
| 45 | */ |
Michael Kolb | b14ff2f | 2011-07-01 15:33:56 -0700 | [diff] [blame] | 46 | public class XLargeUi extends BaseUi { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 47 | |
| 48 | private static final String LOGTAG = "XLargeUi"; |
| 49 | |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 50 | private PaintDrawable mFaviconBackground; |
| 51 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 52 | private ActionBar mActionBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 53 | private TabBar mTabBar; |
| 54 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 55 | private NavigationBarTablet mNavBar; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 56 | |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 57 | private Handler mHandler; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 58 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 59 | /** |
| 60 | * @param browser |
| 61 | * @param controller |
| 62 | */ |
| 63 | public XLargeUi(Activity browser, UiController controller) { |
| 64 | super(browser, controller); |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 65 | mHandler = new Handler(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 66 | mNavBar = (NavigationBarTablet) mTitleBar.getNavigationBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 67 | mTabBar = new TabBar(mActivity, mUiController, this); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 68 | mActionBar = mActivity.getActionBar(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 69 | setupActionBar(); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private void setupActionBar() { |
| 73 | mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 74 | mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); |
| 75 | mActionBar.setCustomView(mTabBar); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 76 | } |
| 77 | |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 78 | public void showComboView(ComboViews startWith, Bundle extras) { |
| 79 | super.showComboView(startWith, extras); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 82 | private void checkHideActionBar() { |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 86 | public void onResume() { |
| 87 | super.onResume(); |
Narayan Kamath | f3174a5 | 2011-11-17 14:43:32 +0000 | [diff] [blame] | 88 | mNavBar.clearCompletions(); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 89 | checkHideActionBar(); |
Narayan Kamath | 67b8c1b | 2011-03-09 20:47:52 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 93 | public void onDestroy() { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 94 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 97 | void stopWebViewScrolling() { |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 98 | BrowserWebView web = (BrowserWebView) mUiController.getCurrentWebView(); |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 99 | if (web != null) { |
| 100 | web.stopScroll(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 104 | @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 Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 110 | |
| 111 | menu.setGroupVisible(R.id.NAV_MENU, false); |
| 112 | |
Michael Kolb | 0d0245f | 2011-12-05 16:36:05 -0800 | [diff] [blame] | 113 | return true; |
| 114 | } |
| 115 | |
| 116 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 117 | // WebView callbacks |
| 118 | |
| 119 | @Override |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 120 | public void addTab(Tab tab) { |
| 121 | mTabBar.onNewTab(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | protected void onAddTabCompleted(Tab tab) { |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 125 | checkHideActionBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 129 | public void setActiveTab(final Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 130 | mTitleBar.cancelTitleBarAnimation(true); |
| 131 | mTitleBar.setSkipTitleBarAnimations(true); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 132 | super.setActiveTab(tab); |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 133 | BrowserWebView view = (BrowserWebView) tab.getWebView(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 134 | // 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 Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 140 | mTabBar.onSetActiveTab(tab); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 141 | updateLockIconToLatest(tab); |
John Reck | 5d43ce8 | 2011-06-21 17:16:51 -0700 | [diff] [blame] | 142 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void updateTabs(List<Tab> tabs) { |
| 147 | mTabBar.updateTabs(tabs); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 148 | checkHideActionBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public void removeTab(Tab tab) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 153 | mTitleBar.cancelTitleBarAnimation(true); |
| 154 | mTitleBar.setSkipTitleBarAnimations(true); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 155 | super.removeTab(tab); |
| 156 | mTabBar.onRemoveTab(tab); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 157 | mTitleBar.setSkipTitleBarAnimations(false); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame^] | 160 | @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 Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 168 | protected void onRemoveTabCompleted(Tab tab) { |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 169 | checkHideActionBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 172 | int getContentWidth() { |
| 173 | if (mContentView != null) { |
| 174 | return mContentView.getWidth(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 175 | } |
| 176 | return 0; |
| 177 | } |
| 178 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 179 | @Override |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 180 | public void editUrl(boolean clearInput, boolean forceIME) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 181 | super.editUrl(clearInput, forceIME); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 184 | // action mode callbacks |
| 185 | |
| 186 | @Override |
| 187 | public void onActionModeStarted(ActionMode mode) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 188 | if (!mTitleBar.isEditingUrl()) { |
Michael Kolb | b2e91fd | 2011-07-14 13:47:29 -0700 | [diff] [blame] | 189 | // hide the title bar when CAB is shown |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 190 | hideTitleBar(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
| 194 | @Override |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 195 | public void onActionModeFinished(boolean inLoad) { |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 196 | checkHideActionBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 197 | if (inLoad) { |
| 198 | // the titlebar was removed when the CAB was shown |
| 199 | // if the page is loading, show it again |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 200 | showTitleBar(); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | @Override |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 205 | protected void updateNavigationState(Tab tab) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 206 | mNavBar.updateNavigationState(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 210 | public void setUrlTitle(Tab tab) { |
| 211 | super.setUrlTitle(tab); |
| 212 | mTabBar.onUrlAndTitle(tab, tab.getUrl(), tab.getTitle()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // Set the favicon in the title bar. |
| 216 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 217 | public void setFavicon(Tab tab) { |
| 218 | super.setFavicon(tab); |
| 219 | mTabBar.onFavicon(tab, tab.getFavicon()); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 222 | @Override |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 223 | public void onHideCustomView() { |
| 224 | super.onHideCustomView(); |
Michael Kolb | da58063 | 2012-04-16 13:30:28 -0700 | [diff] [blame] | 225 | checkHideActionBar(); |
Pankaj Garg | 16053b4 | 2014-12-17 15:23:01 -0800 | [diff] [blame^] | 226 | if (mActionBar != null) |
| 227 | mActionBar.show(); |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 228 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 229 | |
| 230 | @Override |
| 231 | public boolean dispatchKey(int code, KeyEvent event) { |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 232 | 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 Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 240 | editUrl(false, false); |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 241 | return true; |
| 242 | } |
| 243 | } |
| 244 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 245 | if (!ctrl && isTypingKey(event) && !mTitleBar.isEditingUrl()) { |
Michael Kolb | 1f9b356 | 2012-04-24 14:38:34 -0700 | [diff] [blame] | 246 | editUrl(true, false); |
Michael Kolb | dfe99a1 | 2011-03-08 11:45:40 -0800 | [diff] [blame] | 247 | return mContentView.dispatchKeyEvent(event); |
| 248 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 249 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 250 | } |
| 251 | return false; |
| 252 | } |
| 253 | |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 254 | private boolean isTypingKey(KeyEvent evt) { |
| 255 | return evt.getUnicodeChar() > 0; |
| 256 | } |
| 257 | |
| 258 | TabBar getTabBar() { |
| 259 | return mTabBar; |
| 260 | } |
| 261 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 262 | @Override |
| 263 | public boolean shouldCaptureThumbnails() { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 264 | return false; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 265 | } |
| 266 | |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 267 | 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 Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 281 | 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 Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 292 | } |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 293 | return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon); |
John Reck | 034637c | 2011-08-11 11:34:44 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 296 | } |