Home | History | Annotate | Download | only in widget
      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 
     17 package androidx.wear.widget;
     18 
     19 import android.animation.Animator;
     20 import android.os.Build;
     21 
     22 import androidx.annotation.RequiresApi;
     23 import androidx.annotation.RestrictTo;
     24 import androidx.annotation.RestrictTo.Scope;
     25 
     26 /**
     27  * Convenience class for listening for Animator events that implements the AnimatorListener
     28  * interface and allows extending only methods that are necessary.
     29  *
     30  * @hide Hidden until this goes through review
     31  */
     32 @RequiresApi(Build.VERSION_CODES.KITKAT_WATCH)
     33 @RestrictTo(Scope.LIBRARY)
     34 public class SimpleAnimatorListener implements Animator.AnimatorListener {
     35 
     36     private boolean mWasCanceled;
     37 
     38     @Override
     39     public void onAnimationCancel(Animator animator) {
     40         mWasCanceled = true;
     41     }
     42 
     43     @Override
     44     public void onAnimationEnd(Animator animator) {
     45         if (!mWasCanceled) {
     46             onAnimationComplete(animator);
     47         }
     48     }
     49 
     50     @Override
     51     public void onAnimationRepeat(Animator animator) {}
     52 
     53     @Override
     54     public void onAnimationStart(Animator animator) {
     55         mWasCanceled = false;
     56     }
     57 
     58     /**
     59      * Called when the animation finishes. Not called if the animation was canceled.
     60      */
     61     public void onAnimationComplete(Animator animator) {}
     62 
     63     /**
     64      * Provides information if the animation was cancelled.
     65      *
     66      * @return True if animation was cancelled.
     67      */
     68     public boolean wasCanceled() {
     69         return mWasCanceled;
     70     }
     71 }
     72