mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add setting to colorize password
This commit is contained in:
@@ -21,12 +21,10 @@ package com.kunzisoft.keepass.password
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.StyleSpan
|
||||
import com.kunzisoft.keepass.R
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
@@ -256,39 +254,39 @@ class PasswordGenerator(private val resources: Resources) {
|
||||
}
|
||||
|
||||
fun getColorizedPassword(password: String): Spannable {
|
||||
val coloredString = SpannableStringBuilder()
|
||||
val spannableString = SpannableStringBuilder()
|
||||
if (password.isNotEmpty()) {
|
||||
password.forEach {
|
||||
when {
|
||||
UPPERCASE_CHARS.contains(it)||
|
||||
LOWERCASE_CHARS.contains(it) -> {
|
||||
coloredString.append(it)
|
||||
spannableString.append(it)
|
||||
}
|
||||
DIGIT_CHARS.contains(it) -> {
|
||||
// RED
|
||||
coloredString.append(colorizeChar(it, Color.rgb(246, 79, 62)))
|
||||
spannableString.append(colorizeChar(it, Color.rgb(246, 79, 62)))
|
||||
}
|
||||
SPECIAL_CHARS.contains(it) -> {
|
||||
// Blue
|
||||
coloredString.append(colorizeChar(it, Color.rgb(39, 166, 228)))
|
||||
spannableString.append(colorizeChar(it, Color.rgb(39, 166, 228)))
|
||||
}
|
||||
MINUS_CHAR.contains(it)||
|
||||
UNDERLINE_CHAR.contains(it)||
|
||||
BRACKET_CHARS.contains(it) -> {
|
||||
// Purple
|
||||
coloredString.append(colorizeChar(it, Color.rgb(185, 38, 209)))
|
||||
spannableString.append(colorizeChar(it, Color.rgb(185, 38, 209)))
|
||||
}
|
||||
extendedChars().contains(it) -> {
|
||||
// Green
|
||||
coloredString.append(colorizeChar(it, Color.rgb(44, 181, 50)))
|
||||
spannableString.append(colorizeChar(it, Color.rgb(44, 181, 50)))
|
||||
}
|
||||
else -> {
|
||||
coloredString.append(it)
|
||||
spannableString.append(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return coloredString
|
||||
return spannableString
|
||||
}
|
||||
|
||||
private fun colorizeChar(char: Char, color: Int): Spannable {
|
||||
|
||||
@@ -135,6 +135,18 @@ object PreferencesUtil {
|
||||
context.resources.getBoolean(R.bool.show_uuid_default))
|
||||
}
|
||||
|
||||
fun hideProtectedValue(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.hide_password_key),
|
||||
context.resources.getBoolean(R.bool.hide_password_default))
|
||||
}
|
||||
|
||||
fun colorizePassword(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.colorize_password_key),
|
||||
context.resources.getBoolean(R.bool.colorize_password_default))
|
||||
}
|
||||
|
||||
fun showExpiredEntries(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return ! prefs.getBoolean(context.getString(R.string.hide_expired_entries_key),
|
||||
@@ -371,12 +383,6 @@ object PreferencesUtil {
|
||||
context.resources.getBoolean(R.bool.sort_recycle_bin_bottom_default))
|
||||
}
|
||||
|
||||
fun hideProtectedValue(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.hide_password_key),
|
||||
context.resources.getBoolean(R.bool.hide_password_default))
|
||||
}
|
||||
|
||||
fun fieldFontIsInVisibility(context: Context): Boolean {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
return prefs.getBoolean(context.getString(R.string.monospace_font_fields_enable_key),
|
||||
@@ -631,7 +637,6 @@ object PreferencesUtil {
|
||||
context.getString(R.string.lock_database_show_button_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.password_length_key) -> editor.putInt(name, value.toInt())
|
||||
context.getString(R.string.list_password_generator_options_key) -> editor.putStringSet(name, getStringSetFromProperties(value))
|
||||
context.getString(R.string.hide_password_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.allow_copy_password_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.remember_database_locations_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.show_recent_files_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
@@ -679,6 +684,8 @@ object PreferencesUtil {
|
||||
context.getString(R.string.show_uuid_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.list_size_key) -> editor.putString(name, value)
|
||||
context.getString(R.string.monospace_font_fields_enable_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.hide_password_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.colorize_password_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.hide_expired_entries_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
context.getString(R.string.enable_education_screens_key) -> editor.putBoolean(name, value.toBoolean())
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.kunzisoft.keepass.view
|
||||
|
||||
import android.content.Context
|
||||
import android.text.Editable
|
||||
import android.text.SpannableString
|
||||
import android.text.TextWatcher
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
@@ -31,6 +32,7 @@ import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.password.PasswordGenerator
|
||||
import com.kunzisoft.keepass.password.PasswordEntropy
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
|
||||
class PasswordView @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
@@ -119,7 +121,11 @@ class PasswordView @JvmOverloads constructor(context: Context,
|
||||
return passwordText.text.toString()
|
||||
}
|
||||
set(value) {
|
||||
passwordText.text = PasswordGenerator.getColorizedPassword(value)
|
||||
getEntropyStrength(value)
|
||||
val spannableString =
|
||||
if (PreferencesUtil.colorizePassword(context))
|
||||
PasswordGenerator.getColorizedPassword(value)
|
||||
else
|
||||
SpannableString(value)
|
||||
passwordText.text = spannableString
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.google.android.material.textfield.TextInputLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateField
|
||||
import com.kunzisoft.keepass.password.PasswordGenerator
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
|
||||
class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
@@ -130,16 +131,11 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
set(value) {
|
||||
val spannableString =
|
||||
if (TemplateField.isStandardPasswordName(context, label))
|
||||
if (PreferencesUtil.colorizePassword(context)
|
||||
&& TemplateField.isStandardPasswordName(context, label))
|
||||
PasswordGenerator.getColorizedPassword(value)
|
||||
else
|
||||
SpannableString(value)
|
||||
spannableString.setSpan(
|
||||
StyleSpan(Typeface.BOLD),
|
||||
0,
|
||||
spannableString.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
valueView.setText(spannableString)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.template.TemplateField
|
||||
import com.kunzisoft.keepass.model.EntryInfo.Companion.APPLICATION_ID_FIELD_NAME
|
||||
import com.kunzisoft.keepass.password.PasswordGenerator
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.utils.UriUtil
|
||||
|
||||
|
||||
@@ -199,16 +200,11 @@ class TextFieldView @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
set(value) {
|
||||
val spannableString =
|
||||
if (TemplateField.isStandardPasswordName(context, label))
|
||||
if (PreferencesUtil.colorizePassword(context)
|
||||
&& TemplateField.isStandardPasswordName(context, label))
|
||||
PasswordGenerator.getColorizedPassword(value)
|
||||
else
|
||||
SpannableString(value)
|
||||
spannableString.setSpan(
|
||||
StyleSpan(Typeface.BOLD),
|
||||
0,
|
||||
spannableString.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
valueView.text = spannableString
|
||||
changeProtectedValueParameters()
|
||||
}
|
||||
|
||||
@@ -81,10 +81,6 @@
|
||||
<bool name="lock_database_back_root_default" translatable="false">false</bool>
|
||||
<string name="lock_database_show_button_key" translatable="false">lock_database_show_button_key</string>
|
||||
<bool name="lock_database_show_button_default" translatable="false">true</bool>
|
||||
<string name="password_length_key" translatable="false">password_length_key</string>
|
||||
<string name="list_password_generator_options_key" translatable="false">list_password_generator_options_key</string>
|
||||
<string name="hide_password_key" translatable="false">hide_password_key</string>
|
||||
<bool name="hide_password_default" translatable="false">true</bool>
|
||||
<string name="allow_copy_password_key" translatable="false">allow_copy_password_key</string>
|
||||
<bool name="allow_copy_password_default" translatable="false">false</bool>
|
||||
<string name="remember_database_locations_key" translatable="false">remember_database_locations_key</string>
|
||||
@@ -195,12 +191,20 @@
|
||||
<string name="list_size_key" translatable="false">list_size_key</string>
|
||||
<string name="monospace_font_fields_enable_key" translatable="false">monospace_font_extra_fields_enable_key</string>
|
||||
<bool name="monospace_font_fields_enable_default" translatable="false">true</bool>
|
||||
<string name="hide_password_key" translatable="false">hide_password_key</string>
|
||||
<bool name="hide_password_default" translatable="false">true</bool>
|
||||
<string name="colorize_password_key" translatable="false">colorize_password_key</string>
|
||||
<bool name="colorize_password_default" translatable="false">true</bool>
|
||||
<string name="hide_expired_entries_key" translatable="false">hide_expired_entries_key</string>
|
||||
<bool name="hide_expired_entries_default" translatable="false">false</bool>
|
||||
<string name="enable_education_screens_key" translatable="false">enable_education_screens_key</string>
|
||||
<bool name="enable_education_screens_default" translatable="false">true</bool>
|
||||
<string name="reset_education_screens_key" translatable="false">relaunch_education_screens_key</string>
|
||||
|
||||
<!-- Password Generator Settings -->
|
||||
<string name="password_length_key" translatable="false">password_length_key</string>
|
||||
<string name="list_password_generator_options_key" translatable="false">list_password_generator_options_key</string>
|
||||
|
||||
<!-- Database Settings -->
|
||||
<string name="settings_database_key" translatable="false">settings_database_key</string>
|
||||
<string name="settings_database_security_key" translatable="false">settings_database_security_key</string>
|
||||
|
||||
@@ -225,6 +225,8 @@
|
||||
<string name="lowercase">Lower-case</string>
|
||||
<string name="hide_password_title">Hide passwords</string>
|
||||
<string name="hide_password_summary">Mask passwords (***) by default</string>
|
||||
<string name="colorize_password_title">Colorize passwords</string>
|
||||
<string name="colorize_password_summary">Colorize password characters by type</string>
|
||||
<string name="about">About</string>
|
||||
<string name="menu_change_key_settings">Change master key</string>
|
||||
<string name="copy_field">Copy of %1$s</string>
|
||||
|
||||
@@ -87,6 +87,22 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/password">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="@string/hide_password_key"
|
||||
android:title="@string/hide_password_title"
|
||||
android:summary="@string/hide_password_summary"
|
||||
android:defaultValue="@bool/hide_password_default"/>
|
||||
<SwitchPreference
|
||||
android:key="@string/colorize_password_key"
|
||||
android:title="@string/colorize_password_title"
|
||||
android:summary="@string/colorize_password_summary"
|
||||
android:defaultValue="@bool/colorize_password_default"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/other">
|
||||
|
||||
|
||||
@@ -93,17 +93,6 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/password">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="@string/hide_password_key"
|
||||
android:title="@string/hide_password_title"
|
||||
android:summary="@string/hide_password_summary"
|
||||
android:defaultValue="@bool/hide_password_default"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/database_history">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user