i just want to share this piece of code that i wrote. I tried searching for a custom crop activity, but most of them leads to the default \"com.android.camera.action.CROP\"
thanks thehippo... but i've solved finding the view by the layout
Uri imageUri = getIntent().getExtras().getParcelable("path");
b = (BitmapDrawable) BitmapDrawable.createFromPath(getRealPathFromURI(imageUri));
myCropView = (CropView) findViewById(R.id.image_preview);
myCropView.setBackground(b);
but now i can't handle the touch event. The rectangle stay still even if i touch the screen...
EDIT: ok, i've made it works. But now, the rectangle move only inside a smaller area, not in the entire image. I suppose that there's something wrong here
private boolean isInImageRange(PointF point) {
// Get image matrix values and place them in an array
float[] f = new float[9];
getImageMatrix().getValues(f);
// Calculate the scaled dimensions
imageScaledWidth = Math.round(getBackground().getIntrinsicWidth() * f[Matrix.MSCALE_X]);
imageScaledHeight = Math.round(getBackground().getIntrinsicHeight() * f[Matrix.MSCALE_Y]);
return (point.x>=(center.x-(imageScaledWidth/2))&&point.x<=(center.x+(imageScaledWidth/2))&&point.y>=(center.y-(imageScaledHeight/2))&&point.y<=(center.y+(imageScaledHeight/2)))?true:false;
}
i've done a little change to make work the code: getBackground() instead of getDrawable
EDIT 2: OK ive got it, i was doing this in the wrong way. You're code is good. To set the image i was using the view.seBackground()...instead of view.setImageDrawable(). Now everything works. Maybe i will only check if it's possible to create a larger area that fires the scaling of the rectangle