├── .gitignore
├── .idea
├── .gitignore
├── compiler.xml
├── gradle.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── jarRepositories.xml
├── misc.xml
└── vcs.xml
├── LICENSE.txt
├── README.md
├── SECURITY.md
├── build.gradle.kts
├── composeqrcode
├── .gitignore
├── build.gradle.kts
├── gradle.properties
└── src
│ └── main
│ └── java
│ └── com
│ └── lightspark
│ └── composeqr
│ ├── DotShape.kt
│ ├── Examples.kt
│ ├── FinderSquareDrawing.kt
│ ├── QrCodeColors.kt
│ ├── QrCodeView.kt
│ └── QrEncoder.kt
├── docs
└── images
│ ├── boring.png
│ ├── dark_smile_circle.png
│ ├── light_smile_square.png
│ ├── lightning.png
│ └── purple_and_gold.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── scripts
└── versions.main.kts
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2023 Lightspark Group, Inc.
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Compose QR Code
2 |
3 | [](https://central.sonatype.com/artifact/com.lightspark/compose-qr-code/1.0.1)
4 |
5 | __A simple, flexible QR code renderer for Jetpack Compose - by *Lightspark*__
6 |
7 | | | | | |
8 | |------------------------------------------------------------------------------|------------------------------------------------------------------------|---------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
9 |
10 | ## Usage
11 |
12 | First install it from Maven Central:
13 |
14 | Groovy:
15 | ```groovy
16 | dependencies {
17 | implementation "com.lightspark:compose-qr-code:1.0.1"
18 | }
19 | ```
20 | kts:
21 | ```kotlin
22 | dependencies {
23 | implementation("com.lightspark:compose-qr-code:1.0.1")
24 | }
25 | ```
26 |
27 | Then, use it in your code! Here's a plain ol' boring QR Code:
28 |
29 |
30 |
31 |
32 |
33 | ```kotlin
34 | @Composable
35 | fun BoringPreview() {
36 | QrCodeView(
37 | data = "https://github.com/lightsparkdev/compose-qr-code",
38 | modifier = Modifier.size(300.dp)
39 | )
40 | }
41 | ```
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Meh... Let's spice it up a bit with a smiley face overlay:
51 |
52 |
53 |
54 |
55 |
56 | ```kotlin
57 | @Composable
58 | fun SmileyPreview() {
59 | QrCodeView(
60 | data = "https://github.com/lightsparkdev/compose-qr-code",
61 | modifier = Modifier.size(300.dp)
62 | ) {
63 | Smile(
64 | modifier = Modifier.fillMaxSize(),
65 | backgroundColor = Color.Yellow,
66 | smileColor = Color.Black
67 | )
68 | }
69 | }
70 | ```
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | Cool, I guess we're getting somewhere. What about dark mode? Maybe we can also add some style with
80 | circular dots in the qr code...
81 |
82 |
83 |
84 |
85 |
86 | ```kotlin
87 | @Composable
88 | fun SmileyDarkPreview() {
89 | QrCodeView(
90 | data = "https://github.com/lightsparkdev/compose-qr-code",
91 | modifier = Modifier.size(300.dp),
92 | colors = QrCodeColors(
93 | background = Color.Black,
94 | foreground = Color.White
95 | ),
96 | dotShape = DotShape.Circle
97 | ) {
98 | Box(
99 | contentAlignment = Alignment.Center,
100 | modifier = Modifier
101 | .fillMaxSize()
102 | .clip(RoundedCornerShape(8.dp))
103 | .background(Color.White)
104 | .padding(8.dp)
105 | .clip(RoundedCornerShape(8.dp))
106 | .background(Color.Green)
107 | ) {
108 | Smile(modifier = Modifier.fillMaxSize(0.5f))
109 | }
110 | }
111 | }
112 | ```
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | That's not bad! Let's add some even cooler styles, though. *cracks fingers*...
123 |
124 |
125 |
126 |
127 |
128 | ```kotlin
129 | @Composable
130 | fun PurpleAndGold() {
131 | val purple = Color(0xFF552583)
132 | val gold = Color(0xFFFDB927)
133 | QrCodeView(
134 | data = "https://github.com/lightsparkdev/compose-qr-code",
135 | modifier = Modifier.size(300.dp),
136 | colors = QrCodeColors(
137 | background = purple,
138 | foreground = gold
139 | ),
140 | dotShape = DotShape.Circle
141 | ) {
142 | Box(
143 | contentAlignment = Alignment.Center,
144 | modifier = Modifier
145 | .fillMaxSize()
146 | .clip(CircleShape)
147 | .background(purple)
148 | ) {
149 | BasicText(
150 | text = "L",
151 | style = TextStyle.Default.copy(
152 | color = gold,
153 | fontSize = 42.sp,
154 | fontWeight = FontWeight.ExtraBold,
155 | fontStyle = FontStyle.Italic,
156 | fontFamily = FontFamily.Serif
157 | )
158 | )
159 | }
160 | }
161 | }
162 | ```
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 | ## Acknowledgements
172 |
173 | This libraries relies on the great, reliable [zxing](https://github.com/zxing/zxing) library for QR
174 | code data generation.
175 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | At Lightspark, we take security very seriously. We appreciate responsible
4 | disclosure of security issues and will endeavor to acknowledge your
5 | contributions.
6 |
7 |
8 | ## Reporting a Vulnerability
9 |
10 | If you believe you have found a security issue or problem, please email us
11 | at security@lightspark.com with as much detail as possible. Alternatively,
12 | you may report a security issue through the GitHub Security Advisory
13 | ["Report a Vulnerability" tab](https://github.com/lightsparkdev/compose-qr-code/security/advisories/new).
14 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application") version "7.4.1" apply false
3 | id("com.android.library") version "7.4.1" apply false
4 | id("org.jetbrains.kotlin.android") version "1.8.10" apply false
5 | id("com.vanniktech.maven.publish") version "0.24.0" apply false
6 | id("org.jetbrains.dokka") version "1.7.20" apply false
7 | }
--------------------------------------------------------------------------------
/composeqrcode/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/composeqrcode/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import com.vanniktech.maven.publish.SonatypeHost
2 |
3 | plugins {
4 | id("com.android.library")
5 | id("org.jetbrains.kotlin.android")
6 | id("com.vanniktech.maven.publish")
7 | }
8 |
9 | android {
10 | namespace = "com.lightspark.composeqr"
11 | compileSdk = 33
12 |
13 | defaultConfig {
14 | minSdk = 24
15 |
16 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
17 | vectorDrawables {
18 | useSupportLibrary = true
19 | }
20 | }
21 |
22 | compileOptions {
23 | sourceCompatibility = JavaVersion.VERSION_1_8
24 | targetCompatibility = JavaVersion.VERSION_1_8
25 | }
26 | kotlinOptions {
27 | jvmTarget = "1.8"
28 | }
29 | buildFeatures {
30 | compose = true
31 | }
32 | composeOptions {
33 | kotlinCompilerExtensionVersion = "1.4.2"
34 | }
35 | packagingOptions {
36 | resources {
37 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
38 | }
39 | }
40 | // Need to figure out if this is needed:
41 | // publishing {
42 | // singleVariant("release") {
43 | // withJavadocJar()
44 | // withSourcesJar()
45 | // }
46 | // }
47 | }
48 |
49 |
50 | mavenPublishing {
51 | publishToMavenCentral(SonatypeHost.S01)
52 |
53 | signAllPublications()
54 | }
55 |
56 | dependencies {
57 | implementation("androidx.core:core-ktx:1.9.0")
58 | implementation("com.google.zxing:core:3.5.1")
59 |
60 | val composeBom = platform("androidx.compose:compose-bom:2023.01.00")
61 | implementation(composeBom)
62 | androidTestImplementation(composeBom)
63 | implementation("androidx.compose.foundation:foundation")
64 | implementation("androidx.compose.ui:ui")
65 | implementation("androidx.compose.ui:ui-tooling-preview")
66 | debugImplementation("androidx.compose.ui:ui-tooling")
67 |
68 | testImplementation("junit:junit:4.13.2")
69 | }
--------------------------------------------------------------------------------
/composeqrcode/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.lightspark
2 | POM_ARTIFACT_ID=compose-qr-code
3 | # Don't bump this manually. Run `scripts/versions.main.kt ` to bump the version instead.
4 | VERSION_NAME=1.0.1-SNAPSHOT
5 |
6 | POM_NAME=compose-qr-code
7 | POM_PACKAGING=aar
8 |
9 | POM_DESCRIPTION=A simple, flexible QR code renderer for Jetpack Compose.
10 | POM_INCEPTION_YEAR=2023
11 |
12 | POM_URL=https://github.com/lightsparkdev/compose-qr-code
13 | POM_SCM_URL=https://github.com/lightsparkdev/compose-qr-code
14 | POM_SCM_CONNECTION=scm:git@github.com:lightsparkdev/compose-qr-code
15 | POM_SCM_DEV_CONNECTION=scm:git@github.com:lightsparkdev/compose-qr-code
16 |
17 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
18 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
19 | POM_LICENCE_DIST=repo
20 |
21 | POM_DEVELOPER_ID=lightsparkdev
22 | POM_DEVELOPER_NAME=Lightspark
23 | POM_DEVELOPER_URL=https://github.com/lightsparkdev
--------------------------------------------------------------------------------
/composeqrcode/src/main/java/com/lightspark/composeqr/DotShape.kt:
--------------------------------------------------------------------------------
1 | package com.lightspark.composeqr
2 |
3 | /**
4 | * Defines the shape of the individual dots in a QR code. For circle dots, the finder squares will be
5 | * rounded rects to fit the style better.
6 | */
7 | enum class DotShape {
8 | Circle, Square
9 | }
--------------------------------------------------------------------------------
/composeqrcode/src/main/java/com/lightspark/composeqr/Examples.kt:
--------------------------------------------------------------------------------
1 | package com.lightspark.composeqr
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.foundation.background
5 | import androidx.compose.foundation.layout.Box
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.foundation.layout.padding
8 | import androidx.compose.foundation.layout.size
9 | import androidx.compose.foundation.shape.CircleShape
10 | import androidx.compose.foundation.shape.RoundedCornerShape
11 | import androidx.compose.foundation.text.BasicText
12 | import androidx.compose.runtime.Composable
13 | import androidx.compose.ui.Alignment
14 | import androidx.compose.ui.Modifier
15 | import androidx.compose.ui.draw.clip
16 | import androidx.compose.ui.geometry.Offset
17 | import androidx.compose.ui.geometry.Size
18 | import androidx.compose.ui.graphics.Color
19 | import androidx.compose.ui.graphics.drawscope.Stroke
20 | import androidx.compose.ui.text.TextStyle
21 | import androidx.compose.ui.text.font.FontFamily
22 | import androidx.compose.ui.text.font.FontStyle
23 | import androidx.compose.ui.text.font.FontWeight
24 | import androidx.compose.ui.tooling.preview.Preview
25 | import androidx.compose.ui.unit.dp
26 | import androidx.compose.ui.unit.sp
27 |
28 | private const val URL_DATA =
29 | "https://lightspark.com/?doesnotmatter=this-is-a-test-of-longer-urls-to-see-how-it-looks"
30 |
31 | @Composable
32 | private fun Smile(
33 | modifier: Modifier = Modifier,
34 | backgroundColor: Color = Color.Black,
35 | smileColor: Color = Color.White
36 | ) {
37 | Canvas(modifier = modifier) {
38 | drawCircle(
39 | color = backgroundColor,
40 | center = Offset(size.width / 2, size.height / 2),
41 | radius = size.width / 2
42 | )
43 | drawCircle(
44 | color = smileColor,
45 | center = Offset(
46 | size.width / 2 - size.width / 4,
47 | size.height / 2 - size.height / 4
48 | ),
49 | radius = size.width / 8
50 | )
51 | drawCircle(
52 | color = smileColor,
53 | center = Offset(
54 | size.width / 2 + size.width / 4,
55 | size.height / 2 - size.height / 4
56 | ),
57 | radius = size.width / 8
58 | )
59 | drawArc(
60 | color = smileColor,
61 | startAngle = 0f,
62 | sweepAngle = 180f,
63 | useCenter = false,
64 | topLeft = Offset(size.width / 4, size.height / 3),
65 | size = Size(size.width / 2, size.height / 2),
66 | style = Stroke(width = size.width / 8)
67 | )
68 | }
69 | }
70 |
71 | @Preview(showBackground = true)
72 | @Composable
73 | fun BoringPreview() {
74 | QrCodeView(
75 | data = URL_DATA,
76 | modifier = Modifier.size(300.dp)
77 | )
78 | }
79 |
80 | @Preview(showBackground = true)
81 | @Composable
82 | fun SmileyDarkPreview() {
83 | QrCodeView(
84 | data = URL_DATA,
85 | modifier = Modifier.size(300.dp),
86 | colors = QrCodeColors(
87 | background = Color.Black,
88 | foreground = Color.White
89 | ),
90 | dotShape = DotShape.Circle
91 | ) {
92 | Box(
93 | contentAlignment = Alignment.Center,
94 | modifier = Modifier
95 | .fillMaxSize()
96 | .clip(RoundedCornerShape(8.dp))
97 | .background(Color.White)
98 | .padding(8.dp)
99 | .clip(RoundedCornerShape(8.dp))
100 | .background(Color.Green)
101 | ) {
102 | Smile(modifier = Modifier.fillMaxSize(0.5f))
103 | }
104 | }
105 | }
106 |
107 | @Preview(showBackground = true)
108 | @Composable
109 | fun SmileyLightSquarePreview() {
110 | QrCodeView(
111 | data = URL_DATA,
112 | modifier = Modifier.size(300.dp),
113 | colors = QrCodeColors(
114 | background = Color.White,
115 | foreground = Color.Black
116 | ),
117 | dotShape = DotShape.Square
118 | ) {
119 | Smile(
120 | modifier = Modifier.fillMaxSize(),
121 | backgroundColor = Color.Yellow,
122 | smileColor = Color.Black
123 | )
124 | }
125 | }
126 |
127 | @Preview(showBackground = true)
128 | @Composable
129 | fun PurpleAndGold() {
130 | val purple = Color(0xFF552583)
131 | val gold = Color(0xFFFDB927)
132 | QrCodeView(
133 | data = URL_DATA,
134 | modifier = Modifier.size(300.dp),
135 | colors = QrCodeColors(
136 | background = purple,
137 | foreground = gold
138 | ),
139 | dotShape = DotShape.Circle
140 | ) {
141 | Box(
142 | contentAlignment = Alignment.Center,
143 | modifier = Modifier
144 | .fillMaxSize()
145 | .clip(CircleShape)
146 | .background(purple)
147 | ) {
148 | BasicText(
149 | text = "L",
150 | style = TextStyle.Default.copy(
151 | color = gold,
152 | fontSize = 42.sp,
153 | fontWeight = FontWeight.ExtraBold,
154 | fontStyle = FontStyle.Italic,
155 | fontFamily = FontFamily.Serif
156 | )
157 | )
158 | }
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/composeqrcode/src/main/java/com/lightspark/composeqr/FinderSquareDrawing.kt:
--------------------------------------------------------------------------------
1 | package com.lightspark.composeqr
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.foundation.background
5 | import androidx.compose.foundation.layout.size
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.Modifier
8 | import androidx.compose.ui.geometry.CornerRadius
9 | import androidx.compose.ui.geometry.Offset
10 | import androidx.compose.ui.geometry.Size
11 | import androidx.compose.ui.graphics.Color
12 | import androidx.compose.ui.graphics.drawscope.DrawScope
13 | import androidx.compose.ui.tooling.preview.Preview
14 | import androidx.compose.ui.unit.dp
15 |
16 | private const val FINDER_SQUARE_DOT_SIZE = 7
17 |
18 | internal fun DrawScope.drawFinderSquares(
19 | cellSize: Float,
20 | colors: QrCodeColors = QrCodeColors(Color.White, Color.Black),
21 | dotShape: DotShape = DotShape.Square
22 | ) {
23 | drawFinderSquare(cellSize, Offset(0f, 0f), colors, dotShape)
24 | drawFinderSquare(
25 | cellSize,
26 | Offset(size.width - FINDER_SQUARE_DOT_SIZE * cellSize, 0f),
27 | colors,
28 | dotShape
29 | )
30 | drawFinderSquare(
31 | cellSize,
32 | Offset(0f, size.width - FINDER_SQUARE_DOT_SIZE * cellSize),
33 | colors,
34 | dotShape
35 | )
36 | }
37 |
38 | internal fun isFinderCell(x: Int, y: Int, gridSize: Int) =
39 | (x < FINDER_SQUARE_DOT_SIZE && y < FINDER_SQUARE_DOT_SIZE) ||
40 | (x < FINDER_SQUARE_DOT_SIZE && y > gridSize - 1 - FINDER_SQUARE_DOT_SIZE) ||
41 | (x > gridSize - 1 - FINDER_SQUARE_DOT_SIZE && y < FINDER_SQUARE_DOT_SIZE)
42 |
43 | private fun DrawScope.drawFinderSquare(
44 | cellSize: Float,
45 | topLeft: Offset,
46 | colors: QrCodeColors = QrCodeColors(Color.White, Color.Black),
47 | dotShape: DotShape = DotShape.Square
48 | ) {
49 | when (dotShape) {
50 | DotShape.Square -> {
51 | drawRect(
52 | color = colors.foreground,
53 | topLeft = topLeft,
54 | size = Size(cellSize * FINDER_SQUARE_DOT_SIZE, cellSize * FINDER_SQUARE_DOT_SIZE),
55 | )
56 | drawRect(
57 | color = colors.background,
58 | topLeft = topLeft + Offset(cellSize, cellSize),
59 | size = Size(
60 | cellSize * (FINDER_SQUARE_DOT_SIZE - 2),
61 | cellSize * (FINDER_SQUARE_DOT_SIZE - 2)
62 | ),
63 | )
64 | }
65 | DotShape.Circle -> {
66 | drawRoundRect(
67 | color = colors.foreground,
68 | topLeft = topLeft,
69 | size = Size(cellSize * FINDER_SQUARE_DOT_SIZE, cellSize * FINDER_SQUARE_DOT_SIZE),
70 | cornerRadius = CornerRadius(cellSize * 2)
71 | )
72 | drawRoundRect(
73 | color = colors.background,
74 | topLeft = topLeft + Offset(cellSize, cellSize),
75 | size = Size(
76 | cellSize * (FINDER_SQUARE_DOT_SIZE - 2),
77 | cellSize * (FINDER_SQUARE_DOT_SIZE - 2)
78 | ),
79 | cornerRadius = CornerRadius(cellSize)
80 | )
81 | }
82 | }
83 | drawRect(
84 | color = colors.foreground,
85 | topLeft = topLeft + Offset(cellSize * 2, cellSize * 2),
86 | size = Size(
87 | cellSize * (FINDER_SQUARE_DOT_SIZE - 4),
88 | cellSize * (FINDER_SQUARE_DOT_SIZE - 4)
89 | ),
90 | )
91 | }
92 |
93 | @Preview(showBackground = true)
94 | @Composable
95 | fun FinderSquaresPreview() {
96 | Canvas(
97 | modifier = Modifier
98 | .size(300.dp)
99 | .background(Color.White)
100 | ) {
101 | drawFinderSquares(cellSize = 10f)
102 | }
103 | }
104 |
105 | @Preview(showBackground = true)
106 | @Composable
107 | fun FinderSquaresRoundedPreview() {
108 | Canvas(
109 | modifier = Modifier
110 | .size(300.dp)
111 | .background(Color.White)
112 | ) {
113 | drawFinderSquares(cellSize = 10f, dotShape = DotShape.Circle)
114 | }
115 | }
--------------------------------------------------------------------------------
/composeqrcode/src/main/java/com/lightspark/composeqr/QrCodeColors.kt:
--------------------------------------------------------------------------------
1 | package com.lightspark.composeqr
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.ui.graphics.Color
5 |
6 | /**
7 | * Defines the color palette for a QR code.
8 | */
9 | data class QrCodeColors(
10 | val background: Color, val foreground: Color
11 | ) {
12 | companion object {
13 | @Composable
14 | fun default() = QrCodeColors(
15 | background = Color.White,
16 | foreground = Color.Black
17 | )
18 | }
19 | }
--------------------------------------------------------------------------------
/composeqrcode/src/main/java/com/lightspark/composeqr/QrCodeView.kt:
--------------------------------------------------------------------------------
1 | package com.lightspark.composeqr
2 |
3 | import androidx.compose.foundation.Canvas
4 | import androidx.compose.foundation.background
5 | import androidx.compose.foundation.layout.Box
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.foundation.layout.padding
8 | import androidx.compose.foundation.layout.size
9 | import androidx.compose.foundation.shape.CircleShape
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.runtime.remember
12 | import androidx.compose.ui.Alignment
13 | import androidx.compose.ui.Modifier
14 | import androidx.compose.ui.draw.clip
15 | import androidx.compose.ui.geometry.Offset
16 | import androidx.compose.ui.geometry.Size
17 | import androidx.compose.ui.graphics.Color
18 | import androidx.compose.ui.graphics.drawscope.Stroke
19 | import androidx.compose.ui.tooling.preview.Preview
20 | import androidx.compose.ui.unit.dp
21 |
22 | /**
23 | * A composable that renders a QR code from a data string.
24 | *
25 | * @param data The data to encode into a QR code.
26 | * @param modifier The Compose modifier to apply to the QR code.
27 | * @param colors The color palette to use for the QR code - defaults to black and white.
28 | * @param dotShape The shape of the individual dots in the QR code - defaults to square.
29 | * @param encoder The encoder to use to encode the data into a QR code. Meant to be able to stub out in tests if needed.
30 | * @param overlayContent Optional content to overlay on top of the QR code. This overlay is limited to 25% of the size
31 | * of the QR code and will be positioned in the center of it.
32 | */
33 | @Composable
34 | fun QrCodeView(
35 | data: String,
36 | modifier: Modifier = Modifier,
37 | colors: QrCodeColors = QrCodeColors.default(),
38 | dotShape: DotShape = DotShape.Square,
39 | encoder: QrEncoder = ZxingQrEncoder(),
40 | overlayContent: (@Composable () -> Unit)? = null,
41 | ) {
42 | Box(modifier = modifier, contentAlignment = Alignment.Center) {
43 | QrCodeView(
44 | data,
45 | modifier = Modifier.fillMaxSize(),
46 | colors = colors,
47 | dotShape = dotShape,
48 | encoder = encoder
49 | )
50 | if (overlayContent != null) {
51 | Box(modifier = Modifier.fillMaxSize(fraction = 0.25f)) {
52 | overlayContent()
53 | }
54 | }
55 | }
56 | }
57 |
58 | /**
59 | * A composable that renders a QR code from a data string with no overlay content.
60 | *
61 | * @param data The data to encode into a QR code.
62 | * @param modifier The Compose modifier to apply to the QR code.
63 | * @param colors The color palette to use for the QR code - defaults to black and white.
64 | * @param dotShape The shape of the individual dots in the QR code - defaults to square.
65 | * @param encoder The encoder to use to encode the data into a QR code. Meant to be able to stub out in tests if needed.
66 | */
67 | @Composable
68 | fun QrCodeView(
69 | data: String,
70 | modifier: Modifier = Modifier,
71 | colors: QrCodeColors = QrCodeColors.default(),
72 | dotShape: DotShape = DotShape.Square,
73 | encoder: QrEncoder = ZxingQrEncoder()
74 | ) {
75 | val encodedData = remember(data, encoder) { encoder.encode(data) }
76 |
77 | Canvas(modifier = modifier.background(colors.background)) {
78 | encodedData?.let { matrix ->
79 | val cellSize = size.width / matrix.width
80 | for (x in 0 until matrix.width) {
81 | for (y in 0 until matrix.height) {
82 | if (matrix.get(x, y) != 1.toByte() || isFinderCell(x, y, matrix.width)) continue
83 | when (dotShape) {
84 | DotShape.Square -> drawRect(
85 | color = colors.foreground,
86 | topLeft = Offset(x * cellSize, y * cellSize),
87 | size = Size(cellSize, cellSize)
88 | )
89 | DotShape.Circle -> drawCircle(
90 | color = colors.foreground,
91 | center = Offset(
92 | x * cellSize + cellSize / 2, y * cellSize + cellSize / 2
93 | ),
94 | radius = cellSize / 2
95 | )
96 | }
97 | }
98 | }
99 | drawFinderSquares(cellSize, colors, dotShape)
100 | }
101 | }
102 | }
103 |
104 | @Preview(showBackground = true)
105 | @Composable
106 | fun QrCodeViewPreview() {
107 | QrCodeView(
108 | "https://lightspark.com/this-is-a-test-of-longer-urls-to-see-how-it-looks",
109 | modifier = Modifier.size(400.dp),
110 | colors = QrCodeColors(
111 | background = Color.White,
112 | foreground = Color.Black
113 | ),
114 | dotShape = DotShape.Circle,
115 | overlayContent = {
116 | Box(
117 | contentAlignment = Alignment.Center,
118 | modifier = Modifier
119 | .fillMaxSize()
120 | .clip(CircleShape)
121 | .background(Color.White)
122 | .padding(8.dp)
123 | .clip(CircleShape)
124 | .background(Color.Yellow)
125 | ) {
126 | Canvas(modifier = Modifier.fillMaxSize(fraction = 0.5f)) {
127 | // Draw a smiley face
128 | drawCircle(
129 | color = Color.Black,
130 | center = Offset(size.width / 2, size.height / 2),
131 | radius = size.width / 2
132 | )
133 | drawCircle(
134 | color = Color.White,
135 | center = Offset(
136 | size.width / 2 - size.width / 4,
137 | size.height / 2 - size.height / 4
138 | ),
139 | radius = size.width / 8
140 | )
141 | drawCircle(
142 | color = Color.White,
143 | center = Offset(
144 | size.width / 2 + size.width / 4,
145 | size.height / 2 - size.height / 4
146 | ),
147 | radius = size.width / 8
148 | )
149 | drawArc(
150 | color = Color.White,
151 | startAngle = 0f,
152 | sweepAngle = 180f,
153 | useCenter = false,
154 | topLeft = Offset(size.width / 4, size.height / 3),
155 | size = Size(size.width / 2, size.height / 2),
156 | style = Stroke(width = size.width / 8)
157 | )
158 | }
159 | }
160 | })
161 | }
162 |
--------------------------------------------------------------------------------
/composeqrcode/src/main/java/com/lightspark/composeqr/QrEncoder.kt:
--------------------------------------------------------------------------------
1 | package com.lightspark.composeqr
2 |
3 | import com.google.zxing.EncodeHintType
4 | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
5 | import com.google.zxing.qrcode.encoder.ByteMatrix
6 | import com.google.zxing.qrcode.encoder.Encoder
7 |
8 | /**
9 | * Encodes a string into a QR code ByteMatrix. The default implementation, `ZxingQrEncoder` just
10 | * wraps the ZXing library with sane defaults.
11 | */
12 | interface QrEncoder {
13 | fun encode(qrData: String): ByteMatrix?
14 | }
15 |
16 | /**
17 | * This is just a small wrapper around the ZXing library with sane defaults.
18 | */
19 | class ZxingQrEncoder : QrEncoder {
20 | override fun encode(qrData: String): ByteMatrix? {
21 | return Encoder.encode(
22 | qrData,
23 | ErrorCorrectionLevel.H,
24 | mapOf(
25 | EncodeHintType.CHARACTER_SET to "UTF-8",
26 | EncodeHintType.MARGIN to 16,
27 | EncodeHintType.ERROR_CORRECTION to ErrorCorrectionLevel.H,
28 | )
29 | ).matrix
30 | }
31 | }
--------------------------------------------------------------------------------
/docs/images/boring.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lightsparkdev/compose-qr-code/0990049825762517bd08016f81ddd08505a9fbbb/docs/images/boring.png
--------------------------------------------------------------------------------
/docs/images/dark_smile_circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lightsparkdev/compose-qr-code/0990049825762517bd08016f81ddd08505a9fbbb/docs/images/dark_smile_circle.png
--------------------------------------------------------------------------------
/docs/images/light_smile_square.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lightsparkdev/compose-qr-code/0990049825762517bd08016f81ddd08505a9fbbb/docs/images/light_smile_square.png
--------------------------------------------------------------------------------
/docs/images/lightning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lightsparkdev/compose-qr-code/0990049825762517bd08016f81ddd08505a9fbbb/docs/images/lightning.png
--------------------------------------------------------------------------------
/docs/images/purple_and_gold.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lightsparkdev/compose-qr-code/0990049825762517bd08016f81ddd08505a9fbbb/docs/images/purple_and_gold.png
--------------------------------------------------------------------------------
/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/lightsparkdev/compose-qr-code/0990049825762517bd08016f81ddd08505a9fbbb/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 14 20:26:54 PST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-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 |
--------------------------------------------------------------------------------
/scripts/versions.main.kts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env kotlin
2 | import java.io.File
3 | import kotlin.system.exitProcess
4 |
5 | /**
6 | * A script to run locally in order to make a release.
7 | *
8 | * Inspired by https://github.com/apollographql/apollo-kotlin/blob/ef8fa4c222bc34cb00c4294699e324e9604a4b81/scripts/tag.main.kts
9 | */
10 |
11 |
12 | if (runCommand("git", "status", "--porcelain").isNotEmpty()) {
13 | println("Your git repo is not clean. Make sure to stash or commit your changes before making a release")
14 | exitProcess(1)
15 | }
16 |
17 | check(args.size == 1) {
18 | "versions.main.kts [version to tag]"
19 | }
20 | val tagVersion = args[0]
21 | val nextSnapshot = getNextSnapshot(tagVersion)
22 |
23 |
24 | while (true) {
25 | println("Current version is '${getCurrentVersion()}'.")
26 | println("Tag '$tagVersion' and bump to $nextSnapshot [y/n]?")
27 |
28 | when (readLine()!!.trim()) {
29 | "y" -> break
30 | "n" -> {
31 | println("Aborting.")
32 | exitProcess(1)
33 | }
34 | }
35 | }
36 |
37 | setCurrentVersion(tagVersion)
38 | setVersionInDocs(tagVersion, nextSnapshot)
39 |
40 | runCommand("git", "commit", "-a", "-m", "release $tagVersion")
41 | runCommand("git", "tag", "v$tagVersion")
42 |
43 | setCurrentVersion(nextSnapshot)
44 | runCommand("git", "commit", "-a", "-m", "version is now $nextSnapshot")
45 |
46 | println("Everything is done. Verify everything is ok and push upstream to trigger the new version.")
47 |
48 | fun runCommand(vararg args: String): String {
49 | val builder = ProcessBuilder(*args)
50 | .redirectError(ProcessBuilder.Redirect.INHERIT)
51 |
52 | val process = builder.start()
53 | val ret = process.waitFor()
54 |
55 | val output = process.inputStream.bufferedReader().readText()
56 | if (ret != 0) {
57 | throw java.lang.Exception("command ${args.joinToString(" ")} failed:\n$output")
58 | }
59 |
60 | return output
61 | }
62 |
63 | fun setCurrentVersion(version: String) {
64 | print("Setting version in gradle props")
65 | val gradleProperties = File("composeqrcode/gradle.properties")
66 | val newContent = gradleProperties.readLines().joinToString(separator = "\n", postfix = "\n") {
67 | it.replace(Regex("VERSION_NAME=.*"), "VERSION_NAME=$version")
68 | }
69 | gradleProperties.writeText(newContent)
70 | }
71 |
72 | fun getCurrentVersion(): String {
73 | val versionLines = File("composeqrcode/gradle.properties").readLines().filter { it.startsWith("VERSION_NAME=") }
74 |
75 | require(versionLines.isNotEmpty()) {
76 | "cannot find the version in ./gradle.properties"
77 | }
78 |
79 | require(versionLines.size == 1) {
80 | "multiple versions found in ./gradle.properties"
81 | }
82 |
83 | val regex = Regex("VERSION_NAME=(.*)-SNAPSHOT")
84 | val matchResult = regex.matchEntire(versionLines.first())
85 |
86 | require(matchResult != null) {
87 | "'${versionLines.first()}' doesn't match VERSION_NAME=(.*)-SNAPSHOT"
88 | }
89 |
90 | return matchResult.groupValues[1] + "-SNAPSHOT"
91 | }
92 |
93 | fun getNextSnapshot(version: String): String {
94 | val components = version.split(".").toMutableList()
95 | val part = components.removeLast()
96 | var digitCount = 0
97 | for (i in part.indices.reversed()) {
98 | if (part[i] < '0' || part[i] > '9') {
99 | break
100 | }
101 | digitCount++
102 | }
103 |
104 | check(digitCount > 0) {
105 | "Cannot find a number to bump in $version"
106 | }
107 |
108 | // prefix can be "alpha", "dev", etc...
109 | val prefix = if (digitCount < part.length) {
110 | part.substring(0, part.length - digitCount)
111 | } else {
112 | ""
113 | }
114 | val numericPart = part.substring(part.length - digitCount, part.length)
115 | val asNumber = numericPart.toInt()
116 |
117 | val nextPart = if (numericPart[0] == '0') {
118 | // https://docs.gradle.org/current/userguide/single_versions.html#version_ordering
119 | // Gradle understands that alpha2 > alpha10 but it might not be the case for everyone so
120 | // use the same naming schemes as other libs and keep the prefix
121 | val width = numericPart.length
122 | String.format("%0${width}d", asNumber + 1)
123 | } else {
124 | (asNumber + 1).toString()
125 | }
126 |
127 | components.add("$prefix$nextPart")
128 | return components.joinToString(".") + "-SNAPSHOT"
129 | }
130 |
131 | fun setVersionInDocs(version: String, nextSnapshot: String) {
132 | for (file in File("docs/source").walk() + File("README.md")) {
133 | if (file.isDirectory || !(file.name.endsWith(".md") || file.name.endsWith(".mdx"))) continue
134 |
135 | val content = file.readText()
136 | // Dependencies
137 | .replace(Regex(""""com\.lightspark:(.+):.+"""")) {
138 | """"com.lightspark:${it.groupValues[1]}:$version""""
139 | }
140 | // Badge link
141 | .replace(Regex("artifact/com.lightspark/compose-qr-code/.+\\)")) {
142 | "artifact/com.lightspark/compose-qr-code/$version)"
143 | }
144 | file.writeText(content)
145 | }
146 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | import org.gradle.api.initialization.resolve.RepositoriesMode
2 |
3 | pluginManagement {
4 | repositories {
5 | google()
6 | mavenCentral()
7 | gradlePluginPortal()
8 | }
9 | }
10 | dependencyResolutionManagement {
11 | repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
12 | repositories {
13 | google()
14 | mavenCentral()
15 | }
16 | }
17 | rootProject.name = "ComposeQrCode"
18 | include ':composeqrcode'
19 |
--------------------------------------------------------------------------------