I followed this instructions
(https://developer.android.com/codelabs/large-screens/advanced-stylus-support#3
to draw on the Android Tablet screen with Stylus Pen.
I am using a Samsung Tab S6 Lite with S-Pen
I can notice the pressure, tilt and orientation reproduced at the top of the demo.
It’s working fine.
But how can I reproduce this pressure in line stroke of the path in the draw real time?
Because the StylusStates represents all draws in the screen, and if I apply a pressure to stylusStates it will apply to all draws in the screen.
@Composable
@OptIn(ExperimentalComposeUiApi::class)
fun DrawArea(modifier: Modifier = Modifier) {
Canvas(modifier = modifier
.clipToBounds()
.pointerInteropFilter {
viewModel.processMotionEvent(it)
}
) {
with(stylusState) {
drawPath(
path = this.path,
color = Color.Gray,
style = strokeStyle
)
}
}
}
class StylusViewModel : ViewModel() {
...
fun processMotionEvent(motionEvent: MotionEvent): Boolean {
...
else -> return false
}
requestRendering(
StylusState(
tilt = motionEvent.getAxisValue(MotionEvent.AXIS_TILT),
pressure = motionEvent.pressure,
orientation = motionEvent.orientation,
path = createPath()
)
)
I need to apply I think point by point at the moment while drawing. So the drawing will capture all pressure variations and reproduce a real handwrite with different point of pressure while handwriting.
Does any one know how to reproduce this pressure in the line stroke?
Also I tried to apply different color to Paths, but if I apply to StylusStates it will apply to all draws not the new ones.