mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Disable keyboard suggestions when typing PIN.
Converts `PinKeyboardType` to Kotlin and introduces methods to consistently configure PIN entry fields throughout the app, including a fix to disable keyboard suggestions.
This commit is contained in:
@@ -3,8 +3,6 @@ package org.thoughtcrime.securesms.components.settings.app.account
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Typeface
|
||||
import android.text.InputType
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
@@ -115,13 +113,11 @@ class AccountSettingsFragment : ComposeFragment() {
|
||||
val changeKeyboard = DialogCompat.requireViewById(dialog, R.id.reminder_change_keyboard) as MaterialButton
|
||||
|
||||
changeKeyboard.setOnClickListener {
|
||||
if (pinEditText.inputType and InputType.TYPE_CLASS_NUMBER == 0) {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_NUMBER
|
||||
changeKeyboard.setIconResource(PinKeyboardType.ALPHA_NUMERIC.iconResource)
|
||||
} else {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_TEXT
|
||||
changeKeyboard.setIconResource(PinKeyboardType.NUMERIC.iconResource)
|
||||
}
|
||||
val newType = PinKeyboardType.fromEditText(pinEditText).other
|
||||
newType.applyTo(
|
||||
pinEditText = pinEditText,
|
||||
toggleTypeButton = changeKeyboard
|
||||
)
|
||||
pinEditText.typeface = Typeface.DEFAULT
|
||||
}
|
||||
|
||||
@@ -129,19 +125,11 @@ class AccountSettingsFragment : ComposeFragment() {
|
||||
ViewUtil.focusAndShowKeyboard(pinEditText)
|
||||
}
|
||||
|
||||
when (SignalStore.pin.keyboardType) {
|
||||
PinKeyboardType.NUMERIC -> {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_NUMBER
|
||||
changeKeyboard.setIconResource(PinKeyboardType.ALPHA_NUMERIC.iconResource)
|
||||
}
|
||||
SignalStore.pin.keyboardType.applyTo(
|
||||
pinEditText = pinEditText,
|
||||
toggleTypeButton = changeKeyboard
|
||||
)
|
||||
|
||||
PinKeyboardType.ALPHA_NUMERIC -> {
|
||||
pinEditText.inputType = InputType.TYPE_CLASS_TEXT
|
||||
changeKeyboard.setIconResource(PinKeyboardType.NUMERIC.iconResource)
|
||||
}
|
||||
}
|
||||
|
||||
pinEditText.transformationMethod = PasswordTransformationMethod.getInstance()
|
||||
pinEditText.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun onTextChanged(text: String) {
|
||||
turnOffButton.isEnabled = text.length >= SvrConstants.MINIMUM_PIN_LENGTH
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.changenumber
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
@@ -53,6 +51,9 @@ class ChangeNumberRegistrationLockFragment : LoggingFragment(R.layout.fragment_c
|
||||
|
||||
private var timeRemaining: Long = 0
|
||||
|
||||
private val pinEntryKeyboardType: PinKeyboardType
|
||||
get() = PinKeyboardType.fromEditText(editText = binding.kbsLockPinInput)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
RegistrationViewDelegate.setDebugLogSubmitMultiTapView(view.findViewById(R.id.kbs_lock_pin_title))
|
||||
@@ -93,13 +94,9 @@ class ChangeNumberRegistrationLockFragment : LoggingFragment(R.layout.fragment_c
|
||||
}
|
||||
|
||||
binding.kbsLockKeyboardToggle.setOnClickListener {
|
||||
val keyboardType: PinKeyboardType = getPinEntryKeyboardType()
|
||||
updateKeyboard(keyboardType.other)
|
||||
binding.kbsLockKeyboardToggle.setIconResource(keyboardType.iconResource)
|
||||
updateKeyboard(pinEntryKeyboardType.other)
|
||||
}
|
||||
|
||||
val keyboardType: PinKeyboardType = getPinEntryKeyboardType().getOther()
|
||||
binding.kbsLockKeyboardToggle.setIconResource(keyboardType.iconResource)
|
||||
updateKeyboard(pinEntryKeyboardType)
|
||||
|
||||
viewModel.liveLockedTimeRemaining.observe(viewLifecycleOwner) { t: Long -> timeRemaining = t }
|
||||
|
||||
@@ -275,26 +272,14 @@ class ChangeNumberRegistrationLockFragment : LoggingFragment(R.layout.fragment_c
|
||||
private fun enableAndFocusPinEntry() {
|
||||
binding.kbsLockPinInput.setEnabled(true)
|
||||
binding.kbsLockPinInput.setFocusable(true)
|
||||
binding.kbsLockPinInput.transformationMethod = PasswordTransformationMethod.getInstance()
|
||||
ViewUtil.focusAndShowKeyboard(binding.kbsLockPinInput)
|
||||
}
|
||||
|
||||
private fun getPinEntryKeyboardType(): PinKeyboardType {
|
||||
val isNumeric = (binding.kbsLockPinInput.inputType and InputType.TYPE_MASK_CLASS) == InputType.TYPE_CLASS_NUMBER
|
||||
|
||||
return if (isNumeric) PinKeyboardType.NUMERIC else PinKeyboardType.ALPHA_NUMERIC
|
||||
}
|
||||
|
||||
private fun updateKeyboard(keyboard: PinKeyboardType) {
|
||||
val isAlphaNumeric = keyboard == PinKeyboardType.ALPHA_NUMERIC
|
||||
|
||||
binding.kbsLockPinInput.setInputType(
|
||||
if (isAlphaNumeric) InputType.TYPE_CLASS_TEXT
|
||||
else InputType.TYPE_CLASS_NUMBER
|
||||
private fun updateKeyboard(newType: PinKeyboardType) {
|
||||
newType.applyTo(
|
||||
pinEditText = binding.kbsLockPinInput,
|
||||
toggleTypeButton = binding.kbsLockKeyboardToggle
|
||||
)
|
||||
|
||||
binding.kbsLockPinInput.getText().clear()
|
||||
binding.kbsLockPinInput.transformationMethod = PasswordTransformationMethod.getInstance()
|
||||
}
|
||||
|
||||
private fun navigateToAccountLocked() {
|
||||
|
||||
Reference in New Issue
Block a user