// Path: app/src/main/java/com/yuqirong/koku/util/ImageUtils.java
// public class ImageUtils {
//     public static Bitmap getResizeBitmap(String path, int[] imageSize) {
//         BitmapFactory.Options options = new BitmapFactory.Options();
//         options.inJustDecodeBounds = true; // only get bitmap infomation
//         BitmapFactory.decodeFile(path, options);
//         options.inSampleSize = calcSampleSize(options, imageSize);
//         options.inJustDecodeBounds = false;
//         return BitmapFactory.decodeFile(path, options);
//     }
// 
//     private static int calcSampleSize(BitmapFactory.Options options, int[] imageSize) {
//         Log.i("", options.outWidth + "," + imageSize[0] + "\n" + options.outHeight + "," + imageSize[1] + "\n------------\n");
//         int inSampleSize = 1;
//         if (imageSize[0] < options.outWidth || imageSize[1] < options.outHeight) {
//             int widthRadio = Math.round(options.outWidth * 1.0f / imageSize[0]);
//             int heightRadio = Math.round(options.outHeight * 1.0f / imageSize[1]);
//             inSampleSize = Math.min(widthRadio, heightRadio);
//         }
//         return inSampleSize;
//     }
// 
// 
//     public static void getImageViewSize(ImageView imageView, int[] imageSize) {
//         ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
//         imageSize[0] = imageView.getWidth();
//         if (imageSize[0] <= 0) {
//             imageSize[0] = layoutParams.width;
//         }
// 
//         if (imageSize[0] <= 0) {
//             imageSize[0] = getImageViewField(imageView, "mMaxWidth");
//         }
// 
//         if (imageSize[0] <= 0) {
//             DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
//             imageSize[0] = displayMetrics.widthPixels;
//         }
// 
//         imageSize[1] = imageView.getHeight();
//         if (imageSize[1] <= 0) {
//             imageSize[1] = layoutParams.height;
//         }
// 
//         if (imageSize[1] <= 0) {
//             imageSize[1] = getImageViewField(imageView, "mMaxHeight");
//         }
// 
//         if (imageSize[1] <= 0) {
//             DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
//             imageSize[1] = displayMetrics.heightPixels;
//         }
// 
//     }
// 
//     private static int getImageViewField(Object object, String fieldName) {
//         int value = 0;
//         try {
//             Field field = object.getClass().getDeclaredField(fieldName);
//             field.setAccessible(true);
// 
//             int fieldValue = field.getInt(object);
//             if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
//                 value = fieldValue;
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//         return value;
//     }
// 
//     public static void setImageBitmap(ImageView imageView, String imagePath) {
//         //resize image and load image
//         int[] imageSize = new int[2];
//         getImageViewSize(imageView, imageSize);
//         //resize bitmap
//         Bitmap bitmap = ImageUtils.getResizeBitmap(imagePath, imageSize);
//         imageView.setImageBitmap(bitmap);
//     }
// }


