162f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui/*
262f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * Copyright (C) 2014 The Android Open Source Project
362f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui *
462f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * Licensed under the Apache License, Version 2.0 (the "License");
562f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * you may not use this file except in compliance with the License.
662f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * You may obtain a copy of the License at
762f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui *
862f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui *      http://www.apache.org/licenses/LICENSE-2.0
962f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui *
1062f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * Unless required by applicable law or agreed to in writing, software
1162f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * distributed under the License is distributed on an "AS IS" BASIS,
1262f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1362f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * See the License for the specific language governing permissions and
1462f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * limitations under the License.
1562f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui */
1662f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui
1762f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghuipackage android.view;
1862f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui
19c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reckimport android.animation.Animator;
20a3b35907de9a8cd5e9f8fdf1700974f9c39a3df6John Reckimport android.animation.Animator.AnimatorListener;
2162f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghuiimport android.animation.RevealAnimator;
2262f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui
2362f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui/**
2462f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui * Defines common utilities for working with View's animations.
2562f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui *
2662f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui */
271c2ebed64b361691343346595894cc5254292537ztenghuipublic final class ViewAnimationUtils {
2862f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui    private ViewAnimationUtils() {}
2962f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui    /**
304c902fa56d2dc0b0f50bb2255cb511ea7e970c6eChet Haase     * Returns an Animator which can animate a clipping circle.
31e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * <p>
3262f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui     * Any shadow cast by the View will respect the circular clip from this animator.
33e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * <p>
34e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * Only a single non-rectangular clip can be applied on a View at any time.
35e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * Views clipped by a circular reveal animation take priority over
36e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * {@link View#setClipToOutline(boolean) View Outline clipping}.
37e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * <p>
38291161ac3815fb853fd6af21055d60f57a869608John Reck     * Note that the animation returned here is a one-shot animation. It cannot
39a3b35907de9a8cd5e9f8fdf1700974f9c39a3df6John Reck     * be re-used, and once started it cannot be paused or resumed. It is also
40a3b35907de9a8cd5e9f8fdf1700974f9c39a3df6John Reck     * an asynchronous animation that automatically runs off of the UI thread.
41a3b35907de9a8cd5e9f8fdf1700974f9c39a3df6John Reck     * As a result {@link AnimatorListener#onAnimationEnd(Animator)}
42a3b35907de9a8cd5e9f8fdf1700974f9c39a3df6John Reck     * will occur after the animation has ended, but it may be delayed depending
43a3b35907de9a8cd5e9f8fdf1700974f9c39a3df6John Reck     * on thread responsiveness.
449b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * <p>
459b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * Note that if any start delay is set on the reveal animator, the start radius
469b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * will not be applied to the reveal circle until the start delay has passed.
479b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * If it's desired to set a start radius on the reveal circle during the start
489b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * delay, one workaround could be adding an animator with the same start and
499b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * end radius. For example:
509b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * <pre><code>
519b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * public static Animator createRevealWithDelay(View view, int centerX, int centerY, float startRadius, float endRadius) {
529b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     *     Animator delayAnimator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, startRadius);
539b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     *     delayAnimator.setDuration(delayTimeMS);
549b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     *     Animator revealAnimator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius);
559b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     *     AnimatorSet set = new AnimatorSet();
569b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     *     set.playSequentially(delayAnimator, revealAnimator);
579b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     *     return set;
589b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * }
599b3be58403e030b43201a2d966b721f9ab8a805cTeng-Hui Zhu     * </code></pre>
60291161ac3815fb853fd6af21055d60f57a869608John Reck     *
6162f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui     * @param view The View will be clipped to the animating circle.
6294882946112e5a5d384fca5f39b2bdf7584cba6fGeorge Mount     * @param centerX The x coordinate of the center of the animating circle, relative to
6394882946112e5a5d384fca5f39b2bdf7584cba6fGeorge Mount     *                <code>view</code>.
6494882946112e5a5d384fca5f39b2bdf7584cba6fGeorge Mount     * @param centerY The y coordinate of the center of the animating circle, relative to
6594882946112e5a5d384fca5f39b2bdf7584cba6fGeorge Mount     *                <code>view</code>.
6662f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui     * @param startRadius The starting radius of the animating circle.
6762f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui     * @param endRadius The ending radius of the animating circle.
6862f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui     */
69e83cbd451868a734bfac07ccd680d5617080b579Chris Craik    public static Animator createCircularReveal(View view,
7062f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui            int centerX,  int centerY, float startRadius, float endRadius) {
71af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik        return new RevealAnimator(view, centerX, centerY, startRadius, endRadius);
7262f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui    }
7362f30e0bb14b38c54d5fed4771141dc5b3fb6f4bztenghui}
74