1/* 2 * Copyright (C) 2017 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 android.support.transition; 18 19import android.animation.Animator; 20import android.animation.AnimatorListenerAdapter; 21import android.support.annotation.NonNull; 22import android.support.annotation.RequiresApi; 23 24import java.util.ArrayList; 25 26@RequiresApi(14) 27class AnimatorUtilsApi14 implements AnimatorUtilsImpl { 28 29 @Override 30 public void addPauseListener(@NonNull Animator animator, 31 @NonNull AnimatorListenerAdapter listener) { 32 // Do nothing 33 } 34 35 @Override 36 public void pause(@NonNull Animator animator) { 37 final ArrayList<Animator.AnimatorListener> listeners = animator.getListeners(); 38 if (listeners != null) { 39 for (int i = 0, size = listeners.size(); i < size; i++) { 40 final Animator.AnimatorListener listener = listeners.get(i); 41 if (listener instanceof AnimatorPauseListenerCompat) { 42 ((AnimatorPauseListenerCompat) listener).onAnimationPause(animator); 43 } 44 } 45 } 46 } 47 48 @Override 49 public void resume(@NonNull Animator animator) { 50 final ArrayList<Animator.AnimatorListener> listeners = animator.getListeners(); 51 if (listeners != null) { 52 for (int i = 0, size = listeners.size(); i < size; i++) { 53 final Animator.AnimatorListener listener = listeners.get(i); 54 if (listener instanceof AnimatorPauseListenerCompat) { 55 ((AnimatorPauseListenerCompat) listener).onAnimationResume(animator); 56 } 57 } 58 } 59 } 60 61 /** 62 * Listeners can implement this interface in addition to the platform AnimatorPauseListener to 63 * make them compatible with API level 18 and below. Animators will not be paused or resumed, 64 * but the callbacks here are invoked. 65 */ 66 interface AnimatorPauseListenerCompat { 67 68 void onAnimationPause(Animator animation); 69 70 void onAnimationResume(Animator animation); 71 72 } 73 74} 75