1af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock/* 2af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * Copyright (C) 2014 The Android Open Source Project 3af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * 4af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * Licensed under the Apache License, Version 2.0 (the "License"); 5af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * you may not use this file except in compliance with the License. 6af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * You may obtain a copy of the License at 7af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * 8af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * http://www.apache.org/licenses/LICENSE-2.0 9af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * 10af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * Unless required by applicable law or agreed to in writing, software 11af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * distributed under the License is distributed on an "AS IS" BASIS, 12af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * See the License for the specific language governing permissions and 14af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock * limitations under the License. 15af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock */ 16af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 17af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockpackage com.android.systemui.qs; 18af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 19af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockimport android.animation.Animator; 20af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockimport android.animation.Animator.AnimatorListener; 21af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockimport android.animation.AnimatorListenerAdapter; 228af525dd7d1640175fda344301a8712725557caaJohn Spurlockimport android.graphics.drawable.TransitionDrawable; 23af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlockimport android.view.View; 247f8f22a53005f776c8ee4d299e748e74b077ffd9John Spurlockimport android.view.ViewAnimationUtils; 25af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 268af525dd7d1640175fda344301a8712725557caaJohn Spurlock/** Helper for quick settings detail panel clip animations. **/ 278af525dd7d1640175fda344301a8712725557caaJohn Spurlockpublic class QSDetailClipper { 28af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 298af525dd7d1640175fda344301a8712725557caaJohn Spurlock private final View mDetail; 308af525dd7d1640175fda344301a8712725557caaJohn Spurlock private final TransitionDrawable mBackground; 31af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 32c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck private Animator mAnimator; 33af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 348af525dd7d1640175fda344301a8712725557caaJohn Spurlock public QSDetailClipper(View detail) { 358af525dd7d1640175fda344301a8712725557caaJohn Spurlock mDetail = detail; 368af525dd7d1640175fda344301a8712725557caaJohn Spurlock mBackground = (TransitionDrawable) detail.getBackground(); 37af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 38af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 39af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock public void animateCircularClip(int x, int y, boolean in, AnimatorListener listener) { 40af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock if (mAnimator != null) { 41af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock mAnimator.cancel(); 42af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 438af525dd7d1640175fda344301a8712725557caaJohn Spurlock final int w = mDetail.getWidth() - x; 448af525dd7d1640175fda344301a8712725557caaJohn Spurlock final int h = mDetail.getHeight() - y; 45970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos int innerR = 0; 46970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos if (x < 0 || w < 0 || y < 0 || h < 0) { 47970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos innerR = Math.abs(x); 48970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos innerR = Math.min(innerR, Math.abs(y)); 49970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos innerR = Math.min(innerR, Math.abs(w)); 50970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos innerR = Math.min(innerR, Math.abs(h)); 51970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos } 52af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock int r = (int) Math.ceil(Math.sqrt(x * x + y * y)); 53af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + y * y))); 54af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + h * h))); 55af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock r = (int) Math.max(r, Math.ceil(Math.sqrt(x * x + h * h))); 56baf94181f77eff05db6253db57a6eb287641ce3eJohn Reck if (in) { 57970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, innerR, r); 58baf94181f77eff05db6253db57a6eb287641ce3eJohn Reck } else { 59970be5313a03de60e1993c3d98027f34c1c9b4f1Adrian Roos mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, innerR); 60baf94181f77eff05db6253db57a6eb287641ce3eJohn Reck } 618af525dd7d1640175fda344301a8712725557caaJohn Spurlock mAnimator.setDuration((long)(mAnimator.getDuration() * 1.5)); 62af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock if (listener != null) { 63af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock mAnimator.addListener(listener); 64af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 65af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock if (in) { 668af525dd7d1640175fda344301a8712725557caaJohn Spurlock mBackground.startTransition((int)(mAnimator.getDuration() * 0.6)); 67af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock mAnimator.addListener(mVisibleOnStart); 68af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } else { 6919328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock mDetail.postDelayed(mReverseBackground, (long)(mAnimator.getDuration() * 0.65)); 70af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock mAnimator.addListener(mGoneOnEnd); 71af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 72baf94181f77eff05db6253db57a6eb287641ce3eJohn Reck mAnimator.start(); 73af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 74af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 7519328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock private final Runnable mReverseBackground = new Runnable() { 7619328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock @Override 7719328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock public void run() { 7819328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock if (mAnimator != null) { 7919328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock mBackground.reverseTransition((int)(mAnimator.getDuration() * 0.35)); 8019328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock } 8119328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock } 8219328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock }; 8319328fab0e7d1509c4c2f9276900dbd87bce81eaJohn Spurlock 84af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock private final AnimatorListenerAdapter mVisibleOnStart = new AnimatorListenerAdapter() { 85af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 86af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock public void onAnimationStart(Animator animation) { 878af525dd7d1640175fda344301a8712725557caaJohn Spurlock mDetail.setVisibility(View.VISIBLE); 888af525dd7d1640175fda344301a8712725557caaJohn Spurlock } 898af525dd7d1640175fda344301a8712725557caaJohn Spurlock 908af525dd7d1640175fda344301a8712725557caaJohn Spurlock public void onAnimationEnd(Animator animation) { 918af525dd7d1640175fda344301a8712725557caaJohn Spurlock mAnimator = null; 92af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock } 93af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock }; 94af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock 95af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock private final AnimatorListenerAdapter mGoneOnEnd = new AnimatorListenerAdapter() { 96af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock @Override 97af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock public void onAnimationEnd(Animator animation) { 988af525dd7d1640175fda344301a8712725557caaJohn Spurlock mDetail.setVisibility(View.GONE); 998af525dd7d1640175fda344301a8712725557caaJohn Spurlock mBackground.resetTransition(); 1008af525dd7d1640175fda344301a8712725557caaJohn Spurlock mAnimator = null; 101af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock }; 102af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock }; 103af8d6c44f06d2f8baac2c5774a9efdae3fc36797John Spurlock} 104