{"id":13645534,"url":"https://github.com/RiccardoMoro/FreeDrawView","last_synced_at":"2025-04-21T14:31:30.237Z","repository":{"id":216205611,"uuid":"74495356","full_name":"RiccardoMoro/FreeDrawView","owner":"RiccardoMoro","description":"A View on which you can freely draw, customizing paint width, alpha and color, and take a screenshot of the content. Useful for note apps, signatures or free hand writing.","archived":false,"fork":false,"pushed_at":"2017-07-21T14:20:07.000Z","size":3420,"stargazers_count":649,"open_issues_count":11,"forks_count":116,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-08-02T01:25:29.945Z","etag":null,"topics":["android","android-library","canvas","custom-view","drawing","signature"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RiccardoMoro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-22T17:07:50.000Z","updated_at":"2024-07-06T05:01:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"fe150f27-14ac-4926-b824-7e0340ec09a2","html_url":"https://github.com/RiccardoMoro/FreeDrawView","commit_stats":null,"previous_names":["riccardomoro/freedrawview"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoMoro%2FFreeDrawView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoMoro%2FFreeDrawView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoMoro%2FFreeDrawView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RiccardoMoro%2FFreeDrawView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RiccardoMoro","download_url":"https://codeload.github.com/RiccardoMoro/FreeDrawView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223868313,"owners_count":17217070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","canvas","custom-view","drawing","signature"],"created_at":"2024-08-02T01:02:36.763Z","updated_at":"2024-11-09T18:31:39.794Z","avatar_url":"https://github.com/RiccardoMoro.png","language":"Java","funding_links":[],"categories":["其他"],"sub_categories":[],"readme":"FreeDrawView\n======\n\n\u003cimg src=\"sample.gif\" title=\"sample\" /\u003e \u003cbr /\u003e\nA View that let you draw freely on it. You can customize paint width, alpha and color. Can be useful for notes app, signatures or hands-free writing\u003cbr /\u003e\u003cbr /\u003e\n\u003cimg src=\"sample_scrollable.gif\" title=\"sample\" /\u003e \u003cbr /\u003e\nThis View works flawlessly inside Scrolling parents like NestedScrollView. Be careful with lists, you need to restore manually the draw state!\u003cbr /\u003e\u003cbr /\u003e\n\u003cimg src=\"sample_rotation.gif\" title=\"sample\" /\u003e \u003cbr /\u003e\nAlso supports state-restore on rotation, with custom behaviours like \"clear, crop or fitXY\" and you can take a screenshot (given to you as a Bitmap Object) of the View drawn content\u003cbr /\u003e\n\n[Changelog](CHANGELOG.md)\u003cbr /\u003e\n\nYou can try the demo app on google play store. \u003cbr /\u003e\ncoming soon \u003cbr /\u003e \u003cbr /\u003e\nOr see the full video demo on YouTube. \u003cbr /\u003e\nhttps://youtu.be/ejEdq4lnPjc \u003cbr /\u003e \u003cbr /\u003e\n\nDownload\n------\n#### Gradle:\n```groovy\ncompile 'com.rm:freedrawview:1.1.2'\n```\n\n\u003cbr /\u003e\n\u003cb\u003eMin SDK version: 9 (Android 2.3) \u003c/b\u003e\n\u003cbr /\u003e\n\n## Usage\n\nTo use this library, just add this inside your layout file\n\n```xml\n    \u003ccom.rm.freedrawview.FreeDrawView\n                    android:id=\"@+id/your_id\"\n                    android:layout_width=\"match_parent\"\n                    android:layout_height=\"match_parent\"\n                    android:background=\"@color/white\"\n\n                    app:paintAlpha=\"255\"\n                    app:paintColor=\"@color/black\"\n                    app:paintWidth=\"4dp\"\n                    app:resizeBehaviour=\"crop\"/\u003e\n```\n\n... if you need to use this View's custom xml attributes (shown in a table below or in the example above) do not forget to add this to your root layout\n```\nxmlns:app=\"http://schemas.android.com/apk/res-auto\"\n```\n\nAnd this in your Activity\n```java\npublic class MainActivity extends AppCompatActivity {\n    FreeDrawView mSignatureView;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        mSignatureView = (FreeDrawView) findViewById(R.id.your_id);\n\n        // Setup the View\n        mSignatureView.setPaintColor(Color.BLACK);\n        mSignatureView.setPaintWidthPx(getResources.getDimensionPixelSize(R.dimen.paint_width));\n        //mSignatureView.setPaintWidthPx(12);\n        mSignatureView.setPaintWidthDp(getResources.getDimension(R.dimen.paint_width));\n        //mSignatureView.setPaintWidthDp(6);\n        mSignatureView.setPaintAlpha(255);// from 0 to 255\n        mSignatureView.setResizeBehaviour(ResizeBehaviour.CROP);// Must be one of ResizeBehaviour\n                                                                // values;\n\n        // This listener will be notified every time the path done and undone count changes\n        mSignatureView.setPathRedoUndoCountChangeListener(new PathRedoUndoCountChangeListener() {\n                                  @Override\n                                  public void onUndoCountChanged(int undoCount) {\n                                      // The undoCount is the number of the paths that can be undone\n                                  }\n\n                                  @Override\n                                  public void onRedoCountChanged(int redoCount) {\n                                      // The redoCount is the number of path removed that can be redrawn\n                                  }\n                              });\n        // This listener will be notified every time a new path has been drawn\n        mSignatureView.setOnPathDrawnListener(new PathDrawnListener() {\n                    @Override\n                    public void onNewPathDrawn() {\n                        // The user has finished drawing a path\n                    }\n\n                    @Override\n                    public void onPathStart() {\n                        // The user has started drawing a path\n                    }\n                });\n\n        // This will take a screenshot of the current drawn content of the view\n        mSignatureView.getDrawScreenshot(new FreeDrawView.DrawCreatorListener() {\n                                  @Override\n                                  public void onDrawCreated(Bitmap draw) {\n                                      // The draw Bitmap is the drawn content of the View\n                                  }\n\n                                  @Override\n                                  public void onDrawCreationError() {\n                                      // Something went wrong creating the bitmap, should never\n                                      // happen unless the async task has been canceled\n                                  }\n                              });\n    }\n}\n```\n\n#### Save and restore manually the Draw content\nFrom v1.1.0 you can get the current state of the Draw (as a Serializable object) and than restore it:\n```java\n        FreeDrawSerializableState state = mSignatureView.getCurrentViewStateAsSerializable();// This returns a FreeDrawSerializableState (which implements Serializable)\n\n        // Save this \"state\" object into a file or keep it where you want\n\n        mSignatureView.restoreStateFromSerializable(state);// Restore the state of the view\n\n        // Now all the previous paths and points have been restored (including the history)\n```\n\nTo save this Serializable Object inside a file you can take a look at the class [FileHelper](app/src/main/java/com/rm/freedrawsample/FileHelper.java)\n\n\u003cbr /\u003e\n\n#### Supported Attributes\nFreeDrawView\n------\n| XML Attribute                 | Java method                                                     \t| Description                                                                                                     \t| Default value                                      \t                                        |\n|-------------------------\t    |-----------------------------------------------------------------\t|-----------------------------------------------------------------------------------------------------------------\t|---------------------------------------------------------------------------------------------  |\n| paintColor                  \t| setPaintColor(@ColorInt int checked)                              | Set the color of the paint                                                                                      \t| Color.BLACK                                              \t                                    |\n| paintWidth                  \t| setPaintWidthPx(@FloatRange(from = 0) float widthPx)              | Set the width of the paint in pixels \t                                                                            | 4dp                                               \t                                        |\n|                       \t    | setPaintWidthDp(float dp)                                        \t| Set the width of the paint in dp                                                                                  | 4dp                                                \t                                        |\n| paintAlpha            \t    | setPaintAlpha(@IntRange(from = 0, to = 255) int alpha)            | Set the alpha of the paint                                                                                       \t| 255                                                \t                                        |\n| resizeBehaviour        \t    | setResizeBehaviour(ResizeBehaviour newBehaviour)                \t| The behaviour of the view every time it is resized (on rotation for example) one of [clear, fitXY, crop]          | ResizeBehaviour.CROP                          \t                                            |\n\n\u003cbr /\u003e\n\n#### Limitations and TODO\n* Multitouch drawing is currently not supported \u003cbr /\u003e\n* Eraser is not yet implemented \u003cbr /\u003e\n* ~~Manually restore state is not supported~~ \u003cbr /\u003e\n* Get the draw screenshot from a FreeDrawSerializableState without adding the view\n\n\u003cbr /\u003e\n\nAlso, the FreeDrawView class gives some utility methods to handle path history: \u003cbr /\u003e\n* ```public void undoLast()``` \u003cbr /\u003e\n    This method undo the last drawn segment \u003cbr /\u003e \u003cbr /\u003e\n* ```public void redoLast()``` \u003cbr /\u003e\n    This method redraw the last undone segment  \u003cbr /\u003e \u003cbr /\u003e\n* ```public void undoAll()``` \u003cbr /\u003e\n    This method undo all the drawn segments, they can be redone one by one or all in one \u003cbr /\u003e \u003cbr /\u003e\n* ```public void redoAll()``` \u003cbr /\u003e\n    This method redraw all the undone segments \u003cbr /\u003e \u003cbr /\u003e\n* ```public void clearHistory()``` \u003cbr /\u003e\n    This method removes all the history segments (The one that could be redone) \u003cbr /\u003e \u003cbr /\u003e\n* ```public void clearDraw()``` \u003cbr /\u003e\n    This method removes all the current drawn segments, without adding them to the history \u003cbr /\u003e \u003cbr /\u003e\n* ```public void clearDrawAndHistory()``` \u003cbr /\u003e\n    This method removes all the current drawn segments and clears the history \u003cbr /\u003e \u003cbr /\u003e\n* ```public int getPathCount(boolean includeCurrentlyDrawingPath)``` \u003cbr /\u003e\n    This method returns the current number of segments drawn \u003cbr /\u003e \u003cbr /\u003e\n\n\n\u003cbr /\u003e\n\nYou can use: \u003cbr/\u003e\n* ```setOnPathDrawnListener(PathDrawnListener listener)``` \u003cbr /\u003e\nto be notified every time the user starts or finishes drawing a line. \u003cbr /\u003e \u003cbr /\u003e\n* ```setPathRedoUndoCountChangeListener(PathRedoUndoCountChangeListener listener)``` \u003cbr /\u003e\nto be notified when the undo or redo count changes. \u003cbr /\u003e \u003cbr /\u003e\n\nAnd remove them with: \u003cbr/\u003e\n* ```removePathDrawnListener()``` \u003cbr /\u003e\n* ```removePathRedoUndoCountChangeListener()``` \u003cbr /\u003e\n\u003cbr /\u003e\n\nLicense\n--------\n\n    Copyright 2017 Riccardo Moro.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRiccardoMoro%2FFreeDrawView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRiccardoMoro%2FFreeDrawView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRiccardoMoro%2FFreeDrawView/lists"}