首先在sdcard上放几张jpg格式的图片(美女图片)。。。不然效果出不来的 , 注意必须要美女的相片。如果你是女的 ,必须放csdn男会员的相片,不然效果也出不来
public class Main Activity extends Activity {
GestureDetector gesture;
private static final String TAG = "B";
// private List<Bitmap> bitmaps = new ArrayList<Bitmap>();;
private List<String> filepathName = new ArrayList<String>();
// private Bitmap bm;
// private Matrix matrix;
private Handler handler;
private Runnable runnable;
private static final String URL = "/sdcard";
private static final String tempFile = "/sdcard/temp.txt";
int mCenterX = 160;
int mCenterY = 0;
int i = 0;
ImageView mImageView1;
ImageView mImageView2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File file = new File(tempFile);
if(!file.exists()){
getFiles(URL);
writeFile(tempFile,filepathName);
}
filepathName = readFile(tempFile);
setContentView(R.layout.main);
FlingGuest sg = new FlingGuest(this);
gesture = new GestureDetector(sg);
mImageView1 = (ImageView) findViewById(R.id.image1);
mImageView2 = (ImageView) findViewById(R.id.image2);
mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
}
public void delFile(File file){
if(file.exists()){
file.delete();
}
}
public void getFiles(String path){
System.out.println(path);
String filePath;
String fileName;
String extName;
File file = new File(path);
if(file.isDirectory()){
File[] files = file.listFiles();
for(File f:files){
getFiles(f.getAbsolutePath());
}
}else{
filePath = file.getAbsolutePath();
fileName = file.getName();
extName = fileName.substring(fileName.indexOf(".")+1);
if(extName.equals("jpg")||extName.equals("bmp")||extName.equals("gif")||extName.equals("png")){
filepathName.add(filePath);
}
}
}
public void leftMoveHandle() {
Rotate3d leftAnimation = new Rotate3d(0, -90, 0, 0, mCenterX, mCenterY);
Rotate3d rightAnimation = new Rotate3d(90, 0, 0.0f, 0.0f, mCenterX,mCenterY);
leftAnimation.setFillAfter(true);
leftAnimation.setDuration(1000);
rightAnimation.setFillAfter(true);
rightAnimation.setDuration(1000);
mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
if(i==filepathName.size()-1){
i = -1;
}
i++;
mImageView2.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
mImageView1.startAnimation(leftAnimation);
mImageView2.startAnimation(rightAnimation);
}
public void rightMoveHandle() {
Rotate3d leftAnimation = new Rotate3d(0, 90, 0, 0, mCenterX, mCenterY);
Rotate3d rightAnimation = new Rotate3d(-90, 0, 0.0f, 0.0f, mCenterX,mCenterY);
leftAnimation.setFillAfter(true);
leftAnimation.setDuration(1000);
rightAnimation.setFillAfter(true);
rightAnimation.setDuration(1000);
mImageView1.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
if(i==0){
i = filepathName.size();
}
i--;
mImageView2.setImageBitmap(BitmapFactory.decodeFile(filepathName.get(i)));
mImageView1.startAnimation(leftAnimation);
mImageView2.startAnimation(rightAnimation);
}
// called automatically, any screen action will Triggered it
public boolean onTouchEvent(MotionEvent me) {
return gesture.onTouchEvent(me);
}
@Override
protected void onDestroy() {
filepathName.clear();
super.onDestroy();
}
public void writeFile(String file,List<String> list){
try {
FileWriter fw = new FileWriter(new File(file));
for(String s :list){
fw.write(s, 0, s.length());
fw.write("=");
}
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public List<String> readFile(String filepath){
List<String> list = new ArrayList<String>();
StringBuffer sb = new StringBuffer();
String[] s ;
try {
FileReader fr = new FileReader(new File(filepath));
int length = 0;
while((length=fr.read())!=-1){
sb.append((char)length);
}
s = sb.toString().split("=");
for(int i=0;i<s.length;i++){
list.add(s[i]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
}
要demo的留下邮箱 或者http://download.csdn.net/source/3453268