I have got no answer for this question on the internet , I'm trying to paint with different colors which the user can choose from , the problem is this drawview is not drawing anything and i don't know how o ad an on touch eraser to erase only the touched point here's the customview :
public class DrawView extends android.support.v7.widget.AppCompatImageView {
private ArrayList<ColouredPaths> mTouches;
// Current used colour
private int mCurrColour;
private Paint mPaint;
private boolean erase=false;
ColouredPaths mPath;
Canvas mCanvas;
public void setErase(boolean isErase){
//set erase true or false
erase=isErase;
}
public void setColor(int colour) {
mCurrColour = colour;
}
public DrawView(Context context) {
super(context);
init();
}
// XML constructor
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
init(); }
private void init() {
mTouches = new ArrayList<>();
mPaint = new Paint();
mPaint.setColor(mCurrColour);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(5);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
}
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
mPath.reset();
// commit the path to our offscreen
mTouches.add(mPath);
// kill this so we don't double draw
mPath.reset();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
mPath=new ColouredPaths(mCurrColour);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
break;
case MotionEvent.ACTION_UP:
touch_up();
break;
}
return super.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas c) {
// Let the image be drawn first
super.onDraw(c);
// Draw your custom points here
for (ColouredPaths p : mTouches) {
mPaint.setColor(p.colour);
c.drawPath(p,mPaint);}}
/**
* Class to store the coordinate and the colour of the point.
*/
private class ColouredPaths extends Path{
int colour;
public ColouredPaths( int colour) {
this.colour = colour;
}
}
}
it will be appreciated if anyone could provide an answer this is my log :
06-14 21:26:03.926 907-1410/? E/hwintelligencewifi: updataApInfo cellid =4190217533
06-14 21:26:03.926 907-1410/? E/hwintelligencewifi: addCurrentApInfo cellid =4190217533
06-14 21:26:03.928 907-1410/? E/hwintelligencewifi: addCurrentApInfo info is already there
06-14 21:26:03.932 907-1410/? E/hwintelligencewifi: inlineAddCurrentApInfo mInfos.size()=31