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); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 245 | Tab getActiveTab() { |
| 246 | return mActiveTab; |
| 247 | } |
| 248 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 249 | @Override |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 250 | public void updateTabs(List<Tab> tabs) { |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 254 | public void removeTab(Tab tab) { |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 255 | if (mActiveTab == tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 256 | removeTabFromContentView(tab); |
Michael Kolb | 77df456 | 2010-11-19 14:49:34 -0800 | [diff] [blame] | 257 | mActiveTab = null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 258 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public void detachTab(Tab tab) { |
| 263 | removeTabFromContentView(tab); |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public void attachTab(Tab tab) { |
| 268 | attachTabToContentView(tab); |
| 269 | } |
| 270 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 271 | protected void attachTabToContentView(Tab tab) { |
Michael Kolb | d1e2ccc | 2011-01-24 11:38:31 -0800 | [diff] [blame] | 272 | if ((tab == null) || (tab.getWebView() == null)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | View container = tab.getViewContainer(); |
| 276 | WebView mainView = tab.getWebView(); |
| 277 | // Attach the WebView to the container and then attach the |
| 278 | // container to the content view. |
| 279 | FrameLayout wrapper = |
| 280 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 281 | ViewGroup parent = (ViewGroup) mainView.getParent(); |
| 282 | if (parent != wrapper) { |
| 283 | if (parent != null) { |
| 284 | Log.w(LOGTAG, "mMainView already has a parent in" |
| 285 | + " attachTabToContentView!"); |
| 286 | parent.removeView(mainView); |
| 287 | } |
| 288 | wrapper.addView(mainView); |
| 289 | } else { |
| 290 | Log.w(LOGTAG, "mMainView is already attached to wrapper in" |
| 291 | + " attachTabToContentView!"); |
| 292 | } |
| 293 | parent = (ViewGroup) container.getParent(); |
| 294 | if (parent != mContentView) { |
| 295 | if (parent != null) { |
| 296 | Log.w(LOGTAG, "mContainer already has a parent in" |
| 297 | + " attachTabToContentView!"); |
| 298 | parent.removeView(container); |
| 299 | } |
| 300 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 301 | } else { |
| 302 | Log.w(LOGTAG, "mContainer is already attached to content in" |
| 303 | + " attachTabToContentView!"); |
| 304 | } |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 305 | mainView.setNextFocusUpId(R.id.url_focused); |
| 306 | mainView.setNextFocusDownId(R.id.url_focused); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 307 | mUiController.attachSubWindow(tab); |
| 308 | } |
| 309 | |
| 310 | private void removeTabFromContentView(Tab tab) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 311 | hideTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 312 | // Remove the container that contains the main WebView. |
| 313 | WebView mainView = tab.getWebView(); |
| 314 | View container = tab.getViewContainer(); |
| 315 | if (mainView == null) { |
| 316 | return; |
| 317 | } |
| 318 | // Remove the container from the content and then remove the |
| 319 | // WebView from the container. This will trigger a focus change |
| 320 | // needed by WebView. |
Michael Kolb | 20776cc | 2011-01-31 10:19:05 -0800 | [diff] [blame] | 321 | mainView.setEmbeddedTitleBar(null); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 322 | FrameLayout wrapper = |
| 323 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 324 | wrapper.removeView(mainView); |
| 325 | mContentView.removeView(container); |
| 326 | mUiController.endActionMode(); |
| 327 | mUiController.removeSubWindow(tab); |
| 328 | ErrorConsoleView errorConsole = tab.getErrorConsole(false); |
| 329 | if (errorConsole != null) { |
| 330 | mErrorConsoleContainer.removeView(errorConsole); |
| 331 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 334 | @Override |
| 335 | public void onSetWebView(Tab tab, WebView webView) { |
| 336 | View container = tab.getViewContainer(); |
| 337 | if (container == null) { |
| 338 | // The tab consists of a container view, which contains the main |
| 339 | // WebView, as well as any other UI elements associated with the tab. |
| 340 | container = mActivity.getLayoutInflater().inflate(R.layout.tab, |
| 341 | null); |
| 342 | tab.setViewContainer(container); |
| 343 | } |
| 344 | if (tab.getWebView() != webView) { |
| 345 | // Just remove the old one. |
| 346 | FrameLayout wrapper = |
| 347 | (FrameLayout) container.findViewById(R.id.webview_wrapper); |
| 348 | wrapper.removeView(tab.getWebView()); |
| 349 | } |
| 350 | } |
| 351 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 352 | /** |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 353 | * create a sub window container and webview for the tab |
| 354 | * Note: this methods operates through side-effects for now |
| 355 | * it sets both the subView and subViewContainer for the given tab |
| 356 | * @param tab tab to create the sub window for |
| 357 | * @param subView webview to be set as a subwindow for the tab |
| 358 | */ |
| 359 | @Override |
| 360 | public void createSubWindow(Tab tab, WebView subView) { |
| 361 | View subViewContainer = mActivity.getLayoutInflater().inflate( |
| 362 | R.layout.browser_subwindow, null); |
| 363 | ViewGroup inner = (ViewGroup) subViewContainer |
| 364 | .findViewById(R.id.inner_container); |
| 365 | inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, |
| 366 | LayoutParams.MATCH_PARENT)); |
| 367 | final ImageButton cancel = (ImageButton) subViewContainer |
| 368 | .findViewById(R.id.subwindow_close); |
| 369 | final WebView cancelSubView = subView; |
| 370 | cancel.setOnClickListener(new OnClickListener() { |
| 371 | public void onClick(View v) { |
| 372 | cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView); |
| 373 | } |
| 374 | }); |
| 375 | tab.setSubWebView(subView); |
| 376 | tab.setSubViewContainer(subViewContainer); |
| 377 | } |
| 378 | |
| 379 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 380 | * Remove the sub window from the content view. |
| 381 | */ |
| 382 | @Override |
| 383 | public void removeSubWindow(View subviewContainer) { |
| 384 | mContentView.removeView(subviewContainer); |
| 385 | mUiController.endActionMode(); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Attach the sub window to the content view. |
| 390 | */ |
| 391 | @Override |
| 392 | public void attachSubWindow(View container) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 393 | if (container.getParent() != null) { |
| 394 | // already attached, remove first |
| 395 | ((ViewGroup) container.getParent()).removeView(container); |
| 396 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 397 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 398 | } |
| 399 | |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 400 | boolean canShowTitleBar() { |
| 401 | return !isTitleBarShowing() |
| 402 | && !isActivityPaused() |
| 403 | && (getActiveTab() != null) |
| 404 | && (getActiveTab().getWebView() != null) |
| 405 | && !mUiController.isInCustomActionMode(); |
| 406 | } |
| 407 | |
| 408 | void showTitleBar() { |
| 409 | mTitleShowing = true; |
| 410 | } |
| 411 | |
| 412 | protected void hideTitleBar() { |
| 413 | mTitleShowing = false; |
| 414 | } |
| 415 | |
| 416 | protected boolean isTitleBarShowing() { |
| 417 | return mTitleShowing; |
| 418 | } |
| 419 | |
| 420 | protected abstract TitleBarBase getTitleBar(); |
| 421 | |
| 422 | protected void setTitleGravity(int gravity) { |
| 423 | getTitleBar().setTitleGravity(gravity); |
| 424 | Tab tab = getActiveTab(); |
| 425 | if ((tab != null) && (tab.getWebView() != null)) { |
| 426 | tab.getWebView().setTitleBarGravity(gravity); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 430 | @Override |
| 431 | public void showVoiceTitleBar(String title) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 432 | getTitleBar().setInVoiceMode(true); |
| 433 | getTitleBar().setDisplayTitle(title); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 436 | @Override |
| 437 | public void revertVoiceTitleBar(Tab tab) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 438 | getTitleBar().setInVoiceMode(false); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 439 | String url = tab.getUrl(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 440 | getTitleBar().setDisplayTitle(url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public void showComboView(boolean startWithHistory, Bundle extras) { |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 445 | if (mComboView != null) { |
| 446 | return; |
| 447 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 448 | mComboView = new CombinedBookmarkHistoryView(mActivity, |
| 449 | mUiController, |
| 450 | startWithHistory ? |
| 451 | CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY |
| 452 | : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS, |
| 453 | extras); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 454 | FrameLayout wrapper = |
| 455 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 456 | wrapper.setVisibility(View.GONE); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 457 | hideTitleBar(); |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 458 | dismissIME(); |
| 459 | if (mActiveTab != null) { |
| 460 | WebView web = mActiveTab.getWebView(); |
| 461 | mActiveTab.putInBackground(); |
| 462 | } |
John Reck | 5289bc3 | 2011-02-18 14:38:08 -0800 | [diff] [blame] | 463 | mComboView.setAlpha(0f); |
| 464 | ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f); |
| 465 | Resources res = mActivity.getResources(); |
| 466 | anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration)); |
| 467 | anim.start(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 468 | mContentView.addView(mComboView, COVER_SCREEN_PARAMS); |
| 469 | } |
| 470 | |
Michael Kolb | ba23870 | 2011-03-08 10:40:50 -0800 | [diff] [blame] | 471 | public boolean isComboViewShowing() { |
| 472 | return (mComboView != null); |
| 473 | } |
| 474 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 475 | /** |
| 476 | * dismiss the ComboPage |
| 477 | */ |
| 478 | @Override |
| 479 | public void hideComboView() { |
| 480 | if (mComboView != null) { |
| 481 | mContentView.removeView(mComboView); |
Michael Kolb | 47d63f8 | 2011-01-18 10:48:40 -0800 | [diff] [blame] | 482 | FrameLayout wrapper = |
| 483 | (FrameLayout) mContentView.findViewById(R.id.webview_wrapper); |
| 484 | wrapper.setVisibility(View.VISIBLE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 485 | mComboView = null; |
| 486 | } |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 487 | if (mActiveTab != null) { |
| 488 | mActiveTab.putInForeground(); |
| 489 | } |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 490 | mActivity.invalidateOptionsMenu(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public void showCustomView(View view, |
| 495 | WebChromeClient.CustomViewCallback callback) { |
| 496 | // if a view already exists then immediately terminate the new one |
| 497 | if (mCustomView != null) { |
| 498 | callback.onCustomViewHidden(); |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | // Add the custom view to its container. |
| 503 | mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); |
| 504 | mCustomView = view; |
| 505 | mCustomViewCallback = callback; |
| 506 | // Hide the content view. |
| 507 | mContentView.setVisibility(View.GONE); |
| 508 | // Finally show the custom view container. |
| 509 | setStatusBarVisibility(false); |
| 510 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 511 | mCustomViewContainer.bringToFront(); |
| 512 | } |
| 513 | |
| 514 | @Override |
| 515 | public void onHideCustomView() { |
| 516 | if (mCustomView == null) |
| 517 | return; |
| 518 | |
| 519 | // Hide the custom view. |
| 520 | mCustomView.setVisibility(View.GONE); |
| 521 | // Remove the custom view from its container. |
| 522 | mCustomViewContainer.removeView(mCustomView); |
| 523 | mCustomView = null; |
| 524 | mCustomViewContainer.setVisibility(View.GONE); |
| 525 | mCustomViewCallback.onCustomViewHidden(); |
| 526 | // Show the content view. |
| 527 | setStatusBarVisibility(true); |
| 528 | mContentView.setVisibility(View.VISIBLE); |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public boolean isCustomViewShowing() { |
| 533 | return mCustomView != null; |
| 534 | } |
| 535 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 536 | protected void dismissIME() { |
Michael Kolb | 3a69628 | 2010-12-05 13:23:24 -0800 | [diff] [blame] | 537 | if (mInputManager.isActive()) { |
| 538 | mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), |
| 539 | 0); |
| 540 | } |
| 541 | } |
| 542 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 543 | @Override |
| 544 | public boolean showsWeb() { |
| 545 | return mCustomView == null |
| 546 | && mComboView == null; |
| 547 | } |
| 548 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 549 | // ------------------------------------------------------------------------- |
| 550 | |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 551 | protected void updateNavigationState(Tab tab) { |
| 552 | } |
| 553 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 554 | /** |
| 555 | * Update the lock icon to correspond to our latest state. |
| 556 | */ |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 557 | protected void updateLockIconToLatest(Tab t) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 558 | if (t != null && t.inForeground()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 559 | updateLockIconImage(t.getLockIconType()); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 564 | * Updates the lock-icon image in the title-bar. |
| 565 | */ |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 566 | private void updateLockIconImage(LockIcon lockIconType) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 567 | Drawable d = null; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 568 | if (lockIconType == LockIcon.LOCK_ICON_SECURE) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 569 | d = mSecLockIcon; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 570 | } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 571 | d = mMixLockIcon; |
| 572 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 573 | getTitleBar().setLock(d); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 574 | } |
| 575 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 576 | protected void setUrlTitle(Tab tab) { |
| 577 | String url = tab.getUrl(); |
| 578 | String title = tab.getTitle(); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 579 | if (TextUtils.isEmpty(title)) { |
| 580 | title = url; |
Michael Kolb | 81b6f83 | 2010-12-12 12:44:27 -0800 | [diff] [blame] | 581 | } |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 582 | if (tab.isInVoiceSearchMode()) return; |
| 583 | if (tab.inForeground()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 584 | getTitleBar().setDisplayTitle(url); |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | |
| 588 | // Set the favicon in the title bar. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 589 | protected void setFavicon(Tab tab) { |
| 590 | if (tab.inForeground()) { |
| 591 | Bitmap icon = tab.getFavicon(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 592 | getTitleBar().setFavicon(icon); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 593 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | @Override |
| 597 | public void onActionModeFinished(boolean inLoad) { |
| 598 | if (inLoad) { |
| 599 | // the titlebar was removed when the CAB was shown |
| 600 | // if the page is loading, show it again |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 601 | showTitleBar(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 605 | // active tabs page |
| 606 | |
| 607 | public void showActiveTabsPage() { |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Remove the active tabs page. |
| 612 | */ |
| 613 | public void removeActiveTabsPage() { |
| 614 | } |
| 615 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 616 | // menu handling callbacks |
| 617 | |
| 618 | @Override |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame^] | 619 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 620 | return true; |
| 621 | } |
| 622 | |
| 623 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 624 | public void onOptionsMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public void onExtendedMenuOpened() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | @Override |
| 632 | public void onOptionsMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | @Override |
| 636 | public void onExtendedMenuClosed(boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | @Override |
| 640 | public void onContextMenuCreated(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | @Override |
| 644 | public void onContextMenuClosed(Menu menu, boolean inLoad) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | // error console |
| 648 | |
| 649 | @Override |
| 650 | public void setShouldShowErrorConsole(Tab tab, boolean flag) { |
Michael Kolb | 9fcefd1 | 2011-02-17 10:55:59 -0800 | [diff] [blame] | 651 | if (tab == null) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 652 | ErrorConsoleView errorConsole = tab.getErrorConsole(true); |
| 653 | if (flag) { |
| 654 | // Setting the show state of the console will cause it's the layout |
| 655 | // to be inflated. |
| 656 | if (errorConsole.numberOfErrors() > 0) { |
| 657 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 658 | } else { |
| 659 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 660 | } |
| 661 | if (errorConsole.getParent() != null) { |
| 662 | mErrorConsoleContainer.removeView(errorConsole); |
| 663 | } |
| 664 | // Now we can add it to the main view. |
| 665 | mErrorConsoleContainer.addView(errorConsole, |
| 666 | new LinearLayout.LayoutParams( |
| 667 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 668 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 669 | } else { |
| 670 | mErrorConsoleContainer.removeView(errorConsole); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | private void setStatusBarVisibility(boolean visible) { |
Joe Onorato | d3bf86f | 2011-01-25 20:07:10 -0800 | [diff] [blame] | 675 | WindowManager.LayoutParams params = mActivity.getWindow().getAttributes(); |
| 676 | params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN; |
| 677 | mActivity.getWindow().setAttributes(params); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 680 | // ------------------------------------------------------------------------- |
| 681 | // Helper function for WebChromeClient |
| 682 | // ------------------------------------------------------------------------- |
| 683 | |
| 684 | @Override |
| 685 | public Bitmap getDefaultVideoPoster() { |
| 686 | if (mDefaultVideoPoster == null) { |
| 687 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 688 | mActivity.getResources(), R.drawable.default_video_poster); |
| 689 | } |
| 690 | return mDefaultVideoPoster; |
| 691 | } |
| 692 | |
| 693 | @Override |
| 694 | public View getVideoLoadingProgressView() { |
| 695 | if (mVideoProgressView == null) { |
| 696 | LayoutInflater inflater = LayoutInflater.from(mActivity); |
| 697 | mVideoProgressView = inflater.inflate( |
| 698 | R.layout.video_loading_progress, null); |
| 699 | } |
| 700 | return mVideoProgressView; |
| 701 | } |
| 702 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 703 | @Override |
| 704 | public void showMaxTabsWarning() { |
| 705 | Toast warning = Toast.makeText(mActivity, |
| 706 | mActivity.getString(R.string.max_tabs_warning), |
| 707 | Toast.LENGTH_SHORT); |
| 708 | warning.show(); |
| 709 | } |
| 710 | |
Narayan Kamath | 5119edd | 2011-02-23 15:49:17 +0000 | [diff] [blame] | 711 | @Override |
| 712 | public void registerDropdownChangeListener(DropdownChangeListener d) { |
| 713 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 714 | } |