--- android/Side9/src/dk/thoerup/side9/PictureView.java 2011/01/09 15:12:40 1216 +++ android/Side9/src/dk/thoerup/side9/PictureView.java 2011/01/24 22:21:23 1217 @@ -14,8 +14,11 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; +import android.view.animation.AccelerateInterpolator; import android.widget.ImageView; import android.widget.TextView; +import dk.thoerup.side9.anim.DisplayNextView; +import dk.thoerup.side9.anim.Flip3dAnimation; public class PictureView extends Activity { final static int CONTEXT_VIEWIMG = 1000; @@ -24,7 +27,11 @@ TextView mDescription; TextView mCaption; - ImageView mImageView; + ImageView mImageView1; + ImageView mImageView2; + + boolean isFirstImage = true; + ArrayList mImages; int mIndex; @@ -41,14 +48,16 @@ mIndex = getIntent().getIntExtra("index", 0); - mImageView = (ImageView) findViewById(R.id.imageview); - mImageView.setOnTouchListener( new Touch() ); + mImageView1 = (ImageView) findViewById(R.id.imageview1); + mImageView1.setOnTouchListener( new Touch() ); + + mImageView2 = (ImageView) findViewById(R.id.imageview2); mCaption = (TextView) findViewById(R.id.caption); mDescription = (TextView) findViewById(R.id.description); - loadImage(); + loadImage(true, true); } @@ -57,15 +66,37 @@ private void loadImage(int newIndex) { Log.e(TAG, "NewIndex " + newIndex); if (newIndex != mIndex) { + + boolean isForward = (newIndex > mIndex); + mIndex = newIndex; - loadImage(); + loadImage(false,isForward); } } - private void loadImage() { + private void loadImage(boolean firstLoad, boolean isForward) { ImageEntry currentImage = mImages.get(mIndex); mBitmap = BitmapFactory.decodeFile( currentImage.path ); - mImageView.setImageBitmap(mBitmap); + + if (firstLoad) { + mImageView1.setImageBitmap(mBitmap); + isFirstImage = true; + } else { + + int endAngle = isForward ? -90 : 90; + + if (isFirstImage) { + mImageView2.setImageBitmap(mBitmap); + applyRotation(0, endAngle, isForward); + } else { + mImageView1.setImageBitmap(mBitmap); + applyRotation(0, endAngle, isForward); + } + + + + isFirstImage = !isFirstImage; + } if (currentImage.caption.length() > 0) { @@ -80,7 +111,32 @@ String desc = "" + (mIndex +1) + "/" + mImages.size() + " - " + fileName; mDescription.setText(desc); } + + + private void applyRotation(float start, float end, boolean isForward) { + // Find the center of image + final float centerX = mImageView1.getWidth() / 2.0f; + final float centerY = mImageView1.getHeight() / 2.0f; + + // Create a new 3D rotation with the supplied parameter + // The animation listener is used to trigger the next animation + final Flip3dAnimation rotation = new Flip3dAnimation(start, end, centerX, centerY); + rotation.setDuration(250); + rotation.setFillAfter(true); + rotation.setInterpolator(new AccelerateInterpolator()); + rotation.setAnimationListener(new DisplayNextView(isFirstImage, isForward, mImageView1, mImageView2)); + + if (isFirstImage) + { + mImageView1.startAnimation(rotation); + } else { + mImageView2.startAnimation(rotation); + } + + } + + @Override