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