├── .github └── pull_request_template.md ├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── Art ├── AndroidDraw.png ├── banner.png ├── cover.gif └── cover.png ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── divyanshu │ │ └── androiddraw │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ │ └── com │ │ │ └── divyanshu │ │ │ └── androiddraw │ │ │ ├── DrawAdapter.kt │ │ │ ├── ImageActivity.kt │ │ │ └── MainActivity.kt │ └── res │ │ ├── layout │ │ ├── activity_image.xml │ │ ├── activity_main.xml │ │ ├── dialog_save.xml │ │ └── item_view.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── ic_launcher_background.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── divyanshu │ └── androiddraw │ └── ExampleUnitTest.kt ├── build.gradle ├── draw ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── divyanshu │ │ └── draw │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── divyanshu │ │ │ └── draw │ │ │ ├── activity │ │ │ └── DrawingActivity.kt │ │ │ └── widget │ │ │ ├── Action.kt │ │ │ ├── CircleView.kt │ │ │ ├── DrawView.kt │ │ │ ├── Line.kt │ │ │ ├── Move.kt │ │ │ ├── MyPath.kt │ │ │ ├── PaintOptions.kt │ │ │ └── Quad.kt │ └── res │ │ ├── color │ │ └── icon_color_selector.xml │ │ ├── drawable │ │ ├── circle_black.xml │ │ ├── circle_blue.xml │ │ ├── circle_brown.xml │ │ ├── circle_green.xml │ │ ├── circle_pink.xml │ │ ├── circle_red.xml │ │ ├── circle_yellow.xml │ │ ├── ic_adjust_black_24dp.xml │ │ ├── ic_close_black_24dp.xml │ │ ├── ic_color_lens_black_24dp.xml │ │ ├── ic_done_black_24dp.xml │ │ ├── ic_eraser_black_24dp.xml │ │ ├── ic_opacity_black_24dp.xml │ │ ├── ic_redo_black_24dp.xml │ │ └── ic_undo_black_24dp.xml │ │ ├── layout │ │ ├── activity_drawing.xml │ │ └── color_palette_view.xml │ │ └── values │ │ ├── colors.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── divyanshu │ └── draw │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | closes #issue_number 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Art/AndroidDraw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/Art/AndroidDraw.png -------------------------------------------------------------------------------- /Art/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/Art/banner.png -------------------------------------------------------------------------------- /Art/cover.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/Art/cover.gif -------------------------------------------------------------------------------- /Art/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/Art/cover.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Android Draw [![](https://jitpack.io/v/divyanshub024/AndroidDraw.svg)](https://jitpack.io/#divyanshub024/AndroidDraw) [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-AndroidDraw-green.svg?style=flat )]( https://android-arsenal.com/details/1/7150 ) 4 | 5 | A drawing view for your android application 6 | 7 | 8 | 9 | ### Download 10 | 11 | For information : checkout [Sample App Code](https://github.com/divyanshub024/AndroidDraw/tree/master/app) in repository. 12 | 13 | Get it on Google Play 14 | 15 | ## Dependency 16 | 17 | *Step 1*. Add the JitPack repository to your build file 18 | 19 | Add it in your root build.gradle at the end of repositories: 20 | 21 | ```gradle 22 | allprojects { 23 | repositories { 24 | ... 25 | maven { url 'https://jitpack.io' } 26 | } 27 | } 28 | ``` 29 | 30 | 31 | *Step 2*. Add the dependency 32 | 33 | ```gradle 34 | dependencies { 35 | implementation 'com.github.divyanshub024:AndroidDraw:v0.1' 36 | } 37 | 38 | ``` 39 | ## Usage 40 | 41 | There are two ways to use this library. 42 | 43 | ### 1. Use Activity 44 | 45 | You can call the `Drawing Activity` using `startActivityForResult` which will return you bitmap in byteArray. By using this method you will have all the features like change strokeWidth, change strokeColor, change Alpha, erase, redo, undo. 46 | 47 | ```kotlin 48 | val intent = Intent(this, DrawingActivity::class.java) 49 | startActivityForResult(intent, REQUEST_CODE_DRAW) 50 | 51 | // Get bitmap in onActivityResult 52 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 53 | if (data != null && resultCode == Activity.RESULT_OK) { 54 | when(requestCode){ 55 | REQUEST_CODE_DRAW -> { 56 | val result= data.getByteArrayExtra("bitmap") 57 | val bitmap = BitmapFactory.decodeByteArray(result, 0, result.size) 58 | saveImage(bitmap) 59 | } 60 | } 61 | } 62 | } 63 | ``` 64 | ### 2.Use DrawView 65 | 66 | #### Declaration 67 | ```xml 68 | 72 | ``` 73 | 74 | - To clear canvas 75 | ``` 76 | draw_view.clearCanvas() 77 | ``` 78 | - To set stroke width 79 | ```kotlin 80 | // takes input as Float 81 | draw_view.setStrokeWidth(strokeWidth) 82 | ``` 83 | - To set stroke alpha 84 | ```kotlin 85 | // takes input as Int 86 | draw_view.setAlpha(progress) 87 | ``` 88 | - To set stroke color 89 | ``` 90 | draw_view.setColor(color) 91 | ``` 92 | - To undo 93 | ``` 94 | draw_view.undo() 95 | ``` 96 | 97 | - To redo 98 | ``` 99 | draw_view.redo() 100 | ``` 101 | 102 | ## Contributor 103 | Thanks [Arslan Şahin](https://github.com/Arslanshn) for this amazing logo. 104 | 105 | ## Connect 106 | - [Twitter](https://twitter.com/divyanshub024) 107 | - [Medium](https://medium.com/@divyanshub024) 108 | - [LinkedIn](https://www.linkedin.com/in/divyanshub024/) 109 | 110 | ## LICENCE 111 | ``` 112 | Copyright 2018 Divyanshu Bhargava 113 | 114 | Licensed under the Apache License, Version 2.0 (the "License"); 115 | you may not use this file except in compliance with the License. 116 | You may obtain a copy of the License at 117 | 118 | http://www.apache.org/licenses/LICENSE-2.0 119 | 120 | Unless required by applicable law or agreed to in writing, software 121 | distributed under the License is distributed on an "AS IS" BASIS, 122 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123 | See the License for the specific language governing permissions and 124 | limitations under the License. 125 | ``` 126 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | android { 6 | compileSdkVersion 28 7 | defaultConfig { 8 | applicationId "com.divyanshu.androiddraw" 9 | minSdkVersion 21 10 | targetSdkVersion 28 11 | versionCode 3 12 | versionName "1.0.2" 13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | buildFeatures { 22 | viewBinding true 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(include: ['*.jar'], dir: 'libs') 29 | implementation project(':draw') 30 | 31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 32 | 33 | //AndroidX 34 | implementation 'androidx.appcompat:appcompat:1.0.2' 35 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 36 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 37 | implementation 'androidx.cardview:cardview:1.0.0' 38 | 39 | implementation 'com.google.android.material:material:1.0.0' 40 | 41 | //Annotation 42 | implementation 'com.github.bumptech.glide:glide:4.8.0' 43 | annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1' 44 | 45 | //Test 46 | testImplementation 'junit:junit:4.12' 47 | androidTestImplementation 'androidx.test:runner:1.2.0' 48 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 49 | } 50 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/divyanshu/androiddraw/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.androiddraw 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.divyanshu.androiddraw", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/divyanshu/androiddraw/DrawAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.androiddraw 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.net.Uri 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import android.widget.ImageView 10 | import androidx.recyclerview.widget.RecyclerView 11 | import com.bumptech.glide.Glide 12 | 13 | const val IMAGE_PATH = "image_path" 14 | class DrawAdapter(private val context: Context, private val imageList: ArrayList) : RecyclerView.Adapter(){ 15 | 16 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 17 | val view = LayoutInflater.from(parent.context).inflate(R.layout.item_view,parent,false) 18 | return ViewHolder(view) 19 | } 20 | 21 | override fun getItemCount(): Int { 22 | return imageList.size 23 | } 24 | 25 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 26 | val path = imageList[holder.adapterPosition] 27 | Glide.with(context).load(path).into(holder.drawImage) 28 | holder.drawImage.setOnClickListener { 29 | val intent = Intent(context, ImageActivity::class.java) 30 | intent.putExtra(IMAGE_PATH,path) 31 | context.startActivity(intent) 32 | } 33 | } 34 | 35 | class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { 36 | val drawImage: ImageView = itemView.findViewById(R.id.image_draw) 37 | } 38 | 39 | fun addItem(uri: Uri){ 40 | imageList.add(uri.toString()) 41 | notifyItemInserted(imageList.size-1) 42 | } 43 | } -------------------------------------------------------------------------------- /app/src/main/java/com/divyanshu/androiddraw/ImageActivity.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.androiddraw 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import com.bumptech.glide.Glide 6 | import com.divyanshu.androiddraw.databinding.ActivityImageBinding 7 | 8 | class ImageActivity : AppCompatActivity() { 9 | private lateinit var binding: ActivityImageBinding 10 | 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | binding = ActivityImageBinding.inflate(layoutInflater) 14 | val view = binding.root 15 | setContentView(view) 16 | val path = intent.getStringExtra(IMAGE_PATH) 17 | Glide.with(this).load(path).into(binding.imageView) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/divyanshu/androiddraw/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.androiddraw 2 | 3 | import android.Manifest 4 | import android.app.Activity 5 | import android.app.AlertDialog 6 | import android.content.DialogInterface 7 | import android.content.Intent 8 | import android.content.pm.PackageManager 9 | import android.graphics.Bitmap 10 | import android.graphics.BitmapFactory 11 | import android.net.Uri 12 | import androidx.appcompat.app.AppCompatActivity 13 | import android.os.Bundle 14 | import android.os.Environment 15 | import androidx.core.app.ActivityCompat 16 | import androidx.core.content.ContextCompat 17 | import android.util.Log 18 | import android.view.WindowManager 19 | import android.widget.EditText 20 | import com.divyanshu.androiddraw.databinding.ActivityMainBinding 21 | import com.divyanshu.draw.activity.DrawingActivity 22 | import java.io.File 23 | import java.io.FileOutputStream 24 | import java.util.* 25 | import kotlin.collections.ArrayList 26 | 27 | private const val REQUEST_CODE_DRAW = 101 28 | private const val PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 102 29 | class MainActivity : AppCompatActivity() { 30 | 31 | lateinit var adapter: DrawAdapter 32 | private lateinit var binding: ActivityMainBinding 33 | 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | binding = ActivityMainBinding.inflate(layoutInflater) 37 | val view = binding.root 38 | setContentView(view) 39 | 40 | if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) 41 | != PackageManager.PERMISSION_GRANTED){ 42 | ActivityCompat.requestPermissions(this, 43 | arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 44 | PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE) 45 | }else{ 46 | adapter = DrawAdapter(this,getFilesPath()) 47 | binding.recyclerView.adapter = adapter 48 | } 49 | binding.fabAddDraw.setOnClickListener { 50 | val intent = Intent(this, DrawingActivity::class.java) 51 | startActivityForResult(intent, REQUEST_CODE_DRAW) 52 | } 53 | } 54 | 55 | private fun getFilesPath(): ArrayList{ 56 | val resultList = ArrayList() 57 | val imageDir = "${Environment.DIRECTORY_PICTURES}/Android Draw/" 58 | val path = Environment.getExternalStoragePublicDirectory(imageDir) 59 | path.mkdirs() 60 | val imageList = path.listFiles() 61 | for (imagePath in imageList){ 62 | resultList.add(imagePath.absolutePath) 63 | } 64 | return resultList 65 | } 66 | 67 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 68 | if (data != null && resultCode == Activity.RESULT_OK) { 69 | when(requestCode){ 70 | REQUEST_CODE_DRAW -> { 71 | val result= data.getByteArrayExtra("bitmap") 72 | val bitmap = BitmapFactory.decodeByteArray(result, 0, result!!.size) 73 | showSaveDialog(bitmap) 74 | } 75 | } 76 | } 77 | } 78 | 79 | private fun showSaveDialog(bitmap: Bitmap) { 80 | val alertDialog = AlertDialog.Builder(this) 81 | val dialogView = layoutInflater.inflate(R.layout.dialog_save, null) 82 | alertDialog.setView(dialogView) 83 | val fileNameEditText: EditText = dialogView.findViewById(R.id.editText_file_name) 84 | val filename = UUID.randomUUID().toString() 85 | fileNameEditText.setSelectAllOnFocus(true) 86 | fileNameEditText.setText(filename) 87 | alertDialog.setTitle("Save Drawing") 88 | .setPositiveButton("ok") { _, _ -> saveImage(bitmap,fileNameEditText.text.toString()) } 89 | .setNegativeButton("Cancel") { _, _ -> } 90 | 91 | val dialog = alertDialog.create() 92 | dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) 93 | dialog.show() 94 | } 95 | 96 | override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { 97 | when(requestCode){ 98 | PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE -> { 99 | if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)){ 100 | adapter = DrawAdapter(this,getFilesPath()) 101 | binding.recyclerView.adapter = adapter 102 | }else{ 103 | finish() 104 | } 105 | return 106 | } 107 | else -> {} 108 | } 109 | } 110 | 111 | private fun saveImage(bitmap: Bitmap, fileName: String) { 112 | val imageDir = "${Environment.DIRECTORY_PICTURES}/Android Draw/" 113 | val path = Environment.getExternalStoragePublicDirectory(imageDir) 114 | Log.e("path",path.toString()) 115 | val file = File(path, "$fileName.png") 116 | path.mkdirs() 117 | file.createNewFile() 118 | val outputStream = FileOutputStream(file) 119 | bitmap.compress(Bitmap.CompressFormat.PNG,100,outputStream) 120 | outputStream.flush() 121 | outputStream.close() 122 | updateRecyclerView(Uri.fromFile(file)) 123 | } 124 | 125 | private fun updateRecyclerView(uri: Uri) { 126 | adapter.addItem(uri) 127 | } 128 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_save.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | #CCCCCC 5 | #000 6 | #212121 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #000000 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Android Draw 3 | Enter file name 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/divyanshu/androiddraw/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.androiddraw 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.5.21' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.2.2' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /draw/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /draw/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | minSdkVersion 19 7 | targetSdkVersion 28 8 | versionCode 1 9 | versionName "1.0" 10 | 11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(include: ['*.jar'], dir: 'libs') 24 | 25 | //AndroidX 26 | implementation 'androidx.appcompat:appcompat:1.0.2' 27 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 28 | 29 | implementation 'com.google.android.material:material:1.0.0' 30 | 31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 32 | 33 | //Test 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test:runner:1.2.0' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | } 38 | 39 | apply plugin: 'kotlin-android' 40 | apply plugin: 'kotlin-android-extensions' 41 | -------------------------------------------------------------------------------- /draw/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /draw/src/androidTest/java/com/divyanshu/draw/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.divyanshu.draw.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /draw/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/activity/DrawingActivity.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.activity 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.content.res.ColorStateList 6 | import android.content.res.Resources 7 | import android.graphics.Bitmap 8 | import androidx.appcompat.app.AppCompatActivity 9 | import android.os.Bundle 10 | import androidx.core.content.res.ResourcesCompat 11 | import androidx.core.widget.ImageViewCompat 12 | import android.util.Log 13 | import android.view.View 14 | import android.widget.SeekBar 15 | import com.divyanshu.draw.R 16 | import com.divyanshu.draw.widget.DrawView 17 | import kotlinx.android.synthetic.main.activity_drawing.* 18 | import kotlinx.android.synthetic.main.color_palette_view.* 19 | import java.io.ByteArrayOutputStream 20 | 21 | class DrawingActivity : AppCompatActivity() { 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | setContentView(R.layout.activity_drawing) 26 | 27 | image_close_drawing.setOnClickListener { 28 | finish() 29 | } 30 | fab_send_drawing.setOnClickListener { 31 | val bStream = ByteArrayOutputStream() 32 | val bitmap = draw_view.getBitmap() 33 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, bStream) 34 | val byteArray = bStream.toByteArray() 35 | val returnIntent = Intent() 36 | returnIntent.putExtra("bitmap", byteArray) 37 | setResult(Activity.RESULT_OK,returnIntent) 38 | finish() 39 | } 40 | 41 | setUpDrawTools() 42 | 43 | colorSelector() 44 | 45 | setPaintAlpha() 46 | 47 | setPaintWidth() 48 | } 49 | 50 | private fun setUpDrawTools() { 51 | circle_view_opacity.setCircleRadius(100f) 52 | image_draw_eraser.setOnClickListener { 53 | draw_view.toggleEraser() 54 | image_draw_eraser.isSelected = draw_view.isEraserOn 55 | toggleDrawTools(draw_tools,false) 56 | } 57 | image_draw_eraser.setOnLongClickListener { 58 | draw_view.clearCanvas() 59 | toggleDrawTools(draw_tools,false) 60 | true 61 | } 62 | image_draw_width.setOnClickListener { 63 | if (draw_tools.translationY == (56).toPx){ 64 | toggleDrawTools(draw_tools,true) 65 | }else if (draw_tools.translationY == (0).toPx && seekBar_width.visibility == View.VISIBLE){ 66 | toggleDrawTools(draw_tools,false) 67 | } 68 | circle_view_width.visibility = View.VISIBLE 69 | circle_view_opacity.visibility = View.GONE 70 | seekBar_width.visibility = View.VISIBLE 71 | seekBar_opacity.visibility = View.GONE 72 | draw_color_palette.visibility = View.GONE 73 | } 74 | image_draw_opacity.setOnClickListener { 75 | if (draw_tools.translationY == (56).toPx){ 76 | toggleDrawTools(draw_tools,true) 77 | }else if (draw_tools.translationY == (0).toPx && seekBar_opacity.visibility == View.VISIBLE){ 78 | toggleDrawTools(draw_tools,false) 79 | } 80 | circle_view_width.visibility = View.GONE 81 | circle_view_opacity.visibility = View.VISIBLE 82 | seekBar_width.visibility = View.GONE 83 | seekBar_opacity.visibility = View.VISIBLE 84 | draw_color_palette.visibility = View.GONE 85 | } 86 | image_draw_color.setOnClickListener { 87 | if (draw_tools.translationY == (56).toPx){ 88 | toggleDrawTools(draw_tools,true) 89 | }else if (draw_tools.translationY == (0).toPx && draw_color_palette.visibility == View.VISIBLE){ 90 | toggleDrawTools(draw_tools,false) 91 | } 92 | circle_view_width.visibility = View.GONE 93 | circle_view_opacity.visibility = View.GONE 94 | seekBar_width.visibility = View.GONE 95 | seekBar_opacity.visibility = View.GONE 96 | draw_color_palette.visibility = View.VISIBLE 97 | } 98 | image_draw_undo.setOnClickListener { 99 | draw_view.undo() 100 | toggleDrawTools(draw_tools,false) 101 | } 102 | image_draw_redo.setOnClickListener { 103 | draw_view.redo() 104 | toggleDrawTools(draw_tools,false) 105 | } 106 | } 107 | 108 | private fun toggleDrawTools(view: View, showView: Boolean = true) { 109 | if (showView){ 110 | view.animate().translationY((0).toPx) 111 | }else{ 112 | view.animate().translationY((56).toPx) 113 | } 114 | } 115 | 116 | private fun colorSelector() { 117 | image_color_black.setOnClickListener { 118 | val color = ResourcesCompat.getColor(resources, R.color.color_black,null) 119 | draw_view.setColor(color) 120 | circle_view_opacity.setColor(color) 121 | circle_view_width.setColor(color) 122 | scaleColorView(image_color_black) 123 | } 124 | image_color_red.setOnClickListener { 125 | val color = ResourcesCompat.getColor(resources, R.color.color_red,null) 126 | draw_view.setColor(color) 127 | circle_view_opacity.setColor(color) 128 | circle_view_width.setColor(color) 129 | scaleColorView(image_color_red) 130 | } 131 | image_color_yellow.setOnClickListener { 132 | val color = ResourcesCompat.getColor(resources, R.color.color_yellow,null) 133 | draw_view.setColor(color) 134 | circle_view_opacity.setColor(color) 135 | circle_view_width.setColor(color) 136 | scaleColorView(image_color_yellow) 137 | } 138 | image_color_green.setOnClickListener { 139 | val color = ResourcesCompat.getColor(resources, R.color.color_green,null) 140 | draw_view.setColor(color) 141 | circle_view_opacity.setColor(color) 142 | circle_view_width.setColor(color) 143 | scaleColorView(image_color_green) 144 | } 145 | image_color_blue.setOnClickListener { 146 | val color = ResourcesCompat.getColor(resources, R.color.color_blue,null) 147 | draw_view.setColor(color) 148 | circle_view_opacity.setColor(color) 149 | circle_view_width.setColor(color) 150 | scaleColorView(image_color_blue) 151 | } 152 | image_color_pink.setOnClickListener { 153 | val color = ResourcesCompat.getColor(resources, R.color.color_pink,null) 154 | draw_view.setColor(color) 155 | circle_view_opacity.setColor(color) 156 | circle_view_width.setColor(color) 157 | scaleColorView(image_color_pink) 158 | } 159 | image_color_brown.setOnClickListener { 160 | val color = ResourcesCompat.getColor(resources, R.color.color_brown,null) 161 | draw_view.setColor(color) 162 | circle_view_opacity.setColor(color) 163 | circle_view_width.setColor(color) 164 | scaleColorView(image_color_brown) 165 | } 166 | } 167 | 168 | private fun scaleColorView(view: View) { 169 | //reset scale of all views 170 | image_color_black.scaleX = 1f 171 | image_color_black.scaleY = 1f 172 | 173 | image_color_red.scaleX = 1f 174 | image_color_red.scaleY = 1f 175 | 176 | image_color_yellow.scaleX = 1f 177 | image_color_yellow.scaleY = 1f 178 | 179 | image_color_green.scaleX = 1f 180 | image_color_green.scaleY = 1f 181 | 182 | image_color_blue.scaleX = 1f 183 | image_color_blue.scaleY = 1f 184 | 185 | image_color_pink.scaleX = 1f 186 | image_color_pink.scaleY = 1f 187 | 188 | image_color_brown.scaleX = 1f 189 | image_color_brown.scaleY = 1f 190 | 191 | //set scale of selected view 192 | view.scaleX = 1.5f 193 | view.scaleY = 1.5f 194 | } 195 | 196 | private fun setPaintWidth() { 197 | seekBar_width.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{ 198 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 199 | draw_view.setStrokeWidth(progress.toFloat()) 200 | circle_view_width.setCircleRadius(progress.toFloat()) 201 | } 202 | 203 | override fun onStartTrackingTouch(seekBar: SeekBar?) {} 204 | 205 | override fun onStopTrackingTouch(seekBar: SeekBar?) {} 206 | }) 207 | } 208 | 209 | private fun setPaintAlpha() { 210 | seekBar_opacity.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener{ 211 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 212 | draw_view.setAlpha(progress) 213 | circle_view_opacity.setAlpha(progress) 214 | } 215 | 216 | override fun onStartTrackingTouch(seekBar: SeekBar?) {} 217 | 218 | override fun onStopTrackingTouch(seekBar: SeekBar?) {} 219 | }) 220 | } 221 | 222 | private val Int.toPx: Float 223 | get() = (this * Resources.getSystem().displayMetrics.density) 224 | } 225 | -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/Action.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.graphics.Path 4 | import java.io.Serializable 5 | import java.io.Writer 6 | 7 | interface Action : Serializable { 8 | fun perform(path: Path) 9 | 10 | fun perform(writer: Writer) 11 | } 12 | -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/CircleView.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.content.Context 4 | import android.graphics.Canvas 5 | import android.graphics.Color 6 | import android.graphics.Paint 7 | import android.util.AttributeSet 8 | import android.view.View 9 | 10 | class CircleView(context: Context, attrs: AttributeSet): View(context, attrs) { 11 | private var mPaint = Paint() 12 | var radius = 8f 13 | 14 | init { 15 | mPaint.apply { 16 | color = Color.BLACK 17 | style = Paint.Style.FILL 18 | } 19 | } 20 | 21 | override fun onDraw(canvas: Canvas) { 22 | super.onDraw(canvas) 23 | 24 | val width = canvas.width.toFloat() 25 | val height = canvas.height.toFloat() 26 | val cX = width.div(2) 27 | val cY = height.div(2) 28 | 29 | canvas.drawCircle(cX, cY, radius/2, mPaint) 30 | } 31 | 32 | fun setCircleRadius(r: Float){ 33 | radius = r 34 | invalidate() 35 | } 36 | 37 | fun setAlpha(newAlpha: Int){ 38 | val alpha = (newAlpha*255)/100 39 | mPaint.alpha = alpha 40 | invalidate() 41 | } 42 | 43 | fun setColor(color: Int){ 44 | mPaint.color = color 45 | invalidate() 46 | } 47 | } -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/DrawView.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.content.Context 4 | import android.graphics.* 5 | import androidx.annotation.ColorInt 6 | import androidx.core.graphics.ColorUtils 7 | import android.util.AttributeSet 8 | import android.view.MotionEvent 9 | import android.view.View 10 | import java.util.LinkedHashMap 11 | 12 | class DrawView @JvmOverloads constructor( 13 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 14 | ) : View(context, attrs, defStyleAttr) { 15 | private var mPaths = LinkedHashMap() 16 | 17 | private var mLastPaths = LinkedHashMap() 18 | private var mUndonePaths = LinkedHashMap() 19 | 20 | private var mPaint = Paint() 21 | private var mPath = MyPath() 22 | private var mPaintOptions = PaintOptions() 23 | 24 | private var mCurX = 0f 25 | private var mCurY = 0f 26 | private var mStartX = 0f 27 | private var mStartY = 0f 28 | private var mIsSaving = false 29 | private var mIsStrokeWidthBarEnabled = false 30 | 31 | var isEraserOn = false 32 | private set 33 | 34 | init { 35 | mPaint.apply { 36 | color = mPaintOptions.color 37 | style = Paint.Style.STROKE 38 | strokeJoin = Paint.Join.ROUND 39 | strokeCap = Paint.Cap.ROUND 40 | strokeWidth = mPaintOptions.strokeWidth 41 | isAntiAlias = true 42 | } 43 | } 44 | 45 | fun undo() { 46 | if (mPaths.isEmpty() && mLastPaths.isNotEmpty()) { 47 | mPaths = mLastPaths.clone() as LinkedHashMap 48 | mLastPaths.clear() 49 | invalidate() 50 | return 51 | } 52 | if (mPaths.isEmpty()) { 53 | return 54 | } 55 | val lastPath = mPaths.values.lastOrNull() 56 | val lastKey = mPaths.keys.lastOrNull() 57 | 58 | mPaths.remove(lastKey) 59 | if (lastPath != null && lastKey != null) { 60 | mUndonePaths[lastKey] = lastPath 61 | } 62 | invalidate() 63 | } 64 | 65 | fun redo() { 66 | if (mUndonePaths.keys.isEmpty()) { 67 | return 68 | } 69 | 70 | val lastKey = mUndonePaths.keys.last() 71 | addPath(lastKey, mUndonePaths.values.last()) 72 | mUndonePaths.remove(lastKey) 73 | invalidate() 74 | } 75 | 76 | fun setColor(newColor: Int) { 77 | @ColorInt 78 | val alphaColor = ColorUtils.setAlphaComponent(newColor, mPaintOptions.alpha) 79 | mPaintOptions.color = alphaColor 80 | if (mIsStrokeWidthBarEnabled) { 81 | invalidate() 82 | } 83 | } 84 | 85 | fun setAlpha(newAlpha: Int) { 86 | val alpha = (newAlpha*255)/100 87 | mPaintOptions.alpha = alpha 88 | setColor(mPaintOptions.color) 89 | } 90 | 91 | fun setStrokeWidth(newStrokeWidth: Float) { 92 | mPaintOptions.strokeWidth = newStrokeWidth 93 | if (mIsStrokeWidthBarEnabled) { 94 | invalidate() 95 | } 96 | } 97 | 98 | fun getBitmap(): Bitmap { 99 | val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) 100 | val canvas = Canvas(bitmap) 101 | canvas.drawColor(Color.WHITE) 102 | mIsSaving = true 103 | draw(canvas) 104 | mIsSaving = false 105 | return bitmap 106 | } 107 | 108 | fun addPath(path: MyPath, options: PaintOptions) { 109 | mPaths[path] = options 110 | } 111 | 112 | override fun onDraw(canvas: Canvas) { 113 | super.onDraw(canvas) 114 | 115 | for ((key, value) in mPaths) { 116 | changePaint(value) 117 | canvas.drawPath(key, mPaint) 118 | } 119 | 120 | changePaint(mPaintOptions) 121 | canvas.drawPath(mPath, mPaint) 122 | } 123 | 124 | private fun changePaint(paintOptions: PaintOptions) { 125 | mPaint.color = if (paintOptions.isEraserOn) Color.WHITE else paintOptions.color 126 | mPaint.strokeWidth = paintOptions.strokeWidth 127 | } 128 | 129 | fun clearCanvas() { 130 | mLastPaths = mPaths.clone() as LinkedHashMap 131 | mPath.reset() 132 | mPaths.clear() 133 | invalidate() 134 | } 135 | 136 | private fun actionDown(x: Float, y: Float) { 137 | mPath.reset() 138 | mPath.moveTo(x, y) 139 | mCurX = x 140 | mCurY = y 141 | } 142 | 143 | private fun actionMove(x: Float, y: Float) { 144 | mPath.quadTo(mCurX, mCurY, (x + mCurX) / 2, (y + mCurY) / 2) 145 | mCurX = x 146 | mCurY = y 147 | } 148 | 149 | private fun actionUp() { 150 | mPath.lineTo(mCurX, mCurY) 151 | 152 | // draw a dot on click 153 | if (mStartX == mCurX && mStartY == mCurY) { 154 | mPath.lineTo(mCurX, mCurY + 2) 155 | mPath.lineTo(mCurX + 1, mCurY + 2) 156 | mPath.lineTo(mCurX + 1, mCurY) 157 | } 158 | 159 | mPaths[mPath] = mPaintOptions 160 | mPath = MyPath() 161 | mPaintOptions = PaintOptions(mPaintOptions.color, mPaintOptions.strokeWidth, mPaintOptions.alpha, mPaintOptions.isEraserOn) 162 | } 163 | 164 | override fun onTouchEvent(event: MotionEvent): Boolean { 165 | val x = event.x 166 | val y = event.y 167 | 168 | when (event.action) { 169 | MotionEvent.ACTION_DOWN -> { 170 | mStartX = x 171 | mStartY = y 172 | actionDown(x, y) 173 | mUndonePaths.clear() 174 | } 175 | MotionEvent.ACTION_MOVE -> actionMove(x, y) 176 | MotionEvent.ACTION_UP -> actionUp() 177 | } 178 | 179 | invalidate() 180 | return true 181 | } 182 | 183 | fun toggleEraser() { 184 | isEraserOn = !isEraserOn 185 | mPaintOptions.isEraserOn = isEraserOn 186 | invalidate() 187 | } 188 | 189 | } -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/Line.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.graphics.Path 4 | import java.io.Writer 5 | import java.security.InvalidParameterException 6 | 7 | class Line(val x: Float, val y: Float) : Action { 8 | 9 | override fun perform(path: Path) { 10 | path.lineTo(x, y) 11 | } 12 | 13 | override fun perform(writer: Writer) { 14 | writer.write("L$x,$y") 15 | } 16 | } -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/Move.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.graphics.Path 4 | import java.io.Writer 5 | import java.security.InvalidParameterException 6 | 7 | class Move(val x: Float, val y: Float) : Action { 8 | 9 | override fun perform(path: Path) { 10 | path.moveTo(x, y) 11 | } 12 | 13 | override fun perform(writer: Writer) { 14 | writer.write("M$x,$y") 15 | } 16 | } -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/MyPath.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.graphics.Path 4 | import java.io.ObjectInputStream 5 | import java.io.Serializable 6 | import java.util.* 7 | 8 | class MyPath : Path(), Serializable { 9 | val actions = LinkedList() 10 | 11 | private fun readObject(inputStream: ObjectInputStream) { 12 | inputStream.defaultReadObject() 13 | 14 | val copiedActions = actions.map { it } 15 | copiedActions.forEach { 16 | it.perform(this) 17 | } 18 | } 19 | 20 | override fun reset() { 21 | actions.clear() 22 | super.reset() 23 | } 24 | 25 | override fun moveTo(x: Float, y: Float) { 26 | actions.add(Move(x, y)) 27 | super.moveTo(x, y) 28 | } 29 | 30 | override fun lineTo(x: Float, y: Float) { 31 | actions.add(Line(x, y)) 32 | super.lineTo(x, y) 33 | } 34 | 35 | override fun quadTo(x1: Float, y1: Float, x2: Float, y2: Float) { 36 | actions.add(Quad(x1, y1, x2, y2)) 37 | super.quadTo(x1, y1, x2, y2) 38 | } 39 | } -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/PaintOptions.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.graphics.Color 4 | 5 | data class PaintOptions(var color: Int = Color.BLACK, var strokeWidth: Float = 8f, var alpha: Int = 255, var isEraserOn: Boolean = false) 6 | -------------------------------------------------------------------------------- /draw/src/main/java/com/divyanshu/draw/widget/Quad.kt: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw.widget 2 | 3 | import android.graphics.Path 4 | import java.io.Writer 5 | 6 | class Quad(private val x1: Float, private val y1: Float, private val x2: Float, private val y2: Float) : Action { 7 | 8 | override fun perform(path: Path) { 9 | path.quadTo(x1, y1, x2, y2) 10 | } 11 | 12 | override fun perform(writer: Writer) { 13 | writer.write("Q$x1,$y1 $x2,$y2") 14 | } 15 | } -------------------------------------------------------------------------------- /draw/src/main/res/color/icon_color_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/circle_black.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/circle_blue.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/circle_brown.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/circle_green.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/circle_pink.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/circle_red.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/circle_yellow.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_adjust_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_close_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_color_lens_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_done_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_eraser_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_opacity_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_redo_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /draw/src/main/res/drawable/ic_undo_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /draw/src/main/res/layout/activity_drawing.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 27 | 28 | 39 | 40 | 50 | 51 | 63 | 64 | 75 | 76 | 87 | 88 | 99 | 100 | 111 | 112 | 123 | 124 | 134 | 135 | 141 | 142 | 152 | 153 | 159 | 160 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /draw/src/main/res/layout/color_palette_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | 20 | 29 | 30 | 39 | 40 | 49 | 50 | 59 | 60 | 69 | 70 | 79 | -------------------------------------------------------------------------------- /draw/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #C2C2C2 4 | #757575 5 | #757575 6 | #FFFFFF 7 | #000 8 | #FF5252 9 | #FFEB3B 10 | #00C853 11 | #00B0FF 12 | #D500F9 13 | #8D6E63 14 | -------------------------------------------------------------------------------- /draw/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Draw 3 | 4 | -------------------------------------------------------------------------------- /draw/src/test/java/com/divyanshu/draw/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.divyanshu.draw; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | # org.gradle.parallel=true 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyanshub024/AndroidDraw/b10a09478e55797248af4e70a60dc982635fd5df/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':draw' 2 | --------------------------------------------------------------------------------