blob: 93b0ec89f2f89883c6c7f052b5a3c30ab80aa651 [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;
20
Michael Kolb377ea312011-02-17 14:36:56 -080021import android.animation.Animator;
22import android.animation.Animator.AnimatorListener;
John Reck5289bc32011-02-18 14:38:08 -080023import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070024import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.res.Configuration;
26import android.content.res.Resources;
27import android.graphics.Bitmap;
28import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070029import android.graphics.drawable.Drawable;
30import android.os.Bundle;
31import android.text.TextUtils;
32import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.view.Gravity;
34import android.view.LayoutInflater;
35import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080037import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080039import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080041import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.webkit.WebView;
44import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080045import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.widget.LinearLayout;
47import android.widget.Toast;
48
Michael Kolb1bf23132010-11-19 12:55:12 -080049import java.util.List;
50
Michael Kolb8233fac2010-10-26 16:08:53 -070051/**
52 * UI interface definitions
53 */
Michael Kolb66706532010-12-12 19:50:22 -080054public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070055
56 private static final String LOGTAG = "BaseUi";
57
Michael Kolb66706532010-12-12 19:50:22 -080058 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070059 new FrameLayout.LayoutParams(
60 ViewGroup.LayoutParams.MATCH_PARENT,
61 ViewGroup.LayoutParams.MATCH_PARENT);
62
Michael Kolb66706532010-12-12 19:50:22 -080063 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070064 new FrameLayout.LayoutParams(
65 ViewGroup.LayoutParams.MATCH_PARENT,
66 ViewGroup.LayoutParams.MATCH_PARENT,
67 Gravity.CENTER);
68
69 Activity mActivity;
70 UiController mUiController;
71 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080072 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080073 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070074
75 private Drawable mSecLockIcon;
76 private Drawable mMixLockIcon;
77
Michael Kolb8233fac2010-10-26 16:08:53 -070078 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080079 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070080 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070081
82 private View mCustomView;
83 private WebChromeClient.CustomViewCallback mCustomViewCallback;
84
85 private CombinedBookmarkHistoryView mComboView;
86
87 private LinearLayout mErrorConsoleContainer = null;
88
89 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070090
Michael Kolb7cdc4902011-02-03 17:54:40 -080091 private boolean mTitleShowing;
92
Michael Kolb8233fac2010-10-26 16:08:53 -070093 // the default <video> poster
94 private Bitmap mDefaultVideoPoster;
95 // the video progress view
96 private View mVideoProgressView;
97
Michael Kolb8233fac2010-10-26 16:08:53 -070098 private boolean mActivityPaused;
99
100 public BaseUi(Activity browser, UiController controller) {
101 mActivity = browser;
102 mUiController = controller;
103 mTabControl = controller.getTabControl();
104 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800105 mInputManager = (InputMethodManager)
106 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800107 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
109
Michael Kolb8233fac2010-10-26 16:08:53 -0700110 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
111 .getDecorView().findViewById(android.R.id.content);
112 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
113 .inflate(R.layout.custom_screen, null);
114 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
115 R.id.main_content);
116 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
117 .findViewById(R.id.error_console);
118 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
119 .findViewById(R.id.fullscreen_custom_content);
120 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800121 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700122 }
123
Michael Kolb66706532010-12-12 19:50:22 -0800124 /**
125 * common webview initialization
126 * @param w the webview to initialize
127 */
128 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700129 w.setScrollbarFadingEnabled(true);
130 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
131 w.setMapTrackballToArrowKeys(false); // use trackball directly
132 // Enable the built-in zoom
133 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700134
135 // Add this WebView to the settings observer list and update the
136 // settings
137 final BrowserSettings s = BrowserSettings.getInstance();
138 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700139 }
140
141 private void cancelStopToast() {
142 if (mStopToast != null) {
143 mStopToast.cancel();
144 mStopToast = null;
145 }
146 }
147
148 // lifecycle
149
150 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800151 if (isCustomViewShowing()) {
152 onHideCustomView();
153 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700154 cancelStopToast();
155 mActivityPaused = true;
156 }
157
158 public void onResume() {
159 mActivityPaused = false;
160 }
161
Michael Kolb66706532010-12-12 19:50:22 -0800162 protected boolean isActivityPaused() {
163 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700164 }
165
166 public void onConfigurationChanged(Configuration config) {
167 }
168
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800169 public abstract void editUrl(boolean clearInput);
170
Michael Kolb8233fac2010-10-26 16:08:53 -0700171 // key handling
172
173 @Override
174 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700175 if (mComboView != null) {
176 if (!mComboView.onBackPressed()) {
177 mUiController.removeComboView();
178 }
179 return true;
180 }
181 if (mCustomView != null) {
182 mUiController.hideCustomView();
183 return true;
184 }
185 return false;
186 }
187
John Reck30c714c2010-12-16 17:30:34 -0800188 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 @Override
John Reck30c714c2010-12-16 17:30:34 -0800190 public void onTabDataChanged(Tab tab) {
191 setUrlTitle(tab);
192 setFavicon(tab);
193 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800194 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700195 }
196
197 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500198 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800199 if (tab.inForeground()) {
200 boolean isBookmark = tab.isBookmarkedSite();
201 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
202 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500203 }
204
205 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700206 public void onPageStopped(Tab tab) {
207 cancelStopToast();
208 if (tab.inForeground()) {
209 mStopToast = Toast
210 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
211 mStopToast.show();
212 }
213 }
214
215 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800216 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800217 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800218 }
219
220 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 }
223
224 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800225 public void setActiveTab(final Tab tab) {
226 setActiveTab(tab, true);
227 }
228
229 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800230 if ((tab != mActiveTab) && (mActiveTab != null)) {
231 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700232 }
Michael Kolb77df4562010-11-19 14:49:34 -0800233 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800234 if (needsAttaching) {
235 attachTabToContentView(tab);
236 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700237 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800238 onTabDataChanged(tab);
239 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800240 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800241 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700242 }
243
Michael Kolbcfa3af52010-12-14 10:36:11 -0800244 Tab getActiveTab() {
245 return mActiveTab;
246 }
247
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800249 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800250 }
251
252 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700253 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800254 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800256 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700258 }
259
260 @Override
261 public void detachTab(Tab tab) {
262 removeTabFromContentView(tab);
263 }
264
265 @Override
266 public void attachTab(Tab tab) {
267 attachTabToContentView(tab);
268 }
269
Michael Kolb377ea312011-02-17 14:36:56 -0800270 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800271 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 return;
273 }
274 View container = tab.getViewContainer();
275 WebView mainView = tab.getWebView();
276 // Attach the WebView to the container and then attach the
277 // container to the content view.
278 FrameLayout wrapper =
279 (FrameLayout) container.findViewById(R.id.webview_wrapper);
280 ViewGroup parent = (ViewGroup) mainView.getParent();
281 if (parent != wrapper) {
282 if (parent != null) {
283 Log.w(LOGTAG, "mMainView already has a parent in"
284 + " attachTabToContentView!");
285 parent.removeView(mainView);
286 }
287 wrapper.addView(mainView);
288 } else {
289 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
290 + " attachTabToContentView!");
291 }
292 parent = (ViewGroup) container.getParent();
293 if (parent != mContentView) {
294 if (parent != null) {
295 Log.w(LOGTAG, "mContainer already has a parent in"
296 + " attachTabToContentView!");
297 parent.removeView(container);
298 }
299 mContentView.addView(container, COVER_SCREEN_PARAMS);
300 } else {
301 Log.w(LOGTAG, "mContainer is already attached to content in"
302 + " attachTabToContentView!");
303 }
Michael Kolba4183062011-01-16 10:43:21 -0800304 mainView.setNextFocusUpId(R.id.url_focused);
305 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700306 mUiController.attachSubWindow(tab);
307 }
308
309 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800310 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700311 // Remove the container that contains the main WebView.
312 WebView mainView = tab.getWebView();
313 View container = tab.getViewContainer();
314 if (mainView == null) {
315 return;
316 }
317 // Remove the container from the content and then remove the
318 // WebView from the container. This will trigger a focus change
319 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800320 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700321 FrameLayout wrapper =
322 (FrameLayout) container.findViewById(R.id.webview_wrapper);
323 wrapper.removeView(mainView);
324 mContentView.removeView(container);
325 mUiController.endActionMode();
326 mUiController.removeSubWindow(tab);
327 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
328 if (errorConsole != null) {
329 mErrorConsoleContainer.removeView(errorConsole);
330 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700331 }
332
Michael Kolba713ec82010-11-29 17:27:06 -0800333 @Override
334 public void onSetWebView(Tab tab, WebView webView) {
335 View container = tab.getViewContainer();
336 if (container == null) {
337 // The tab consists of a container view, which contains the main
338 // WebView, as well as any other UI elements associated with the tab.
339 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
340 null);
341 tab.setViewContainer(container);
342 }
343 if (tab.getWebView() != webView) {
344 // Just remove the old one.
345 FrameLayout wrapper =
346 (FrameLayout) container.findViewById(R.id.webview_wrapper);
347 wrapper.removeView(tab.getWebView());
348 }
349 }
350
Michael Kolb8233fac2010-10-26 16:08:53 -0700351 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800352 * create a sub window container and webview for the tab
353 * Note: this methods operates through side-effects for now
354 * it sets both the subView and subViewContainer for the given tab
355 * @param tab tab to create the sub window for
356 * @param subView webview to be set as a subwindow for the tab
357 */
358 @Override
359 public void createSubWindow(Tab tab, WebView subView) {
360 View subViewContainer = mActivity.getLayoutInflater().inflate(
361 R.layout.browser_subwindow, null);
362 ViewGroup inner = (ViewGroup) subViewContainer
363 .findViewById(R.id.inner_container);
364 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
365 LayoutParams.MATCH_PARENT));
366 final ImageButton cancel = (ImageButton) subViewContainer
367 .findViewById(R.id.subwindow_close);
368 final WebView cancelSubView = subView;
369 cancel.setOnClickListener(new OnClickListener() {
370 public void onClick(View v) {
371 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
372 }
373 });
374 tab.setSubWebView(subView);
375 tab.setSubViewContainer(subViewContainer);
376 }
377
378 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 * Remove the sub window from the content view.
380 */
381 @Override
382 public void removeSubWindow(View subviewContainer) {
383 mContentView.removeView(subviewContainer);
384 mUiController.endActionMode();
385 }
386
387 /**
388 * Attach the sub window to the content view.
389 */
390 @Override
391 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800392 if (container.getParent() != null) {
393 // already attached, remove first
394 ((ViewGroup) container.getParent()).removeView(container);
395 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700396 mContentView.addView(container, COVER_SCREEN_PARAMS);
397 }
398
Michael Kolb7cdc4902011-02-03 17:54:40 -0800399 boolean canShowTitleBar() {
400 return !isTitleBarShowing()
401 && !isActivityPaused()
402 && (getActiveTab() != null)
403 && (getActiveTab().getWebView() != null)
404 && !mUiController.isInCustomActionMode();
405 }
406
407 void showTitleBar() {
408 mTitleShowing = true;
409 }
410
411 protected void hideTitleBar() {
412 mTitleShowing = false;
413 }
414
415 protected boolean isTitleBarShowing() {
416 return mTitleShowing;
417 }
418
419 protected abstract TitleBarBase getTitleBar();
420
421 protected void setTitleGravity(int gravity) {
422 getTitleBar().setTitleGravity(gravity);
423 Tab tab = getActiveTab();
424 if ((tab != null) && (tab.getWebView() != null)) {
425 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 }
427 }
428
Michael Kolb66706532010-12-12 19:50:22 -0800429 @Override
430 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800431 getTitleBar().setInVoiceMode(true);
432 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700433 }
434
Michael Kolb66706532010-12-12 19:50:22 -0800435 @Override
436 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800437 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800438 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800439 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700440 }
441
442 @Override
443 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800444 if (mComboView != null) {
445 return;
446 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700447 mComboView = new CombinedBookmarkHistoryView(mActivity,
448 mUiController,
449 startWithHistory ?
450 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
451 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
452 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800453 FrameLayout wrapper =
454 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
455 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800456 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800457 dismissIME();
458 if (mActiveTab != null) {
459 WebView web = mActiveTab.getWebView();
460 mActiveTab.putInBackground();
461 }
John Reck5289bc32011-02-18 14:38:08 -0800462 mComboView.setAlpha(0f);
463 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
464 Resources res = mActivity.getResources();
465 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
466 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700467 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
468 }
469
470 /**
471 * dismiss the ComboPage
472 */
473 @Override
474 public void hideComboView() {
475 if (mComboView != null) {
476 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800477 FrameLayout wrapper =
478 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
479 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700480 mComboView = null;
481 }
Michael Kolb3a696282010-12-05 13:23:24 -0800482 if (mActiveTab != null) {
483 mActiveTab.putInForeground();
484 }
John Reckb3417f02011-01-14 11:01:05 -0800485 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700486 }
487
488 @Override
489 public void showCustomView(View view,
490 WebChromeClient.CustomViewCallback callback) {
491 // if a view already exists then immediately terminate the new one
492 if (mCustomView != null) {
493 callback.onCustomViewHidden();
494 return;
495 }
496
497 // Add the custom view to its container.
498 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
499 mCustomView = view;
500 mCustomViewCallback = callback;
501 // Hide the content view.
502 mContentView.setVisibility(View.GONE);
503 // Finally show the custom view container.
504 setStatusBarVisibility(false);
505 mCustomViewContainer.setVisibility(View.VISIBLE);
506 mCustomViewContainer.bringToFront();
507 }
508
509 @Override
510 public void onHideCustomView() {
511 if (mCustomView == null)
512 return;
513
514 // Hide the custom view.
515 mCustomView.setVisibility(View.GONE);
516 // Remove the custom view from its container.
517 mCustomViewContainer.removeView(mCustomView);
518 mCustomView = null;
519 mCustomViewContainer.setVisibility(View.GONE);
520 mCustomViewCallback.onCustomViewHidden();
521 // Show the content view.
522 setStatusBarVisibility(true);
523 mContentView.setVisibility(View.VISIBLE);
524 }
525
526 @Override
527 public boolean isCustomViewShowing() {
528 return mCustomView != null;
529 }
530
Michael Kolb66706532010-12-12 19:50:22 -0800531 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800532 if (mInputManager.isActive()) {
533 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
534 0);
535 }
536 }
537
Michael Kolb66706532010-12-12 19:50:22 -0800538 @Override
539 public boolean showsWeb() {
540 return mCustomView == null
541 && mComboView == null;
542 }
543
Michael Kolb8233fac2010-10-26 16:08:53 -0700544 // -------------------------------------------------------------------------
545
Michael Kolb5a72f182011-01-13 20:35:06 -0800546 protected void updateNavigationState(Tab tab) {
547 }
548
Michael Kolb8233fac2010-10-26 16:08:53 -0700549 /**
550 * Update the lock icon to correspond to our latest state.
551 */
Michael Kolb66706532010-12-12 19:50:22 -0800552 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800553 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700554 updateLockIconImage(t.getLockIconType());
555 }
556 }
557
558 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700559 * Updates the lock-icon image in the title-bar.
560 */
John Reck30c714c2010-12-16 17:30:34 -0800561 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700562 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800563 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700564 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800565 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700566 d = mMixLockIcon;
567 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800568 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700569 }
570
John Reck30c714c2010-12-16 17:30:34 -0800571 protected void setUrlTitle(Tab tab) {
572 String url = tab.getUrl();
573 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800574 if (TextUtils.isEmpty(title)) {
575 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800576 }
Michael Kolb66706532010-12-12 19:50:22 -0800577 if (tab.isInVoiceSearchMode()) return;
578 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800579 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800580 }
581 }
582
583 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800584 protected void setFavicon(Tab tab) {
585 if (tab.inForeground()) {
586 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800587 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800588 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700589 }
590
591 @Override
592 public void onActionModeFinished(boolean inLoad) {
593 if (inLoad) {
594 // the titlebar was removed when the CAB was shown
595 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800596 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700597 }
598 }
599
Michael Kolb66706532010-12-12 19:50:22 -0800600 // active tabs page
601
602 public void showActiveTabsPage() {
603 }
604
605 /**
606 * Remove the active tabs page.
607 */
608 public void removeActiveTabsPage() {
609 }
610
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 // menu handling callbacks
612
613 @Override
614 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700615 }
616
617 @Override
618 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700619 }
620
621 @Override
622 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700623 }
624
625 @Override
626 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700627 }
628
629 @Override
630 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700631 }
632
633 @Override
634 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 }
636
637 // error console
638
639 @Override
640 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800641 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700642 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
643 if (flag) {
644 // Setting the show state of the console will cause it's the layout
645 // to be inflated.
646 if (errorConsole.numberOfErrors() > 0) {
647 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
648 } else {
649 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
650 }
651 if (errorConsole.getParent() != null) {
652 mErrorConsoleContainer.removeView(errorConsole);
653 }
654 // Now we can add it to the main view.
655 mErrorConsoleContainer.addView(errorConsole,
656 new LinearLayout.LayoutParams(
657 ViewGroup.LayoutParams.MATCH_PARENT,
658 ViewGroup.LayoutParams.WRAP_CONTENT));
659 } else {
660 mErrorConsoleContainer.removeView(errorConsole);
661 }
662 }
663
664 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800665 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
666 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
667 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 }
669
Michael Kolb8233fac2010-10-26 16:08:53 -0700670 // -------------------------------------------------------------------------
671 // Helper function for WebChromeClient
672 // -------------------------------------------------------------------------
673
674 @Override
675 public Bitmap getDefaultVideoPoster() {
676 if (mDefaultVideoPoster == null) {
677 mDefaultVideoPoster = BitmapFactory.decodeResource(
678 mActivity.getResources(), R.drawable.default_video_poster);
679 }
680 return mDefaultVideoPoster;
681 }
682
683 @Override
684 public View getVideoLoadingProgressView() {
685 if (mVideoProgressView == null) {
686 LayoutInflater inflater = LayoutInflater.from(mActivity);
687 mVideoProgressView = inflater.inflate(
688 R.layout.video_loading_progress, null);
689 }
690 return mVideoProgressView;
691 }
692
Michael Kolb843510f2010-12-09 10:51:49 -0800693 @Override
694 public void showMaxTabsWarning() {
695 Toast warning = Toast.makeText(mActivity,
696 mActivity.getString(R.string.max_tabs_warning),
697 Toast.LENGTH_SHORT);
698 warning.show();
699 }
700
Michael Kolb8233fac2010-10-26 16:08:53 -0700701}