import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import com.yuqirong.koku.util.ImageUtils;
        int x1 = (int) (f[0] * 0 + f[1] * 0 + f[2]);
        int y1 = (int) (f[3] * 0 + f[4] * 0 + f[5]);
        int x2 = (int) (f[0] * mBitmap.getWidth() + f[1] * 0 + f[2]);
        int y2 = (int) (f[3] * mBitmap.getWidth() + f[4] * 0 + f[5]);
        int x3 = (int) (f[0] * 0 + f[1] * mBitmap.getHeight() + f[2]);
        int y3 = (int) (f[3] * 0 + f[4] * mBitmap.getHeight() + f[5]);
        int x4 = (int) (f[0] * mBitmap.getWidth() + f[1] * mBitmap.getHeight() + f[2]);
        int y4 = (int) (f[3] * mBitmap.getWidth() + f[4] * mBitmap.getHeight() + f[5]);


        showL("x1:" + x1 + ",y1:" + y1);
        showL("x2:" + x2 + ",y2:" + y2);
        showL("x3:" + x3 + ",y3:" + y3);
        showL("x4:" + x4 + ",y4:" + y4);


        boolean result;
        if (scale > 1) { //放大
            result = true;
        } else { //缩小
            result = x1 + ((centerX-x1)*1f/(x2-x2)) * ( (x2-x1) - (x2-x1)*Math.sqrt(scale)) <= -dp2px(5)   && x2 -  ((centerX-x1)*1f/(x2-x2)) * ( (x2-x1) - (x2-x1)*Math.sqrt(scale)) >= viewWidth + dp2px(5)  ;
        }

        return result;
    }

    public void setImagePath(String imagePath) {
        int[] imageSize = new int[2];
        imageSize[0] = viewWidth;
        imageSize[1] = viewHeight;
// Path: app/src/main/java/com/yuqirong/koku/util/ImageUtils.java
// public class ImageUtils {
//     public static Bitmap getResizeBitmap(String path, int[] imageSize) {
//         BitmapFactory.Options options = new BitmapFactory.Options();
//         options.inJustDecodeBounds = true; // only get bitmap infomation
//         BitmapFactory.decodeFile(path, options);
//         options.inSampleSize = calcSampleSize(options, imageSize);
//         options.inJustDecodeBounds = false;
//         return BitmapFactory.decodeFile(path, options);
//     }
// 
//     private static int calcSampleSize(BitmapFactory.Options options, int[] imageSize) {
//         Log.i("", options.outWidth + "," + imageSize[0] + "\n" + options.outHeight + "," + imageSize[1] + "\n------------\n");
//         int inSampleSize = 1;
//         if (imageSize[0] < options.outWidth || imageSize[1] < options.outHeight) {
//             int widthRadio = Math.round(options.outWidth * 1.0f / imageSize[0]);
//             int heightRadio = Math.round(options.outHeight * 1.0f / imageSize[1]);
//             inSampleSize = Math.min(widthRadio, heightRadio);
//         }
//         return inSampleSize;
//     }
// 
// 
//     public static void getImageViewSize(ImageView imageView, int[] imageSize) {
//         ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
//         imageSize[0] = imageView.getWidth();
//         if (imageSize[0] <= 0) {
//             imageSize[0] = layoutParams.width;
//         }
// 
//         if (imageSize[0] <= 0) {
//             imageSize[0] = getImageViewField(imageView, "mMaxWidth");
//         }
// 
//         if (imageSize[0] <= 0) {
//             DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
//             imageSize[0] = displayMetrics.widthPixels;
//         }
// 
//         imageSize[1] = imageView.getHeight();
//         if (imageSize[1] <= 0) {
//             imageSize[1] = layoutParams.height;
//         }
// 
//         if (imageSize[1] <= 0) {
//             imageSize[1] = getImageViewField(imageView, "mMaxHeight");
//         }
// 
//         if (imageSize[1] <= 0) {
//             DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
//             imageSize[1] = displayMetrics.heightPixels;
//         }
// 
//     }
// 
//     private static int getImageViewField(Object object, String fieldName) {
//         int value = 0;
//         try {
//             Field field = object.getClass().getDeclaredField(fieldName);
//             field.setAccessible(true);
// 
//             int fieldValue = field.getInt(object);
//             if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
//                 value = fieldValue;
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//         return value;
//     }
// 
//     public static void setImageBitmap(ImageView imageView, String imagePath) {
//         //resize image and load image
//         int[] imageSize = new int[2];
//         getImageViewSize(imageView, imageSize);
//         //resize bitmap
//         Bitmap bitmap = ImageUtils.getResizeBitmap(imagePath, imageSize);
//         imageView.setImageBitmap(bitmap);
//     }
// }


// Path: app/src/main/java/com/yuqirong/koku/view/CropImageView.java
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import com.yuqirong.koku.util.ImageUtils;

        int x1 = (int) (f[0] * 0 + f[1] * 0 + f[2]);
        int y1 = (int) (f[3] * 0 + f[4] * 0 + f[5]);
        int x2 = (int) (f[0] * mBitmap.getWidth() + f[1] * 0 + f[2]);
        int y2 = (int) (f[3] * mBitmap.getWidth() + f[4] * 0 + f[5]);
        int x3 = (int) (f[0] * 0 + f[1] * mBitmap.getHeight() + f[2]);
        int y3 = (int) (f[3] * 0 + f[4] * mBitmap.getHeight() + f[5]);
        int x4 = (int) (f[0] * mBitmap.getWidth() + f[1] * mBitmap.getHeight() + f[2]);
        int y4 = (int) (f[3] * mBitmap.getWidth() + f[4] * mBitmap.getHeight() + f[5]);


        showL("x1:" + x1 + ",y1:" + y1);
        showL("x2:" + x2 + ",y2:" + y2);
        showL("x3:" + x3 + ",y3:" + y3);
        showL("x4:" + x4 + ",y4:" + y4);


        boolean result;
        if (scale > 1) { //放大
            result = true;
        } else { //缩小
            result = x1 + ((centerX-x1)*1f/(x2-x2)) * ( (x2-x1) - (x2-x1)*Math.sqrt(scale)) <= -dp2px(5)   && x2 -  ((centerX-x1)*1f/(x2-x2)) * ( (x2-x1) - (x2-x1)*Math.sqrt(scale)) >= viewWidth + dp2px(5)  ;
        }

        return result;
    }

    public void setImagePath(String imagePath) {
        int[] imageSize = new int[2];
        imageSize[0] = viewWidth;
        imageSize[1] = viewHeight;
        mBitmap = ImageUtils.getResizeBitmap(imagePath, imageSize);