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