My favorites
▼
|
Sign in
myandroidwidgets
Sample Apps for Android
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
FlipAnimatorExample
/
src
/
com
/
beanie
/
examples
/
animation
/
FlipAnimator
/
FlipAnimator.java
r56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.beanie.examples.animation.FlipAnimator;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class FlipAnimator extends Animation {
private Camera camera;
private View fromView;
private View toView;
private float centerX;
private float centerY;
private boolean forward = true;
private boolean visibilitySwapped;
/**
* Creates a 3D flip animation between two views. If forward is true, its
* assumed that view1 is "visible" and view2 is "gone" before the animation
* starts. At the end of the animation, view1 will be "gone" and view2 will
* be "visible". If forward is false, the reverse is assumed.
*
* @param fromView First view in the transition.
* @param toView Second view in the transition.
* @param centerX The center of the views in the x-axis.
* @param centerY The center of the views in the y-axis.
* @param forward The direction of the animation.
*/
public FlipAnimator(View fromView, View toView, int centerX, int centerY) {
this.fromView = fromView;
this.toView = toView;
this.centerX = centerX;
this.centerY = centerY;
setDuration(500);
setFillAfter(true);
setInterpolator(new AccelerateDecelerateInterpolator());
}
public void reverse() {
forward = false;
View temp = toView;
toView = fromView;
fromView = temp;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
camera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
// Angle around the y-axis of the rotation at the given time. It is
// calculated both in radians and in the equivalent degrees.
final double radians = Math.PI * interpolatedTime;
float degrees = (float) (180.0 * radians / Math.PI);
// Once we reach the midpoint in the animation, we need to hide the
// source view and show the destination view. We also need to change
// the angle by 180 degrees so that the destination does not come in
// flipped around. This is the main problem with SDK sample, it does not
// do this.
if (interpolatedTime >= 0.5f) {
degrees -= 180.f;
if (!visibilitySwapped) {
fromView.setVisibility(View.GONE);
toView.setVisibility(View.VISIBLE);
visibilitySwapped = true;
}
}
if (forward)
degrees = -degrees;
final Matrix matrix = t.getMatrix();
camera.save();
camera.translate(0.0f, 0.0f, (float) (150.0 * Math.sin(radians)));
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
Show details
Hide details
Change log
r50
by coomar.101 on Jul 14, 2011
Diff
[No log message]
Go to:
...k/FlipAnimatorExample/.classpath
/trunk/FlipAnimatorExample/.project
...matorExample/AndroidManifest.xml
/trunk/FlipAnimatorExample/assets
...imatorExample/default.properties
...FlipAnimatorExample/proguard.cfg
/trunk/FlipAnimatorExample/res
...nimatorExample/res/drawable-hdpi
...ample/res/drawable-hdpi/icon.png
...nimatorExample/res/drawable-ldpi
...ample/res/drawable-ldpi/icon.png
...nimatorExample/res/drawable-mdpi
...ample/res/drawable-mdpi/icon.png
...le/res/drawable-mdpi/image_1.png
...le/res/drawable-mdpi/image_2.png
...k/FlipAnimatorExample/res/layout
...matorExample/res/layout/main.xml
...k/FlipAnimatorExample/res/values
...orExample/res/values/strings.xml
/trunk/FlipAnimatorExample/src
/trunk/FlipAnimatorExample/src/com
...ipAnimatorExample/src/com/beanie
...rExample/src/com/beanie/examples
...rc/com/beanie/examples/animation
.../examples/animation/FlipAnimator
...n/FlipAnimator/FlipAnimator.java
...FlipAnimatorExampleActivity.java
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 3219 bytes, 99 lines
View raw file
Powered by
Google Project Hosting