use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.
the class AnimUtils method progressWidthOut.
public static ValueAnimator progressWidthOut(final ProgressBar circularProgress, Animator.AnimatorListener listener) {
final float arcWidth = circularProgress.getBarPadding() + circularProgress.getBarWidth();
float start = circularProgress.getBarWidth();
ValueAnimator animator = ValueAnimator.ofFloat(start, 0);
animator.setDuration((long) (100 * start));
animator.setInterpolator(new DecelerateInterpolator());
if (listener != null)
animator.addListener(listener);
animator.addUpdateListener(valueAnimator -> {
float value = (Float) valueAnimator.getAnimatedValue();
circularProgress.setBarWidth(value);
circularProgress.setBarPadding(arcWidth - value);
});
animator.start();
return animator;
}
use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.
the class AnimUtils method flyOut.
public static ValueAnimator flyOut(final View view, Animator.AnimatorListener listener) {
float start = ViewHelper.getAlpha(view);
ValueAnimator animator = ValueAnimator.ofFloat(start, 0);
animator.setDuration((long) (200 * start));
animator.setInterpolator(new DecelerateInterpolator());
if (listener != null)
animator.addListener(listener);
animator.addUpdateListener(valueAnimator -> {
ViewHelper.setAlpha(view, (Float) valueAnimator.getAnimatedValue());
ViewHelper.setTranslationY(view, Math.min(view.getHeight() / 2, view.getResources().getDimension(R.dimen.carbon_1dip) * 50.0f) * (1 - (Float) valueAnimator.getAnimatedValue()));
if (view.getParent() != null)
((View) view.getParent()).postInvalidate();
});
animator.start();
return animator;
}
use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.
the class Snackbar method show.
public void show(final ViewGroup container) {
synchronized (Snackbar.class) {
this.container = container;
if (!next.contains(this))
next.add(this);
if (next.indexOf(this) == 0) {
Rect windowFrame = new Rect();
container.getWindowVisibleDisplayFrame(windowFrame);
Rect drawingRect = new Rect();
container.getDrawingRect(drawingRect);
setPadding(0, 0, 0, drawingRect.bottom - windowFrame.bottom);
container.addView(this);
ViewHelper.setAlpha(content, 0);
AnimUtils.flyIn(content, null);
for (final View pushedView : pushedViews) {
ValueAnimator animator = ValueAnimator.ofFloat(0, -1);
animator.setDuration(200);
animator.setInterpolator(new DecelerateInterpolator());
animator.addUpdateListener(valueAnimator -> {
MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
ViewHelper.setTranslationY(pushedView, (content.getHeight() + lp.bottomMargin) * (Float) valueAnimator.getAnimatedValue());
if (pushedView.getParent() != null)
((View) pushedView.getParent()).postInvalidate();
});
animator.start();
}
if (duration != INFINITE)
handler.postDelayed(hideRunnable, duration);
}
}
}
use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.
the class Snackbar method onScroll.
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (swipeToDismiss && animator == null && getParent() != null) {
swipe = e2.getX() - e1.getX();
ViewHelper.setTranslationX(content, swipe);
ViewHelper.setAlpha(content, Math.max(0, 1 - 2 * Math.abs(swipe) / content.getMeasuredWidth()));
if (Math.abs(swipe) > content.getMeasuredWidth() / 4) {
handler.removeCallbacks(hideRunnable);
animator = ObjectAnimator.ofFloat(swipe, content.getMeasuredWidth() / 2.0f * Math.signum(swipe));
animator.setDuration(200);
animator.addUpdateListener(valueAnimator -> {
float s = (Float) valueAnimator.getAnimatedValue();
ViewHelper.setTranslationX(content, s);
float alpha = Math.max(0, 1 - 2 * Math.abs((Float) valueAnimator.getAnimatedValue()) / content.getMeasuredWidth());
ViewHelper.setAlpha(content, alpha);
});
animator.start();
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
hideInternal();
animator = null;
}
});
for (final View pushedView : pushedViews) {
ValueAnimator animator = ValueAnimator.ofFloat(-1, 0);
animator.setDuration(200);
animator.setInterpolator(new DecelerateInterpolator());
animator.addUpdateListener(valueAnimator -> {
MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
ViewHelper.setTranslationY(pushedView, (content.getHeight() + lp.bottomMargin) * (Float) valueAnimator.getAnimatedValue());
if (pushedView.getParent() != null)
((View) pushedView.getParent()).postInvalidate();
});
animator.start();
}
}
return true;
}
return false;
}
use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.
the class TextView method setVisibility.
public void setVisibility(final int visibility) {
if (visibility == View.VISIBLE && (getVisibility() != View.VISIBLE || animator != null)) {
if (animator != null)
animator.cancel();
if (inAnim != AnimUtils.Style.None) {
animator = AnimUtils.animateIn(this, inAnim, new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator a) {
animator = null;
clearAnimation();
}
});
}
super.setVisibility(visibility);
} else if (visibility != View.VISIBLE && (getVisibility() == View.VISIBLE || animator != null)) {
if (animator != null)
animator.cancel();
if (outAnim == AnimUtils.Style.None) {
super.setVisibility(visibility);
return;
}
animator = AnimUtils.animateOut(this, outAnim, new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator a) {
if (((ValueAnimator) a).getAnimatedFraction() == 1)
TextView.super.setVisibility(visibility);
animator = null;
clearAnimation();
}
});
}
}
Aggregations