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