use of android.animation.PropertyValuesHolder in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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);
}
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by crdroidandroid.
the class FastScroller method animateBounds.
/**
* Returns an animator for the view's bounds.
*/
private static Animator animateBounds(View v, Rect bounds) {
final PropertyValuesHolder left = PropertyValuesHolder.ofInt(LEFT, bounds.left);
final PropertyValuesHolder top = PropertyValuesHolder.ofInt(TOP, bounds.top);
final PropertyValuesHolder right = PropertyValuesHolder.ofInt(RIGHT, bounds.right);
final PropertyValuesHolder bottom = PropertyValuesHolder.ofInt(BOTTOM, bounds.bottom);
return ObjectAnimator.ofPropertyValuesHolder(v, left, top, right, bottom);
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by crdroidandroid.
the class NotificationStackScrollLayout method startTopAnimation.
private void startTopAnimation() {
int previousEndValue = mEndAnimationRect.top;
int newEndValue = mBackgroundBounds.top;
ObjectAnimator previousAnimator = mTopAnimator;
if (previousAnimator != null && previousEndValue == newEndValue) {
return;
}
if (!mAnimateNextBackgroundTop) {
// 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
int previousStartValue = mStartAnimationRect.top;
PropertyValuesHolder[] values = previousAnimator.getValues();
values[0].setIntValues(previousStartValue, newEndValue);
mStartAnimationRect.top = previousStartValue;
mEndAnimationRect.top = newEndValue;
previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
return;
} else {
// no new animation needed, let's just apply the value
setBackgroundTop(newEndValue);
return;
}
}
if (previousAnimator != null) {
previousAnimator.cancel();
}
ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundTop", mCurrentBounds.top, 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.top = -1;
mEndAnimationRect.top = -1;
mTopAnimator = null;
}
});
animator.start();
mStartAnimationRect.top = mCurrentBounds.top;
mEndAnimationRect.top = newEndValue;
mTopAnimator = animator;
}
use of android.animation.PropertyValuesHolder in project android_frameworks_base by crdroidandroid.
the class StackStateAnimator method startInsetAnimation.
private void startInsetAnimation(final ExpandableView child, StackViewState viewState, long duration, long delay) {
Integer previousStartValue = getChildTag(child, TAG_START_TOP_INSET);
Integer previousEndValue = getChildTag(child, TAG_END_TOP_INSET);
int newEndValue = viewState.clipTopAmount;
if (previousEndValue != null && previousEndValue == newEndValue) {
return;
}
ValueAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TOP_INSET);
if (!mAnimationFilter.animateTopInset) {
// 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();
int relativeDiff = newEndValue - previousEndValue;
int newStartValue = previousStartValue + relativeDiff;
values[0].setIntValues(newStartValue, newEndValue);
child.setTag(TAG_START_TOP_INSET, newStartValue);
child.setTag(TAG_END_TOP_INSET, newEndValue);
previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
return;
} else {
// no new animation needed, let's just apply the value
child.setClipTopAmount(newEndValue);
return;
}
}
ValueAnimator animator = ValueAnimator.ofInt(child.getClipTopAmount(), newEndValue);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
child.setClipTopAmount((int) animation.getAnimatedValue());
}
});
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_TOP_INSET, null);
child.setTag(TAG_START_TOP_INSET, null);
child.setTag(TAG_END_TOP_INSET, null);
}
});
startAnimator(animator);
child.setTag(TAG_ANIMATOR_TOP_INSET, animator);
child.setTag(TAG_START_TOP_INSET, child.getClipTopAmount());
child.setTag(TAG_END_TOP_INSET, newEndValue);
}
Aggregations