List of usage examples for android.animation ObjectAnimator setStartDelay
@Override public void setStartDelay(long startDelay)
From source file:cn.fulldroid.lib.datetimepicker.time.TimePickerDialog.java
private void setCurrentItemShowing(int index, boolean animateCircle, boolean delayLabelAnimate, boolean announce) { mTimePicker.setCurrentItemShowing(index, animateCircle); TextView labelToAnimate;//from w w w. j a v a 2s. c om if (index == HOUR_INDEX) { int hours = mTimePicker.getHours(); if (!mIs24HourMode) { hours = hours % 12; } mTimePicker.setContentDescription(mHourPickerDescription + ": " + hours); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectHours); } labelToAnimate = mHourView; } else { int minutes = mTimePicker.getMinutes(); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + minutes); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectMinutes); } labelToAnimate = mMinuteView; } int hourColor = (index == HOUR_INDEX) ? mBlue : mBlack; int minuteColor = (index == MINUTE_INDEX) ? mBlue : mBlack; mHourView.setTextColor(hourColor); mMinuteView.setTextColor(minuteColor); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(labelToAnimate, 0.85f, 1.1f); if (delayLabelAnimate) { pulseAnimator.setStartDelay(PULSE_ANIMATOR_DELAY); } pulseAnimator.start(); }
From source file:com.example.reedme.date.DatePickerDialog.java
private void setCurrentView(final int viewIndex) { long millis = mCalendar.getTimeInMillis(); switch (viewIndex) { case MONTH_AND_DAY_VIEW: ObjectAnimator pulseAnimator = Util.getPulseAnimator(mMonthAndDayView, 0.9f, 1.05f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false;/*from w ww .jav a 2 s . c o m*/ } mDayPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(true); mYearView.setSelected(false); mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); int flags = DateUtils.FORMAT_SHOW_DATE; String dayString = DateUtils.formatDateTime(getActivity(), millis, flags); mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString); Util.tryAccessibilityAnnounce(mAnimator, mSelectDay); break; case YEAR_VIEW: pulseAnimator = Util.getPulseAnimator(mYearView, 0.85f, 1.1f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } mYearPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(false); mYearView.setSelected(true); mAnimator.setDisplayedChild(YEAR_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); CharSequence yearString = YEAR_FORMAT.format(millis); mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString); Util.tryAccessibilityAnnounce(mAnimator, mSelectYear); break; } }
From source file:com.itsronald.widget.IndicatorDotPathView.java
/** * Animation: fill out the connecting center dot path to form a straight path between the two * dots.//from w ww. j a v a 2 s . c om * * @return An animator that grows pathCenter to the appropriate height. */ @NonNull private Animator centerSegmentGrowAnimator() { final float fromScale = 0f, toScale = 1f; final ObjectAnimator growAnimator; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { final PropertyValuesHolder scaleYProperty = PropertyValuesHolder.ofFloat(View.SCALE_Y, fromScale, toScale); growAnimator = ObjectAnimator.ofPropertyValuesHolder(centerSegment, scaleYProperty); } else { growAnimator = ObjectAnimator.ofFloat(centerSegment, "scaleY", fromScale, toScale); } // Start growing when the two ends of the path meet in the middle. final long animationDuration = PATH_STRETCH_ANIM_DURATION / 4; growAnimator.setStartDelay(animationDuration); growAnimator.setDuration(animationDuration); growAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); centerSegment.setVisibility(VISIBLE); } }); return growAnimator; }
From source file:com.philliphsu.hybridtimepicker.HybridTimePickerDialog.java
private void setCurrentItemShowing(int index, boolean animatePage, boolean delayLabelAnimate, boolean announce) { mGridPicker.setCurrentItemShowing(index, animatePage); TextView labelToAnimate;// ww w .java 2 s.c o m if (index == HOUR_INDEX) { /* int hours = mTimePicker.getHours(); if (!mIs24HourMode) { hours = hours % 12; } mTimePicker.setContentDescription(mHourPickerDescription + ": " + hours); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectHours); } */ labelToAnimate = mHourView; } else { /* int minutes = mTimePicker.getMinutes(); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + minutes); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectMinutes); } */ labelToAnimate = mMinuteView; } int hourColor = (index == HOUR_INDEX) ? mSelectedColor : mUnselectedColor; int minuteColor = (index == MINUTE_INDEX) ? mSelectedColor : mUnselectedColor; mHourView.setTextColor(hourColor); mMinuteView.setTextColor(minuteColor); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(labelToAnimate, 0.85f, 1.1f); if (delayLabelAnimate) { pulseAnimator.setStartDelay(PULSE_ANIMATOR_DELAY); } pulseAnimator.start(); }
From source file:com.example.pickerclickcar.time.TimePickerDialog.java
private void setCurrentItemShowing(int index, boolean animateCircle, boolean delayLabelAnimate, boolean announce) { mTimePicker.setCurrentItemShowing(index, animateCircle); TextView labelToAnimate;//ww w . j a v a 2 s. com if (index == HOUR_INDEX) { int hours = mTimePicker.getHours(); if (!mIs24HourMode) { hours = hours % 12; } mTimePicker.setContentDescription(mHourPickerDescription + ": " + hours); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectHours); } labelToAnimate = mHourView; } else { int minutes = mTimePicker.getMinutes(); mTimePicker.setContentDescription(mMinutePickerDescription + ": " + minutes); if (announce) { Utils.tryAccessibilityAnnounce(mTimePicker, mSelectMinutes); } labelToAnimate = mMinuteView; } int hourColor = (index == HOUR_INDEX) ? mSelectedColor : mUnselectedColor; int minuteColor = (index == MINUTE_INDEX) ? mSelectedColor : mUnselectedColor; mHourView.setTextColor(hourColor); mMinuteView.setTextColor(minuteColor); ObjectAnimator pulseAnimator = Utils.getPulseAnimator(labelToAnimate, 0.85f, 1.1f); if (delayLabelAnimate) { pulseAnimator.setStartDelay(PULSE_ANIMATOR_DELAY); } pulseAnimator.start(); }
From source file:com.leavjenn.smoothdaterangepicker.date.SmoothDateRangePickerFragment.java
private void setViewSelected(View... views) { mMonthAndDayView.setSelected(false); mMonthAndDayViewEnd.setSelected(false); mYearView.setSelected(false);//from w w w. j av a 2s .c o m mYearViewEnd.setSelected(false); mDurationView.setSelected(false); for (View view : views) { view.setSelected(true); if (view != mDurationView) { // disable DurationView animation ObjectAnimator pulseAnimator = Utils.getPulseAnimator(view, 0.9f, 1.05f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } pulseAnimator.start(); } } }
From source file:com.android.tv.menu.MenuLayoutManager.java
/** * Move the current selection to the given {@code position} with animation. * The animation specification is included in http://b/21069476 *//*ww w . ja v a 2 s . c o m*/ public void setSelectedPositionSmooth(final int position) { if (DEBUG) { Log.d(TAG, "setSelectedPositionSmooth(position=" + position + ") {previousPosition=" + mSelectedPosition + "}"); } if (mMenuView.getVisibility() != View.VISIBLE) { setSelectedPosition(position); return; } if (mSelectedPosition == position) { return; } boolean oldIndexValid = Utils.isIndexValid(mMenuRowViews, mSelectedPosition); SoftPreconditions.checkState(oldIndexValid, TAG, "No previous selection: " + mSelectedPosition); if (!oldIndexValid) { return; } boolean newIndexValid = Utils.isIndexValid(mMenuRowViews, position); SoftPreconditions.checkArgument(newIndexValid, TAG, "position " + position); if (!newIndexValid) { return; } MenuRow row = mMenuRows.get(position); if (!row.isVisible()) { Log.e(TAG, "Moving to the invisible row: " + position); return; } if (mAnimatorSet != null) { // Do not cancel the animation here. The property values should be set to the end values // when the animation finishes. mAnimatorSet.end(); } if (mTitleFadeOutAnimator != null) { // Cancel the animation instead of ending it in order that the title animation starts // again from the intermediate state. mTitleFadeOutAnimator.cancel(); } final int oldPosition = mSelectedPosition; mSelectedPosition = position; if (DEBUG) dumpChildren("startRowAnimation()"); MenuRowView currentView = mMenuRowViews.get(position); // Show the children of the next row. currentView.getTitleView().setVisibility(View.VISIBLE); currentView.getContentsView().setVisibility(View.VISIBLE); // Request focus after the new contents view shows up. mMenuView.requestFocus(); if (mTempTitleViewForOld == null) { // Initialize here because we don't know when the views are inflated. mTempTitleViewForOld = (TextView) mMenuView.findViewById(R.id.temp_title_for_old); mTempTitleViewForCurrent = (TextView) mMenuView.findViewById(R.id.temp_title_for_current); } // Animations. mPropertyValuesAfterAnimation.clear(); List<Animator> animators = new ArrayList<>(); boolean scrollDown = position > oldPosition; List<Rect> layouts = getViewLayouts(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), mMenuView.getBottom()); // Old row. MenuRow oldRow = mMenuRows.get(oldPosition); MenuRowView oldView = mMenuRowViews.get(oldPosition); View oldContentsView = oldView.getContentsView(); // Old contents view. animators.add(createAlphaAnimator(oldContentsView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) .setDuration(mOldContentsFadeOutDuration)); final TextView oldTitleView = oldView.getTitleView(); setTempTitleView(mTempTitleViewForOld, oldTitleView); Rect oldLayoutRect = layouts.get(oldPosition); if (scrollDown) { // Old title view. if (oldRow.hideTitleWhenSelected() && oldTitleView.getVisibility() != View.VISIBLE) { // This case is not included in the animation specification. mTempTitleViewForOld.setScaleX(1.0f); mTempTitleViewForOld.setScaleY(1.0f); animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, oldView.getTitleViewAlphaDeselected(), mFastOutLinearIn)); int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop(); animators.add(createTranslationYAnimator(mTempTitleViewForOld, offset + mRowScrollUpAnimationOffset, offset)); } else { animators .add(createScaleXAnimator(mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f)); animators .add(createScaleYAnimator(mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f)); animators.add(createAlphaAnimator(mTempTitleViewForOld, oldTitleView.getAlpha(), oldView.getTitleViewAlphaDeselected(), mLinearOutSlowIn)); animators.add(createTranslationYAnimator(mTempTitleViewForOld, 0, oldLayoutRect.top - mTempTitleViewForOld.getTop())); } oldTitleView.setAlpha(oldView.getTitleViewAlphaDeselected()); oldTitleView.setVisibility(View.INVISIBLE); } else { Rect currentLayoutRect = new Rect(layouts.get(position)); // Old title view. // The move distance in the specification is 32dp(mRowScrollUpAnimationOffset). // But if the height of the upper row is small, the upper row will move down a lot. In // this case, this row needs to move more than the specification to avoid the overlap of // the two titles. // The maximum is to the top of the start position of mTempTitleViewForOld. int distanceCurrentTitle = currentLayoutRect.top - currentView.getTop(); int distance = Math.max(mRowScrollUpAnimationOffset, distanceCurrentTitle); int distanceToTopOfSecondTitle = oldLayoutRect.top - mRowScrollUpAnimationOffset - oldView.getTop(); animators.add( createTranslationYAnimator(oldTitleView, 0.0f, Math.min(distance, distanceToTopOfSecondTitle))); animators.add(createAlphaAnimator(oldTitleView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) .setDuration(mOldContentsFadeOutDuration)); animators.add(createScaleXAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f)); animators.add(createScaleYAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f)); mTempTitleViewForOld.setScaleX(1.0f); mTempTitleViewForOld.setScaleY(1.0f); animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, oldView.getTitleViewAlphaDeselected(), mFastOutLinearIn)); int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop(); animators.add( createTranslationYAnimator(mTempTitleViewForOld, offset - mRowScrollUpAnimationOffset, offset)); } // Current row. Rect currentLayoutRect = new Rect(layouts.get(position)); TextView currentTitleView = currentView.getTitleView(); View currentContentsView = currentView.getContentsView(); currentContentsView.setAlpha(0.0f); if (scrollDown) { // Current title view. setTempTitleView(mTempTitleViewForCurrent, currentTitleView); // The move distance in the specification is 32dp(mRowScrollUpAnimationOffset). // But if the height of the upper row is small, the upper row will move up a lot. In // this case, this row needs to start the move from more than the specification to avoid // the overlap of the two titles. // The maximum is to the top of the end position of mTempTitleViewForCurrent. int distanceOldTitle = oldView.getTop() - oldLayoutRect.top; int distance = Math.max(mRowScrollUpAnimationOffset, distanceOldTitle); int distanceTopOfSecondTitle = currentView.getTop() - mRowScrollUpAnimationOffset - currentLayoutRect.top; animators.add(createTranslationYAnimator(currentTitleView, Math.min(distance, distanceTopOfSecondTitle), 0.0f)); currentView.setTop(currentLayoutRect.top); ObjectAnimator animator = createAlphaAnimator(currentTitleView, 0.0f, 1.0f, mFastOutLinearIn) .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); currentTitleView.setAlpha(0.0f); animators.add(animator); animators.add(createScaleXAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); animators.add(createScaleYAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); animators.add(createTranslationYAnimator(mTempTitleViewForCurrent, 0.0f, -mRowScrollUpAnimationOffset)); animators.add(createAlphaAnimator(mTempTitleViewForCurrent, currentView.getTitleViewAlphaDeselected(), 0, mLinearOutSlowIn)); // Current contents view. animators.add(createTranslationYAnimator(currentContentsView, mRowScrollUpAnimationOffset, 0.0f)); animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn) .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); animators.add(animator); } else { currentView.setBottom(currentLayoutRect.bottom); // Current title view. int currentViewOffset = currentLayoutRect.top - currentView.getTop(); animators.add(createTranslationYAnimator(currentTitleView, 0, currentViewOffset)); animators.add(createAlphaAnimator(currentTitleView, currentView.getTitleViewAlphaDeselected(), 1.0f, mFastOutSlowIn)); animators.add(createScaleXAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); animators.add(createScaleYAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); // Current contents view. animators.add(createTranslationYAnimator(currentContentsView, currentViewOffset - mRowScrollUpAnimationOffset, currentViewOffset)); ObjectAnimator animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn) .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); animators.add(animator); } // Next row. int nextPosition; if (scrollDown) { nextPosition = findNextVisiblePosition(position); if (nextPosition != -1) { MenuRowView nextView = mMenuRowViews.get(nextPosition); Rect nextLayoutRect = layouts.get(nextPosition); animators.add(createTranslationYAnimator(nextView, nextLayoutRect.top + mRowScrollUpAnimationOffset - nextView.getTop(), nextLayoutRect.top - nextView.getTop())); animators.add(createAlphaAnimator(nextView, 0.0f, 1.0f, mFastOutLinearIn)); } } else { nextPosition = findNextVisiblePosition(oldPosition); if (nextPosition != -1) { MenuRowView nextView = mMenuRowViews.get(nextPosition); animators.add(createTranslationYAnimator(nextView, 0, mRowScrollUpAnimationOffset)); animators.add(createAlphaAnimator(nextView, nextView.getTitleViewAlphaDeselected(), 0.0f, 1.0f, mLinearOutSlowIn)); } } // Other rows. int count = mMenuRowViews.size(); for (int i = 0; i < count; ++i) { MenuRowView view = mMenuRowViews.get(i); if (view.getVisibility() == View.VISIBLE && i != oldPosition && i != position && i != nextPosition) { Rect rect = layouts.get(i); animators.add(createTranslationYAnimator(view, 0, rect.top - view.getTop())); } } // Run animation. final List<ViewPropertyValueHolder> propertyValuesAfterAnimation = new ArrayList<>(); propertyValuesAfterAnimation.addAll(mPropertyValuesAfterAnimation); mAnimatorSet = new AnimatorSet(); mAnimatorSet.playTogether(animators); mAnimatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { if (DEBUG) dumpChildren("onRowAnimationEndBefore"); mAnimatorSet = null; // The property values which are different from the end values and need to be // changed after the animation are set here. // e.g. setting translationY to 0, alpha of the contents view to 1. for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) { holder.property.set(holder.view, holder.value); } oldTitleView.setVisibility(View.VISIBLE); mMenuRowViews.get(oldPosition).onDeselected(); mMenuRowViews.get(position).onSelected(true); mTempTitleViewForOld.setVisibility(View.GONE); mTempTitleViewForCurrent.setVisibility(View.GONE); layout(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), mMenuView.getBottom()); if (DEBUG) dumpChildren("onRowAnimationEndAfter"); MenuRow currentRow = mMenuRows.get(position); if (currentRow.hideTitleWhenSelected()) { View titleView = mMenuRowViews.get(position).getTitleView(); mTitleFadeOutAnimator = createAlphaAnimator(titleView, titleView.getAlpha(), 0.0f, mLinearOutSlowIn); mTitleFadeOutAnimator.setStartDelay(TITLE_SHOW_DURATION_BEFORE_HIDDEN_MS); mTitleFadeOutAnimator.addListener(new AnimatorListenerAdapter() { private boolean mCanceled; @Override public void onAnimationCancel(Animator animator) { mCanceled = true; } @Override public void onAnimationEnd(Animator animator) { mTitleFadeOutAnimator = null; if (!mCanceled) { mMenuRowViews.get(position).onSelected(false); } } }); mTitleFadeOutAnimator.start(); } } }); mAnimatorSet.start(); if (DEBUG) dumpChildren("startedRowAnimation()"); }
From source file:com.customdatepicker.date.DatePickerDialog.java
private void setCurrentView(final int viewIndex) { long millis = mCalendar.getTimeInMillis(); switch (viewIndex) { case MONTH_AND_DAY_VIEW: if (mVersion == Version.VERSION_1) { ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f, 1.05f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; }//from ww w .j av a 2s . co m mDayPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(true); mYearView.setSelected(false); mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); } else { mDayPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(true); mYearView.setSelected(false); mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW); mCurrentView = viewIndex; } } int flags = DateUtils.FORMAT_SHOW_DATE; String dayString = DateUtils.formatDateTime(getActivity(), millis, flags); mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay); break; case YEAR_VIEW: if (mVersion == Version.VERSION_1) { ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mYearView, 0.85f, 1.1f); if (mDelayAnimation) { pulseAnimator.setStartDelay(ANIMATION_DELAY); mDelayAnimation = false; } mYearPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(false); mYearView.setSelected(true); mAnimator.setDisplayedChild(YEAR_VIEW); mCurrentView = viewIndex; } pulseAnimator.start(); } else { mYearPickerView.onDateChanged(); if (mCurrentView != viewIndex) { mMonthAndDayView.setSelected(false); mYearView.setSelected(true); mAnimator.setDisplayedChild(YEAR_VIEW); mCurrentView = viewIndex; } } CharSequence yearString = YEAR_FORMAT.format(millis); mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear); break; } }
From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java
private void animateIdleStateButtonAfterClick() { int textColorChangeDuration = 10; ObjectAnimator colorAnim = ObjectAnimator.ofInt(this, "textColor", getNormalColor(this.getTextColors()), mIdleStateTextColorAfterClick); colorAnim.setDuration(textColorChangeDuration); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.start();/* ww w . j av a 2 s . c o m*/ ObjectAnimator colorAnim1 = ObjectAnimator.ofInt(this, "textColor", mIdleStateTextColorAfterClick, getNormalColor(this.getTextColors())); colorAnim1.setDuration(0); colorAnim1.setStartDelay(IDLE_STATE_ANIMATION_DURATION_AFTER_CLICK - textColorChangeDuration); colorAnim1.setEvaluator(new ArgbEvaluator()); colorAnim1.setInterpolator(new BounceInterpolator()); colorAnim1.start(); ObjectAnimator bgAnim = ObjectAnimator.ofInt(this, "backgroundColor", getNormalColor(mIdleColorState), mIdleStateBackgroundColorAfterClick); bgAnim.setDuration(0); bgAnim.setEvaluator(new ArgbEvaluator()); bgAnim.start(); int textSizeAnimationDuration = 150; ValueAnimator animator = ValueAnimator.ofFloat(textSize, textSize - textSize / 4); animator.setDuration(textSizeAnimationDuration); animator.setRepeatCount(1); animator.setRepeatMode(ValueAnimator.REVERSE); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float animatedValue = (float) valueAnimator.getAnimatedValue(); setTextSize(animatedValue); } }); animator.start(); }
From source file:io.plaidapp.core.ui.transitions.ReflowText.java
/** * Create Animators to transition each run of text from start to end position and size. *//*from w ww .j a va2 s . com*/ @NonNull private List<Animator> createRunAnimators(View view, ReflowData startData, ReflowData endData, Bitmap startText, Bitmap endText, List<Run> runs) { List<Animator> animators = new ArrayList<>(runs.size()); int dx = startData.bounds.left - endData.bounds.left; int dy = startData.bounds.top - endData.bounds.top; long startDelay = 0L; // move text closest to the destination first i.e. loop forward or backward over the runs boolean upward = startData.bounds.centerY() > endData.bounds.centerY(); boolean first = true; boolean lastRightward = true; LinearInterpolator linearInterpolator = new LinearInterpolator(); for (int i = upward ? 0 : runs.size() - 1; ((upward && i < runs.size()) || (!upward && i >= 0)); i += (upward ? 1 : -1)) { Run run = runs.get(i); // skip text runs which aren't visible in either state if (!run.startVisible && !run.endVisible) continue; // create & position the drawable which displays the run; add it to the overlay. SwitchDrawable drawable = new SwitchDrawable(startText, run.start, startData.textSize, endText, run.end, endData.textSize); drawable.setBounds(run.start.left + dx, run.start.top + dy, run.start.right + dx, run.start.bottom + dy); view.getOverlay().add(drawable); PropertyValuesHolder topLeft = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, null, getPathMotion().getPath(run.start.left + dx, run.start.top + dy, run.end.left, run.end.top)); PropertyValuesHolder width = PropertyValuesHolder.ofInt(SwitchDrawable.WIDTH, run.start.width(), run.end.width()); PropertyValuesHolder height = PropertyValuesHolder.ofInt(SwitchDrawable.HEIGHT, run.start.height(), run.end.height()); // the progress property drives the switching behaviour PropertyValuesHolder progress = PropertyValuesHolder.ofFloat(SwitchDrawable.PROGRESS, 0f, 1f); Animator runAnim = ObjectAnimator.ofPropertyValuesHolder(drawable, topLeft, width, height, progress); boolean rightward = run.start.centerX() + dx < run.end.centerX(); if ((run.startVisible && run.endVisible) && !first && rightward != lastRightward) { // increase the start delay (by a decreasing amount) for the next run // (if it's visible throughout) to stagger the movement and try to minimize overlaps startDelay += staggerDelay; staggerDelay *= STAGGER_DECAY; } lastRightward = rightward; first = false; runAnim.setStartDelay(startDelay); long animDuration = Math.max(minDuration, duration - (startDelay / 2)); runAnim.setDuration(animDuration); animators.add(runAnim); if (run.startVisible != run.endVisible) { // if run is appearing/disappearing then fade it in/out ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, run.startVisible ? OPAQUE : TRANSPARENT, run.endVisible ? OPAQUE : TRANSPARENT); fade.setDuration((duration + startDelay) / 2); if (!run.startVisible) { drawable.setAlpha(TRANSPARENT); fade.setStartDelay((duration + startDelay) / 2); } else { fade.setStartDelay(startDelay); } animators.add(fade); } else { // slightly fade during transition to minimize movement ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, OPAQUE, OPACITY_MID_TRANSITION, OPAQUE); fade.setStartDelay(startDelay); fade.setDuration(duration + startDelay); fade.setInterpolator(linearInterpolator); animators.add(fade); } } return animators; }