• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2013 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 com.example.android.batchstepsensor.cardstream;
18 
19 import android.animation.ObjectAnimator;
20 import android.content.Context;
21 import android.view.View;
22 
23 /**
24  * An abstract class which defines animators for CardStreamLinearLayout.
25  */
26 abstract class CardStreamAnimator {
27 
28     protected float mSpeedFactor = 1.f;
29 
30     /**
31      * Set speed factor of animations. Higher value means longer duration & slow animation.
32      *
33      * @param speedFactor speed type 1: SLOW, 2: NORMAL, 3:FAST
34      */
setSpeedFactor(float speedFactor)35     public void setSpeedFactor(float speedFactor) {
36         mSpeedFactor = speedFactor;
37     }
38 
39     /**
40      * Define initial animation of each child which fired when a user rotate a screen.
41      *
42      * @param context
43      * @return ObjectAnimator for initial animation
44      */
getInitalAnimator(Context context)45     public abstract ObjectAnimator getInitalAnimator(Context context);
46 
47     /**
48      * Define disappearing animation of a child which fired when a view is removed programmatically
49      *
50      * @param context
51      * @return ObjectAnimator for disappearing animation
52      */
getDisappearingAnimator(Context context)53     public abstract ObjectAnimator getDisappearingAnimator(Context context);
54 
55     /**
56      * Define appearing animation of a child which fired when a view is added programmatically
57      *
58      * @param context
59      * @return ObjectAnimator for appearing animation
60      */
getAppearingAnimator(Context context)61     public abstract ObjectAnimator getAppearingAnimator(Context context);
62 
63     /**
64      * Define swipe-in (back to the origin position) animation of a child
65      * which fired when a view is not moved enough to be removed.
66      *
67      * @param view   target view
68      * @param deltaX delta distance by x-axis
69      * @param deltaY delta distance by y-axis
70      * @return ObjectAnimator for swipe-in animation
71      */
getSwipeInAnimator(View view, float deltaX, float deltaY)72     public abstract ObjectAnimator getSwipeInAnimator(View view, float deltaX, float deltaY);
73 
74     /**
75      * Define swipe-out animation of a child
76      * which fired when a view is removing by a user swipe action.
77      *
78      * @param view   target view
79      * @param deltaX delta distance by x-axis
80      * @param deltaY delta distance by y-axis
81      * @return ObjectAnimator for swipe-out animation
82      */
getSwipeOutAnimator(View view, float deltaX, float deltaY)83     public abstract ObjectAnimator getSwipeOutAnimator(View view, float deltaX, float deltaY);
84 
85     /**
86      * A simple CardStreamAnimator implementation which is used to turn animations off.
87      */
88     public static class EmptyAnimator extends CardStreamAnimator {
89 
90         @Override
getInitalAnimator(Context context)91         public ObjectAnimator getInitalAnimator(Context context) {
92             return null;
93         }
94 
95         @Override
getDisappearingAnimator(Context context)96         public ObjectAnimator getDisappearingAnimator(Context context) {
97             return null;
98         }
99 
100         @Override
getAppearingAnimator(Context context)101         public ObjectAnimator getAppearingAnimator(Context context) {
102             return null;
103         }
104 
105         @Override
getSwipeInAnimator(View view, float deltaX, float deltaY)106         public ObjectAnimator getSwipeInAnimator(View view, float deltaX, float deltaY) {
107             return null;
108         }
109 
110         @Override
getSwipeOutAnimator(View view, float deltaX, float deltaY)111         public ObjectAnimator getSwipeOutAnimator(View view, float deltaX, float deltaY) {
112             return null;
113         }
114     }
115 
116 }
117 
118