John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [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 com.android.systemui.qs; |
| 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.Animator.AnimatorListener; |
| 21 | import android.animation.AnimatorListenerAdapter; |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 22 | import android.graphics.drawable.TransitionDrawable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 23 | import android.view.View; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 24 | import android.view.ViewAnimationUtils; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 25 | |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 26 | /** Helper for quick settings detail panel clip animations. **/ |
| 27 | public class QSDetailClipper { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 28 | |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 29 | private final View mDetail; |
| 30 | private final TransitionDrawable mBackground; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 31 | |
John Reck | c01bd11 | 2014-07-18 16:22:09 -0700 | [diff] [blame] | 32 | private Animator mAnimator; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 33 | |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 34 | public QSDetailClipper(View detail) { |
| 35 | mDetail = detail; |
| 36 | mBackground = (TransitionDrawable) detail.getBackground(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | public void animateCircularClip(int x, int y, boolean in, AnimatorListener listener) { |
| 40 | if (mAnimator != null) { |
| 41 | mAnimator.cancel(); |
| 42 | } |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 43 | final int w = mDetail.getWidth() - x; |
| 44 | final int h = mDetail.getHeight() - y; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 45 | int innerR = 0; |
| 46 | if (x < 0 || w < 0 || y < 0 || h < 0) { |
| 47 | innerR = Math.abs(x); |
| 48 | innerR = Math.min(innerR, Math.abs(y)); |
| 49 | innerR = Math.min(innerR, Math.abs(w)); |
| 50 | innerR = Math.min(innerR, Math.abs(h)); |
| 51 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 52 | int r = (int) Math.ceil(Math.sqrt(x * x + y * y)); |
| 53 | r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + y * y))); |
| 54 | r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + h * h))); |
| 55 | r = (int) Math.max(r, Math.ceil(Math.sqrt(x * x + h * h))); |
John Reck | baf9418 | 2014-08-20 08:36:42 -0700 | [diff] [blame] | 56 | if (in) { |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 57 | mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, innerR, r); |
John Reck | baf9418 | 2014-08-20 08:36:42 -0700 | [diff] [blame] | 58 | } else { |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 59 | mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, innerR); |
John Reck | baf9418 | 2014-08-20 08:36:42 -0700 | [diff] [blame] | 60 | } |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 61 | mAnimator.setDuration((long)(mAnimator.getDuration() * 1.5)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 62 | if (listener != null) { |
| 63 | mAnimator.addListener(listener); |
| 64 | } |
| 65 | if (in) { |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 66 | mBackground.startTransition((int)(mAnimator.getDuration() * 0.6)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 67 | mAnimator.addListener(mVisibleOnStart); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 68 | } else { |
John Spurlock | 19328fa | 2014-08-03 11:47:35 -0400 | [diff] [blame] | 69 | mDetail.postDelayed(mReverseBackground, (long)(mAnimator.getDuration() * 0.65)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 70 | mAnimator.addListener(mGoneOnEnd); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 71 | } |
John Reck | baf9418 | 2014-08-20 08:36:42 -0700 | [diff] [blame] | 72 | mAnimator.start(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 73 | } |
| 74 | |
John Spurlock | 19328fa | 2014-08-03 11:47:35 -0400 | [diff] [blame] | 75 | private final Runnable mReverseBackground = new Runnable() { |
| 76 | @Override |
| 77 | public void run() { |
| 78 | if (mAnimator != null) { |
| 79 | mBackground.reverseTransition((int)(mAnimator.getDuration() * 0.35)); |
| 80 | } |
| 81 | } |
| 82 | }; |
| 83 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 84 | private final AnimatorListenerAdapter mVisibleOnStart = new AnimatorListenerAdapter() { |
| 85 | @Override |
| 86 | public void onAnimationStart(Animator animation) { |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 87 | mDetail.setVisibility(View.VISIBLE); |
| 88 | } |
| 89 | |
| 90 | public void onAnimationEnd(Animator animation) { |
| 91 | mAnimator = null; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 92 | } |
| 93 | }; |
| 94 | |
| 95 | private final AnimatorListenerAdapter mGoneOnEnd = new AnimatorListenerAdapter() { |
| 96 | @Override |
| 97 | public void onAnimationEnd(Animator animation) { |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 98 | mDetail.setVisibility(View.GONE); |
| 99 | mBackground.resetTransition(); |
| 100 | mAnimator = null; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 101 | }; |
| 102 | }; |
Selim Cinek | 707e207 | 2017-06-30 18:32:40 +0200 | [diff] [blame] | 103 | |
| 104 | public void showBackground() { |
| 105 | mBackground.showSecondLayer(); |
| 106 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 107 | } |