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