private Animator createHideItemAnimator(final View item) { final float dx = centerItem.getX() - item.getX(); final float dy = centerItem.getY() - item.getY(); Animator anim = ObjectAnimator.ofPropertyValuesHolder( item, AnimatorUtils.scaleX(1f, 0f), AnimatorUtils.scaleY(1f, 0f), AnimatorUtils.translationX(0f, dx), AnimatorUtils.translationY(0f, dy)); anim.setInterpolator(new DecelerateInterpolator()); anim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); item.setTranslationX(0f); item.setTranslationY(0f); } }); anim.setDuration(50); return anim; }
@Override protected void runAnimators() { reflectSetupStartEndListeners(); animMap.clear(); for (int i = 0, count = getTransitionCount(); i < count; i++) { Transition transition = getTransitionAt(i); ArrayList<ValueAnimator> valueAnimators = new ArrayList<>(); for (Animator animator : AnimatorUtils.collectAnimators(transition)) { valueAnimators.addAll(AnimatorUtils.collectValueAnimators(animator)); } // insure animator's duration, startDelay, Interpolator same as this transition long duration = (long) (getDuration() / AnimatorUtils.getAnimatorDurationScale()); long startDelay = getStartDelay(); TimeInterpolator interpolator = getInterpolator(); for (ValueAnimator animator : valueAnimators) { if (duration >= 0) animator.setDuration(duration); if (startDelay >= 0) animator.setStartDelay(startDelay + animator.getStartDelay()); if (interpolator != null) animator.setInterpolator(interpolator); } animMap.put(transition, valueAnimators); // you can change transition's duration, startDelay and Interpolator at here if (playControl != null) playControl.onPreRunAnimator(transition, valueAnimators); } }
@Test public void should_round_do_nothing_if_price_is_already_rounded() { // GIVEN: Price double price = 25.48; // WHEN: round double rounded = AnimatorUtils.round(price); // THEN: price are same assertThat(rounded).isEqualTo(price); }
@Test public void should_round_up() { // GIVEN: Price double price = 25.489; // WHEN: round double rounded = AnimatorUtils.round(price); // THEN: price are same assertThat(rounded).isEqualTo(25.49); }
private Animator createShowItemAnimator(View item) { float dx = centerItem.getX() - item.getX(); float dy = centerItem.getY() - item.getY(); item.setScaleX(0f); item.setScaleY(0f); item.setTranslationX(dx); item.setTranslationY(dy); Animator anim = ObjectAnimator.ofPropertyValuesHolder( item, AnimatorUtils.scaleX(0f, 1f), AnimatorUtils.scaleY(0f, 1f), AnimatorUtils.translationX(dx, 0f), AnimatorUtils.translationY(dy, 0f)); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(50); return anim; }