blob: 51775d2c666dc48f1e1725f852b11c2201fa1d32 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
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
17package com.android.browser;
18
John Reck30c714c2010-12-16 17:30:34 -080019import com.android.browser.Tab.LockIcon;
John Reck74830e12011-03-14 11:43:05 -070020import com.android.browser.UI.DropdownChangeListener;
John Reck30c714c2010-12-16 17:30:34 -080021
John Reck74830e12011-03-14 11:43:05 -070022import android.animation.Animator;
23import android.animation.Animator.AnimatorListener;
24import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.app.Activity;
John Reckb9a051b2011-03-18 11:55:48 -070026import android.content.pm.PackageManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070027import android.content.res.Configuration;
28import android.content.res.Resources;
29import android.graphics.Bitmap;
30import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.graphics.drawable.Drawable;
32import android.os.Bundle;
33import android.text.TextUtils;
34import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.Gravity;
36import android.view.LayoutInflater;
37import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080039import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080041import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080043import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070045import android.webkit.WebView;
46import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080047import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070048import android.widget.LinearLayout;
49import android.widget.Toast;
50
Michael Kolb1bf23132010-11-19 12:55:12 -080051import java.util.List;
52
Michael Kolb8233fac2010-10-26 16:08:53 -070053/**
54 * UI interface definitions
55 */
Michael Kolb66706532010-12-12 19:50:22 -080056public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070057
58 private static final String LOGTAG = "BaseUi";
59
Michael Kolb66706532010-12-12 19:50:22 -080060 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070061 new FrameLayout.LayoutParams(
62 ViewGroup.LayoutParams.MATCH_PARENT,
63 ViewGroup.LayoutParams.MATCH_PARENT);
64
Michael Kolb66706532010-12-12 19:50:22 -080065 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070066 new FrameLayout.LayoutParams(
67 ViewGroup.LayoutParams.MATCH_PARENT,
68 ViewGroup.LayoutParams.MATCH_PARENT,
69 Gravity.CENTER);
70
71 Activity mActivity;
72 UiController mUiController;
73 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080074 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080075 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070076
77 private Drawable mSecLockIcon;
78 private Drawable mMixLockIcon;
79
Michael Kolb8233fac2010-10-26 16:08:53 -070080 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080081 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070082 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070083
84 private View mCustomView;
85 private WebChromeClient.CustomViewCallback mCustomViewCallback;
86
87 private CombinedBookmarkHistoryView mComboView;
88
89 private LinearLayout mErrorConsoleContainer = null;
90
91 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070092
Michael Kolb7cdc4902011-02-03 17:54:40 -080093 private boolean mTitleShowing;
94
Michael Kolb8233fac2010-10-26 16:08:53 -070095 // the default <video> poster
96 private Bitmap mDefaultVideoPoster;
97 // the video progress view
98 private View mVideoProgressView;
99
Michael Kolb8233fac2010-10-26 16:08:53 -0700100 private boolean mActivityPaused;
101
102 public BaseUi(Activity browser, UiController controller) {
103 mActivity = browser;
104 mUiController = controller;
105 mTabControl = controller.getTabControl();
106 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800107 mInputManager = (InputMethodManager)
108 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800109 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700110 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
111
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
113 .getDecorView().findViewById(android.R.id.content);
114 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
115 .inflate(R.layout.custom_screen, null);
116 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
117 R.id.main_content);
118 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
119 .findViewById(R.id.error_console);
120 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
121 .findViewById(R.id.fullscreen_custom_content);
122 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800123 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700124 }
125
John Reckb9a051b2011-03-18 11:55:48 -0700126 @Override
127 public WebView createWebView(boolean privateBrowsing) {
128 // Create a new WebView
129 BrowserWebView w = new BrowserWebView(mActivity, null,
130 android.R.attr.webViewStyle, privateBrowsing);
131 initWebViewSettings(w);
132 return w;
133 }
134
135 @Override
136 public WebView createSubWebView(boolean privateBrowsing) {
137 return createWebView(privateBrowsing);
138 }
139
Michael Kolb66706532010-12-12 19:50:22 -0800140 /**
141 * common webview initialization
142 * @param w the webview to initialize
143 */
144 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700145 w.setScrollbarFadingEnabled(true);
146 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
147 w.setMapTrackballToArrowKeys(false); // use trackball directly
148 // Enable the built-in zoom
149 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700150 boolean supportsMultiTouch = mActivity.getPackageManager()
151 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
152 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
153 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700154
155 // Add this WebView to the settings observer list and update the
156 // settings
157 final BrowserSettings s = BrowserSettings.getInstance();
158 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700159 }
160
161 private void cancelStopToast() {
162 if (mStopToast != null) {
163 mStopToast.cancel();
164 mStopToast = null;
165 }
166 }
167
168 // lifecycle
169
170 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800171 if (isCustomViewShowing()) {
172 onHideCustomView();
173 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700174 cancelStopToast();
175 mActivityPaused = true;
176 }
177
178 public void onResume() {
179 mActivityPaused = false;
180 }
181
Michael Kolb66706532010-12-12 19:50:22 -0800182 protected boolean isActivityPaused() {
183 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700184 }
185
186 public void onConfigurationChanged(Configuration config) {
187 }
188
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800189 public abstract void editUrl(boolean clearInput);
190
Michael Kolb8233fac2010-10-26 16:08:53 -0700191 // key handling
192
193 @Override
194 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700195 if (mComboView != null) {
196 if (!mComboView.onBackPressed()) {
197 mUiController.removeComboView();
198 }
199 return true;
200 }
201 if (mCustomView != null) {
202 mUiController.hideCustomView();
203 return true;
204 }
205 return false;
206 }
207
John Reck30c714c2010-12-16 17:30:34 -0800208 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700209 @Override
John Reck30c714c2010-12-16 17:30:34 -0800210 public void onTabDataChanged(Tab tab) {
211 setUrlTitle(tab);
212 setFavicon(tab);
213 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800214 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700215 }
216
217 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500218 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800219 if (tab.inForeground()) {
220 boolean isBookmark = tab.isBookmarkedSite();
221 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
222 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500223 }
224
225 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 public void onPageStopped(Tab tab) {
227 cancelStopToast();
228 if (tab.inForeground()) {
229 mStopToast = Toast
230 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
231 mStopToast.show();
232 }
233 }
234
235 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800236 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800237 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800238 }
239
240 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 }
243
244 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800245 public void setActiveTab(final Tab tab) {
246 setActiveTab(tab, true);
247 }
248
249 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800250 if ((tab != mActiveTab) && (mActiveTab != null)) {
251 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 }
Michael Kolb77df4562010-11-19 14:49:34 -0800253 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800254 if (needsAttaching) {
255 attachTabToContentView(tab);
256 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800258 onTabDataChanged(tab);
259 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800260 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800261 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500262 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700263 }
264
Michael Kolbcfa3af52010-12-14 10:36:11 -0800265 Tab getActiveTab() {
266 return mActiveTab;
267 }
268
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800270 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800271 }
272
273 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700274 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800275 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700276 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800277 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700278 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700279 }
280
281 @Override
282 public void detachTab(Tab tab) {
283 removeTabFromContentView(tab);
284 }
285
286 @Override
287 public void attachTab(Tab tab) {
288 attachTabToContentView(tab);
289 }
290
Michael Kolb377ea312011-02-17 14:36:56 -0800291 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800292 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700293 return;
294 }
295 View container = tab.getViewContainer();
296 WebView mainView = tab.getWebView();
297 // Attach the WebView to the container and then attach the
298 // container to the content view.
299 FrameLayout wrapper =
300 (FrameLayout) container.findViewById(R.id.webview_wrapper);
301 ViewGroup parent = (ViewGroup) mainView.getParent();
302 if (parent != wrapper) {
303 if (parent != null) {
304 Log.w(LOGTAG, "mMainView already has a parent in"
305 + " attachTabToContentView!");
306 parent.removeView(mainView);
307 }
308 wrapper.addView(mainView);
309 } else {
310 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
311 + " attachTabToContentView!");
312 }
313 parent = (ViewGroup) container.getParent();
314 if (parent != mContentView) {
315 if (parent != null) {
316 Log.w(LOGTAG, "mContainer already has a parent in"
317 + " attachTabToContentView!");
318 parent.removeView(container);
319 }
320 mContentView.addView(container, COVER_SCREEN_PARAMS);
321 } else {
322 Log.w(LOGTAG, "mContainer is already attached to content in"
323 + " attachTabToContentView!");
324 }
Michael Kolba4183062011-01-16 10:43:21 -0800325 mainView.setNextFocusUpId(R.id.url_focused);
326 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700327 mUiController.attachSubWindow(tab);
328 }
329
330 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800331 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 // Remove the container that contains the main WebView.
333 WebView mainView = tab.getWebView();
334 View container = tab.getViewContainer();
335 if (mainView == null) {
336 return;
337 }
338 // Remove the container from the content and then remove the
339 // WebView from the container. This will trigger a focus change
340 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800341 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700342 FrameLayout wrapper =
343 (FrameLayout) container.findViewById(R.id.webview_wrapper);
344 wrapper.removeView(mainView);
345 mContentView.removeView(container);
346 mUiController.endActionMode();
347 mUiController.removeSubWindow(tab);
348 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
349 if (errorConsole != null) {
350 mErrorConsoleContainer.removeView(errorConsole);
351 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700352 }
353
Michael Kolba713ec82010-11-29 17:27:06 -0800354 @Override
355 public void onSetWebView(Tab tab, WebView webView) {
356 View container = tab.getViewContainer();
357 if (container == null) {
358 // The tab consists of a container view, which contains the main
359 // WebView, as well as any other UI elements associated with the tab.
360 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
361 null);
362 tab.setViewContainer(container);
363 }
364 if (tab.getWebView() != webView) {
365 // Just remove the old one.
366 FrameLayout wrapper =
367 (FrameLayout) container.findViewById(R.id.webview_wrapper);
368 wrapper.removeView(tab.getWebView());
369 }
370 }
371
Michael Kolb8233fac2010-10-26 16:08:53 -0700372 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800373 * create a sub window container and webview for the tab
374 * Note: this methods operates through side-effects for now
375 * it sets both the subView and subViewContainer for the given tab
376 * @param tab tab to create the sub window for
377 * @param subView webview to be set as a subwindow for the tab
378 */
379 @Override
380 public void createSubWindow(Tab tab, WebView subView) {
381 View subViewContainer = mActivity.getLayoutInflater().inflate(
382 R.layout.browser_subwindow, null);
383 ViewGroup inner = (ViewGroup) subViewContainer
384 .findViewById(R.id.inner_container);
385 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
386 LayoutParams.MATCH_PARENT));
387 final ImageButton cancel = (ImageButton) subViewContainer
388 .findViewById(R.id.subwindow_close);
389 final WebView cancelSubView = subView;
390 cancel.setOnClickListener(new OnClickListener() {
391 public void onClick(View v) {
392 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
393 }
394 });
395 tab.setSubWebView(subView);
396 tab.setSubViewContainer(subViewContainer);
397 }
398
399 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700400 * Remove the sub window from the content view.
401 */
402 @Override
403 public void removeSubWindow(View subviewContainer) {
404 mContentView.removeView(subviewContainer);
405 mUiController.endActionMode();
406 }
407
408 /**
409 * Attach the sub window to the content view.
410 */
411 @Override
412 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800413 if (container.getParent() != null) {
414 // already attached, remove first
415 ((ViewGroup) container.getParent()).removeView(container);
416 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 mContentView.addView(container, COVER_SCREEN_PARAMS);
418 }
419
Michael Kolb7cdc4902011-02-03 17:54:40 -0800420 boolean canShowTitleBar() {
421 return !isTitleBarShowing()
422 && !isActivityPaused()
423 && (getActiveTab() != null)
424 && (getActiveTab().getWebView() != null)
425 && !mUiController.isInCustomActionMode();
426 }
427
428 void showTitleBar() {
429 mTitleShowing = true;
430 }
431
432 protected void hideTitleBar() {
433 mTitleShowing = false;
434 }
435
436 protected boolean isTitleBarShowing() {
437 return mTitleShowing;
438 }
439
440 protected abstract TitleBarBase getTitleBar();
441
442 protected void setTitleGravity(int gravity) {
443 getTitleBar().setTitleGravity(gravity);
444 Tab tab = getActiveTab();
445 if ((tab != null) && (tab.getWebView() != null)) {
446 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700447 }
448 }
449
Michael Kolb66706532010-12-12 19:50:22 -0800450 @Override
451 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800452 getTitleBar().setInVoiceMode(true);
453 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700454 }
455
Michael Kolb66706532010-12-12 19:50:22 -0800456 @Override
457 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800458 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800459 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800460 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700461 }
462
463 @Override
464 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800465 if (mComboView != null) {
466 return;
467 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700468 mComboView = new CombinedBookmarkHistoryView(mActivity,
469 mUiController,
470 startWithHistory ?
471 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
472 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
473 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800474 FrameLayout wrapper =
475 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
476 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800477 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800478 dismissIME();
479 if (mActiveTab != null) {
480 WebView web = mActiveTab.getWebView();
481 mActiveTab.putInBackground();
482 }
John Reck74830e12011-03-14 11:43:05 -0700483 mComboView.setAlpha(0f);
484 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
485 Resources res = mActivity.getResources();
486 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
487 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700488 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
489 }
490
Michael Kolbba238702011-03-08 10:40:50 -0800491 public boolean isComboViewShowing() {
492 return (mComboView != null);
493 }
494
Michael Kolb8233fac2010-10-26 16:08:53 -0700495 /**
496 * dismiss the ComboPage
497 */
498 @Override
499 public void hideComboView() {
500 if (mComboView != null) {
501 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800502 FrameLayout wrapper =
503 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
504 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700505 mComboView = null;
506 }
Michael Kolb3a696282010-12-05 13:23:24 -0800507 if (mActiveTab != null) {
508 mActiveTab.putInForeground();
509 }
John Reckb3417f02011-01-14 11:01:05 -0800510 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700511 }
512
513 @Override
514 public void showCustomView(View view,
515 WebChromeClient.CustomViewCallback callback) {
516 // if a view already exists then immediately terminate the new one
517 if (mCustomView != null) {
518 callback.onCustomViewHidden();
519 return;
520 }
521
522 // Add the custom view to its container.
523 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
524 mCustomView = view;
525 mCustomViewCallback = callback;
526 // Hide the content view.
527 mContentView.setVisibility(View.GONE);
528 // Finally show the custom view container.
529 setStatusBarVisibility(false);
530 mCustomViewContainer.setVisibility(View.VISIBLE);
531 mCustomViewContainer.bringToFront();
532 }
533
534 @Override
535 public void onHideCustomView() {
536 if (mCustomView == null)
537 return;
538
539 // Hide the custom view.
540 mCustomView.setVisibility(View.GONE);
541 // Remove the custom view from its container.
542 mCustomViewContainer.removeView(mCustomView);
543 mCustomView = null;
544 mCustomViewContainer.setVisibility(View.GONE);
545 mCustomViewCallback.onCustomViewHidden();
546 // Show the content view.
547 setStatusBarVisibility(true);
548 mContentView.setVisibility(View.VISIBLE);
549 }
550
551 @Override
552 public boolean isCustomViewShowing() {
553 return mCustomView != null;
554 }
555
Michael Kolb66706532010-12-12 19:50:22 -0800556 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800557 if (mInputManager.isActive()) {
558 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
559 0);
560 }
561 }
562
Michael Kolb66706532010-12-12 19:50:22 -0800563 @Override
564 public boolean showsWeb() {
565 return mCustomView == null
566 && mComboView == null;
567 }
568
Patrick Scott92066772011-03-10 08:46:27 -0500569 @Override
570 public void showAutoLogin(Tab tab) {
571 updateAutoLogin(tab, true);
572 }
573
574 @Override
575 public void hideAutoLogin(Tab tab) {
576 updateAutoLogin(tab, true);
577 }
578
Michael Kolb8233fac2010-10-26 16:08:53 -0700579 // -------------------------------------------------------------------------
580
Michael Kolb5a72f182011-01-13 20:35:06 -0800581 protected void updateNavigationState(Tab tab) {
582 }
583
Patrick Scott92066772011-03-10 08:46:27 -0500584 protected void updateAutoLogin(Tab tab, boolean animate) {}
585
Michael Kolb8233fac2010-10-26 16:08:53 -0700586 /**
587 * Update the lock icon to correspond to our latest state.
588 */
Michael Kolb66706532010-12-12 19:50:22 -0800589 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800590 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700591 updateLockIconImage(t.getLockIconType());
592 }
593 }
594
595 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 * Updates the lock-icon image in the title-bar.
597 */
John Reck30c714c2010-12-16 17:30:34 -0800598 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700599 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800600 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800602 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 d = mMixLockIcon;
604 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800605 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700606 }
607
John Reck30c714c2010-12-16 17:30:34 -0800608 protected void setUrlTitle(Tab tab) {
609 String url = tab.getUrl();
610 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800611 if (TextUtils.isEmpty(title)) {
612 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800613 }
Michael Kolb66706532010-12-12 19:50:22 -0800614 if (tab.isInVoiceSearchMode()) return;
615 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800616 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800617 }
618 }
619
620 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800621 protected void setFavicon(Tab tab) {
622 if (tab.inForeground()) {
623 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800624 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800625 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700626 }
627
628 @Override
629 public void onActionModeFinished(boolean inLoad) {
630 if (inLoad) {
631 // the titlebar was removed when the CAB was shown
632 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800633 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700634 }
635 }
636
Michael Kolb66706532010-12-12 19:50:22 -0800637 // active tabs page
638
639 public void showActiveTabsPage() {
640 }
641
642 /**
643 * Remove the active tabs page.
644 */
645 public void removeActiveTabsPage() {
646 }
647
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 // menu handling callbacks
649
650 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800651 public boolean onPrepareOptionsMenu(Menu menu) {
652 return true;
653 }
654
655 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700657 }
658
659 @Override
660 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700661 }
662
663 @Override
664 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700665 }
666
667 @Override
668 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 }
670
671 @Override
672 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700673 }
674
675 @Override
676 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 }
678
679 // error console
680
681 @Override
682 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800683 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700684 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
685 if (flag) {
686 // Setting the show state of the console will cause it's the layout
687 // to be inflated.
688 if (errorConsole.numberOfErrors() > 0) {
689 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
690 } else {
691 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
692 }
693 if (errorConsole.getParent() != null) {
694 mErrorConsoleContainer.removeView(errorConsole);
695 }
696 // Now we can add it to the main view.
697 mErrorConsoleContainer.addView(errorConsole,
698 new LinearLayout.LayoutParams(
699 ViewGroup.LayoutParams.MATCH_PARENT,
700 ViewGroup.LayoutParams.WRAP_CONTENT));
701 } else {
702 mErrorConsoleContainer.removeView(errorConsole);
703 }
704 }
705
706 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800707 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
708 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
709 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 }
711
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 // -------------------------------------------------------------------------
713 // Helper function for WebChromeClient
714 // -------------------------------------------------------------------------
715
716 @Override
717 public Bitmap getDefaultVideoPoster() {
718 if (mDefaultVideoPoster == null) {
719 mDefaultVideoPoster = BitmapFactory.decodeResource(
720 mActivity.getResources(), R.drawable.default_video_poster);
721 }
722 return mDefaultVideoPoster;
723 }
724
725 @Override
726 public View getVideoLoadingProgressView() {
727 if (mVideoProgressView == null) {
728 LayoutInflater inflater = LayoutInflater.from(mActivity);
729 mVideoProgressView = inflater.inflate(
730 R.layout.video_loading_progress, null);
731 }
732 return mVideoProgressView;
733 }
734
Michael Kolb843510f2010-12-09 10:51:49 -0800735 @Override
736 public void showMaxTabsWarning() {
737 Toast warning = Toast.makeText(mActivity,
738 mActivity.getString(R.string.max_tabs_warning),
739 Toast.LENGTH_SHORT);
740 warning.show();
741 }
742
Narayan Kamath5119edd2011-02-23 15:49:17 +0000743 @Override
744 public void registerDropdownChangeListener(DropdownChangeListener d) {
745 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700746}