blob: 6e8f603bc36a6a2979925413a2dc7d050ded6acd [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 Kolb8233fac2010-10-26 16:08:53 -070021import android.app.Activity;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070026import android.graphics.drawable.Drawable;
27import android.os.Bundle;
28import android.text.TextUtils;
29import android.util.Log;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.view.Gravity;
31import android.view.LayoutInflater;
32import android.view.Menu;
Michael Kolb8233fac2010-10-26 16:08:53 -070033import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080034import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070035import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080036import android.view.ViewGroup.LayoutParams;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080038import android.view.inputmethod.InputMethodManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070039import android.webkit.WebChromeClient;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.webkit.WebView;
41import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.widget.LinearLayout;
44import android.widget.Toast;
45
Michael Kolb1bf23132010-11-19 12:55:12 -080046import java.util.List;
47
Michael Kolb8233fac2010-10-26 16:08:53 -070048/**
49 * UI interface definitions
50 */
Michael Kolb66706532010-12-12 19:50:22 -080051public abstract class BaseUi implements UI, WebViewFactory {
Michael Kolb8233fac2010-10-26 16:08:53 -070052
53 private static final String LOGTAG = "BaseUi";
54
Michael Kolb66706532010-12-12 19:50:22 -080055 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070056 new FrameLayout.LayoutParams(
57 ViewGroup.LayoutParams.MATCH_PARENT,
58 ViewGroup.LayoutParams.MATCH_PARENT);
59
Michael Kolb66706532010-12-12 19:50:22 -080060 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070061 new FrameLayout.LayoutParams(
62 ViewGroup.LayoutParams.MATCH_PARENT,
63 ViewGroup.LayoutParams.MATCH_PARENT,
64 Gravity.CENTER);
65
66 Activity mActivity;
67 UiController mUiController;
68 TabControl mTabControl;
Michael Kolb77df4562010-11-19 14:49:34 -080069 private Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080070 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070071
72 private Drawable mSecLockIcon;
73 private Drawable mMixLockIcon;
74
Michael Kolb8233fac2010-10-26 16:08:53 -070075 private FrameLayout mBrowserFrameLayout;
Michael Kolb66706532010-12-12 19:50:22 -080076 protected FrameLayout mContentView;
Michael Kolb8233fac2010-10-26 16:08:53 -070077 private FrameLayout mCustomViewContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070078
79 private View mCustomView;
80 private WebChromeClient.CustomViewCallback mCustomViewCallback;
81
82 private CombinedBookmarkHistoryView mComboView;
83
84 private LinearLayout mErrorConsoleContainer = null;
85
86 private Toast mStopToast;
Michael Kolb8233fac2010-10-26 16:08:53 -070087
Michael Kolb7cdc4902011-02-03 17:54:40 -080088 private boolean mTitleShowing;
89
Michael Kolb8233fac2010-10-26 16:08:53 -070090 // the default <video> poster
91 private Bitmap mDefaultVideoPoster;
92 // the video progress view
93 private View mVideoProgressView;
94
Michael Kolb8233fac2010-10-26 16:08:53 -070095 private boolean mActivityPaused;
96
97 public BaseUi(Activity browser, UiController controller) {
98 mActivity = browser;
99 mUiController = controller;
100 mTabControl = controller.getTabControl();
101 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800102 mInputManager = (InputMethodManager)
103 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb5a72f182011-01-13 20:35:06 -0800104 mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
Michael Kolb8233fac2010-10-26 16:08:53 -0700105 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
108 .getDecorView().findViewById(android.R.id.content);
109 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
110 .inflate(R.layout.custom_screen, null);
111 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
112 R.id.main_content);
113 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
114 .findViewById(R.id.error_console);
115 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
116 .findViewById(R.id.fullscreen_custom_content);
117 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800118 mTitleShowing = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700119 }
120
Michael Kolb66706532010-12-12 19:50:22 -0800121 /**
122 * common webview initialization
123 * @param w the webview to initialize
124 */
125 protected void initWebViewSettings(WebView w) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700126 w.setScrollbarFadingEnabled(true);
127 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
128 w.setMapTrackballToArrowKeys(false); // use trackball directly
129 // Enable the built-in zoom
130 w.getSettings().setBuiltInZoomControls(true);
Michael Kolb8233fac2010-10-26 16:08:53 -0700131
132 // Add this WebView to the settings observer list and update the
133 // settings
134 final BrowserSettings s = BrowserSettings.getInstance();
135 s.addObserver(w.getSettings()).update(s, null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700136 }
137
138 private void cancelStopToast() {
139 if (mStopToast != null) {
140 mStopToast.cancel();
141 mStopToast = null;
142 }
143 }
144
145 // lifecycle
146
147 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800148 if (isCustomViewShowing()) {
149 onHideCustomView();
150 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700151 cancelStopToast();
152 mActivityPaused = true;
153 }
154
155 public void onResume() {
156 mActivityPaused = false;
157 }
158
Michael Kolb66706532010-12-12 19:50:22 -0800159 protected boolean isActivityPaused() {
160 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700161 }
162
163 public void onConfigurationChanged(Configuration config) {
164 }
165
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800166 public abstract void editUrl(boolean clearInput);
167
Michael Kolb8233fac2010-10-26 16:08:53 -0700168 // key handling
169
170 @Override
171 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700172 if (mComboView != null) {
173 if (!mComboView.onBackPressed()) {
174 mUiController.removeComboView();
175 }
176 return true;
177 }
178 if (mCustomView != null) {
179 mUiController.hideCustomView();
180 return true;
181 }
182 return false;
183 }
184
John Reck30c714c2010-12-16 17:30:34 -0800185 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700186 @Override
John Reck30c714c2010-12-16 17:30:34 -0800187 public void onTabDataChanged(Tab tab) {
188 setUrlTitle(tab);
189 setFavicon(tab);
190 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800191 updateNavigationState(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700192 }
193
194 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500195 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800196 if (tab.inForeground()) {
197 boolean isBookmark = tab.isBookmarkedSite();
198 getTitleBar().setCurrentUrlIsBookmark(isBookmark);
199 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500200 }
201
202 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700203 public void onPageStopped(Tab tab) {
204 cancelStopToast();
205 if (tab.inForeground()) {
206 mStopToast = Toast
207 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
208 mStopToast.show();
209 }
210 }
211
212 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800213 public boolean needsRestoreAllTabs() {
Michael Kolb66706532010-12-12 19:50:22 -0800214 return false;
Michael Kolb1bf23132010-11-19 12:55:12 -0800215 }
216
217 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700218 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 }
220
221 @Override
222 public void setActiveTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800223 if ((tab != mActiveTab) && (mActiveTab != null)) {
224 removeTabFromContentView(mActiveTab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700225 }
Michael Kolb77df4562010-11-19 14:49:34 -0800226 mActiveTab = tab;
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 attachTabToContentView(tab);
228 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800229 onTabDataChanged(tab);
230 onProgressChanged(tab);
John Reck117f07d2011-01-24 09:39:03 -0800231 boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800232 getTitleBar().setIncognitoMode(incognito);
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 }
234
Michael Kolbcfa3af52010-12-14 10:36:11 -0800235 Tab getActiveTab() {
236 return mActiveTab;
237 }
238
Michael Kolb8233fac2010-10-26 16:08:53 -0700239 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800240 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800241 }
242
243 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700244 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800245 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700246 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800247 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 }
250
251 @Override
252 public void detachTab(Tab tab) {
253 removeTabFromContentView(tab);
254 }
255
256 @Override
257 public void attachTab(Tab tab) {
258 attachTabToContentView(tab);
259 }
260
261 private void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800262 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700263 return;
264 }
265 View container = tab.getViewContainer();
266 WebView mainView = tab.getWebView();
267 // Attach the WebView to the container and then attach the
268 // container to the content view.
269 FrameLayout wrapper =
270 (FrameLayout) container.findViewById(R.id.webview_wrapper);
271 ViewGroup parent = (ViewGroup) mainView.getParent();
272 if (parent != wrapper) {
273 if (parent != null) {
274 Log.w(LOGTAG, "mMainView already has a parent in"
275 + " attachTabToContentView!");
276 parent.removeView(mainView);
277 }
278 wrapper.addView(mainView);
279 } else {
280 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
281 + " attachTabToContentView!");
282 }
283 parent = (ViewGroup) container.getParent();
284 if (parent != mContentView) {
285 if (parent != null) {
286 Log.w(LOGTAG, "mContainer already has a parent in"
287 + " attachTabToContentView!");
288 parent.removeView(container);
289 }
290 mContentView.addView(container, COVER_SCREEN_PARAMS);
291 } else {
292 Log.w(LOGTAG, "mContainer is already attached to content in"
293 + " attachTabToContentView!");
294 }
Michael Kolba4183062011-01-16 10:43:21 -0800295 mainView.setNextFocusUpId(R.id.url_focused);
296 mainView.setNextFocusDownId(R.id.url_focused);
Michael Kolb8233fac2010-10-26 16:08:53 -0700297 mUiController.attachSubWindow(tab);
298 }
299
300 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800301 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700302 // Remove the container that contains the main WebView.
303 WebView mainView = tab.getWebView();
304 View container = tab.getViewContainer();
305 if (mainView == null) {
306 return;
307 }
308 // Remove the container from the content and then remove the
309 // WebView from the container. This will trigger a focus change
310 // needed by WebView.
Michael Kolb20776cc2011-01-31 10:19:05 -0800311 mainView.setEmbeddedTitleBar(null);
Michael Kolb8233fac2010-10-26 16:08:53 -0700312 FrameLayout wrapper =
313 (FrameLayout) container.findViewById(R.id.webview_wrapper);
314 wrapper.removeView(mainView);
315 mContentView.removeView(container);
316 mUiController.endActionMode();
317 mUiController.removeSubWindow(tab);
318 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
319 if (errorConsole != null) {
320 mErrorConsoleContainer.removeView(errorConsole);
321 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700322 }
323
Michael Kolba713ec82010-11-29 17:27:06 -0800324 @Override
325 public void onSetWebView(Tab tab, WebView webView) {
326 View container = tab.getViewContainer();
327 if (container == null) {
328 // The tab consists of a container view, which contains the main
329 // WebView, as well as any other UI elements associated with the tab.
330 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
331 null);
332 tab.setViewContainer(container);
333 }
334 if (tab.getWebView() != webView) {
335 // Just remove the old one.
336 FrameLayout wrapper =
337 (FrameLayout) container.findViewById(R.id.webview_wrapper);
338 wrapper.removeView(tab.getWebView());
339 }
340 }
341
Michael Kolb8233fac2010-10-26 16:08:53 -0700342 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800343 * create a sub window container and webview for the tab
344 * Note: this methods operates through side-effects for now
345 * it sets both the subView and subViewContainer for the given tab
346 * @param tab tab to create the sub window for
347 * @param subView webview to be set as a subwindow for the tab
348 */
349 @Override
350 public void createSubWindow(Tab tab, WebView subView) {
351 View subViewContainer = mActivity.getLayoutInflater().inflate(
352 R.layout.browser_subwindow, null);
353 ViewGroup inner = (ViewGroup) subViewContainer
354 .findViewById(R.id.inner_container);
355 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
356 LayoutParams.MATCH_PARENT));
357 final ImageButton cancel = (ImageButton) subViewContainer
358 .findViewById(R.id.subwindow_close);
359 final WebView cancelSubView = subView;
360 cancel.setOnClickListener(new OnClickListener() {
361 public void onClick(View v) {
362 cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
363 }
364 });
365 tab.setSubWebView(subView);
366 tab.setSubViewContainer(subViewContainer);
367 }
368
369 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700370 * Remove the sub window from the content view.
371 */
372 @Override
373 public void removeSubWindow(View subviewContainer) {
374 mContentView.removeView(subviewContainer);
375 mUiController.endActionMode();
376 }
377
378 /**
379 * Attach the sub window to the content view.
380 */
381 @Override
382 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800383 if (container.getParent() != null) {
384 // already attached, remove first
385 ((ViewGroup) container.getParent()).removeView(container);
386 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700387 mContentView.addView(container, COVER_SCREEN_PARAMS);
388 }
389
Michael Kolb7cdc4902011-02-03 17:54:40 -0800390 boolean canShowTitleBar() {
391 return !isTitleBarShowing()
392 && !isActivityPaused()
393 && (getActiveTab() != null)
394 && (getActiveTab().getWebView() != null)
395 && !mUiController.isInCustomActionMode();
396 }
397
398 void showTitleBar() {
399 mTitleShowing = true;
400 }
401
402 protected void hideTitleBar() {
403 mTitleShowing = false;
404 }
405
406 protected boolean isTitleBarShowing() {
407 return mTitleShowing;
408 }
409
410 protected abstract TitleBarBase getTitleBar();
411
412 protected void setTitleGravity(int gravity) {
413 getTitleBar().setTitleGravity(gravity);
414 Tab tab = getActiveTab();
415 if ((tab != null) && (tab.getWebView() != null)) {
416 tab.getWebView().setTitleBarGravity(gravity);
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 }
418 }
419
Michael Kolb66706532010-12-12 19:50:22 -0800420 @Override
421 public void showVoiceTitleBar(String title) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800422 getTitleBar().setInVoiceMode(true);
423 getTitleBar().setDisplayTitle(title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700424 }
425
Michael Kolb66706532010-12-12 19:50:22 -0800426 @Override
427 public void revertVoiceTitleBar(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800428 getTitleBar().setInVoiceMode(false);
John Reck30c714c2010-12-16 17:30:34 -0800429 String url = tab.getUrl();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800430 getTitleBar().setDisplayTitle(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700431 }
432
433 @Override
434 public void showComboView(boolean startWithHistory, Bundle extras) {
John Reck439c9a52010-12-14 10:04:39 -0800435 if (mComboView != null) {
436 return;
437 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700438 mComboView = new CombinedBookmarkHistoryView(mActivity,
439 mUiController,
440 startWithHistory ?
441 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
442 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
443 extras);
Michael Kolb47d63f82011-01-18 10:48:40 -0800444 FrameLayout wrapper =
445 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
446 wrapper.setVisibility(View.GONE);
Michael Kolb7cdc4902011-02-03 17:54:40 -0800447 hideTitleBar();
Michael Kolb3a696282010-12-05 13:23:24 -0800448 dismissIME();
449 if (mActiveTab != null) {
450 WebView web = mActiveTab.getWebView();
451 mActiveTab.putInBackground();
452 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700453 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
454 }
455
456 /**
457 * dismiss the ComboPage
458 */
459 @Override
460 public void hideComboView() {
461 if (mComboView != null) {
462 mContentView.removeView(mComboView);
Michael Kolb47d63f82011-01-18 10:48:40 -0800463 FrameLayout wrapper =
464 (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
465 wrapper.setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700466 mComboView = null;
467 }
Michael Kolb3a696282010-12-05 13:23:24 -0800468 if (mActiveTab != null) {
469 mActiveTab.putInForeground();
470 }
John Reckb3417f02011-01-14 11:01:05 -0800471 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 }
473
474 @Override
475 public void showCustomView(View view,
476 WebChromeClient.CustomViewCallback callback) {
477 // if a view already exists then immediately terminate the new one
478 if (mCustomView != null) {
479 callback.onCustomViewHidden();
480 return;
481 }
482
483 // Add the custom view to its container.
484 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
485 mCustomView = view;
486 mCustomViewCallback = callback;
487 // Hide the content view.
488 mContentView.setVisibility(View.GONE);
489 // Finally show the custom view container.
490 setStatusBarVisibility(false);
491 mCustomViewContainer.setVisibility(View.VISIBLE);
492 mCustomViewContainer.bringToFront();
493 }
494
495 @Override
496 public void onHideCustomView() {
497 if (mCustomView == null)
498 return;
499
500 // Hide the custom view.
501 mCustomView.setVisibility(View.GONE);
502 // Remove the custom view from its container.
503 mCustomViewContainer.removeView(mCustomView);
504 mCustomView = null;
505 mCustomViewContainer.setVisibility(View.GONE);
506 mCustomViewCallback.onCustomViewHidden();
507 // Show the content view.
508 setStatusBarVisibility(true);
509 mContentView.setVisibility(View.VISIBLE);
510 }
511
512 @Override
513 public boolean isCustomViewShowing() {
514 return mCustomView != null;
515 }
516
Michael Kolb66706532010-12-12 19:50:22 -0800517 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800518 if (mInputManager.isActive()) {
519 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
520 0);
521 }
522 }
523
Michael Kolb66706532010-12-12 19:50:22 -0800524 @Override
525 public boolean showsWeb() {
526 return mCustomView == null
527 && mComboView == null;
528 }
529
Michael Kolb8233fac2010-10-26 16:08:53 -0700530 // -------------------------------------------------------------------------
531
Michael Kolb5a72f182011-01-13 20:35:06 -0800532 protected void updateNavigationState(Tab tab) {
533 }
534
Michael Kolb8233fac2010-10-26 16:08:53 -0700535 /**
536 * Update the lock icon to correspond to our latest state.
537 */
Michael Kolb66706532010-12-12 19:50:22 -0800538 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800539 if (t != null && t.inForeground()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700540 updateLockIconImage(t.getLockIconType());
541 }
542 }
543
544 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 * Updates the lock-icon image in the title-bar.
546 */
John Reck30c714c2010-12-16 17:30:34 -0800547 private void updateLockIconImage(LockIcon lockIconType) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700548 Drawable d = null;
John Reck30c714c2010-12-16 17:30:34 -0800549 if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700550 d = mSecLockIcon;
John Reck30c714c2010-12-16 17:30:34 -0800551 } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700552 d = mMixLockIcon;
553 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800554 getTitleBar().setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700555 }
556
John Reck30c714c2010-12-16 17:30:34 -0800557 protected void setUrlTitle(Tab tab) {
558 String url = tab.getUrl();
559 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800560 if (TextUtils.isEmpty(title)) {
561 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800562 }
Michael Kolb66706532010-12-12 19:50:22 -0800563 if (tab.isInVoiceSearchMode()) return;
564 if (tab.inForeground()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800565 getTitleBar().setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800566 }
567 }
568
569 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800570 protected void setFavicon(Tab tab) {
571 if (tab.inForeground()) {
572 Bitmap icon = tab.getFavicon();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800573 getTitleBar().setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800574 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700575 }
576
577 @Override
578 public void onActionModeFinished(boolean inLoad) {
579 if (inLoad) {
580 // the titlebar was removed when the CAB was shown
581 // if the page is loading, show it again
Michael Kolb7cdc4902011-02-03 17:54:40 -0800582 showTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700583 }
584 }
585
Michael Kolb66706532010-12-12 19:50:22 -0800586 // active tabs page
587
588 public void showActiveTabsPage() {
589 }
590
591 /**
592 * Remove the active tabs page.
593 */
594 public void removeActiveTabsPage() {
595 }
596
Michael Kolb8233fac2010-10-26 16:08:53 -0700597 // menu handling callbacks
598
599 @Override
600 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 }
602
603 @Override
604 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700605 }
606
607 @Override
608 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700609 }
610
611 @Override
612 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700613 }
614
615 @Override
616 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700617 }
618
619 @Override
620 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700621 }
622
623 // error console
624
625 @Override
626 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
627 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
628 if (flag) {
629 // Setting the show state of the console will cause it's the layout
630 // to be inflated.
631 if (errorConsole.numberOfErrors() > 0) {
632 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
633 } else {
634 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
635 }
636 if (errorConsole.getParent() != null) {
637 mErrorConsoleContainer.removeView(errorConsole);
638 }
639 // Now we can add it to the main view.
640 mErrorConsoleContainer.addView(errorConsole,
641 new LinearLayout.LayoutParams(
642 ViewGroup.LayoutParams.MATCH_PARENT,
643 ViewGroup.LayoutParams.WRAP_CONTENT));
644 } else {
645 mErrorConsoleContainer.removeView(errorConsole);
646 }
647 }
648
649 private void setStatusBarVisibility(boolean visible) {
Joe Onoratod3bf86f2011-01-25 20:07:10 -0800650 WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
651 params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
652 mActivity.getWindow().setAttributes(params);
Michael Kolb8233fac2010-10-26 16:08:53 -0700653 }
654
Michael Kolb8233fac2010-10-26 16:08:53 -0700655 // -------------------------------------------------------------------------
656 // Helper function for WebChromeClient
657 // -------------------------------------------------------------------------
658
659 @Override
660 public Bitmap getDefaultVideoPoster() {
661 if (mDefaultVideoPoster == null) {
662 mDefaultVideoPoster = BitmapFactory.decodeResource(
663 mActivity.getResources(), R.drawable.default_video_poster);
664 }
665 return mDefaultVideoPoster;
666 }
667
668 @Override
669 public View getVideoLoadingProgressView() {
670 if (mVideoProgressView == null) {
671 LayoutInflater inflater = LayoutInflater.from(mActivity);
672 mVideoProgressView = inflater.inflate(
673 R.layout.video_loading_progress, null);
674 }
675 return mVideoProgressView;
676 }
677
Michael Kolb843510f2010-12-09 10:51:49 -0800678 @Override
679 public void showMaxTabsWarning() {
680 Toast warning = Toast.makeText(mActivity,
681 mActivity.getString(R.string.max_tabs_warning),
682 Toast.LENGTH_SHORT);
683 warning.show();
684 }
685
Michael Kolb8233fac2010-10-26 16:08:53 -0700686}