diff options
| -rw-r--r-- | api/current.xml | 2 | ||||
| -rw-r--r-- | core/java/android/widget/AdapterViewAnimator.java | 1 | ||||
| -rw-r--r-- | core/java/android/widget/StackView.java | 77 | ||||
| -rw-r--r-- | core/res/res/values/ids.xml | 1 |
4 files changed, 54 insertions, 27 deletions
diff --git a/api/current.xml b/api/current.xml index f417e3d89f59..86c47f589e53 100644 --- a/api/current.xml +++ b/api/current.xml @@ -260231,7 +260231,7 @@ deprecated="not deprecated" visibility="public" > -<parameter name="arg0" type="T"> +<parameter name="t" type="T"> </parameter> </method> </interface> diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java index 1b3937100456..c27082f928f9 100644 --- a/core/java/android/widget/AdapterViewAnimator.java +++ b/core/java/android/widget/AdapterViewAnimator.java @@ -787,6 +787,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> // We do the former in case mAdapter is null, and hence setDisplayedChild won't // set mWhichChild mWhichChild = ss.whichChild; + setDisplayedChild(mWhichChild); } diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java index 0476d28fffdf..264af71eb438 100644 --- a/core/java/android/widget/StackView.java +++ b/core/java/android/widget/StackView.java @@ -194,7 +194,21 @@ public class StackView extends AdapterViewAnimator { /** * Animate the views between different relative indexes within the {@link AdapterViewAnimator} */ - void animateViewForTransition(int fromIndex, int toIndex, View view) { + void animateViewForTransition(int fromIndex, int toIndex, final View view) { + ObjectAnimator alphaOa = null; + ObjectAnimator oldAlphaOa = null; + + // If there is currently an alpha animation on this view, we need + // to know about it, and may need to cancel it so as not to interfere with + // a new alpha animation. + Object tag = view.getTag(com.android.internal.R.id.viewAlphaAnimation); + if (tag instanceof WeakReference<?>) { + Object obj = ((WeakReference<?>) tag).get(); + if (obj instanceof ObjectAnimator) { + oldAlphaOa = (ObjectAnimator) obj; + } + } + if (fromIndex == -1 && toIndex == NUM_ACTIVE_VIEWS -1) { // Fade item in if (view.getAlpha() == 1) { @@ -206,9 +220,12 @@ public class StackView extends AdapterViewAnimator { view.setTranslationY(0); view.setVisibility(VISIBLE); - ObjectAnimator fadeIn = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 1.0f); - fadeIn.setDuration(FADE_IN_ANIMATION_DURATION); - fadeIn.start(); + alphaOa = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 1.0f); + alphaOa.setDuration(FADE_IN_ANIMATION_DURATION); + if (oldAlphaOa != null) oldAlphaOa.cancel(); + alphaOa.start(); + view.setTagInternal(com.android.internal.R.id.viewAlphaAnimation, + new WeakReference<ObjectAnimator>(alphaOa)); } else if (fromIndex == 0 && toIndex == 1) { // Slide item in view.setVisibility(VISIBLE); @@ -216,39 +233,45 @@ public class StackView extends AdapterViewAnimator { int duration = Math.round(mStackSlider.getDurationForNeutralPosition(mYVelocity)); StackSlider animationSlider = new StackSlider(mStackSlider); + animationSlider.setView(view); PropertyValuesHolder slideInY = PropertyValuesHolder.ofFloat("YProgress", 0.0f); PropertyValuesHolder slideInX = PropertyValuesHolder.ofFloat("XProgress", 0.0f); - ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, + ObjectAnimator slideIn = ObjectAnimator.ofPropertyValuesHolder(animationSlider, slideInX, slideInY); - pa.setDuration(duration); - pa.setInterpolator(new LinearInterpolator()); - pa.start(); + slideIn.setDuration(duration); + slideIn.setInterpolator(new LinearInterpolator()); + slideIn.start(); } else if (fromIndex == 1 && toIndex == 0) { // Slide item out int duration = Math.round(mStackSlider.getDurationForOffscreenPosition(mYVelocity)); StackSlider animationSlider = new StackSlider(mStackSlider); + animationSlider.setView(view); PropertyValuesHolder slideOutY = PropertyValuesHolder.ofFloat("YProgress", 1.0f); PropertyValuesHolder slideOutX = PropertyValuesHolder.ofFloat("XProgress", 0.0f); - ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, + ObjectAnimator slideOut = ObjectAnimator.ofPropertyValuesHolder(animationSlider, slideOutX, slideOutY); - pa.setDuration(duration); - pa.setInterpolator(new LinearInterpolator()); - pa.start(); - } else if (fromIndex == -1 && toIndex == 0) { + slideOut.setDuration(duration); + slideOut.setInterpolator(new LinearInterpolator()); + slideOut.start(); + } else if (toIndex == 0) { // Make sure this view that is "waiting in the wings" is invisible view.setAlpha(0.0f); view.setVisibility(INVISIBLE); - LayoutParams lp = (LayoutParams) view.getLayoutParams(); - lp.setVerticalOffset(-mSlideAmount); + } else if (fromIndex == 0 && toIndex > 1) { + view.setVisibility(VISIBLE); + view.setAlpha(1.0f); } else if (fromIndex == -1) { view.setAlpha(1.0f); view.setVisibility(VISIBLE); } else if (toIndex == -1) { // Fade item out - ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 0.0f); - fadeOut.setDuration(STACK_RELAYOUT_DURATION); - fadeOut.start(); + alphaOa = ObjectAnimator.ofFloat(view, "alpha", view.getAlpha(), 0.0f); + alphaOa.setDuration(STACK_RELAYOUT_DURATION); + if (oldAlphaOa != null) oldAlphaOa.cancel(); + alphaOa.start(); + view.setTagInternal(com.android.internal.R.id.viewAlphaAnimation, + new WeakReference<ObjectAnimator>(alphaOa)); } // Implement the faked perspective @@ -279,6 +302,16 @@ public class StackView extends AdapterViewAnimator { (getMeasuredWidth() * (1 - PERSPECTIVE_SHIFT_FACTOR_X) / 2.0f); final float transX = perspectiveTranslationX + scaleShiftCorrectionX; + // If this view is currently being animated for a certain position, we need to cancel + // this animation so as not to interfere with the new transformation. + Object tag = view.getTag(com.android.internal.R.id.viewAnimation); + if (tag instanceof WeakReference<?>) { + Object obj = ((WeakReference<?>) tag).get(); + if (obj instanceof ObjectAnimator) { + ((ObjectAnimator) obj).cancel(); + } + } + if (animate) { PropertyValuesHolder translationX = PropertyValuesHolder.ofFloat("translationX", transX); PropertyValuesHolder translationY = PropertyValuesHolder.ofFloat("translationY", transY); @@ -292,14 +325,6 @@ public class StackView extends AdapterViewAnimator { new WeakReference<ObjectAnimator>(oa)); oa.start(); } else { - Object tag = view.getTag(com.android.internal.R.id.viewAnimation); - if (tag instanceof WeakReference<?>) { - Object obj = ((WeakReference<?>) tag).get(); - if (obj instanceof ObjectAnimator) { - ((ObjectAnimator) obj).cancel(); - } - } - view.setTranslationX(transX); view.setTranslationY(transY); view.setScaleX(scale); diff --git a/core/res/res/values/ids.xml b/core/res/res/values/ids.xml index 93ccd4f9b8cd..837e04f536e8 100644 --- a/core/res/res/values/ids.xml +++ b/core/res/res/values/ids.xml @@ -74,4 +74,5 @@ <item type="id" name="rowTypeId" /> <item type="id" name="up" /> <item type="id" name="viewAnimation" /> + <item type="id" name="viewAlphaAnimation" /> </resources> |