Java Code Examples for android.view.ViewAnimationUtils#createCircularReveal()

The following examples show how to use android.view.ViewAnimationUtils#createCircularReveal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FabTransformationBehavior.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Adds post radial expansion animator. */
private void createPostFillRadialExpansion(
    View child,
    long delay,
    long duration,
    long totalDuration,
    int revealCenterX,
    int revealCenterY,
    float toRadius,
    @NonNull List<Animator> animations) {
  if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
    // Circular reveal in L+ doesn't stick around.
    if (delay + duration < totalDuration) {
      Animator animator =
          ViewAnimationUtils.createCircularReveal(
              child, revealCenterX, revealCenterY, toRadius, toRadius);
      animator.setStartDelay(delay + duration);
      animator.setDuration(totalDuration - (delay + duration));
      animations.add(animator);
    }
  }
}
 
Example 2
Source File: Utils.java    From KA27 with Apache License 2.0 6 votes vote down vote up
public static void circleAnimate(final View view, int cx, int cy) {
    if (view == null) return;
    try {
        view.setVisibility(View.INVISIBLE);

        int finalRadius = Math.max(view.getWidth(), view.getHeight());
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
        anim.setDuration(500);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                view.setVisibility(View.VISIBLE);
            }
        });
        anim.start();
    } catch (IllegalStateException e) {
        view.setVisibility(View.VISIBLE);
    }
}
 
Example 3
Source File: NeighborsFragment.java    From android-wallet-app with GNU General Public License v3.0 6 votes vote down vote up
private void showRevealEditText(FrameLayout view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int cx = view.getRight() - 30;
        int cy = view.getBottom() - 60;
        int finalRadius = Math.max(view.getWidth(), view.getHeight());

        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
        view.setVisibility(View.VISIBLE);
        isEditTextVisible = true;
        anim.start();
    } else {
        view.setVisibility(View.VISIBLE);
        isEditTextVisible = true;
    }

}
 
Example 4
Source File: AnimationUtils.java    From adamant-android with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void startCircularRevealExitAnimation(Context context, final View view, RevealAnimationSetting revealSettings, int startColor, int endColor, final AnimationFinishedListener listener) {
    if (isAnimationEnabled() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int cx = revealSettings.getCenterX();
        int cy = revealSettings.getCenterY();
        int width = revealSettings.getWidth();
        int height = revealSettings.getHeight();

        float initRadius = (float) Math.sqrt(width * width + height * height);
        Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initRadius, 0);
        anim.setDuration(getMediumDuration(context));
        anim.setInterpolator(new FastOutSlowInInterpolator());
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                //Important: This will prevent the view's flashing (visible between the finished animation and the Fragment remove)
                view.setVisibility(View.GONE);
                listener.onAnimationFinished();
            }
        });
        anim.start();
        startBackgroundColorAnimation(view, startColor, endColor, getMediumDuration(context));
    } else {
        listener.onAnimationFinished();
    }
}
 
Example 5
Source File: Utils.java    From AndroidBlueprints with Apache License 2.0 6 votes vote down vote up
/**
 * Create the reveal effect animation
 *
 * @param view the View to reveal
 * @param cx   coordinate X
 * @param cy   coordinate Y
 */
@TargetApi(VERSION_CODES.LOLLIPOP)
public static void reveal(final View view, int cx, int cy) {
    if (!hasLollipop()) {
        view.setVisibility(View.VISIBLE);
        return;
    }

    //Get the final radius for the clipping circle
    int finalRadius = Math.max(view.getWidth(), view.getHeight());

    //Create the animator for this view (the start radius is zero)
    Animator animator =
            ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);

    //Make the view visible and start the animation
    view.setVisibility(View.VISIBLE);
    animator.start();
}
 
Example 6
Source File: BeatBoxFragment.java    From AndroidProgramming3e with Apache License 2.0 6 votes vote down vote up
private void performRevealAnimation(final View view, int screenCenterX, int screenCenterY) {
    int[] animatingViewCoords = new int[2];
    view.getLocationOnScreen(animatingViewCoords);
    int centerX = screenCenterX - animatingViewCoords[0];
    int centerY = screenCenterY - animatingViewCoords[1];

    Point size = new Point();
    getActivity().getWindowManager().getDefaultDisplay().getSize(size);
    int maxRadius = size.y;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        view.setVisibility(View.VISIBLE);
        Animator animator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, 0, maxRadius);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });
        animator.start();
    }
}
 
