Skip to content

Commit

Permalink
Add optional digit button randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Feb 23, 2023
1 parent 8d1a007 commit 45b2109
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/kotlin/com/cyb3rko/pincredible/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.preference.SwitchPreferenceCompat
import com.cyb3rko.pincredible.databinding.ActivitySettingsBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder

internal const val KEY_BUTTON_RANDOMIZER = "button_randomizer"
internal const val KEY_ADAPTIVE_COLORS = "adaptive_colors"

internal class SettingsActivity : AppCompatActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.core.content.res.ResourcesCompat
import androidx.core.view.get
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.cyb3rko.pincredible.KEY_BUTTON_RANDOMIZER
import com.cyb3rko.pincredible.R
import com.cyb3rko.pincredible.crypto.CryptoManager
import com.cyb3rko.pincredible.crypto.CryptoManager.EnDecryptionException
Expand All @@ -38,11 +39,13 @@ import com.cyb3rko.pincredible.databinding.FragmentPinCreatorBinding
import com.cyb3rko.pincredible.modals.ErrorDialog
import com.cyb3rko.pincredible.modals.InputDialog
import com.cyb3rko.pincredible.utils.ObjectSerializer
import com.cyb3rko.pincredible.utils.Safe
import com.cyb3rko.pincredible.utils.Vibration
import com.cyb3rko.pincredible.utils.hide
import com.cyb3rko.pincredible.utils.iterate
import com.cyb3rko.pincredible.utils.show
import java.io.File
import java.security.SecureRandom
import kotlin.jvm.Throws
import kotlin.random.Random

Expand Down Expand Up @@ -130,6 +133,7 @@ class PinCreatorFragment : Fragment() {
myContext.theme
)!!
clickedCell = Cell(it, row, column, currentBackgroundInt)
shuffleButtonDigits()
binding.buttonContainer.show()
}
}
Expand Down Expand Up @@ -265,6 +269,21 @@ class PinCreatorFragment : Fragment() {
}
}

private fun shuffleButtonDigits() {
if (!Safe.getBoolean(myContext, KEY_BUTTON_RANDOMIZER, false)) return
val digits = MutableList(10) { it }.apply {
shuffle(SecureRandom())
}
binding.run {
setOf(
button1, button2, button3, button4, button5, button6, button7, button8, button9,
button0
).forEach { button ->
button.text = digits.removeFirst().toString()
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/kotlin/com/cyb3rko/pincredible/utils/Safe.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 Cyb3rKo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cyb3rko.pincredible.utils

import android.content.Context
import androidx.preference.PreferenceManager

internal object Safe {
internal fun getBoolean(
context: Context,
key: String,
default: Boolean
) = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, default)
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/colored_ic_shuffle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_shuffle"
android:tint="@color/app_bar_icon" />
Binary file added app/src/main/res/drawable/ic_shuffle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<string name="dialog_about_message">App Version: %1$s (%2$d)\nBuild Type: %3$s\nDevice: %4$s %5$s (%6$s)\nSoftware: Android %7$s (%8$d)</string>
<string name="dialog_about_title">About</string>
<string name="dialog_credits_button">Open Flaticon</string>
<string name="dialog_credits_message">Information icon created by Freepik - Flaticon\n\nVerified icon created by Freepik - Flaticon\n\nEmpty box icon created by juicy_fish\n\nRight Arrow icon created by Roundicons\n\nGit icon created by Creatype\n\nSetting icon created by Freepik - Flaticon\n\nArt icon created by Freepik - Flaticon</string>
<string name="dialog_credits_message">Information icon created by Freepik - Flaticon\n\nVerified icon created by Freepik - Flaticon\n\nEmpty box icon created by juicy_fish\n\nRight Arrow icon created by Roundicons\n\nGit icon created by Creatype\n\nSetting icon created by Freepik - Flaticon\n\nArt icon created by Freepik - Flaticon\n\nRandom icon created by Uniconlabs</string>
<string name="dialog_credits_title">Icon Credits</string>
<string name="dialog_delete_button1">Yes</string>
<string name="dialog_delete_button2">No</string>
Expand Down Expand Up @@ -82,6 +82,9 @@
<string name="toast_stacktrace">Stracktrace copied</string>

<!-- Preferences -->
<string name="preference_category_security">Security</string>
<string name="preference_item_button_randomizer">Digit Button Randomizer</string>
<string name="preference_item_button_randomizer_summary">Shuffle digit buttons for protection against touch location logging</string>
<string name="preference_category_appearance">Appearance</string>
<string name="preference_item_material_you">Material You (adaptive colors)</string>
<string name="preference_item_material_you_summary">Use adaptive system colors over brand colors</string>
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto">

<PreferenceCategory
app:title="@string/preference_category_security">

<SwitchPreferenceCompat
app:key="button_randomizer"
app:defaultValue="false"
app:singleLineTitle="false"
app:title="@string/preference_item_button_randomizer"
app:summary="@string/preference_item_button_randomizer_summary"
app:icon="@drawable/colored_ic_shuffle" />

</PreferenceCategory>

<PreferenceCategory
app:title="@string/preference_category_appearance">

Expand Down

0 comments on commit 45b2109

Please sign in to comment.