1 |
torben |
1217 |
package dk.thoerup.side9.anim; |
2 |
|
|
|
3 |
|
|
import android.view.View; |
4 |
|
|
import android.view.animation.DecelerateInterpolator; |
5 |
|
|
import android.widget.ImageView; |
6 |
|
|
|
7 |
|
|
public final class SwapViews implements Runnable { |
8 |
|
|
private boolean mIsFirstView; |
9 |
|
|
ImageView image1; |
10 |
|
|
ImageView image2; |
11 |
|
|
boolean forward; |
12 |
|
|
|
13 |
|
|
public SwapViews(boolean isFirstView, boolean forward, ImageView image1, ImageView image2) { |
14 |
|
|
mIsFirstView = isFirstView; |
15 |
|
|
this.image1 = image1; |
16 |
|
|
this.image2 = image2; |
17 |
|
|
this.forward = forward; |
18 |
|
|
} |
19 |
|
|
|
20 |
torben |
1218 |
@Override |
21 |
torben |
1217 |
public void run() { |
22 |
|
|
final float centerX = image1.getWidth() / 2.0f; |
23 |
|
|
final float centerY = image1.getHeight() / 2.0f; |
24 |
|
|
Flip3dAnimation rotation; |
25 |
|
|
|
26 |
|
|
if (mIsFirstView) { |
27 |
|
|
image1.setVisibility(View.GONE); |
28 |
|
|
image2.setVisibility(View.VISIBLE); |
29 |
|
|
image2.requestFocus(); |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
} else { |
33 |
|
|
image2.setVisibility(View.GONE); |
34 |
|
|
image1.setVisibility(View.VISIBLE); |
35 |
|
|
image1.requestFocus(); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
int startAngle = forward ? 90 : -90; |
39 |
|
|
|
40 |
|
|
rotation = new Flip3dAnimation(startAngle, 0, centerX, centerY); |
41 |
|
|
|
42 |
|
|
rotation.setDuration(250); |
43 |
|
|
rotation.setFillAfter(true); |
44 |
|
|
rotation.setInterpolator(new DecelerateInterpolator()); |
45 |
|
|
|
46 |
|
|
if (mIsFirstView) { |
47 |
|
|
image2.startAnimation(rotation); |
48 |
|
|
} else { |
49 |
|
|
image1.startAnimation(rotation); |
50 |
|
|
} |
51 |
|
|
} |
52 |
|
|
} |