Skip to content

gauravyadav673/HandDraw

Repository files navigation

HandDraw

Android library to add a touch-to-draw view to your Android application. It can also be used for capturing signatures.

Support

Minimum SDK is 21.

Add With Gradle Dependency

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency

implementation 'com.github.gauravyadav673:HandDraw:v2.0'

Add HandDraw to layout

<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.

Customization Through XML

<!-- Change paint color -->
app:paint_color="#ffffff"
<!-- Change stroke width -->
app:paint_width="10f"
<!-- Change background color -->
app:bg_color="#000000"

Example: Full Customization

<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"/>

Access HandDraw from Java

TouchDrawView touchDrawView; // declare

// inside onCreate()
touchDrawView = (TouchDrawView) findViewById(R.id.canvas);

Available API

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>/). No WRITE_EXTERNAL_STORAGE permission is required on Android 10 and above.

How can you contribute?

Contributors are most welcome. You can add comments to the code, report issues or bugs, or contribute on any of the following topics:

  1. Implementing a color picker.
  2. Adding more to this list

About

Android library to add a touch to draw view to your android application.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages