Skip to content

Most visited

Recently visited

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

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.