blob: 5084e319ed91048865d2ac9eca001b67ec337202 [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;
Narayan Kamath5119edd2011-02-23 15:49:17 +000020import com.android.browser.UI.DropdownChangeListener;
John Reck30c714c2010-12-16 17:30:34 -080021
Michael Kolb377ea312011-02-17 14:36:56 -080022import android.animation.Animator;
23import android.animation.Animator.AnimatorListener;
John Reck5289bc32011-02-18 14:38:08 -080024import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.content.res.Configuration;
27import android.content.res.Resources;
28import android.graphics.Bitmap;
29import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.graphics.drawable.Drawable;
31import android.os.Bundle;
32import android.text.TextUtils;
33import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.view.Gravity;
35import android.view.LayoutInflater;
36import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080038import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080040import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080042import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.webkit.WebView;
45import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080046import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070047import android.widget.LinearLayout;
48import android.widget.Toast;
49
Michael Kolb1bf23132010-11-19 12:55:12 -080050import java.util.List;
51
Michael Kolb8233fac2010-10-26 16:08:53 -070052/**
53 * UI interface definitions
54 */
Michael Kolb66706532010-12-12 19:50:22 -080055public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070056
57 private static final String LOGTAG = "BaseUi";
58
Michael Kolb66706532010-12-12 19:50:22 -080059 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070060 new FrameLayout.LayoutParams(
61 ViewGroup.LayoutParams.MATCH_PARENT,
62 ViewGroup.LayoutParams.MATCH_PARENT);
63
Michael Kolb66706532010-12-12 19:50:22 -080064 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070065 new FrameLayout.LayoutParams(
66 ViewGroup.LayoutParams.MATCH_PARENT,
67 ViewGroup.LayoutParams.MATCH_PARENT,
68 Gravity.CENTER);
69
70 Activity mActivity;
71 UiController mUiController;
72 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080073 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080074 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070075
76 private Drawable mSecLockIcon;
77 private Drawable mMixLockIcon;
78
Michael Kolb8233fac2010-10-26 16:08:53 -070079 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080080 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070081 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070082
83 private View mCustomView;
84 private WebChromeClient.CustomViewCallback mCustomViewCallback;
85
86 private CombinedBookmarkHistoryView mComboView;
87
88 private LinearLayout mErrorConsoleContainer = null;
89
90 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb7cdc4902011-02-03 17:54:40 -080092 private boolean mTitleShowing;
93
Michael Kolb8233fac2010-10-26 16:08:53 -070094 // the default <video> poster
95 private Bitmap mDefaultVideoPoster;
96 // the video progress view
97 private View mVideoProgressView;
98
Michael Kolb8233fac2010-10-26 16:08:53 -070099 private boolean mActivityPaused;
100
101 public BaseUi(Activity browser, UiController controller) {
102 mActivity = browser;
103 mUiController = controller;
104 mTabControl = controller.getTabControl();
105 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800106 mInputManager = (InputMethodManager)
107 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800108 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700109 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
110
Michael Kolb8233fac2010-10-26 16:08:53 -0700111 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
112 .getDecorView().findViewById(android.R.id.content);
113 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
114 .inflate(R.layout.custom_screen, null);
115 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
116 R.id.main_content);
117 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
118 .findViewById(R.id.error_console);
119 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
120 .findViewById(R.id.fullscreen_custom_content);
121 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800122 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700123 }
124
Michael Kolb66706532010-12-12 19:50:22 -0800125 /**
126 * common webview initialization
127 * @param w the webview to initialize
128 */
129 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700130 w.setScrollbarFadingEnabled(true);
131 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
132 w.setMapTrackballToArrowKeys(false); // use trackball directly
133 // Enable the built-in zoom
134 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700135
136 // Add this WebView to the settings observer list and update the
137 // settings
138 final BrowserSettings s = BrowserSettings.getInstance();
139 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700140 }
141
142 private void cancelStopToast() {
143 if (mStopToast != null) {
144 mStopToast.cancel();
145 mStopToast = null;
146 }
147 }
148
149 // lifecycle
150
151 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800152 if (isCustomViewShowing()) {
153 onHideCustomView();
154 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700155 cancelStopToast();
156 mActivityPaused = true;
157 }
158
159 public void onResume() {
160 mActivityPaused = false;
161 }
162
Michael Kolb66706532010-12-12 19:50:22 -0800163 protected boolean isActivityPaused() {
164 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700165 }
166
167 public void onConfigurationChanged(Configuration config) {
168 }
169
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800170 public abstract void editUrl(boolean clearInput);
171
Michael Kolb8233fac2010-10-26 16:08:53 -0700172 // key handling
173
174 @Override
175 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700176 if (mComboView != null) {
177 if (!mComboView.onBackPressed()) {
178 mUiController.removeComboView();
179 }
180 return true;
181 }
182 if (mCustomView != null) {
183 mUiController.hideCustomView();
184 return true;
185 }
186 return false;
187 }
188
John Reck30c714c2010-12-16 17:30:34 -0800189 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 @Override
John Reck30c714c2010-12-16 17:30:34 -0800191 public void onTabDataChanged(Tab tab) {
192 setUrlTitle(tab);
193 setFavicon(tab);
194 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800195 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 }
197
198 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500199 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800200 if (tab.inForeground()) {
201 boolean isBookmark = tab.isBookmarkedSite();
202 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
203 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500204 }
205
206 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 public void onPageStopped(Tab tab) {
208 cancelStopToast();
209 if (tab.inForeground()) {
210 mStopToast = Toast
211 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
212 mStopToast.show();
213 }
214 }
215
216 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800217 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800218 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800219 }
220
221 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700222 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 }
224
225 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800226 public void setActiveTab(final Tab tab) {
227 setActiveTab(tab, true);
228 }
229
230 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800231 if ((tab != mActiveTab) && (mActiveTab != null)) {
232 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 }
Michael Kolb77df4562010-11-19 14:49:34 -0800234 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800235 if (needsAttaching) {
236 attachTabToContentView(tab);
237 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800239 onTabDataChanged(tab);
240 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800241 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800242 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700243 }
244
Michael Kolbcfa3af52010-12-14 10:36:11 -0800245 Tab getActiveTab() {
246 return mActiveTab;
247 }
248
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800250 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800251 }
252
253 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800255 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800257 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700258 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 }
260
261 @Override
262 public void detachTab(Tab tab) {
263 removeTabFromContentView(tab);
264 }
265
266 @Override
267 public void attachTab(Tab tab) {
268 attachTabToContentView(tab);
269 }
270
Michael Kolb377ea312011-02-17 14:36:56 -0800271 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800272 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700273 return;
274 }
275 View container = tab.getViewContainer();
276 WebView mainView = tab.getWebView();
277 // Attach the WebView to the container and then attach the
278 // container to the content view.
279 FrameLayout wrapper =
280 (FrameLayout) container.findViewById(R.id.webview_wrapper);
281 ViewGroup parent = (ViewGroup) mainView.getParent();
282 if (parent != wrapper) {
283 if (parent != null) {
284 Log.w(LOGTAG, "mMainView already has a parent in"
285 + " attachTabToContentView!");
286 parent.removeView(mainView);
287 }
288 wrapper.addView(mainView);
289 } else {
290 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
291 + " attachTabToContentView!");
292 }
293 parent = (ViewGroup) container.getParent();
294 if (parent != mContentView) {
295 if (parent != null) {
296 Log.w(LOGTAG, "mContainer already has a parent in"
297 + " attachTabToContentView!");
298 parent.removeView(container);
299 }
300 mContentView.addView(container, COVER_SCREEN_PARAMS);
301 } else {
302 Log.w(LOGTAG, "mContainer is already attached to content in"
303 + " attachTabToContentView!");
304 }
Michael Kolba4183062011-01-16 10:43:21 -0800305 mainView.setNextFocusUpId(R.id.url_focused);
306 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700307 mUiController.attachSubWindow(tab);
308 }
309
310 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800311 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700312 // Remove the container that contains the main WebView.
313 WebView mainView = tab.getWebView();
314 View container = tab.getViewContainer();
315 if (mainView == null) {
316 return;
317 }
318 // Remove the container from the content and then remove the
319 // WebView from the container. This will trigger a focus change
320 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800321 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700322 FrameLayout wrapper =
323 (FrameLayout) container.findViewById(R.id.webview_wrapper);
324 wrapper.removeView(mainView);
325 mContentView.removeView(container);
326 mUiController.endActionMode();
327 mUiController.removeSubWindow(tab);
328 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
329 if (errorConsole != null) {
330 mErrorConsoleContainer.removeView(errorConsole);
331 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 }
333
Michael Kolba713ec82010-11-29 17:27:06 -0800334 @Override
335 public void onSetWebView(Tab tab, WebView webView) {
336 View container = tab.getViewContainer();
337 if (container == null) {
338 // The tab consists of a container view, which contains the main
339 // WebView, as well as any other UI elements associated with the tab.
340 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
341 null);
342 tab.setViewContainer(container);
343 }
344 if (tab.getWebView() != webView) {
345 // Just remove the old one.
346 FrameLayout wrapper =
347 (FrameLayout) container.findViewById(R.id.webview_wrapper);
348 wrapper.removeView(tab.getWebView());
349 }
350 }
351
Michael Kolb8233fac2010-10-26 16:08:53 -0700352 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800353 * create a sub window container and webview for the tab
354 * Note: this methods operates through side-effects for now
355 * it sets both the subView and subViewContainer for the given tab
356 * @param tab tab to create the sub window for
357 * @param subView webview to be set as a subwindow for the tab
358 */
359 @Override
360 public void createSubWindow(Tab tab, WebView subView) {
361 View subViewContainer = mActivity.getLayoutInflater().inflate(
362 R.layout.browser_subwindow, null);
363 ViewGroup inner = (ViewGroup) subViewContainer
364 .findViewById(R.id.inner_container);
365 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
366 LayoutParams.MATCH_PARENT));
367 final ImageButton cancel = (ImageButton) subViewContainer
368 .findViewById(R.id.subwindow_close);
369 final WebView cancelSubView = subView;
370 cancel.setOnClickListener(new OnClickListener() {
371 public void onClick(View v) {
372 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
373 }
374 });
375 tab.setSubWebView(subView);
376 tab.setSubViewContainer(subViewContainer);
377 }
378
379 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 * Remove the sub window from the content view.
381 */
382 @Override
383 public void removeSubWindow(View subviewContainer) {
384 mContentView.removeView(subviewContainer);
385 mUiController.endActionMode();
386 }
387
388 /**
389 * Attach the sub window to the content view.
390 */
391 @Override
392 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800393 if (container.getParent() != null) {
394 // already attached, remove first
395 ((ViewGroup) container.getParent()).removeView(container);
396 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700397 mContentView.addView(container, COVER_SCREEN_PARAMS);
398 }
399
Michael Kolb7cdc4902011-02-03 17:54:40 -0800400 boolean canShowTitleBar() {
401 return !isTitleBarShowing()
402 && !isActivityPaused()
403 && (getActiveTab() != null)
404 && (getActiveTab().getWebView() != null)
405 && !mUiController.isInCustomActionMode();
406 }
407
408 void showTitleBar() {
409 mTitleShowing = true;
410 }
411
412 protected void hideTitleBar() {
413 mTitleShowing = false;
414 }
415
416 protected boolean isTitleBarShowing() {
417 return mTitleShowing;
418 }
419
420 protected abstract TitleBarBase getTitleBar();
421
422 protected void setTitleGravity(int gravity) {
423 getTitleBar().setTitleGravity(gravity);
424 Tab tab = getActiveTab();
425 if ((tab != null) && (tab.getWebView() != null)) {
426 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700427 }
428 }
429
Michael Kolb66706532010-12-12 19:50:22 -0800430 @Override
431 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800432 getTitleBar().setInVoiceMode(true);
433 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700434 }
435
Michael Kolb66706532010-12-12 19:50:22 -0800436 @Override
437 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800438 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800439 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800440 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700441 }
442
443 @Override
444 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800445 if (mComboView != null) {
446 return;
447 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700448 mComboView = new CombinedBookmarkHistoryView(mActivity,
449 mUiController,
450 startWithHistory ?
451 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
452 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
453 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800454 FrameLayout wrapper =
455 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
456 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800457 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800458 dismissIME();
459 if (mActiveTab != null) {
460 WebView web = mActiveTab.getWebView();
461 mActiveTab.putInBackground();
462 }
John Reck5289bc32011-02-18 14:38:08 -0800463 mComboView.setAlpha(0f);
464 ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
465 Resources res = mActivity.getResources();
466 anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
467 anim.start();
Michael Kolb8233fac2010-10-26 16:08:53 -0700468 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
469 }
470
Michael Kolbba238702011-03-08 10:40:50 -0800471 public boolean isComboViewShowing() {
472 return (mComboView != null);
473 }
474
Michael Kolb8233fac2010-10-26 16:08:53 -0700475 /**
476 * dismiss the ComboPage
477 */
478 @Override
479 public void hideComboView() {
480 if (mComboView != null) {
481 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800482 FrameLayout wrapper =
483 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
484 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700485 mComboView = null;
486 }
Michael Kolb3a696282010-12-05 13:23:24 -0800487 if (mActiveTab != null) {
488 mActiveTab.putInForeground();
489 }
John Reckb3417f02011-01-14 11:01:05 -0800490 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700491 }
492
493 @Override
494 public void showCustomView(View view,
495 WebChromeClient.CustomViewCallback callback) {
496 // if a view already exists then immediately terminate the new one
497 if (mCustomView != null) {
498 callback.onCustomViewHidden();
499 return;
500 }
501
502 // Add the custom view to its container.
503 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
504 mCustomView = view;
505 mCustomViewCallback = callback;
506 // Hide the content view.
507 mContentView.setVisibility(View.GONE);
508 // Finally show the custom view container.
509 setStatusBarVisibility(false);
510 mCustomViewContainer.setVisibility(View.VISIBLE);
511 mCustomViewContainer.bringToFront();
512 }
513
514 @Override
515 public void onHideCustomView() {
516 if (mCustomView == null)
517 return;
518
519 // Hide the custom view.
520 mCustomView.setVisibility(View.GONE);
521 // Remove the custom view from its container.
522 mCustomViewContainer.removeView(mCustomView);
523 mCustomView = null;
524 mCustomViewContainer.setVisibility(View.GONE);
525 mCustomViewCallback.onCustomViewHidden();
526 // Show the content view.
527 setStatusBarVisibility(true);
528 mContentView.setVisibility(View.VISIBLE);
529 }
530
531 @Override
532 public boolean isCustomViewShowing() {
533 return mCustomView != null;
534 }
535
Michael Kolb66706532010-12-12 19:50:22 -0800536 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800537 if (mInputManager.isActive()) {
538 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
539 0);
540 }
541 }
542
Michael Kolb66706532010-12-12 19:50:22 -0800543 @Override
544 public boolean showsWeb() {
545 return mCustomView == null
546 && mComboView == null;
547 }
548
Michael Kolb8233fac2010-10-26 16:08:53 -0700549 // -------------------------------------------------------------------------
550
Michael Kolb5a72f182011-01-13 20:35:06 -0800551 protected void updateNavigationState(Tab tab) {
552 }
553
Michael Kolb8233fac2010-10-26 16:08:53 -0700554 /**
555 * Update the lock icon to correspond to our latest state.
556 */
Michael Kolb66706532010-12-12 19:50:22 -0800557 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800558 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700559 updateLockIconImage(t.getLockIconType());
560 }
561 }
562
563 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700564 * Updates the lock-icon image in the title-bar.
565 */
John Reck30c714c2010-12-16 17:30:34 -0800566 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700567 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800568 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700569 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800570 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700571 d = mMixLockIcon;
572 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800573 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700574 }
575
John Reck30c714c2010-12-16 17:30:34 -0800576 protected void setUrlTitle(Tab tab) {
577 String url = tab.getUrl();
578 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800579 if (TextUtils.isEmpty(title)) {
580 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800581 }
Michael Kolb66706532010-12-12 19:50:22 -0800582 if (tab.isInVoiceSearchMode()) return;
583 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800584 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800585 }
586 }
587
588 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800589 protected void setFavicon(Tab tab) {
590 if (tab.inForeground()) {
591 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800592 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800593 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700594 }
595
596 @Override
597 public void onActionModeFinished(boolean inLoad) {
598 if (inLoad) {
599 // the titlebar was removed when the CAB was shown
600 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800601 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 }
603 }
604
Michael Kolb66706532010-12-12 19:50:22 -0800605 // active tabs page
606
607 public void showActiveTabsPage() {
608 }
609
610 /**
611 * Remove the active tabs page.
612 */
613 public void removeActiveTabsPage() {
614 }
615
Michael Kolb8233fac2010-10-26 16:08:53 -0700616 // menu handling callbacks
617
618 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800619 public boolean onPrepareOptionsMenu(Menu menu) {
620 return true;
621 }
622
623 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700624 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 }
626
627 @Override
628 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700629 }
630
631 @Override
632 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700633 }
634
635 @Override
636 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700637 }
638
639 @Override
640 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700641 }
642
643 @Override
644 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700645 }
646
647 // error console
648
649 @Override
650 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800651 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700652 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
653 if (flag) {
654 // Setting the show state of the console will cause it's the layout
655 // to be inflated.
656 if (errorConsole.numberOfErrors() > 0) {
657 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
658 } else {
659 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
660 }
661 if (errorConsole.getParent() != null) {
662 mErrorConsoleContainer.removeView(errorConsole);
663 }
664 // Now we can add it to the main view.
665 mErrorConsoleContainer.addView(errorConsole,
666 new LinearLayout.LayoutParams(
667 ViewGroup.LayoutParams.MATCH_PARENT,
668 ViewGroup.LayoutParams.WRAP_CONTENT));
669 } else {
670 mErrorConsoleContainer.removeView(errorConsole);
671 }
672 }
673
674 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800675 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
676 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
677 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700678 }
679
Michael Kolb8233fac2010-10-26 16:08:53 -0700680 // -------------------------------------------------------------------------
681 // Helper function for WebChromeClient
682 // -------------------------------------------------------------------------
683
684 @Override
685 public Bitmap getDefaultVideoPoster() {
686 if (mDefaultVideoPoster == null) {
687 mDefaultVideoPoster = BitmapFactory.decodeResource(
688 mActivity.getResources(), R.drawable.default_video_poster);
689 }
690 return mDefaultVideoPoster;
691 }
692
693 @Override
694 public View getVideoLoadingProgressView() {
695 if (mVideoProgressView == null) {
696 LayoutInflater inflater = LayoutInflater.from(mActivity);
697 mVideoProgressView = inflater.inflate(
698 R.layout.video_loading_progress, null);
699 }
700 return mVideoProgressView;
701 }
702
Michael Kolb843510f2010-12-09 10:51:49 -0800703 @Override
704 public void showMaxTabsWarning() {
705 Toast warning = Toast.makeText(mActivity,
706 mActivity.getString(R.string.max_tabs_warning),
707 Toast.LENGTH_SHORT);
708 warning.show();
709 }
710
Narayan Kamath5119edd2011-02-23 15:49:17 +0000711 @Override
712 public void registerDropdownChangeListener(DropdownChangeListener d) {
713 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700714}