use of android.animation.PropertyValuesHolder in project UltimateAndroid by cymcsg.
the class SlideInAnimationHandler method animateMenuOpening.
@Override
public void animateMenuOpening(Point center) {
super.animateMenuOpening(center);
setAnimating(true);
Animator lastAnimation = null;
for (int i = 0; i < menu.getSubActionItems().size(); i++) {
menu.getSubActionItems().get(i).view.setAlpha(0);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) menu.getSubActionItems().get(i).view.getLayoutParams();
params.setMargins(menu.getSubActionItems().get(i).x, menu.getSubActionItems().get(i).y + DIST_Y, 0, 0);
menu.getSubActionItems().get(i).view.setLayoutParams(params);
// PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x/* - center.x + menu.getSubActionItems().get(i).width / 2*/);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -DIST_Y);
// PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
// PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);
final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new DecelerateInterpolator());
animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));
if (i == 0) {
lastAnimation = animation;
}
animation.setStartDelay(Math.abs(menu.getSubActionItems().size() / 2 - i) * LAG_BETWEEN_ITEMS);
animation.start();
}
if (lastAnimation != null) {
lastAnimation.addListener(new LastAnimationListener());
}
}
use of android.animation.PropertyValuesHolder in project UltimateAndroid by cymcsg.
the class SlideInAnimationHandler method animateMenuClosing.
@Override
public void animateMenuClosing(Point center) {
super.animateMenuOpening(center);
setAnimating(true);
Animator lastAnimation = null;
for (int i = 0; i < menu.getSubActionItems().size(); i++) {
// PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, DIST_Y);
// PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
// PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);
final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
animation.setDuration(DURATION);
animation.setInterpolator(new AccelerateInterpolator());
animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));
if (i == 0) {
lastAnimation = animation;
}
if (i <= menu.getSubActionItems().size() / 2) {
animation.setStartDelay(i * LAG_BETWEEN_ITEMS);
} else {
animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
}
animation.start();
}
if (lastAnimation != null) {
lastAnimation.addListener(new LastAnimationListener());
}
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by DirtyUnicorns.
the class AnimatedVectorDrawable method updateAnimatorProperty.
private static void updateAnimatorProperty(Animator animator, String targetName, VectorDrawable vectorDrawable, boolean ignoreInvalidAnim) {
if (animator instanceof ObjectAnimator) {
// Change the property of the Animator from using reflection based on the property
// name to a Property object that wraps the setter and getter for modifying that
// specific property for a given object. By replacing the reflection with a direct call,
// we can largely reduce the time it takes for a animator to modify a VD property.
PropertyValuesHolder[] holders = ((ObjectAnimator) animator).getValues();
for (int i = 0; i < holders.length; i++) {
PropertyValuesHolder pvh = holders[i];
String propertyName = pvh.getPropertyName();
Object targetNameObj = vectorDrawable.getTargetByName(targetName);
Property property = null;
if (targetNameObj instanceof VectorDrawable.VObject) {
property = ((VectorDrawable.VObject) targetNameObj).getProperty(propertyName);
} else if (targetNameObj instanceof VectorDrawable.VectorDrawableState) {
property = ((VectorDrawable.VectorDrawableState) targetNameObj).getProperty(propertyName);
}
if (property != null) {
if (containsSameValueType(pvh, property)) {
pvh.setProperty(property);
} else if (!ignoreInvalidAnim) {
throw new RuntimeException("Wrong valueType for Property: " + propertyName + ". Expected type: " + property.getType().toString() + ". Actual " + "type defined in resources: " + pvh.getValueType().toString());
}
}
}
} else if (animator instanceof AnimatorSet) {
for (Animator anim : ((AnimatorSet) animator).getChildAnimations()) {
updateAnimatorProperty(anim, targetName, vectorDrawable, ignoreInvalidAnim);
}
}
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by DirtyUnicorns.
the class NotificationStackScrollLayout method startBottomAnimation.
private void startBottomAnimation() {
int previousStartValue = mStartAnimationRect.bottom;
int previousEndValue = mEndAnimationRect.bottom;
int newEndValue = mBackgroundBounds.bottom;
ObjectAnimator previousAnimator = mBottomAnimator;
if (previousAnimator != null && previousEndValue == newEndValue) {
return;
}
if (!mAnimateNextBackgroundBottom) {
// just a local update was performed
if (previousAnimator != null) {
// we need to increase all animation keyframes of the previous animator by the
// relative change to the end value
PropertyValuesHolder[] values = previousAnimator.getValues();
values[0].setIntValues(previousStartValue, newEndValue);
mStartAnimationRect.bottom = previousStartValue;
mEndAnimationRect.bottom = newEndValue;
previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
return;
} else {
// no new animation needed, let's just apply the value
setBackgroundBottom(newEndValue);
return;
}
}
if (previousAnimator != null) {
previousAnimator.cancel();
}
ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom", mCurrentBounds.bottom, newEndValue);
Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN;
animator.setInterpolator(interpolator);
animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
// remove the tag when the animation is finished
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mStartAnimationRect.bottom = -1;
mEndAnimationRect.bottom = -1;
mBottomAnimator = null;
}
});
animator.start();
mStartAnimationRect.bottom = mCurrentBounds.bottom;
mEndAnimationRect.bottom = newEndValue;
mBottomAnimator = animator;
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by DirtyUnicorns.
the class StackView method transformViewForTransition.
/**
* Animate the views between different relative indexes within the {@link AdapterViewAnimator}
*/
void transformViewForTransition(int fromIndex, int toIndex, final View view, boolean animate) {
if (!animate) {
((StackFrame) view).cancelSliderAnimator();
view.setRotationX(0f);
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.setVerticalOffset(0);
lp.setHorizontalOffset(0);
}
if (fromIndex == -1 && toIndex == getNumActiveViews() - 1) {
transformViewAtIndex(toIndex, view, false);
view.setVisibility(VISIBLE);
view.setAlpha(1.0f);
} else if (fromIndex == 0 && toIndex == 1) {
// Slide item in
((StackFrame) view).cancelSliderAnimator();
view.setVisibility(VISIBLE);
int duration = Math.round(mStackSlider.getDurationForNeutralPosition(mYVelocity));
StackSlider animationSlider = new StackSlider(mStackSlider);
animationSlider.setView(view);
if (animate) {
PropertyValuesHolder slideInY = PropertyValuesHolder.ofFloat("YProgress", 0.0f);
PropertyValuesHolder slideInX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
ObjectAnimator slideIn = ObjectAnimator.ofPropertyValuesHolder(animationSlider, slideInX, slideInY);
slideIn.setDuration(duration);
slideIn.setInterpolator(new LinearInterpolator());
((StackFrame) view).setSliderAnimator(slideIn);
slideIn.start();
} else {
animationSlider.setYProgress(0f);
animationSlider.setXProgress(0f);
}
} else if (fromIndex == 1 && toIndex == 0) {
// Slide item out
((StackFrame) view).cancelSliderAnimator();
int duration = Math.round(mStackSlider.getDurationForOffscreenPosition(mYVelocity));
StackSlider animationSlider = new StackSlider(mStackSlider);
animationSlider.setView(view);
if (animate) {
PropertyValuesHolder slideOutY = PropertyValuesHolder.ofFloat("YProgress", 1.0f);
PropertyValuesHolder slideOutX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
ObjectAnimator slideOut = ObjectAnimator.ofPropertyValuesHolder(animationSlider, slideOutX, slideOutY);
slideOut.setDuration(duration);
slideOut.setInterpolator(new LinearInterpolator());
((StackFrame) view).setSliderAnimator(slideOut);
slideOut.start();
} else {
animationSlider.setYProgress(1.0f);
animationSlider.setXProgress(0f);
}
} else if (toIndex == 0) {
// Make sure this view that is "waiting in the wings" is invisible
view.setAlpha(0.0f);
view.setVisibility(INVISIBLE);
} else if ((fromIndex == 0 || fromIndex == 1) && toIndex > 1) {
view.setVisibility(VISIBLE);
view.setAlpha(1.0f);
view.setRotationX(0f);
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.setVerticalOffset(0);
lp.setHorizontalOffset(0);
} else if (fromIndex == -1) {
view.setAlpha(1.0f);
view.setVisibility(VISIBLE);
} else if (toIndex == -1) {
if (animate) {
postDelayed(new Runnable() {
public void run() {
view.setAlpha(0);
}
}, STACK_RELAYOUT_DURATION);
} else {
view.setAlpha(0f);
}
}
// Implement the faked perspective
if (toIndex != -1) {
transformViewAtIndex(toIndex, view, animate);
}
}
Aggregations