blob: 052c9c58fc86b607a7c0d6f1d1153ae9dc997a56 [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
19import android.app.ActionBar;
20import android.app.Activity;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
26import android.graphics.PixelFormat;
27import android.graphics.drawable.Drawable;
28import android.os.Bundle;
29import android.text.TextUtils;
30import android.util.Log;
31import android.view.ActionMode;
32import android.view.Gravity;
33import android.view.LayoutInflater;
34import android.view.Menu;
35import android.view.MenuItem;
36import android.view.View;
37import android.view.ViewGroup;
38import android.view.WindowManager;
39import android.webkit.WebChromeClient;
40import android.webkit.WebHistoryItem;
41import android.webkit.WebView;
42import android.widget.FrameLayout;
43import android.widget.LinearLayout;
44import android.widget.Toast;
45
46/**
47 * UI interface definitions
48 */
49public class BaseUi implements UI, WebViewFactory {
50
51 private static final String LOGTAG = "BaseUi";
52
53 private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
54 new FrameLayout.LayoutParams(
55 ViewGroup.LayoutParams.MATCH_PARENT,
56 ViewGroup.LayoutParams.MATCH_PARENT);
57
58 private static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
59 new FrameLayout.LayoutParams(
60 ViewGroup.LayoutParams.MATCH_PARENT,
61 ViewGroup.LayoutParams.MATCH_PARENT,
62 Gravity.CENTER);
63
64 Activity mActivity;
65 UiController mUiController;
66 TabControl mTabControl;
67
68 private Drawable mSecLockIcon;
69 private Drawable mMixLockIcon;
70
71 private boolean mXLargeScreenSize;
72 private FrameLayout mBrowserFrameLayout;
73 private FrameLayout mContentView;
74 private FrameLayout mCustomViewContainer;
75 private TitleBarBase mTitleBar;
76 private TitleBarBase mFakeTitleBar;
77 private TabBar mTabBar;
78
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;
87 private ActiveTabsPage mActiveTabsPage;
88
89 // the default <video> poster
90 private Bitmap mDefaultVideoPoster;
91 // the video progress view
92 private View mVideoProgressView;
93
94 boolean mExtendedMenuOpen;
95 boolean mOptionsMenuOpen;
96
97 private boolean mActivityPaused;
98
99 public BaseUi(Activity browser, UiController controller) {
100 mActivity = browser;
101 mUiController = controller;
102 mTabControl = controller.getTabControl();
103 Resources res = mActivity.getResources();
104 mSecLockIcon = res.getDrawable(R.drawable.ic_secure);
105 mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
106
107
108 mXLargeScreenSize = (res.getConfiguration().screenLayout
109 & Configuration.SCREENLAYOUT_SIZE_MASK)
110 == Configuration.SCREENLAYOUT_SIZE_XLARGE;
111
112 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
113 .getDecorView().findViewById(android.R.id.content);
114 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(mActivity)
115 .inflate(R.layout.custom_screen, null);
116 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
117 R.id.main_content);
118 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
119 .findViewById(R.id.error_console);
120 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
121 .findViewById(R.id.fullscreen_custom_content);
122 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
123
124 if (mXLargeScreenSize) {
125 mTitleBar = new TitleBarXLarge(mActivity, mUiController);
126 mTitleBar.setProgress(100);
127 mFakeTitleBar = new TitleBarXLarge(mActivity, mUiController);
128 ActionBar actionBar = mActivity.getActionBar();
129 mTabBar = new TabBar(mActivity, mUiController, this);
130 actionBar.setCustomNavigationMode(mTabBar);
131 } else {
132 mTitleBar = new TitleBar(mActivity, mUiController);
133 // mTitleBar will be always be shown in the fully loaded mode on
134 // phone
135 mTitleBar.setProgress(100);
136 mFakeTitleBar = new TitleBar(mActivity, mUiController);
137 }
138 }
139
140 // webview factory
141
142 @Override
143 public WebView createWebView(boolean privateBrowsing) {
144 // Create a new WebView
145 ScrollWebView w = new ScrollWebView(mActivity, null,
146 android.R.attr.webViewStyle, privateBrowsing);
147 w.setScrollbarFadingEnabled(true);
148 w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
149 w.setMapTrackballToArrowKeys(false); // use trackball directly
150 // Enable the built-in zoom
151 w.getSettings().setBuiltInZoomControls(true);
152 if (mXLargeScreenSize) {
153 w.setScrollListener(mTabBar);
154 w.getSettings().setDisplayZoomControls(false);
155 }
156
157 // Add this WebView to the settings observer list and update the
158 // settings
159 final BrowserSettings s = BrowserSettings.getInstance();
160 s.addObserver(w.getSettings()).update(s, null);
161 return w;
162 }
163
164 void stopWebViewScrolling() {
165 ScrollWebView web = (ScrollWebView) mUiController.getCurrentWebView();
166 if (web != null) {
167 web.stopScroll();
168 }
169 }
170
171 private void cancelStopToast() {
172 if (mStopToast != null) {
173 mStopToast.cancel();
174 mStopToast = null;
175 }
176 }
177
178 // lifecycle
179
180 public void onPause() {
181 // FIXME: This removes the active tabs page and resets the menu to
182 // MAIN_MENU. A better solution might be to do this work in onNewIntent
183 // but then we would need to save it in onSaveInstanceState and restore
184 // it in onCreate/onRestoreInstanceState
185 if (mActiveTabsPage != null) {
186 mUiController.removeActiveTabsPage(true);
187 }
188 cancelStopToast();
189 mActivityPaused = true;
190 }
191
192 public void onResume() {
193 mActivityPaused = false;
194 }
195
196 public void onDestroy() {
197 hideFakeTitleBar();
198 }
199
200 public void onConfigurationChanged(Configuration config) {
201 }
202
203 // key handling
204
205 @Override
206 public boolean onBackKey() {
207 if (mActiveTabsPage != null) {
208 // if tab page is showing, hide it
209 mUiController.removeActiveTabsPage(true);
210 return true;
211 }
212 if (mComboView != null) {
213 if (!mComboView.onBackPressed()) {
214 mUiController.removeComboView();
215 }
216 return true;
217 }
218 if (mCustomView != null) {
219 mUiController.hideCustomView();
220 return true;
221 }
222 return false;
223 }
224
225 // WebView callbacks
226
227 @Override
228 public void onPageStarted(Tab tab, String url, Bitmap favicon) {
229 if (mXLargeScreenSize) {
230 mTabBar.onPageStarted(tab, url, favicon);
231 }
232 if (tab.inForeground()) {
233 resetLockIcon(tab, url);
234 setUrlTitle(tab, url, null);
235 setFavicon(tab, favicon);
236 }
237
238 }
239
240 @Override
241 public void onPageFinished(Tab tab, String url) {
242 if (mXLargeScreenSize) {
243 mTabBar.onPageFinished(tab);
244 }
245 if (tab.inForeground()) {
246 // Reset the title and icon in case we stopped a provisional load.
247 resetTitleAndIcon(tab);
248 // Update the lock icon image only once we are done loading
249 updateLockIconToLatest(tab);
250 }
251 }
252
253 @Override
254 public void onPageStopped(Tab tab) {
255 cancelStopToast();
256 if (tab.inForeground()) {
257 mStopToast = Toast
258 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
259 mStopToast.show();
260 }
261 }
262
263 @Override
264 public void onProgressChanged(Tab tab, int progress) {
265 if (mXLargeScreenSize) {
266 mTabBar.onProgress(tab, progress);
267 }
268 if (tab.inForeground()) {
269 mFakeTitleBar.setProgress(progress);
270 if (progress == 100) {
271 if (!mOptionsMenuOpen || !mExtendedMenuOpen) {
272 hideFakeTitleBar();
273 }
274 } else {
275 if (!mOptionsMenuOpen || mExtendedMenuOpen) {
276 showFakeTitleBar();
277 }
278 }
279 }
280 }
281
282 @Override
283 public void addTab(Tab tab) {
284 if (mXLargeScreenSize) {
285 mTabBar.onNewTab(tab);
286 }
287 }
288
289 @Override
290 public void setActiveTab(Tab tab) {
291 Tab current = mTabControl.getCurrentTab();
292 if ((tab != current) && (current != null)) {
293 removeTabFromContentView(current);
294 }
295 attachTabToContentView(tab);
296 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
297
298 WebView view = tab.getWebView();
299 view.setEmbeddedTitleBar(mTitleBar);
300 if (tab.isInVoiceSearchMode()) {
301 showVoiceTitleBar(tab.getVoiceDisplayTitle());
302 } else {
303 revertVoiceTitleBar(tab);
304 }
305
306 if (mXLargeScreenSize) {
307 // Request focus on the top window.
308 mTabBar.onSetActiveTab(tab);
309 }
310 resetTitleIconAndProgress(tab);
311 updateLockIconToLatest(tab);
312 tab.getTopWindow().requestFocus();
313 }
314
315 @Override
316 public void removeTab(Tab tab) {
317 if (mTabControl.getCurrentTab() == tab) {
318 removeTabFromContentView(tab);
319 }
320 if (mXLargeScreenSize) {
321 mTabBar.onRemoveTab(tab);
322 }
323 }
324
325 @Override
326 public void detachTab(Tab tab) {
327 removeTabFromContentView(tab);
328 }
329
330 @Override
331 public void attachTab(Tab tab) {
332 attachTabToContentView(tab);
333 }
334
335 private void attachTabToContentView(Tab tab) {
336 if (tab.getWebView() == null) {
337 return;
338 }
339 View container = tab.getViewContainer();
340 WebView mainView = tab.getWebView();
341 // Attach the WebView to the container and then attach the
342 // container to the content view.
343 FrameLayout wrapper =
344 (FrameLayout) container.findViewById(R.id.webview_wrapper);
345 ViewGroup parent = (ViewGroup) mainView.getParent();
346 if (parent != wrapper) {
347 if (parent != null) {
348 Log.w(LOGTAG, "mMainView already has a parent in"
349 + " attachTabToContentView!");
350 parent.removeView(mainView);
351 }
352 wrapper.addView(mainView);
353 } else {
354 Log.w(LOGTAG, "mMainView is already attached to wrapper in"
355 + " attachTabToContentView!");
356 }
357 parent = (ViewGroup) container.getParent();
358 if (parent != mContentView) {
359 if (parent != null) {
360 Log.w(LOGTAG, "mContainer already has a parent in"
361 + " attachTabToContentView!");
362 parent.removeView(container);
363 }
364 mContentView.addView(container, COVER_SCREEN_PARAMS);
365 } else {
366 Log.w(LOGTAG, "mContainer is already attached to content in"
367 + " attachTabToContentView!");
368 }
369 mUiController.attachSubWindow(tab);
370 }
371
372 private void removeTabFromContentView(Tab tab) {
373 // Remove the container that contains the main WebView.
374 WebView mainView = tab.getWebView();
375 View container = tab.getViewContainer();
376 if (mainView == null) {
377 return;
378 }
379 // Remove the container from the content and then remove the
380 // WebView from the container. This will trigger a focus change
381 // needed by WebView.
382 FrameLayout wrapper =
383 (FrameLayout) container.findViewById(R.id.webview_wrapper);
384 wrapper.removeView(mainView);
385 mContentView.removeView(container);
386 mUiController.endActionMode();
387 mUiController.removeSubWindow(tab);
388 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
389 if (errorConsole != null) {
390 mErrorConsoleContainer.removeView(errorConsole);
391 }
392 mainView.setEmbeddedTitleBar(null);
393 }
394
395 /**
396 * Remove the sub window from the content view.
397 */
398 @Override
399 public void removeSubWindow(View subviewContainer) {
400 mContentView.removeView(subviewContainer);
401 mUiController.endActionMode();
402 }
403
404 /**
405 * Attach the sub window to the content view.
406 */
407 @Override
408 public void attachSubWindow(View container) {
409 mContentView.addView(container, COVER_SCREEN_PARAMS);
410 }
411
412 void showFakeTitleBar() {
413 if (!isFakeTitleBarShowing() && mActiveTabsPage == null &&
414 !mActivityPaused) {
415 WebView mainView = mUiController.getCurrentWebView();
416 // if there is no current WebView, don't show the faked title bar;
417 if (mainView == null) {
418 return;
419 }
420 // Do not need to check for null, since the current tab will have
421 // at least a main WebView, or we would have returned above.
422 if (mUiController.isInCustomActionMode()) {
423 // Do not show the fake title bar, while a custom ActionMode
424 // (i.e. find or select) is showing.
425 return;
426 }
427 if (mXLargeScreenSize) {
428 mContentView.addView(mFakeTitleBar);
429 mTabBar.onShowTitleBar();
430 } else {
431 WindowManager manager = (WindowManager)
432 mActivity.getSystemService(Context.WINDOW_SERVICE);
433
434 // Add the title bar to the window manager so it can receive
435 // touches
436 // while the menu is up
437 WindowManager.LayoutParams params =
438 new WindowManager.LayoutParams(
439 ViewGroup.LayoutParams.MATCH_PARENT,
440 ViewGroup.LayoutParams.WRAP_CONTENT,
441 WindowManager.LayoutParams.TYPE_APPLICATION,
442 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
443 PixelFormat.TRANSLUCENT);
444 params.gravity = Gravity.TOP;
445 boolean atTop = mainView.getScrollY() == 0;
446 params.windowAnimations = atTop ? 0 : R.style.TitleBar;
447 manager.addView(mFakeTitleBar, params);
448 }
449 }
450 }
451
452 void hideFakeTitleBar() {
453 if (!isFakeTitleBarShowing()) return;
454 if (mXLargeScreenSize) {
455 mContentView.removeView(mFakeTitleBar);
456 mTabBar.onHideTitleBar();
457 } else {
458 WindowManager.LayoutParams params =
459 (WindowManager.LayoutParams) mFakeTitleBar.getLayoutParams();
460 WebView mainView = mUiController.getCurrentWebView();
461 // Although we decided whether or not to animate based on the
462 // current
463 // scroll position, the scroll position may have changed since the
464 // fake title bar was displayed. Make sure it has the appropriate
465 // animation/lack thereof before removing.
466 params.windowAnimations =
467 mainView != null && mainView.getScrollY() == 0 ?
468 0 : R.style.TitleBar;
469 WindowManager manager = (WindowManager) mActivity
470 .getSystemService(Context.WINDOW_SERVICE);
471 manager.updateViewLayout(mFakeTitleBar, params);
472 manager.removeView(mFakeTitleBar);
473 }
474 }
475
476 boolean isFakeTitleBarShowing() {
477 return (mFakeTitleBar.getParent() != null);
478 }
479
480 @Override
481 public void showComboView(boolean startWithHistory, Bundle extras) {
482 mComboView = new CombinedBookmarkHistoryView(mActivity,
483 mUiController,
484 startWithHistory ?
485 CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY
486 : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS,
487 extras);
488 mTitleBar.setVisibility(View.GONE);
489 hideFakeTitleBar();
490 mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
491 }
492
493 /**
494 * dismiss the ComboPage
495 */
496 @Override
497 public void hideComboView() {
498 if (mComboView != null) {
499 mContentView.removeView(mComboView);
500 mTitleBar.setVisibility(View.VISIBLE);
501 mComboView = null;
502 }
503 }
504
505 @Override
506 public void showCustomView(View view,
507 WebChromeClient.CustomViewCallback callback) {
508 // if a view already exists then immediately terminate the new one
509 if (mCustomView != null) {
510 callback.onCustomViewHidden();
511 return;
512 }
513
514 // Add the custom view to its container.
515 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
516 mCustomView = view;
517 mCustomViewCallback = callback;
518 // Hide the content view.
519 mContentView.setVisibility(View.GONE);
520 // Finally show the custom view container.
521 setStatusBarVisibility(false);
522 mCustomViewContainer.setVisibility(View.VISIBLE);
523 mCustomViewContainer.bringToFront();
524 }
525
526 @Override
527 public void onHideCustomView() {
528 if (mCustomView == null)
529 return;
530
531 // Hide the custom view.
532 mCustomView.setVisibility(View.GONE);
533 // Remove the custom view from its container.
534 mCustomViewContainer.removeView(mCustomView);
535 mCustomView = null;
536 mCustomViewContainer.setVisibility(View.GONE);
537 mCustomViewCallback.onCustomViewHidden();
538 // Show the content view.
539 setStatusBarVisibility(true);
540 mContentView.setVisibility(View.VISIBLE);
541 }
542
543 @Override
544 public boolean isCustomViewShowing() {
545 return mCustomView != null;
546 }
547
548 @Override
549 public void showVoiceTitleBar(String title) {
550 mTitleBar.setInVoiceMode(true);
551 mTitleBar.setDisplayTitle(title);
552 mFakeTitleBar.setInVoiceMode(true);
553 mFakeTitleBar.setDisplayTitle(title);
554 }
555
556 @Override
557 public void revertVoiceTitleBar(Tab tab) {
558 mTitleBar.setInVoiceMode(false);
559 String url = tab.getCurrentUrl();
560 mTitleBar.setDisplayTitle(url);
561 mFakeTitleBar.setInVoiceMode(false);
562 mFakeTitleBar.setDisplayTitle(url);
563 }
564
565 // -------------------------------------------------------------------------
566
567 @Override
568 public void resetTitleAndRevertLockIcon(Tab tab) {
569 tab.revertLockIcon();
570 updateLockIconToLatest(tab);
571 resetTitleIconAndProgress(tab);
572 }
573
574 /**
575 * Resets the lock icon. This method is called when we start a new load and
576 * know the url to be loaded.
577 */
578 private void resetLockIcon(Tab tab, String url) {
579 // Save the lock-icon state (we revert to it if the load gets cancelled)
580 tab.resetLockIcon(url);
581 updateLockIconImage(Tab.LOCK_ICON_UNSECURE);
582 }
583
584 /**
585 * Update the lock icon to correspond to our latest state.
586 */
587 private void updateLockIconToLatest(Tab t) {
588 if (t != null) {
589 updateLockIconImage(t.getLockIconType());
590 }
591 }
592
593 /**
594 * Reset the title, favicon, and progress.
595 */
596 private void resetTitleIconAndProgress(Tab tab) {
597 WebView current = tab.getWebView();
598 if (current == null) {
599 return;
600 }
601 resetTitleAndIcon(current);
602 int progress = current.getProgress();
603 current.getWebChromeClient().onProgressChanged(current, progress);
604 }
605
606 @Override
607 public void resetTitleAndIcon(Tab tab) {
608 WebView current = tab.getWebView();
609 if (current != null) {
610 resetTitleAndIcon(current);
611 }
612 }
613
614 // Reset the title and the icon based on the given item.
615 private void resetTitleAndIcon(WebView view) {
616 WebHistoryItem item = view.copyBackForwardList().getCurrentItem();
617 Tab tab = mTabControl.getTabFromView(view);
618 if (item != null) {
619 setUrlTitle(tab, item.getUrl(), item.getTitle());
620 setFavicon(tab, item.getFavicon());
621 } else {
622 setUrlTitle(tab, null, null);
623 setFavicon(tab, null);
624 }
625 }
626
627 /**
628 * Updates the lock-icon image in the title-bar.
629 */
630 private void updateLockIconImage(int lockIconType) {
631 Drawable d = null;
632 if (lockIconType == Tab.LOCK_ICON_SECURE) {
633 d = mSecLockIcon;
634 } else if (lockIconType == Tab.LOCK_ICON_MIXED) {
635 d = mMixLockIcon;
636 }
637 mTitleBar.setLock(d);
638 mFakeTitleBar.setLock(d);
639 }
640
641 // active tabs page
642
643 public void showActiveTabsPage() {
644 mActiveTabsPage = new ActiveTabsPage(mActivity, mUiController);
645 mTitleBar.setVisibility(View.GONE);
646 hideFakeTitleBar();
647 mContentView.addView(mActiveTabsPage, COVER_SCREEN_PARAMS);
648 mActiveTabsPage.requestFocus();
649 }
650
651 /**
652 * Remove the active tabs page.
653 * @param needToAttach If true, the active tabs page did not attach a tab
654 * to the content view, so we need to do that here.
655 */
656 public void removeActiveTabsPage() {
657 mContentView.removeView(mActiveTabsPage);
658 mTitleBar.setVisibility(View.VISIBLE);
659 mActiveTabsPage = null;
660 }
661
662 // action mode callbacks
663
664 @Override
665 public void onActionModeStarted(ActionMode mode) {
666 // hide the fake title bar when CAB is shown
667 hideFakeTitleBar();
668 }
669
670 @Override
671 public void onActionModeFinished(boolean inLoad) {
672 if (inLoad) {
673 // the titlebar was removed when the CAB was shown
674 // if the page is loading, show it again
675 showFakeTitleBar();
676 }
677 }
678
679 // menu handling callbacks
680
681 @Override
682 public void onOptionsMenuOpened() {
683 mOptionsMenuOpen = true;
684 // options menu opened, show fake title bar
685 showFakeTitleBar();
686 }
687
688 @Override
689 public void onExtendedMenuOpened() {
690 // Switching the menu to expanded view, so hide the
691 // title bar.
692 mExtendedMenuOpen = true;
693 hideFakeTitleBar();
694 }
695
696 @Override
697 public void onOptionsMenuClosed(boolean inLoad) {
698 mOptionsMenuOpen = false;
699 if (!inLoad) {
700 hideFakeTitleBar();
701 }
702 }
703
704 @Override
705 public void onExtendedMenuClosed(boolean inLoad) {
706 mExtendedMenuOpen = false;
707 if (inLoad) {
708 showFakeTitleBar();
709 }
710 }
711
712 @Override
713 public void onContextMenuCreated(Menu menu) {
714 hideFakeTitleBar();
715 }
716
717 @Override
718 public void onContextMenuClosed(Menu menu, boolean inLoad) {
719 if (inLoad) {
720 showFakeTitleBar();
721 }
722 }
723
724 @Override
725 public void onScroll(boolean titleVisible) {
726 if (mTabBar != null) {
727 mTabBar.onScroll(titleVisible);
728 }
729 }
730
731 // error console
732
733 @Override
734 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
735 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
736 if (flag) {
737 // Setting the show state of the console will cause it's the layout
738 // to be inflated.
739 if (errorConsole.numberOfErrors() > 0) {
740 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
741 } else {
742 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
743 }
744 if (errorConsole.getParent() != null) {
745 mErrorConsoleContainer.removeView(errorConsole);
746 }
747 // Now we can add it to the main view.
748 mErrorConsoleContainer.addView(errorConsole,
749 new LinearLayout.LayoutParams(
750 ViewGroup.LayoutParams.MATCH_PARENT,
751 ViewGroup.LayoutParams.WRAP_CONTENT));
752 } else {
753 mErrorConsoleContainer.removeView(errorConsole);
754 }
755 }
756
757 private void setStatusBarVisibility(boolean visible) {
758 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
759 mActivity.getWindow().setFlags(flag,
760 WindowManager.LayoutParams.FLAG_FULLSCREEN);
761 }
762
763 @Override
764 public void setUrlTitle(Tab tab, String url, String title) {
765 if (TextUtils.isEmpty(title)) {
766 if (TextUtils.isEmpty(url)) {
767 title = mActivity.getResources()
768 .getString(R.string.title_bar_loading);
769 } else {
770 title = url;
771 }
772 }
773 if (tab.isInVoiceSearchMode()) return;
774 if (tab.inForeground()) {
775 mTitleBar.setDisplayTitle(url);
776 mFakeTitleBar.setDisplayTitle(url);
777 }
778 if (mXLargeScreenSize) {
779 mTabBar.onUrlAndTitle(tab, url, title);
780 }
781 }
782
783 // Set the favicon in the title bar.
784 @Override
785 public void setFavicon(Tab tab, Bitmap icon) {
786 mTitleBar.setFavicon(icon);
787 mFakeTitleBar.setFavicon(icon);
788 if (mXLargeScreenSize) {
789 mTabBar.onFavicon(tab, icon);
790 }
791 }
792 @Override
793 public boolean showsWeb() {
794 return mCustomView == null && mActiveTabsPage == null
795 && mComboView == null;
796 }
797
798 @Override
799 public void onPrepareOptionsMenu(Menu menu) {
800 if (!mXLargeScreenSize) {
801 final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id);
802 newtab.setEnabled(mUiController.getTabControl().canCreateNewTab());
803 }
804 }
805
806 // -------------------------------------------------------------------------
807 // Helper function for WebChromeClient
808 // -------------------------------------------------------------------------
809
810 @Override
811 public Bitmap getDefaultVideoPoster() {
812 if (mDefaultVideoPoster == null) {
813 mDefaultVideoPoster = BitmapFactory.decodeResource(
814 mActivity.getResources(), R.drawable.default_video_poster);
815 }
816 return mDefaultVideoPoster;
817 }
818
819 @Override
820 public View getVideoLoadingProgressView() {
821 if (mVideoProgressView == null) {
822 LayoutInflater inflater = LayoutInflater.from(mActivity);
823 mVideoProgressView = inflater.inflate(
824 R.layout.video_loading_progress, null);
825 }
826 return mVideoProgressView;
827 }
828
829}