1/* 2 * Copyright (C) 2018 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.util.wakelock; 18 19import android.animation.Animator; 20import android.animation.AnimatorListenerAdapter; 21import android.content.Context; 22import android.view.animation.Animation; 23 24import com.android.internal.annotations.VisibleForTesting; 25import com.android.systemui.util.Assert; 26 27public class KeepAwakeAnimationListener extends AnimatorListenerAdapter 28 implements Animation.AnimationListener { 29 @VisibleForTesting 30 static WakeLock sWakeLock; 31 32 public KeepAwakeAnimationListener(Context context) { 33 Assert.isMainThread(); 34 if (sWakeLock == null) { 35 sWakeLock = WakeLock.createPartial(context, "animation"); 36 } 37 } 38 39 @Override 40 public void onAnimationStart(Animation animation) { 41 onStart(); 42 } 43 44 @Override 45 public void onAnimationEnd(Animation animation) { 46 onEnd(); 47 } 48 49 @Override 50 public void onAnimationRepeat(Animation animation) { 51 52 } 53 54 @Override 55 public void onAnimationStart(Animator animation) { 56 onStart(); 57 } 58 59 @Override 60 public void onAnimationEnd(Animator animation) { 61 onEnd(); 62 } 63 64 private void onStart() { 65 Assert.isMainThread(); 66 sWakeLock.acquire(); 67 } 68 69 private void onEnd() { 70 Assert.isMainThread(); 71 sWakeLock.release(); 72 } 73} 74