Example 7
Source File: SheetLayout.java    From HaiNaBaiChuan with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void contractLollipop(int x, int y, float startRadius, float endRadius) {

    Animator toolbarContractAnim = ViewAnimationUtils.createCircularReveal(
            mFabExpandLayout, x, y, startRadius, endRadius);
    toolbarContractAnim.setDuration(animationDuration);

    toolbarContractAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            contractAnimationEnd();
        }
    });

    toolbarContractAnim.start();
}
 
Example 8
Source File: AnimationUtils.java    From outlay with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void hideWithReveal(View view, Point point) {
    if(DeviceUtils.supportV5()) {
        // get the initial radius for the clipping circle
        int initialRadius = (int) Math.hypot(view.getWidth(), view.getHeight());

        // create the animation (the final radius is zero)
        Animator animator = ViewAnimationUtils.createCircularReveal(view, point.x, point.y, initialRadius, 0);

        // make the view invisible when the animation is done
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                view.setVisibility(View.INVISIBLE);
            }
        });

        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.setDuration(500);
        animator.start();
    } else {
        view.setVisibility(View.INVISIBLE);
    }
}
 
Example 9
Source File: UserDetailActivity.java    From timecat with Apache License 2.0 6 votes vote down vote up
private void animateAvatarSelectorShow(int duration) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        gridContainer.setVisibility(View.INVISIBLE);
        // get the center for the clipping circle
        int cx = (int) fab.getX() + fab.getWidth() / 2;
        int cy = 0;
        // get the final radius for the clipping circle
        int finalRadius = (int) Math.hypot(userAvatarBg.getWidth(), bg.getHeight() - userAvatarBg.getHeight());
        // create the animator for this view (the start radius is zero)
        Animator anim = ViewAnimationUtils.createCircularReveal(gridContainer, cx, cy, 0, finalRadius);
        anim.setInterpolator(new DecelerateInterpolator());
        // make the view visible and start the animation
        gridContainer.setVisibility(View.VISIBLE);
        anim.setDuration(duration).start();
        gridContainer.postDelayed(new Runnable() {
            @Override
            public void run() {
                scrollToColor(user.color());
            }
        }, duration);
    }
}
 
Example 10
Source File: CircularAnimUtil.java    From SeeWeather with Apache License 2.0 6 votes vote down vote up
/**
 * 向四周伸张,直到完成显示。
 */
@SuppressLint("NewApi")
public static void show(View myView, float startRadius, long durationMills) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        myView.setVisibility(View.VISIBLE);
        return;
    }

    int cx = (myView.getLeft() + myView.getRight()) / 2;
    int cy = (myView.getTop() + myView.getBottom()) / 2;

    int w = myView.getWidth();
    int h = myView.getHeight();

    // 勾股定理 & 进一法
    int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;

    Animator anim =
        ViewAnimationUtils.createCircularReveal(myView, cx, cy, startRadius, finalRadius);
    myView.setVisibility(View.VISIBLE);
    anim.setDuration(durationMills);
    anim.start();
}
 
Example 11
Source File: CircularAnimUtil.java    From SeeWeather with Apache License 2.0 5 votes vote down vote up
/**
 * 由满向中间收缩,直到隐藏。
 */
@SuppressLint("NewApi")
public static void hide(final View myView, float endRadius, long durationMills) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        myView.setVisibility(View.INVISIBLE);
        return;
    }

    int cx = (myView.getLeft() + myView.getRight()) / 2;
    int cy = (myView.getTop() + myView.getBottom()) / 2;
    int w = myView.getWidth();
    int h = myView.getHeight();

    // 勾股定理 & 进一法
    int initialRadius = (int) Math.sqrt(w * w + h * h) + 1;

    Animator anim =
        ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, endRadius);
    anim.setDuration(durationMills);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            myView.setVisibility(View.INVISIBLE);
        }
    });

    anim.start();
}
 
Example 12
Source File: CircularReveal.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
@Override
public Animator onAppear(ViewGroup sceneRoot, View view,
                         TransitionValues startValues,
                         TransitionValues endValues) {
    if (view == null || view.getHeight() == 0 || view.getWidth() == 0) return null;
    ensureCenterPoint(sceneRoot, view);
    return new AnimUtils.NoPauseAnimator(ViewAnimationUtils.createCircularReveal(
            view,
            center.x,
            center.y,
            startRadius,
            getFullyRevealedRadius(view)));
}
 
