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