blob: c3549b3b849510f6a674fc3a9b33893ee6691880 [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 Kolb11d19782011-03-20 10:17:40 -070045import android.webkit.WebSettings.ZoomDensity;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.webkit.WebView;
47import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080048import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.LinearLayout;
50import android.widget.Toast;
51
Michael Kolb1bf23132010-11-19 12:55:12 -080052import java.util.List;
53
Michael Kolb8233fac2010-10-26 16:08:53 -070054/**
55 * UI interface definitions
56 */
Michael Kolb66706532010-12-12 19:50:22 -080057public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070058
59 private static final String LOGTAG = "BaseUi";
60
Michael Kolb66706532010-12-12 19:50:22 -080061 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070062 new FrameLayout.LayoutParams(
63 ViewGroup.LayoutParams.MATCH_PARENT,
64 ViewGroup.LayoutParams.MATCH_PARENT);
65
Michael Kolb66706532010-12-12 19:50:22 -080066 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070067 new FrameLayout.LayoutParams(
68 ViewGroup.LayoutParams.MATCH_PARENT,
69 ViewGroup.LayoutParams.MATCH_PARENT,
70 Gravity.CENTER);
71
72 Activity mActivity;
73 UiController mUiController;
74 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080075 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080076 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070077
78 private Drawable mSecLockIcon;
79 private Drawable mMixLockIcon;
80
Michael Kolb8233fac2010-10-26 16:08:53 -070081 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080082 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070083 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070084
85 private View mCustomView;
86 private WebChromeClient.CustomViewCallback mCustomViewCallback;
87
88 private CombinedBookmarkHistoryView mComboView;
89
90 private LinearLayout mErrorConsoleContainer = null;
91
92 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070093
Michael Kolb7cdc4902011-02-03 17:54:40 -080094 private boolean mTitleShowing;
95
Michael Kolb8233fac2010-10-26 16:08:53 -070096 // the default <video> poster
97 private Bitmap mDefaultVideoPoster;
98 // the video progress view
99 private View mVideoProgressView;
100
Michael Kolb8233fac2010-10-26 16:08:53 -0700101 private boolean mActivityPaused;
102
103 public BaseUi(Activity browser, UiController controller) {
104 mActivity = browser;
105 mUiController = controller;
106 mTabControl = controller.getTabControl();
107 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800108 mInputManager = (InputMethodManager)
109 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800110 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700111 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
112
Michael Kolb8233fac2010-10-26 16:08:53 -0700113 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
114 .getDecorView().findViewById(android.R.id.content);
115 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
116 .inflate(R.layout.custom_screen, null);
117 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
118 R.id.main_content);
119 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
120 .findViewById(R.id.error_console);
121 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
122 .findViewById(R.id.fullscreen_custom_content);
123 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800124 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700125 }
126
John Reckb9a051b2011-03-18 11:55:48 -0700127 @Override
128 public WebView createWebView(boolean privateBrowsing) {
129 // Create a new WebView
130 BrowserWebView w = new BrowserWebView(mActivity, null,
131 android.R.attr.webViewStyle, privateBrowsing);
132 initWebViewSettings(w);
133 return w;
134 }
135
136 @Override
137 public WebView createSubWebView(boolean privateBrowsing) {
138 return createWebView(privateBrowsing);
139 }
140
Michael Kolb66706532010-12-12 19:50:22 -0800141 /**
142 * common webview initialization
143 * @param w the webview to initialize
144 */
145 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700146 w.setScrollbarFadingEnabled(true);
147 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
148 w.setMapTrackballToArrowKeys(false); // use trackball directly
149 // Enable the built-in zoom
150 w.getSettings().setBuiltInZoomControls(true);
John Reckb9a051b2011-03-18 11:55:48 -0700151 boolean supportsMultiTouch = mActivity.getPackageManager()
152 .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
153 w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
154 w.setExpandedTileBounds(true); // smoother scrolling
Michael Kolb8233fac2010-10-26 16:08:53 -0700155
156 // Add this WebView to the settings observer list and update the
157 // settings
158 final BrowserSettings s = BrowserSettings.getInstance();
159 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700160 }
161
162 private void cancelStopToast() {
163 if (mStopToast != null) {
164 mStopToast.cancel();
165 mStopToast = null;
166 }
167 }
168
169 // lifecycle
170
171 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800172 if (isCustomViewShowing()) {
173 onHideCustomView();
174 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700175 cancelStopToast();
176 mActivityPaused = true;
177 }
178
179 public void onResume() {
180 mActivityPaused = false;
181 }
182
Michael Kolb66706532010-12-12 19:50:22 -0800183 protected boolean isActivityPaused() {
184 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700185 }
186
187 public void onConfigurationChanged(Configuration config) {
188 }
189
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800190 public abstract void editUrl(boolean clearInput);
191
Michael Kolb8233fac2010-10-26 16:08:53 -0700192 // key handling
193
194 @Override
195 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 if (mComboView != null) {
197 if (!mComboView.onBackPressed()) {
198 mUiController.removeComboView();
199 }
200 return true;
201 }
202 if (mCustomView != null) {
203 mUiController.hideCustomView();
204 return true;
205 }
206 return false;
207 }
208
John Reck30c714c2010-12-16 17:30:34 -0800209 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700210 @Override
John Reck30c714c2010-12-16 17:30:34 -0800211 public void onTabDataChanged(Tab tab) {
212 setUrlTitle(tab);
213 setFavicon(tab);
214 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800215 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 }
217
218 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500219 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800220 if (tab.inForeground()) {
221 boolean isBookmark = tab.isBookmarkedSite();
222 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
223 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500224 }
225
226 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 public void onPageStopped(Tab tab) {
228 cancelStopToast();
229 if (tab.inForeground()) {
230 mStopToast = Toast
231 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
232 mStopToast.show();
233 }
234 }
235
236 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800237 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800238 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800239 }
240
241 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 }
244
245 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800246 public void setActiveTab(final Tab tab) {
247 setActiveTab(tab, true);
248 }
249
250 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800251 if ((tab != mActiveTab) && (mActiveTab != null)) {
252 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700253 }
Michael Kolb77df4562010-11-19 14:49:34 -0800254 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800255 if (needsAttaching) {
256 attachTabToContentView(tab);
257 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700258 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800259 onTabDataChanged(tab);
260 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800261 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800262 getTitleBar().setIncognitoMode(incognito);
Patrick Scott92066772011-03-10 08:46:27 -0500263 updateAutoLogin(tab, false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700264 }
265
Michael Kolbcfa3af52010-12-14 10:36:11 -0800266 Tab getActiveTab() {
267 return mActiveTab;
268 }
269
Michael Kolb8233fac2010-10-26 16:08:53 -0700270 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800271 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800272 }
273
274 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700275 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800276 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700277 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800278 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700279 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700280 }
281
282 @Override
283 public void detachTab(Tab tab) {
284 removeTabFromContentView(tab);
285 }
286
287 @Override
288 public void attachTab(Tab tab) {
289 attachTabToContentView(tab);
290 }
291
Michael Kolb377ea312011-02-17 14:36:56 -0800292 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800293 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700294 return;
295 }
296 View container = tab.getViewContainer();
297 WebView mainView = tab.getWebView();
298 // Attach the WebView to the container and then attach the
299 // container to the content view.
300 FrameLayout wrapper =
301 (FrameLayout) container.findViewById(R.id.webview_wrapper);
302 ViewGroup parent = (ViewGroup) mainView.getParent();
303 if (parent != wrapper) {
304 if (parent != null) {
305 Log.w(LOGTAG, "mMainView already has a parent in"
306 + " attachTabToContentView!");
307 parent.removeView(mainView);
308 }
309 wrapper.addView(mainView);
310 } else {
311 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
312 + " attachTabToContentView!");
313 }
314 parent = (ViewGroup) container.getParent();
315 if (parent != mContentView) {
316 if (parent != null) {
317 Log.w(LOGTAG, "mContainer already has a parent in"
318 + " attachTabToContentView!");
319 parent.removeView(container);
320 }
321 mContentView.addView(container, COVER_SCREEN_PARAMS);
322 } else {
323 Log.w(LOGTAG, "mContainer is already attached to content in"
324 + " attachTabToContentView!");
325 }
326 mUiController.attachSubWindow(tab);
327 }
328
329 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800330 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700331 // Remove the container that contains the main WebView.
332 WebView mainView = tab.getWebView();
333 View container = tab.getViewContainer();
334 if (mainView == null) {
335 return;
336 }
337 // Remove the container from the content and then remove the
338 // WebView from the container. This will trigger a focus change
339 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800340 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700341 FrameLayout wrapper =
342 (FrameLayout) container.findViewById(R.id.webview_wrapper);
343 wrapper.removeView(mainView);
344 mContentView.removeView(container);
345 mUiController.endActionMode();
346 mUiController.removeSubWindow(tab);
347 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
348 if (errorConsole != null) {
349 mErrorConsoleContainer.removeView(errorConsole);
350 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700351 }
352
Michael Kolba713ec82010-11-29 17:27:06 -0800353 @Override
354 public void onSetWebView(Tab tab, WebView webView) {
355 View container = tab.getViewContainer();
356 if (container == null) {
357 // The tab consists of a container view, which contains the main
358 // WebView, as well as any other UI elements associated with the tab.
359 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
360 null);
361 tab.setViewContainer(container);
362 }
363 if (tab.getWebView() != webView) {
364 // Just remove the old one.
365 FrameLayout wrapper =
366 (FrameLayout) container.findViewById(R.id.webview_wrapper);
367 wrapper.removeView(tab.getWebView());
368 }
369 }
370
Michael Kolb8233fac2010-10-26 16:08:53 -0700371 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800372 * create a sub window container and webview for the tab
373 * Note: this methods operates through side-effects for now
374 * it sets both the subView and subViewContainer for the given tab
375 * @param tab tab to create the sub window for
376 * @param subView webview to be set as a subwindow for the tab
377 */
378 @Override
379 public void createSubWindow(Tab tab, WebView subView) {
380 View subViewContainer = mActivity.getLayoutInflater().inflate(
381 R.layout.browser_subwindow, null);
382 ViewGroup inner = (ViewGroup) subViewContainer
383 .findViewById(R.id.inner_container);
384 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
385 LayoutParams.MATCH_PARENT));
386 final ImageButton cancel = (ImageButton) subViewContainer
387 .findViewById(R.id.subwindow_close);
388 final WebView cancelSubView = subView;
389 cancel.setOnClickListener(new OnClickListener() {
390 public void onClick(View v) {
391 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
392 }
393 });
394 tab.setSubWebView(subView);
395 tab.setSubViewContainer(subViewContainer);
396 }
397
398 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700399 * Remove the sub window from the content view.
400 */
401 @Override
402 public void removeSubWindow(View subviewContainer) {
403 mContentView.removeView(subviewContainer);
404 mUiController.endActionMode();
405 }
406
407 /**
408 * Attach the sub window to the content view.
409 */
410 @Override
411 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800412 if (container.getParent() != null) {
413 // already attached, remove first
414 ((ViewGroup) container.getParent()).removeView(container);
415 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 mContentView.addView(container, COVER_SCREEN_PARAMS);
417 }
418
Michael Kolb11d19782011-03-20 10:17:40 -0700419 protected void refreshWebView() {
420 Tab tab = getActiveTab();
421 if ((tab != null) && (tab.getWebView() != null)) {
422 tab.getWebView().invalidate();
423 }
424 }
425
Michael Kolb7cdc4902011-02-03 17:54:40 -0800426 boolean canShowTitleBar() {
427 return !isTitleBarShowing()
428 && !isActivityPaused()
429 && (getActiveTab() != null)
430 && (getActiveTab().getWebView() != null)
431 && !mUiController.isInCustomActionMode();
432 }
433
434 void showTitleBar() {
435 mTitleShowing = true;
436 }
437
438 protected void hideTitleBar() {
439 mTitleShowing = false;
440 }
441
442 protected boolean isTitleBarShowing() {
443 return mTitleShowing;
444 }
445
446 protected abstract TitleBarBase getTitleBar();
447
448 protected void setTitleGravity(int gravity) {
449 getTitleBar().setTitleGravity(gravity);
450 Tab tab = getActiveTab();
451 if ((tab != null) && (tab.getWebView() != null)) {
452 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700453 }
454 }
455
Michael Kolb66706532010-12-12 19:50:22 -0800456 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700457 public void showVoiceTitleBar(String title, List<String> results) {
458 getTitleBar().setInVoiceMode(true, results);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800459 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700460 }
461
Michael Kolb66706532010-12-12 19:50:22 -0800462 @Override
463 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb11d19782011-03-20 10:17:40 -0700464 getTitleBar().setInVoiceMode(false, null);
John Reck30c714c2010-12-16 17:30:34 -0800465 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800466 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 }
468
469 @Override
Michael Kolb11d19782011-03-20 10:17:40 -0700470 public void registerDropdownChangeListener(DropdownChangeListener d) {
471 getTitleBar().registerDropdownChangeListener(d);
472 }
473
474 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700475 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800476 if (mComboView != null) {
477 return;
478 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700479 mComboView = new CombinedBookmarkHistoryView(mActivity,
480 mUiController,
481 startWithHistory ?
482 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
483 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
484 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800485 FrameLayout wrapper =
486 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
487 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800488 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800489 dismissIME();
490 if (mActiveTab != null) {
491 WebView web = mActiveTab.getWebView();
492 mActiveTab.putInBackground();
493 }
John Reck74830e12011-03-14 11:43:05 -0700494 mComboView.setAlpha(0f);
495 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
496 Resources res = mActivity.getResources();
497 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
498 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700499 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
500 }
501
Michael Kolbba238702011-03-08 10:40:50 -0800502 public boolean isComboViewShowing() {
503 return (mComboView != null);
504 }
505
Michael Kolb8233fac2010-10-26 16:08:53 -0700506 /**
507 * dismiss the ComboPage
508 */
509 @Override
510 public void hideComboView() {
511 if (mComboView != null) {
512 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800513 FrameLayout wrapper =
514 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
515 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700516 mComboView = null;
517 }
Michael Kolb3a696282010-12-05 13:23:24 -0800518 if (mActiveTab != null) {
519 mActiveTab.putInForeground();
520 }
John Reckb3417f02011-01-14 11:01:05 -0800521 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700522 }
523
524 @Override
525 public void showCustomView(View view,
526 WebChromeClient.CustomViewCallback callback) {
527 // if a view already exists then immediately terminate the new one
528 if (mCustomView != null) {
529 callback.onCustomViewHidden();
530 return;
531 }
532
533 // Add the custom view to its container.
534 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
535 mCustomView = view;
536 mCustomViewCallback = callback;
537 // Hide the content view.
538 mContentView.setVisibility(View.GONE);
539 // Finally show the custom view container.
540 setStatusBarVisibility(false);
541 mCustomViewContainer.setVisibility(View.VISIBLE);
542 mCustomViewContainer.bringToFront();
543 }
544
545 @Override
546 public void onHideCustomView() {
547 if (mCustomView == null)
548 return;
549
550 // Hide the custom view.
551 mCustomView.setVisibility(View.GONE);
552 // Remove the custom view from its container.
553 mCustomViewContainer.removeView(mCustomView);
554 mCustomView = null;
555 mCustomViewContainer.setVisibility(View.GONE);
556 mCustomViewCallback.onCustomViewHidden();
557 // Show the content view.
558 setStatusBarVisibility(true);
559 mContentView.setVisibility(View.VISIBLE);
560 }
561
562 @Override
563 public boolean isCustomViewShowing() {
564 return mCustomView != null;
565 }
566
Michael Kolb66706532010-12-12 19:50:22 -0800567 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800568 if (mInputManager.isActive()) {
569 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
570 0);
571 }
572 }
573
Michael Kolb66706532010-12-12 19:50:22 -0800574 @Override
575 public boolean showsWeb() {
576 return mCustomView == null
577 && mComboView == null;
578 }
579
Patrick Scott92066772011-03-10 08:46:27 -0500580 @Override
581 public void showAutoLogin(Tab tab) {
582 updateAutoLogin(tab, true);
583 }
584
585 @Override
586 public void hideAutoLogin(Tab tab) {
587 updateAutoLogin(tab, true);
588 }
589
Michael Kolb8233fac2010-10-26 16:08:53 -0700590 // -------------------------------------------------------------------------
591
Michael Kolb5a72f182011-01-13 20:35:06 -0800592 protected void updateNavigationState(Tab tab) {
593 }
594
Michael Kolb11d19782011-03-20 10:17:40 -0700595 protected void updateAutoLogin(Tab tab, boolean animate) {
596 getTitleBar().updateAutoLogin(tab, animate);
597 }
Patrick Scott92066772011-03-10 08:46:27 -0500598
Michael Kolb8233fac2010-10-26 16:08:53 -0700599 /**
600 * Update the lock icon to correspond to our latest state.
601 */
Michael Kolb66706532010-12-12 19:50:22 -0800602 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800603 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700604 updateLockIconImage(t.getLockIconType());
605 }
606 }
607
608 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 * Updates the lock-icon image in the title-bar.
610 */
John Reck30c714c2010-12-16 17:30:34 -0800611 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800613 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800615 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 d = mMixLockIcon;
617 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800618 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700619 }
620
John Reck30c714c2010-12-16 17:30:34 -0800621 protected void setUrlTitle(Tab tab) {
622 String url = tab.getUrl();
623 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800624 if (TextUtils.isEmpty(title)) {
625 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800626 }
Michael Kolb66706532010-12-12 19:50:22 -0800627 if (tab.isInVoiceSearchMode()) return;
628 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800629 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800630 }
631 }
632
633 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800634 protected void setFavicon(Tab tab) {
635 if (tab.inForeground()) {
636 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800637 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800638 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700639 }
640
641 @Override
642 public void onActionModeFinished(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700643 }
644
Michael Kolb66706532010-12-12 19:50:22 -0800645 // active tabs page
646
647 public void showActiveTabsPage() {
648 }
649
650 /**
651 * Remove the active tabs page.
652 */
653 public void removeActiveTabsPage() {
654 }
655
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 // menu handling callbacks
657
658 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800659 public boolean onPrepareOptionsMenu(Menu menu) {
660 return true;
661 }
662
663 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700664 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700665 }
666
667 @Override
668 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 }
670
671 @Override
672 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700673 }
674
675 @Override
676 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 }
678
679 @Override
680 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700681 }
682
683 @Override
684 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700685 }
686
687 // error console
688
689 @Override
690 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800691 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700692 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
693 if (flag) {
694 // Setting the show state of the console will cause it's the layout
695 // to be inflated.
696 if (errorConsole.numberOfErrors() > 0) {
697 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
698 } else {
699 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
700 }
701 if (errorConsole.getParent() != null) {
702 mErrorConsoleContainer.removeView(errorConsole);
703 }
704 // Now we can add it to the main view.
705 mErrorConsoleContainer.addView(errorConsole,
706 new LinearLayout.LayoutParams(
707 ViewGroup.LayoutParams.MATCH_PARENT,
708 ViewGroup.LayoutParams.WRAP_CONTENT));
709 } else {
710 mErrorConsoleContainer.removeView(errorConsole);
711 }
712 }
713
714 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800715 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
716 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
717 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700718 }
719
Michael Kolb8233fac2010-10-26 16:08:53 -0700720 // -------------------------------------------------------------------------
721 // Helper function for WebChromeClient
722 // -------------------------------------------------------------------------
723
724 @Override
725 public Bitmap getDefaultVideoPoster() {
726 if (mDefaultVideoPoster == null) {
727 mDefaultVideoPoster = BitmapFactory.decodeResource(
728 mActivity.getResources(), R.drawable.default_video_poster);
729 }
730 return mDefaultVideoPoster;
731 }
732
733 @Override
734 public View getVideoLoadingProgressView() {
735 if (mVideoProgressView == null) {
736 LayoutInflater inflater = LayoutInflater.from(mActivity);
737 mVideoProgressView = inflater.inflate(
738 R.layout.video_loading_progress, null);
739 }
740 return mVideoProgressView;
741 }
742
Michael Kolb843510f2010-12-09 10:51:49 -0800743 @Override
744 public void showMaxTabsWarning() {
745 Toast warning = Toast.makeText(mActivity,
746 mActivity.getString(R.string.max_tabs_warning),
747 Toast.LENGTH_SHORT);
748 warning.show();
749 }
750
Michael Kolb8233fac2010-10-26 16:08:53 -0700751}