Animate url bar hide/show
Bug: 3443911
Change-Id: I3121371a784d17183a62dd8f9323de900b792b21
diff --git a/res/values/integers.xml b/res/values/integers.xml
index ad0ed90..e936ed8 100644
--- a/res/values/integers.xml
+++ b/res/values/integers.xml
@@ -24,7 +24,6 @@
<!-- The maximum number of most visited URLs in the history tab -->
<integer name="most_visits_limit">10</integer>
<!-- Animation durations -->
- <integer name="comboViewFadeInDuration">400</integer>
<!-- fade between tabs duration -->
<integer name="tabFadeDuration">300</integer>
</resources>
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 5084e31..e89012f 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -17,11 +17,8 @@
package com.android.browser;
import com.android.browser.Tab.LockIcon;
-import com.android.browser.UI.DropdownChangeListener;
-import android.animation.Animator;
-import android.animation.Animator.AnimatorListener;
-import android.animation.ObjectAnimator;
+import android.animation.LayoutTransition;
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -114,6 +111,7 @@
.inflate(R.layout.custom_screen, null);
mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
R.id.main_content);
+ mContentView.setLayoutTransition(new LayoutTransition());
mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
.findViewById(R.id.error_console);
mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
@@ -460,11 +458,6 @@
WebView web = mActiveTab.getWebView();
mActiveTab.putInBackground();
}
- mComboView.setAlpha(0f);
- ObjectAnimator anim = ObjectAnimator.ofFloat(mComboView, "alpha", 0f, 1f);
- Resources res = mActivity.getResources();
- anim.setDuration(res.getInteger(R.integer.comboViewFadeInDuration));
- anim.start();
mContentView.addView(mComboView, COVER_SCREEN_PARAMS);
}
diff --git a/src/com/android/browser/XLargeUi.java b/src/com/android/browser/XLargeUi.java
index a9a55e8..9023f17 100644
--- a/src/com/android/browser/XLargeUi.java
+++ b/src/com/android/browser/XLargeUi.java
@@ -18,6 +18,9 @@
import com.android.browser.ScrollWebView.ScrollListener;
+import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.ObjectAnimator;
import android.app.ActionBar;
import android.app.Activity;
import android.content.pm.PackageManager;
@@ -47,6 +50,7 @@
private TabBar mTabBar;
private TitleBarXLarge mTitleBar;
+ private Animator mTitleBarAnimator;
private boolean mUseQuickControls;
private PieControl mPieControl;
@@ -317,6 +321,18 @@
if (mUseQuickControls) {
mContentView.addView(mTitleBar);
} else {
+ if (mTitleBarAnimator != null) {
+ mTitleBarAnimator.cancel();
+ }
+ int visibleHeight = getVisibleTitleHeight();
+ float startPos = (-mTitleBar.getEmbeddedHeight() + visibleHeight);
+ if (mTitleBar.getTranslationY() != 0) {
+ startPos = Math.max(startPos, mTitleBar.getTranslationY());
+ }
+ mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar,
+ "translationY",
+ startPos, 0);
+ mTitleBarAnimator.start();
setTitleGravity(Gravity.TOP);
}
super.showTitleBar();
@@ -331,12 +347,51 @@
if (mUseQuickControls) {
mContentView.removeView(mTitleBar);
} else {
- setTitleGravity(Gravity.NO_GRAVITY);
+ if (mTitleBarAnimator != null) {
+ mTitleBarAnimator.cancel();
+ }
+ int visibleHeight = getVisibleTitleHeight();
+ mTitleBarAnimator = ObjectAnimator.ofFloat(mTitleBar,
+ "translationY", mTitleBar.getTranslationY(),
+ (-mTitleBar.getEmbeddedHeight() + visibleHeight));
+ mTitleBarAnimator.addListener(mHideTileBarAnimatorListener);
+ mTitleBarAnimator.start();
}
super.hideTitleBar();
}
}
+ private int getVisibleTitleHeight() {
+ WebView webview = mActiveTab != null ? mActiveTab.getWebView() : null;
+ return webview != null ? webview.getVisibleTitleHeight() : 0;
+ }
+
+ private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() {
+
+ boolean mWasCanceled;
+ @Override
+ public void onAnimationStart(Animator animation) {
+ mWasCanceled = false;
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator animation) {
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ if (!mWasCanceled) {
+ mTitleBar.setTranslationY(0);
+ setTitleGravity(Gravity.NO_GRAVITY);
+ }
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mWasCanceled = true;
+ }
+ };
+
public boolean isEditingUrl() {
return mTitleBar.isEditingUrl();
}