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