Shura Capricorn
Shura Capricorn

Reputation: 129

Android: How to change between finger and spen when drawing

I have developed a drawing app. Now I need to add a button that, when it is ON, it only allows drawing on the canvas using the spen and when its off it only allows drawing with fingers on the canvas.

My goal is to avoid messing a drawing when I am using the spen and my hand touches the canvas.

Thanks

Upvotes: 0

Views: 145

Answers (1)

Konrad Krakowiak
Konrad Krakowiak

Reputation: 12365

The answer is in MotionEvent object in method getToolType(int)

This method returns one of values below:

TOOL_TYPE_UNKNOWN
TOOL_TYPE_FINGER
TOOL_TYPE_STYLUS
TOOL_TYPE_MOUSE

There are constants from MotionEvent class.

So you can check the tool type and your button state in some condition which defines that you can draw on canvas.

Upvotes: 1

Related Questions