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