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