Skip to content

Commit f6f96d3

Browse files
Update dir_structure.md
1 parent 83aa258 commit f6f96d3

15 files changed

+177
-42
lines changed

.idea/appInsightsSettings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetDropDown.xml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/migrations.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ android {
2727
getDefaultProguardFile("proguard-android-optimize.txt"),
2828
"proguard-rules.pro"
2929
)
30+
signingConfig = signingConfigs.getByName("debug")
3031
}
3132
}
3233
compileOptions {
@@ -53,7 +54,7 @@ dependencies {
5354
implementation("androidx.core:core-ktx:1.12.0")
5455
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
5556
implementation("androidx.activity:activity-compose:1.8.1")
56-
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
57+
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
5758
implementation("androidx.compose.ui:ui")
5859
implementation("androidx.compose.ui:ui-graphics")
5960
implementation("androidx.compose.ui:ui-tooling-preview")
@@ -63,7 +64,7 @@ dependencies {
6364
testImplementation("junit:junit:4.13.2")
6465
androidTestImplementation("androidx.test.ext:junit:1.1.5")
6566
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
66-
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
67+
androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01"))
6768
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
6869
debugImplementation("androidx.compose.ui:ui-tooling")
6970
debugImplementation("androidx.compose.ui:ui-test-manifest")

app/debug/app-debug.aab

669 KB
Binary file not shown.

app/release/app-release.aab

461 KB
Binary file not shown.

app/src/main/java/com/example/programmingtools/MainActivity.kt

+45-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.example.programmingtools
22

33
import android.graphics.Bitmap
4+
import android.graphics.Canvas
5+
import android.graphics.Color
6+
import android.graphics.Paint
7+
import android.graphics.Typeface
48
import android.net.Uri
59
import android.os.Bundle
610
import android.widget.Button
@@ -16,6 +20,9 @@ import java.io.IOException
1620
class MainActivity : ComponentActivity() {
1721
private lateinit var imageViewQRCode: ImageView
1822
private lateinit var bitmap: Bitmap
23+
private lateinit var editTextSize: EditText // For user to input desired size
24+
private lateinit var editTextSaveText: EditText // For user to input text to save beneath the image
25+
private lateinit var editTextColor: EditText // For user to input desired QR code color
1926
private val qrCodeGenerator = QRCodeGenerator()
2027

2128
private val createDocument =
@@ -29,15 +36,28 @@ class MainActivity : ComponentActivity() {
2936
super.onCreate(savedInstanceState)
3037
setContentView(R.layout.activity_main) // Assuming you have a corresponding XML layout
3138

39+
imageViewQRCode = findViewById(R.id.imageViewQRCode1)
3240
val editText = findViewById<EditText>(R.id.editTextText)
33-
imageViewQRCode = findViewById(R.id.imageViewQRCode)
34-
val buttonGenerate = findViewById<Button>(R.id.buttonGenerate)
41+
val buttonGenerate = findViewById<Button>(R.id.buttonGenerate1)
42+
43+
editTextSize = findViewById(R.id.editTextSize) // Assuming you have this in your layout
44+
editTextSaveText = findViewById(R.id.editTextSaveText) // Assuming you have this in your layout
45+
editTextColor = findViewById(R.id.editTextColor) // Assuming you have this in your layout
3546

3647
buttonGenerate.setOnClickListener {
3748
val text = editText.text.toString()
38-
bitmap = qrCodeGenerator.generateQRCode(text, 512, 512)
49+
val size = editTextSize.text.toString().toIntOrNull() ?: 512 // Default size if input is invalid
50+
51+
// Get the color from the input field
52+
val color = Color.parseColor(editTextColor.text.toString())
53+
54+
// Generate QR code with custom color
55+
bitmap = qrCodeGenerator.generateQRCode(text, size, size, color)
3956
imageViewQRCode.setImageBitmap(bitmap)
4057

58+
// Combine QR code and saved text into one image
59+
bitmap = combineImageAndText(bitmap, editTextSaveText.text.toString())
60+
4161
// Launch intent to save the image
4262
createDocument.launch("QRCode.png")
4363
}
@@ -58,16 +78,36 @@ class MainActivity : ComponentActivity() {
5878
}
5979
}
6080
}
81+
82+
private fun combineImageAndText(image: Bitmap, text: String): Bitmap {
83+
// Implementation to combine the QR code and text into a single Bitmap
84+
// This can be done using Canvas and Paint classes
85+
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
86+
paint.color = Color.BLACK // Set the text color
87+
paint.textSize = 40f // Set the text size
88+
paint.typeface = Typeface.DEFAULT_BOLD // Set the typeface as bold
89+
90+
val textWidth = paint.measureText(text)
91+
val combinedImage = Bitmap.createBitmap(image.width, image.height + (paint.textSize * 1.5).toInt(), Bitmap.Config.ARGB_8888)
92+
93+
val canvas = Canvas(combinedImage)
94+
canvas.drawBitmap(image, 0f, 0f, null) // Draw the QR code on the canvas
95+
canvas.drawText(text, (image.width - textWidth) / 2, image.height + paint.textSize, paint) // Draw the text beneath the QR code
96+
97+
return combinedImage
98+
}
6199
}
62100

63101
class QRCodeGenerator {
64-
fun generateQRCode(text: String, width: Int, height: Int): Bitmap {
102+
fun generateQRCode(text: String, width: Int, height: Int, color: Int): Bitmap {
65103
val writer = QRCodeWriter()
66104
val bitMatrix = writer.encode(text, BarcodeFormat.QR_CODE, width, height)
67105
val bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
106+
107+
// Use the provided color for QR code pixels instead of default black
68108
for (x in 0 until width) {
69109
for (y in 0 until height) {
70-
bmp.setPixel(x, y, if (bitMatrix[x, y]) -0x1000000 else -0x1)
110+
bmp.setPixel(x, y, if (bitMatrix[x, y]) color else -0x1)
71111
}
72112
}
73113
return bmp
+70-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,82 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:orientation="vertical"
7+
android:padding="16dp">
28

3-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
9+
<EditText
10+
android:id="@+id/editTextText"
411
android:layout_width="match_parent"
512
android:layout_height="wrap_content"
6-
android:orientation="horizontal"
7-
android:padding="16dp"
8-
android:layout_weight="1"
9-
android:hint="@string/edit_text_hint"
10-
android:inputType="text" >
13+
android:autofillHints="name"
14+
android:hint="@string/enter_text_for_qr_code"
15+
android:inputType="text"
16+
android:minHeight="48dp" />
1117

1218
<EditText
13-
android:id="@+id/editTextText"
14-
android:layout_width="0dp"
19+
android:id="@+id/editTextSize"
20+
android:layout_width="match_parent"
1521
android:layout_height="wrap_content"
16-
android:autofillHints="name"
17-
android:layout_weight="1"
18-
android:hint="Enter text"
19-
android:inputType="text" />
20-
21-
<Button
22-
android:id="@+id/buttonGenerate"
23-
android:layout_width="0dp"
24-
android:layout_height="48dp"
25-
android:layout_weight="0.3"
26-
android:text="@string/generate_button"
27-
android:contentDescription="@string/generate_button_description" />
22+
android:autofillHints=""
23+
android:hint="@string/enter_size_e_g_512"
24+
android:inputType="number"
25+
android:minHeight="48dp" />
26+
27+
<EditText
28+
android:id="@+id/editTextSaveText"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
android:autofillHints=""
32+
android:hint="@string/enter_text_to_save_beneath_the_image"
33+
android:inputType="text"
34+
android:minHeight="48dp" />
35+
36+
<ImageView
37+
android:id="@+id/imageViewQRCode1"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:visibility="visible"
41+
android:contentDescription="@string/todo1" />
42+
43+
<EditText
44+
android:id="@+id/editTextColor"
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content"
47+
android:autofillHints=""
48+
android:hint="@string/color_edit_text_hint"
49+
android:inputType="text"
50+
android:minHeight="48dp" />
51+
52+
<LinearLayout
53+
android:layout_width="match_parent"
54+
android:layout_height="wrap_content"
55+
android:orientation="horizontal">
56+
57+
<Button
58+
android:id="@+id/buttonGenerate1"
59+
style="?android:attr/buttonBarButtonStyle"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content"
62+
android:text="@string/generate_qr_code"
63+
android:textColor="#00796B"
64+
tools:ignore="DuplicateSpeakableTextCheck" />
65+
66+
<Button
67+
android:id="@+id/buttonGenerate2"
68+
style="?android:attr/buttonBarButtonStyle"
69+
android:layout_width="wrap_content"
70+
android:layout_height="wrap_content"
71+
android:text="@string/generate_button"
72+
android:textColor="#00796B" />
73+
</LinearLayout>
2874

2975
<ImageView
30-
android:id="@+id/imageViewQRCode"
76+
android:id="@+id/imageViewQRCode2"
3177
android:layout_width="wrap_content"
3278
android:layout_height="wrap_content"
33-
android:contentDescription="@string/image_description"
34-
android:visibility="gone" />
79+
android:visibility="visible"
80+
android:contentDescription="@string/todo" />
3581

36-
</LinearLayout>
82+
</LinearLayout>

app/src/main/res/values/colors.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
99
<color name="white">#FFFFFFFF</color>
10-
</resources>
10+
</resources>

app/src/main/res/values/strings.xml

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<resources>
22
<string name="app_name">ProgrammingTools</string>
3-
<string name="edit_text_hint">Enter text</string>
3+
<string name="edit_text_hint">Enter text for QR Code</string>
4+
<string name="size_edit_text_hint">Enter size (e.g., 512)</string>
5+
<string name="save_text_edit_text_hint">Enter text to save beneath the image</string>
6+
<string name="color_edit_text_hint">Enter QR Code color</string>
47
<string name="generate_button">Generate QR Code</string>
58
<string name="generate_button_description">Button to generate QR code</string>
69
<string name="image_description">Image of QR Code</string>
7-
</resources>
10+
<string name="enter_size_e_g_512">Enter size (e.g., 512)</string>
11+
<string name="enter_text_for_qr_code">Enter text for QR Code</string>
12+
<string name="todo">TODO</string>
13+
<string name="generate_qr_code">Generate QR Code</string>
14+
<string name="enter_text_to_save_beneath_the_image">Enter text to save beneath the image</string>
15+
<string name="todo1">TODO</string>
16+
</resources>

build.gradle.kts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
buildscript {
2+
val agpVersion by extra("8.5.0")
3+
}
14
// Top-level build file where you can add configuration options common to all sub-projects/modules.
25
plugins {
3-
id("com.android.application") version "8.1.4" apply false
6+
id("com.android.application") version "8.2.0" apply false
47
id("org.jetbrains.kotlin.android") version "1.8.10" apply false
58
}

docs/dir_structure.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Directory Structure
2+
3+
```sh
14
.
25
├── app
36
│   ├── build.gradle
@@ -69,5 +72,4 @@
6972
├── gradlew.bat
7073
├── local.properties
7174
└── settings.gradle
72-
73-
34 directories, 37 files
75+
```
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Nov 25 09:01:11 MST 2023
1+
#Sun Dec 03 21:27:00 MST 2023
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)