TitleBar.java revision ef654f1dd80f55609060005342fc4f2cde62990c
10f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck/* 20f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Copyright (C) 2010 The Android Open Source Project 30f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * 40f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Licensed under the Apache License, Version 2.0 (the "License"); 50f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * you may not use this file except in compliance with the License. 60f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * You may obtain a copy of the License at 70f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * 80f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * http://www.apache.org/licenses/LICENSE-2.0 90f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * 100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Unless required by applicable law or agreed to in writing, software 110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * distributed under the License is distributed on an "AS IS" BASIS, 120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * See the License for the specific language governing permissions and 140f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * limitations under the License. 150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck */ 160f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckpackage com.android.browser; 180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 190f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.animation.Animator; 200f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.animation.Animator.AnimatorListener; 210f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.animation.ObjectAnimator; 220f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.content.Context; 230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.content.res.Resources; 240f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.Gravity; 250f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.LayoutInflater; 260f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.View; 270f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.ViewGroup; 280f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.animation.Animation; 290f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.animation.Animation.AnimationListener; 300f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.animation.AnimationUtils; 310f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.animation.DecelerateInterpolator; 320f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.webkit.WebView; 330f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.widget.AbsoluteLayout; 340f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.widget.FrameLayout; 350f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.widget.RelativeLayout; 360f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 370f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 380f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck/** 390f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Base class for a title bar used by the browser. 400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck */ 410f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckpublic class TitleBar extends RelativeLayout { 420f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 430f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private static final int PROGRESS_MAX = 100; 440f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private static final float ANIM_TITLEBAR_DECELERATE = 2.5f; 450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private UiController mUiController; 470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private BaseUi mBaseUi; 480f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private FrameLayout mParent; 490f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private PageProgressView mProgress; 500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 510f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private AutologinBar mAutoLogin; 520f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private NavigationBarBase mNavBar; 530f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private boolean mUseQuickControls; 54ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck private SnapshotBar mSnapshotBar; 550f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 560f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck //state 570f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private boolean mShowing; 580f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private boolean mInLoad; 590f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private boolean mSkipTitleBarAnimations; 600f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private Animator mTitleBarAnimator; 610f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 620f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public TitleBar(Context context, UiController controller, BaseUi ui, 630f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck FrameLayout parent) { 640f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck super(context, null); 650f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mUiController = controller; 660f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi = ui; 670f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mParent = parent; 680f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck initLayout(context); 690f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 700f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 710f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private void initLayout(Context context) { 720f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck LayoutInflater factory = LayoutInflater.from(context); 730f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck factory.inflate(R.layout.title_bar, this); 740f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mProgress = (PageProgressView) findViewById(R.id.progress); 750f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin = (AutologinBar) findViewById(R.id.autologin); 760f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.setTitleBar(this); 770f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavBar = (NavigationBarBase) findViewById(R.id.taburlbar); 780f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavBar.setTitleBar(this); 79ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mSnapshotBar = (SnapshotBar) findViewById(R.id.snapshotbar); 80ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mSnapshotBar.setTitleBar(this); 810f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 820f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 830f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public BaseUi getUi() { 840f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mBaseUi; 850f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 860f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 870f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public UiController getUiController() { 880f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mUiController; 890f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 900f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 910f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void setUseQuickControls(boolean use) { 920f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mUseQuickControls = use; 930f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck setLayoutParams(makeLayoutParams()); 940f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 950f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 960f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck void setShowProgressOnly(boolean progress) { 97ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck if (progress && !wantsToBeVisible()) { 980f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavBar.setVisibility(View.GONE); 990f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 1000f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavBar.setVisibility(View.VISIBLE); 1010f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1020f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1030f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1040f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck void setSkipTitleBarAnimations(boolean skip) { 1050f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mSkipTitleBarAnimations = skip; 1060f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1070f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1080f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck void setupTitleBarAnimator(Animator animator) { 1090f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck Resources res = mContext.getResources(); 1100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck int duration = res.getInteger(R.integer.titlebar_animation_duration); 1110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck animator.setInterpolator(new DecelerateInterpolator( 1120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck ANIM_TITLEBAR_DECELERATE)); 1130f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck animator.setDuration(duration); 1140f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1160f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck void show() { 1170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mUseQuickControls) { 1180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mParent.addView(this); 1190f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 1200f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (!mSkipTitleBarAnimations) { 1210f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck cancelTitleBarAnimation(false); 1220f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck int visibleHeight = getVisibleTitleHeight(); 1230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck float startPos = (-getEmbeddedHeight() + visibleHeight); 1240f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (getTranslationY() != 0) { 1250f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck startPos = Math.max(startPos, getTranslationY()); 1260f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1270f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBarAnimator = ObjectAnimator.ofFloat(this, 1280f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck "translationY", 1290f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck startPos, 0); 1300f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck setupTitleBarAnimator(mTitleBarAnimator); 1310f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBarAnimator.start(); 1320f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1330f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.setTitleGravity(Gravity.TOP); 1340f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1350f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mShowing = true; 1360f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1370f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1380f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck void hide() { 1390f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mUseQuickControls) { 1400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mParent.removeView(this); 1410f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 1420f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (!mSkipTitleBarAnimations) { 1430f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck cancelTitleBarAnimation(false); 1440f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck int visibleHeight = getVisibleTitleHeight(); 1450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBarAnimator = ObjectAnimator.ofFloat(this, 1460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck "translationY", getTranslationY(), 1470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck (-getEmbeddedHeight() + visibleHeight)); 1480f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBarAnimator.addListener(mHideTileBarAnimatorListener); 1490f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck setupTitleBarAnimator(mTitleBarAnimator); 1500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBarAnimator.start(); 1510f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 1520f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.setTitleGravity(Gravity.NO_GRAVITY); 1530f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1540f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1550f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mShowing = false; 1560f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1570f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1580f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck boolean isShowing() { 1590f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mShowing; 1600f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1610f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1620f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck void cancelTitleBarAnimation(boolean reset) { 1630f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mTitleBarAnimator != null) { 1640f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBarAnimator.cancel(); 1650f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mTitleBarAnimator = null; 1660f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1670f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (reset) { 1680f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck setTranslationY(0); 1690f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1700f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1710f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1720f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() { 1730f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1740f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck boolean mWasCanceled; 1750f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 1760f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void onAnimationStart(Animator animation) { 1770f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mWasCanceled = false; 1780f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1790f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1800f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 1810f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void onAnimationRepeat(Animator animation) { 1820f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1830f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1840f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 1850f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void onAnimationEnd(Animator animation) { 1860f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (!mWasCanceled) { 1870f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck setTranslationY(0); 1880f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1890f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.setTitleGravity(Gravity.NO_GRAVITY); 1900f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1910f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1920f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 1930f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void onAnimationCancel(Animator animation) { 1940f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mWasCanceled = true; 1950f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 1960f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck }; 1970f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 1980f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private int getVisibleTitleHeight() { 1990f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck Tab tab = mBaseUi.getActiveTab(); 2000f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck WebView webview = tab != null ? tab.getWebView() : null; 2010f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return webview != null ? webview.getVisibleTitleHeight() : 0; 2020f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2030f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 2040f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck /** 2050f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Update the progress, from 0 to 100. 2060f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck */ 2070f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void setProgress(int newProgress) { 2080f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (newProgress >= PROGRESS_MAX) { 2090f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mProgress.setProgress(PageProgressView.MAX_PROGRESS); 2100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mProgress.setVisibility(View.GONE); 2110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mInLoad = false; 2120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavBar.onProgressStopped(); 2130f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck // check if needs to be hidden 214ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck if (!isEditingUrl() && !wantsToBeVisible()) { 2150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck hide(); 2160f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mUseQuickControls) { 2170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck setShowProgressOnly(false); 2180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2190f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2200f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 2210f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (!mInLoad) { 2220f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mProgress.setVisibility(View.VISIBLE); 2230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mInLoad = true; 2240f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mNavBar.onProgressStarted(); 2250f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2260f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS 2270f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck / PROGRESS_MAX); 2280f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (!mShowing) { 2290f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mUseQuickControls && !isEditingUrl()) { 2300f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck setShowProgressOnly(true); 2310f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2320f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck show(); 2330f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2340f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2350f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2360f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 2370f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public int getEmbeddedHeight() { 2380f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck int height = mNavBar.getHeight(); 2390f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mAutoLogin.getVisibility() == View.VISIBLE) { 2400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck height += mAutoLogin.getHeight(); 2410f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2420f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return height; 2430f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2440f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 2450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void updateAutoLogin(Tab tab, boolean animate) { 2460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.updateAutoLogin(tab, animate); 2470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2480f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 2490f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void showAutoLogin(boolean animate) { 2500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mUseQuickControls) { 2510f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.showTitleBar(); 2520f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2530f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.setVisibility(View.VISIBLE); 2540f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (animate) { 2550f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.startAnimation(AnimationUtils.loadAnimation( 2560f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck getContext(), R.anim.autologin_enter)); 2570f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2580f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2590f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 2600f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void hideAutoLogin(boolean animate) { 2610f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mUseQuickControls) { 2620f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.hideTitleBar(); 2630f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.setVisibility(View.GONE); 2640f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.refreshWebView(); 2650f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 2660f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (animate) { 2670f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck Animation anim = AnimationUtils.loadAnimation(getContext(), 2680f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck R.anim.autologin_exit); 2690f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck anim.setAnimationListener(new AnimationListener() { 2700f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 2710f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void onAnimationEnd(Animation a) { 2720f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.setVisibility(View.GONE); 2730f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.refreshWebView(); 2740f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2750f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 2760f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 2770f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void onAnimationStart(Animation a) { 2780f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2790f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 2800f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 2810f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public void onAnimationRepeat(Animation a) { 2820f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2830f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck }); 2840f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.startAnimation(anim); 2850f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else if (mAutoLogin.getAnimation() == null) { 2860f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mAutoLogin.setVisibility(View.GONE); 2870f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck mBaseUi.refreshWebView(); 2880f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2890f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2900f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 2910f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 292ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck public boolean wantsToBeVisible() { 293ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck return inAutoLogin() 294ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck || (mSnapshotBar.getVisibility() == View.VISIBLE 295ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck && mSnapshotBar.isAnimating()); 296ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck } 297ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck 298ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck private boolean inAutoLogin() { 2990f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mAutoLogin.getVisibility() == View.VISIBLE; 3000f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3010f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3020f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public boolean isEditingUrl() { 3030f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mNavBar.isEditingUrl(); 3040f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3050f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3060f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public WebView getCurrentWebView() { 3070f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck Tab t = mBaseUi.getActiveTab(); 3080f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (t != null) { 3090f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return t.getWebView(); 3100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 3110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return null; 3120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3130f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3140f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public PageProgressView getProgressView() { 3160f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mProgress; 3170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3190f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public NavigationBarBase getNavigationBar() { 3200f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mNavBar; 3210f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3220f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public boolean useQuickControls() { 3240f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mUseQuickControls; 3250f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3260f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3270f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public boolean isInLoad() { 3280f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return mInLoad; 3290f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3300f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3310f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck private ViewGroup.LayoutParams makeLayoutParams() { 3320f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (mUseQuickControls) { 3330f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 3340f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck LayoutParams.WRAP_CONTENT); 3350f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } else { 3360f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return new AbsoluteLayout.LayoutParams( 3370f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 3380f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 0, 0); 3390f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3410f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 3420f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck @Override 3430f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck public View focusSearch(View focused, int dir) { 3440f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck if (FOCUS_DOWN == dir && hasFocus()) { 3450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return getCurrentWebView(); 3460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck return super.focusSearch(focused, dir); 3480f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck } 3490f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck 350ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck public void onTabDataChanged(Tab tab) { 351ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mSnapshotBar.onTabDataChanged(tab); 352ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck if (tab.isSnapshot()) { 353ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mSnapshotBar.setVisibility(VISIBLE); 354ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mNavBar.setVisibility(GONE); 355ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck } else { 356ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mSnapshotBar.setVisibility(GONE); 357ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck mNavBar.setVisibility(VISIBLE); 358ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck } 359ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck } 360ef654f1dd80f55609060005342fc4f2cde62990cJohn Reck 3610f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck} 362