From 26e51bc628e5cae07fbc5f898e124c40910097b1 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 27 Oct 2019 13:43:43 +0530 Subject: [PATCH] Initial commit --- .gitignore | 14 ++ .idea/.name | 1 + .idea/codeStyles/Project.xml | 122 +++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/gradle.xml | 20 ++ .idea/misc.xml | 14 ++ .idea/runConfigurations.xml | 12 ++ build.gradle | 28 +++ canvasview/.gitignore | 1 + canvasview/build.gradle | 35 ++++ canvasview/consumer-rules.pro | 0 canvasview/proguard-rules.pro | 21 +++ .../canvasview/ExampleInstrumentedTest.kt | 24 +++ canvasview/src/main/AndroidManifest.xml | 2 + .../abhishekkumar/canvasview/CanvasView.kt | 155 ++++++++++++++++ canvasview/src/main/res/values/colors.xml | 5 + canvasview/src/main/res/values/strings.xml | 3 + .../canvasview/ExampleUnitTest.kt | 17 ++ example/.gitignore | 1 + example/build.gradle | 35 ++++ example/proguard-rules.pro | 21 +++ .../canvasview/ExampleInstrumentedTest.kt | 24 +++ example/src/main/AndroidManifest.xml | 21 +++ .../abhishekkumar/canvasview/MainActivity.kt | 40 ++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ example/src/main/res/layout/activity_main.xml | 54 ++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes example/src/main/res/values/colors.xml | 6 + example/src/main/res/values/strings.xml | 6 + example/src/main/res/values/styles.xml | 11 ++ .../canvasview/ExampleUnitTest.kt | 17 ++ gradle.properties | 21 +++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 2 + 49 files changed, 1214 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 build.gradle create mode 100644 canvasview/.gitignore create mode 100644 canvasview/build.gradle create mode 100644 canvasview/consumer-rules.pro create mode 100644 canvasview/proguard-rules.pro create mode 100644 canvasview/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt create mode 100644 canvasview/src/main/AndroidManifest.xml create mode 100644 canvasview/src/main/java/dev/abhishekkumar/canvasview/CanvasView.kt create mode 100644 canvasview/src/main/res/values/colors.xml create mode 100644 canvasview/src/main/res/values/strings.xml create mode 100644 canvasview/src/test/java/dev/abhishekkumar/canvasview/ExampleUnitTest.kt create mode 100644 example/.gitignore create mode 100644 example/build.gradle create mode 100644 example/proguard-rules.pro create mode 100644 example/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt create mode 100644 example/src/main/AndroidManifest.xml create mode 100644 example/src/main/java/dev/abhishekkumar/canvasview/MainActivity.kt create mode 100644 example/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 example/src/main/res/drawable/ic_launcher_background.xml create mode 100644 example/src/main/res/layout/activity_main.xml create mode 100644 example/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 example/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 example/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 example/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 example/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 example/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 example/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 example/src/main/res/values/colors.xml create mode 100644 example/src/main/res/values/strings.xml create mode 100644 example/src/main/res/values/styles.xml create mode 100644 example/src/test/java/dev/abhishekkumar/canvasview/ExampleUnitTest.kt create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..5ffff8f --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +CanvasView \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..88ea3aa --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,122 @@ + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+ + +
+
\ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..c2a245e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..af0bbdd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f729556 --- /dev/null +++ b/build.gradle @@ -0,0 +1,28 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + ext.kotlin_version = '1.3.50' + repositories { + google() + jcenter() + + } + dependencies { + classpath 'com.android.tools.build:gradle:3.5.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/canvasview/.gitignore b/canvasview/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/canvasview/.gitignore @@ -0,0 +1 @@ +/build diff --git a/canvasview/build.gradle b/canvasview/build.gradle new file mode 100644 index 0000000..4986174 --- /dev/null +++ b/canvasview/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +android { + compileSdkVersion 28 + + + defaultConfig { + minSdkVersion 23 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/canvasview/consumer-rules.pro b/canvasview/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/canvasview/proguard-rules.pro b/canvasview/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/canvasview/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/canvasview/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt b/canvasview/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..951c303 --- /dev/null +++ b/canvasview/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package dev.abhishekkumar.canvasview + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("dev.abhishekkumar.canvasview.test", appContext.packageName) + } +} diff --git a/canvasview/src/main/AndroidManifest.xml b/canvasview/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6e05686 --- /dev/null +++ b/canvasview/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/canvasview/src/main/java/dev/abhishekkumar/canvasview/CanvasView.kt b/canvasview/src/main/java/dev/abhishekkumar/canvasview/CanvasView.kt new file mode 100644 index 0000000..0f9b6eb --- /dev/null +++ b/canvasview/src/main/java/dev/abhishekkumar/canvasview/CanvasView.kt @@ -0,0 +1,155 @@ +package dev.abhishekkumar.canvasview + +import android.content.Context +import android.graphics.* +import android.util.AttributeSet +import android.view.MotionEvent +import android.view.View +import android.view.ViewConfiguration +import androidx.core.content.res.ResourcesCompat +import kotlin.math.abs +import android.graphics.Bitmap +import java.io.FileOutputStream +import java.io.IOException +import java.io.File + + +private var STROKE_WIDTH = 12f + +class CanvasView : View { + private lateinit var extraCanvas: Canvas + private lateinit var extraBitmap: Bitmap + + + constructor(context: Context) : super(context) {} + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {} + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( + context, + attrs, + defStyleAttr + ) + + private var colorBackground = ResourcesCompat.getColor(resources, R.color.colorBackground, null) + + fun setColorBackground(color: Int) { + colorBackground = ResourcesCompat.getColor(resources, color, null) + } + + private var drawColor = ResourcesCompat.getColor(resources, R.color.colorPaint, null) + + fun setColorMarker(color: Int) { + drawColor = ResourcesCompat.getColor(resources, color, null) + setPaint() + } + + fun setStrokeWidth(width: Float) { + STROKE_WIDTH = width + setPaint() + } + + fun getBitmap(): Bitmap { + return extraBitmap + } + + fun setBitmap(bitmap: Bitmap) { + extraBitmap = bitmap + } + + fun saveAs(format: Bitmap.CompressFormat, quality: Int, destination: File) { + try { + val fileOutputStream = FileOutputStream(destination) + fileOutputStream.use { out -> + extraBitmap.compress(format, quality, out) + + } + } catch (e: IOException) { + e.printStackTrace() + } + + } + + fun clearView() { + extraCanvas.drawColor(colorBackground) + } + + private fun setPaint(): Paint { + return Paint().apply { + color = drawColor + isAntiAlias = true + isDither = true + style = Paint.Style.STROKE + strokeJoin = Paint.Join.ROUND + strokeCap = Paint.Cap.ROUND + strokeWidth = STROKE_WIDTH + } + } + + private var path = Path() + private var motionTouchEventX = 0f + private var motionTouchEventY = 0f + private var currentX = 0f + private var currentY = 0f + + private fun touchStart() { + path.reset() + path.moveTo(motionTouchEventX, motionTouchEventY) + currentX = motionTouchEventX + currentY = motionTouchEventY + } + + private val touchTolerance = ViewConfiguration.get(context).scaledTouchSlop + + private fun touchMove() { + val dx = abs(motionTouchEventX - currentX) + val dy = abs(motionTouchEventY - currentY) + if (dx >= touchTolerance || dy >= touchTolerance) { + path.quadTo( + currentX, + currentY, + (motionTouchEventX + currentX) / 2, + (motionTouchEventY + currentY) / 2 + ) + currentX = motionTouchEventX + currentY = motionTouchEventY + extraCanvas.drawPath(path, setPaint()) + } + invalidate() + } + + private fun touchUp() { + path.reset() + } + + override fun onTouchEvent(event: MotionEvent?): Boolean { + motionTouchEventX = event!!.x + motionTouchEventY = event.y + + when (event.action) { + MotionEvent.ACTION_DOWN -> touchStart() + MotionEvent.ACTION_MOVE -> touchMove() + MotionEvent.ACTION_UP -> touchUp() + } + return true + + } + + override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) { + super.onSizeChanged(width, height, oldWidth, oldHeight) + if (::extraBitmap.isInitialized) extraBitmap.recycle() + extraBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) + extraCanvas = Canvas(extraBitmap) + extraCanvas.drawColor(colorBackground) + } + + override fun onDraw(canvas: Canvas?) { + super.onDraw(canvas) + canvas!!.drawBitmap(extraBitmap, 0f, 0f, null) + } + + +} + + + diff --git a/canvasview/src/main/res/values/colors.xml b/canvasview/src/main/res/values/colors.xml new file mode 100644 index 0000000..ba98ea4 --- /dev/null +++ b/canvasview/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #FFFFFF + #000000 + diff --git a/canvasview/src/main/res/values/strings.xml b/canvasview/src/main/res/values/strings.xml new file mode 100644 index 0000000..3168a14 --- /dev/null +++ b/canvasview/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + CanvasView + diff --git a/canvasview/src/test/java/dev/abhishekkumar/canvasview/ExampleUnitTest.kt b/canvasview/src/test/java/dev/abhishekkumar/canvasview/ExampleUnitTest.kt new file mode 100644 index 0000000..055ecd1 --- /dev/null +++ b/canvasview/src/test/java/dev/abhishekkumar/canvasview/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package dev.abhishekkumar.canvasview + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/example/.gitignore @@ -0,0 +1 @@ +/build diff --git a/example/build.gradle b/example/build.gradle new file mode 100644 index 0000000..06fe20e --- /dev/null +++ b/example/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "dev.abhishekkumar.canvasview" + minSdkVersion 23 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation project(':canvasview') + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/example/proguard-rules.pro b/example/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/example/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/example/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt b/example/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..91d0ab6 --- /dev/null +++ b/example/src/androidTest/java/dev/abhishekkumar/canvasview/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package dev.abhishekkumar.canvasview + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("dev.abhishekkumar.canvasview", appContext.packageName) + } +} diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f871282 --- /dev/null +++ b/example/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/example/src/main/java/dev/abhishekkumar/canvasview/MainActivity.kt b/example/src/main/java/dev/abhishekkumar/canvasview/MainActivity.kt new file mode 100644 index 0000000..0f50ea0 --- /dev/null +++ b/example/src/main/java/dev/abhishekkumar/canvasview/MainActivity.kt @@ -0,0 +1,40 @@ +package dev.abhishekkumar.canvasview + +import android.graphics.Bitmap +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import kotlinx.android.synthetic.main.activity_main.* +import android.os.Environment.getExternalStorageDirectory +import androidx.core.app.ComponentActivity.ExtraData +import androidx.core.content.ContextCompat.getSystemService +import android.icu.lang.UCharacter.GraphemeClusterBreak.T +import android.os.Environment +import java.io.File + + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + val canvasView = findViewById(R.id.canvasView) + canvasView.setColorBackground(R.color.colorPrimary) + canvasView.setColorMarker(R.color.colorAccent) + canvasView.setStrokeWidth(12f) + clear.setOnClickListener { + canvasView.clearView() + } + saveBtn.setOnClickListener { + val filename = "test.png" + val sd = getExternalStorageDirectory() + val dest = File(sd, filename) + canvasView.saveAs(Bitmap.CompressFormat.PNG, 90, dest) + } + + setImage.setOnClickListener { + imageView.setImageBitmap(canvasView.getBitmap()) + } + + } +} diff --git a/example/src/main/res/drawable-v24/ic_launcher_foreground.xml b/example/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/example/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/example/src/main/res/drawable/ic_launcher_background.xml b/example/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/example/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..4b3cd01 --- /dev/null +++ b/example/src/main/res/layout/activity_main.xml @@ -0,0 +1,54 @@ + + + + + +