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