private void hideMenu(int cx, int cy, float startRadius, float endRadius) { List<Animator> animList = new ArrayList<>(); for (int i = arcLayout.getChildCount() - 1; i >= 0; i--) { animList.add(createHideItemAnimator(arcLayout.getChildAt(i))); } animList.add(createHideItemAnimator(centerItem)); Animator revealAnim = createCircularReveal(menuLayout, cx, cy, startRadius, endRadius); revealAnim.setInterpolator(new AccelerateDecelerateInterpolator()); revealAnim.setDuration(200); revealAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); menuLayout.setVisibility(View.INVISIBLE); } }); animList.add(revealAnim); AnimatorSet animSet = new AnimatorSet(); animSet.playSequentially(animList); animSet.start(); }
private void startTrans() { ObjectAnimator animator = ObjectAnimator.ofFloat(this, "translationX", 0, width / 3); animator.setDuration(200); animator.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator2 = ObjectAnimator.ofFloat(this, "translationX", width / 3, -width / 4); animator2.setDuration(200); animator2.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator3 = ObjectAnimator.ofFloat(this, "translationX", -width / 4, width / 5); animator3.setDuration(200); animator3.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator4 = ObjectAnimator.ofFloat(this, "translationX", width / 5, -width / 6); animator4.setDuration(200); animator4.setInterpolator(new DecelerateInterpolator()); ObjectAnimator animator5 = ObjectAnimator.ofFloat(this, "translationX", -width / 6, 0); animator5.setDuration(200); animator5.setInterpolator(new DecelerateInterpolator()); AnimatorSet set = new AnimatorSet(); List<Animator> items = new ArrayList<Animator>(); items.add(animator); items.add(animator2); items.add(animator3); items.add(animator4); items.add(animator5); set.playSequentially(items); set.start(); }
private void animateFadeOutFadeIn(final View src, final View dst) { if (dst.getVisibility() != View.VISIBLE || dst.getAlpha() != 1f) { AnimatorSet set = new AnimatorSet(); set.playSequentially( ObjectAnimator.ofFloat(src, "alpha", 0f), ObjectAnimator.ofFloat(dst, "alpha", 1f)); set.setInterpolator(new LinearInterpolator()); set.addListener( new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { src.setAlpha(1f); dst.setAlpha(0f); src.setVisibility(View.VISIBLE); dst.setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { src.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) {} }); set.setDuration(250); set.start(); } else { src.setAlpha(1f); src.setVisibility(View.GONE); } }
public void compatSetOrAnimatePlusCheckIcon( final ImageView imageView, boolean isCheck, boolean allowAnimate) { final int imageResId = isCheck ? R.drawable.add_schedule_button_icon_checked : R.drawable.add_schedule_button_icon_unchecked; if (imageView.getTag() != null) { if (imageView.getTag() instanceof Animator) { Animator anim = (Animator) imageView.getTag(); anim.end(); imageView.setAlpha(1f); } } if (allowAnimate && isCheck) { int duration = mActivity.getResources().getInteger(android.R.integer.config_shortAnimTime); Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f); outAnimator.setDuration(duration / 2); outAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageResource(imageResId); } }); AnimatorSet inAnimator = new AnimatorSet(); outAnimator.setDuration(duration); inAnimator.playTogether( ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f)); AnimatorSet set = new AnimatorSet(); set.playSequentially(outAnimator, inAnimator); set.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setTag(null); } }); imageView.setTag(set); set.start(); } else { mHandler.post( new Runnable() { @Override public void run() { imageView.setImageResource(imageResId); } }); } }
/** * Default constructor. * * @param pathView The view that must be animated. */ public AnimatorSetBuilder(final PathView pathView) { paths = pathView.paths; for (SvgUtils.SvgPath path : paths) { path.setAnimationStepListener(pathView); ObjectAnimator animation = ObjectAnimator.ofFloat(path, "length", 0.0f, path.getLength()); animators.add(animation); } animatorSet.playSequentially(animators); }
private void startLineAnim() { mStatus = LINE_MOVE; int duration = 1; // (cxRight - cxLeft) != mRecWidth. 极小的数字也会画出一个点 linePosXAnim = ValueAnimator.ofFloat(0, cxRight - cxLeft); linePosXAnim.setDuration(duration * mRippleDuration); linePosXAnim.setInterpolator(new LinearInterpolator()); linePosXAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mLinePosX = (float) animation.getAnimatedValue(); postInvalidate(); } }); sweepAngAnim = ValueAnimator.ofFloat(180f, mSweepAngMin); sweepAngAnim.setDuration(duration * mRippleDuration); sweepAngAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mSweepAng = (float) animation.getAnimatedValue(); postInvalidate(); } }); sweepAngAnim.setInterpolator(new LinearInterpolator()); sweepAngAnim.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { mLinePosX = 0; mSweepAng = 180f; startTickAnim(); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); AnimatorSet animSet = new AnimatorSet(); animSet.playSequentially(linePosXAnim, sweepAngAnim); animSet.start(); }
private void clearAnimation() { final Animator startAnimator; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final int revealSize = resultContainerView.getWidth(); final int[] location = new int[2]; deleteButton.getLocationInWindow(location); final int centerX = location[0] + deleteButton.getWidth() / 2; startAnimator = ViewAnimationUtils.createCircularReveal( revealView, centerX, resultContainerView.getHeight(), 0, revealSize); } else { startAnimator = ObjectAnimator.ofFloat( revealView, View.TRANSLATION_Y, resultContainerView.getHeight(), 0); } startAnimator.setDuration(ANIMATION_DURATION_CLEAR_START); final Animator endAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 1, 0); final AnimatorSet animator = new AnimatorSet(); animator.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { revealView.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { revealView.setVisibility(View.GONE); revealView.setAlpha(1); } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); animator.playSequentially(startAnimator, endAnimator); animator.start(); }
private void showMenu(int cx, int cy, float startRadius, float endRadius) { menuLayout.setVisibility(View.VISIBLE); List<Animator> animList = new ArrayList<>(); Animator revealAnim = createCircularReveal(menuLayout, cx, cy, startRadius, endRadius); revealAnim.setInterpolator(new AccelerateDecelerateInterpolator()); revealAnim.setDuration(200); animList.add(revealAnim); animList.add(createShowItemAnimator(centerItem)); for (int i = 0, len = arcLayout.getChildCount(); i < len; i++) { animList.add(createShowItemAnimator(arcLayout.getChildAt(i))); } AnimatorSet animSet = new AnimatorSet(); animSet.playSequentially(animList); animSet.start(); }
/** Starts the animation after taking the screenshot */ private void startAnimation( final Runnable finisher, int w, int h, boolean statusBarVisible, boolean navBarVisible) { // Add the view for the animation mScreenshotView.setImageBitmap(mScreenBitmap); mScreenshotLayout.requestFocus(); // Setup the animation with the screenshot just taken if (mScreenshotAnimation != null) { mScreenshotAnimation.end(); } mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); ValueAnimator screenshotDropInAnim = createScreenshotDropInAnimation(); ValueAnimator screenshotFadeOutAnim = createScreenshotDropOutAnimation(w, h, statusBarVisible, navBarVisible); mScreenshotAnimation = new AnimatorSet(); mScreenshotAnimation.playSequentially(screenshotDropInAnim, screenshotFadeOutAnim); mScreenshotAnimation.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Save the screenshot once we have a bit of time now saveScreenshotInWorkerThread(finisher); mWindowManager.removeView(mScreenshotLayout); } }); mScreenshotLayout.post( new Runnable() { @Override public void run() { // Play the shutter sound to notify that we've taken a screenshot mCameraSound.playSound(CameraSound.SHUTTER_CLICK); mScreenshotView.setLayerType(View.LAYER_TYPE_HARDWARE, null); mScreenshotView.buildLayer(); mScreenshotAnimation.start(); } }); }
Animator getCancelAnimator() { ObjectAnimator backToTransparent1 = (ObjectAnimator) AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_end); ObjectAnimator goDark = (ObjectAnimator) AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_go_dark); ObjectAnimator backToTransparent2 = (ObjectAnimator) AnimatorInflater.loadAnimator(view.getContext(), R.animator.pin_background_end); ViewGroup parent = (ViewGroup) view.getParent(); ArgbEvaluator evaluator = new ArgbEvaluator(); for (ObjectAnimator animator : list(backToTransparent1, goDark, backToTransparent2)) { animator.setTarget(parent); animator.setEvaluator(evaluator); } AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setTarget(parent); animatorSet.playSequentially(backToTransparent1, goDark, backToTransparent2); return animatorSet; }
private void populateToolbarAnimations() { mSecurityButtonShowAnimator = new AnimatorSet(); int securityIconButtonWidth = getResources().getDimensionPixelSize(R.dimen.location_bar_icon_width); Animator titleUrlTranslateAnimator = ObjectAnimator.ofFloat(mTitleUrlContainer, TRANSLATION_X, securityIconButtonWidth); titleUrlTranslateAnimator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); titleUrlTranslateAnimator.setDuration(CUSTOM_TAB_TOOLBAR_SLIDE_DURATION_MS); Animator securityButtonAlphaAnimator = ObjectAnimator.ofFloat(mSecurityButton, ALPHA, 1); securityButtonAlphaAnimator.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE); securityButtonAlphaAnimator.setDuration(CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS); securityButtonAlphaAnimator.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mSecurityButton.setVisibility(VISIBLE); mTitleUrlContainer.setTranslationX(0); } }); mSecurityButtonShowAnimator.playSequentially( titleUrlTranslateAnimator, securityButtonAlphaAnimator); }
@Override public boolean animateChange( RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, ItemHolderInfo preInfo, ItemHolderInfo postInfo) { if (preInfo instanceof DesignerNewsItemHolderInfo && ((DesignerNewsItemHolderInfo) preInfo).animateAddToPocket) { final FeedAdapter.DesignerNewsStoryHolder holder = (FeedAdapter.DesignerNewsStoryHolder) newHolder; // setup for anim holder.itemView.setHasTransientState(true); ((ViewGroup) holder.pocket.getParent().getParent()).setClipChildren(false); final int initialLeft = holder.pocket.getLeft(); final int initialTop = holder.pocket.getTop(); final int translatedLeft = (holder.itemView.getWidth() - holder.pocket.getWidth()) / 2; final int translatedTop = initialTop - ((holder.itemView.getHeight() - holder.pocket.getHeight()) / 2); final ArcMotion arc = new ArcMotion(); // animate the title & pocket icon up, scale the pocket icon up Animator titleMoveFadeOut = ObjectAnimator.ofPropertyValuesHolder( holder.title, PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -(holder.itemView.getHeight() / 5)), PropertyValuesHolder.ofFloat(View.ALPHA, 0.54f)); Animator pocketMoveUp = ObjectAnimator.ofFloat( holder.pocket, View.TRANSLATION_X, View.TRANSLATION_Y, arc.getPath(initialLeft, initialTop, translatedLeft, translatedTop)); Animator pocketScaleUp = ObjectAnimator.ofPropertyValuesHolder( holder.pocket, PropertyValuesHolder.ofFloat(View.SCALE_X, 3f), PropertyValuesHolder.ofFloat(View.SCALE_Y, 3f)); ObjectAnimator pocketFadeUp = ObjectAnimator.ofInt(holder.pocket, ViewUtils.IMAGE_ALPHA, 255); AnimatorSet up = new AnimatorSet(); up.playTogether(titleMoveFadeOut, pocketMoveUp, pocketScaleUp, pocketFadeUp); up.setDuration(300); up.setInterpolator( AnimationUtils.loadInterpolator( holder.itemView.getContext(), android.R.interpolator.fast_out_slow_in)); // animate everything back into place Animator titleMoveFadeIn = ObjectAnimator.ofPropertyValuesHolder( holder.title, PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f), PropertyValuesHolder.ofFloat(View.ALPHA, 1f)); Animator pocketMoveDown = ObjectAnimator.ofFloat( holder.pocket, View.TRANSLATION_X, View.TRANSLATION_Y, arc.getPath(translatedLeft, translatedTop, 0, 0)); Animator pvhPocketScaleDown = ObjectAnimator.ofPropertyValuesHolder( holder.pocket, PropertyValuesHolder.ofFloat(View.SCALE_X, 1f), PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f)); ObjectAnimator pocketFadeDown = ObjectAnimator.ofInt(holder.pocket, ViewUtils.IMAGE_ALPHA, 138); AnimatorSet down = new AnimatorSet(); down.playTogether(titleMoveFadeIn, pocketMoveDown, pvhPocketScaleDown, pocketFadeDown); down.setDuration(300); down.setInterpolator( AnimationUtils.loadInterpolator( holder.itemView.getContext(), android.R.interpolator.fast_out_slow_in)); down.setStartDelay(500); // play it AnimatorSet upDown = new AnimatorSet(); upDown.playSequentially(up, down); // clean up upDown.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAnimationStarted(holder); } @Override public void onAnimationEnd(Animator animation) { ((ViewGroup) holder.pocket.getParent().getParent()).setClipChildren(true); holder.itemView.setHasTransientState(false); dispatchAnimationFinished(holder); } }); upDown.start(); } return super.animateChange(oldHolder, newHolder, preInfo, postInfo); }
@Override public Animator createAnimator( ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (startValues == null || endValues == null || !(startValues.view instanceof TextView) || !(endValues.view instanceof TextView)) { return null; } final TextView view = (TextView) endValues.view; Map<String, Object> startVals = startValues.values; Map<String, Object> endVals = endValues.values; final CharSequence startText = startVals.get(PROPNAME_TEXT) != null ? (CharSequence) startVals.get(PROPNAME_TEXT) : ""; final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ? (CharSequence) endVals.get(PROPNAME_TEXT) : ""; final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd; if (view instanceof EditText) { startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1; startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart; endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1; endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart; } else { startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1; } if (!startText.equals(endText)) { final int startColor; final int endColor; if (mChangeBehavior != CHANGE_BEHAVIOR_IN) { view.setText(startText); if (view instanceof EditText) { setSelection(((EditText) view), startSelectionStart, startSelectionEnd); } } Animator anim; if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) { startColor = endColor = 0; anim = ValueAnimator.ofFloat(0, 1); anim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (startText.equals(view.getText())) { // Only set if it hasn't been changed since anim started view.setText(endText); if (view instanceof EditText) { setSelection(((EditText) view), endSelectionStart, endSelectionEnd); } } } }); } else { startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR); endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR); // Fade out start text ValueAnimator outAnim = null, inAnim = null; if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_OUT) { outAnim = ValueAnimator.ofInt(255, 0); outAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int currAlpha = (Integer) animation.getAnimatedValue(); view.setTextColor( currAlpha << 24 | startColor & 0xff0000 | startColor & 0xff00 | startColor & 0xff); } }); outAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (startText.equals(view.getText())) { // Only set if it hasn't been changed since anim started view.setText(endText); if (view instanceof EditText) { setSelection(((EditText) view), endSelectionStart, endSelectionEnd); } } // restore opaque alpha and correct end color view.setTextColor(endColor); } }); } if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_IN) { inAnim = ValueAnimator.ofInt(0, 255); inAnim.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int currAlpha = (Integer) animation.getAnimatedValue(); view.setTextColor( currAlpha << 24 | Color.red(endColor) << 16 | Color.green(endColor) << 8 | Color.red(endColor)); } }); inAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationCancel(Animator animation) { // restore opaque alpha and correct end color view.setTextColor(endColor); } }); } if (outAnim != null && inAnim != null) { anim = new AnimatorSet(); ((AnimatorSet) anim).playSequentially(outAnim, inAnim); } else if (outAnim != null) { anim = outAnim; } else { // Must be an in-only animation anim = inAnim; } } TransitionListener transitionListener = new TransitionListenerAdapter() { int mPausedColor = 0; @Override public void onTransitionPause(Transition transition) { if (mChangeBehavior != CHANGE_BEHAVIOR_IN) { view.setText(endText); if (view instanceof EditText) { setSelection(((EditText) view), endSelectionStart, endSelectionEnd); } } if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) { mPausedColor = view.getCurrentTextColor(); view.setTextColor(endColor); } } @Override public void onTransitionResume(Transition transition) { if (mChangeBehavior != CHANGE_BEHAVIOR_IN) { view.setText(startText); if (view instanceof EditText) { setSelection(((EditText) view), startSelectionStart, startSelectionEnd); } } if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) { view.setTextColor(mPausedColor); } } }; addListener(transitionListener); if (DBG) { Log.d(LOG_TAG, "createAnimator returning " + anim); } return anim; } return null; }
private void setupAnimations() { mOvershootInterpolator = new OvershootInterpolator(mOvershootValue); mArrowLineToDot = ValueAnimator.ofFloat(0, mRadius / 4); mArrowLineToDot.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mArrowLineToDotAnimatedValue = (float) valueAnimator.getAnimatedValue(); invalidate(); } }); mArrowLineToDot.setDuration(200); mArrowLineToDot.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mState = State.ANIMATING_LINE_TO_DOT; if (mOnProgressUpdateListener != null) { mOnProgressUpdateListener.onAnimationStarted(); } } @Override public void onAnimationEnd(Animator animator) {} @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); mArrowLineToDot.setInterpolator(new AccelerateInterpolator()); mArrowLineToHorizontalLine = ValueAnimator.ofFloat(0, mRadius / 2); mArrowLineToHorizontalLine.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mArrowLineToHorizontalLineAnimatedValue = (float) valueAnimator.getAnimatedValue(); invalidate(); } }); mArrowLineToHorizontalLine.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) {} @Override public void onAnimationEnd(Animator animator) {} @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); mArrowLineToHorizontalLine.setDuration(600); mArrowLineToHorizontalLine.setStartDelay(400); mArrowLineToHorizontalLine.setInterpolator(mOvershootInterpolator); mDotToProgressAnimation = ValueAnimator.ofFloat(0, mRadius); mDotToProgressAnimation.setDuration(600); mDotToProgressAnimation.setStartDelay(600); mDotToProgressAnimation.setInterpolator(mOvershootInterpolator); mDotToProgressAnimation.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mDotToProgressAnimatedValue = (float) valueAnimator.getAnimatedValue(); invalidate(); } }); mDotToProgressAnimation.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) {} @Override public void onAnimationEnd(Animator animator) { mProgressAnimationSet.start(); mState = State.ANIMATING_PROGRESS; } @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); mArrowToLineAnimatorSet = new AnimatorSet(); mArrowToLineAnimatorSet.playTogether( mArrowLineToDot, mArrowLineToHorizontalLine, mDotToProgressAnimation); mProgressAnimation = ValueAnimator.ofFloat(0, 360f); mProgressAnimation.setStartDelay(500); mProgressAnimation.setInterpolator(new LinearInterpolator()); mProgressAnimation.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mCurrentGlobalProgressValue = (float) valueAnimator.getAnimatedValue(); if (mOnProgressUpdateListener != null) { mOnProgressUpdateListener.onProgressUpdate(mCurrentGlobalProgressValue); } invalidate(); } }); mProgressAnimation.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mDotToProgressAnimatedValue = 0; } @Override public void onAnimationEnd(Animator animator) {} @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); mProgressAnimation.setDuration(mProgressDuration); mExpandAnimation = ValueAnimator.ofFloat(0, mRadius / 6); mExpandAnimation.setDuration(300); mExpandAnimation.setInterpolator(new DecelerateInterpolator()); mExpandAnimation.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mExpandCollapseValue = (float) animation.getAnimatedValue(); invalidate(); } }); mCollapseAnimation = ValueAnimator.ofFloat(mRadius / 6, mStrokeWidth / 2); mCollapseAnimation.setDuration(300); mCollapseAnimation.setStartDelay(300); mCollapseAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); mCollapseAnimation.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mExpandCollapseValue = (float) animation.getAnimatedValue(); invalidate(); } }); mProgressAnimationSet = new AnimatorSet(); mProgressAnimationSet.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {} @Override public void onAnimationEnd(Animator animation) { if (mResultState == State.ANIMATING_ERROR) { mErrorAnimation.start(); } else if (mResultState == State.ANIMATING_SUCCESS) { mSuccessAnimation.start(); } } @Override public void onAnimationCancel(Animator animation) {} @Override public void onAnimationRepeat(Animator animation) {} }); mProgressAnimationSet.playSequentially( mExpandAnimation, mProgressAnimation, mCollapseAnimation); mErrorAnimation = ValueAnimator.ofFloat(0, mRadius / 4); mErrorAnimation.setDuration(600); mErrorAnimation.setStartDelay(500); mErrorAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); mErrorAnimation.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mErrorValue = (float) valueAnimator.getAnimatedValue(); invalidate(); } }); mErrorAnimation.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mState = State.ANIMATING_ERROR; if (mOnProgressUpdateListener != null) { mOnProgressUpdateListener.onAnimationError(); } } @Override public void onAnimationEnd(Animator animator) { postDelayed( new Runnable() { @Override public void run() { if (mOnProgressUpdateListener != null) { mOnProgressUpdateListener.onAnimationEnded(); } mState = State.IDLE; resetValues(); invalidate(); } }, mResultDuration); } @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); mSuccessAnimation = ValueAnimator.ofFloat(0, mRadius / 4); mSuccessAnimation.setDuration(600); mSuccessAnimation.setStartDelay(500); mSuccessAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); mSuccessAnimation.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mSuccessValue = (float) valueAnimator.getAnimatedValue(); invalidate(); } }); mSuccessAnimation.addListener( new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mState = State.ANIMATING_SUCCESS; if (mOnProgressUpdateListener != null) { mOnProgressUpdateListener.onAnimationSuccess(); } } @Override public void onAnimationEnd(Animator animator) { postDelayed( new Runnable() { @Override public void run() { if (mOnProgressUpdateListener != null) { mOnProgressUpdateListener.onAnimationEnded(); } mState = State.IDLE; resetValues(); invalidate(); } }, mResultDuration); } @Override public void onAnimationCancel(Animator animator) {} @Override public void onAnimationRepeat(Animator animator) {} }); }
public SendUi(Context context, Callback callback) { mContext = context; mCallback = callback; mDisplayMetrics = new DisplayMetrics(); mDisplayMatrix = new Matrix(); mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); mDisplay = mWindowManager.getDefaultDisplay(); mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mScreenshotLayout = mLayoutInflater.inflate(R.layout.screenshot, null); mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.screenshot); mScreenshotLayout.setFocusable(true); mTextHint = (TextView) mScreenshotLayout.findViewById(R.id.calltoaction); mTextureView = (TextureView) mScreenshotLayout.findViewById(R.id.fireflies); mTextureView.setSurfaceTextureListener(this); // We're only allowed to use hardware acceleration if // isHighEndGfx() returns true - otherwise, we're too limited // on resources to do it. mHardwareAccelerated = ActivityManager.isHighEndGfx(mDisplay); int hwAccelerationFlags = mHardwareAccelerated ? WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED : 0; mWindowLayoutParams = new WindowManager.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0, 0, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_FULLSCREEN | hwAccelerationFlags | WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.OPAQUE); mWindowLayoutParams.token = new Binder(); PropertyValuesHolder preX = PropertyValuesHolder.ofFloat("scaleX", PRE_SCREENSHOT_SCALE); PropertyValuesHolder preY = PropertyValuesHolder.ofFloat("scaleY", PRE_SCREENSHOT_SCALE); mPreAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, preX, preY); mPreAnimator.setInterpolator(new DecelerateInterpolator()); mPreAnimator.setDuration(PRE_DURATION_MS); mPreAnimator.addListener(this); PropertyValuesHolder postX = PropertyValuesHolder.ofFloat("scaleX", CLONE_SCREENSHOT_SCALE); PropertyValuesHolder postY = PropertyValuesHolder.ofFloat("scaleY", CLONE_SCREENSHOT_SCALE); PropertyValuesHolder alphaDown = PropertyValuesHolder.ofFloat("alpha", new float[] {1.0f, 0.0f}); mSlowSendAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, postX, postY); mSlowSendAnimator.setInterpolator(new DecelerateInterpolator()); mSlowSendAnimator.setDuration(SLOW_SEND_DURATION_MS); mFastCloneAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, postX, postY, alphaDown); mFastCloneAnimator.setInterpolator(new DecelerateInterpolator()); mFastCloneAnimator.setDuration(FAST_CLONE_DURATION_MS); mFastCloneAnimator.addListener(this); PropertyValuesHolder scaleUpX = PropertyValuesHolder.ofFloat("scaleX", SCALE_UP_SCREENSHOT_SCALE); PropertyValuesHolder scaleUpY = PropertyValuesHolder.ofFloat("scaleY", SCALE_UP_SCREENSHOT_SCALE); mScaleUpAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, scaleUpX, scaleUpY); mScaleUpAnimator.setInterpolator(new DecelerateInterpolator()); mScaleUpAnimator.setDuration(SCALE_UP_DURATION_MS); mScaleUpAnimator.addListener(this); PropertyValuesHolder fadeIn = PropertyValuesHolder.ofFloat("alpha", 1.0f); mFadeInAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, fadeIn); mFadeInAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); mFadeInAnimator.setDuration(FADE_IN_DURATION_MS); mFadeInAnimator.setStartDelay(FADE_IN_START_DELAY_MS); mFadeInAnimator.addListener(this); PropertyValuesHolder alphaUp = PropertyValuesHolder.ofFloat("alpha", TEXT_HINT_ALPHA_RANGE); mHintAnimator = ObjectAnimator.ofPropertyValuesHolder(mTextHint, alphaUp); mHintAnimator.setInterpolator(null); mHintAnimator.setDuration(TEXT_HINT_ALPHA_DURATION_MS); mHintAnimator.setStartDelay(TEXT_HINT_ALPHA_START_DELAY_MS); mSuccessAnimatorSet = new AnimatorSet(); mSuccessAnimatorSet.playSequentially(mFastCloneAnimator, mFadeInAnimator); mAttached = false; }
private void doMaterialAnimation() { // From circle to small square ValueAnimator toSmallSquare = ObjectAnimator.ofFloat( 1, 0); // A set of values that the animation will animate between over time. toSmallSquare.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // Redraw the cardview on each update transformMaterial( mOrigSize, mTargetSize1, mOrigSize, mTargetSize1, mOrigRadius, mTargetRadius1, animation); } }); // From small square to big circle ValueAnimator toBigCircle = ObjectAnimator.ofFloat( 1, 0); // A set of values that the animation will animate between over time. toBigCircle.setStartDelay(ANIMATION_INTERVAL_MS); toBigCircle.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // Redraw the cardview on each update transformMaterial( mTargetSize1, mTargetSize2, mTargetSize1, mTargetSize2, mTargetRadius1, mTargetRadius2, animation); } }); // From big circle to small rectangle ValueAnimator toSmallRectangle = ObjectAnimator.ofFloat( 1, 0); // A set of values that the animation will animate between over time. toSmallRectangle.setStartDelay(ANIMATION_INTERVAL_MS); toSmallRectangle.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // Redraw the cardview on each update transformMaterial( mTargetSize2, mTargetSize1, mTargetSize2, mOrigSize, mTargetRadius2, mTargetRadius3, animation); } }); // From small rectangle to circle ValueAnimator toCircle = ObjectAnimator.ofFloat( 1, 0); // A set of values that the animation will animate between over time. toCircle.setStartDelay(ANIMATION_INTERVAL_MS); toCircle.addUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { // Redraw the cardview on each update transformMaterial( mTargetSize1, mOrigSize, mOrigSize, mOrigSize, mTargetRadius3, mOrigRadius, animation); } }); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playSequentially(toSmallSquare, toBigCircle, toSmallRectangle, toCircle); animatorSet.setDuration(ANIMATION_DURATION_MS); animatorSet.setInterpolator( new PathInterpolator(0.75f, 0, 0.25f, 1f)); // see http://cubic-bezier.com/#.75,0,.25,1 animatorSet.start(); }