Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [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 | |
| 17 | package com.android.browser; |
| 18 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 19 | import com.android.browser.Tab.LockIcon; |
Michael Kolb | fedb492 | 2011-04-20 16:45:33 -0700 | [diff] [blame] | 20 | import com.android.internal.view.menu.MenuBuilder; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 21 | |
John Reck | 74830e1 | 2011-03-14 11:43:05 -0700 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 23 | import android.app.Activity; |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 25 | import android.content.res.Configuration; |
| 26 | import android.content.res.Resources; |
| 27 | import android.graphics.Bitmap; |
| 28 | import android.graphics.BitmapFactory; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 29 | import android.graphics.Color; |
| 30 | import android.graphics.drawable.BitmapDrawable; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 32 | import android.graphics.drawable.LayerDrawable; |
| 33 | import android.graphics.drawable.PaintDrawable; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
| 35 | import android.text.TextUtils; |
| 36 | import android.util.Log; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 37 | import android.view.Gravity; |
| 38 | import android.view.LayoutInflater; |
| 39 | import android.view.Menu; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 40 | import android.view.View; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 41 | import android.view.View.OnClickListener; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 42 | import android.view.ViewGroup; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 43 | import android.view.ViewGroup.LayoutParams; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 44 | import android.view.WindowManager; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 45 | import android.view.inputmethod.InputMethodManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 46 | import android.webkit.WebChromeClient; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 47 | import android.webkit.WebView; |
| 48 | import android.widget.FrameLayout; |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 49 | import android.widget.ImageButton; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 50 | import android.widget.LinearLayout; |
| 51 | import android.widget.Toast; |
| 52 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 53 | import java.util.List; |
| 54 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 55 | /** |
| 56 | * UI interface definitions |
| 57 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 58 | public abstract class BaseUi implements UI, WebViewFactory { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 59 | |
| 60 | private static final String LOGTAG = "BaseUi"; |
| 61 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 62 | protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 63 | new FrameLayout.LayoutParams( |
| 64 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 65 | ViewGroup.LayoutParams.MATCH_PARENT); |
| 66 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 67 | protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 68 | new FrameLayout.LayoutParams( |
| 69 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 70 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 71 | Gravity.CENTER); |
| 72 | |
| 73 | Activity mActivity; |
| 74 | UiController mUiController; |
| 75 | TabControl mTabControl; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 76 | protected Tab mActiveTab; |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 77 | private InputMethodManager mInputManager; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 78 | |
| 79 | private Drawable mSecLockIcon; |
| 80 | private Drawable mMixLockIcon; |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 81 | protected Drawable mGenericFavicon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 82 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 83 | private FrameLayout mBrowserFrameLayout; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 84 | protected FrameLayout mContentView; |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 85 | protected FrameLayout mCustomViewContainer; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 86 | |
| 87 | private View mCustomView; |
| 88 | private WebChromeClient.CustomViewCallback mCustomViewCallback; |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame^] | 89 | private int mOriginalOrientation; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 90 | |
| 91 | private CombinedBookmarkHistoryView mComboView; |
| 92 | |
| 93 | private LinearLayout mErrorConsoleContainer = null; |
| 94 | |
| 95 | private Toast mStopToast; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 96 | |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 97 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 98 | // the default <video> poster |
| 99 | private Bitmap mDefaultVideoPoster; |
| 100 | // the video progress view |
| 101 | private View mVideoProgressView; |
| 102 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 103 | private boolean mActivityPaused; |
| 104 | |
| 105 | public BaseUi(Activity browser, UiController controller) { |
| 106 | mActivity = browser; |
| 107 | mUiController = controller; |
| 108 | mTabControl = controller.getTabControl(); |
| 109 | Resources res = mActivity.getResources(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 110 | mInputManager = (InputMethodManager) |
| 111 | browser.getSystemService(Activity.INPUT_METHOD_SERVICE); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 112 | mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 113 | mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure); |
| 114 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 115 | FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() |
| 116 | .getDecorView().findViewById(android.R.id.content); |
| 117 | mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity) |
| 118 | .inflate(R.layout.custom_screen, null); |
| 119 | mContentView = (FrameLayout) mBrowserFrameLayout.findViewById( |
| 120 | R.id.main_content); |
| 121 | mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout |
| 122 | .findViewById(R.id.error_console); |
| 123 | mCustomViewContainer = (FrameLayout) mBrowserFrameLayout |
| 124 | .findViewById(R.id.fullscreen_custom_content); |
| 125 | frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS); |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 126 | setFullscreen(BrowserSettings.getInstance().useFullscreen()); |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 127 | mGenericFavicon = res.getDrawable( |
| 128 | R.drawable.app_web_browser_sm); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 129 | } |
| 130 | |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 131 | @Override |
| 132 | public WebView createWebView(boolean privateBrowsing) { |
| 133 | // Create a new WebView |
| 134 | BrowserWebView w = new BrowserWebView(mActivity, null, |
| 135 | android.R.attr.webViewStyle, privateBrowsing); |
| 136 | initWebViewSettings(w); |
| 137 | return w; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public WebView createSubWebView(boolean privateBrowsing) { |
| 142 | return createWebView(privateBrowsing); |
| 143 | } |
| 144 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 145 | /** |
| 146 | * common webview initialization |
| 147 | * @param w the webview to initialize |
| 148 | */ |
| 149 | protected void initWebViewSettings(WebView w) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 150 | w.setScrollbarFadingEnabled(true); |
| 151 | w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); |
| 152 | w.setMapTrackballToArrowKeys(false); // use trackball directly |
| 153 | // Enable the built-in zoom |
| 154 | w.getSettings().setBuiltInZoomControls(true); |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 155 | boolean supportsMultiTouch = mActivity.getPackageManager() |
| 156 | .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH); |
| 157 | w.getSettings().setDisplayZoomControls(!supportsMultiTouch); |
| 158 | w.setExpandedTileBounds(true); // smoother scrolling |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 159 | |
| 160 | // Add this WebView to the settings observer list and update the |
| 161 | // settings |
| 162 | final BrowserSettings s = BrowserSettings.getInstance(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 163 | s.startManagingSettings(w.getSettings()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | private void cancelStopToast() { |
| 167 | if (mStopToast != null) { |
| 168 | mStopToast.cancel(); |
| 169 | mStopToast = null; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // lifecycle |
| 174 | |
| 175 | public void onPause() { |
Michael Kolb | 7a5cf47 | 2010-11-30 13:23:53 -0800 | [diff] [blame] | 176 | if (isCustomViewShowing()) { |
| 177 | onHideCustomView(); |
| 178 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 179 | cancelStopToast(); |
| 180 | mActivityPaused = true; |
| 181 | } |
| 182 | |
| 183 | public void onResume() { |
| 184 | mActivityPaused = false; |
| 185 | } |
| 186 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 187 | protected boolean isActivityPaused() { |
| 188 | return mActivityPaused; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | public void onConfigurationChanged(Configuration config) { |
| 192 | } |
| 193 | |
| 194 | // key handling |
| 195 | |
| 196 | @Override |
| 197 | public boolean onBackKey() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 198 | if (mComboView != null) { |
| 199 | if (!mComboView.onBackPressed()) { |
| 200 | mUiController.removeComboView(); |
| 201 | } |
| 202 | return true; |
| 203 | } |
| 204 | if (mCustomView != null) { |
| 205 | mUiController.hideCustomView(); |
| 206 | return true; |
| 207 | } |
| 208 | return false; |
| 209 | } |
| 210 | |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 211 | @Override |
| 212 | public boolean onMenuKey() { |
| 213 | return false; |
| 214 | } |
| 215 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 216 | // Tab callbacks |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 217 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 218 | public void onTabDataChanged(Tab tab) { |
| 219 | setUrlTitle(tab); |
| 220 | setFavicon(tab); |
| 221 | updateLockIconToLatest(tab); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 222 | updateNavigationState(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | @Override |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 226 | public void bookmarkedStatusHasChanged(Tab tab) { |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 227 | if (tab.inForeground()) { |
| 228 | boolean isBookmark = tab.isBookmarkedSite(); |
| 229 | getTitleBar().setCurrentUrlIsBookmark(isBookmark); |
| 230 | } |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 234 | public void onPageStopped(Tab tab) { |
| 235 | cancelStopToast(); |
| 236 | if (tab.inForeground()) { |
| 237 | mStopToast = Toast |
| 238 | .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); |
| 239 | mStopToast.show(); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 244 | public boolean needsRestoreAllTabs() { |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 245 | return true; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 249 | public void addTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Override |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 253 | public void setActiveTab(final Tab tab) { |
| 254 | setActiveTab(tab, true); |
| 255 | } |
| 256 | |
| 257 | void setActiveTab(Tab tab, boolean needsAttaching) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 258 | if ((tab != mActiveTab) && (mActiveTab != null)) { |
| 259 | removeTabFromContentView(mActiveTab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 260 | } |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 261 | mActiveTab = tab; |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 262 | if (needsAttaching) { |
| 263 | attachTabToContentView(tab); |
| 264 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 265 | setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 266 | onTabDataChanged(tab); |
| 267 | onProgressChanged(tab); |
John Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 268 | boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 269 | getTitleBar().setIncognitoMode(incognito); |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 270 | updateAutoLogin(tab, false); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 273 | Tab getActiveTab() { |
| 274 | return mActiveTab; |
| 275 | } |
| 276 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 277 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 278 | public void updateTabs(List<Tab> tabs) { |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 282 | public void removeTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 283 | if (mActiveTab == tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 284 | removeTabFromContentView(tab); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 285 | mActiveTab = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 286 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public void detachTab(Tab tab) { |
| 291 | removeTabFromContentView(tab); |
| 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public void attachTab(Tab tab) { |
| 296 | attachTabToContentView(tab); |
| 297 | } |
| 298 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 299 | protected void attachTabToContentView(Tab tab) { |
Michael Kolb | d1e2ccc | 2011-01-24 11:38:31 -0800 | [diff] [blame] | 300 | if ((tab == null) || (tab.getWebView() == null)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 301 | return; |
| 302 | } |
| 303 | View container = tab.getViewContainer(); |
| 304 | WebView mainView = tab.getWebView(); |
| 305 | // Attach the WebView to the container and then attach the |
| 306 | // container to the content view. |
| 307 | FrameLayout wrapper = |
| 308 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 309 | ViewGroup parent = (ViewGroup) mainView.getParent(); |
| 310 | if (parent != wrapper) { |
| 311 | if (parent != null) { |
| 312 | Log.w(LOGTAG, "mMainView already has a parent in" |
| 313 | + " attachTabToContentView!"); |
| 314 | parent.removeView(mainView); |
| 315 | } |
| 316 | wrapper.addView(mainView); |
| 317 | } else { |
| 318 | Log.w(LOGTAG, "mMainView is already attached to wrapper in" |
| 319 | + " attachTabToContentView!"); |
| 320 | } |
| 321 | parent = (ViewGroup) container.getParent(); |
| 322 | if (parent != mContentView) { |
| 323 | if (parent != null) { |
| 324 | Log.w(LOGTAG, "mContainer already has a parent in" |
| 325 | + " attachTabToContentView!"); |
| 326 | parent.removeView(container); |
| 327 | } |
| 328 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 329 | } else { |
| 330 | Log.w(LOGTAG, "mContainer is already attached to content in" |
| 331 | + " attachTabToContentView!"); |
| 332 | } |
| 333 | mUiController.attachSubWindow(tab); |
| 334 | } |
| 335 | |
| 336 | private void removeTabFromContentView(Tab tab) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 337 | hideTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 338 | // Remove the container that contains the main WebView. |
| 339 | WebView mainView = tab.getWebView(); |
| 340 | View container = tab.getViewContainer(); |
| 341 | if (mainView == null) { |
| 342 | return; |
| 343 | } |
| 344 | // Remove the container from the content and then remove the |
| 345 | // WebView from the container. This will trigger a focus change |
| 346 | // needed by WebView. |
Michael Kolb | 20776cc | 2011-01-31 10:19:05 -0800 | [diff] [blame] | 347 | mainView.setEmbeddedTitleBar(null); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 348 | FrameLayout wrapper = |
| 349 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 350 | wrapper.removeView(mainView); |
| 351 | mContentView.removeView(container); |
| 352 | mUiController.endActionMode(); |
| 353 | mUiController.removeSubWindow(tab); |
| 354 | ErrorConsoleView errorConsole = tab.getErrorConsole(false); |
| 355 | if (errorConsole != null) { |
| 356 | mErrorConsoleContainer.removeView(errorConsole); |
| 357 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 360 | @Override |
| 361 | public void onSetWebView(Tab tab, WebView webView) { |
| 362 | View container = tab.getViewContainer(); |
| 363 | if (container == null) { |
| 364 | // The tab consists of a container view, which contains the main |
| 365 | // WebView, as well as any other UI elements associated with the tab. |
| 366 | container = mActivity.getLayoutInflater().inflate(R.layout.tab, |
| 367 | null); |
| 368 | tab.setViewContainer(container); |
| 369 | } |
| 370 | if (tab.getWebView() != webView) { |
| 371 | // Just remove the old one. |
| 372 | FrameLayout wrapper = |
| 373 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 374 | wrapper.removeView(tab.getWebView()); |
| 375 | } |
| 376 | } |
| 377 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 378 | /** |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 379 | * create a sub window container and webview for the tab |
| 380 | * Note: this methods operates through side-effects for now |
| 381 | * it sets both the subView and subViewContainer for the given tab |
| 382 | * @param tab tab to create the sub window for |
| 383 | * @param subView webview to be set as a subwindow for the tab |
| 384 | */ |
| 385 | @Override |
| 386 | public void createSubWindow(Tab tab, WebView subView) { |
| 387 | View subViewContainer = mActivity.getLayoutInflater().inflate( |
| 388 | R.layout.browser_subwindow, null); |
| 389 | ViewGroup inner = (ViewGroup) subViewContainer |
| 390 | .findViewById(R.id.inner_container); |
| 391 | inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, |
| 392 | LayoutParams.MATCH_PARENT)); |
| 393 | final ImageButton cancel = (ImageButton) subViewContainer |
| 394 | .findViewById(R.id.subwindow_close); |
| 395 | final WebView cancelSubView = subView; |
| 396 | cancel.setOnClickListener(new OnClickListener() { |
| 397 | public void onClick(View v) { |
| 398 | cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView); |
| 399 | } |
| 400 | }); |
| 401 | tab.setSubWebView(subView); |
| 402 | tab.setSubViewContainer(subViewContainer); |
| 403 | } |
| 404 | |
| 405 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 406 | * Remove the sub window from the content view. |
| 407 | */ |
| 408 | @Override |
| 409 | public void removeSubWindow(View subviewContainer) { |
| 410 | mContentView.removeView(subviewContainer); |
| 411 | mUiController.endActionMode(); |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Attach the sub window to the content view. |
| 416 | */ |
| 417 | @Override |
| 418 | public void attachSubWindow(View container) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 419 | if (container.getParent() != null) { |
| 420 | // already attached, remove first |
| 421 | ((ViewGroup) container.getParent()).removeView(container); |
| 422 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 423 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 424 | } |
| 425 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 426 | protected void refreshWebView() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 427 | WebView web = getWebView(); |
| 428 | if (web != null) { |
| 429 | web.invalidate(); |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 433 | public void editUrl(boolean clearInput) { |
| 434 | if (mUiController.isInCustomActionMode()) { |
| 435 | mUiController.endActionMode(); |
| 436 | } |
| 437 | showTitleBar(); |
| 438 | getTitleBar().startEditingUrl(clearInput); |
| 439 | } |
| 440 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 441 | boolean canShowTitleBar() { |
| 442 | return !isTitleBarShowing() |
| 443 | && !isActivityPaused() |
| 444 | && (getActiveTab() != null) |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 445 | && (getWebView() != null) |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 446 | && !mUiController.isInCustomActionMode(); |
| 447 | } |
| 448 | |
| 449 | void showTitleBar() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 450 | if (canShowTitleBar()) { |
| 451 | getTitleBar().show(); |
| 452 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | protected void hideTitleBar() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 456 | if (getTitleBar().isShowing()) { |
| 457 | getTitleBar().hide(); |
| 458 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | protected boolean isTitleBarShowing() { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 462 | return getTitleBar().isShowing(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | protected abstract TitleBarBase getTitleBar(); |
| 466 | |
| 467 | protected void setTitleGravity(int gravity) { |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 468 | WebView web = getWebView(); |
| 469 | if (web != null) { |
| 470 | web.setTitleBarGravity(gravity); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 474 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 475 | public void showVoiceTitleBar(String title, List<String> results) { |
| 476 | getTitleBar().setInVoiceMode(true, results); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 477 | getTitleBar().setDisplayTitle(title); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 480 | @Override |
| 481 | public void revertVoiceTitleBar(Tab tab) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 482 | getTitleBar().setInVoiceMode(false, null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 483 | String url = tab.getUrl(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 484 | getTitleBar().setDisplayTitle(url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 488 | public void registerDropdownChangeListener(DropdownChangeListener d) { |
| 489 | getTitleBar().registerDropdownChangeListener(d); |
| 490 | } |
| 491 | |
| 492 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 493 | public void showComboView(boolean startWithHistory, Bundle extras) { |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 494 | if (mComboView != null) { |
| 495 | return; |
| 496 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 497 | mComboView = new CombinedBookmarkHistoryView(mActivity, |
| 498 | mUiController, |
| 499 | startWithHistory ? |
| 500 | CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY |
| 501 | : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS, |
| 502 | extras); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 503 | FrameLayout wrapper = |
| 504 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 505 | wrapper.setVisibility(View.GONE); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 506 | getTitleBar().stopEditingUrl(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 507 | dismissIME(); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 508 | hideTitleBar(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 509 | if (mActiveTab != null) { |
| 510 | WebView web = mActiveTab.getWebView(); |
| 511 | mActiveTab.putInBackground(); |
| 512 | } |
John Reck | 74830e1 | 2011-03-14 11:43:05 -0700 | [diff] [blame] | 513 | mComboView.setAlpha(0f); |
| 514 | ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f); |
| 515 | Resources res = mActivity.getResources(); |
| 516 | anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration)); |
| 517 | anim.start(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 518 | mContentView.addView(mComboView, COVER_SCREEN_PARAMS); |
| 519 | } |
| 520 | |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 521 | public boolean isComboViewShowing() { |
| 522 | return (mComboView != null); |
| 523 | } |
| 524 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 525 | /** |
| 526 | * dismiss the ComboPage |
| 527 | */ |
| 528 | @Override |
| 529 | public void hideComboView() { |
| 530 | if (mComboView != null) { |
| 531 | mContentView.removeView(mComboView); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 532 | FrameLayout wrapper = |
| 533 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 534 | wrapper.setVisibility(View.VISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 535 | mComboView = null; |
| 536 | } |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 537 | if (mActiveTab != null) { |
| 538 | mActiveTab.putInForeground(); |
| 539 | } |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 540 | mActivity.invalidateOptionsMenu(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | @Override |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame^] | 544 | public void showCustomView(View view, int requestedOrientation, |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 545 | WebChromeClient.CustomViewCallback callback) { |
| 546 | // if a view already exists then immediately terminate the new one |
| 547 | if (mCustomView != null) { |
| 548 | callback.onCustomViewHidden(); |
| 549 | return; |
| 550 | } |
| 551 | |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame^] | 552 | mOriginalOrientation = mActivity.getRequestedOrientation(); |
| 553 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 554 | // Add the custom view to its container. |
| 555 | mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); |
| 556 | mCustomView = view; |
| 557 | mCustomViewCallback = callback; |
| 558 | // Hide the content view. |
| 559 | mContentView.setVisibility(View.GONE); |
| 560 | // Finally show the custom view container. |
| 561 | setStatusBarVisibility(false); |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame^] | 562 | mActivity.setRequestedOrientation(requestedOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 563 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 564 | mCustomViewContainer.bringToFront(); |
| 565 | } |
| 566 | |
| 567 | @Override |
| 568 | public void onHideCustomView() { |
| 569 | if (mCustomView == null) |
| 570 | return; |
| 571 | |
| 572 | // Hide the custom view. |
| 573 | mCustomView.setVisibility(View.GONE); |
| 574 | // Remove the custom view from its container. |
| 575 | mCustomViewContainer.removeView(mCustomView); |
| 576 | mCustomView = null; |
| 577 | mCustomViewContainer.setVisibility(View.GONE); |
| 578 | mCustomViewCallback.onCustomViewHidden(); |
| 579 | // Show the content view. |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame^] | 580 | mActivity.setRequestedOrientation(mOriginalOrientation); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 581 | setStatusBarVisibility(true); |
| 582 | mContentView.setVisibility(View.VISIBLE); |
| 583 | } |
| 584 | |
| 585 | @Override |
| 586 | public boolean isCustomViewShowing() { |
| 587 | return mCustomView != null; |
| 588 | } |
| 589 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 590 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 591 | if (mInputManager.isActive()) { |
| 592 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 593 | 0); |
| 594 | } |
| 595 | } |
| 596 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 597 | @Override |
| 598 | public boolean showsWeb() { |
| 599 | return mCustomView == null |
| 600 | && mComboView == null; |
| 601 | } |
| 602 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 603 | @Override |
| 604 | public void showAutoLogin(Tab tab) { |
| 605 | updateAutoLogin(tab, true); |
| 606 | } |
| 607 | |
| 608 | @Override |
| 609 | public void hideAutoLogin(Tab tab) { |
| 610 | updateAutoLogin(tab, true); |
| 611 | } |
| 612 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 613 | // ------------------------------------------------------------------------- |
| 614 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 615 | protected void updateNavigationState(Tab tab) { |
| 616 | } |
| 617 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 618 | protected void updateAutoLogin(Tab tab, boolean animate) { |
| 619 | getTitleBar().updateAutoLogin(tab, animate); |
| 620 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 621 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 622 | /** |
| 623 | * Update the lock icon to correspond to our latest state. |
| 624 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 625 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 626 | if (t != null && t.inForeground()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 627 | updateLockIconImage(t.getLockIconType()); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 632 | * Updates the lock-icon image in the title-bar. |
| 633 | */ |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 634 | private void updateLockIconImage(LockIcon lockIconType) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 635 | Drawable d = null; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 636 | if (lockIconType == LockIcon.LOCK_ICON_SECURE) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 637 | d = mSecLockIcon; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 638 | } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 639 | d = mMixLockIcon; |
| 640 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 641 | getTitleBar().setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 642 | } |
| 643 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 644 | protected void setUrlTitle(Tab tab) { |
| 645 | String url = tab.getUrl(); |
| 646 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 647 | if (TextUtils.isEmpty(title)) { |
| 648 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 649 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 650 | if (tab.isInVoiceSearchMode()) return; |
| 651 | if (tab.inForeground()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 652 | getTitleBar().setDisplayTitle(url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
| 656 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 657 | protected void setFavicon(Tab tab) { |
| 658 | if (tab.inForeground()) { |
| 659 | Bitmap icon = tab.getFavicon(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 660 | getTitleBar().setFavicon(icon); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 661 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public void onActionModeFinished(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 668 | // active tabs page |
| 669 | |
| 670 | public void showActiveTabsPage() { |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Remove the active tabs page. |
| 675 | */ |
| 676 | public void removeActiveTabsPage() { |
| 677 | } |
| 678 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 679 | // menu handling callbacks |
| 680 | |
| 681 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 682 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 683 | return true; |
| 684 | } |
| 685 | |
| 686 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 687 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | @Override |
| 691 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | @Override |
| 699 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | @Override |
| 703 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | @Override |
| 707 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | // error console |
| 711 | |
| 712 | @Override |
| 713 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
Michael Kolb | 9fcefd1 | 2011-02-17 10:55:59 -0800 | [diff] [blame] | 714 | if (tab == null) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 715 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 716 | if (flag) { |
| 717 | // Setting the show state of the console will cause it's the layout |
| 718 | // to be inflated. |
| 719 | if (errorConsole.numberOfErrors() > 0) { |
| 720 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 721 | } else { |
| 722 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 723 | } |
| 724 | if (errorConsole.getParent() != null) { |
| 725 | mErrorConsoleContainer.removeView(errorConsole); |
| 726 | } |
| 727 | // Now we can add it to the main view. |
| 728 | mErrorConsoleContainer.addView(errorConsole, |
| 729 | new LinearLayout.LayoutParams( |
| 730 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 731 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 732 | } else { |
| 733 | mErrorConsoleContainer.removeView(errorConsole); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | private void setStatusBarVisibility(boolean visible) { |
Joe Onorato | d3bf86f | 2011-01-25 20:07:10 -0800 | [diff] [blame] | 738 | WindowManager.LayoutParams params = mActivity.getWindow().getAttributes(); |
| 739 | params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN; |
| 740 | mActivity.getWindow().setAttributes(params); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 743 | // ------------------------------------------------------------------------- |
| 744 | // Helper function for WebChromeClient |
| 745 | // ------------------------------------------------------------------------- |
| 746 | |
| 747 | @Override |
| 748 | public Bitmap getDefaultVideoPoster() { |
| 749 | if (mDefaultVideoPoster == null) { |
| 750 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 751 | mActivity.getResources(), R.drawable.default_video_poster); |
| 752 | } |
| 753 | return mDefaultVideoPoster; |
| 754 | } |
| 755 | |
| 756 | @Override |
| 757 | public View getVideoLoadingProgressView() { |
| 758 | if (mVideoProgressView == null) { |
| 759 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 760 | mVideoProgressView = inflater.inflate( |
| 761 | R.layout.video_loading_progress, null); |
| 762 | } |
| 763 | return mVideoProgressView; |
| 764 | } |
| 765 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 766 | @Override |
| 767 | public void showMaxTabsWarning() { |
| 768 | Toast warning = Toast.makeText(mActivity, |
| 769 | mActivity.getString(R.string.max_tabs_warning), |
| 770 | Toast.LENGTH_SHORT); |
| 771 | warning.show(); |
| 772 | } |
| 773 | |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 774 | protected void captureTab(final Tab tab) { |
| 775 | captureTab(tab, |
| 776 | (int) mActivity.getResources() |
| 777 | .getDimension(R.dimen.qc_thumb_width), |
| 778 | (int) mActivity.getResources() |
| 779 | .getDimension(R.dimen.qc_thumb_height)); |
| 780 | } |
| 781 | |
| 782 | protected void captureTab(final Tab tab, int width, int height) { |
| 783 | if ((tab == null) || (tab.getWebView() == null)) return; |
| 784 | Bitmap sshot = Controller.createScreenshot(tab, width, height); |
| 785 | tab.setScreenshot(sshot); |
| 786 | } |
| 787 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 788 | protected WebView getWebView() { |
| 789 | if (mActiveTab != null) { |
| 790 | return mActiveTab.getWebView(); |
| 791 | } else { |
| 792 | return null; |
| 793 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Michael Kolb | fedb492 | 2011-04-20 16:45:33 -0700 | [diff] [blame] | 796 | protected Menu getMenu() { |
| 797 | MenuBuilder menu = new MenuBuilder(mActivity); |
| 798 | mActivity.getMenuInflater().inflate(R.menu.browser, menu); |
| 799 | return menu; |
| 800 | } |
| 801 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 802 | public void setFullscreen(boolean enabled) { |
| 803 | if (enabled) { |
| 804 | mActivity.getWindow().setFlags( |
| 805 | WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| 806 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 807 | } else { |
| 808 | mActivity.getWindow().clearFlags( |
| 809 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 810 | } |
| 811 | } |
| 812 | |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame] | 813 | protected Drawable getFaviconDrawable(Bitmap icon) { |
| 814 | Drawable[] array = new Drawable[3]; |
| 815 | array[0] = new PaintDrawable(Color.BLACK); |
| 816 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 817 | array[1] = p; |
| 818 | if (icon == null) { |
| 819 | array[2] = mGenericFavicon; |
| 820 | } else { |
| 821 | array[2] = new BitmapDrawable(icon); |
| 822 | } |
| 823 | LayerDrawable d = new LayerDrawable(array); |
| 824 | d.setLayerInset(1, 1, 1, 1, 1); |
| 825 | d.setLayerInset(2, 2, 2, 2, 2); |
| 826 | return d; |
| 827 | } |
| 828 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 829 | } |