summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Powell <adamp@google.com> 2011-02-08 16:20:15 -0800
committer Adam Powell <adamp@google.com> 2011-02-08 16:24:15 -0800
commit50efbed668a9410cdec51f7c8604fa44ed267fed (patch)
tree080d33737acdb9ec4e980a503b290369eb769e46
parent2157f045d3579cb789d7c2c4f892724c7b0b1b39 (diff)
Fix bug 3345948 - ActionBar.show()/hide() shouldn't animate if called
before first layout Enable/disable the action bar show/hide animation as part of the activity/dialog lifecycle. This allows apps to set action bar visibility state as the activity first becomes visible or returns to visibility without the associated animation. Change-Id: I85ff9268d2cb2c8fcd3364dd275597fe90529224
-rw-r--r--core/java/android/app/Activity.java2
-rw-r--r--core/java/android/app/Dialog.java2
-rw-r--r--core/java/com/android/internal/app/ActionBarImpl.java72
3 files changed, 53 insertions, 23 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 04d839db2c07..aed0fa384704 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -1067,6 +1067,7 @@ public class Activity extends ContextThemeWrapper
protected void onPostResume() {
final Window win = getWindow();
if (win != null) win.makeActive();
+ if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true);
mCalled = true;
}
@@ -1319,6 +1320,7 @@ public class Activity extends ContextThemeWrapper
* @see #onDestroy
*/
protected void onStop() {
+ if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false);
mCalled = true;
}
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index de5d6a1bdf18..cc4fefc3ea3b 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -352,12 +352,14 @@ public class Dialog implements DialogInterface, Window.Callback,
* Called when the dialog is starting.
*/
protected void onStart() {
+ if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true);
}
/**
* Called to tell you that you're stopping.
*/
protected void onStop() {
+ if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false);
}
private static final String DIALOG_SHOWING_TAG = "android:dialogShowing";
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 471a5a91f7b1..ab53adb8ae43 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -92,6 +92,7 @@ public class ActionBarImpl extends ActionBar {
final Handler mHandler = new Handler();
private Animator mCurrentAnim;
+ private boolean mShowHideAnimationEnabled;
private static final TimeInterpolator sFadeOutInterpolator = new DecelerateInterpolator();
@@ -217,6 +218,20 @@ public class ActionBarImpl extends ActionBar {
CONTEXT_DISPLAY_NORMAL : CONTEXT_DISPLAY_SPLIT;
}
+ /**
+ * Enables or disables animation between show/hide states.
+ * If animation is disabled using this method, animations in progress
+ * will be finished.
+ *
+ * @param enabled true to animate, false to not animate.
+ */
+ public void setShowHideAnimationEnabled(boolean enabled) {
+ mShowHideAnimationEnabled = enabled;
+ if (!enabled && mCurrentAnim != null) {
+ mCurrentAnim.end();
+ }
+ }
+
public void addOnMenuVisibilityListener(OnMenuVisibilityListener listener) {
mMenuVisibilityListeners.add(listener);
}
@@ -361,6 +376,7 @@ public class ActionBarImpl extends ActionBar {
mLowerContextView.setVisibility(View.VISIBLE);
}
mActionMode = mode;
+ show();
return mode;
}
return null;
@@ -487,18 +503,23 @@ public class ActionBarImpl extends ActionBar {
return;
}
mContainerView.setVisibility(View.VISIBLE);
- mContainerView.setAlpha(0);
- AnimatorSet anim = new AnimatorSet();
- AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 1));
- if (mContentView != null) {
- b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
- -mContainerView.getHeight(), 0));
- mContainerView.setTranslationY(-mContainerView.getHeight());
- b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
+
+ if (mShowHideAnimationEnabled) {
+ mContainerView.setAlpha(0);
+ AnimatorSet anim = new AnimatorSet();
+ AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 1));
+ if (mContentView != null) {
+ b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
+ -mContainerView.getHeight(), 0));
+ mContainerView.setTranslationY(-mContainerView.getHeight());
+ b.with(ObjectAnimator.ofFloat(mContainerView, "translationY", 0));
+ }
+ anim.addListener(mShowListener);
+ mCurrentAnim = anim;
+ anim.start();
+ } else {
+ mShowListener.onAnimationEnd(null);
}
- anim.addListener(mShowListener);
- mCurrentAnim = anim;
- anim.start();
}
@Override
@@ -509,18 +530,23 @@ public class ActionBarImpl extends ActionBar {
if (mContainerView.getVisibility() == View.GONE) {
return;
}
- mContainerView.setAlpha(1);
- AnimatorSet anim = new AnimatorSet();
- AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 0));
- if (mContentView != null) {
- b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
- 0, -mContainerView.getHeight()));
- b.with(ObjectAnimator.ofFloat(mContainerView, "translationY",
- -mContainerView.getHeight()));
- }
- anim.addListener(mHideListener);
- mCurrentAnim = anim;
- anim.start();
+
+ if (mShowHideAnimationEnabled) {
+ mContainerView.setAlpha(1);
+ AnimatorSet anim = new AnimatorSet();
+ AnimatorSet.Builder b = anim.play(ObjectAnimator.ofFloat(mContainerView, "alpha", 0));
+ if (mContentView != null) {
+ b.with(ObjectAnimator.ofFloat(mContentView, "translationY",
+ 0, -mContainerView.getHeight()));
+ b.with(ObjectAnimator.ofFloat(mContainerView, "translationY",
+ -mContainerView.getHeight()));
+ }
+ anim.addListener(mHideListener);
+ mCurrentAnim = anim;
+ anim.start();
+ } else {
+ mHideListener.onAnimationEnd(null);
+ }
}
public boolean isShowing() {