1 |
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 |
public void run() { |
21 |
final float centerX = image1.getWidth() / 2.0f; |
22 |
final float centerY = image1.getHeight() / 2.0f; |
23 |
Flip3dAnimation rotation; |
24 |
|
25 |
if (mIsFirstView) { |
26 |
image1.setVisibility(View.GONE); |
27 |
image2.setVisibility(View.VISIBLE); |
28 |
image2.requestFocus(); |
29 |
|
30 |
|
31 |
} else { |
32 |
image2.setVisibility(View.GONE); |
33 |
image1.setVisibility(View.VISIBLE); |
34 |
image1.requestFocus(); |
35 |
} |
36 |
|
37 |
int startAngle = forward ? 90 : -90; |
38 |
|
39 |
rotation = new Flip3dAnimation(startAngle, 0, centerX, centerY); |
40 |
|
41 |
rotation.setDuration(250); |
42 |
rotation.setFillAfter(true); |
43 |
rotation.setInterpolator(new DecelerateInterpolator()); |
44 |
|
45 |
if (mIsFirstView) { |
46 |
image2.startAnimation(rotation); |
47 |
} else { |
48 |
image1.startAnimation(rotation); |
49 |
} |
50 |
} |
51 |
} |