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