List of usage examples for android.animation Animator addListener
public void addListener(AnimatorListener listener)
From source file:bottombar.BottomBar.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void backgroundCircularRevealAnimation(View clickedView, final int newColor) { int centerX = (int) (ViewCompat.getX(clickedView) + (clickedView.getMeasuredWidth() / 2)); int yOffset = isTabletMode ? (int) ViewCompat.getY(clickedView) : 0; int centerY = yOffset + clickedView.getMeasuredHeight() / 2; int startRadius = 0; int finalRadius = isTabletMode ? outerContainer.getHeight() : outerContainer.getWidth(); Animator animator = ViewAnimationUtils.createCircularReveal(backgroundOverlay, centerX, centerY, startRadius, finalRadius);//ww w. j a va 2s. c o m if (isTabletMode) { animator.setDuration(500); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { onEnd(); } @Override public void onAnimationCancel(Animator animation) { onEnd(); } private void onEnd() { outerContainer.setBackgroundColor(newColor); backgroundOverlay.setVisibility(View.INVISIBLE); ViewCompat.setAlpha(backgroundOverlay, 1); } }); animator.start(); }
From source file:br.liveo.searchliveo.SearchCardLiveo.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showAnimation() { try {// w ww. j a va 2s .com if (getStatusBarShowColor() != -1) { mContext.getWindow().setStatusBarColor(getStatusBarShowColor()); } else { mContext.getWindow() .setStatusBarColor(ContextCompat.getColor(mContext, R.color.search_liveo_primary_dark)); } final Animator animator = ViewAnimationUtils.createCircularReveal(mCardSearch, mCardSearch.getWidth() - (int) dpToPixel(24, this.mContext), (int) dpToPixel(23, this.mContext), 0, (float) Math.hypot(mCardSearch.getWidth(), mCardSearch.getHeight())); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animator.setDuration(300); animator.start(); } catch (Exception e) { e.getStackTrace(); mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }); } mCardSearch.setVisibility(View.VISIBLE); }
From source file:br.liveo.searchliveo.SearchCardLiveo.java
private SearchCardLiveo hideAnimation() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (getStatusBarHideColor() != -1) { mContext.getWindow().setStatusBarColor(getStatusBarHideColor()); } else {/*from w ww . ja va2 s . c om*/ mContext.getWindow().setStatusBarColor(getColorPrimaryDark()); } final Animator animatorHide = ViewAnimationUtils.createCircularReveal(mCardSearch, mCardSearch.getWidth() - (int) dpToPixel(24, mContext), (int) dpToPixel(23, mContext), (float) Math.hypot(mCardSearch.getWidth(), mCardSearch.getHeight()), 0); animatorHide.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0); } }); } @Override public void onAnimationEnd(Animator animation) { mCardSearch.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorHide.setDuration(200); animatorHide.start(); } else { mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0); } }); Animation mFadeOut = AnimationUtils.loadAnimation(mContext.getApplicationContext(), android.R.anim.fade_out); mCardSearch.setAnimation(mFadeOut); mCardSearch.setVisibility(View.INVISIBLE); } mEdtSearch.setText(""); mCardSearch.setEnabled(false); return this; }
From source file:br.liveo.searchliveo.SearchLiveo.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showAnimation() { try {/*from w w w. jav a 2s . co m*/ if (getStatusBarShowColor() != -1) { mContext.getWindow().setStatusBarColor(getStatusBarShowColor()); } else { mContext.getWindow() .setStatusBarColor(ContextCompat.getColor(mContext, R.color.search_liveo_primary_dark)); } final Animator animator = ViewAnimationUtils.createCircularReveal(mViewSearch, mViewSearch.getWidth() - (int) dpToPixel(24, this.mContext), (int) dpToPixel(23, this.mContext), 0, (float) Math.hypot(mViewSearch.getWidth(), mViewSearch.getHeight())); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animator.setDuration(300); animator.start(); } catch (Exception e) { e.getStackTrace(); mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } }); } mViewSearch.setVisibility(View.VISIBLE); }
From source file:br.liveo.searchliveo.SearchLiveo.java
private SearchLiveo hideAnimation() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (getStatusBarHideColor() != -1) { mContext.getWindow().setStatusBarColor(getStatusBarHideColor()); } else {/*from w w w . j ava 2 s . com*/ mContext.getWindow().setStatusBarColor(getColorPrimaryDark()); } final Animator animatorHide = ViewAnimationUtils.createCircularReveal(mViewSearch, mViewSearch.getWidth() - (int) dpToPixel(24, mContext), (int) dpToPixel(23, mContext), (float) Math.hypot(mViewSearch.getWidth(), mViewSearch.getHeight()), 0); animatorHide.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0); } }); } @Override public void onAnimationEnd(Animator animation) { mViewSearch.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorHide.setDuration(200); animatorHide.start(); } else { mContext.runOnUiThread(new Runnable() { @Override public void run() { ((InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mRecyclerView.getWindowToken(), 0); } }); Animation mFadeOut = AnimationUtils.loadAnimation(mContext.getApplicationContext(), android.R.anim.fade_out); mViewSearch.setAnimation(mFadeOut); mViewSearch.setVisibility(View.INVISIBLE); } mEdtSearch.setText(""); mViewSearch.setEnabled(false); return this; }
From source file:io.plaidapp.ui.DribbbleShot.java
private void expandImageAndFinish() { if (imageView.getOffset() != 0f) { Animator expandImage = ObjectAnimator.ofFloat(imageView, ParallaxScrimageView.OFFSET, 0f); expandImage.setDuration(80);//w w w . ja v a2 s. c o m expandImage.setInterpolator( AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in)); expandImage.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { finishAfterTransition(); } }); expandImage.start(); } else { finishAfterTransition(); } }
From source file:de.dreier.mytargets.utils.transitions.FabTransform.java
@Override public Animator createAnimator(@NonNull final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) { return null; }/*from ww w . ja v a2s .c o m*/ final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Rect fabBounds = fromFab ? startBounds : endBounds; final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); } final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) { fabColor.setAlpha(0); } view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) { fabIcon.setAlpha(0); } view.getOverlay().add(fabIcon); // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(new FastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(new LinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { final int left = (view.getWidth() - fabBounds.width()) / 2; final int top = (view.getHeight() - fabBounds.height()) / 2; outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height()); view.setClipToOutline(true); } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Work around issue with elevation shadows. At the end of the return transition the shared // element's shadow is drawn twice (by each activity) which is jarring. This workaround // still causes the shadow to snap, but it's better than seeing it double drawn. Animator elevation = null; if (!fromFab) { elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation()); elevation.setDuration(duration); elevation.setInterpolator(fastOutSlowInInterpolator); } // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (elevation != null) { transition.play(elevation); } if (fromFab) { transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); } }); } return new NoPauseAnimator(transition); }
From source file:com.github.takahirom.plaidanimation.transition.FabTransform.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) return null; final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Rect fabBounds = fromFab ? startBounds : endBounds; final Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); }//from w w w. j a v a 2 s . c o m final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) fabColor.setAlpha(0); view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) fabIcon.setAlpha(0); view.getOverlay().add(fabIcon); // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(new FastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(new LinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { final int left = (view.getWidth() - fabBounds.width()) / 2; final int top = (view.getHeight() - fabBounds.height()) / 2; outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height()); view.setClipToOutline(true); } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Work around issue with elevation shadows. At the end of the return transition the shared // element's shadow is drawn twice (by each activity) which is jarring. This workaround // still causes the shadow to snap, but it's better than seeing it double drawn. Animator elevation = null; if (!fromFab) { elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation()); elevation.setDuration(duration); elevation.setInterpolator(fastOutSlowInInterpolator); } // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (elevation != null) transition.play(elevation); if (fromFab) { transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); } }); } return new AnimUtils.NoPauseAnimator(transition); }
From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) return null; final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator(); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); }/*from w w w. j a va 2 s. c o m*/ final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) fabColor.setAlpha(0); view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) fabIcon.setAlpha(0); view.getOverlay().add(fabIcon); // Since the view that's being transition to always seems to be on the top (z-order), we have // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out. // There has to be another way to do this, right? Drawable dialogView = null; if (!fromFab) { startValues.view.setDrawingCacheEnabled(true); startValues.view.buildDrawingCache(); Bitmap viewBitmap = startValues.view.getDrawingCache(); dialogView = new BitmapDrawable(view.getResources(), viewBitmap); dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); view.getOverlay().add(dialogView); } // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator()); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator()); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider(); view.setOutlineProvider(new ViewOutlineProvider() { boolean hasRun = false; @Override public void getOutline(final View view, Outline outline) { final int left = (view.getWidth() - endBounds.width()) / 2; final int top = (view.getHeight() - endBounds.height()) / 2; outline.setOval(left, top, left + endBounds.width(), top + endBounds.height()); if (!hasRun) { hasRun = true; view.setClipToOutline(true); // We have to remove this as soon as it's laid out so we can get the shadow back view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { if (view.getWidth() == endBounds.width() && view.getHeight() == endBounds.height()) { view.setOutlineProvider(fabOutlineProvider); view.setClipToOutline(false); view.getViewTreeObserver().removeOnPreDrawListener(this); return true; } return true; } }); } } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (dialogView != null) { final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0) .setDuration(twoThirdsDuration); dialogViewFade.setInterpolator(fastOutSlowInInterpolator); transition.playTogether(dialogViewFade); } transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); if (!fromFab) { view.setTranslationX(0); view.setTranslationY(0); view.setTranslationZ(0); view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom); } } }); return new AnimUtils.NoPauseAnimator(transition); }
From source file:com.android.calculator2.Calculator.java
private void reveal(View sourceView, int colorRes, AnimatorListener listener) { final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay(); final Rect displayRect = new Rect(); mDisplayView.getGlobalVisibleRect(displayRect); // Make reveal cover the display and status bar. final View revealView = new View(this); revealView.setBottom(displayRect.bottom); revealView.setLeft(displayRect.left); revealView.setRight(displayRect.right); revealView.setBackgroundColor(getResources().getColor(colorRes)); groupOverlay.add(revealView);//from ww w . j av a 2 s . c om final int[] clearLocation = new int[2]; sourceView.getLocationInWindow(clearLocation); clearLocation[0] += sourceView.getWidth() / 2; clearLocation[1] += sourceView.getHeight() / 2; final int revealCenterX = clearLocation[0] - revealView.getLeft(); final int revealCenterY = clearLocation[1] - revealView.getTop(); final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2); final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2); final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2); final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2)); final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX, revealCenterY, 0.0f, revealRadius); revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); revealAnimator.addListener(listener); final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(revealAnimator).before(alphaAnimator); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { groupOverlay.remove(revealView); mCurrentAnimator = null; } }); mCurrentAnimator = animatorSet; animatorSet.start(); }