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