blob: c454048d06493647faee362d41b2d79f5615e835 [file] [log] [blame]
John Spurlockaf8d6c42014-05-07 17:49:08 -04001/*
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
17package com.android.systemui.qs;
18
19import android.animation.Animator;
20import android.animation.Animator.AnimatorListener;
21import android.animation.AnimatorListenerAdapter;
John Spurlock8af525d2014-08-02 10:56:05 -040022import android.graphics.drawable.TransitionDrawable;
John Spurlockaf8d6c42014-05-07 17:49:08 -040023import android.view.View;
John Spurlock7f8f22a2014-07-02 18:54:17 -040024import android.view.ViewAnimationUtils;
John Spurlockaf8d6c42014-05-07 17:49:08 -040025
John Spurlock8af525d2014-08-02 10:56:05 -040026/** Helper for quick settings detail panel clip animations. **/
27public class QSDetailClipper {
John Spurlockaf8d6c42014-05-07 17:49:08 -040028
John Spurlock8af525d2014-08-02 10:56:05 -040029 private final View mDetail;
30 private final TransitionDrawable mBackground;
John Spurlockaf8d6c42014-05-07 17:49:08 -040031
John Reckc01bd112014-07-18 16:22:09 -070032 private Animator mAnimator;
John Spurlockaf8d6c42014-05-07 17:49:08 -040033
John Spurlock8af525d2014-08-02 10:56:05 -040034 public QSDetailClipper(View detail) {
35 mDetail = detail;
36 mBackground = (TransitionDrawable) detail.getBackground();
John Spurlockaf8d6c42014-05-07 17:49:08 -040037 }
38
39 public void animateCircularClip(int x, int y, boolean in, AnimatorListener listener) {
40 if (mAnimator != null) {
41 mAnimator.cancel();
42 }
John Spurlock8af525d2014-08-02 10:56:05 -040043 final int w = mDetail.getWidth() - x;
44 final int h = mDetail.getHeight() - y;
Adrian Roos970be532014-11-21 15:50:16 +010045 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 Spurlockaf8d6c42014-05-07 17:49:08 -040052 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 Reckbaf94182014-08-20 08:36:42 -070056 if (in) {
Adrian Roos970be532014-11-21 15:50:16 +010057 mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, innerR, r);
John Reckbaf94182014-08-20 08:36:42 -070058 } else {
Adrian Roos970be532014-11-21 15:50:16 +010059 mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, innerR);
John Reckbaf94182014-08-20 08:36:42 -070060 }
John Spurlock8af525d2014-08-02 10:56:05 -040061 mAnimator.setDuration((long)(mAnimator.getDuration() * 1.5));
John Spurlockaf8d6c42014-05-07 17:49:08 -040062 if (listener != null) {
63 mAnimator.addListener(listener);
64 }
65 if (in) {
John Spurlock8af525d2014-08-02 10:56:05 -040066 mBackground.startTransition((int)(mAnimator.getDuration() * 0.6));
John Spurlockaf8d6c42014-05-07 17:49:08 -040067 mAnimator.addListener(mVisibleOnStart);
John Spurlockaf8d6c42014-05-07 17:49:08 -040068 } else {
John Spurlock19328fa2014-08-03 11:47:35 -040069 mDetail.postDelayed(mReverseBackground, (long)(mAnimator.getDuration() * 0.65));
John Spurlockaf8d6c42014-05-07 17:49:08 -040070 mAnimator.addListener(mGoneOnEnd);
John Spurlockaf8d6c42014-05-07 17:49:08 -040071 }
John Reckbaf94182014-08-20 08:36:42 -070072 mAnimator.start();
John Spurlockaf8d6c42014-05-07 17:49:08 -040073 }
74
John Spurlock19328fa2014-08-03 11:47:35 -040075 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 Spurlockaf8d6c42014-05-07 17:49:08 -040084 private final AnimatorListenerAdapter mVisibleOnStart = new AnimatorListenerAdapter() {
85 @Override
86 public void onAnimationStart(Animator animation) {
John Spurlock8af525d2014-08-02 10:56:05 -040087 mDetail.setVisibility(View.VISIBLE);
88 }
89
90 public void onAnimationEnd(Animator animation) {
91 mAnimator = null;
John Spurlockaf8d6c42014-05-07 17:49:08 -040092 }
93 };
94
95 private final AnimatorListenerAdapter mGoneOnEnd = new AnimatorListenerAdapter() {
96 @Override
97 public void onAnimationEnd(Animator animation) {
John Spurlock8af525d2014-08-02 10:56:05 -040098 mDetail.setVisibility(View.GONE);
99 mBackground.resetTransition();
100 mAnimator = null;
John Spurlockaf8d6c42014-05-07 17:49:08 -0400101 };
102 };
Selim Cinek707e2072017-06-30 18:32:40 +0200103
104 public void showBackground() {
105 mBackground.showSecondLayer();
106 }
John Spurlockaf8d6c42014-05-07 17:49:08 -0400107}