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