use of android.view.animation.Interpolator in project UltimateAndroid by cymcsg.
the class RayLayout method bindChildAnimation.
private void bindChildAnimation(final View child, final int index, final long duration) {
final boolean expanded = mExpanded;
final int childCount = getChildCount();
Rect frame = computeChildFrame(!expanded, mLeftHolderWidth, index, mChildGap, mChildSize);
final int toXDelta = frame.left - child.getLeft();
final int toYDelta = frame.top - child.getTop();
Interpolator interpolator = mExpanded ? new AccelerateInterpolator() : new OvershootInterpolator(1.5f);
final long startOffset = computeStartOffset(childCount, mExpanded, index, 0.1f, duration, interpolator);
Animation animation = mExpanded ? createShrinkAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator) : createExpandAnimation(0, toXDelta, 0, toYDelta, startOffset, duration, interpolator);
final boolean isLast = getTransformedIndex(expanded, childCount, index) == childCount - 1;
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (isLast) {
postDelayed(new Runnable() {
@Override
public void run() {
onAllAnimationsEnd();
}
}, 0);
}
}
});
child.setAnimation(animation);
}
use of android.view.animation.Interpolator in project android_frameworks_base by DirtyUnicorns.
the class AnimatorInflater method loadAnimator.
/**
* Creates a new animation whose parameters come from the specified context
* and attributes set.
*
* @param res The resources
* @param attrs The set of attributes holding the animation parameters
* @param anim Null if this is a ValueAnimator, otherwise this is an
* ObjectAnimator
*/
private static ValueAnimator loadAnimator(Resources res, Theme theme, AttributeSet attrs, ValueAnimator anim, float pathErrorScale) throws NotFoundException {
TypedArray arrayAnimator = null;
TypedArray arrayObjectAnimator = null;
if (theme != null) {
arrayAnimator = theme.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0);
} else {
arrayAnimator = res.obtainAttributes(attrs, R.styleable.Animator);
}
// If anim is not null, then it is an object animator.
if (anim != null) {
if (theme != null) {
arrayObjectAnimator = theme.obtainStyledAttributes(attrs, R.styleable.PropertyAnimator, 0, 0);
} else {
arrayObjectAnimator = res.obtainAttributes(attrs, R.styleable.PropertyAnimator);
}
anim.appendChangingConfigurations(arrayObjectAnimator.getChangingConfigurations());
}
if (anim == null) {
anim = new ValueAnimator();
}
anim.appendChangingConfigurations(arrayAnimator.getChangingConfigurations());
parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator, pathErrorScale);
final int resID = arrayAnimator.getResourceId(R.styleable.Animator_interpolator, 0);
if (resID > 0) {
final Interpolator interpolator = AnimationUtils.loadInterpolator(res, theme, resID);
if (interpolator instanceof BaseInterpolator) {
anim.appendChangingConfigurations(((BaseInterpolator) interpolator).getChangingConfiguration());
}
anim.setInterpolator(interpolator);
}
arrayAnimator.recycle();
if (arrayObjectAnimator != null) {
arrayObjectAnimator.recycle();
}
return anim;
}
use of android.view.animation.Interpolator in project android_frameworks_base by DirtyUnicorns.
the class AnimatorInflater method loadKeyframe.
private static Keyframe loadKeyframe(Resources res, Theme theme, AttributeSet attrs, int valueType) throws XmlPullParserException, IOException {
TypedArray a;
if (theme != null) {
a = theme.obtainStyledAttributes(attrs, R.styleable.Keyframe, 0, 0);
} else {
a = res.obtainAttributes(attrs, R.styleable.Keyframe);
}
Keyframe keyframe = null;
float fraction = a.getFloat(R.styleable.Keyframe_fraction, -1);
TypedValue keyframeValue = a.peekValue(R.styleable.Keyframe_value);
boolean hasValue = (keyframeValue != null);
if (valueType == VALUE_TYPE_UNDEFINED) {
// If not, fall back to default value type (i.e. float type).
if (hasValue && isColorType(keyframeValue.type)) {
valueType = VALUE_TYPE_COLOR;
} else {
valueType = VALUE_TYPE_FLOAT;
}
}
if (hasValue) {
switch(valueType) {
case VALUE_TYPE_FLOAT:
float value = a.getFloat(R.styleable.Keyframe_value, 0);
keyframe = Keyframe.ofFloat(fraction, value);
break;
case VALUE_TYPE_COLOR:
case VALUE_TYPE_INT:
int intValue = a.getInt(R.styleable.Keyframe_value, 0);
keyframe = Keyframe.ofInt(fraction, intValue);
break;
}
} else {
keyframe = (valueType == VALUE_TYPE_FLOAT) ? Keyframe.ofFloat(fraction) : Keyframe.ofInt(fraction);
}
final int resID = a.getResourceId(R.styleable.Keyframe_interpolator, 0);
if (resID > 0) {
final Interpolator interpolator = AnimationUtils.loadInterpolator(res, theme, resID);
keyframe.setInterpolator(interpolator);
}
a.recycle();
return keyframe;
}
use of android.view.animation.Interpolator in project android_frameworks_base by DirtyUnicorns.
the class KeyguardAffordanceView method setCircleRadius.
private void setCircleRadius(float circleRadius, boolean slowAnimation, boolean noAnimation) {
// Check if we need a new animation
boolean radiusHidden = (mCircleAnimator != null && mCircleWillBeHidden) || (mCircleAnimator == null && mCircleRadius == 0.0f);
boolean nowHidden = circleRadius == 0.0f;
boolean radiusNeedsAnimation = (radiusHidden != nowHidden) && !noAnimation;
if (!radiusNeedsAnimation) {
if (mCircleAnimator == null) {
mCircleRadius = circleRadius;
updateIconColor();
invalidate();
if (nowHidden) {
if (mPreviewView != null) {
mPreviewView.setVisibility(View.INVISIBLE);
}
}
} else if (!mCircleWillBeHidden) {
// We just update the end value
float diff = circleRadius - mMinBackgroundRadius;
PropertyValuesHolder[] values = mCircleAnimator.getValues();
values[0].setFloatValues(mCircleStartValue + diff, circleRadius);
mCircleAnimator.setCurrentPlayTime(mCircleAnimator.getCurrentPlayTime());
}
} else {
cancelAnimator(mCircleAnimator);
cancelAnimator(mPreviewClipper);
ValueAnimator animator = getAnimatorToRadius(circleRadius);
Interpolator interpolator = circleRadius == 0.0f ? Interpolators.FAST_OUT_LINEAR_IN : Interpolators.LINEAR_OUT_SLOW_IN;
animator.setInterpolator(interpolator);
long duration = 250;
if (!slowAnimation) {
float durationFactor = Math.abs(mCircleRadius - circleRadius) / (float) mMinBackgroundRadius;
duration = (long) (CIRCLE_APPEAR_DURATION * durationFactor);
duration = Math.min(duration, CIRCLE_DISAPPEAR_MAX_DURATION);
}
animator.setDuration(duration);
animator.start();
if (mPreviewView != null && mPreviewView.getVisibility() == View.VISIBLE) {
mPreviewView.setVisibility(View.VISIBLE);
mPreviewClipper = ViewAnimationUtils.createCircularReveal(mPreviewView, getLeft() + mCenterX, getTop() + mCenterY, mCircleRadius, circleRadius);
mPreviewClipper.setInterpolator(interpolator);
mPreviewClipper.setDuration(duration);
mPreviewClipper.addListener(mClipEndListener);
mPreviewClipper.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mPreviewView.setVisibility(View.INVISIBLE);
}
});
mPreviewClipper.start();
}
}
}
use of android.view.animation.Interpolator 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;
}
Aggregations