├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── smarttoolfactory
│ │ └── composedrawingapp
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── smarttoolfactory
│ │ │ └── composedrawingapp
│ │ │ ├── DrawMode.kt
│ │ │ ├── DrawingApp.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── gesture
│ │ │ ├── AwaitDragMotionModifier.kt
│ │ │ └── MotionEvent.kt
│ │ │ ├── model
│ │ │ └── PathProperties.kt
│ │ │ └── ui
│ │ │ ├── ColorSelection.kt
│ │ │ ├── menu
│ │ │ └── Menus.kt
│ │ │ └── theme
│ │ │ ├── Color.kt
│ │ │ ├── Shape.kt
│ │ │ ├── Theme.kt
│ │ │ └── Type.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_eraser_black_24dp.xml
│ │ └── ic_launcher_background.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-ldpi
│ │ └── ic_launcher.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
│ │ └── themes.xml
│ └── test
│ └── java
│ └── com
│ └── smarttoolfactory
│ └── composedrawingapp
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
└── intro.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/*
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | .cxx
10 | local.properties
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Smart Tool Factory
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Jetpack Compose Drawing App
2 |
3 | Drawing app written with Jetpack Compose Canvas.Draw to canvas using touch down, move and up events using array of paths to have erase, undo, redo actions and set properties for each path separately.
4 |
5 |
6 |
7 |
8 | ### TODOs:
9 | - [ ] Save and load drawing
10 | - [ ] Record each action to restore Canvas state when a drawing is opened
11 | - [ ] Retrieve drawing output as png or jpg
12 | - [ ] Add circle color picker instead of static color wheel
13 | - [ ] Add option to open an image and draw on it
14 | - [ ] Add option to display layout grid
15 | - [ ] Add option to draw text with properties
16 | - [ ] Add option to draw shapes like circle, rectangle or polygons
17 | - [ ] Add BitmapShader for different type of pencils
18 | - [ ] Add gradient options
19 | - [ ] Add rotation and zoom to drawing
20 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | compileSdk 31
8 |
9 | defaultConfig {
10 | applicationId "com.smarttoolfactory.composedrawingapp"
11 | minSdk 21
12 | targetSdk 31
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | vectorDrawables {
18 | useSupportLibrary true
19 | }
20 | }
21 |
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 | kotlinOptions {
33 | jvmTarget = '1.8'
34 | }
35 | buildFeatures {
36 | compose true
37 | }
38 | composeOptions {
39 | kotlinCompilerExtensionVersion compose_version
40 | }
41 | packagingOptions {
42 | resources {
43 | excludes += '/META-INF/{AL2.0,LGPL2.1}'
44 | }
45 | }
46 | }
47 |
48 | dependencies {
49 |
50 | implementation 'androidx.core:core-ktx:1.7.0'
51 |
52 | // Jetpack Compose
53 | implementation "androidx.compose.ui:ui:$compose_version"
54 | implementation "androidx.compose.ui:ui-tooling:$compose_version"
55 | implementation "androidx.compose.material:material:$compose_version"
56 | implementation "androidx.compose.material:material-icons-extended:$compose_version"
57 | implementation "androidx.compose.runtime:runtime:$compose_version"
58 |
59 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
60 | implementation 'androidx.activity:activity-compose:1.4.0'
61 |
62 | testImplementation 'junit:junit:4.13.2'
63 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
64 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
65 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
66 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
67 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/smarttoolfactory/composedrawingapp/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext
22 | assertEquals("com.smarttoolfactory.composedrawingapp", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/DrawMode.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp
2 |
3 | enum class DrawMode {
4 | Draw, Touch, Erase
5 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/DrawingApp.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp
2 |
3 | import android.graphics.Paint
4 | import android.widget.Toast
5 | import androidx.compose.foundation.Canvas
6 | import androidx.compose.foundation.background
7 | import androidx.compose.foundation.layout.*
8 | import androidx.compose.foundation.shape.RoundedCornerShape
9 | import androidx.compose.runtime.*
10 | import androidx.compose.ui.Modifier
11 | import androidx.compose.ui.draw.shadow
12 | import androidx.compose.ui.geometry.Offset
13 | import androidx.compose.ui.graphics.*
14 | import androidx.compose.ui.graphics.drawscope.DrawScope
15 | import androidx.compose.ui.graphics.drawscope.Stroke
16 | import androidx.compose.ui.input.pointer.consumeDownChange
17 | import androidx.compose.ui.input.pointer.consumePositionChange
18 | import androidx.compose.ui.input.pointer.positionChange
19 | import androidx.compose.ui.platform.LocalContext
20 | import androidx.compose.ui.unit.dp
21 | import com.smarttoolfactory.composedrawingapp.gesture.MotionEvent
22 | import com.smarttoolfactory.composedrawingapp.gesture.dragMotionEvent
23 | import com.smarttoolfactory.composedrawingapp.model.PathProperties
24 | import com.smarttoolfactory.composedrawingapp.ui.menu.DrawingPropertiesMenu
25 | import com.smarttoolfactory.composedrawingapp.ui.theme.backgroundColor
26 |
27 | @Composable
28 | fun DrawingApp(paddingValues: PaddingValues) {
29 |
30 | val context = LocalContext.current
31 |
32 | /**
33 | * Paths that are added, this is required to have paths with different options and paths
34 | * ith erase to keep over each other
35 | */
36 | val paths = remember { mutableStateListOf>() }
37 |
38 | /**
39 | * Paths that are undone via button. These paths are restored if user pushes
40 | * redo button if there is no new path drawn.
41 | *
42 | * If new path is drawn after this list is cleared to not break paths after undoing previous
43 | * ones.
44 | */
45 | val pathsUndone = remember { mutableStateListOf>() }
46 |
47 | /**
48 | * Canvas touch state. [MotionEvent.Idle] by default, [MotionEvent.Down] at first contact,
49 | * [MotionEvent.Move] while dragging and [MotionEvent.Up] when first pointer is up
50 | */
51 | var motionEvent by remember { mutableStateOf(MotionEvent.Idle) }
52 |
53 | /**
54 | * Current position of the pointer that is pressed or being moved
55 | */
56 | var currentPosition by remember { mutableStateOf(Offset.Unspecified) }
57 |
58 | /**
59 | * Previous motion event before next touch is saved into this current position.
60 | */
61 | var previousPosition by remember { mutableStateOf(Offset.Unspecified) }
62 |
63 | /**
64 | * Draw mode, erase mode or touch mode to
65 | */
66 | var drawMode by remember { mutableStateOf(DrawMode.Draw) }
67 |
68 | /**
69 | * Path that is being drawn between [MotionEvent.Down] and [MotionEvent.Up]. When
70 | * pointer is up this path is saved to **paths** and new instance is created
71 | */
72 | var currentPath by remember { mutableStateOf(Path()) }
73 |
74 | /**
75 | * Properties of path that is currently being drawn between
76 | * [MotionEvent.Down] and [MotionEvent.Up].
77 | */
78 | var currentPathProperty by remember { mutableStateOf(PathProperties()) }
79 |
80 | val canvasText = remember { StringBuilder() }
81 | val paint = remember {
82 | Paint().apply {
83 | textSize = 40f
84 | color = Color.Black.toArgb()
85 | }
86 | }
87 |
88 | Column(
89 | modifier = Modifier
90 | .fillMaxSize()
91 | .background(backgroundColor)
92 | ) {
93 |
94 | val drawModifier = Modifier
95 | .padding(8.dp)
96 | .shadow(1.dp)
97 | .fillMaxWidth()
98 | .weight(1f)
99 | .background(Color.White)
100 | // .background(getRandomColor())
101 | .dragMotionEvent(
102 | onDragStart = { pointerInputChange ->
103 | motionEvent = MotionEvent.Down
104 | currentPosition = pointerInputChange.position
105 | pointerInputChange.consumeDownChange()
106 |
107 | },
108 | onDrag = { pointerInputChange ->
109 | motionEvent = MotionEvent.Move
110 | currentPosition = pointerInputChange.position
111 |
112 | if (drawMode == DrawMode.Touch) {
113 | val change = pointerInputChange.positionChange()
114 | println("DRAG: $change")
115 | paths.forEach { entry ->
116 | val path: Path = entry.first
117 | path.translate(change)
118 | }
119 | currentPath.translate(change)
120 | }
121 | pointerInputChange.consumePositionChange()
122 |
123 | },
124 | onDragEnd = { pointerInputChange ->
125 | motionEvent = MotionEvent.Up
126 | pointerInputChange.consumeDownChange()
127 | }
128 | )
129 |
130 | Canvas(modifier = drawModifier) {
131 |
132 | when (motionEvent) {
133 |
134 | MotionEvent.Down -> {
135 | if (drawMode != DrawMode.Touch) {
136 | currentPath.moveTo(currentPosition.x, currentPosition.y)
137 | }
138 |
139 | previousPosition = currentPosition
140 |
141 | }
142 | MotionEvent.Move -> {
143 |
144 | if (drawMode != DrawMode.Touch) {
145 | currentPath.quadraticBezierTo(
146 | previousPosition.x,
147 | previousPosition.y,
148 | (previousPosition.x + currentPosition.x) / 2,
149 | (previousPosition.y + currentPosition.y) / 2
150 |
151 | )
152 | }
153 |
154 | previousPosition = currentPosition
155 | }
156 |
157 | MotionEvent.Up -> {
158 | if (drawMode != DrawMode.Touch) {
159 | currentPath.lineTo(currentPosition.x, currentPosition.y)
160 |
161 | // Pointer is up save current path
162 | // paths[currentPath] = currentPathProperty
163 | paths.add(Pair(currentPath, currentPathProperty))
164 |
165 | // Since paths are keys for map, use new one for each key
166 | // and have separate path for each down-move-up gesture cycle
167 | currentPath = Path()
168 |
169 | // Create new instance of path properties to have new path and properties
170 | // only for the one currently being drawn
171 | currentPathProperty = PathProperties(
172 | strokeWidth = currentPathProperty.strokeWidth,
173 | color = currentPathProperty.color,
174 | strokeCap = currentPathProperty.strokeCap,
175 | strokeJoin = currentPathProperty.strokeJoin,
176 | eraseMode = currentPathProperty.eraseMode
177 | )
178 | }
179 |
180 | // Since new path is drawn no need to store paths to undone
181 | pathsUndone.clear()
182 |
183 | // If we leave this state at MotionEvent.Up it causes current path to draw
184 | // line from (0,0) if this composable recomposes when draw mode is changed
185 | currentPosition = Offset.Unspecified
186 | previousPosition = currentPosition
187 | motionEvent = MotionEvent.Idle
188 | }
189 | else -> Unit
190 | }
191 |
192 | with(drawContext.canvas.nativeCanvas) {
193 |
194 | val checkPoint = saveLayer(null, null)
195 |
196 | paths.forEach {
197 |
198 | val path = it.first
199 | val property = it.second
200 |
201 | if (!property.eraseMode) {
202 | drawPath(
203 | color = property.color,
204 | path = path,
205 | style = Stroke(
206 | width = property.strokeWidth,
207 | cap = property.strokeCap,
208 | join = property.strokeJoin
209 | )
210 | )
211 | } else {
212 |
213 | // Source
214 | drawPath(
215 | color = Color.Transparent,
216 | path = path,
217 | style = Stroke(
218 | width = currentPathProperty.strokeWidth,
219 | cap = currentPathProperty.strokeCap,
220 | join = currentPathProperty.strokeJoin
221 | ),
222 | blendMode = BlendMode.Clear
223 | )
224 | }
225 | }
226 |
227 | if (motionEvent != MotionEvent.Idle) {
228 |
229 | if (!currentPathProperty.eraseMode) {
230 | drawPath(
231 | color = currentPathProperty.color,
232 | path = currentPath,
233 | style = Stroke(
234 | width = currentPathProperty.strokeWidth,
235 | cap = currentPathProperty.strokeCap,
236 | join = currentPathProperty.strokeJoin
237 | )
238 | )
239 | } else {
240 | drawPath(
241 | color = Color.Transparent,
242 | path = currentPath,
243 | style = Stroke(
244 | width = currentPathProperty.strokeWidth,
245 | cap = currentPathProperty.strokeCap,
246 | join = currentPathProperty.strokeJoin
247 | ),
248 | blendMode = BlendMode.Clear
249 | )
250 | }
251 | }
252 | restoreToCount(checkPoint)
253 | }
254 |
255 | // 🔥🔥 This is for debugging
256 | // canvasText.clear()
257 | //
258 | // paths.forEach {
259 | // val path = it.first
260 | // val property = it.second
261 | //
262 | // canvasText.append(
263 | // "pHash: ${path.hashCode()}, " +
264 | // "propHash: ${property.hashCode()}, " +
265 | // "Mode: ${property.eraseMode}\n"
266 | // )
267 | // }
268 | //
269 | // canvasText.append(
270 | // "🔥 pHash: ${currentPath.hashCode()}, " +
271 | // "propHash: ${currentPathProperty.hashCode()}, " +
272 | // "Mode: ${currentPathProperty.eraseMode}\n"
273 | // )
274 | //
275 | // drawText(text = canvasText.toString(), x = 0f, y = 60f, paint)
276 | }
277 |
278 | DrawingPropertiesMenu(
279 | modifier = Modifier
280 | .padding(bottom = 8.dp, start = 8.dp, end = 8.dp)
281 | .shadow(1.dp, RoundedCornerShape(8.dp))
282 | .fillMaxWidth()
283 | .background(Color.White)
284 | .padding(4.dp),
285 | pathProperties = currentPathProperty,
286 | drawMode = drawMode,
287 | onUndo = {
288 | if (paths.isNotEmpty()) {
289 |
290 | val lastItem = paths.last()
291 | val lastPath = lastItem.first
292 | val lastPathProperty = lastItem.second
293 | paths.remove(lastItem)
294 |
295 | pathsUndone.add(Pair(lastPath, lastPathProperty))
296 |
297 | }
298 | },
299 | onRedo = {
300 | if (pathsUndone.isNotEmpty()) {
301 |
302 | val lastPath = pathsUndone.last().first
303 | val lastPathProperty = pathsUndone.last().second
304 | pathsUndone.removeLast()
305 | paths.add(Pair(lastPath, lastPathProperty))
306 | }
307 | },
308 | onPathPropertiesChange = {
309 | motionEvent = MotionEvent.Idle
310 | },
311 | onDrawModeChanged = {
312 | motionEvent = MotionEvent.Idle
313 | drawMode = it
314 | currentPathProperty.eraseMode = (drawMode == DrawMode.Erase)
315 | Toast.makeText(
316 | context, "pathProperty: ${currentPathProperty.hashCode()}, " +
317 | "Erase Mode: ${currentPathProperty.eraseMode}", Toast.LENGTH_SHORT
318 | ).show()
319 | }
320 | )
321 | }
322 | }
323 |
324 |
325 | private fun DrawScope.drawText(text: String, x: Float, y: Float, paint: Paint) {
326 |
327 | val lines = text.split("\n")
328 | // 🔥🔥 There is not a built-in function as of 1.0.0
329 | // for drawing text so we get the native canvas to draw text and use a Paint object
330 | val nativeCanvas = drawContext.canvas.nativeCanvas
331 |
332 | lines.indices.withIndex().forEach { (posY, i) ->
333 | nativeCanvas.drawText(lines[i], x, posY * 40 + y, paint)
334 | }
335 | }
336 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.compose.foundation.layout.PaddingValues
7 | import androidx.compose.foundation.layout.fillMaxSize
8 | import androidx.compose.foundation.layout.padding
9 | import androidx.compose.material.*
10 | import androidx.compose.material.icons.Icons
11 | import androidx.compose.material.icons.filled.Expand
12 | import androidx.compose.runtime.Composable
13 | import androidx.compose.ui.Modifier
14 | import androidx.compose.ui.tooling.preview.Preview
15 | import androidx.compose.ui.unit.dp
16 | import com.smarttoolfactory.composedrawingapp.ui.theme.ComposeDrawingAppTheme
17 | import com.smarttoolfactory.composedrawingapp.ui.theme.backgroundColor
18 | import kotlinx.coroutines.launch
19 |
20 | class MainActivity : ComponentActivity() {
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | super.onCreate(savedInstanceState)
23 | setContent {
24 | ComposeDrawingAppTheme {
25 | // A surface container using the 'background' color from the theme
26 | Surface(
27 | modifier = Modifier.fillMaxSize(),
28 | color = MaterialTheme.colors.background
29 | ) {
30 | Scaffold(
31 |
32 | topBar = {
33 | TopAppBar(
34 | elevation = 2.dp,
35 | backgroundColor = MaterialTheme.colors.surface,
36 | contentColor = MaterialTheme.colors.onSurface,
37 | title = {
38 | Text("Drawing App")
39 | },
40 |
41 | actions = {}
42 | )
43 | }
44 | ) { paddingValues: PaddingValues ->
45 | DrawingApp(paddingValues)
46 | }
47 | }
48 | }
49 | }
50 | }
51 | }
52 |
53 | @Composable
54 | fun Greeting(name: String) {
55 | Text(text = "Hello $name!")
56 | }
57 |
58 | @Preview(showBackground = true)
59 | @Composable
60 | fun DefaultPreview() {
61 | ComposeDrawingAppTheme {
62 | Greeting("Android")
63 | }
64 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/gesture/AwaitDragMotionModifier.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.gesture
2 |
3 | import androidx.compose.foundation.gestures.awaitFirstDown
4 | import androidx.compose.foundation.gestures.awaitTouchSlopOrCancellation
5 | import androidx.compose.foundation.gestures.drag
6 | import androidx.compose.foundation.gestures.forEachGesture
7 | import androidx.compose.ui.Modifier
8 | import androidx.compose.ui.geometry.Offset
9 | import androidx.compose.ui.input.pointer.AwaitPointerEventScope
10 | import androidx.compose.ui.input.pointer.PointerInputChange
11 | import androidx.compose.ui.input.pointer.consumePositionChange
12 | import androidx.compose.ui.input.pointer.pointerInput
13 |
14 | suspend fun AwaitPointerEventScope.awaitDragMotionEvent(
15 | onTouchEvent: (MotionEvent, PointerInputChange) -> Unit
16 | ) {
17 | // Wait for at least one pointer to press down, and set first contact position
18 | val down: PointerInputChange = awaitFirstDown()
19 | onTouchEvent(MotionEvent.Down, down)
20 |
21 | var pointer = down
22 |
23 | // 🔥 Waits for drag threshold to be passed by pointer
24 | // or it returns null if up event is triggered
25 | val change: PointerInputChange? =
26 | awaitTouchSlopOrCancellation(down.id) { change: PointerInputChange, over: Offset ->
27 | // 🔥🔥 If consumePositionChange() is not consumed drag does not
28 | // function properly.
29 | // Consuming position change causes change.positionChanged() to return false.
30 | change.consumePositionChange()
31 | }
32 |
33 | if (change != null) {
34 | // 🔥 Calls awaitDragOrCancellation(pointer) in a while loop
35 | drag(change.id) { pointerInputChange: PointerInputChange ->
36 | pointer = pointerInputChange
37 | onTouchEvent(MotionEvent.Move, pointer)
38 | }
39 |
40 | // All of the pointers are up
41 | onTouchEvent(MotionEvent.Up, pointer)
42 | } else {
43 | // Drag threshold is not passed and last pointer is up
44 | onTouchEvent(MotionEvent.Up, pointer)
45 | }
46 | }
47 |
48 | fun Modifier.dragMotionEvent(onTouchEvent: (MotionEvent, PointerInputChange) -> Unit) = this.then(
49 | Modifier.pointerInput(Unit) {
50 | forEachGesture {
51 | awaitPointerEventScope {
52 | awaitDragMotionEvent(onTouchEvent)
53 | }
54 | }
55 | }
56 | )
57 |
58 |
59 | suspend fun AwaitPointerEventScope.awaitDragMotionEvent(
60 | onDragStart: (PointerInputChange) -> Unit = {},
61 | onDrag: (PointerInputChange) -> Unit = {},
62 | onDragEnd: (PointerInputChange) -> Unit = {}
63 | ) {
64 | // Wait for at least one pointer to press down, and set first contact position
65 | val down: PointerInputChange = awaitFirstDown()
66 | onDragStart(down)
67 |
68 | var pointer = down
69 |
70 | // 🔥 Waits for drag threshold to be passed by pointer
71 | // or it returns null if up event is triggered
72 | val change: PointerInputChange? =
73 | awaitTouchSlopOrCancellation(down.id) { change: PointerInputChange, over: Offset ->
74 | // 🔥🔥 If consumePositionChange() is not consumed drag does not
75 | // function properly.
76 | // Consuming position change causes change.positionChanged() to return false.
77 | change.consumePositionChange()
78 | }
79 |
80 | if (change != null) {
81 | // 🔥 Calls awaitDragOrCancellation(pointer) in a while loop
82 | drag(change.id) { pointerInputChange: PointerInputChange ->
83 | pointer = pointerInputChange
84 | onDrag(pointer)
85 | }
86 |
87 | // All of the pointers are up
88 | onDragEnd(pointer)
89 | } else {
90 | // Drag threshold is not passed and last pointer is up
91 | onDragEnd(pointer)
92 | }
93 | }
94 |
95 | fun Modifier.dragMotionEvent(
96 | onDragStart: (PointerInputChange) -> Unit = {},
97 | onDrag: (PointerInputChange) -> Unit = {},
98 | onDragEnd: (PointerInputChange) -> Unit = {}
99 | ) = this.then(
100 | Modifier.pointerInput(Unit) {
101 | forEachGesture {
102 | awaitPointerEventScope {
103 | awaitDragMotionEvent(onDragStart, onDrag, onDragEnd)
104 | }
105 | }
106 | }
107 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/gesture/MotionEvent.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.gesture
2 |
3 | enum class MotionEvent {
4 | Idle, Down, Move, Up
5 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/model/PathProperties.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.model
2 |
3 | import androidx.compose.ui.graphics.Color
4 | import androidx.compose.ui.graphics.StrokeCap
5 | import androidx.compose.ui.graphics.StrokeJoin
6 |
7 | class PathProperties(
8 | var strokeWidth: Float = 10f,
9 | var color: Color = Color.Black,
10 | var alpha: Float = 1f,
11 | var strokeCap: StrokeCap = StrokeCap.Round,
12 | var strokeJoin: StrokeJoin = StrokeJoin.Round,
13 | var eraseMode: Boolean = false
14 | ) {
15 |
16 | fun copy(
17 | strokeWidth: Float = this.strokeWidth,
18 | color: Color = this.color,
19 | alpha: Float = this.alpha,
20 | strokeCap: StrokeCap = this.strokeCap,
21 | strokeJoin: StrokeJoin = this.strokeJoin,
22 | eraseMode: Boolean = this.eraseMode
23 | ) = PathProperties(
24 | strokeWidth, color, alpha, strokeCap, strokeJoin, eraseMode
25 | )
26 |
27 | fun copyFrom(properties: PathProperties) {
28 | this.strokeWidth = properties.strokeWidth
29 | this.color = properties.color
30 | this.strokeCap = properties.strokeCap
31 | this.strokeJoin = properties.strokeJoin
32 | this.eraseMode = properties.eraseMode
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/ui/ColorSelection.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.ui
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.foundation.layout.*
5 | import androidx.compose.material.*
6 | import androidx.compose.runtime.*
7 | import androidx.compose.ui.Alignment
8 | import androidx.compose.ui.Modifier
9 | import androidx.compose.ui.geometry.Offset
10 | import androidx.compose.ui.graphics.Brush
11 | import androidx.compose.ui.graphics.Color
12 | import androidx.compose.ui.graphics.drawscope.Stroke
13 | import androidx.compose.ui.text.font.FontWeight
14 | import androidx.compose.ui.unit.dp
15 | import androidx.compose.ui.unit.sp
16 | import com.smarttoolfactory.composedrawingapp.ui.theme.gradientColors
17 |
18 | /**
19 | * Simple circle with stroke to show rainbow colors as [Brush.sweepGradient]
20 | */
21 | @Composable
22 | fun ColorWheel(modifier: Modifier = Modifier) {
23 |
24 | Canvas(modifier = modifier) {
25 | val canvasWidth = size.width
26 | val canvasHeight = size.height
27 |
28 | require(canvasWidth == canvasHeight,
29 | lazyMessage = {
30 | print("Canvas dimensions should be equal to each other")
31 | }
32 | )
33 | val cX = canvasWidth / 2
34 | val cY = canvasHeight / 2
35 | val canvasRadius = canvasWidth.coerceAtMost(canvasHeight) / 2f
36 | val center = Offset(cX, cY)
37 | val strokeWidth = canvasRadius * .3f
38 | // Stroke is drawn out of the radius, so it's required to subtract stroke width from radius
39 | val radius = canvasRadius - strokeWidth
40 |
41 | drawCircle(
42 | brush = Brush.sweepGradient(colors = gradientColors, center = center),
43 | radius = radius,
44 | center = center,
45 | style = Stroke(
46 | width = strokeWidth
47 | )
48 | )
49 | }
50 | }
51 |
52 | /**
53 | * Composable that shows a title as initial letter, title color and a Slider to pick color
54 | */
55 | @Composable
56 | fun ColorSlider(
57 | modifier: Modifier,
58 | title: String,
59 | titleColor: Color,
60 | valueRange: ClosedFloatingPointRange = 0f..255f,
61 | rgb: Float,
62 | onColorChanged: (Float) -> Unit
63 | ) {
64 | Row(modifier, verticalAlignment = Alignment.CenterVertically) {
65 |
66 | Text(text = title.substring(0, 1), color = titleColor, fontWeight = FontWeight.Bold)
67 | Spacer(modifier = Modifier.width(8.dp))
68 | Slider(
69 | modifier = Modifier.weight(1f),
70 | value = rgb,
71 | onValueChange = { onColorChanged(it) },
72 | valueRange = valueRange,
73 | onValueChangeFinished = {}
74 | )
75 |
76 | Spacer(modifier = Modifier.width(8.dp))
77 | Text(
78 | text = rgb.toInt().toString(),
79 | color = Color.LightGray,
80 | fontSize = 12.sp,
81 | modifier = Modifier.width(30.dp)
82 | )
83 |
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/ui/menu/Menus.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.ui.menu
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.foundation.background
5 | import androidx.compose.foundation.layout.*
6 | import androidx.compose.foundation.shape.RoundedCornerShape
7 | import androidx.compose.material.*
8 | import androidx.compose.material.icons.Icons
9 | import androidx.compose.material.icons.filled.Brush
10 | import androidx.compose.material.icons.filled.Redo
11 | import androidx.compose.material.icons.filled.TouchApp
12 | import androidx.compose.material.icons.filled.Undo
13 | import androidx.compose.runtime.*
14 | import androidx.compose.ui.Alignment
15 | import androidx.compose.ui.Modifier
16 | import androidx.compose.ui.draw.shadow
17 | import androidx.compose.ui.graphics.Color
18 | import androidx.compose.ui.graphics.Path
19 | import androidx.compose.ui.graphics.StrokeCap
20 | import androidx.compose.ui.graphics.StrokeJoin
21 | import androidx.compose.ui.graphics.drawscope.Stroke
22 | import androidx.compose.ui.platform.LocalDensity
23 | import androidx.compose.ui.res.painterResource
24 | import androidx.compose.ui.text.font.FontWeight
25 | import androidx.compose.ui.unit.dp
26 | import androidx.compose.ui.unit.sp
27 | import androidx.compose.ui.window.Dialog
28 | import com.smarttoolfactory.composedrawingapp.*
29 | import com.smarttoolfactory.composedrawingapp.R
30 | import com.smarttoolfactory.composedrawingapp.model.PathProperties
31 | import com.smarttoolfactory.composedrawingapp.ui.ColorSlider
32 | import com.smarttoolfactory.composedrawingapp.ui.ColorWheel
33 | import com.smarttoolfactory.composedrawingapp.ui.theme.Blue400
34 | import kotlin.math.roundToInt
35 |
36 | @Composable
37 | fun DrawingPropertiesMenu(
38 | modifier: Modifier = Modifier,
39 | pathProperties: PathProperties,
40 | drawMode: DrawMode,
41 | onUndo: () -> Unit,
42 | onRedo: () -> Unit,
43 | onPathPropertiesChange: (PathProperties) -> Unit,
44 | onDrawModeChanged: (DrawMode) -> Unit
45 | ) {
46 |
47 | val properties by rememberUpdatedState(newValue = pathProperties)
48 |
49 | var showColorDialog by remember { mutableStateOf(false) }
50 | var showPropertiesDialog by remember { mutableStateOf(false) }
51 | var currentDrawMode = drawMode
52 |
53 | Row(
54 | modifier = modifier
55 | // .background(getRandomColor())
56 | ,
57 | verticalAlignment = Alignment.CenterVertically,
58 | horizontalArrangement = Arrangement.SpaceEvenly
59 | ) {
60 | IconButton(
61 | onClick = {
62 | currentDrawMode = if (currentDrawMode == DrawMode.Touch) {
63 | DrawMode.Draw
64 | } else {
65 | DrawMode.Touch
66 | }
67 | onDrawModeChanged(currentDrawMode)
68 | }
69 | ) {
70 | Icon(
71 | Icons.Filled.TouchApp,
72 | contentDescription = null,
73 | tint = if (currentDrawMode == DrawMode.Touch) Color.Black else Color.LightGray
74 | )
75 | }
76 | IconButton(
77 | onClick = {
78 | currentDrawMode = if (currentDrawMode == DrawMode.Erase) {
79 | DrawMode.Draw
80 | } else {
81 | DrawMode.Erase
82 | }
83 | onDrawModeChanged(currentDrawMode)
84 | }
85 | ) {
86 | Icon(
87 | painter = painterResource(id = R.drawable.ic_eraser_black_24dp),
88 | contentDescription = null,
89 | tint = if (currentDrawMode == DrawMode.Erase) Color.Black else Color.LightGray
90 | )
91 | }
92 |
93 |
94 | IconButton(onClick = { showColorDialog = !showColorDialog }) {
95 | ColorWheel(modifier = Modifier.size(24.dp))
96 | }
97 |
98 | IconButton(onClick = { showPropertiesDialog = !showPropertiesDialog }) {
99 | Icon(Icons.Filled.Brush, contentDescription = null, tint = Color.LightGray)
100 | }
101 |
102 | IconButton(onClick = {
103 | onUndo()
104 | }) {
105 | Icon(Icons.Filled.Undo, contentDescription = null, tint = Color.LightGray)
106 | }
107 |
108 | IconButton(onClick = {
109 | onRedo()
110 | }) {
111 | Icon(Icons.Filled.Redo, contentDescription = null, tint = Color.LightGray)
112 | }
113 | }
114 |
115 | if (showColorDialog) {
116 | ColorSelectionDialog(
117 | properties.color,
118 | onDismiss = { showColorDialog = !showColorDialog },
119 | onNegativeClick = { showColorDialog = !showColorDialog },
120 | onPositiveClick = { color: Color ->
121 | showColorDialog = !showColorDialog
122 | properties.color = color
123 | }
124 | )
125 | }
126 |
127 | if (showPropertiesDialog) {
128 | PropertiesMenuDialog(properties) {
129 | showPropertiesDialog = !showPropertiesDialog
130 | }
131 | }
132 | }
133 |
134 | @Composable
135 | fun PropertiesMenuDialog(pathOption: PathProperties, onDismiss: () -> Unit) {
136 |
137 | var strokeWidth by remember { mutableStateOf(pathOption.strokeWidth) }
138 | var strokeCap by remember { mutableStateOf(pathOption.strokeCap) }
139 | var strokeJoin by remember { mutableStateOf(pathOption.strokeJoin) }
140 |
141 | Dialog(onDismissRequest = onDismiss) {
142 |
143 | Card(
144 | elevation = 2.dp,
145 | shape = RoundedCornerShape(8.dp),
146 | modifier = Modifier.padding(vertical = 8.dp)
147 | ) {
148 | Column(modifier = Modifier.padding(8.dp)) {
149 |
150 | Text(
151 | text = "Properties",
152 | color = Blue400,
153 | fontSize = 18.sp,
154 | fontWeight = FontWeight.Bold,
155 | modifier = Modifier.padding(start = 12.dp, top = 12.dp)
156 | )
157 |
158 | Canvas(
159 | modifier = Modifier
160 | .padding(horizontal = 24.dp, vertical = 20.dp)
161 | .height(40.dp)
162 | .fillMaxWidth()
163 | ) {
164 | val path = Path()
165 | path.moveTo(0f, size.height / 2)
166 | path.lineTo(size.width, size.height / 2)
167 |
168 | drawPath(
169 | color = pathOption.color,
170 | path = path,
171 | style = Stroke(
172 | width = strokeWidth,
173 | cap = strokeCap,
174 | join = strokeJoin
175 | )
176 | )
177 | }
178 |
179 | Text(
180 | text = "Stroke Width ${strokeWidth.toInt()}",
181 | fontSize = 16.sp,
182 | modifier = Modifier.padding(horizontal = 12.dp)
183 | )
184 |
185 | Slider(
186 | value = strokeWidth,
187 | onValueChange = {
188 | strokeWidth = it
189 | pathOption.strokeWidth = strokeWidth
190 | },
191 | valueRange = 1f..100f,
192 | onValueChangeFinished = {}
193 | )
194 |
195 |
196 | ExposedSelectionMenu(title = "Stroke Cap",
197 | index = when (strokeCap) {
198 | StrokeCap.Butt -> 0
199 | StrokeCap.Round -> 1
200 | else -> 2
201 | },
202 | options = listOf("Butt", "Round", "Square"),
203 | onSelected = {
204 | println("STOKE CAP $it")
205 | strokeCap = when (it) {
206 | 0 -> StrokeCap.Butt
207 | 1 -> StrokeCap.Round
208 | else -> StrokeCap.Square
209 | }
210 |
211 | pathOption.strokeCap = strokeCap
212 |
213 | }
214 | )
215 |
216 | ExposedSelectionMenu(title = "Stroke Join",
217 | index = when (strokeJoin) {
218 | StrokeJoin.Miter -> 0
219 | StrokeJoin.Round -> 1
220 | else -> 2
221 | },
222 | options = listOf("Miter", "Round", "Bevel"),
223 | onSelected = {
224 | println("STOKE JOIN $it")
225 |
226 | strokeJoin = when (it) {
227 | 0 -> StrokeJoin.Miter
228 | 1 -> StrokeJoin.Round
229 | else -> StrokeJoin.Bevel
230 | }
231 |
232 | pathOption.strokeJoin = strokeJoin
233 | }
234 | )
235 | }
236 | }
237 | }
238 | }
239 |
240 |
241 | @Composable
242 | fun ColorSelectionDialog(
243 | initialColor: Color,
244 | onDismiss: () -> Unit,
245 | onNegativeClick: () -> Unit,
246 | onPositiveClick: (Color) -> Unit
247 | ) {
248 | var red by remember { mutableStateOf(initialColor.red * 255) }
249 | var green by remember { mutableStateOf(initialColor.green * 255) }
250 | var blue by remember { mutableStateOf(initialColor.blue * 255) }
251 | var alpha by remember { mutableStateOf(initialColor.alpha * 255) }
252 |
253 | val color = Color(
254 | red = red.roundToInt(),
255 | green = green.roundToInt(),
256 | blue = blue.roundToInt(),
257 | alpha = alpha.roundToInt()
258 | )
259 |
260 | Dialog(onDismissRequest = onDismiss) {
261 |
262 | BoxWithConstraints(
263 | Modifier
264 | .shadow(1.dp, RoundedCornerShape(8.dp))
265 | .background(Color.White)
266 | ) {
267 |
268 | val widthInDp = LocalDensity.current.run { maxWidth }
269 |
270 |
271 | Column(horizontalAlignment = Alignment.CenterHorizontally) {
272 |
273 | Text(
274 | text = "Color",
275 | color = Blue400,
276 | fontSize = 18.sp,
277 | fontWeight = FontWeight.Bold,
278 | modifier = Modifier.padding(top = 12.dp)
279 | )
280 |
281 | // Initial and Current Colors
282 | Row(
283 | modifier = Modifier
284 | .fillMaxWidth()
285 | .padding(horizontal = 50.dp, vertical = 20.dp)
286 | ) {
287 |
288 | Box(
289 | modifier = Modifier
290 | .weight(1f)
291 | .height(40.dp)
292 | .background(
293 | initialColor,
294 | shape = RoundedCornerShape(topStart = 8.dp, bottomStart = 8.dp)
295 | )
296 | )
297 | Box(
298 | modifier = Modifier
299 | .weight(1f)
300 | .height(40.dp)
301 | .background(
302 | color,
303 | shape = RoundedCornerShape(topEnd = 8.dp, bottomEnd = 8.dp)
304 | )
305 | )
306 | }
307 |
308 | ColorWheel(
309 | modifier = Modifier
310 | .width(widthInDp * .8f)
311 | .aspectRatio(1f)
312 | )
313 |
314 | Spacer(modifier = Modifier.height(16.dp))
315 |
316 | // Sliders
317 | ColorSlider(
318 | modifier = Modifier
319 | .padding(start = 12.dp, end = 12.dp)
320 | .fillMaxWidth(),
321 | title = "Red",
322 | titleColor = Color.Red,
323 | rgb = red,
324 | onColorChanged = {
325 | red = it
326 | }
327 | )
328 | Spacer(modifier = Modifier.height(4.dp))
329 | ColorSlider(
330 | modifier = Modifier
331 | .padding(start = 12.dp, end = 12.dp)
332 | .fillMaxWidth(),
333 | title = "Green",
334 | titleColor = Color.Green,
335 | rgb = green,
336 | onColorChanged = {
337 | green = it
338 | }
339 | )
340 | Spacer(modifier = Modifier.height(4.dp))
341 |
342 | ColorSlider(
343 | modifier = Modifier
344 | .padding(start = 12.dp, end = 12.dp)
345 | .fillMaxWidth(),
346 | title = "Blue",
347 | titleColor = Color.Blue,
348 | rgb = blue,
349 | onColorChanged = {
350 | blue = it
351 | }
352 | )
353 |
354 | Spacer(modifier = Modifier.height(4.dp))
355 |
356 | ColorSlider(
357 | modifier = Modifier
358 | .padding(start = 12.dp, end = 12.dp)
359 | .fillMaxWidth(),
360 | title = "Alpha",
361 | titleColor = Color.Black,
362 | rgb = alpha,
363 | onColorChanged = {
364 | alpha = it
365 | }
366 | )
367 | Spacer(modifier = Modifier.height(24.dp))
368 |
369 | // Buttons
370 |
371 | Row(
372 | modifier = Modifier
373 | .fillMaxWidth()
374 | .height(60.dp)
375 | .background(Color(0xffF3E5F5)),
376 | verticalAlignment = Alignment.CenterVertically
377 |
378 | ) {
379 |
380 | TextButton(
381 | onClick = onNegativeClick,
382 | modifier = Modifier
383 | .weight(1f)
384 | .fillMaxHeight()
385 | ) {
386 | Text(text = "CANCEL")
387 | }
388 | TextButton(
389 | modifier = Modifier
390 | .weight(1f)
391 | .fillMaxHeight(),
392 | onClick = {
393 | onPositiveClick(color)
394 | },
395 | ) {
396 | Text(text = "OK")
397 | }
398 | }
399 | }
400 | }
401 | }
402 | }
403 |
404 | /**
405 | * Expandable selection menu
406 | * @param title of the displayed item on top
407 | * @param index index of selected item
408 | * @param options list of [String] options
409 | * @param onSelected lambda to be invoked when an item is selected that returns
410 | * its index.
411 | */
412 | @OptIn(ExperimentalMaterialApi::class)
413 | @Composable
414 | fun ExposedSelectionMenu(
415 | title: String,
416 | index: Int,
417 | options: List,
418 | onSelected: (Int) -> Unit
419 | ) {
420 |
421 | var expanded by remember { mutableStateOf(false) }
422 | var selectedOptionText by remember { mutableStateOf(options[index]) }
423 | var selectedIndex = remember { index }
424 |
425 | ExposedDropdownMenuBox(
426 | modifier = Modifier
427 | .fillMaxWidth()
428 | .padding(vertical = 4.dp),
429 | expanded = expanded,
430 | onExpandedChange = {
431 | expanded = !expanded
432 | }
433 | ) {
434 | TextField(
435 | modifier = Modifier.fillMaxWidth(),
436 | readOnly = true,
437 | value = selectedOptionText,
438 | onValueChange = { },
439 | label = { Text(title) },
440 | trailingIcon = {
441 | ExposedDropdownMenuDefaults.TrailingIcon(
442 | expanded = expanded
443 | )
444 | },
445 | colors = ExposedDropdownMenuDefaults.textFieldColors(
446 | backgroundColor = Color.White,
447 | focusedIndicatorColor = Color.Transparent,
448 | unfocusedIndicatorColor = Color.Transparent,
449 | disabledIndicatorColor = Color.Transparent,
450 | )
451 | )
452 | ExposedDropdownMenu(
453 | modifier = Modifier.fillMaxWidth(),
454 | expanded = expanded,
455 | onDismissRequest = {
456 | expanded = false
457 |
458 | }
459 | ) {
460 | options.forEachIndexed { index: Int, selectionOption: String ->
461 | DropdownMenuItem(
462 | modifier = Modifier.fillMaxWidth(),
463 | onClick = {
464 | selectedOptionText = selectionOption
465 | expanded = false
466 | selectedIndex = index
467 | onSelected(selectedIndex)
468 | }
469 | ) {
470 | Text(text = selectionOption)
471 | }
472 | }
473 | }
474 | }
475 | }
476 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple200 = Color(0xFFBB86FC)
6 | val Purple500 = Color(0xFF6200EE)
7 | val Purple700 = Color(0xFF3700B3)
8 | val Teal200 = Color(0xFF03DAC5)
9 |
10 | val backgroundColor = Color(0xffECEFF1)
11 |
12 | val Orange400 = Color(0xffFFA726)
13 | val Blue400 = Color(0xff42A5F5)
14 | val Pink400 = Color(0xffEC407A)
15 | val Green400 = Color(0xff66BB6A)
16 | val Red400 = Color(0xffEF5350)
17 | val Yellow400 = Color(0xffFFEE58)
18 | val Purple400 = Color(0xffAB47BC)
19 | val Brown400 = Color(0xff8D6E63)
20 | val BlueGrey400 = Color(0xff78909C)
21 |
22 | val gradientColors = listOf(
23 | Color.Red,
24 | Color.Magenta,
25 | Color.Blue,
26 | Color.Cyan,
27 | Color.Green,
28 | Color.Yellow,
29 | Color.Red
30 | )
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/ui/theme/Shape.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.ui.theme
2 |
3 | import androidx.compose.foundation.shape.RoundedCornerShape
4 | import androidx.compose.material.Shapes
5 | import androidx.compose.ui.unit.dp
6 |
7 | val Shapes = Shapes(
8 | small = RoundedCornerShape(4.dp),
9 | medium = RoundedCornerShape(4.dp),
10 | large = RoundedCornerShape(0.dp)
11 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.ui.theme
2 |
3 | import androidx.compose.foundation.isSystemInDarkTheme
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.darkColors
6 | import androidx.compose.material.lightColors
7 | import androidx.compose.runtime.Composable
8 |
9 | private val DarkColorPalette = darkColors(
10 | primary = Purple200,
11 | primaryVariant = Purple700,
12 | secondary = Teal200
13 | )
14 |
15 | private val LightColorPalette = lightColors(
16 | primary = Purple500,
17 | primaryVariant = Purple700,
18 | secondary = Teal200
19 |
20 | /* Other default colors to override
21 | background = Color.White,
22 | surface = Color.White,
23 | onPrimary = Color.White,
24 | onSecondary = Color.Black,
25 | onBackground = Color.Black,
26 | onSurface = Color.Black,
27 | */
28 | )
29 |
30 | @Composable
31 | fun ComposeDrawingAppTheme(
32 | darkTheme: Boolean = isSystemInDarkTheme(),
33 | content: @Composable () -> Unit
34 | ) {
35 | val colors = if (darkTheme) {
36 | DarkColorPalette
37 | } else {
38 | LightColorPalette
39 | }
40 |
41 | MaterialTheme(
42 | colors = colors,
43 | typography = Typography,
44 | shapes = Shapes,
45 | content = content
46 | )
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/smarttoolfactory/composedrawingapp/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp.ui.theme
2 |
3 | import androidx.compose.material.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontFamily
6 | import androidx.compose.ui.text.font.FontWeight
7 | import androidx.compose.ui.unit.sp
8 |
9 | // Set of Material typography styles to start with
10 | val Typography = Typography(
11 | body1 = TextStyle(
12 | fontFamily = FontFamily.Default,
13 | fontWeight = FontWeight.Normal,
14 | fontSize = 16.sp
15 | )
16 | /* Other default text styles to override
17 | button = TextStyle(
18 | fontFamily = FontFamily.Default,
19 | fontWeight = FontWeight.W500,
20 | fontSize = 14.sp
21 | ),
22 | caption = TextStyle(
23 | fontFamily = FontFamily.Default,
24 | fontWeight = FontWeight.Normal,
25 | fontSize = 12.sp
26 | )
27 | */
28 | )
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_eraser_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffeb3b
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Compose Drawing App
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/smarttoolfactory/composedrawingapp/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.smarttoolfactory.composedrawingapp
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | compose_version = '1.2.0-alpha03'
4 | }
5 | }// Top-level build file where you can add configuration options common to all sub-projects/modules.
6 | plugins {
7 | id 'com.android.application' version '7.1.2' apply false
8 | id 'com.android.library' version '7.1.2' apply false
9 | id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
10 | }
11 |
12 | task clean(type: Delete) {
13 | delete rootProject.buildDir
14 | }
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Feb 25 12:50:10 TRT 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/screenshots/intro.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartToolFactory/Compose-Drawing-App/abb13004ab81042166c6d47a2deffe7fe690602b/screenshots/intro.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "Compose Drawing App"
16 | include ':app'
17 |
--------------------------------------------------------------------------------