14 |
import android.view.MenuItem; |
import android.view.MenuItem; |
15 |
import android.view.MotionEvent; |
import android.view.MotionEvent; |
16 |
import android.view.View; |
import android.view.View; |
17 |
|
import android.view.animation.AccelerateInterpolator; |
18 |
import android.widget.ImageView; |
import android.widget.ImageView; |
19 |
import android.widget.TextView; |
import android.widget.TextView; |
20 |
|
import dk.thoerup.side9.anim.DisplayNextView; |
21 |
|
import dk.thoerup.side9.anim.Flip3dAnimation; |
22 |
|
|
23 |
public class PictureView extends Activity { |
public class PictureView extends Activity { |
24 |
final static int CONTEXT_VIEWIMG = 1000; |
final static int CONTEXT_VIEWIMG = 1000; |
27 |
|
|
28 |
TextView mDescription; |
TextView mDescription; |
29 |
TextView mCaption; |
TextView mCaption; |
30 |
ImageView mImageView; |
ImageView mImageView1; |
31 |
|
ImageView mImageView2; |
32 |
|
|
33 |
|
boolean isFirstImage = true; |
34 |
|
|
35 |
ArrayList<ImageEntry> mImages; |
ArrayList<ImageEntry> mImages; |
36 |
int mIndex; |
int mIndex; |
37 |
|
|
48 |
mIndex = getIntent().getIntExtra("index", 0); |
mIndex = getIntent().getIntExtra("index", 0); |
49 |
|
|
50 |
|
|
51 |
mImageView = (ImageView) findViewById(R.id.imageview); |
mImageView1 = (ImageView) findViewById(R.id.imageview1); |
52 |
mImageView.setOnTouchListener( new Touch() ); |
mImageView1.setOnTouchListener( new Touch() ); |
53 |
|
|
54 |
|
mImageView2 = (ImageView) findViewById(R.id.imageview2); |
55 |
|
|
56 |
mCaption = (TextView) findViewById(R.id.caption); |
mCaption = (TextView) findViewById(R.id.caption); |
57 |
mDescription = (TextView) findViewById(R.id.description); |
mDescription = (TextView) findViewById(R.id.description); |
58 |
|
|
59 |
|
|
60 |
loadImage(); |
loadImage(true, true); |
61 |
|
|
62 |
} |
} |
63 |
|
|
66 |
private void loadImage(int newIndex) { |
private void loadImage(int newIndex) { |
67 |
Log.e(TAG, "NewIndex " + newIndex); |
Log.e(TAG, "NewIndex " + newIndex); |
68 |
if (newIndex != mIndex) { |
if (newIndex != mIndex) { |
69 |
|
|
70 |
|
boolean isForward = (newIndex > mIndex); |
71 |
|
|
72 |
mIndex = newIndex; |
mIndex = newIndex; |
73 |
loadImage(); |
loadImage(false,isForward); |
74 |
} |
} |
75 |
} |
} |
76 |
|
|
77 |
private void loadImage() { |
private void loadImage(boolean firstLoad, boolean isForward) { |
78 |
ImageEntry currentImage = mImages.get(mIndex); |
ImageEntry currentImage = mImages.get(mIndex); |
79 |
mBitmap = BitmapFactory.decodeFile( currentImage.path ); |
mBitmap = BitmapFactory.decodeFile( currentImage.path ); |
80 |
mImageView.setImageBitmap(mBitmap); |
|
81 |
|
if (firstLoad) { |
82 |
|
mImageView1.setImageBitmap(mBitmap); |
83 |
|
isFirstImage = true; |
84 |
|
} else { |
85 |
|
|
86 |
|
int endAngle = isForward ? -90 : 90; |
87 |
|
|
88 |
|
if (isFirstImage) { |
89 |
|
mImageView2.setImageBitmap(mBitmap); |
90 |
|
applyRotation(0, endAngle, isForward); |
91 |
|
} else { |
92 |
|
mImageView1.setImageBitmap(mBitmap); |
93 |
|
applyRotation(0, endAngle, isForward); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
isFirstImage = !isFirstImage; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
if (currentImage.caption.length() > 0) { |
if (currentImage.caption.length() > 0) { |
111 |
String desc = "" + (mIndex +1) + "/" + mImages.size() + " - " + fileName; |
String desc = "" + (mIndex +1) + "/" + mImages.size() + " - " + fileName; |
112 |
mDescription.setText(desc); |
mDescription.setText(desc); |
113 |
} |
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
private void applyRotation(float start, float end, boolean isForward) { |
118 |
|
// Find the center of image |
119 |
|
final float centerX = mImageView1.getWidth() / 2.0f; |
120 |
|
final float centerY = mImageView1.getHeight() / 2.0f; |
121 |
|
|
122 |
|
// Create a new 3D rotation with the supplied parameter |
123 |
|
// The animation listener is used to trigger the next animation |
124 |
|
final Flip3dAnimation rotation = new Flip3dAnimation(start, end, centerX, centerY); |
125 |
|
rotation.setDuration(250); |
126 |
|
rotation.setFillAfter(true); |
127 |
|
rotation.setInterpolator(new AccelerateInterpolator()); |
128 |
|
rotation.setAnimationListener(new DisplayNextView(isFirstImage, isForward, mImageView1, mImageView2)); |
129 |
|
|
130 |
|
if (isFirstImage) |
131 |
|
{ |
132 |
|
mImageView1.startAnimation(rotation); |
133 |
|
} else { |
134 |
|
mImageView2.startAnimation(rotation); |
135 |
|
} |
136 |
|
|
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
@Override |
@Override |