summaryrefslogtreecommitdiff
path: root/samples/browseable/BatchStepSensor/src/com.example.android.batchstepsensor/cardstream/CardStreamAnimator.java
blob: 91a05aeeb2644365174a18d1ab67085ab1bd869a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.batchstepsensor.cardstream;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.View;

/**
 * An abstract class which defines animators for CardStreamLinearLayout.
 */
abstract class CardStreamAnimator {

    protected float mSpeedFactor = 1.f;

    /**
     * Set speed factor of animations. Higher value means longer duration & slow animation.
     *
     * @param speedFactor speed type 1: SLOW, 2: NORMAL, 3:FAST
     */
    public void setSpeedFactor(float speedFactor) {
        mSpeedFactor = speedFactor;
    }

    /**
     * Define initial animation of each child which fired when a user rotate a screen.
     *
     * @param context
     * @return ObjectAnimator for initial animation
     */
    public abstract ObjectAnimator getInitalAnimator(Context context);

    /**
     * Define disappearing animation of a child which fired when a view is removed programmatically
     *
     * @param context
     * @return ObjectAnimator for disappearing animation
     */
    public abstract ObjectAnimator getDisappearingAnimator(Context context);

    /**
     * Define appearing animation of a child which fired when a view is added programmatically
     *
     * @param context
     * @return ObjectAnimator for appearing animation
     */
    public abstract ObjectAnimator getAppearingAnimator(Context context);

    /**
     * Define swipe-in (back to the origin position) animation of a child
     * which fired when a view is not moved enough to be removed.
     *
     * @param view   target view
     * @param deltaX delta distance by x-axis
     * @param deltaY delta distance by y-axis
     * @return ObjectAnimator for swipe-in animation
     */
    public abstract ObjectAnimator getSwipeInAnimator(View view, float deltaX, float deltaY);

    /**
     * Define swipe-out animation of a child
     * which fired when a view is removing by a user swipe action.
     *
     * @param view   target view
     * @param deltaX delta distance by x-axis
     * @param deltaY delta distance by y-axis
     * @return ObjectAnimator for swipe-out animation
     */
    public abstract ObjectAnimator getSwipeOutAnimator(View view, float deltaX, float deltaY);

    /**
     * A simple CardStreamAnimator implementation which is used to turn animations off.
     */
    public static class EmptyAnimator extends CardStreamAnimator {

        @Override
        public ObjectAnimator getInitalAnimator(Context context) {
            return null;
        }

        @Override
        public ObjectAnimator getDisappearingAnimator(Context context) {
            return null;
        }

        @Override
        public ObjectAnimator getAppearingAnimator(Context context) {
            return null;
        }

        @Override
        public ObjectAnimator getSwipeInAnimator(View view, float deltaX, float deltaY) {
            return null;
        }

        @Override
        public ObjectAnimator getSwipeOutAnimator(View view, float deltaX, float deltaY) {
            return null;
        }
    }

}