blob: e89012fdf87930082f1d8dade00eafc24e391b08 [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
John Recke5c21d92011-03-11 15:09:46 -080021import android.animation.LayoutTransition;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.content.res.Configuration;
24import android.content.res.Resources;
25import android.graphics.Bitmap;
26import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070027import android.graphics.drawable.Drawable;
28import android.os.Bundle;
29import android.text.TextUtils;
30import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.view.Gravity;
32import android.view.LayoutInflater;
33import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080035import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080037import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070038import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080039import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.webkit.WebView;
42import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080043import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.widget.LinearLayout;
45import android.widget.Toast;
46
Michael Kolb1bf23132010-11-19 12:55:12 -080047import java.util.List;
48
Michael Kolb8233fac2010-10-26 16:08:53 -070049/**
50 * UI interface definitions
51 */
Michael Kolb66706532010-12-12 19:50:22 -080052public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070053
54 private static final String LOGTAG = "BaseUi";
55
Michael Kolb66706532010-12-12 19:50:22 -080056 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070057 new FrameLayout.LayoutParams(
58 ViewGroup.LayoutParams.MATCH_PARENT,
59 ViewGroup.LayoutParams.MATCH_PARENT);
60
Michael Kolb66706532010-12-12 19:50:22 -080061 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070062 new FrameLayout.LayoutParams(
63 ViewGroup.LayoutParams.MATCH_PARENT,
64 ViewGroup.LayoutParams.MATCH_PARENT,
65 Gravity.CENTER);
66
67 Activity mActivity;
68 UiController mUiController;
69 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080070 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080071 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070072
73 private Drawable mSecLockIcon;
74 private Drawable mMixLockIcon;
75
Michael Kolb8233fac2010-10-26 16:08:53 -070076 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080077 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070078 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070079
80 private View mCustomView;
81 private WebChromeClient.CustomViewCallback mCustomViewCallback;
82
83 private CombinedBookmarkHistoryView mComboView;
84
85 private LinearLayout mErrorConsoleContainer = null;
86
87 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070088
Michael Kolb7cdc4902011-02-03 17:54:40 -080089 private boolean mTitleShowing;
90
Michael Kolb8233fac2010-10-26 16:08:53 -070091 // the default <video> poster
92 private Bitmap mDefaultVideoPoster;
93 // the video progress view
94 private View mVideoProgressView;
95
Michael Kolb8233fac2010-10-26 16:08:53 -070096 private boolean mActivityPaused;
97
98 public BaseUi(Activity browser, UiController controller) {
99 mActivity = browser;
100 mUiController = controller;
101 mTabControl = controller.getTabControl();
102 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800103 mInputManager = (InputMethodManager)
104 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800105 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
107
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
109 .getDecorView().findViewById(android.R.id.content);
110 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
111 .inflate(R.layout.custom_screen, null);
112 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
113 R.id.main_content);
John Recke5c21d92011-03-11 15:09:46 -0800114 mContentView.setLayoutTransition(new LayoutTransition());
Michael Kolb8233fac2010-10-26 16:08:53 -0700115 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
116 .findViewById(R.id.error_console);
117 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
118 .findViewById(R.id.fullscreen_custom_content);
119 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800120 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700121 }
122
Michael Kolb66706532010-12-12 19:50:22 -0800123 /**
124 * common webview initialization
125 * @param w the webview to initialize
126 */
127 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700128 w.setScrollbarFadingEnabled(true);
129 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
130 w.setMapTrackballToArrowKeys(false); // use trackball directly
131 // Enable the built-in zoom
132 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700133
134 // Add this WebView to the settings observer list and update the
135 // settings
136 final BrowserSettings s = BrowserSettings.getInstance();
137 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700138 }
139
140 private void cancelStopToast() {
141 if (mStopToast != null) {
142 mStopToast.cancel();
143 mStopToast = null;
144 }
145 }
146
147 // lifecycle
148
149 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800150 if (isCustomViewShowing()) {
151 onHideCustomView();
152 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700153 cancelStopToast();
154 mActivityPaused = true;
155 }
156
157 public void onResume() {
158 mActivityPaused = false;
159 }
160
Michael Kolb66706532010-12-12 19:50:22 -0800161 protected boolean isActivityPaused() {
162 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700163 }
164
165 public void onConfigurationChanged(Configuration config) {
166 }
167
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800168 public abstract void editUrl(boolean clearInput);
169
Michael Kolb8233fac2010-10-26 16:08:53 -0700170 // key handling
171
172 @Override
173 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700174 if (mComboView != null) {
175 if (!mComboView.onBackPressed()) {
176 mUiController.removeComboView();
177 }
178 return true;
179 }
180 if (mCustomView != null) {
181 mUiController.hideCustomView();
182 return true;
183 }
184 return false;
185 }
186
John Reck30c714c2010-12-16 17:30:34 -0800187 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700188 @Override
John Reck30c714c2010-12-16 17:30:34 -0800189 public void onTabDataChanged(Tab tab) {
190 setUrlTitle(tab);
191 setFavicon(tab);
192 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800193 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700194 }
195
196 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500197 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800198 if (tab.inForeground()) {
199 boolean isBookmark = tab.isBookmarkedSite();
200 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
201 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500202 }
203
204 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700205 public void onPageStopped(Tab tab) {
206 cancelStopToast();
207 if (tab.inForeground()) {
208 mStopToast = Toast
209 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
210 mStopToast.show();
211 }
212 }
213
214 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800215 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800216 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800217 }
218
219 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700220 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700221 }
222
223 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800224 public void setActiveTab(final Tab tab) {
225 setActiveTab(tab, true);
226 }
227
228 void setActiveTab(Tab tab, boolean needsAttaching) {
Michael Kolb77df4562010-11-19 14:49:34 -0800229 if ((tab != mActiveTab) && (mActiveTab != null)) {
230 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700231 }
Michael Kolb77df4562010-11-19 14:49:34 -0800232 mActiveTab = tab;
Michael Kolb377ea312011-02-17 14:36:56 -0800233 if (needsAttaching) {
234 attachTabToContentView(tab);
235 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800237 onTabDataChanged(tab);
238 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800239 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800240 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700241 }
242
Michael Kolbcfa3af52010-12-14 10:36:11 -0800243 Tab getActiveTab() {
244 return mActiveTab;
245 }
246
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800248 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800249 }
250
251 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800253 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700254 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800255 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700256 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 }
258
259 @Override
260 public void detachTab(Tab tab) {
261 removeTabFromContentView(tab);
262 }
263
264 @Override
265 public void attachTab(Tab tab) {
266 attachTabToContentView(tab);
267 }
268
Michael Kolb377ea312011-02-17 14:36:56 -0800269 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800270 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 return;
272 }
273 View container = tab.getViewContainer();
274 WebView mainView = tab.getWebView();
275 // Attach the WebView to the container and then attach the
276 // container to the content view.
277 FrameLayout wrapper =
278 (FrameLayout) container.findViewById(R.id.webview_wrapper);
279 ViewGroup parent = (ViewGroup) mainView.getParent();
280 if (parent != wrapper) {
281 if (parent != null) {
282 Log.w(LOGTAG, "mMainView already has a parent in"
283 + " attachTabToContentView!");
284 parent.removeView(mainView);
285 }
286 wrapper.addView(mainView);
287 } else {
288 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
289 + " attachTabToContentView!");
290 }
291 parent = (ViewGroup) container.getParent();
292 if (parent != mContentView) {
293 if (parent != null) {
294 Log.w(LOGTAG, "mContainer already has a parent in"
295 + " attachTabToContentView!");
296 parent.removeView(container);
297 }
298 mContentView.addView(container, COVER_SCREEN_PARAMS);
299 } else {
300 Log.w(LOGTAG, "mContainer is already attached to content in"
301 + " attachTabToContentView!");
302 }
Michael Kolba4183062011-01-16 10:43:21 -0800303 mainView.setNextFocusUpId(R.id.url_focused);
304 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700305 mUiController.attachSubWindow(tab);
306 }
307
308 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800309 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700310 // Remove the container that contains the main WebView.
311 WebView mainView = tab.getWebView();
312 View container = tab.getViewContainer();
313 if (mainView == null) {
314 return;
315 }
316 // Remove the container from the content and then remove the
317 // WebView from the container. This will trigger a focus change
318 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800319 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700320 FrameLayout wrapper =
321 (FrameLayout) container.findViewById(R.id.webview_wrapper);
322 wrapper.removeView(mainView);
323 mContentView.removeView(container);
324 mUiController.endActionMode();
325 mUiController.removeSubWindow(tab);
326 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
327 if (errorConsole != null) {
328 mErrorConsoleContainer.removeView(errorConsole);
329 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700330 }
331
Michael Kolba713ec82010-11-29 17:27:06 -0800332 @Override
333 public void onSetWebView(Tab tab, WebView webView) {
334 View container = tab.getViewContainer();
335 if (container == null) {
336 // The tab consists of a container view, which contains the main
337 // WebView, as well as any other UI elements associated with the tab.
338 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
339 null);
340 tab.setViewContainer(container);
341 }
342 if (tab.getWebView() != webView) {
343 // Just remove the old one.
344 FrameLayout wrapper =
345 (FrameLayout) container.findViewById(R.id.webview_wrapper);
346 wrapper.removeView(tab.getWebView());
347 }
348 }
349
Michael Kolb8233fac2010-10-26 16:08:53 -0700350 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800351 * create a sub window container and webview for the tab
352 * Note: this methods operates through side-effects for now
353 * it sets both the subView and subViewContainer for the given tab
354 * @param tab tab to create the sub window for
355 * @param subView webview to be set as a subwindow for the tab
356 */
357 @Override
358 public void createSubWindow(Tab tab, WebView subView) {
359 View subViewContainer = mActivity.getLayoutInflater().inflate(
360 R.layout.browser_subwindow, null);
361 ViewGroup inner = (ViewGroup) subViewContainer
362 .findViewById(R.id.inner_container);
363 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
364 LayoutParams.MATCH_PARENT));
365 final ImageButton cancel = (ImageButton) subViewContainer
366 .findViewById(R.id.subwindow_close);
367 final WebView cancelSubView = subView;
368 cancel.setOnClickListener(new OnClickListener() {
369 public void onClick(View v) {
370 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
371 }
372 });
373 tab.setSubWebView(subView);
374 tab.setSubViewContainer(subViewContainer);
375 }
376
377 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 * Remove the sub window from the content view.
379 */
380 @Override
381 public void removeSubWindow(View subviewContainer) {
382 mContentView.removeView(subviewContainer);
383 mUiController.endActionMode();
384 }
385
386 /**
387 * Attach the sub window to the content view.
388 */
389 @Override
390 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800391 if (container.getParent() != null) {
392 // already attached, remove first
393 ((ViewGroup) container.getParent()).removeView(container);
394 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700395 mContentView.addView(container, COVER_SCREEN_PARAMS);
396 }
397
Michael Kolb7cdc4902011-02-03 17:54:40 -0800398 boolean canShowTitleBar() {
399 return !isTitleBarShowing()
400 && !isActivityPaused()
401 && (getActiveTab() != null)
402 && (getActiveTab().getWebView() != null)
403 && !mUiController.isInCustomActionMode();
404 }
405
406 void showTitleBar() {
407 mTitleShowing = true;
408 }
409
410 protected void hideTitleBar() {
411 mTitleShowing = false;
412 }
413
414 protected boolean isTitleBarShowing() {
415 return mTitleShowing;
416 }
417
418 protected abstract TitleBarBase getTitleBar();
419
420 protected void setTitleGravity(int gravity) {
421 getTitleBar().setTitleGravity(gravity);
422 Tab tab = getActiveTab();
423 if ((tab != null) && (tab.getWebView() != null)) {
424 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700425 }
426 }
427
Michael Kolb66706532010-12-12 19:50:22 -0800428 @Override
429 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800430 getTitleBar().setInVoiceMode(true);
431 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700432 }
433
Michael Kolb66706532010-12-12 19:50:22 -0800434 @Override
435 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800436 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800437 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800438 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700439 }
440
441 @Override
442 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800443 if (mComboView != null) {
444 return;
445 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700446 mComboView = new CombinedBookmarkHistoryView(mActivity,
447 mUiController,
448 startWithHistory ?
449 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
450 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
451 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800452 FrameLayout wrapper =
453 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
454 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800455 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800456 dismissIME();
457 if (mActiveTab != null) {
458 WebView web = mActiveTab.getWebView();
459 mActiveTab.putInBackground();
460 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700461 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
462 }
463
Michael Kolbba238702011-03-08 10:40:50 -0800464 public boolean isComboViewShowing() {
465 return (mComboView != null);
466 }
467
Michael Kolb8233fac2010-10-26 16:08:53 -0700468 /**
469 * dismiss the ComboPage
470 */
471 @Override
472 public void hideComboView() {
473 if (mComboView != null) {
474 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800475 FrameLayout wrapper =
476 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
477 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700478 mComboView = null;
479 }
Michael Kolb3a696282010-12-05 13:23:24 -0800480 if (mActiveTab != null) {
481 mActiveTab.putInForeground();
482 }
John Reckb3417f02011-01-14 11:01:05 -0800483 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700484 }
485
486 @Override
487 public void showCustomView(View view,
488 WebChromeClient.CustomViewCallback callback) {
489 // if a view already exists then immediately terminate the new one
490 if (mCustomView != null) {
491 callback.onCustomViewHidden();
492 return;
493 }
494
495 // Add the custom view to its container.
496 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
497 mCustomView = view;
498 mCustomViewCallback = callback;
499 // Hide the content view.
500 mContentView.setVisibility(View.GONE);
501 // Finally show the custom view container.
502 setStatusBarVisibility(false);
503 mCustomViewContainer.setVisibility(View.VISIBLE);
504 mCustomViewContainer.bringToFront();
505 }
506
507 @Override
508 public void onHideCustomView() {
509 if (mCustomView == null)
510 return;
511
512 // Hide the custom view.
513 mCustomView.setVisibility(View.GONE);
514 // Remove the custom view from its container.
515 mCustomViewContainer.removeView(mCustomView);
516 mCustomView = null;
517 mCustomViewContainer.setVisibility(View.GONE);
518 mCustomViewCallback.onCustomViewHidden();
519 // Show the content view.
520 setStatusBarVisibility(true);
521 mContentView.setVisibility(View.VISIBLE);
522 }
523
524 @Override
525 public boolean isCustomViewShowing() {
526 return mCustomView != null;
527 }
528
Michael Kolb66706532010-12-12 19:50:22 -0800529 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800530 if (mInputManager.isActive()) {
531 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
532 0);
533 }
534 }
535
Michael Kolb66706532010-12-12 19:50:22 -0800536 @Override
537 public boolean showsWeb() {
538 return mCustomView == null
539 && mComboView == null;
540 }
541
Michael Kolb8233fac2010-10-26 16:08:53 -0700542 // -------------------------------------------------------------------------
543
Michael Kolb5a72f182011-01-13 20:35:06 -0800544 protected void updateNavigationState(Tab tab) {
545 }
546
Michael Kolb8233fac2010-10-26 16:08:53 -0700547 /**
548 * Update the lock icon to correspond to our latest state.
549 */
Michael Kolb66706532010-12-12 19:50:22 -0800550 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800551 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700552 updateLockIconImage(t.getLockIconType());
553 }
554 }
555
556 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700557 * Updates the lock-icon image in the title-bar.
558 */
John Reck30c714c2010-12-16 17:30:34 -0800559 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700560 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800561 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700562 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800563 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700564 d = mMixLockIcon;
565 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800566 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700567 }
568
John Reck30c714c2010-12-16 17:30:34 -0800569 protected void setUrlTitle(Tab tab) {
570 String url = tab.getUrl();
571 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800572 if (TextUtils.isEmpty(title)) {
573 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800574 }
Michael Kolb66706532010-12-12 19:50:22 -0800575 if (tab.isInVoiceSearchMode()) return;
576 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800577 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800578 }
579 }
580
581 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800582 protected void setFavicon(Tab tab) {
583 if (tab.inForeground()) {
584 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800585 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800586 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700587 }
588
589 @Override
590 public void onActionModeFinished(boolean inLoad) {
591 if (inLoad) {
592 // the titlebar was removed when the CAB was shown
593 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800594 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700595 }
596 }
597
Michael Kolb66706532010-12-12 19:50:22 -0800598 // active tabs page
599
600 public void showActiveTabsPage() {
601 }
602
603 /**
604 * Remove the active tabs page.
605 */
606 public void removeActiveTabsPage() {
607 }
608
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 // menu handling callbacks
610
611 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800612 public boolean onPrepareOptionsMenu(Menu menu) {
613 return true;
614 }
615
616 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700618 }
619
620 @Override
621 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 }
623
624 @Override
625 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700626 }
627
628 @Override
629 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700630 }
631
632 @Override
633 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700634 }
635
636 @Override
637 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700638 }
639
640 // error console
641
642 @Override
643 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800644 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700645 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
646 if (flag) {
647 // Setting the show state of the console will cause it's the layout
648 // to be inflated.
649 if (errorConsole.numberOfErrors() > 0) {
650 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
651 } else {
652 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
653 }
654 if (errorConsole.getParent() != null) {
655 mErrorConsoleContainer.removeView(errorConsole);
656 }
657 // Now we can add it to the main view.
658 mErrorConsoleContainer.addView(errorConsole,
659 new LinearLayout.LayoutParams(
660 ViewGroup.LayoutParams.MATCH_PARENT,
661 ViewGroup.LayoutParams.WRAP_CONTENT));
662 } else {
663 mErrorConsoleContainer.removeView(errorConsole);
664 }
665 }
666
667 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800668 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
669 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
670 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 }
672
Michael Kolb8233fac2010-10-26 16:08:53 -0700673 // -------------------------------------------------------------------------
674 // Helper function for WebChromeClient
675 // -------------------------------------------------------------------------
676
677 @Override
678 public Bitmap getDefaultVideoPoster() {
679 if (mDefaultVideoPoster == null) {
680 mDefaultVideoPoster = BitmapFactory.decodeResource(
681 mActivity.getResources(), R.drawable.default_video_poster);
682 }
683 return mDefaultVideoPoster;
684 }
685
686 @Override
687 public View getVideoLoadingProgressView() {
688 if (mVideoProgressView == null) {
689 LayoutInflater inflater = LayoutInflater.from(mActivity);
690 mVideoProgressView = inflater.inflate(
691 R.layout.video_loading_progress, null);
692 }
693 return mVideoProgressView;
694 }
695
Michael Kolb843510f2010-12-09 10:51:49 -0800696 @Override
697 public void showMaxTabsWarning() {
698 Toast warning = Toast.makeText(mActivity,
699 mActivity.getString(R.string.max_tabs_warning),
700 Toast.LENGTH_SHORT);
701 warning.show();
702 }
703
Narayan Kamath5119edd2011-02-23 15:49:17 +0000704 @Override
705 public void registerDropdownChangeListener(DropdownChangeListener d) {
706 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700707}