Example 13
Source File: CardPlayerFragment.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
public AnimatorSet createDefaultColorChangeAnimatorSet(int newColor) {
    Animator backgroundAnimator;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int topMargin = fragment.getResources().getDimensionPixelSize(R.dimen.status_bar_padding);
        //noinspection ConstantConditions
        int x = (int) (fragment.playbackControlsFragment.playPauseFab.getX() + fragment.playbackControlsFragment.playPauseFab.getWidth() / 2 + fragment.playbackControlsFragment.getView().getX());
        int y = (int) (topMargin + fragment.playbackControlsFragment.playPauseFab.getY() + fragment.playbackControlsFragment.playPauseFab.getHeight() / 2 + fragment.playbackControlsFragment.getView().getY());
        float startRadius = Math.max(fragment.playbackControlsFragment.playPauseFab.getWidth() / 2, fragment.playbackControlsFragment.playPauseFab.getHeight() / 2);
        float endRadius = Math.max(fragment.colorBackground.getWidth(), fragment.colorBackground.getHeight());
        fragment.colorBackground.setBackgroundColor(newColor);
        backgroundAnimator = ViewAnimationUtils.createCircularReveal(fragment.colorBackground, x, y, startRadius, endRadius);
    } else {
        backgroundAnimator = ViewUtil.createBackgroundColorTransition(fragment.colorBackground, fragment.lastColor, newColor);
    }

    AnimatorSet animatorSet = new AnimatorSet();

    animatorSet.play(backgroundAnimator);

    if (!ATHUtil.isWindowBackgroundDark(fragment.getActivity())) {
        int adjustedLastColor = ColorUtil.isColorLight(fragment.lastColor) ? ColorUtil.darkenColor(fragment.lastColor) : fragment.lastColor;
        int adjustedNewColor = ColorUtil.isColorLight(newColor) ? ColorUtil.darkenColor(newColor) : newColor;
        Animator subHeaderAnimator = ViewUtil.createTextColorTransition(fragment.playerQueueSubHeader, adjustedLastColor, adjustedNewColor);
        animatorSet.play(subHeaderAnimator);
    }

    animatorSet.setDuration(ViewUtil.PHONOGRAPH_ANIM_TIME);
    return animatorSet;
}
 
Example 14
Source File: BaseActivity.java    From GracefulMovies with Apache License 2.0 5 votes vote down vote up
/**
 * 带水波动画的Activity跳转
 */
@SuppressLint("NewApi")
protected void navigateWithRippleCompat(final Activity activity, final Intent intent,
                                        final View triggerView, @ColorRes int color) {

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ActivityOptionsCompat option = ActivityOptionsCompat.makeClipRevealAnimation(triggerView, 0, 0,
                triggerView.getMeasuredWidth(), triggerView.getMeasuredHeight());
        ActivityCompat.startActivity(activity, intent, option.toBundle());

        return;
    }

    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth() / 2;
    final int cy = location[1] + triggerView.getHeight() / 2;
    final ImageView view = new ImageView(activity);
    view.setImageResource(color);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);
    int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    anim.setDuration(500);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);

            activity.startActivity(intent);
            activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            decorView.postDelayed(() -> decorView.removeView(view), 500);
        }
    });
    anim.start();
}
 
Example 15
Source File: HolyGraphActivity.java    From intra42 with Apache License 2.0 5 votes vote down vote up
public void animate(View action, View view) {

        view.bringToFront();
        view.setVisibility(View.VISIBLE);

        if (action == null)
            return;

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {

            if (!action.isAttachedToWindow() || !view.isAttachedToWindow())
                return;

            // finding X and Y co-ordinates
            int[] coordinateAction = {0, 0};
            int[] coordinateView = {0, 0};
            action.getLocationInWindow(coordinateAction);
            view.getLocationInWindow(coordinateView);
            int cx = (coordinateAction[0] + action.getWidth() / 2);
            int cy = (0 - coordinateView[1] + coordinateAction[1] + action.getHeight() / 2);

            // to find  radius when icon is tapped for showing layout
            int startRadius = 0;
            int endRadius = Math.max(view.getWidth() + cx, view.getHeight() + cy);

            // performing circular reveal when icon will be tapped
            Animator animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, startRadius, endRadius);
            animator.setInterpolator(new AccelerateDecelerateInterpolator());
            animator.setDuration(350);

            // to show the layout when icon is tapped
            animator.start();
        }
    }
 
