From ec8412b257679e0b175a57d21a9776aeebbe1e8f Mon Sep 17 00:00:00 2001 From: Pavel Baksy Date: Thu, 8 Feb 2024 16:48:45 +0100 Subject: [PATCH] First changes --- .gitignore | 15 ++ app/.gitignore | 1 + app/build.gradle.kts | 48 +++++ app/proguard-rules.pro | 21 ++ .../passwordzebra/ExampleInstrumentedTest.kt | 24 +++ app/src/main/AndroidManifest.xml | 26 +++ .../cz/bugsy/passwordzebra/MainActivity.kt | 110 +++++++++++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 +++ .../main/res/drawable/password_background.xml | 5 + app/src/main/res/layout/activity_main.xml | 77 ++++++++ .../main/res/mipmap-anydpi/ic_launcher.xml | 6 + .../res/mipmap-anydpi/ic_launcher_round.xml | 6 + app/src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes app/src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes app/src/main/res/values-night/themes.xml | 7 + app/src/main/res/values/colors.xml | 5 + app/src/main/res/values/strings.xml | 5 + app/src/main/res/values/themes.xml | 9 + app/src/main/res/xml/backup_rules.xml | 13 ++ .../main/res/xml/data_extraction_rules.xml | 19 ++ .../cz/bugsy/passwordzebra/ExampleUnitTest.kt | 17 ++ build.gradle.kts | 5 + gradle.properties | 23 +++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59203 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 185 ++++++++++++++++++ gradlew.bat | 89 +++++++++ settings.gradle.kts | 17 ++ 37 files changed, 939 insertions(+) create mode 100644 .gitignore create mode 100644 app/.gitignore create mode 100644 app/build.gradle.kts create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/cz/bugsy/passwordzebra/ExampleInstrumentedTest.kt create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/cz/bugsy/passwordzebra/MainActivity.kt create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/password_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/main/res/xml/backup_rules.xml create mode 100644 app/src/main/res/xml/data_extraction_rules.xml create mode 100644 app/src/test/java/cz/bugsy/passwordzebra/ExampleUnitTest.kt create mode 100644 build.gradle.kts create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle.kts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..4a96a5b --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,48 @@ +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") +} + +android { + namespace = "cz.bugsy.passwordzebra" + compileSdk = 34 + + defaultConfig { + applicationId = "cz.bugsy.passwordzebra" + minSdk = 29 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + + implementation("androidx.core:core-ktx:1.12.0") + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("com.google.android.material:material:1.11.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("com.google.android.material:material:1.11.0") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/cz/bugsy/passwordzebra/ExampleInstrumentedTest.kt b/app/src/androidTest/java/cz/bugsy/passwordzebra/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..27c9d1c --- /dev/null +++ b/app/src/androidTest/java/cz/bugsy/passwordzebra/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package cz.bugsy.passwordzebra + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("cz.bugsy.passwordzebra", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..925d952 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/cz/bugsy/passwordzebra/MainActivity.kt b/app/src/main/java/cz/bugsy/passwordzebra/MainActivity.kt new file mode 100644 index 0000000..d027a54 --- /dev/null +++ b/app/src/main/java/cz/bugsy/passwordzebra/MainActivity.kt @@ -0,0 +1,110 @@ +package cz.bugsy.passwordzebra + +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.os.Bundle +import android.widget.Button +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import kotlin.random.Random + +class MainActivity : AppCompatActivity() { + + private lateinit var generateButton: Button + private lateinit var passwordTextView: TextView + private lateinit var infoTextView: TextView + private lateinit var switchWithoutSpaces: com.google.android.material.switchmaterial.SwitchMaterial + private lateinit var switchSpecialChars: com.google.android.material.switchmaterial.SwitchMaterial + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + generateButton = findViewById(R.id.generateButton) + passwordTextView = findViewById(R.id.passwordTextView) + infoTextView = findViewById(R.id.infoTextView) + generateButton = findViewById(R.id.generateButton) + switchWithoutSpaces = findViewById(R.id.switchWithoutSpaces) + switchSpecialChars = findViewById(R.id.switchSpecialChars) + + generateButton.setOnClickListener { + generatePassword() + } + + // Initially generate a password + generatePassword() + + // Set click listener to copy password to clipboard + passwordTextView.setOnClickListener { + copyToClipboard(passwordTextView.text.toString(), getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) + } + } + + private fun generatePassword() { + val password = generateRandomWords(6) + + passwordTextView.text = password + } + + private fun generateRandomWords(numWords: Int): String { + val syllables = arrayOf( + "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al", "am", "an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw", "ax", "ay", "az", + "ba", "be", "bi", "bo", "bu", "by", "br", "bl", "bh", "bn", "bt", "bs", "bv", "bw", "bz", + "ca", "ce", "ci", "co", "cu", "cy", "cr", "cl", "ch", "ck", "cn", "ct", "cs", "cv", "cw", "cz", + "da", "de", "di", "do", "du", "dy", "dr", "dl", "dh", "dn", "dt", "ds", "dv", "dw", "dz", + "ea", "eb", "ec", "ed", "ef", "eg", "eh", "ei", "ej", "ek", "el", "em", "en", "eo", "ep", "eq", "er", "es", "et", "eu", "ev", "ew", "ex", "ey", "ez", + "ta", "te", "ti", "to", "tu", "ty", "tr", "tl", "th", "tn", "tt", "ts", "tv", "tw", "tz", + "ia", "ib", "ic", "id", "if", "ig", "ih", "ii", "ij", "ik", "il", "im", "in", "io", "ip", "iq", "ir", "is", "it", "iu", "iv", "iw", "ix", "iy", "iz", + "ja", "je", "ji", "jo", "ju", "jr", "jl", "jh", "jn", "jt", "js", "jv", "jw", "jz", + "ga", "ge", "gi", "go", "gu", "gy", "gr", "gl", "gh", "gn", "gt", "gs", "gv", "gw", "gz", + "ta", "te", "ti", "to", "tu", "ty", "tr", "tl", "th", "tn", "tt", "ts", "tv", "tw", "tz", + "aa", "ae", "ee", "ea", "ay", "ou", "oo", + "sa", "se", "si", "so", "su", "sy", "sr", "sl", "sh", "sn", "st", "ss", "sv", "sw", + "qa", "qe", "qi", "qo", "qu", "qy", "qw", + "ra", "re", "ri", "ro", "ru", "ry", "rr", "rl", "rh", "rn", "rs", "rv", "rw", "rz", + "ob", "oc", "od", "oe", "of", "og", "oh", "oj", "ok", "ol", "om", "on", "op", "oq", "or", "os", "ot", "ou", "ov", "ow", "ox", "oy", "oz", + // Add more syllables as needed + ) + + val random = Random.Default + + return buildString { + repeat(numWords) { + append(generateRandomWord(syllables, random)) + append(" ") // Add space between words + } + }.let { password -> + // Check if the switch for adding special characters is checked + if (switchSpecialChars.isChecked) { + addSpecialCharacters(password) + } else { + password + } + }.trim() // Remove trailing space + } + + private fun generateRandomWord(syllables: Array, random: Random): String { + return buildString { + repeat(random.nextInt(2, 4)) { + append(syllables[random.nextInt(syllables.size)]) + } + } + } + + private fun copyToClipboard(text: String, clipboardManager: ClipboardManager) { + val clipData = ClipData.newPlainText("Password", text) + clipboardManager.setPrimaryClip(clipData) + } + + private fun addSpecialCharacters(password: String): String { + // Add special characters like $, comma, dot, etc. + val specialChars = listOf('$', ',', '.', '#', '@', '!', '%', '&') + val random = Random.Default + + val index = random.nextInt(0, password.length + 1) + val specialChar = specialChars[random.nextInt(specialChars.size)] + + return password.substring(0, index) + specialChar + password.substring(index) + } +} diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/password_background.xml b/app/src/main/res/drawable/password_background.xml new file mode 100644 index 0000000..0434eaa --- /dev/null +++ b/app/src/main/res/drawable/password_background.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..fa406ea --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,77 @@ + + + + + + + +