2

I have implemented the following code. let me know where i have to change the code to draw the point when touch down method start.

Currently the line drawing smoothly while touch MOVE method running. but if i click then the point is not drawing.

I want to draw point while i start the TOUCH DOWN method.

Please give any solution.

    mPaint = new Paint();
        mPaintText = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(Color.BLUE);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(7);

        mCanvas = new Canvas();
        mPath = new Path();



@Override
    public boolean onTouch(View arg0, MotionEvent event) {
        float x = event.getX();
        float y = event.getY();

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:

                 touch_start(x, y);
             invalidate();
                 break;

               case MotionEvent.ACTION_MOVE:
               touch_move(x, y);
            invalidate();
                break;

               case MotionEvent.ACTION_UP:
               touch_up();
           invalidate();

                break;
        }
        return true;
    }


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);

        mCanvas.drawPath(mPath, mPaint);

        Paint newPaint = new Paint(mPaint); // Clones the mPaint object
        mPath = new Path();

    }


@Override
    protected void onDraw(Canvas canvas) {

        canvas.drawPath(mPath, mPaint);

}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
dilipkaklotar
  • 1,469
  • 3
  • 20
  • 28

1 Answers1

0

Try this, Android FingerPaint sample does not draw dot?

Community
  • 1
  • 1
Nouman Bhatti
  • 1,777
  • 4
  • 28
  • 55