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