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 | d463a72 | 2011-04-08 10:17:49 -0700 | [diff] [blame] | 462 | // update the titlebar layout params |
| 463 | // required to avoid scroll to top when focused |
| 464 | getTitleBar().setTitleGravity(gravity); |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 465 | WebView web = getWebView(); |
| 466 | if (web != null) { |
| 467 | web.setTitleBarGravity(gravity); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 471 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 472 | public void showVoiceTitleBar(String title, List<String> results) { |
| 473 | getTitleBar().setInVoiceMode(true, results); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 474 | getTitleBar().setDisplayTitle(title); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 477 | @Override |
| 478 | public void revertVoiceTitleBar(Tab tab) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 479 | getTitleBar().setInVoiceMode(false, null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 480 | String url = tab.getUrl(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 481 | getTitleBar().setDisplayTitle(url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | @Override |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 485 | public void registerDropdownChangeListener(DropdownChangeListener d) { |
| 486 | getTitleBar().registerDropdownChangeListener(d); |
| 487 | } |
| 488 | |
| 489 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 490 | public void showComboView(boolean startWithHistory, Bundle extras) { |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 491 | if (mComboView != null) { |
| 492 | return; |
| 493 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 494 | mComboView = new CombinedBookmarkHistoryView(mActivity, |
| 495 | mUiController, |
| 496 | startWithHistory ? |
| 497 | CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY |
| 498 | : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS, |
| 499 | extras); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 500 | FrameLayout wrapper = |
| 501 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 502 | wrapper.setVisibility(View.GONE); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 503 | getTitleBar().stopEditingUrl(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 504 | dismissIME(); |
Michael Kolb | c16c595 | 2011-03-29 15:37:03 -0700 | [diff] [blame] | 505 | hideTitleBar(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 506 | if (mActiveTab != null) { |
| 507 | WebView web = mActiveTab.getWebView(); |
| 508 | mActiveTab.putInBackground(); |
| 509 | } |
John Reck | 74830e1 | 2011-03-14 11:43:05 -0700 | [diff] [blame] | 510 | mComboView.setAlpha(0f); |
| 511 | ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f); |
| 512 | Resources res = mActivity.getResources(); |
| 513 | anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration)); |
| 514 | anim.start(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 515 | mContentView.addView(mComboView, COVER_SCREEN_PARAMS); |
| 516 | } |
| 517 | |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 518 | public boolean isComboViewShowing() { |
| 519 | return (mComboView != null); |
| 520 | } |
| 521 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 522 | /** |
| 523 | * dismiss the ComboPage |
| 524 | */ |
| 525 | @Override |
| 526 | public void hideComboView() { |
| 527 | if (mComboView != null) { |
| 528 | mContentView.removeView(mComboView); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 529 | FrameLayout wrapper = |
| 530 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 531 | wrapper.setVisibility(View.VISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 532 | mComboView = null; |
| 533 | } |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 534 | if (mActiveTab != null) { |
| 535 | mActiveTab.putInForeground(); |
| 536 | } |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 537 | mActivity.invalidateOptionsMenu(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | @Override |
| 541 | public void showCustomView(View view, |
| 542 | WebChromeClient.CustomViewCallback callback) { |
| 543 | // if a view already exists then immediately terminate the new one |
| 544 | if (mCustomView != null) { |
| 545 | callback.onCustomViewHidden(); |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | // Add the custom view to its container. |
| 550 | mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); |
| 551 | mCustomView = view; |
| 552 | mCustomViewCallback = callback; |
| 553 | // Hide the content view. |
| 554 | mContentView.setVisibility(View.GONE); |
| 555 | // Finally show the custom view container. |
| 556 | setStatusBarVisibility(false); |
| 557 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 558 | mCustomViewContainer.bringToFront(); |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public void onHideCustomView() { |
| 563 | if (mCustomView == null) |
| 564 | return; |
| 565 | |
| 566 | // Hide the custom view. |
| 567 | mCustomView.setVisibility(View.GONE); |
| 568 | // Remove the custom view from its container. |
| 569 | mCustomViewContainer.removeView(mCustomView); |
| 570 | mCustomView = null; |
| 571 | mCustomViewContainer.setVisibility(View.GONE); |
| 572 | mCustomViewCallback.onCustomViewHidden(); |
| 573 | // Show the content view. |
| 574 | setStatusBarVisibility(true); |
| 575 | mContentView.setVisibility(View.VISIBLE); |
| 576 | } |
| 577 | |
| 578 | @Override |
| 579 | public boolean isCustomViewShowing() { |
| 580 | return mCustomView != null; |
| 581 | } |
| 582 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 583 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 584 | if (mInputManager.isActive()) { |
| 585 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 586 | 0); |
| 587 | } |
| 588 | } |
| 589 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 590 | @Override |
| 591 | public boolean showsWeb() { |
| 592 | return mCustomView == null |
| 593 | && mComboView == null; |
| 594 | } |
| 595 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 596 | @Override |
| 597 | public void showAutoLogin(Tab tab) { |
| 598 | updateAutoLogin(tab, true); |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public void hideAutoLogin(Tab tab) { |
| 603 | updateAutoLogin(tab, true); |
| 604 | } |
| 605 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 606 | // ------------------------------------------------------------------------- |
| 607 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 608 | protected void updateNavigationState(Tab tab) { |
| 609 | } |
| 610 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 611 | protected void updateAutoLogin(Tab tab, boolean animate) { |
| 612 | getTitleBar().updateAutoLogin(tab, animate); |
| 613 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 614 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 615 | /** |
| 616 | * Update the lock icon to correspond to our latest state. |
| 617 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 618 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 619 | if (t != null && t.inForeground()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 620 | updateLockIconImage(t.getLockIconType()); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 625 | * Updates the lock-icon image in the title-bar. |
| 626 | */ |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 627 | private void updateLockIconImage(LockIcon lockIconType) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 628 | Drawable d = null; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 629 | if (lockIconType == LockIcon.LOCK_ICON_SECURE) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 630 | d = mSecLockIcon; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 631 | } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 632 | d = mMixLockIcon; |
| 633 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 634 | getTitleBar().setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 635 | } |
| 636 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 637 | protected void setUrlTitle(Tab tab) { |
| 638 | String url = tab.getUrl(); |
| 639 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 640 | if (TextUtils.isEmpty(title)) { |
| 641 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 642 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 643 | if (tab.isInVoiceSearchMode()) return; |
| 644 | if (tab.inForeground()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 645 | getTitleBar().setDisplayTitle(url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
| 649 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 650 | protected void setFavicon(Tab tab) { |
| 651 | if (tab.inForeground()) { |
| 652 | Bitmap icon = tab.getFavicon(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 653 | getTitleBar().setFavicon(icon); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 654 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | @Override |
| 658 | public void onActionModeFinished(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 661 | // active tabs page |
| 662 | |
| 663 | public void showActiveTabsPage() { |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Remove the active tabs page. |
| 668 | */ |
| 669 | public void removeActiveTabsPage() { |
| 670 | } |
| 671 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 672 | // menu handling callbacks |
| 673 | |
| 674 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 675 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 676 | return true; |
| 677 | } |
| 678 | |
| 679 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 680 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | @Override |
| 684 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | @Override |
| 688 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | @Override |
| 692 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | @Override |
| 696 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | @Override |
| 700 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // error console |
| 704 | |
| 705 | @Override |
| 706 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
Michael Kolb | 9fcefd1 | 2011-02-17 10:55:59 -0800 | [diff] [blame] | 707 | if (tab == null) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 708 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 709 | if (flag) { |
| 710 | // Setting the show state of the console will cause it's the layout |
| 711 | // to be inflated. |
| 712 | if (errorConsole.numberOfErrors() > 0) { |
| 713 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 714 | } else { |
| 715 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 716 | } |
| 717 | if (errorConsole.getParent() != null) { |
| 718 | mErrorConsoleContainer.removeView(errorConsole); |
| 719 | } |
| 720 | // Now we can add it to the main view. |
| 721 | mErrorConsoleContainer.addView(errorConsole, |
| 722 | new LinearLayout.LayoutParams( |
| 723 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 724 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 725 | } else { |
| 726 | mErrorConsoleContainer.removeView(errorConsole); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | private void setStatusBarVisibility(boolean visible) { |
Joe Onorato | d3bf86f | 2011-01-25 20:07:10 -0800 | [diff] [blame] | 731 | WindowManager.LayoutParams params = mActivity.getWindow().getAttributes(); |
| 732 | params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN; |
| 733 | mActivity.getWindow().setAttributes(params); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 736 | // ------------------------------------------------------------------------- |
| 737 | // Helper function for WebChromeClient |
| 738 | // ------------------------------------------------------------------------- |
| 739 | |
| 740 | @Override |
| 741 | public Bitmap getDefaultVideoPoster() { |
| 742 | if (mDefaultVideoPoster == null) { |
| 743 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 744 | mActivity.getResources(), R.drawable.default_video_poster); |
| 745 | } |
| 746 | return mDefaultVideoPoster; |
| 747 | } |
| 748 | |
| 749 | @Override |
| 750 | public View getVideoLoadingProgressView() { |
| 751 | if (mVideoProgressView == null) { |
| 752 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 753 | mVideoProgressView = inflater.inflate( |
| 754 | R.layout.video_loading_progress, null); |
| 755 | } |
| 756 | return mVideoProgressView; |
| 757 | } |
| 758 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 759 | @Override |
| 760 | public void showMaxTabsWarning() { |
| 761 | Toast warning = Toast.makeText(mActivity, |
| 762 | mActivity.getString(R.string.max_tabs_warning), |
| 763 | Toast.LENGTH_SHORT); |
| 764 | warning.show(); |
| 765 | } |
| 766 | |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 767 | protected void captureTab(final Tab tab) { |
| 768 | captureTab(tab, |
| 769 | (int) mActivity.getResources() |
| 770 | .getDimension(R.dimen.qc_thumb_width), |
| 771 | (int) mActivity.getResources() |
| 772 | .getDimension(R.dimen.qc_thumb_height)); |
| 773 | } |
| 774 | |
| 775 | protected void captureTab(final Tab tab, int width, int height) { |
| 776 | if ((tab == null) || (tab.getWebView() == null)) return; |
| 777 | Bitmap sshot = Controller.createScreenshot(tab, width, height); |
| 778 | tab.setScreenshot(sshot); |
| 779 | } |
| 780 | |
Michael Kolb | 46f987e | 2011-04-05 10:39:10 -0700 | [diff] [blame] | 781 | protected WebView getWebView() { |
| 782 | if (mActiveTab != null) { |
| 783 | return mActiveTab.getWebView(); |
| 784 | } else { |
| 785 | return null; |
| 786 | } |
Michael Kolb | fdb7024 | 2011-03-24 09:41:11 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Michael Kolb | fedb492 | 2011-04-20 16:45:33 -0700 | [diff] [blame] | 789 | protected Menu getMenu() { |
| 790 | MenuBuilder menu = new MenuBuilder(mActivity); |
| 791 | mActivity.getMenuInflater().inflate(R.menu.browser, menu); |
| 792 | return menu; |
| 793 | } |
| 794 | |
Michael Kolb | c38c604 | 2011-04-27 10:46:06 -0700 | [diff] [blame] | 795 | public void setFullscreen(boolean enabled) { |
| 796 | if (enabled) { |
| 797 | mActivity.getWindow().setFlags( |
| 798 | WindowManager.LayoutParams.FLAG_FULLSCREEN, |
| 799 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 800 | } else { |
| 801 | mActivity.getWindow().clearFlags( |
| 802 | WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 803 | } |
| 804 | } |
| 805 | |
Michael Kolb | 5a4372f | 2011-04-29 13:53:10 -0700 | [diff] [blame^] | 806 | protected Drawable getFaviconDrawable(Bitmap icon) { |
| 807 | Drawable[] array = new Drawable[3]; |
| 808 | array[0] = new PaintDrawable(Color.BLACK); |
| 809 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 810 | array[1] = p; |
| 811 | if (icon == null) { |
| 812 | array[2] = mGenericFavicon; |
| 813 | } else { |
| 814 | array[2] = new BitmapDrawable(icon); |
| 815 | } |
| 816 | LayerDrawable d = new LayerDrawable(array); |
| 817 | d.setLayerInset(1, 1, 1, 1, 1); |
| 818 | d.setLayerInset(2, 2, 2, 2, 2); |
| 819 | return d; |
| 820 | } |
| 821 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 822 | } |