Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
BatchStepSensor / src / com.example.android.batchstepsensor / cardstream /

DefaultCardStreamAnimator.java

       
        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.animation.PropertyValuesHolder;
       
       
        24
       
       
        import android.annotation.TargetApi;
       
       
        25
       
       
        import android.content.Context;
       
       
        26
       
       
        import android.graphics.Point;
       
       
        27
       
       
        import android.os.Build;
       
       
        28
       
       
        import android.view.View;
       
       
        29
       
       
        import android.view.WindowManager;
       
       
        30
       
       
        import android.view.animation.BounceInterpolator;
       
       
        31
       
       
       
       
        32
       
       
        class DefaultCardStreamAnimator extends CardStreamAnimator {
       
       
        33
       
       
       
       
        34
       
       
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
       
       
        35
       
       
        @Override
       
       
        36
       
       
        public ObjectAnimator getDisappearingAnimator(Context context){
       
       
        37
       
       
       
       
        38
       
       
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(new Object(),
       
       
        39
       
       
        PropertyValuesHolder.ofFloat("alpha", 1.f, 0.f),
       
       
        40
       
       
        PropertyValuesHolder.ofFloat("scaleX", 1.f, 0.f),
       
       
        41
       
       
        PropertyValuesHolder.ofFloat("scaleY", 1.f, 0.f),
       
       
        42
       
       
        PropertyValuesHolder.ofFloat("rotation", 0.f, 270.f));
       
       
        43
       
       
       
       
        44
       
       
        animator.setDuration((long) (200 * mSpeedFactor));
       
       
        45
       
       
        return animator;
       
       
        46
       
       
        }
       
       
        47
       
       
       
       
        48
       
       
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
       
       
        49
       
       
        @Override
       
       
        50
       
       
        public ObjectAnimator getAppearingAnimator(Context context){
       
       
        51
       
       
       
       
        52
       
       
        final Point outPoint = new Point();
       
       
        53
       
       
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
       
       
        54
       
       
        wm.getDefaultDisplay().getSize(outPoint);
       
       
        55
       
       
       
       
        56
       
       
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(new Object(),
       
       
        57
       
       
        PropertyValuesHolder.ofFloat("alpha", 0.f, 1.f),
       
       
        58
       
       
        PropertyValuesHolder.ofFloat("translationY", outPoint.y / 2.f, 0.f),
       
       
        59
       
       
        PropertyValuesHolder.ofFloat("rotation", -45.f, 0.f));
       
       
        60
       
       
       
       
        61
       
       
        animator.setDuration((long) (200 * mSpeedFactor));
       
       
        62
       
       
        return animator;
       
       
        63
       
       
        }
       
       
        64
       
       
       
       
        65
       
       
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
       
       
        66
       
       
        @Override
       
       
        67
       
       
        public ObjectAnimator getInitalAnimator(Context context){
       
       
        68
       
       
       
       
        69
       
       
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(new Object(),
       
       
        70
       
       
        PropertyValuesHolder.ofFloat("alpha", 0.5f, 1.f),
       
       
        71
       
       
        PropertyValuesHolder.ofFloat("rotation", 60.f, 0.f));
       
       
        72
       
       
       
       
        73
       
       
        animator.setDuration((long) (200 * mSpeedFactor));
       
       
        74
       
       
        return animator;
       
       
        75
       
       
        }
       
       
        76
       
       
       
       
        77
       
       
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
       
       
        78
       
       
        @Override
       
       
        79
       
       
        public ObjectAnimator getSwipeInAnimator(View view, float deltaX, float deltaY){
       
       
        80
       
       
       
       
        81
       
       
        float deltaXAbs = Math.abs(deltaX);
       
       
        82
       
       
       
       
        83
       
       
        float fractionCovered = 1.f - (deltaXAbs / view.getWidth());
       
       
        84
       
       
        long duration = Math.abs((int) ((1 - fractionCovered) * 200 * mSpeedFactor));
       
       
        85
       
       
       
       
        86
       
       
        // Animate position and alpha of swiped item
       
       
        87
       
       
       
       
        88
       
       
        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(view,
       
       
        89
       
       
        PropertyValuesHolder.ofFloat("alpha", 1.f),
       
       
        90
       
       
        PropertyValuesHolder.ofFloat("translationX", 0.f),
       
       
        91
       
       
        PropertyValuesHolder.ofFloat("rotationY", 0.f));
       
       
        92
       
       
       
       
        93
       
       
        animator.setDuration(duration).setInterpolator(new BounceInterpolator());
       
       
        94
       
       
       
       
        95
       
       
        return  animator;
       
       
        96
       
       
        }
       
       
        97
       
       
       
       
        98
       
       
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
       
       
        99
       
       
        @Override
       
       
        100
       
       
        public ObjectAnimator getSwipeOutAnimator(View view, float deltaX, float deltaY){
       
       
        101
       
       
       
       
        102
       
       
        float endX;
       
       
        103
       
       
        float endRotationY;
       
       
        104
       
       
       
       
        105
       
       
        float deltaXAbs = Math.abs(deltaX);
       
       
        106
       
       
       
       
        107
       
       
        float fractionCovered = 1.f - (deltaXAbs / view.getWidth());
       
       
        108
       
       
        long duration = Math.abs((int) ((1 - fractionCovered) * 200 * mSpeedFactor));
       
       
        109
       
       
       
       
        110
       
       
        endX = deltaX < 0 ? -view.getWidth() : view.getWidth();
       
       
        111
       
       
        if (deltaX > 0)
       
       
        112
       
       
        endRotationY = -15.f;
       
       
        113
       
       
        else
       
       
        114
       
       
        endRotationY = 15.f;
       
       
        115
       
       
       
       
        116
       
       
        // Animate position and alpha of swiped item
       
       
        117
       
       
        return ObjectAnimator.ofPropertyValuesHolder(view,
       
       
        118
       
       
        PropertyValuesHolder.ofFloat("alpha", 0.f),
       
       
        119
       
       
        PropertyValuesHolder.ofFloat("translationX", endX),
       
       
        120
       
       
        PropertyValuesHolder.ofFloat("rotationY", endRotationY)).setDuration(duration);
       
       
        121
       
       
       
       
        122
       
       
        }
       
       
        123
       
       
       
       
        124
       
       
        }