// Path: app/src/main/java/com/jiangpeng/android/antrace/Utils.java
// public class Utils {
// 	public static native void threshold(Bitmap input, int t, Bitmap output);
// 	public static native void grayScale(Bitmap input, Bitmap output);
// 	public static native path traceImage(Bitmap input);
// 	public static native void unsharpMask(Bitmap input, Bitmap output);
// 	public static native boolean saveSVG(String filename, int w, int h);
// 	public static native boolean saveDXF(String filename, int w, int h);
// 	public static native boolean savePDF(String filename, int w, int h);
// 	public static native void clearState();
// 	
// 	private static android.content.pm.PackageInfo getPackageInfo(Context context)
// 	{
//         android.content.pm.PackageInfo pi = null;
//         try
//         {
//             String name = context.getPackageName();
//             PackageManager pm = context.getPackageManager();
// 
//             pi = pm.getPackageInfo(name, 0);
//         } catch (Exception err)
//         {
//             return null;
//         }
//         return pi;
//     }
// 	
// 	public static String getCurrentVersionName(Context context)
// 	{
//         android.content.pm.PackageInfo pi = getPackageInfo(context);
//         return pi == null ? "0.0" : pi.versionName;
// 	}
// 
// 	public static DisplayMetrics getDisplayMetrics(Context context)
// 	{
// 	    DisplayMetrics metrics = new DisplayMetrics();
// 	    WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
// 	    wm.getDefaultDisplay().getMetrics(metrics); 
// 	    
// 	    return metrics;
// 	}
// 	
//     public static int getDPI(Context context)
//     {
// 	    DisplayMetrics metrics = getDisplayMetrics(context);
// 	    return metrics.densityDpi;
//     }
//    
// }


import com.jiangpeng.android.antrace.Utils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.RectF;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
	protected static final int NONE = 0;
    protected static final int DRAG = 1;
    protected static final int ZOOM = 2;
    protected static final int ZOOM_SELECTION = 4;
    protected static final int DRAG_SELECTION = 5;
    protected Matrix m_imageToScreen = new Matrix();
    protected Matrix m_screenToImage = new Matrix();
    protected Bitmap m_bitmap = null;
    protected Paint m_paint = new Paint();

    protected static float HitRadius = 40f;
    protected static final float MinSize = 80f;
    protected int m_mode = NONE;
    protected HitTestResult m_hitTest = HitTestResult.None;
    
    // Remember some things for zooming
    protected PointF m_start = new PointF();
    protected PointF m_last = new PointF();
    protected ImageView m_imageView = null;
    protected boolean m_isCropping = false;
    
    public abstract void draw(Canvas c);
    public abstract boolean onTouch(View v, MotionEvent rawEvent);
    public abstract void startCrop();

    public abstract Bitmap getCroppedBitmap();

    public ImageInteraction(ImageView view)
    {
    	m_imageView = view;
// Path: app/src/main/java/com/jiangpeng/android/antrace/Utils.java
// public class Utils {
// 	public static native void threshold(Bitmap input, int t, Bitmap output);
// 	public static native void grayScale(Bitmap input, Bitmap output);
// 	public static native path traceImage(Bitmap input);
// 	public static native void unsharpMask(Bitmap input, Bitmap output);
// 	public static native boolean saveSVG(String filename, int w, int h);
// 	public static native boolean saveDXF(String filename, int w, int h);
// 	public static native boolean savePDF(String filename, int w, int h);
// 	public static native void clearState();
// 	
// 	private static android.content.pm.PackageInfo getPackageInfo(Context context)
// 	{
//         android.content.pm.PackageInfo pi = null;
//         try
//         {
//             String name = context.getPackageName();
//             PackageManager pm = context.getPackageManager();
// 
//             pi = pm.getPackageInfo(name, 0);
//         } catch (Exception err)
//         {
//             return null;
//         }
//         return pi;
//     }
// 	
// 	public static String getCurrentVersionName(Context context)
// 	{
//         android.content.pm.PackageInfo pi = getPackageInfo(context);
//         return pi == null ? "0.0" : pi.versionName;
// 	}
// 
// 	public static DisplayMetrics getDisplayMetrics(Context context)
// 	{
// 	    DisplayMetrics metrics = new DisplayMetrics();
// 	    WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
// 	    wm.getDefaultDisplay().getMetrics(metrics); 
// 	    
// 	    return metrics;
// 	}
// 	
//     public static int getDPI(Context context)
//     {
// 	    DisplayMetrics metrics = getDisplayMetrics(context);
// 	    return metrics.densityDpi;
//     }
//    
// }


// Path: app/src/main/java/com/jiangpeng/android/antrace/Objects/ImageInteraction.java
import com.jiangpeng.android.antrace.Utils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.RectF;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

	protected static final int NONE = 0;
    protected static final int DRAG = 1;
    protected static final int ZOOM = 2;
    protected static final int ZOOM_SELECTION = 4;
    protected static final int DRAG_SELECTION = 5;
    protected Matrix m_imageToScreen = new Matrix();
    protected Matrix m_screenToImage = new Matrix();
    protected Bitmap m_bitmap = null;
    protected Paint m_paint = new Paint();

    protected static float HitRadius = 40f;
    protected static final float MinSize = 80f;
    protected int m_mode = NONE;
    protected HitTestResult m_hitTest = HitTestResult.None;
    
    // Remember some things for zooming
    protected PointF m_start = new PointF();
    protected PointF m_last = new PointF();
    protected ImageView m_imageView = null;
    protected boolean m_isCropping = false;
    
    public abstract void draw(Canvas c);
    public abstract boolean onTouch(View v, MotionEvent rawEvent);
    public abstract void startCrop();

    public abstract Bitmap getCroppedBitmap();

    public ImageInteraction(ImageView view)
    {
    	m_imageView = view;
    	HitRadius = Utils.getDPI(view.getContext()) / 7;