summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2012-04-18 16:20:08 -0700
committerChet Haase <chet@google.com>2012-04-19 11:01:27 -0700
commit563d4f2d461d264457b7e7068e2fc7b9b0bcafb3 (patch)
treee592afd70f4cfc2169282a6558621f7a33eb457d /core/java
parentf37d87b35b9bc860487104b1870f74caa3ae2e71 (diff)
downloadframeworks_base-563d4f2d461d264457b7e7068e2fc7b9b0bcafb3.zip
frameworks_base-563d4f2d461d264457b7e7068e2fc7b9b0bcafb3.tar.gz
frameworks_base-563d4f2d461d264457b7e7068e2fc7b9b0bcafb3.tar.bz2
Make ViewPropertyAnimator ListView-animation-capable
ViewPropertyAnimator now sets the hasTransientState flag in View to tell it when an animation has started (and unsets it when the animation ends). This allows ListView to retain views with transient state without recycling them, which makes ListView item animation possible (because you can't animate a View if it's being recycled and reused elsewhere as it moves into and out of view). Change-Id: I75c26a7a56474a76428500afef03a80bb46e04e0
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/View.java39
-rw-r--r--core/java/android/view/ViewPropertyAnimator.java2
2 files changed, 30 insertions, 11 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 7e5fe63..537c474 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -2472,6 +2472,12 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
int mSystemUiVisibility;
/**
+ * Reference count for transient state.
+ * @see #setHasTransientState(boolean)
+ */
+ int mTransientStateCount = 0;
+
+ /**
* Count of how many windows this view has been attached to.
*/
int mWindowAttachCount;
@@ -5400,21 +5406,32 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
/**
* Set whether this view is currently tracking transient state that the
- * framework should attempt to preserve when possible.
+ * framework should attempt to preserve when possible. This flag is reference counted,
+ * so every call to setHasTransientState(true) should be paired with a later call
+ * to setHasTransientState(false).
*
* @param hasTransientState true if this view has transient state
*/
public void setHasTransientState(boolean hasTransientState) {
- if (hasTransientState() == hasTransientState) return;
-
- mPrivateFlags2 = (mPrivateFlags2 & ~HAS_TRANSIENT_STATE) |
- (hasTransientState ? HAS_TRANSIENT_STATE : 0);
- if (mParent != null) {
- try {
- mParent.childHasTransientStateChanged(this, hasTransientState);
- } catch (AbstractMethodError e) {
- Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() +
- " does not fully implement ViewParent", e);
+ mTransientStateCount = hasTransientState ? mTransientStateCount + 1 :
+ mTransientStateCount - 1;
+ if (mTransientStateCount < 0) {
+ mTransientStateCount = 0;
+ Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " +
+ "unmatched pair of setHasTransientState calls");
+ }
+ if ((hasTransientState && mTransientStateCount == 1) ||
+ (hasTransientState && mTransientStateCount == 0)) {
+ // update flag if we've just incremented up from 0 or decremented down to 0
+ mPrivateFlags2 = (mPrivateFlags2 & ~HAS_TRANSIENT_STATE) |
+ (hasTransientState ? HAS_TRANSIENT_STATE : 0);
+ if (mParent != null) {
+ try {
+ mParent.childHasTransientStateChanged(this, hasTransientState);
+ } catch (AbstractMethodError e) {
+ Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() +
+ " does not fully implement ViewParent", e);
+ }
}
}
}
diff --git a/core/java/android/view/ViewPropertyAnimator.java b/core/java/android/view/ViewPropertyAnimator.java
index 3626aba..e573056 100644
--- a/core/java/android/view/ViewPropertyAnimator.java
+++ b/core/java/android/view/ViewPropertyAnimator.java
@@ -714,6 +714,7 @@ public class ViewPropertyAnimator {
* value accordingly.
*/
private void startAnimation() {
+ mView.setHasTransientState(true);
ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
ArrayList<NameValuesHolder> nameValueList =
(ArrayList<NameValuesHolder>) mPendingAnimations.clone();
@@ -960,6 +961,7 @@ public class ViewPropertyAnimator {
@Override
public void onAnimationEnd(Animator animation) {
+ mView.setHasTransientState(false);
if (mListener != null) {
mListener.onAnimationEnd(animation);
}