use of android.animation.PropertyValuesHolder in project android_frameworks_base by ResurrectionRemix.
the class ChangeTransform method createTransformAnimator.
private ObjectAnimator createTransformAnimator(TransitionValues startValues, TransitionValues endValues, final boolean handleParentChange) {
Matrix startMatrix = (Matrix) startValues.values.get(PROPNAME_MATRIX);
Matrix endMatrix = (Matrix) endValues.values.get(PROPNAME_MATRIX);
if (startMatrix == null) {
startMatrix = Matrix.IDENTITY_MATRIX;
}
if (endMatrix == null) {
endMatrix = Matrix.IDENTITY_MATRIX;
}
if (startMatrix.equals(endMatrix)) {
return null;
}
final Transforms transforms = (Transforms) endValues.values.get(PROPNAME_TRANSFORMS);
// clear the transform properties so that we can use the animation matrix instead
final View view = endValues.view;
setIdentityTransforms(view);
final float[] startMatrixValues = new float[9];
startMatrix.getValues(startMatrixValues);
final float[] endMatrixValues = new float[9];
endMatrix.getValues(endMatrixValues);
final PathAnimatorMatrix pathAnimatorMatrix = new PathAnimatorMatrix(view, startMatrixValues);
PropertyValuesHolder valuesProperty = PropertyValuesHolder.ofObject(NON_TRANSLATIONS_PROPERTY, new FloatArrayEvaluator(new float[9]), startMatrixValues, endMatrixValues);
Path path = getPathMotion().getPath(startMatrixValues[Matrix.MTRANS_X], startMatrixValues[Matrix.MTRANS_Y], endMatrixValues[Matrix.MTRANS_X], endMatrixValues[Matrix.MTRANS_Y]);
PropertyValuesHolder translationProperty = PropertyValuesHolder.ofObject(TRANSLATIONS_PROPERTY, null, path);
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(pathAnimatorMatrix, valuesProperty, translationProperty);
final Matrix finalEndMatrix = endMatrix;
AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {
private boolean mIsCanceled;
private Matrix mTempMatrix = new Matrix();
@Override
public void onAnimationCancel(Animator animation) {
mIsCanceled = true;
}
@Override
public void onAnimationEnd(Animator animation) {
if (!mIsCanceled) {
if (handleParentChange && mUseOverlay) {
setCurrentMatrix(finalEndMatrix);
} else {
view.setTagInternal(R.id.transitionTransform, null);
view.setTagInternal(R.id.parentMatrix, null);
}
}
view.setAnimationMatrix(null);
transforms.restore(view);
}
@Override
public void onAnimationPause(Animator animation) {
Matrix currentMatrix = pathAnimatorMatrix.getMatrix();
setCurrentMatrix(currentMatrix);
}
@Override
public void onAnimationResume(Animator animation) {
setIdentityTransforms(view);
}
private void setCurrentMatrix(Matrix currentMatrix) {
mTempMatrix.set(currentMatrix);
view.setTagInternal(R.id.transitionTransform, mTempMatrix);
transforms.restore(view);
}
};
animator.addListener(listener);
animator.addPauseListener(listener);
return animator;
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class StackView method handlePointerUp.
private void handlePointerUp(MotionEvent ev) {
int pointerIndex = ev.findPointerIndex(mActivePointerId);
float newY = ev.getY(pointerIndex);
int deltaY = (int) (newY - mInitialY);
mLastInteractionTime = System.currentTimeMillis();
if (mVelocityTracker != null) {
mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
mYVelocity = (int) mVelocityTracker.getYVelocity(mActivePointerId);
}
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
if (deltaY > mSwipeThreshold && mSwipeGestureType == GESTURE_SLIDE_DOWN && mStackSlider.mMode == StackSlider.NORMAL_MODE) {
// We reset the gesture variable, because otherwise we will ignore showPrevious() /
// showNext();
mSwipeGestureType = GESTURE_NONE;
// Swipe threshold exceeded, swipe down
if (mStackMode == ITEMS_SLIDE_UP) {
showPrevious();
} else {
showNext();
}
mHighlight.bringToFront();
} else if (deltaY < -mSwipeThreshold && mSwipeGestureType == GESTURE_SLIDE_UP && mStackSlider.mMode == StackSlider.NORMAL_MODE) {
// We reset the gesture variable, because otherwise we will ignore showPrevious() /
// showNext();
mSwipeGestureType = GESTURE_NONE;
// Swipe threshold exceeded, swipe up
if (mStackMode == ITEMS_SLIDE_UP) {
showNext();
} else {
showPrevious();
}
mHighlight.bringToFront();
} else if (mSwipeGestureType == GESTURE_SLIDE_UP) {
// Didn't swipe up far enough, snap back down
int duration;
float finalYProgress = (mStackMode == ITEMS_SLIDE_DOWN) ? 1 : 0;
if (mStackMode == ITEMS_SLIDE_UP || mStackSlider.mMode != StackSlider.NORMAL_MODE) {
duration = Math.round(mStackSlider.getDurationForNeutralPosition());
} else {
duration = Math.round(mStackSlider.getDurationForOffscreenPosition());
}
StackSlider animationSlider = new StackSlider(mStackSlider);
PropertyValuesHolder snapBackY = PropertyValuesHolder.ofFloat("YProgress", finalYProgress);
PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, snapBackX, snapBackY);
pa.setDuration(duration);
pa.setInterpolator(new LinearInterpolator());
pa.start();
} else if (mSwipeGestureType == GESTURE_SLIDE_DOWN) {
// Didn't swipe down far enough, snap back up
float finalYProgress = (mStackMode == ITEMS_SLIDE_DOWN) ? 0 : 1;
int duration;
if (mStackMode == ITEMS_SLIDE_DOWN || mStackSlider.mMode != StackSlider.NORMAL_MODE) {
duration = Math.round(mStackSlider.getDurationForNeutralPosition());
} else {
duration = Math.round(mStackSlider.getDurationForOffscreenPosition());
}
StackSlider animationSlider = new StackSlider(mStackSlider);
PropertyValuesHolder snapBackY = PropertyValuesHolder.ofFloat("YProgress", finalYProgress);
PropertyValuesHolder snapBackX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
ObjectAnimator pa = ObjectAnimator.ofPropertyValuesHolder(animationSlider, snapBackX, snapBackY);
pa.setDuration(duration);
pa.start();
}
mActivePointerId = INVALID_POINTER;
mSwipeGestureType = GESTURE_NONE;
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by ResurrectionRemix.
the class StackStateAnimator method startZTranslationAnimation.
private void startZTranslationAnimation(final View child, final ViewState viewState, long duration, long delay) {
Float previousStartValue = getChildTag(child, TAG_START_TRANSLATION_Z);
Float previousEndValue = getChildTag(child, TAG_END_TRANSLATION_Z);
float newEndValue = viewState.zTranslation;
if (previousEndValue != null && previousEndValue == newEndValue) {
return;
}
ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TRANSLATION_Z);
if (!mAnimationFilter.animateZ) {
// 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();
float relativeDiff = newEndValue - previousEndValue;
float newStartValue = previousStartValue + relativeDiff;
values[0].setFloatValues(newStartValue, newEndValue);
child.setTag(TAG_START_TRANSLATION_Z, newStartValue);
child.setTag(TAG_END_TRANSLATION_Z, newEndValue);
previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
return;
} else {
// no new animation needed, let's just apply the value
child.setTranslationZ(newEndValue);
}
}
ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Z, child.getTranslationZ(), newEndValue);
animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator);
animator.setDuration(newDuration);
if (delay > 0 && (previousAnimator == null || previousAnimator.getAnimatedFraction() == 0)) {
animator.setStartDelay(delay);
}
animator.addListener(getGlobalAnimationFinishedListener());
// remove the tag when the animation is finished
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
child.setTag(TAG_ANIMATOR_TRANSLATION_Z, null);
child.setTag(TAG_START_TRANSLATION_Z, null);
child.setTag(TAG_END_TRANSLATION_Z, null);
}
});
startAnimator(animator);
child.setTag(TAG_ANIMATOR_TRANSLATION_Z, animator);
child.setTag(TAG_START_TRANSLATION_Z, child.getTranslationZ());
child.setTag(TAG_END_TRANSLATION_Z, newEndValue);
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by ResurrectionRemix.
the class StackStateAnimator method startYTranslationAnimation.
private void startYTranslationAnimation(final View child, ViewState viewState, long duration, long delay) {
Float previousStartValue = getChildTag(child, TAG_START_TRANSLATION_Y);
Float previousEndValue = getChildTag(child, TAG_END_TRANSLATION_Y);
float newEndValue = viewState.yTranslation;
if (previousEndValue != null && previousEndValue == newEndValue) {
return;
}
ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TRANSLATION_Y);
if (!mAnimationFilter.animateY) {
// 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();
float relativeDiff = newEndValue - previousEndValue;
float newStartValue = previousStartValue + relativeDiff;
values[0].setFloatValues(newStartValue, newEndValue);
child.setTag(TAG_START_TRANSLATION_Y, newStartValue);
child.setTag(TAG_END_TRANSLATION_Y, newEndValue);
previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
return;
} else {
// no new animation needed, let's just apply the value
child.setTranslationY(newEndValue);
return;
}
}
ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, child.getTranslationY(), newEndValue);
Interpolator interpolator = mHeadsUpAppearChildren.contains(child) ? mHeadsUpAppearInterpolator : Interpolators.FAST_OUT_SLOW_IN;
animator.setInterpolator(interpolator);
long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator);
animator.setDuration(newDuration);
if (delay > 0 && (previousAnimator == null || previousAnimator.getAnimatedFraction() == 0)) {
animator.setStartDelay(delay);
}
animator.addListener(getGlobalAnimationFinishedListener());
final boolean isHeadsUpDisappear = mHeadsUpDisappearChildren.contains(child);
// remove the tag when the animation is finished
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
HeadsUpManager.setIsClickedNotification(child, false);
child.setTag(TAG_ANIMATOR_TRANSLATION_Y, null);
child.setTag(TAG_START_TRANSLATION_Y, null);
child.setTag(TAG_END_TRANSLATION_Y, null);
if (isHeadsUpDisappear) {
((ExpandableNotificationRow) child).setHeadsupDisappearRunning(false);
}
}
});
startAnimator(animator);
child.setTag(TAG_ANIMATOR_TRANSLATION_Y, animator);
child.setTag(TAG_START_TRANSLATION_Y, child.getTranslationY());
child.setTag(TAG_END_TRANSLATION_Y, newEndValue);
}
Aggregations