BaseUi.java revision c5675ad4baf34547770a98c7c0d8dec7f8fb4999
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; 2053ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolbimport android.content.Context; 21d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reckimport android.content.Intent; 228233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.content.res.Configuration; 238233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.content.res.Resources; 248233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.Bitmap; 258233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.BitmapFactory; 265a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.Color; 275a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.drawable.BitmapDrawable; 288233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.graphics.drawable.Drawable; 295a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.drawable.LayerDrawable; 305a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolbimport android.graphics.drawable.PaintDrawable; 318233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.os.Bundle; 325d43ce897758b7cb5deadc1203717b965334784cJohn Reckimport android.os.Handler; 335d43ce897758b7cb5deadc1203717b965334784cJohn Reckimport android.os.Message; 348233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.text.TextUtils; 358233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.util.Log; 368233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.Gravity; 378233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.LayoutInflater; 388233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.Menu; 393ca12750f9b6231b00a1856dcb25c2d2e07e8784Michael Kolbimport android.view.MenuItem; 4031065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolbimport android.view.MotionEvent; 418233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.View; 421514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.view.View.OnClickListener; 438233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.ViewGroup; 441514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.view.ViewGroup.LayoutParams; 45c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolbimport android.view.Window; 468233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.view.WindowManager; 473a696280cba53eea153c9d5707b236997d193328Michael Kolbimport android.view.inputmethod.InputMethodManager; 488233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.webkit.WebChromeClient; 498233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.webkit.WebView; 508233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.FrameLayout; 511514bb7ed5656316a8dac966cee21653f3c59affMichael Kolbimport android.widget.ImageButton; 528233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.LinearLayout; 538233facddcc51865d612a919d450db6954aa48e3Michael Kolbimport android.widget.Toast; 548233facddcc51865d612a919d450db6954aa48e3Michael Kolb 552466effd6ef97aa17396c214d51f9f19a4760260Steve Blockimport com.android.browser.Tab.SecurityState; 56bf2ec206e8743467961da3e857b07aad6c50cd67John Reckimport com.android.internal.view.menu.MenuBuilder; 57bf2ec206e8743467961da3e857b07aad6c50cd67John Reck 581bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolbimport java.util.List; 591bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb 608233facddcc51865d612a919d450db6954aa48e3Michael Kolb/** 618233facddcc51865d612a919d450db6954aa48e3Michael Kolb * UI interface definitions 628233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 63718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reckpublic abstract class BaseUi implements UI { 648233facddcc51865d612a919d450db6954aa48e3Michael Kolb 658233facddcc51865d612a919d450db6954aa48e3Michael Kolb private static final String LOGTAG = "BaseUi"; 668233facddcc51865d612a919d450db6954aa48e3Michael Kolb 676670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = 688233facddcc51865d612a919d450db6954aa48e3Michael Kolb new FrameLayout.LayoutParams( 698233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 708233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT); 718233facddcc51865d612a919d450db6954aa48e3Michael Kolb 726670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = 738233facddcc51865d612a919d450db6954aa48e3Michael Kolb new FrameLayout.LayoutParams( 748233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 758233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 768233facddcc51865d612a919d450db6954aa48e3Michael Kolb Gravity.CENTER); 778233facddcc51865d612a919d450db6954aa48e3Michael Kolb 785d43ce897758b7cb5deadc1203717b965334784cJohn Reck private static final int MSG_HIDE_TITLEBAR = 1; 79ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms 805d43ce897758b7cb5deadc1203717b965334784cJohn Reck 818233facddcc51865d612a919d450db6954aa48e3Michael Kolb Activity mActivity; 828233facddcc51865d612a919d450db6954aa48e3Michael Kolb UiController mUiController; 838233facddcc51865d612a919d450db6954aa48e3Michael Kolb TabControl mTabControl; 84377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb protected Tab mActiveTab; 853a696280cba53eea153c9d5707b236997d193328Michael Kolb private InputMethodManager mInputManager; 868233facddcc51865d612a919d450db6954aa48e3Michael Kolb 872466effd6ef97aa17396c214d51f9f19a4760260Steve Block private Drawable mLockIconSecure; 882466effd6ef97aa17396c214d51f9f19a4760260Steve Block private Drawable mLockIconMixed; 895a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb protected Drawable mGenericFavicon; 908233facddcc51865d612a919d450db6954aa48e3Michael Kolb 916670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected FrameLayout mContentView; 92f205560dacc8a85f0443ca1949a68962404321e8Michael Kolb protected FrameLayout mCustomViewContainer; 9331065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb protected FrameLayout mFullscreenContainer; 948233facddcc51865d612a919d450db6954aa48e3Michael Kolb 9531065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb private View mCustomView; 968233facddcc51865d612a919d450db6954aa48e3Michael Kolb private WebChromeClient.CustomViewCallback mCustomViewCallback; 972d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger private int mOriginalOrientation; 988233facddcc51865d612a919d450db6954aa48e3Michael Kolb 998233facddcc51865d612a919d450db6954aa48e3Michael Kolb private LinearLayout mErrorConsoleContainer = null; 1008233facddcc51865d612a919d450db6954aa48e3Michael Kolb 101718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck private UrlBarAutoShowManager mUrlBarAutoShowManager; 1028233facddcc51865d612a919d450db6954aa48e3Michael Kolb 103718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck private Toast mStopToast; 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); 1222466effd6ef97aa17396c214d51f9f19a4760260Steve Block mLockIconSecure = res.getDrawable(R.drawable.ic_secure_holo_dark); 1232466effd6ef97aa17396c214d51f9f19a4760260Steve Block mLockIconMixed = res.getDrawable(R.drawable.ic_secure_partial_holo_dark); 1248233facddcc51865d612a919d450db6954aa48e3Michael Kolb FrameLayout frameLayout = (FrameLayout) mActivity.getWindow() 1258233facddcc51865d612a919d450db6954aa48e3Michael Kolb .getDecorView().findViewById(android.R.id.content); 1267c6e1c928ea078034e7eacf32ef5c209138001d9John Reck LayoutInflater.from(mActivity) 1277c6e1c928ea078034e7eacf32ef5c209138001d9John Reck .inflate(R.layout.custom_screen, frameLayout); 1287c6e1c928ea078034e7eacf32ef5c209138001d9John Reck mContentView = (FrameLayout) frameLayout.findViewById( 1298233facddcc51865d612a919d450db6954aa48e3Michael Kolb R.id.main_content); 13053ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolb mCustomViewContainer = (FrameLayout) frameLayout.findViewById( 13153ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolb R.id.fullscreen_custom_content); 1327c6e1c928ea078034e7eacf32ef5c209138001d9John Reck mErrorConsoleContainer = (LinearLayout) frameLayout 1338233facddcc51865d612a919d450db6954aa48e3Michael Kolb .findViewById(R.id.error_console); 134c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb setFullscreen(BrowserSettings.getInstance().useFullscreen()); 1355a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb mGenericFavicon = res.getDrawable( 1365a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb R.drawable.app_web_browser_sm); 1370f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBar = new TitleBar(mActivity, mUiController, this, 1380f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mContentView); 1390f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBar.setProgress(100); 1400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar = mTitleBar.getNavigationBar(); 141718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck mUrlBarAutoShowManager = new UrlBarAutoShowManager(this); 1428233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1438233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1448233facddcc51865d612a919d450db6954aa48e3Michael Kolb private void cancelStopToast() { 1458233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mStopToast != null) { 1468233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast.cancel(); 1478233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast = null; 1488233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1498233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1508233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1518233facddcc51865d612a919d450db6954aa48e3Michael Kolb // lifecycle 1528233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1538233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onPause() { 1547a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb if (isCustomViewShowing()) { 1557a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb onHideCustomView(); 1567a5cf4714453bd982afc662f373d0c38cddfb023Michael Kolb } 1578233facddcc51865d612a919d450db6954aa48e3Michael Kolb cancelStopToast(); 1588233facddcc51865d612a919d450db6954aa48e3Michael Kolb mActivityPaused = true; 1598233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1608233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1618233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onResume() { 1628233facddcc51865d612a919d450db6954aa48e3Michael Kolb mActivityPaused = false; 1632ae6ef7f6c146a5bc3a4c7ef8de56505eb02399eMichael Kolb // check if we exited without setting active tab 1642ae6ef7f6c146a5bc3a4c7ef8de56505eb02399eMichael Kolb // b: 5188145 1651a4625a4fa1f3aae01de5cee5338ee4552edd3e8Michael Kolb final Tab ct = mTabControl.getCurrentTab(); 1661a4625a4fa1f3aae01de5cee5338ee4552edd3e8Michael Kolb if (ct != null) { 1671a4625a4fa1f3aae01de5cee5338ee4552edd3e8Michael Kolb setActiveTab(ct); 1681a4625a4fa1f3aae01de5cee5338ee4552edd3e8Michael Kolb } 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 (mCustomView != null) { 1878233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.hideCustomView(); 1888233facddcc51865d612a919d450db6954aa48e3Michael Kolb return true; 1898233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1908233facddcc51865d612a919d450db6954aa48e3Michael Kolb return false; 1918233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 1928233facddcc51865d612a919d450db6954aa48e3Michael Kolb 1932814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb @Override 1942814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb public boolean onMenuKey() { 1952814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb return false; 1962814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb } 1972814a362c21ac219410d9b54e1bd3e8152b845c7Michael Kolb 19830c714c853a4239e72ab1e238ce2a92472d06ab0John Reck // Tab callbacks 1998233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 20030c714c853a4239e72ab1e238ce2a92472d06ab0John Reck public void onTabDataChanged(Tab tab) { 20130c714c853a4239e72ab1e238ce2a92472d06ab0John Reck setUrlTitle(tab); 20230c714c853a4239e72ab1e238ce2a92472d06ab0John Reck setFavicon(tab); 20330c714c853a4239e72ab1e238ce2a92472d06ab0John Reck updateLockIconToLatest(tab); 2045a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb updateNavigationState(tab); 205ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mTitleBar.onTabDataChanged(tab); 206419f6b4136a8fac758e2159f223700b1dfcc20e2John Reck mNavigationBar.onTabDataChanged(tab); 207a53c98902be0f9f959b6af06227254e5ad2130c9Michael Kolb onProgressChanged(tab); 2088233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2098233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2108233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2114cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins public void bookmarkedStatusHasChanged(Tab tab) { 21294b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck if (tab.inForeground()) { 21394b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck boolean isBookmark = tab.isBookmarkedSite(); 2140f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setCurrentUrlIsBookmark(isBookmark); 21594b7e04932d77d73f348efecf7f2dd6b4ee5e5a1John Reck } 2164cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins } 2174cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins 2184cd97793901e8f5681cf642d0b2684697964a37aLeon Scroggins @Override 2198233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onPageStopped(Tab tab) { 2208233facddcc51865d612a919d450db6954aa48e3Michael Kolb cancelStopToast(); 2218233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (tab.inForeground()) { 2228233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast = Toast 2238233facddcc51865d612a919d450db6954aa48e3Michael Kolb .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT); 2248233facddcc51865d612a919d450db6954aa48e3Michael Kolb mStopToast.show(); 2258233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2268233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2278233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2288233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2291bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb public boolean needsRestoreAllTabs() { 230847b532045e3cb117a847ebb956c9919401f332dJohn Reck return true; 2311bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb } 2321bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb 2331bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb @Override 2348233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void addTab(Tab tab) { 2358233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2368233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2378233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 238377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb public void setActiveTab(final Tab tab) { 2395d43ce897758b7cb5deadc1203717b965334784cJohn Reck mHandler.removeMessages(MSG_HIDE_TITLEBAR); 24077df4568331d527f993f4d69168218ddf5acdddaMichael Kolb if ((tab != mActiveTab) && (mActiveTab != null)) { 24177df4568331d527f993f4d69168218ddf5acdddaMichael Kolb removeTabFromContentView(mActiveTab); 242bf2ec206e8743467961da3e857b07aad6c50cd67John Reck WebView web = mActiveTab.getWebView(); 243bf2ec206e8743467961da3e857b07aad6c50cd67John Reck if (web != null) { 244bf2ec206e8743467961da3e857b07aad6c50cd67John Reck web.setOnTouchListener(null); 245bf2ec206e8743467961da3e857b07aad6c50cd67John Reck } 2468233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 24777df4568331d527f993f4d69168218ddf5acdddaMichael Kolb mActiveTab = tab; 248bf2ec206e8743467961da3e857b07aad6c50cd67John Reck WebView web = mActiveTab.getWebView(); 249718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck updateUrlBarAutoShowManagerTarget(); 2505d43ce897758b7cb5deadc1203717b965334784cJohn Reck attachTabToContentView(tab); 2518233facddcc51865d612a919d450db6954aa48e3Michael Kolb setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole()); 25230c714c853a4239e72ab1e238ce2a92472d06ab0John Reck onTabDataChanged(tab); 25330c714c853a4239e72ab1e238ce2a92472d06ab0John Reck onProgressChanged(tab); 25403b6bc6dc3644e9843f2ff05bca543e546fe3a61Michael Kolb mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled()); 2559206677e461328f15854c5fcb1366d0e261534c6Patrick Scott updateAutoLogin(tab, false); 2566ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck if (web != null && web.getVisibleTitleHeight() 2570f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck != mTitleBar.getEmbeddedHeight() 2580241e7556501caae1f57d2bdf3677d7e4a619eb0Michael Kolb && !mUseQuickControls) { 2596ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck showTitleBarForDuration(); 2606ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck } 2618233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2628233facddcc51865d612a919d450db6954aa48e3Michael Kolb 263718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck protected void updateUrlBarAutoShowManagerTarget() { 264718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck WebView web = mActiveTab != null ? mActiveTab.getWebView() : null; 265718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck if (!mUseQuickControls && web instanceof BrowserWebView) { 266718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck mUrlBarAutoShowManager.setTarget((BrowserWebView) web); 267718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck } else { 268718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck mUrlBarAutoShowManager.setTarget(null); 269718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck } 270718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck } 271718a24d6c9671fe2da4112a3b5f30fd3939b38e8John Reck 272cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb Tab getActiveTab() { 273cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb return mActiveTab; 274cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb } 275cfa3af5c59abb38c895416a80ef16da0ec1b5287Michael Kolb 2768233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2771bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb public void updateTabs(List<Tab> tabs) { 2781bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb } 2791bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb 2801bf231334fd4bda8dbde5b9a0345c756a213b3a2Michael Kolb @Override 2818233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void removeTab(Tab tab) { 28277df4568331d527f993f4d69168218ddf5acdddaMichael Kolb if (mActiveTab == tab) { 2838233facddcc51865d612a919d450db6954aa48e3Michael Kolb removeTabFromContentView(tab); 28477df4568331d527f993f4d69168218ddf5acdddaMichael Kolb mActiveTab = null; 2858233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2868233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2878233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2888233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2898233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void detachTab(Tab tab) { 2908233facddcc51865d612a919d450db6954aa48e3Michael Kolb removeTabFromContentView(tab); 2918233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2928233facddcc51865d612a919d450db6954aa48e3Michael Kolb 2938233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 2948233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void attachTab(Tab tab) { 2958233facddcc51865d612a919d450db6954aa48e3Michael Kolb attachTabToContentView(tab); 2968233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 2978233facddcc51865d612a919d450db6954aa48e3Michael Kolb 298377ea31324391e7878f6f5b7a991c74988c18403Michael Kolb protected void attachTabToContentView(Tab tab) { 299d1e2ccc38a2d5318a4ab06b2349cb43303fd6cebMichael Kolb if ((tab == null) || (tab.getWebView() == null)) { 3008233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 3018233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3028233facddcc51865d612a919d450db6954aa48e3Michael Kolb View container = tab.getViewContainer(); 3038233facddcc51865d612a919d450db6954aa48e3Michael Kolb WebView mainView = tab.getWebView(); 3048233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Attach the WebView to the container and then attach the 3058233facddcc51865d612a919d450db6954aa48e3Michael Kolb // container to the content view. 3068233facddcc51865d612a919d450db6954aa48e3Michael Kolb FrameLayout wrapper = 3078233facddcc51865d612a919d450db6954aa48e3Michael Kolb (FrameLayout) container.findViewById(R.id.webview_wrapper); 3088233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup parent = (ViewGroup) mainView.getParent(); 3098233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != wrapper) { 3108233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != null) { 3118233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mMainView already has a parent in" 3128233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 3138233facddcc51865d612a919d450db6954aa48e3Michael Kolb parent.removeView(mainView); 3148233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3158233facddcc51865d612a919d450db6954aa48e3Michael Kolb wrapper.addView(mainView); 3168233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 3178233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mMainView is already attached to wrapper in" 3188233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 3198233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3208233facddcc51865d612a919d450db6954aa48e3Michael Kolb parent = (ViewGroup) container.getParent(); 3218233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != mContentView) { 3228233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (parent != null) { 3238233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mContainer already has a parent in" 3248233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 3258233facddcc51865d612a919d450db6954aa48e3Michael Kolb parent.removeView(container); 3268233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3278233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.addView(container, COVER_SCREEN_PARAMS); 3288233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 3298233facddcc51865d612a919d450db6954aa48e3Michael Kolb Log.w(LOGTAG, "mContainer is already attached to content in" 3308233facddcc51865d612a919d450db6954aa48e3Michael Kolb + " attachTabToContentView!"); 3318233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3328233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.attachSubWindow(tab); 3338233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3348233facddcc51865d612a919d450db6954aa48e3Michael Kolb 3358233facddcc51865d612a919d450db6954aa48e3Michael Kolb private void removeTabFromContentView(Tab tab) { 3367cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb hideTitleBar(); 3378233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Remove the container that contains the main WebView. 3388233facddcc51865d612a919d450db6954aa48e3Michael Kolb WebView mainView = tab.getWebView(); 3398233facddcc51865d612a919d450db6954aa48e3Michael Kolb View container = tab.getViewContainer(); 3408233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mainView == null) { 3418233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 3428233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3438233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Remove the container from the content and then remove the 3448233facddcc51865d612a919d450db6954aa48e3Michael Kolb // WebView from the container. This will trigger a focus change 3458233facddcc51865d612a919d450db6954aa48e3Michael Kolb // needed by WebView. 34620776cc370cf1f092b73c356c02a0df966cfd185Michael Kolb mainView.setEmbeddedTitleBar(null); 3478233facddcc51865d612a919d450db6954aa48e3Michael Kolb FrameLayout wrapper = 3488233facddcc51865d612a919d450db6954aa48e3Michael Kolb (FrameLayout) container.findViewById(R.id.webview_wrapper); 3498233facddcc51865d612a919d450db6954aa48e3Michael Kolb wrapper.removeView(mainView); 3508233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.removeView(container); 3518233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.endActionMode(); 3528233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.removeSubWindow(tab); 3538233facddcc51865d612a919d450db6954aa48e3Michael Kolb ErrorConsoleView errorConsole = tab.getErrorConsole(false); 3548233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (errorConsole != null) { 3558233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.removeView(errorConsole); 3568233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3578233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 3588233facddcc51865d612a919d450db6954aa48e3Michael Kolb 359a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb @Override 360a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb public void onSetWebView(Tab tab, WebView webView) { 361a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb View container = tab.getViewContainer(); 362a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb if (container == null) { 363a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb // The tab consists of a container view, which contains the main 364a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb // WebView, as well as any other UI elements associated with the tab. 365a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb container = mActivity.getLayoutInflater().inflate(R.layout.tab, 3667c6e1c928ea078034e7eacf32ef5c209138001d9John Reck mContentView, false); 367a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb tab.setViewContainer(container); 368a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb } 369a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb if (tab.getWebView() != webView) { 370a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb // Just remove the old one. 371a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb FrameLayout wrapper = 372a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb (FrameLayout) container.findViewById(R.id.webview_wrapper); 373a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb wrapper.removeView(tab.getWebView()); 374a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb } 375a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb } 376a713ec8cc9da6c0c8078cd297c6240eb8bf01bbbMichael Kolb 3778233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 3781514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * create a sub window container and webview for the tab 3791514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * Note: this methods operates through side-effects for now 3801514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * it sets both the subView and subViewContainer for the given tab 3811514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * @param tab tab to create the sub window for 3821514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb * @param subView webview to be set as a subwindow for the tab 3831514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb */ 3841514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb @Override 3851514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb public void createSubWindow(Tab tab, WebView subView) { 3861514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb View subViewContainer = mActivity.getLayoutInflater().inflate( 3871514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb R.layout.browser_subwindow, null); 3881514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb ViewGroup inner = (ViewGroup) subViewContainer 3891514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb .findViewById(R.id.inner_container); 3901514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT, 3911514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb LayoutParams.MATCH_PARENT)); 3921514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb final ImageButton cancel = (ImageButton) subViewContainer 3931514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb .findViewById(R.id.subwindow_close); 3941514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb final WebView cancelSubView = subView; 3951514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb cancel.setOnClickListener(new OnClickListener() { 3961514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb public void onClick(View v) { 3971514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb cancelSubView.getWebChromeClient().onCloseWindow(cancelSubView); 3981514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb } 3991514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb }); 4001514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb tab.setSubWebView(subView); 4011514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb tab.setSubViewContainer(subViewContainer); 4021514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb } 4031514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb 4041514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb /** 4058233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Remove the sub window from the content view. 4068233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 4078233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 4088233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void removeSubWindow(View subviewContainer) { 4098233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.removeView(subviewContainer); 4108233facddcc51865d612a919d450db6954aa48e3Michael Kolb mUiController.endActionMode(); 4118233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4128233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4138233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 4148233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Attach the sub window to the content view. 4158233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 4168233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 4178233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void attachSubWindow(View container) { 4181514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb if (container.getParent() != null) { 4191514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb // already attached, remove first 4201514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb ((ViewGroup) container.getParent()).removeView(container); 4211514bb7ed5656316a8dac966cee21653f3c59affMichael Kolb } 4228233facddcc51865d612a919d450db6954aa48e3Michael Kolb mContentView.addView(container, COVER_SCREEN_PARAMS); 4238233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4248233facddcc51865d612a919d450db6954aa48e3Michael Kolb 42511d1978d8d16004598347abc93918b54a5ef760bMichael Kolb protected void refreshWebView() { 42646f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb WebView web = getWebView(); 42746f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb if (web != null) { 42846f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb web.invalidate(); 42946f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb } 43046f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb } 43146f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb 43246f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb public void editUrl(boolean clearInput) { 43346f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb if (mUiController.isInCustomActionMode()) { 43446f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb mUiController.endActionMode(); 43511d1978d8d16004598347abc93918b54a5ef760bMichael Kolb } 43646f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb showTitleBar(); 437ace2ff88b860c60c634d6cd49177eb4c5413228bMichael Kolb if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) { 438ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mNavigationBar.startEditingUrl(clearInput); 439ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck } 44011d1978d8d16004598347abc93918b54a5ef760bMichael Kolb } 44111d1978d8d16004598347abc93918b54a5ef760bMichael Kolb 4427cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb boolean canShowTitleBar() { 4437cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb return !isTitleBarShowing() 4447cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb && !isActivityPaused() 4457cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb && (getActiveTab() != null) 44646f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb && (getWebView() != null) 4477cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb && !mUiController.isInCustomActionMode(); 4488233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4498233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck protected void showTitleBar() { 451ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mHandler.removeMessages(MSG_HIDE_TITLEBAR); 45246f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb if (canShowTitleBar()) { 4530f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBar.show(); 45446f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb } 4557cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4566670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4577cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb protected void hideTitleBar() { 4580f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mTitleBar.isShowing()) { 4590f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBar.hide(); 46046f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb } 4617cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4626670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4637cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb protected boolean isTitleBarShowing() { 4640f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mTitleBar.isShowing(); 4657cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4666670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4675d43ce897758b7cb5deadc1203717b965334784cJohn Reck public boolean isEditingUrl() { 4680f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mTitleBar.isEditingUrl(); 4695d43ce897758b7cb5deadc1203717b965334784cJohn Reck } 4705d43ce897758b7cb5deadc1203717b965334784cJohn Reck 4710f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public TitleBar getTitleBar() { 4720f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mTitleBar; 4730f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 4746670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4757cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb protected void setTitleGravity(int gravity) { 47646f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb WebView web = getWebView(); 47746f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb if (web != null) { 47846f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb web.setTitleBarGravity(gravity); 4797cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4807cdc4906fc5852297a9a254c3251ad2f4dead6eeMichael Kolb } 4816670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 4826670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb @Override 48311d1978d8d16004598347abc93918b54a5ef760bMichael Kolb public void showVoiceTitleBar(String title, List<String> results) { 4840f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setInVoiceMode(true, results); 4850f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setDisplayTitle(title); 4868233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4878233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4886670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb @Override 4896670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public void revertVoiceTitleBar(Tab tab) { 4900f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setInVoiceMode(false, null); 49130c714c853a4239e72ab1e238ce2a92472d06ab0John Reck String url = tab.getUrl(); 4920f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setDisplayTitle(url); 4938233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 4948233facddcc51865d612a919d450db6954aa48e3Michael Kolb 4958233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 49611d1978d8d16004598347abc93918b54a5ef760bMichael Kolb public void registerDropdownChangeListener(DropdownChangeListener d) { 4970f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.registerDropdownChangeListener(d); 49811d1978d8d16004598347abc93918b54a5ef760bMichael Kolb } 49911d1978d8d16004598347abc93918b54a5ef760bMichael Kolb 50011d1978d8d16004598347abc93918b54a5ef760bMichael Kolb @Override 5012bc8042224be51966d748b870768ec1b376a1621John Reck public void showComboView(ComboViews startingView, Bundle extras) { 502d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck Intent intent = new Intent(mActivity, ComboViewActivity.class); 503d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name()); 504d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras); 505d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck Tab t = getActiveTab(); 506d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck if (t != null) { 507d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl()); 5083a696280cba53eea153c9d5707b236997d193328Michael Kolb } 509d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck mActivity.startActivityForResult(intent, Controller.COMBO_VIEW); 5108233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5118233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5128233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 5132d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger public void showCustomView(View view, int requestedOrientation, 5148233facddcc51865d612a919d450db6954aa48e3Michael Kolb WebChromeClient.CustomViewCallback callback) { 5158233facddcc51865d612a919d450db6954aa48e3Michael Kolb // if a view already exists then immediately terminate the new one 5168233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mCustomView != null) { 5178233facddcc51865d612a919d450db6954aa48e3Michael Kolb callback.onCustomViewHidden(); 5188233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 5198233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5208233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5212d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger mOriginalOrientation = mActivity.getRequestedOrientation(); 52231065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); 52331065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb mFullscreenContainer = new FullscreenHolder(mActivity); 52431065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS); 52531065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS); 52631065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb mCustomView = view; 527c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb setFullscreen(true); 5288233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewCallback = callback; 5292d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger mActivity.setRequestedOrientation(requestedOrientation); 5308233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5318233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5328233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 5338233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onHideCustomView() { 5348233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mCustomView == null) 5358233facddcc51865d612a919d450db6954aa48e3Michael Kolb return; 536c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb setFullscreen(false); 53731065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); 53831065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb decor.removeView(mFullscreenContainer); 53931065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb mFullscreenContainer = null; 5408233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomView = null; 5418233facddcc51865d612a919d450db6954aa48e3Michael Kolb mCustomViewCallback.onCustomViewHidden(); 5428233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Show the content view. 5432d4f1e2553dee6bce5a12162ff6d4459babe2512Derek Sollenberger mActivity.setRequestedOrientation(mOriginalOrientation); 5448233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5458233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5468233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 5478233facddcc51865d612a919d450db6954aa48e3Michael Kolb public boolean isCustomViewShowing() { 5488233facddcc51865d612a919d450db6954aa48e3Michael Kolb return mCustomView != null; 5498233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5508233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5516670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected void dismissIME() { 5523a696280cba53eea153c9d5707b236997d193328Michael Kolb if (mInputManager.isActive()) { 5533a696280cba53eea153c9d5707b236997d193328Michael Kolb mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(), 5543a696280cba53eea153c9d5707b236997d193328Michael Kolb 0); 5553a696280cba53eea153c9d5707b236997d193328Michael Kolb } 5563a696280cba53eea153c9d5707b236997d193328Michael Kolb } 5573a696280cba53eea153c9d5707b236997d193328Michael Kolb 5586670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb @Override 5593ba455394dd3413b6246f00d2bf2083547862735John Reck public boolean isWebShowing() { 560d3e4d5b4ffdf374b836ec9d4d3e315040c8c3779John Reck return mCustomView == null; 5616670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 5626670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 5639206677e461328f15854c5fcb1366d0e261534c6Patrick Scott @Override 5649206677e461328f15854c5fcb1366d0e261534c6Patrick Scott public void showAutoLogin(Tab tab) { 5659206677e461328f15854c5fcb1366d0e261534c6Patrick Scott updateAutoLogin(tab, true); 5669206677e461328f15854c5fcb1366d0e261534c6Patrick Scott } 5679206677e461328f15854c5fcb1366d0e261534c6Patrick Scott 5689206677e461328f15854c5fcb1366d0e261534c6Patrick Scott @Override 5699206677e461328f15854c5fcb1366d0e261534c6Patrick Scott public void hideAutoLogin(Tab tab) { 5709206677e461328f15854c5fcb1366d0e261534c6Patrick Scott updateAutoLogin(tab, true); 5719206677e461328f15854c5fcb1366d0e261534c6Patrick Scott } 5729206677e461328f15854c5fcb1366d0e261534c6Patrick Scott 5738233facddcc51865d612a919d450db6954aa48e3Michael Kolb // ------------------------------------------------------------------------- 5748233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5755a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb protected void updateNavigationState(Tab tab) { 5765a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb } 5775a72f1858c2f73be3558c6cdaa2c84b4c36fa748Michael Kolb 57811d1978d8d16004598347abc93918b54a5ef760bMichael Kolb protected void updateAutoLogin(Tab tab, boolean animate) { 5790f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBar.updateAutoLogin(tab, animate); 58011d1978d8d16004598347abc93918b54a5ef760bMichael Kolb } 5819206677e461328f15854c5fcb1366d0e261534c6Patrick Scott 5828233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 5838233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Update the lock icon to correspond to our latest state. 5848233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 5856670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb protected void updateLockIconToLatest(Tab t) { 58630c714c853a4239e72ab1e238ce2a92472d06ab0John Reck if (t != null && t.inForeground()) { 5872466effd6ef97aa17396c214d51f9f19a4760260Steve Block updateLockIconImage(t.getSecurityState()); 5888233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5898233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 5908233facddcc51865d612a919d450db6954aa48e3Michael Kolb 5918233facddcc51865d612a919d450db6954aa48e3Michael Kolb /** 5928233facddcc51865d612a919d450db6954aa48e3Michael Kolb * Updates the lock-icon image in the title-bar. 5938233facddcc51865d612a919d450db6954aa48e3Michael Kolb */ 5942466effd6ef97aa17396c214d51f9f19a4760260Steve Block private void updateLockIconImage(SecurityState securityState) { 5958233facddcc51865d612a919d450db6954aa48e3Michael Kolb Drawable d = null; 5962466effd6ef97aa17396c214d51f9f19a4760260Steve Block if (securityState == SecurityState.SECURITY_STATE_SECURE) { 5972466effd6ef97aa17396c214d51f9f19a4760260Steve Block d = mLockIconSecure; 5984895b0133c337a8d55bf7e9eac64fcecab4e3e79Steve Block } else if (securityState == SecurityState.SECURITY_STATE_MIXED 5994895b0133c337a8d55bf7e9eac64fcecab4e3e79Steve Block || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) { 6004895b0133c337a8d55bf7e9eac64fcecab4e3e79Steve Block // TODO: It would be good to have different icons for insecure vs mixed content. 6014895b0133c337a8d55bf7e9eac64fcecab4e3e79Steve Block // See http://b/5403800 6022466effd6ef97aa17396c214d51f9f19a4760260Steve Block d = mLockIconMixed; 6038233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6040f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setLock(d); 6058233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6068233facddcc51865d612a919d450db6954aa48e3Michael Kolb 60730c714c853a4239e72ab1e238ce2a92472d06ab0John Reck protected void setUrlTitle(Tab tab) { 60830c714c853a4239e72ab1e238ce2a92472d06ab0John Reck String url = tab.getUrl(); 60930c714c853a4239e72ab1e238ce2a92472d06ab0John Reck String title = tab.getTitle(); 6106670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb if (TextUtils.isEmpty(title)) { 6116670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb title = url; 6126670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 6136670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb if (tab.isInVoiceSearchMode()) return; 6146670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb if (tab.inForeground()) { 6150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setDisplayTitle(url); 6166670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 6178233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6188233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6196670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb // Set the favicon in the title bar. 62030c714c853a4239e72ab1e238ce2a92472d06ab0John Reck protected void setFavicon(Tab tab) { 62130c714c853a4239e72ab1e238ce2a92472d06ab0John Reck if (tab.inForeground()) { 62230c714c853a4239e72ab1e238ce2a92472d06ab0John Reck Bitmap icon = tab.getFavicon(); 6230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavigationBar.setFavicon(icon); 62430c714c853a4239e72ab1e238ce2a92472d06ab0John Reck } 6258233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6268233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6278233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6288233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onActionModeFinished(boolean inLoad) { 6298233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6308233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6316670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb // active tabs page 6326670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 6336670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public void showActiveTabsPage() { 6346670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 6356670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 6366670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb /** 6376670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb * Remove the active tabs page. 6386670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb */ 6396670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb public void removeActiveTabsPage() { 6406670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb } 6416670653d355fea0ae20dc51f6c693f994c4cbb54Michael Kolb 6428233facddcc51865d612a919d450db6954aa48e3Michael Kolb // menu handling callbacks 6438233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6448233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6451acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb public boolean onPrepareOptionsMenu(Menu menu) { 6461acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb return true; 6471acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 6481acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 6491acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb @Override 6507bdee0b303d8969aace4d3e43be5bb9f16e276bfMichael Kolb public void updateMenuState(Tab tab, Menu menu) { 6517bdee0b303d8969aace4d3e43be5bb9f16e276bfMichael Kolb } 6527bdee0b303d8969aace4d3e43be5bb9f16e276bfMichael Kolb 6537bdee0b303d8969aace4d3e43be5bb9f16e276bfMichael Kolb @Override 6548233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onOptionsMenuOpened() { 6558233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6568233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6578233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6588233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onExtendedMenuOpened() { 6598233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6608233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6618233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6623ca12750f9b6231b00a1856dcb25c2d2e07e8784Michael Kolb public boolean onOptionsItemSelected(MenuItem item) { 6633ca12750f9b6231b00a1856dcb25c2d2e07e8784Michael Kolb return false; 6643ca12750f9b6231b00a1856dcb25c2d2e07e8784Michael Kolb } 6653ca12750f9b6231b00a1856dcb25c2d2e07e8784Michael Kolb 6663ca12750f9b6231b00a1856dcb25c2d2e07e8784Michael Kolb @Override 6678233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onOptionsMenuClosed(boolean inLoad) { 6688233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6698233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6708233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6718233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onExtendedMenuClosed(boolean inLoad) { 6728233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6738233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6748233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6758233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onContextMenuCreated(Menu menu) { 6768233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6778233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6788233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6798233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void onContextMenuClosed(Menu menu, boolean inLoad) { 6808233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6818233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6828233facddcc51865d612a919d450db6954aa48e3Michael Kolb // error console 6838233facddcc51865d612a919d450db6954aa48e3Michael Kolb 6848233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 6858233facddcc51865d612a919d450db6954aa48e3Michael Kolb public void setShouldShowErrorConsole(Tab tab, boolean flag) { 6869fcefd19ee20ec9f792ddc84be9a871550e82997Michael Kolb if (tab == null) return; 6878233facddcc51865d612a919d450db6954aa48e3Michael Kolb ErrorConsoleView errorConsole = tab.getErrorConsole(true); 6888233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (flag) { 6898233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Setting the show state of the console will cause it's the layout 6908233facddcc51865d612a919d450db6954aa48e3Michael Kolb // to be inflated. 6918233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (errorConsole.numberOfErrors() > 0) { 6928233facddcc51865d612a919d450db6954aa48e3Michael Kolb errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); 6938233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 6948233facddcc51865d612a919d450db6954aa48e3Michael Kolb errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); 6958233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6968233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (errorConsole.getParent() != null) { 6978233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.removeView(errorConsole); 6988233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 6998233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Now we can add it to the main view. 7008233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.addView(errorConsole, 7018233facddcc51865d612a919d450db6954aa48e3Michael Kolb new LinearLayout.LayoutParams( 7028233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.MATCH_PARENT, 7038233facddcc51865d612a919d450db6954aa48e3Michael Kolb ViewGroup.LayoutParams.WRAP_CONTENT)); 7048233facddcc51865d612a919d450db6954aa48e3Michael Kolb } else { 7058233facddcc51865d612a919d450db6954aa48e3Michael Kolb mErrorConsoleContainer.removeView(errorConsole); 7068233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7078233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7088233facddcc51865d612a919d450db6954aa48e3Michael Kolb 7098233facddcc51865d612a919d450db6954aa48e3Michael Kolb // ------------------------------------------------------------------------- 7108233facddcc51865d612a919d450db6954aa48e3Michael Kolb // Helper function for WebChromeClient 7118233facddcc51865d612a919d450db6954aa48e3Michael Kolb // ------------------------------------------------------------------------- 7128233facddcc51865d612a919d450db6954aa48e3Michael Kolb 7138233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 7148233facddcc51865d612a919d450db6954aa48e3Michael Kolb public Bitmap getDefaultVideoPoster() { 7158233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mDefaultVideoPoster == null) { 7168233facddcc51865d612a919d450db6954aa48e3Michael Kolb mDefaultVideoPoster = BitmapFactory.decodeResource( 7178233facddcc51865d612a919d450db6954aa48e3Michael Kolb mActivity.getResources(), R.drawable.default_video_poster); 7188233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7198233facddcc51865d612a919d450db6954aa48e3Michael Kolb return mDefaultVideoPoster; 7208233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7218233facddcc51865d612a919d450db6954aa48e3Michael Kolb 7228233facddcc51865d612a919d450db6954aa48e3Michael Kolb @Override 7238233facddcc51865d612a919d450db6954aa48e3Michael Kolb public View getVideoLoadingProgressView() { 7248233facddcc51865d612a919d450db6954aa48e3Michael Kolb if (mVideoProgressView == null) { 7258233facddcc51865d612a919d450db6954aa48e3Michael Kolb LayoutInflater inflater = LayoutInflater.from(mActivity); 7268233facddcc51865d612a919d450db6954aa48e3Michael Kolb mVideoProgressView = inflater.inflate( 7278233facddcc51865d612a919d450db6954aa48e3Michael Kolb R.layout.video_loading_progress, null); 7288233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7298233facddcc51865d612a919d450db6954aa48e3Michael Kolb return mVideoProgressView; 7308233facddcc51865d612a919d450db6954aa48e3Michael Kolb } 7318233facddcc51865d612a919d450db6954aa48e3Michael Kolb 732843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb @Override 733843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb public void showMaxTabsWarning() { 734843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb Toast warning = Toast.makeText(mActivity, 735843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb mActivity.getString(R.string.max_tabs_warning), 736843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb Toast.LENGTH_SHORT); 737843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb warning.show(); 738843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb } 739843510fb4f36a9a834c69d8773156db20ca3d740Michael Kolb 74046f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb protected WebView getWebView() { 74146f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb if (mActiveTab != null) { 74246f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb return mActiveTab.getWebView(); 74346f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb } else { 74446f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb return null; 74546f987eca738a36e2c8382aaec6c7ef2ae2482aeMichael Kolb } 746fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb } 747fdb7024334dffd63273eb9c424260b5fe633b94dMichael Kolb 748fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb protected Menu getMenu() { 749fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb MenuBuilder menu = new MenuBuilder(mActivity); 750fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb mActivity.getMenuInflater().inflate(R.menu.browser, menu); 751fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb return menu; 752fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb } 753fedb492d1ac1068e17028b6d4083d1a6b0578287Michael Kolb 754c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb public void setFullscreen(boolean enabled) { 755c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb Window win = mActivity.getWindow(); 756c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb WindowManager.LayoutParams winParams = win.getAttributes(); 757c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; 758c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb if (enabled) { 759c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb winParams.flags |= bits; 760c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb if (mCustomView != null) { 761c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); 762c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb } else { 763c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); 764c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb } 765c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb } else { 766c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb winParams.flags &= ~bits; 767c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb if (mCustomView != null) { 768c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); 769c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb } else { 770c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); 771c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb } 772c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb } 773c5675ad4baf34547770a98c7c0d8dec7f8fb4999Michael Kolb win.setAttributes(winParams); 774c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb } 775c38c604eca3bd0620cd9284187aace78455e723dMichael Kolb 7760f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public Drawable getFaviconDrawable(Bitmap icon) { 7775a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb Drawable[] array = new Drawable[3]; 7785a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb array[0] = new PaintDrawable(Color.BLACK); 7795a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb PaintDrawable p = new PaintDrawable(Color.WHITE); 7805a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb array[1] = p; 7815a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb if (icon == null) { 7825a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb array[2] = mGenericFavicon; 7835a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb } else { 7845a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb array[2] = new BitmapDrawable(icon); 7855a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb } 7865a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb LayerDrawable d = new LayerDrawable(array); 7875a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb d.setLayerInset(1, 1, 1, 1, 1); 7885a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb d.setLayerInset(2, 2, 2, 2, 2); 7895a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb return d; 7905a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb } 7915a4372f4638f9a1fc5c052d85977fbcc0c4d8c55Michael Kolb 7925d43ce897758b7cb5deadc1203717b965334784cJohn Reck public boolean isLoading() { 7935d43ce897758b7cb5deadc1203717b965334784cJohn Reck return mActiveTab != null ? mActiveTab.inPageLoad() : false; 7945d43ce897758b7cb5deadc1203717b965334784cJohn Reck } 7955d43ce897758b7cb5deadc1203717b965334784cJohn Reck 7965d43ce897758b7cb5deadc1203717b965334784cJohn Reck /** 7975d43ce897758b7cb5deadc1203717b965334784cJohn Reck * Suggest to the UI that the title bar can be hidden. The UI will then 7985d43ce897758b7cb5deadc1203717b965334784cJohn Reck * decide whether or not to hide based off a number of factors, such 7995d43ce897758b7cb5deadc1203717b965334784cJohn Reck * as if the user is editing the URL bar or if the page is loading 8005d43ce897758b7cb5deadc1203717b965334784cJohn Reck */ 8015d43ce897758b7cb5deadc1203717b965334784cJohn Reck public void suggestHideTitleBar() { 80258891907e3cf77b72f1107ef5d9f4c984cb176edJohn Reck if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible() 80358891907e3cf77b72f1107ef5d9f4c984cb176edJohn Reck && !mNavigationBar.isMenuShowing()) { 8045d43ce897758b7cb5deadc1203717b965334784cJohn Reck hideTitleBar(); 8055d43ce897758b7cb5deadc1203717b965334784cJohn Reck } 8065d43ce897758b7cb5deadc1203717b965334784cJohn Reck } 8075d43ce897758b7cb5deadc1203717b965334784cJohn Reck 808bc6adb4501853dbaba1c3bb592a159ee901b70e7John Reck protected final void showTitleBarForDuration() { 809bc6adb4501853dbaba1c3bb592a159ee901b70e7John Reck showTitleBarForDuration(HIDE_TITLEBAR_DELAY); 810bc6adb4501853dbaba1c3bb592a159ee901b70e7John Reck } 811bc6adb4501853dbaba1c3bb592a159ee901b70e7John Reck 812bc6adb4501853dbaba1c3bb592a159ee901b70e7John Reck protected final void showTitleBarForDuration(long duration) { 8136ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck showTitleBar(); 8146ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR); 815bc6adb4501853dbaba1c3bb592a159ee901b70e7John Reck mHandler.sendMessageDelayed(msg, duration); 8166ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck } 8176ac5bfda1a372219e469d965e94899d3b4895e0fJohn Reck 8189c5004e6d5645cdf32fff3a3f04817a307b84dd6John Reck protected Handler mHandler = new Handler() { 8195d43ce897758b7cb5deadc1203717b965334784cJohn Reck 8205d43ce897758b7cb5deadc1203717b965334784cJohn Reck @Override 8215d43ce897758b7cb5deadc1203717b965334784cJohn Reck public void handleMessage(Message msg) { 8225d43ce897758b7cb5deadc1203717b965334784cJohn Reck if (msg.what == MSG_HIDE_TITLEBAR) { 8235d43ce897758b7cb5deadc1203717b965334784cJohn Reck suggestHideTitleBar(); 8245d43ce897758b7cb5deadc1203717b965334784cJohn Reck } 8259c5004e6d5645cdf32fff3a3f04817a307b84dd6John Reck BaseUi.this.handleMessage(msg); 8265d43ce897758b7cb5deadc1203717b965334784cJohn Reck } 8275d43ce897758b7cb5deadc1203717b965334784cJohn Reck }; 8283ba455394dd3413b6246f00d2bf2083547862735John Reck 8299c5004e6d5645cdf32fff3a3f04817a307b84dd6John Reck protected void handleMessage(Message msg) {} 8309c5004e6d5645cdf32fff3a3f04817a307b84dd6John Reck 8313ba455394dd3413b6246f00d2bf2083547862735John Reck @Override 8323ba455394dd3413b6246f00d2bf2083547862735John Reck public void showWeb(boolean animate) { 8333ba455394dd3413b6246f00d2bf2083547862735John Reck mUiController.hideCustomView(); 8343ba455394dd3413b6246f00d2bf2083547862735John Reck } 8353ba455394dd3413b6246f00d2bf2083547862735John Reck 83631065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb static class FullscreenHolder extends FrameLayout { 83753ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolb 83831065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb public FullscreenHolder(Context ctx) { 83931065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb super(ctx); 84031065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb setBackgroundColor(ctx.getResources().getColor(R.color.black)); 84153ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolb } 84253ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolb 84331065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb @Override 84431065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb public boolean onTouchEvent(MotionEvent evt) { 84531065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb return true; 84653ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolb } 84753ed62c0171fdbaecaccfbbb08cbf22cb08d39a5Michael Kolb 84831065b1940cb70ad131f20e29ad6250f7d09a290Michael Kolb } 8498233facddcc51865d612a919d450db6954aa48e3Michael Kolb} 850