package com.szxys.doubleclike;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Matrix;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.provider.ContactsContract.CommonDataKinds.Im;import android.view.View;import android.view.animation.Animation;import android.view.animation.ScaleAnimation;import android.widget.ImageView;public class DoubleClickActivity extends Activity {/** Called when the activity is first created. */private ImageView image;private Bitmap bitmap;private boolean isbig = false;private int count = 2;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);image = (ImageView) findViewById(R.id.image);bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.girl_1);image.setBackgroundResource(R.drawable.girl_1);image.setOnClickListener(new clike());}private long sTime = 0;private long eTime = 0;private Drawable drawable;interface TimeListener{public long getCurrentTime();}class clike implements View.OnClickListener,  TimeListener{@Overridepublic long getCurrentTime() {// TODO Auto-generated method stubreturn System.currentTimeMillis();}@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(sTime!=0&&(getCurrentTime()-sTime>500)){sTime = 0;count=2;}if (!isbig) {--count;if (count > 0) {sTime = getCurrentTime();System.out.println(sTime + "--s--");}if (count == 0) {eTime = getCurrentTime();System.out.println(sTime + "--e--");if ((eTime - sTime) <= 500) {drawable = resizeImage(bitmap,bitmap.getWidth() * 4, bitmap.getHeight() * 4);image.setBackgroundDrawable(drawable);ScaleAnimation animation = new ScaleAnimation(0.25f, 1.0f, 0.25f, 1.0f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);animation.setDuration(500);animation.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation animation) {// TODO Auto-generated method stubisbig = true;sTime = 0;eTime = 0;count = 2;}});image.setAnimation(animation);System.out.println("----------haha--------------");}}}else{--count;if (count > 0) {sTime = getCurrentTime();System.out.println(sTime + "--s--");}if (count == 0) {eTime = getCurrentTime();System.out.println(sTime + "--e--");Drawable Tempdrawable = drawable;final Bitmap bitmap = ((BitmapDrawable)Tempdrawable).getBitmap();if ((eTime - sTime) <= 500) {drawable = resizeImage(bitmap,bitmap.getWidth()/4, bitmap.getHeight()/4);ScaleAnimation animation = new ScaleAnimation(1.0f, 0.25f, 1.0f, 0.25f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f);animation.setDuration(500);animation.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {image.clearAnimation();image.setBackgroundDrawable(drawable);isbig = false;sTime = 0;eTime = 0;count = 2;}});image.setBackgroundDrawable(Tempdrawable);image.setAnimation(animation);System.out.println("----------haha--------------");}}}}}// 压缩图片到指定大小public static Drawable resizeImage(Bitmap bitmap, int w, int h) {Bitmap BitmapOrg = bitmap;int width = BitmapOrg.getWidth();int height = BitmapOrg.getHeight();int newWidth = w;int newHeight = h;float scaleWidth = ((float) newWidth) / width;float scaleHeight = ((float) newHeight) / height;Matrix matrix = new Matrix();matrix.postScale(scaleWidth, scaleHeight);Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,height, matrix, true);return new BitmapDrawable(resizedBitmap);}}

更多相关文章

  1. Android(安卓)删除指定文件代码
  2. Android从相机或相册获取图片裁剪
  3. [Android(安卓)Pro] proguard.cfg 配置文件
  4. Android上实现zlib解压缩的方法 Inflater用法
  5. android中限制EditText中输入指定字符
  6. Android(安卓)drawableleft如何设置图片大小
  7. Intent在Android中的几种用法
  8. Android四种布局
  9. Android(安卓)之shape

随机推荐

  1. (翻译) Android(安卓)Accounts Api使用指
  2. FFmpeg 2.8.4 移植到android平台(二)
  3. Android(安卓)Studio开发工具快捷键
  4. vitamio视频播放报错: java.lang.Unsatis
  5. 【安卓学习总结】安卓开发
  6. Android(安卓)listview适配器
  7. Android(安卓)地址选择器仿京东;
  8. Android中的drawable像素密度适配详解
  9. Android败笔之ListView设置分割线颜色
  10. Android(安卓)- 修改最小SDK版本(minSdkV