Android library to add a touch-to-draw view to your Android application. It can also be used for capturing signatures.
Minimum SDK is 21.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}implementation 'com.github.gauravyadav673:HandDraw:v2.0'<com.raodevs.touchdraw.TouchDrawView
android:id="@+id/canvas"
android:layout_width="match_parent"
android:layout_height="match_parent"/>You can resize and position this view according to your needs.
<!-- Change paint color -->
app:paint_color="#ffffff"
<!-- Change stroke width -->
app:paint_width="10f"
<!-- Change background color -->
app:bg_color="#000000"<com.raodevs.touchdraw.TouchDrawView
android:id="@+id/canvas"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:paint_color="#ffffff"
app:paint_width="10f"
app:bg_color="#000000"/>TouchDrawView touchDrawView; // declare
// inside onCreate()
touchDrawView = (TouchDrawView) findViewById(R.id.canvas);touchDrawView.setPaintColor(Color.MAGENTA); // change paint color
touchDrawView.setBGColor(Color.BLUE); // change background color
touchDrawView.setStrokeWidth(20f); // change stroke width
touchDrawView.clear(); // clear the whole view (can be redone)
touchDrawView.undo(); // undo last stroke
touchDrawView.redo(); // redo last undone stroke
touchDrawView.saveFile(folderName, fileName); // saves as .jpeg to app-scoped external storage
touchDrawView.getFile(); // returns current view as a Bitmap
// Eraser
touchDrawView.setEraserMode(true); // switch to eraser mode
touchDrawView.setEraserMode(false); // switch back to draw mode (restores previous color & width)
touchDrawView.isEraserMode(); // returns true if eraser is currently active
touchDrawView.setEraserWidth(50f); // set eraser stroke width (default 30f)Note:
saveFile()saves to the app's scoped external storage directory (Android/data/<package>/files/<folderName>/). NoWRITE_EXTERNAL_STORAGEpermission is required on Android 10 and above.
Contributors are most welcome. You can add comments to the code, report issues or bugs, or contribute on any of the following topics:
- Implementing a color picker.
- Adding more to this list

