package com.worldchip.apk;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Matrix;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Display;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Toast;
public class ImageGalleryView extends Activity{
private static final String TAG = "ImageGalleryView";
private static final String PREF_SLIDESHOW_REPEAT =
"pref_gallery_slideshow_repeat_key";
Gallery gallery=null;
Animation anim=null;
String[] paths=null;
List<String> mImagePathList;
private ImageGetter mGetter;
private final Random mRandom = new Random(System.currentTimeMillis());
boolean mPaused = true;
private boolean mSlideShowLoop = false;
private int mSlideShowInterval=1000;
private int mLastSlideShowImage;
int mCurrentPosition = 0;
// represents which style animation to use
private int mAnimationIndex;
private Animation [] mSlideShowInAnimation;
private Animation [] mSlideShowOutAnimation;
private SharedPreferences mPrefs;
// Choices for what adjacents to load.
private static final int[] sOrderAdjacents = new int[] {0, 1, -1};
private static final int[] sOrderSlideshow = new int[] {0};
GestureDetector mGestureDetector;
final GetterHandler mHandler = new GetterHandler();
static final int MODE_NORMAL = 1;
static final int MODE_SLIDESHOW = 2;
private int mMode = MODE_NORMAL;
// The image view displayed for normal mode.
private ImageViewTouch mCurrentImageView;
private Button mSaveConfirm;
private Button mSaveCancel;
// This is the cache for thumbnail bitmaps.
private BitmapCache mCache;
String path=null;
GalleryAdapter galleryAdapter=null;
private float scaleWidth=1, scaleHeight=1;
private int mSlideShowImageCurrent = 0;
private final ImageViewTouchBase [] mSlideShowImageViews =
new ImageViewTouchBase[2];
private Bitmap currentBitmap;
private Bitmap effectsBitmap;
private String currentPath;
private int currentPosition;
private int displayWidth, displayHeight;
//FLING PARMS
public static final int FLING_MIN_DISTANCE=100;
public static final int FLING_MIN_VELOCITY=200;
//Menu
public static final int ANIMATION = Menu.FIRST;
public static final int ROTATE = Menu.FIRST+1;
public static final int THUMBNAIL = Menu.FIRST+2;
public static final int SETUPFOR = Menu.FIRST+5;
public static final int DELETE = Menu.FIRST+6;
public static final int DETAILS = Menu.FIRST+3;
public static final int QUITE = Menu.FIRST+4;
public static final int EFFECTS = Menu.FIRST+7;
private void setupOnTouchListeners(View rootView) {
mGestureDetector = new GestureDetector(this, new MyGestureListener());
OnTouchListener rootListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
mGestureDetector.onTouchEvent(event);
// We do not use the return value of
// mGestureDetector.onTouchEvent because we will not receive
// the "up" event if we return false for the "down" event.
return true;
}
};
rootView.setOnTouchListener(rootListener);
}
private class MyGestureListener extends
GestureDetector.SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
//if (mPaused) return false;
ImageViewTouch imageView = mCurrentImageView;
if (imageView.getScale() > 1F) {
imageView.postTranslateCenter(-distanceX, -distanceY);
}
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
if((e1.getX()-e2.getX()>FLING_MIN_DISTANCE)&&
Math.abs(velocityX)>FLING_MIN_VELOCITY)
{
moveNextOrPrevious(1);
}
else if((e2.getX()-e1.getX()>FLING_MIN_DISTANCE)&&
Math.abs(velocityX)>FLING_MIN_VELOCITY)
{
moveNextOrPrevious(-1);
}
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
//if (mPaused) return false;
//setMode(MODE_NORMAL);
//openOptionsMenu();
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
//if (mPaused) return false;
//showOnScreenControls();
//scheduleDismissOnScreenControls();
setMode(MODE_NORMAL);
openOptionsMenu();
return true;
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return super.onDown(e);
}
@Override
public boolean onDoubleTap(MotionEvent e) {
//if (mPaused) return false;
ImageViewTouch imageView = mCurrentImageView;
// Switch between the original scale and 3x scale.
if (imageView.getScale() > 2F) {
mCurrentImageView.zoomTo(1f);
} else {
mCurrentImageView.zoomToPoint(3f, e.getX(), e.getY());
}
return true;
}
}
private Animation makeInAnimation(int id) {
Animation inAnimation = AnimationUtils.loadAnimation(this, id);
return inAnimation;
}
private Animation makeOutAnimation(int id) {
Animation outAnimation = AnimationUtils.loadAnimation(this, id);
return outAnimation;
}
private static int getPreferencesInteger(
SharedPreferences prefs, String key, int defaultValue) {
String value = prefs.getString(key, null);
try {
return value == null ? defaultValue : Integer.parseInt(value);
} catch (NumberFormatException ex) {
Log.e(TAG, "couldn't parse preference: " + value, ex);
return defaultValue;
}
}
void setMode(int mode) {
if (mMode == mode) {
return;
}
View slideshowPanel = findViewById(R.id.slideShowContainer);
View normalPanel = findViewById(R.id.abs);
Window win = getWindow();
mMode = mode;
if (mo