Skip to content

Commit ae9613d

Browse files
committed
Adding some images
1 parent 58e73b6 commit ae9613d

7 files changed

Lines changed: 74 additions & 43 deletions

File tree

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
# A QR Code Renderer For Jetpack Compose
1+
# Compose QR Code
2+
__A simple, flexible QR Code Renderer For Jetpack Compose__
3+
4+
[image: ./docs/images/purple_and_gold.png]
5+
6+
## Usage
7+
8+
9+
```kotlin
210

311
TODO: Add a documentation and examples.
45.8 KB
Loading
109 KB
Loading
53.1 KB
Loading
109 KB
Loading

composeqrcode/src/main/java/com/lightspark/composeqr/Examples.kt

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,55 @@ import androidx.compose.foundation.layout.padding
88
import androidx.compose.foundation.layout.size
99
import androidx.compose.foundation.shape.CircleShape
1010
import androidx.compose.foundation.shape.RoundedCornerShape
11+
import androidx.compose.foundation.text.BasicText
1112
import androidx.compose.runtime.Composable
1213
import androidx.compose.ui.Alignment
1314
import androidx.compose.ui.Modifier
1415
import androidx.compose.ui.draw.clip
1516
import androidx.compose.ui.geometry.Offset
1617
import androidx.compose.ui.geometry.Size
1718
import androidx.compose.ui.graphics.Color
18-
import androidx.compose.ui.graphics.Path
19-
import androidx.compose.ui.graphics.drawscope.Fill
2019
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
2124
import androidx.compose.ui.tooling.preview.Preview
2225
import androidx.compose.ui.unit.dp
26+
import androidx.compose.ui.unit.sp
27+
28+
private const val URL_DATA = "https://lightspark.com/?doesnotmatter=this-is-a-test-of-longer-urls-to-see-how-it-looks"
2329

2430
@Composable
25-
private fun Smile() {
26-
Canvas(modifier = Modifier.fillMaxSize(fraction = 0.5f)) {
27-
// Draw a smiley face
31+
private fun Smile(
32+
modifier: Modifier = Modifier,
33+
backgroundColor: Color = Color.Black,
34+
smileColor: Color = Color.White
35+
) {
36+
Canvas(modifier = modifier) {
2837
drawCircle(
29-
color = Color.Black,
38+
color = backgroundColor,
3039
center = Offset(size.width / 2, size.height / 2),
3140
radius = size.width / 2
3241
)
3342
drawCircle(
34-
color = Color.White,
43+
color = smileColor,
3544
center = Offset(
3645
size.width / 2 - size.width / 4,
3746
size.height / 2 - size.height / 4
3847
),
3948
radius = size.width / 8
4049
)
4150
drawCircle(
42-
color = Color.White,
51+
color = smileColor,
4352
center = Offset(
4453
size.width / 2 + size.width / 4,
4554
size.height / 2 - size.height / 4
4655
),
4756
radius = size.width / 8
4857
)
4958
drawArc(
50-
color = Color.White,
59+
color = smileColor,
5160
startAngle = 0f,
5261
sweepAngle = 180f,
5362
useCenter = false,
@@ -61,9 +70,9 @@ private fun Smile() {
6170

6271
@Preview(showBackground = true)
6372
@Composable
64-
fun SmilyDarkPreview() {
73+
fun SmileyDarkPreview() {
6574
QrCodeView(
66-
"https://lightspark.com/this-is-a-test-of-longer-urls-to-see-how-it-looks",
75+
data = URL_DATA,
6776
modifier = Modifier.size(300.dp),
6877
colors = QrCodeColors(
6978
background = Color.Black,
@@ -81,16 +90,16 @@ fun SmilyDarkPreview() {
8190
.clip(RoundedCornerShape(8.dp))
8291
.background(Color.Green)
8392
) {
84-
Smile()
93+
Smile(modifier = Modifier.fillMaxSize(0.5f))
8594
}
8695
})
8796
}
8897

8998
@Preview(showBackground = true)
9099
@Composable
91-
fun SmilyLightSquarePreview() {
100+
fun SmileyLightSquarePreview() {
92101
QrCodeView(
93-
"https://lightspark.com/this-is-a-test-of-longer-urls-to-see-how-it-looks",
102+
data = URL_DATA,
94103
modifier = Modifier.size(300.dp),
95104
colors = QrCodeColors(
96105
background = Color.White,
@@ -100,28 +109,42 @@ fun SmilyLightSquarePreview() {
100109
overlayContent = {
101110
Box(
102111
contentAlignment = Alignment.Center,
103-
modifier = Modifier
104-
.fillMaxSize()
105-
.clip(RoundedCornerShape(16.dp))
106-
.background(Color.White)
107-
.padding(8.dp)
108-
.clip(RoundedCornerShape(16.dp))
109-
.background(Color.Green)
112+
modifier = Modifier.fillMaxSize()
110113
) {
111-
Smile()
114+
Smile(
115+
modifier = Modifier.fillMaxSize(),
116+
backgroundColor = Color.Yellow,
117+
smileColor = Color.Black
118+
)
112119
}
113120
})
114121
}
115122

116123
@Preview(showBackground = true)
117124
@Composable
118-
fun ColorfulStarOverlay() {
125+
fun BoringPreview() {
126+
QrCodeView(
127+
data = URL_DATA,
128+
modifier = Modifier.size(300.dp),
129+
colors = QrCodeColors(
130+
background = Color.White,
131+
foreground = Color.Black
132+
),
133+
dotShape = DotShape.Square,
134+
)
135+
}
136+
137+
@Preview(showBackground = true)
138+
@Composable
139+
fun PurpleAndGold() {
140+
val purple = Color(0xFF552583)
141+
val gold = Color(0xFFFDB927)
119142
QrCodeView(
120-
"https://lightspark.com/this-is-a-test-of-longer-urls-to-see-how-it-looks",
143+
data = URL_DATA,
121144
modifier = Modifier.size(300.dp),
122145
colors = QrCodeColors(
123-
background = Color.Blue,
124-
foreground = Color.Yellow
146+
background = purple,
147+
foreground = gold
125148
),
126149
dotShape = DotShape.Circle,
127150
overlayContent = {
@@ -130,24 +153,18 @@ fun ColorfulStarOverlay() {
130153
modifier = Modifier
131154
.fillMaxSize()
132155
.clip(CircleShape)
133-
.background(Color.Blue)
156+
.background(purple)
134157
) {
135-
Canvas(modifier = Modifier.fillMaxSize(0.5f)) {
136-
val coolArrow = Path().apply {
137-
moveTo(0f, 0f)
138-
lineTo(size.width / 2, size.height / 2)
139-
lineTo(0f, size.height)
140-
lineTo(size.width, size.height / 2)
141-
lineTo(size.width / 2, 0f)
142-
lineTo(size.width, size.height / 2)
143-
close()
144-
}
145-
drawPath(
146-
path = coolArrow,
147-
color = Color.White,
148-
style = Fill
158+
BasicText(
159+
text = "L",
160+
style = TextStyle.Default.copy(
161+
color = gold,
162+
fontSize = 42.sp,
163+
fontWeight = FontWeight.ExtraBold,
164+
fontStyle = FontStyle.Italic,
165+
fontFamily = FontFamily.Serif
149166
)
150-
}
167+
)
151168
}
152169
})
153170
}

0 commit comments

Comments
 (0)