I appreciate your suggestions.Thanks!
I wish to elaborate more on this.
Following is the class i modified my class to.. But there are two things that happen now:
1) My Image is gone and is replaced by a blank black screen. (If I remove the ondraw(canvas) method from this class - I am able to see the image on the screen).
2)Doing this I am able to get the XY coordiates on mouse down and up click(can see them in my logs)- but not able to see anything(Rectangle in my case) getting drawn on the screen (might be because of the blank screen)..
I am in a learning mode of this but getting somewhat lost here.
Using java Syntax Highlighting
public class MyView extends ImageView {
public MyView(Context c) {
super(c);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setARGB(255, 255, 255, 255);
}
private final Paint mPaint;
private boolean mCurDown, mCurUp;
float x1=0F,y1=0F,x2=0F,y2=0F;
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
mCurDown = action == MotionEvent.ACTION_DOWN ;
mCurUp = action == MotionEvent.ACTION_UP;
if(mCurDown){
if(!(x1 > 0) && !(y1 > 0)){
x1 = event.getX();
y1 = event.getY();
}
}
if(mCurUp){
if(!(x2 > 0) && !(y2 > 0)){
x2 = event.getX();
y2 = event.getY();
}
}
Log.i("x1",String.valueOf(x1));
Log.i("y1",String.valueOf(y1));
Log.i("x2",String.valueOf(x2));
Log.i("y2",String.valueOf(y2));
Log.i("Draw Canvas...","Draw Canvas...");
return true;
}
protected void onDraw(Canvas canvas)
{
mImageView.setImageResource(resID);
mImageView.setDrawingCacheEnabled(true);
Bitmap bitmap = mImageView.getDrawingCache();
Log.i("Bitmap = ",String.valueOf(bitmap));
if (bitmap != null) {
if (x1 > 0 || x2 > 0 || y1 > 0 || y2 > 0)
canvas.drawRect(x1, y1, x2, y2, mPaint);
mImageView.draw(canvas);
}
}
}
Parsed in 0.042 seconds, using
GeSHi 1.0.8.4
Please pass on any more knowledge/information you can share on this. Thank you - Vishal