Example 16
Source File: CardPlayerFragment.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
public AnimatorSet createDefaultColorChangeAnimatorSet(int newColor) {
    Animator backgroundAnimator;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        //noinspection ConstantConditions
        int x = (int) (fragment.playbackControlsFragment.playPauseFab.getX() + fragment.playbackControlsFragment.playPauseFab.getWidth() / 2 + fragment.playbackControlsFragment.getView().getX());
        int y = (int) (fragment.playbackControlsFragment.playPauseFab.getY() + fragment.playbackControlsFragment.playPauseFab.getHeight() / 2 + fragment.playbackControlsFragment.getView().getY() + fragment.playbackControlsFragment.progressSlider.getHeight());
        float startRadius = Math.max(fragment.playbackControlsFragment.playPauseFab.getWidth() / 2, fragment.playbackControlsFragment.playPauseFab.getHeight() / 2);
        float endRadius = Math.max(fragment.colorBackground.getWidth(), fragment.colorBackground.getHeight());
        fragment.colorBackground.setBackgroundColor(newColor);
        backgroundAnimator = ViewAnimationUtils.createCircularReveal(fragment.colorBackground, x, y, startRadius, endRadius);
    } else {
        backgroundAnimator = ViewUtil.createBackgroundColorTransition(fragment.colorBackground, fragment.lastColor, newColor);
    }

    AnimatorSet animatorSet = new AnimatorSet();

    animatorSet.play(backgroundAnimator);

    if (!ATHUtil.isWindowBackgroundDark(fragment.getActivity())) {
        int adjustedLastColor = ColorUtil.isColorLight(fragment.lastColor) ? ColorUtil.darkenColor(fragment.lastColor) : fragment.lastColor;
        int adjustedNewColor = ColorUtil.isColorLight(newColor) ? ColorUtil.darkenColor(newColor) : newColor;
        Animator subHeaderAnimator = ViewUtil.createTextColorTransition(fragment.playerQueueSubHeader, adjustedLastColor, adjustedNewColor);
        animatorSet.play(subHeaderAnimator);
    }

    animatorSet.setDuration(ViewUtil.MUSIC_ANIM_TIME);
    return animatorSet;
}
 
Example 17
Source File: FABRevealProvider.java    From Flubber with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private Animator getCloseReveal(final View view) {
    int cx = view.getWidth() / 2;
    int cy = view.getHeight() / 2;

    float radius = (float) Math.hypot(cx, cy);

    final Animator animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, radius, 0);

    return animator;
}
 
Example 18
Source File: CircularRevealChangeHandler.java    From AndroidStarterAlt with Apache License 2.0 5 votes vote down vote up
@Override
protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) {
    final float radius = (float) Math.hypot(mCx, mCy);
    Animator animator = null;
    if (isPush && to != null) {
        animator = ViewAnimationUtils.createCircularReveal(to, mCx, mCy, 0, radius);
    } else if (!isPush && from != null) {
        animator = ViewAnimationUtils.createCircularReveal(from, mCx, mCy, radius, 0);
    }
    return animator;
}
 
Example 19
Source File: Utils.java    From AndroidBlueprints with Apache License 2.0 5 votes vote down vote up
/**
 * Create the un-reveal effect animation
 *
 * @param view the View to hide
 * @param cx   coordinate X
 * @param cy   coordinate Y
 */
@TargetApi(VERSION_CODES.LOLLIPOP)
public static void unReveal(final View view, int cx, int cy) {
    if (!hasLollipop()) {
        view.setVisibility(View.GONE);
        return;
    }

    //Get the initial radius for the clipping circle
    int initialRadius = view.getWidth();

    //Create the animation (the final radius is zero)
    Animator animator =
            ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0);

    //Make the view invisible when the animation is done
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            view.setVisibility(View.GONE);
        }
    });

    //Start the animation
    animator.start();
}
 
Example 20
Source File: ViewUtils.java    From animation-samples with Apache License 2.0 3 votes vote down vote up
/**
 * Create a simple circular reveal from a given start view to it's target view.
 * This reveal will start from the start view's boundaries until it fills the target view.
 *
 * @param center The center x and y coordinates of the start circle.
 * @param width The initial width of the view's coordinates.
 * @param targetView The target view which will be displayed once the reveal is done.
 * @param interpolator The interpolator to use.
 * @return The created circular reveal.
 */
@NonNull
public static Animator createCircularReveal(@NonNull Point center, int width,
                                            @NonNull View targetView,
                                            @NonNull Interpolator interpolator) {
    final Animator circularReveal = ViewAnimationUtils.createCircularReveal(targetView,
            center.x, center.y, width, (float) Math.hypot(center.x, center.y));
    circularReveal.setInterpolator(interpolator);
    return circularReveal;
}