Hi I am trying to create a Custom View that takes as well as deletes a picture and looks like the following:
Following operations a view can perform:
- Take a picture (by clicking on the No Image Available sign) -- works
- Delete a picture (by clicking on the red cross) -- works
- Preview a picture
How do I create a listener to find out when the image has been taken by the camera? The location of the image that needs to be taken is known before.
public class artooPicture extends RelativeLayout {
ImageView preview, delete;
String value = Environment.getExternalStorageDirectory() + "/99006796"
+ "_" + ".jpg", suffix;
boolean clicked = false;
public artooPicture(Context context) {
this(context, null);
}
public artooPicture(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public artooPicture(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
((Activity) getContext()).getLayoutInflater().inflate(R.layout.picture,
this, true);
delete = (ImageView) findViewById(R.id.scan_delete);
preview = (ImageView) findViewById(R.id.scan_preview);
File f = new File(value);
if (f.exists()) {
clicked = true;
preview.setImageDrawable(BitmapDrawable.createFromPath(value));
} else {
}
delete.setOnClickListener(deleteListener);
preview.setOnClickListener(previewListener);
}
View.OnClickListener deleteListener = new OnClickListener() {
@Override
public void onClick(View v) {
if(clicked){
File f = new File(value);
f.delete();
preview.setImageResource(R.drawable.no_image);
}
clicked = false;
}
};
View.OnClickListener previewListener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(value)));
getContext().startActivity(i);
}
};
}