ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
John Reck | c01bd11 | 2014-07-18 16:22:09 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
John Reck | a3b3590 | 2014-11-14 13:33:24 -0800 | [diff] [blame] | 20 | import android.animation.Animator.AnimatorListener; |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 21 | import android.animation.RevealAnimator; |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Defines common utilities for working with View's animations. |
| 25 | * |
| 26 | */ |
ztenghui | 1c2ebed | 2014-06-12 13:35:38 -0700 | [diff] [blame] | 27 | public final class ViewAnimationUtils { |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 28 | private ViewAnimationUtils() {} |
| 29 | /** |
Chet Haase | 4c902fa | 2014-08-21 18:55:38 -0700 | [diff] [blame] | 30 | * Returns an Animator which can animate a clipping circle. |
Chris Craik | e83cbd4 | 2014-09-03 17:52:24 -0700 | [diff] [blame] | 31 | * <p> |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 32 | * Any shadow cast by the View will respect the circular clip from this animator. |
Chris Craik | e83cbd4 | 2014-09-03 17:52:24 -0700 | [diff] [blame] | 33 | * <p> |
| 34 | * Only a single non-rectangular clip can be applied on a View at any time. |
| 35 | * Views clipped by a circular reveal animation take priority over |
| 36 | * {@link View#setClipToOutline(boolean) View Outline clipping}. |
| 37 | * <p> |
John Reck | 291161a | 2014-07-22 07:31:09 -0700 | [diff] [blame] | 38 | * Note that the animation returned here is a one-shot animation. It cannot |
John Reck | a3b3590 | 2014-11-14 13:33:24 -0800 | [diff] [blame] | 39 | * be re-used, and once started it cannot be paused or resumed. It is also |
| 40 | * an asynchronous animation that automatically runs off of the UI thread. |
| 41 | * As a result {@link AnimatorListener#onAnimationEnd(Animator)} |
| 42 | * will occur after the animation has ended, but it may be delayed depending |
| 43 | * on thread responsiveness. |
Teng-Hui Zhu | 9b3be58 | 2016-04-01 16:42:47 -0700 | [diff] [blame] | 44 | * <p> |
| 45 | * Note that if any start delay is set on the reveal animator, the start radius |
| 46 | * will not be applied to the reveal circle until the start delay has passed. |
| 47 | * If it's desired to set a start radius on the reveal circle during the start |
| 48 | * delay, one workaround could be adding an animator with the same start and |
| 49 | * end radius. For example: |
| 50 | * <pre><code> |
| 51 | * public static Animator createRevealWithDelay(View view, int centerX, int centerY, float startRadius, float endRadius) { |
| 52 | * Animator delayAnimator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, startRadius); |
| 53 | * delayAnimator.setDuration(delayTimeMS); |
| 54 | * Animator revealAnimator = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius); |
| 55 | * AnimatorSet set = new AnimatorSet(); |
| 56 | * set.playSequentially(delayAnimator, revealAnimator); |
| 57 | * return set; |
| 58 | * } |
| 59 | * </code></pre> |
John Reck | 291161a | 2014-07-22 07:31:09 -0700 | [diff] [blame] | 60 | * |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 61 | * @param view The View will be clipped to the animating circle. |
George Mount | 9488294 | 2015-07-01 11:07:13 -0700 | [diff] [blame] | 62 | * @param centerX The x coordinate of the center of the animating circle, relative to |
| 63 | * <code>view</code>. |
| 64 | * @param centerY The y coordinate of the center of the animating circle, relative to |
| 65 | * <code>view</code>. |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 66 | * @param startRadius The starting radius of the animating circle. |
| 67 | * @param endRadius The ending radius of the animating circle. |
| 68 | */ |
Chris Craik | e83cbd4 | 2014-09-03 17:52:24 -0700 | [diff] [blame] | 69 | public static Animator createCircularReveal(View view, |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 70 | int centerX, int centerY, float startRadius, float endRadius) { |
Chris Craik | af4d04c | 2014-07-29 12:50:14 -0700 | [diff] [blame] | 71 | return new RevealAnimator(view, centerX, centerY, startRadius, endRadius); |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 72 | } |
| 73 | } |