BaseUi.java revision ef654f1dd80f55609060005342fc4f2cde62990c
18233facddcc51865d612a919d450db6954aa48e3Michael Kolb/*
28233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Copyright (C) 2010 The Android Open Source Project
38233facddcc51865d612a919d450db6954aa48e3Michael Kolb *
48233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Licensed under the Apache License, Version 2.0 (the "License");
58233facddcc51865d612a919d450db6954aa48e3Michael Kolb * you may not use this file except in compliance with the License.
68233facddcc51865d612a919d450db6954aa48e3Michael Kolb * You may obtain a copy of the License at
78233facddcc51865d612a919d450db6954aa48e3Michael Kolb *
88233facddcc51865d612a919d450db6954aa48e3Michael Kolb *      http://www.apache.org/licenses/LICENSE-2.0
98233facddcc51865d612a919d450db6954aa48e3Michael Kolb *
108233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Unless required by applicable law or agreed to in writing, software
118233facddcc51865d612a919d450db6954aa48e3Michael Kolb * distributed under the License is distributed on an "AS IS" BASIS,
128233facddcc51865d612a919d450db6954aa48e3Michael Kolb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138233facddcc51865d612a919d450db6954aa48e3Michael Kolb * See the License for the specific language governing permissions and
148233facddcc51865d612a919d450db6954aa48e3Michael Kolb * limitations under the License.
158233facddcc51865d612a919d450db6954aa48e3Michael Kolb */
168233facddcc51865d612a919d450db6954aa48e3Michael Kolb
178233facddcc51865d612a919d450db6954aa48e3Michael Kolbpackage com.android.browser;
188233facddcc51865d612a919d450db6954aa48e3Michael Kolb
198233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.app.Activity;
208233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.content.res.Configuration;
218233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.content.res.Resources;
228233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.Bitmap;
238233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.BitmapFactory;
245a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.Color;
255a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.drawable.BitmapDrawable;
268233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.drawable.Drawable;
275a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.drawable.LayerDrawable;
285a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.drawable.PaintDrawable;
298233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.os.Bundle;
305d43ce897758b7cb5deadc1203717b965334784cJohn Reckimport android.os.Handler;
315d43ce897758b7cb5deadc1203717b965334784cJohn Reckimport android.os.Message;
328233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.text.TextUtils;
338233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.util.Log;
348233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.Gravity;
358233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.LayoutInflater;
368233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.Menu;
37bf2ec206e8743467961da3e857b07aad6c50cd67John Reckimport android.view.MotionEvent;
388233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.View;
391514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.view.View.OnClickListener;
40bf2ec206e8743467961da3e857b07aad6c50cd67John Reckimport android.view.View.OnTouchListener;
41bf2ec206e8743467961da3e857b07aad6c50cd67John Reckimport android.view.ViewConfiguration;
428233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.ViewGroup;
431514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.view.ViewGroup.LayoutParams;
448233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.WindowManager;
453a696280cba53eea153c9d5707b236997d193328Michael Kolbimport android.view.inputmethod.InputMethodManager;
468233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.webkit.WebChromeClient;
478233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.webkit.WebView;
488233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.FrameLayout;
491514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.widget.ImageButton;
508233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.LinearLayout;
518233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.Toast;
528233facddcc51865d612a919d450db6954aa48e3Michael Kolb
53bf2ec206e8743467961da3e857b07aad6c50cd67John Reckimport com.android.browser.Tab.LockIcon;
54bf2ec206e8743467961da3e857b07aad6c50cd67John Reckimport com.android.internal.view.menu.MenuBuilder;
55bf2ec206e8743467961da3e857b07aad6c50cd67John Reck
561bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolbimport java.util.List;
571bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb
588233facddcc51865d612a919d450db6954aa48e3Michael Kolb/**
598233facddcc51865d612a919d450db6954aa48e3Michael Kolb * UI interface definitions
608233facddcc51865d612a919d450db6954aa48e3Michael Kolb */
611461244018a225006a8d4c203f9dfe294ffe94faMichael Kolbpublic abstract class BaseUi implements UI, OnTouchListener {
628233facddcc51865d612a919d450db6954aa48e3Michael Kolb
638233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private static final String LOGTAG = "BaseUi";
648233facddcc51865d612a919d450db6954aa48e3Michael Kolb
656670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
668233facddcc51865d612a919d450db6954aa48e3Michael Kolb        new FrameLayout.LayoutParams(
678233facddcc51865d612a919d450db6954aa48e3Michael Kolb        ViewGroup.LayoutParams.MATCH_PARENT,
688233facddcc51865d612a919d450db6954aa48e3Michael Kolb        ViewGroup.LayoutParams.MATCH_PARENT);
698233facddcc51865d612a919d450db6954aa48e3Michael Kolb
706670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
718233facddcc51865d612a919d450db6954aa48e3Michael Kolb        new FrameLayout.LayoutParams(
728233facddcc51865d612a919d450db6954aa48e3Michael Kolb        ViewGroup.LayoutParams.MATCH_PARENT,
738233facddcc51865d612a919d450db6954aa48e3Michael Kolb        ViewGroup.LayoutParams.MATCH_PARENT,
748233facddcc51865d612a919d450db6954aa48e3Michael Kolb        Gravity.CENTER);
758233facddcc51865d612a919d450db6954aa48e3Michael Kolb
765d43ce897758b7cb5deadc1203717b965334784cJohn Reck    private static final int MSG_HIDE_TITLEBAR = 1;
77ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck    public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
785d43ce897758b7cb5deadc1203717b965334784cJohn Reck
798233facddcc51865d612a919d450db6954aa48e3Michael Kolb    Activity mActivity;
808233facddcc51865d612a919d450db6954aa48e3Michael Kolb    UiController mUiController;
818233facddcc51865d612a919d450db6954aa48e3Michael Kolb    TabControl mTabControl;
82377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb    protected Tab mActiveTab;
833a696280cba53eea153c9d5707b236997d193328Michael Kolb    private InputMethodManager mInputManager;
848233facddcc51865d612a919d450db6954aa48e3Michael Kolb
858233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private Drawable mSecLockIcon;
868233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private Drawable mMixLockIcon;
875a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb    protected Drawable mGenericFavicon;
888233facddcc51865d612a919d450db6954aa48e3Michael Kolb
896670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    protected FrameLayout mContentView;
90f205560dacc8a85f0443ca1949a68962404321e8Michael Kolb    protected FrameLayout mCustomViewContainer;
918233facddcc51865d612a919d450db6954aa48e3Michael Kolb
928233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private View mCustomView;
938233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private WebChromeClient.CustomViewCallback mCustomViewCallback;
942d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger    private int mOriginalOrientation;
958233facddcc51865d612a919d450db6954aa48e3Michael Kolb
968233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private CombinedBookmarkHistoryView mComboView;
978233facddcc51865d612a919d450db6954aa48e3Michael Kolb
988233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private LinearLayout mErrorConsoleContainer = null;
998233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1008233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private Toast mStopToast;
1018233facddcc51865d612a919d450db6954aa48e3Michael Kolb
102bf2ec206e8743467961da3e857b07aad6c50cd67John Reck    private float mInitialY;
1035d43ce897758b7cb5deadc1203717b965334784cJohn Reck    private int mTitlebarScrollTriggerSlop;
1045a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb
1058233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // the default <video> poster
1068233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private Bitmap mDefaultVideoPoster;
1078233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // the video progress view
1088233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private View mVideoProgressView;
1098233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1108233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private boolean mActivityPaused;
111bf2ec206e8743467961da3e857b07aad6c50cd67John Reck    protected boolean mUseQuickControls;
1120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected TitleBar mTitleBar;
1130f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    private NavigationBarBase mNavigationBar;
1148233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1158233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public BaseUi(Activity browser, UiController controller) {
1168233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mActivity = browser;
1178233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mUiController = controller;
1188233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mTabControl = controller.getTabControl();
1198233facddcc51865d612a919d450db6954aa48e3Michael Kolb        Resources res = mActivity.getResources();
1203a696280cba53eea153c9d5707b236997d193328Michael Kolb        mInputManager = (InputMethodManager)
1213a696280cba53eea153c9d5707b236997d193328Michael Kolb                browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
1225a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb        mSecLockIcon = res.getDrawable(R.drawable.ic_secure_holo_dark);
1238233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mMixLockIcon = res.getDrawable(R.drawable.ic_partial_secure);
1248233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1258233facddcc51865d612a919d450db6954aa48e3Michael Kolb        FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
1268233facddcc51865d612a919d450db6954aa48e3Michael Kolb                .getDecorView().findViewById(android.R.id.content);
1277c6e1c928ea078034e7eacf32ef5c209138001d9John Reck        LayoutInflater.from(mActivity)
1287c6e1c928ea078034e7eacf32ef5c209138001d9John Reck                .inflate(R.layout.custom_screen, frameLayout);
1297c6e1c928ea078034e7eacf32ef5c209138001d9John Reck        mContentView = (FrameLayout) frameLayout.findViewById(
1308233facddcc51865d612a919d450db6954aa48e3Michael Kolb                R.id.main_content);
1317c6e1c928ea078034e7eacf32ef5c209138001d9John Reck        mErrorConsoleContainer = (LinearLayout) frameLayout
1328233facddcc51865d612a919d450db6954aa48e3Michael Kolb                .findViewById(R.id.error_console);
1337c6e1c928ea078034e7eacf32ef5c209138001d9John Reck        mCustomViewContainer = (FrameLayout) frameLayout
1348233facddcc51865d612a919d450db6954aa48e3Michael Kolb                .findViewById(R.id.fullscreen_custom_content);
135c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb        setFullscreen(BrowserSettings.getInstance().useFullscreen());
1365a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        mGenericFavicon = res.getDrawable(
1375a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb                R.drawable.app_web_browser_sm);
1385d43ce897758b7cb5deadc1203717b965334784cJohn Reck        ViewConfiguration config = ViewConfiguration.get(browser);
1395d43ce897758b7cb5deadc1203717b965334784cJohn Reck        mTitlebarScrollTriggerSlop = Math.max(
1405d43ce897758b7cb5deadc1203717b965334784cJohn Reck                config.getScaledOverflingDistance(),
1415d43ce897758b7cb5deadc1203717b965334784cJohn Reck                config.getScaledOverscrollDistance());
1425d43ce897758b7cb5deadc1203717b965334784cJohn Reck        mTitlebarScrollTriggerSlop = Math.max(mTitlebarScrollTriggerSlop,
1435d43ce897758b7cb5deadc1203717b965334784cJohn Reck                config.getScaledTouchSlop());
1440f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mTitleBar = new TitleBar(mActivity, mUiController, this,
1450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                mContentView);
1460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mTitleBar.setProgress(100);
1470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar = mTitleBar.getNavigationBar();
1488233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
1498233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1508233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private void cancelStopToast() {
1518233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mStopToast != null) {
1528233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mStopToast.cancel();
1538233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mStopToast = null;
1548233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
1558233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
1568233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1578233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // lifecycle
1588233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1598233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onPause() {
1607a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb        if (isCustomViewShowing()) {
1617a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb            onHideCustomView();
1627a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb        }
1638233facddcc51865d612a919d450db6954aa48e3Michael Kolb        cancelStopToast();
1648233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mActivityPaused = true;
1658233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
1668233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1678233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onResume() {
1688233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mActivityPaused = false;
1698233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
1708233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1716670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    protected boolean isActivityPaused() {
1726670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb        return mActivityPaused;
1738233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
1748233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1758233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onConfigurationChanged(Configuration config) {
1768233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
1778233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1780f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public Activity getActivity() {
1790f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        return mActivity;
1800f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1810f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1828233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // key handling
1838233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1848233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
1858233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public boolean onBackKey() {
1868233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mComboView != null) {
1878233facddcc51865d612a919d450db6954aa48e3Michael Kolb            if (!mComboView.onBackPressed()) {
1888233facddcc51865d612a919d450db6954aa48e3Michael Kolb                mUiController.removeComboView();
1898233facddcc51865d612a919d450db6954aa48e3Michael Kolb            }
1908233facddcc51865d612a919d450db6954aa48e3Michael Kolb            return true;
1918233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
1928233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mCustomView != null) {
1938233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mUiController.hideCustomView();
1948233facddcc51865d612a919d450db6954aa48e3Michael Kolb            return true;
1958233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
1968233facddcc51865d612a919d450db6954aa48e3Michael Kolb        return false;
1978233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
1988233facddcc51865d612a919d450db6954aa48e3Michael Kolb
1992814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb    @Override
2002814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb    public boolean onMenuKey() {
2012814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb        return false;
2022814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb    }
2032814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb
20430c714c853a4239e72ab1e238ce2a92472d06ab0John Reck    // Tab callbacks
2058233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
20630c714c853a4239e72ab1e238ce2a92472d06ab0John Reck    public void onTabDataChanged(Tab tab) {
20730c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        setUrlTitle(tab);
20830c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        setFavicon(tab);
20930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        updateLockIconToLatest(tab);
2105a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb        updateNavigationState(tab);
211ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck        mTitleBar.onTabDataChanged(tab);
2128233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
2138233facddcc51865d612a919d450db6954aa48e3Michael Kolb
2148233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
2154cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins    public void bookmarkedStatusHasChanged(Tab tab) {
21694b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck        if (tab.inForeground()) {
21794b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck            boolean isBookmark = tab.isBookmarkedSite();
2180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
21994b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck        }
2204cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins    }
2214cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins
2224cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins    @Override
2238233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onPageStopped(Tab tab) {
2248233facddcc51865d612a919d450db6954aa48e3Michael Kolb        cancelStopToast();
2258233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (tab.inForeground()) {
2268233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mStopToast = Toast
2278233facddcc51865d612a919d450db6954aa48e3Michael Kolb                    .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
2288233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mStopToast.show();
2298233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
2308233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
2318233facddcc51865d612a919d450db6954aa48e3Michael Kolb
2328233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
2331bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb    public boolean needsRestoreAllTabs() {
234847b532045e3cb117a847ebb956c9919401f332dJohn Reck        return true;
2351bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb    }
2361bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb
2371bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb    @Override
2388233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void addTab(Tab tab) {
2398233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
2408233facddcc51865d612a919d450db6954aa48e3Michael Kolb
2418233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
242377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb    public void setActiveTab(final Tab tab) {
2435d43ce897758b7cb5deadc1203717b965334784cJohn Reck        mHandler.removeMessages(MSG_HIDE_TITLEBAR);
24477df4568331d527f993f4d69168218ddf5acdddaMichael Kolb        if ((tab != mActiveTab) && (mActiveTab != null)) {
24577df4568331d527f993f4d69168218ddf5acdddaMichael Kolb            removeTabFromContentView(mActiveTab);
246bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            WebView web = mActiveTab.getWebView();
247bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            if (web != null) {
248bf2ec206e8743467961da3e857b07aad6c50cd67John Reck                web.setOnTouchListener(null);
249bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            }
2508233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
25177df4568331d527f993f4d69168218ddf5acdddaMichael Kolb        mActiveTab = tab;
252bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        WebView web = mActiveTab.getWebView();
253bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        if (web != null && !mUseQuickControls) {
254bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            web.setOnTouchListener(this);
255bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        }
2565d43ce897758b7cb5deadc1203717b965334784cJohn Reck        attachTabToContentView(tab);
2578233facddcc51865d612a919d450db6954aa48e3Michael Kolb        setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
25830c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        onTabDataChanged(tab);
25930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        onProgressChanged(tab);
260117f07d08e3e25e3c920a1dabe31dcd7643bacb2John Reck        boolean incognito = mActiveTab.getWebView().isPrivateBrowsingEnabled();
2610f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.setIncognitoMode(incognito);
2629206677e461328f15854c5fcb1366d0e261534c6Patrick Scott        updateAutoLogin(tab, false);
2636ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck        if (web != null && web.getVisibleTitleHeight()
2640f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                != mTitleBar.getEmbeddedHeight()
2650241e7556501caae1f57d2bdf3677d7e4a619eb0Michael Kolb                && !mUseQuickControls) {
2666ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck            showTitleBarForDuration();
2676ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck        }
2688233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
2698233facddcc51865d612a919d450db6954aa48e3Michael Kolb
270cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb    Tab getActiveTab() {
271cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb        return mActiveTab;
272cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb    }
273cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb
2748233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
2751bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb    public void updateTabs(List<Tab> tabs) {
2761bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb    }
2771bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb
2781bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb    @Override
2798233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void removeTab(Tab tab) {
28077df4568331d527f993f4d69168218ddf5acdddaMichael Kolb        if (mActiveTab == tab) {
2818233facddcc51865d612a919d450db6954aa48e3Michael Kolb            removeTabFromContentView(tab);
28277df4568331d527f993f4d69168218ddf5acdddaMichael Kolb            mActiveTab = null;
2838233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
2848233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
2858233facddcc51865d612a919d450db6954aa48e3Michael Kolb
2868233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
2878233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void detachTab(Tab tab) {
2888233facddcc51865d612a919d450db6954aa48e3Michael Kolb        removeTabFromContentView(tab);
2898233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
2908233facddcc51865d612a919d450db6954aa48e3Michael Kolb
2918233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
2928233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void attachTab(Tab tab) {
2938233facddcc51865d612a919d450db6954aa48e3Michael Kolb        attachTabToContentView(tab);
2948233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
2958233facddcc51865d612a919d450db6954aa48e3Michael Kolb
296377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb    protected void attachTabToContentView(Tab tab) {
297d1e2ccc38a2d5318a4ab06b2349cb43303fd6cebMichael Kolb        if ((tab == null) || (tab.getWebView() == null)) {
2988233facddcc51865d612a919d450db6954aa48e3Michael Kolb            return;
2998233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
3008233facddcc51865d612a919d450db6954aa48e3Michael Kolb        View container = tab.getViewContainer();
3018233facddcc51865d612a919d450db6954aa48e3Michael Kolb        WebView mainView  = tab.getWebView();
3028233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Attach the WebView to the container and then attach the
3038233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // container to the content view.
3048233facddcc51865d612a919d450db6954aa48e3Michael Kolb        FrameLayout wrapper =
3058233facddcc51865d612a919d450db6954aa48e3Michael Kolb                (FrameLayout) container.findViewById(R.id.webview_wrapper);
3068233facddcc51865d612a919d450db6954aa48e3Michael Kolb        ViewGroup parent = (ViewGroup) mainView.getParent();
3078233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (parent != wrapper) {
3088233facddcc51865d612a919d450db6954aa48e3Michael Kolb            if (parent != null) {
3098233facddcc51865d612a919d450db6954aa48e3Michael Kolb                Log.w(LOGTAG, "mMainView already has a parent in"
3108233facddcc51865d612a919d450db6954aa48e3Michael Kolb                        + " attachTabToContentView!");
3118233facddcc51865d612a919d450db6954aa48e3Michael Kolb                parent.removeView(mainView);
3128233facddcc51865d612a919d450db6954aa48e3Michael Kolb            }
3138233facddcc51865d612a919d450db6954aa48e3Michael Kolb            wrapper.addView(mainView);
3148233facddcc51865d612a919d450db6954aa48e3Michael Kolb        } else {
3158233facddcc51865d612a919d450db6954aa48e3Michael Kolb            Log.w(LOGTAG, "mMainView is already attached to wrapper in"
3168233facddcc51865d612a919d450db6954aa48e3Michael Kolb                    + " attachTabToContentView!");
3178233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
3188233facddcc51865d612a919d450db6954aa48e3Michael Kolb        parent = (ViewGroup) container.getParent();
3198233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (parent != mContentView) {
3208233facddcc51865d612a919d450db6954aa48e3Michael Kolb            if (parent != null) {
3218233facddcc51865d612a919d450db6954aa48e3Michael Kolb                Log.w(LOGTAG, "mContainer already has a parent in"
3228233facddcc51865d612a919d450db6954aa48e3Michael Kolb                        + " attachTabToContentView!");
3238233facddcc51865d612a919d450db6954aa48e3Michael Kolb                parent.removeView(container);
3248233facddcc51865d612a919d450db6954aa48e3Michael Kolb            }
3258233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mContentView.addView(container, COVER_SCREEN_PARAMS);
3268233facddcc51865d612a919d450db6954aa48e3Michael Kolb        } else {
3278233facddcc51865d612a919d450db6954aa48e3Michael Kolb            Log.w(LOGTAG, "mContainer is already attached to content in"
3288233facddcc51865d612a919d450db6954aa48e3Michael Kolb                    + " attachTabToContentView!");
3298233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
3308233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mUiController.attachSubWindow(tab);
3318233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
3328233facddcc51865d612a919d450db6954aa48e3Michael Kolb
3338233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private void removeTabFromContentView(Tab tab) {
3347cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb        hideTitleBar();
3358233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Remove the container that contains the main WebView.
3368233facddcc51865d612a919d450db6954aa48e3Michael Kolb        WebView mainView = tab.getWebView();
3378233facddcc51865d612a919d450db6954aa48e3Michael Kolb        View container = tab.getViewContainer();
3388233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mainView == null) {
3398233facddcc51865d612a919d450db6954aa48e3Michael Kolb            return;
3408233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
3418233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Remove the container from the content and then remove the
3428233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // WebView from the container. This will trigger a focus change
3438233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // needed by WebView.
34420776cc370cf1f092b73c356c02a0df966cfd185Michael Kolb        mainView.setEmbeddedTitleBar(null);
3458233facddcc51865d612a919d450db6954aa48e3Michael Kolb        FrameLayout wrapper =
3468233facddcc51865d612a919d450db6954aa48e3Michael Kolb                (FrameLayout) container.findViewById(R.id.webview_wrapper);
3478233facddcc51865d612a919d450db6954aa48e3Michael Kolb        wrapper.removeView(mainView);
3488233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mContentView.removeView(container);
3498233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mUiController.endActionMode();
3508233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mUiController.removeSubWindow(tab);
3518233facddcc51865d612a919d450db6954aa48e3Michael Kolb        ErrorConsoleView errorConsole = tab.getErrorConsole(false);
3528233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (errorConsole != null) {
3538233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mErrorConsoleContainer.removeView(errorConsole);
3548233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
3558233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
3568233facddcc51865d612a919d450db6954aa48e3Michael Kolb
357a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb    @Override
358a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb    public void onSetWebView(Tab tab, WebView webView) {
359a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb        View container = tab.getViewContainer();
360a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb        if (container == null) {
361a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb            // The tab consists of a container view, which contains the main
362a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb            // WebView, as well as any other UI elements associated with the tab.
363a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb            container = mActivity.getLayoutInflater().inflate(R.layout.tab,
3647c6e1c928ea078034e7eacf32ef5c209138001d9John Reck                    mContentView, false);
365a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb            tab.setViewContainer(container);
366a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb        }
367a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb        if (tab.getWebView() != webView) {
368a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb            // Just remove the old one.
369a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb            FrameLayout wrapper =
370a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb                    (FrameLayout) container.findViewById(R.id.webview_wrapper);
371a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb            wrapper.removeView(tab.getWebView());
372a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb        }
373a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb    }
374a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb
3758233facddcc51865d612a919d450db6954aa48e3Michael Kolb    /**
3761514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb     * create a sub window container and webview for the tab
3771514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb     * Note: this methods operates through side-effects for now
3781514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb     * it sets both the subView and subViewContainer for the given tab
3791514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb     * @param tab tab to create the sub window for
3801514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb     * @param subView webview to be set as a subwindow for the tab
3811514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb     */
3821514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb    @Override
3831514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb    public void createSubWindow(Tab tab, WebView subView) {
3841514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        View subViewContainer = mActivity.getLayoutInflater().inflate(
3851514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb                R.layout.browser_subwindow, null);
3861514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        ViewGroup inner = (ViewGroup) subViewContainer
3871514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb                .findViewById(R.id.inner_container);
3881514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
3891514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb                LayoutParams.MATCH_PARENT));
3901514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        final ImageButton cancel = (ImageButton) subViewContainer
3911514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb                .findViewById(R.id.subwindow_close);
3921514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        final WebView cancelSubView = subView;
3931514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        cancel.setOnClickListener(new OnClickListener() {
3941514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb            public void onClick(View v) {
3951514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb                cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView);
3961514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb            }
3971514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        });
3981514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        tab.setSubWebView(subView);
3991514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        tab.setSubViewContainer(subViewContainer);
4001514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb    }
4011514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb
4021514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb    /**
4038233facddcc51865d612a919d450db6954aa48e3Michael Kolb     * Remove the sub window from the content view.
4048233facddcc51865d612a919d450db6954aa48e3Michael Kolb     */
4058233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
4068233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void removeSubWindow(View subviewContainer) {
4078233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mContentView.removeView(subviewContainer);
4088233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mUiController.endActionMode();
4098233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
4108233facddcc51865d612a919d450db6954aa48e3Michael Kolb
4118233facddcc51865d612a919d450db6954aa48e3Michael Kolb    /**
4128233facddcc51865d612a919d450db6954aa48e3Michael Kolb     * Attach the sub window to the content view.
4138233facddcc51865d612a919d450db6954aa48e3Michael Kolb     */
4148233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
4158233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void attachSubWindow(View container) {
4161514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        if (container.getParent() != null) {
4171514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb            // already attached, remove first
4181514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb            ((ViewGroup) container.getParent()).removeView(container);
4191514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb        }
4208233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mContentView.addView(container, COVER_SCREEN_PARAMS);
4218233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
4228233facddcc51865d612a919d450db6954aa48e3Michael Kolb
42311d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    protected void refreshWebView() {
42446f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        WebView web = getWebView();
42546f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        if (web != null) {
42646f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb            web.invalidate();
42746f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        }
42846f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb    }
42946f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb
43046f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb    public void editUrl(boolean clearInput) {
43146f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        if (mUiController.isInCustomActionMode()) {
43246f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb            mUiController.endActionMode();
43311d1978d8d16004598347abc93918b54a5ef760bMichael Kolb        }
43446f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        showTitleBar();
435ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck        if (!getActiveTab().isSnapshot()) {
436ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck            mNavigationBar.startEditingUrl(clearInput);
437ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck        }
43811d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    }
43911d1978d8d16004598347abc93918b54a5ef760bMichael Kolb
4407cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    boolean canShowTitleBar() {
4417cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb        return !isTitleBarShowing()
4427cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb                && !isActivityPaused()
4437cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb                && (getActiveTab() != null)
44446f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb                && (getWebView() != null)
4457cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb                && !mUiController.isInCustomActionMode();
4468233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
4478233facddcc51865d612a919d450db6954aa48e3Michael Kolb
4480f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected void showTitleBar() {
449ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck        mHandler.removeMessages(MSG_HIDE_TITLEBAR);
45046f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        if (canShowTitleBar()) {
4510f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mTitleBar.show();
45246f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        }
4537cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    }
4546670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
4557cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    protected void hideTitleBar() {
4560f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (mTitleBar.isShowing()) {
4570f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mTitleBar.hide();
45846f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        }
4597cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    }
4606670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
4617cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    protected boolean isTitleBarShowing() {
4620f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        return mTitleBar.isShowing();
4637cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    }
4646670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
4655d43ce897758b7cb5deadc1203717b965334784cJohn Reck    public boolean isEditingUrl() {
4660f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        return mTitleBar.isEditingUrl();
4675d43ce897758b7cb5deadc1203717b965334784cJohn Reck    }
4685d43ce897758b7cb5deadc1203717b965334784cJohn Reck
4690f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public TitleBar getTitleBar() {
4700f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        return mTitleBar;
4710f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
4726670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
4737cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    protected void setTitleGravity(int gravity) {
47446f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        WebView web = getWebView();
47546f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        if (web != null) {
47646f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb            web.setTitleBarGravity(gravity);
4777cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb        }
4787cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb    }
4796670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
4806670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    @Override
48111d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    public void showVoiceTitleBar(String title, List<String> results) {
4820f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.setInVoiceMode(true, results);
4830f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.setDisplayTitle(title);
4848233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
4858233facddcc51865d612a919d450db6954aa48e3Michael Kolb
4866670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    @Override
4876670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    public void revertVoiceTitleBar(Tab tab) {
4880f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.setInVoiceMode(false, null);
48930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        String url = tab.getUrl();
4900f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.setDisplayTitle(url);
4918233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
4928233facddcc51865d612a919d450db6954aa48e3Michael Kolb
4938233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
49411d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    public void registerDropdownChangeListener(DropdownChangeListener d) {
4950f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.registerDropdownChangeListener(d);
49611d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    }
49711d1978d8d16004598347abc93918b54a5ef760bMichael Kolb
49811d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    @Override
4992bc8042224be51966d748b870768ec1b376a1621John Reck    public void showComboView(ComboViews startingView, Bundle extras) {
500439c9a58765aa6aab95d55422ee61ea8360e912dJohn Reck        if (mComboView != null) {
501439c9a58765aa6aab95d55422ee61ea8360e912dJohn Reck            return;
502439c9a58765aa6aab95d55422ee61ea8360e912dJohn Reck        }
5038233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mComboView = new CombinedBookmarkHistoryView(mActivity,
5048233facddcc51865d612a919d450db6954aa48e3Michael Kolb                mUiController,
5052bc8042224be51966d748b870768ec1b376a1621John Reck                startingView,
5068233facddcc51865d612a919d450db6954aa48e3Michael Kolb                extras);
50747d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb        FrameLayout wrapper =
50847d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb            (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
50947d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb        wrapper.setVisibility(View.GONE);
5100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.stopEditingUrl();
5113a696280cba53eea153c9d5707b236997d193328Michael Kolb        dismissIME();
512c16c595136aa7b49927a43ead26241abb1c731caMichael Kolb        hideTitleBar();
5133a696280cba53eea153c9d5707b236997d193328Michael Kolb        if (mActiveTab != null) {
5143a696280cba53eea153c9d5707b236997d193328Michael Kolb            mActiveTab.putInBackground();
5153a696280cba53eea153c9d5707b236997d193328Michael Kolb        }
5168233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
5178233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
5188233facddcc51865d612a919d450db6954aa48e3Michael Kolb
519ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb    public boolean isComboViewShowing() {
520ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb        return (mComboView != null);
521ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb    }
522ba23870babf7041e72f7d1119ad59d9bb32c6634Michael Kolb
5238233facddcc51865d612a919d450db6954aa48e3Michael Kolb    /**
5248233facddcc51865d612a919d450db6954aa48e3Michael Kolb     * dismiss the ComboPage
5258233facddcc51865d612a919d450db6954aa48e3Michael Kolb     */
5268233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
5278233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void hideComboView() {
5288233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mComboView != null) {
5298233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mContentView.removeView(mComboView);
53047d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb            FrameLayout wrapper =
53147d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb                (FrameLayout) mContentView.findViewById(R.id.webview_wrapper);
53247d63f843cf6973c7cb59db99888df7485bfee39Michael Kolb            wrapper.setVisibility(View.VISIBLE);
5338233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mComboView = null;
5348233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
5353a696280cba53eea153c9d5707b236997d193328Michael Kolb        if (mActiveTab != null) {
5363a696280cba53eea153c9d5707b236997d193328Michael Kolb            mActiveTab.putInForeground();
5373a696280cba53eea153c9d5707b236997d193328Michael Kolb        }
538b3417f0a68a1efc64604ea354ae7f856ce79cb16John Reck        mActivity.invalidateOptionsMenu();
5398233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
5408233facddcc51865d612a919d450db6954aa48e3Michael Kolb
5418233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
5422d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger    public void showCustomView(View view, int requestedOrientation,
5438233facddcc51865d612a919d450db6954aa48e3Michael Kolb            WebChromeClient.CustomViewCallback callback) {
5448233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // if a view already exists then immediately terminate the new one
5458233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mCustomView != null) {
5468233facddcc51865d612a919d450db6954aa48e3Michael Kolb            callback.onCustomViewHidden();
5478233facddcc51865d612a919d450db6954aa48e3Michael Kolb            return;
5488233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
5498233facddcc51865d612a919d450db6954aa48e3Michael Kolb
5502d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger        mOriginalOrientation = mActivity.getRequestedOrientation();
5512d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger
5528233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Add the custom view to its container.
5538233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
5548233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomView = view;
5558233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomViewCallback = callback;
5568233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Hide the content view.
5578233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mContentView.setVisibility(View.GONE);
5588233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Finally show the custom view container.
5598233facddcc51865d612a919d450db6954aa48e3Michael Kolb        setStatusBarVisibility(false);
5602d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger        mActivity.setRequestedOrientation(requestedOrientation);
5618233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomViewContainer.setVisibility(View.VISIBLE);
5628233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomViewContainer.bringToFront();
5638233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
5648233facddcc51865d612a919d450db6954aa48e3Michael Kolb
5658233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
5668233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onHideCustomView() {
5678233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mCustomView == null)
5688233facddcc51865d612a919d450db6954aa48e3Michael Kolb            return;
5698233facddcc51865d612a919d450db6954aa48e3Michael Kolb
5708233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Hide the custom view.
5718233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomView.setVisibility(View.GONE);
5728233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Remove the custom view from its container.
5738233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomViewContainer.removeView(mCustomView);
5748233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomView = null;
5758233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomViewContainer.setVisibility(View.GONE);
5768233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mCustomViewCallback.onCustomViewHidden();
5778233facddcc51865d612a919d450db6954aa48e3Michael Kolb        // Show the content view.
5782d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger        mActivity.setRequestedOrientation(mOriginalOrientation);
5798233facddcc51865d612a919d450db6954aa48e3Michael Kolb        setStatusBarVisibility(true);
5808233facddcc51865d612a919d450db6954aa48e3Michael Kolb        mContentView.setVisibility(View.VISIBLE);
5818233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
5828233facddcc51865d612a919d450db6954aa48e3Michael Kolb
5838233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
5848233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public boolean isCustomViewShowing() {
5858233facddcc51865d612a919d450db6954aa48e3Michael Kolb        return mCustomView != null;
5868233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
5878233facddcc51865d612a919d450db6954aa48e3Michael Kolb
5886670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    protected void dismissIME() {
5893a696280cba53eea153c9d5707b236997d193328Michael Kolb        if (mInputManager.isActive()) {
5903a696280cba53eea153c9d5707b236997d193328Michael Kolb            mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
5913a696280cba53eea153c9d5707b236997d193328Michael Kolb                    0);
5923a696280cba53eea153c9d5707b236997d193328Michael Kolb        }
5933a696280cba53eea153c9d5707b236997d193328Michael Kolb    }
5943a696280cba53eea153c9d5707b236997d193328Michael Kolb
5956670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    @Override
5966670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    public boolean showsWeb() {
5976670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb        return mCustomView == null
5986670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb            && mComboView == null;
5996670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    }
6006670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
6019206677e461328f15854c5fcb1366d0e261534c6Patrick Scott    @Override
6029206677e461328f15854c5fcb1366d0e261534c6Patrick Scott    public void showAutoLogin(Tab tab) {
6039206677e461328f15854c5fcb1366d0e261534c6Patrick Scott        updateAutoLogin(tab, true);
6049206677e461328f15854c5fcb1366d0e261534c6Patrick Scott    }
6059206677e461328f15854c5fcb1366d0e261534c6Patrick Scott
6069206677e461328f15854c5fcb1366d0e261534c6Patrick Scott    @Override
6079206677e461328f15854c5fcb1366d0e261534c6Patrick Scott    public void hideAutoLogin(Tab tab) {
6089206677e461328f15854c5fcb1366d0e261534c6Patrick Scott        updateAutoLogin(tab, true);
6099206677e461328f15854c5fcb1366d0e261534c6Patrick Scott    }
6109206677e461328f15854c5fcb1366d0e261534c6Patrick Scott
6118233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // -------------------------------------------------------------------------
6128233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6135a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb    protected void updateNavigationState(Tab tab) {
6145a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb    }
6155a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb
61611d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    protected void updateAutoLogin(Tab tab, boolean animate) {
6170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mTitleBar.updateAutoLogin(tab, animate);
61811d1978d8d16004598347abc93918b54a5ef760bMichael Kolb    }
6199206677e461328f15854c5fcb1366d0e261534c6Patrick Scott
6208233facddcc51865d612a919d450db6954aa48e3Michael Kolb    /**
6218233facddcc51865d612a919d450db6954aa48e3Michael Kolb     * Update the lock icon to correspond to our latest state.
6228233facddcc51865d612a919d450db6954aa48e3Michael Kolb     */
6236670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    protected void updateLockIconToLatest(Tab t) {
62430c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        if (t != null && t.inForeground()) {
6258233facddcc51865d612a919d450db6954aa48e3Michael Kolb            updateLockIconImage(t.getLockIconType());
6268233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
6278233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6288233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6298233facddcc51865d612a919d450db6954aa48e3Michael Kolb    /**
6308233facddcc51865d612a919d450db6954aa48e3Michael Kolb     * Updates the lock-icon image in the title-bar.
6318233facddcc51865d612a919d450db6954aa48e3Michael Kolb     */
63230c714c853a4239e72ab1e238ce2a92472d06ab0John Reck    private void updateLockIconImage(LockIcon lockIconType) {
6338233facddcc51865d612a919d450db6954aa48e3Michael Kolb        Drawable d = null;
63430c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        if (lockIconType == LockIcon.LOCK_ICON_SECURE) {
6358233facddcc51865d612a919d450db6954aa48e3Michael Kolb            d = mSecLockIcon;
63630c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        } else if (lockIconType == LockIcon.LOCK_ICON_MIXED) {
6378233facddcc51865d612a919d450db6954aa48e3Michael Kolb            d = mMixLockIcon;
6388233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
6390f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mNavigationBar.setLock(d);
6408233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6418233facddcc51865d612a919d450db6954aa48e3Michael Kolb
64230c714c853a4239e72ab1e238ce2a92472d06ab0John Reck    protected void setUrlTitle(Tab tab) {
64330c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        String url = tab.getUrl();
64430c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        String title = tab.getTitle();
6456670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb        if (TextUtils.isEmpty(title)) {
6466670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb            title = url;
6476670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb        }
6486670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb        if (tab.isInVoiceSearchMode()) return;
6496670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb        if (tab.inForeground()) {
6500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mNavigationBar.setDisplayTitle(url);
6516670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb        }
6528233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6538233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6546670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    // Set the favicon in the title bar.
65530c714c853a4239e72ab1e238ce2a92472d06ab0John Reck    protected void setFavicon(Tab tab) {
65630c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        if (tab.inForeground()) {
65730c714c853a4239e72ab1e238ce2a92472d06ab0John Reck            Bitmap icon = tab.getFavicon();
6580f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mNavigationBar.setFavicon(icon);
65930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck        }
6608233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6618233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6628233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
6638233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onActionModeFinished(boolean inLoad) {
6648233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6658233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6666670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    // active tabs page
6676670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
6686670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    public void showActiveTabsPage() {
6696670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    }
6706670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
6716670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    /**
6726670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb     * Remove the active tabs page.
6736670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb     */
6746670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    public void removeActiveTabsPage() {
6756670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb    }
6766670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb
6778233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // menu handling callbacks
6788233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6798233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
6801acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    public boolean onPrepareOptionsMenu(Menu menu) {
6811acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb        return true;
6821acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    }
6831acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb
6841acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb    @Override
6858233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onOptionsMenuOpened() {
6868233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6878233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6888233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
6898233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onExtendedMenuOpened() {
6908233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6918233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6928233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
6938233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onOptionsMenuClosed(boolean inLoad) {
6948233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6958233facddcc51865d612a919d450db6954aa48e3Michael Kolb
6968233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
6978233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onExtendedMenuClosed(boolean inLoad) {
6988233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
6998233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7008233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
7018233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onContextMenuCreated(Menu menu) {
7028233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
7038233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7048233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
7058233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void onContextMenuClosed(Menu menu, boolean inLoad) {
7068233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
7078233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7088233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // error console
7098233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7108233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
7118233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public void setShouldShowErrorConsole(Tab tab, boolean flag) {
7129fcefd19ee20ec9f792ddc84be9a871550e82997Michael Kolb        if (tab == null) return;
7138233facddcc51865d612a919d450db6954aa48e3Michael Kolb        ErrorConsoleView errorConsole = tab.getErrorConsole(true);
7148233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (flag) {
7158233facddcc51865d612a919d450db6954aa48e3Michael Kolb            // Setting the show state of the console will cause it's the layout
7168233facddcc51865d612a919d450db6954aa48e3Michael Kolb            // to be inflated.
7178233facddcc51865d612a919d450db6954aa48e3Michael Kolb            if (errorConsole.numberOfErrors() > 0) {
7188233facddcc51865d612a919d450db6954aa48e3Michael Kolb                errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
7198233facddcc51865d612a919d450db6954aa48e3Michael Kolb            } else {
7208233facddcc51865d612a919d450db6954aa48e3Michael Kolb                errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
7218233facddcc51865d612a919d450db6954aa48e3Michael Kolb            }
7228233facddcc51865d612a919d450db6954aa48e3Michael Kolb            if (errorConsole.getParent() != null) {
7238233facddcc51865d612a919d450db6954aa48e3Michael Kolb                mErrorConsoleContainer.removeView(errorConsole);
7248233facddcc51865d612a919d450db6954aa48e3Michael Kolb            }
7258233facddcc51865d612a919d450db6954aa48e3Michael Kolb            // Now we can add it to the main view.
7268233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mErrorConsoleContainer.addView(errorConsole,
7278233facddcc51865d612a919d450db6954aa48e3Michael Kolb                    new LinearLayout.LayoutParams(
7288233facddcc51865d612a919d450db6954aa48e3Michael Kolb                            ViewGroup.LayoutParams.MATCH_PARENT,
7298233facddcc51865d612a919d450db6954aa48e3Michael Kolb                            ViewGroup.LayoutParams.WRAP_CONTENT));
7308233facddcc51865d612a919d450db6954aa48e3Michael Kolb        } else {
7318233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mErrorConsoleContainer.removeView(errorConsole);
7328233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
7338233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
7348233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7358233facddcc51865d612a919d450db6954aa48e3Michael Kolb    private void setStatusBarVisibility(boolean visible) {
736d3bf86fd84f4f1a75cc9cd26f818ae157c806d9bJoe Onorato        WindowManager.LayoutParams params = mActivity.getWindow().getAttributes();
737d3bf86fd84f4f1a75cc9cd26f818ae157c806d9bJoe Onorato        params.systemUiVisibility = visible ? View.STATUS_BAR_VISIBLE : View.STATUS_BAR_HIDDEN;
738d3bf86fd84f4f1a75cc9cd26f818ae157c806d9bJoe Onorato        mActivity.getWindow().setAttributes(params);
7398233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
7408233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7418233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // -------------------------------------------------------------------------
7428233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // Helper function for WebChromeClient
7438233facddcc51865d612a919d450db6954aa48e3Michael Kolb    // -------------------------------------------------------------------------
7448233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7458233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
7468233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public Bitmap getDefaultVideoPoster() {
7478233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mDefaultVideoPoster == null) {
7488233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mDefaultVideoPoster = BitmapFactory.decodeResource(
7498233facddcc51865d612a919d450db6954aa48e3Michael Kolb                    mActivity.getResources(), R.drawable.default_video_poster);
7508233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
7518233facddcc51865d612a919d450db6954aa48e3Michael Kolb        return mDefaultVideoPoster;
7528233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
7538233facddcc51865d612a919d450db6954aa48e3Michael Kolb
7548233facddcc51865d612a919d450db6954aa48e3Michael Kolb    @Override
7558233facddcc51865d612a919d450db6954aa48e3Michael Kolb    public View getVideoLoadingProgressView() {
7568233facddcc51865d612a919d450db6954aa48e3Michael Kolb        if (mVideoProgressView == null) {
7578233facddcc51865d612a919d450db6954aa48e3Michael Kolb            LayoutInflater inflater = LayoutInflater.from(mActivity);
7588233facddcc51865d612a919d450db6954aa48e3Michael Kolb            mVideoProgressView = inflater.inflate(
7598233facddcc51865d612a919d450db6954aa48e3Michael Kolb                    R.layout.video_loading_progress, null);
7608233facddcc51865d612a919d450db6954aa48e3Michael Kolb        }
7618233facddcc51865d612a919d450db6954aa48e3Michael Kolb        return mVideoProgressView;
7628233facddcc51865d612a919d450db6954aa48e3Michael Kolb    }
7638233facddcc51865d612a919d450db6954aa48e3Michael Kolb
764843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb    @Override
765843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb    public void showMaxTabsWarning() {
766843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb        Toast warning = Toast.makeText(mActivity,
767843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb                mActivity.getString(R.string.max_tabs_warning),
768843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb                Toast.LENGTH_SHORT);
769843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb        warning.show();
770843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb    }
771843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb
772fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb    protected void captureTab(final Tab tab) {
773fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb        captureTab(tab,
774fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb                (int) mActivity.getResources()
775fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb                        .getDimension(R.dimen.qc_thumb_width),
776fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb                (int) mActivity.getResources()
777fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb                        .getDimension(R.dimen.qc_thumb_height));
778fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb    }
779fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb
780fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb    protected void captureTab(final Tab tab, int width, int height) {
781fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb        if ((tab == null) || (tab.getWebView() == null)) return;
782fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb        Bitmap sshot = Controller.createScreenshot(tab, width, height);
783fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb        tab.setScreenshot(sshot);
784fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb    }
785fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb
78646f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb    protected WebView getWebView() {
78746f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        if (mActiveTab != null) {
78846f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb            return mActiveTab.getWebView();
78946f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        } else {
79046f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb            return null;
79146f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb        }
792fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb    }
793fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb
794fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb    protected Menu getMenu() {
795fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb        MenuBuilder menu = new MenuBuilder(mActivity);
796fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb        mActivity.getMenuInflater().inflate(R.menu.browser, menu);
797fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb        return menu;
798fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb    }
799fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb
800c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb    public void setFullscreen(boolean enabled) {
801c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb        if (enabled) {
802c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb            mActivity.getWindow().setFlags(
803c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
804c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
805c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb        } else {
806c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb            mActivity.getWindow().clearFlags(
807c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
808c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb        }
809c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb    }
810c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb
8110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public Drawable getFaviconDrawable(Bitmap icon) {
8125a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        Drawable[] array = new Drawable[3];
8135a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        array[0] = new PaintDrawable(Color.BLACK);
8145a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        PaintDrawable p = new PaintDrawable(Color.WHITE);
8155a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        array[1] = p;
8165a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        if (icon == null) {
8175a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb            array[2] = mGenericFavicon;
8185a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        } else {
8195a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb            array[2] = new BitmapDrawable(icon);
8205a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        }
8215a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        LayerDrawable d = new LayerDrawable(array);
8225a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        d.setLayerInset(1, 1, 1, 1, 1);
8235a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        d.setLayerInset(2, 2, 2, 2, 2);
8245a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb        return d;
8255a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb    }
8265a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb
8275d43ce897758b7cb5deadc1203717b965334784cJohn Reck    public boolean isLoading() {
8285d43ce897758b7cb5deadc1203717b965334784cJohn Reck        return mActiveTab != null ? mActiveTab.inPageLoad() : false;
8295d43ce897758b7cb5deadc1203717b965334784cJohn Reck    }
8305d43ce897758b7cb5deadc1203717b965334784cJohn Reck
8315d43ce897758b7cb5deadc1203717b965334784cJohn Reck    /**
8325d43ce897758b7cb5deadc1203717b965334784cJohn Reck     * Suggest to the UI that the title bar can be hidden. The UI will then
8335d43ce897758b7cb5deadc1203717b965334784cJohn Reck     * decide whether or not to hide based off a number of factors, such
8345d43ce897758b7cb5deadc1203717b965334784cJohn Reck     * as if the user is editing the URL bar or if the page is loading
8355d43ce897758b7cb5deadc1203717b965334784cJohn Reck     */
8365d43ce897758b7cb5deadc1203717b965334784cJohn Reck    public void suggestHideTitleBar() {
837ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck        if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()) {
8385d43ce897758b7cb5deadc1203717b965334784cJohn Reck            hideTitleBar();
8395d43ce897758b7cb5deadc1203717b965334784cJohn Reck        }
8405d43ce897758b7cb5deadc1203717b965334784cJohn Reck    }
8415d43ce897758b7cb5deadc1203717b965334784cJohn Reck
842017ffabc8af29b0cf14fecc6aad4a61acb8373a2Michael Kolb    protected void showTitleBarForDuration() {
8436ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck        showTitleBar();
8446ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck        Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
8456ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck        mHandler.sendMessageDelayed(msg, HIDE_TITLEBAR_DELAY);
8466ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck    }
8476ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck
8485d43ce897758b7cb5deadc1203717b965334784cJohn Reck    @Override
849bf2ec206e8743467961da3e857b07aad6c50cd67John Reck    public boolean onTouch(View v, MotionEvent event) {
850bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        switch (event.getAction()) {
851bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        case MotionEvent.ACTION_DOWN:
852bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            mInitialY = event.getY();
853bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            break;
854bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        case MotionEvent.ACTION_MOVE:
855bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            WebView web = (WebView) v;
8561e822eba4fea39d926c92e304626efd7cc769d53John Reck            if (event.getPointerCount() == 1
8571e822eba4fea39d926c92e304626efd7cc769d53John Reck                    && !isTitleBarShowing()
858bf2ec206e8743467961da3e857b07aad6c50cd67John Reck                    && web.getVisibleTitleHeight() == 0
859bf2ec206e8743467961da3e857b07aad6c50cd67John Reck                    && event.getY() > (mInitialY + mTitlebarScrollTriggerSlop)) {
8605d43ce897758b7cb5deadc1203717b965334784cJohn Reck                showTitleBar();
861bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            } else if (event.getY() < mInitialY) {
862bf2ec206e8743467961da3e857b07aad6c50cd67John Reck                mInitialY = event.getY();
863bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            }
864bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            break;
865bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        case MotionEvent.ACTION_CANCEL:
866bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        case MotionEvent.ACTION_UP:
867bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            if (isTitleBarShowing()) {
8685d43ce897758b7cb5deadc1203717b965334784cJohn Reck                Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
8695d43ce897758b7cb5deadc1203717b965334784cJohn Reck                mHandler.sendMessageDelayed(msg, HIDE_TITLEBAR_DELAY);
8705d43ce897758b7cb5deadc1203717b965334784cJohn Reck            }
871bf2ec206e8743467961da3e857b07aad6c50cd67John Reck            break;
8725d43ce897758b7cb5deadc1203717b965334784cJohn Reck        }
873bf2ec206e8743467961da3e857b07aad6c50cd67John Reck        return false;
8745d43ce897758b7cb5deadc1203717b965334784cJohn Reck    }
8755d43ce897758b7cb5deadc1203717b965334784cJohn Reck
8765d43ce897758b7cb5deadc1203717b965334784cJohn Reck    private Handler mHandler = new Handler() {
8775d43ce897758b7cb5deadc1203717b965334784cJohn Reck
8785d43ce897758b7cb5deadc1203717b965334784cJohn Reck        @Override
8795d43ce897758b7cb5deadc1203717b965334784cJohn Reck        public void handleMessage(Message msg) {
8805d43ce897758b7cb5deadc1203717b965334784cJohn Reck            if (msg.what == MSG_HIDE_TITLEBAR) {
8815d43ce897758b7cb5deadc1203717b965334784cJohn Reck                suggestHideTitleBar();
8825d43ce897758b7cb5deadc1203717b965334784cJohn Reck            }
8835d43ce897758b7cb5deadc1203717b965334784cJohn Reck        }
8845d43ce897758b7cb5deadc1203717b965334784cJohn Reck    };
8858233facddcc51865d612a919d450db6954aa48e3Michael Kolb}
886