Better focus implementation

This commit is contained in:
J-Jamet
2020-08-05 16:37:30 +02:00
parent bb477984aa
commit d56246767b
4 changed files with 39 additions and 10 deletions

View File

@@ -353,21 +353,18 @@ class EntryEditActivity : LockingActivity(),
EntryCustomFieldDialogFragment.getInstance().show(supportFragmentManager, "customFieldDialog")
}
private fun scrollToView(view: View?, showKeyboard: Boolean = false) {
if (showKeyboard)
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
scrollView?.post {
//scrollView?.smoothScrollTo(0, customFieldView.bottom)
scrollView?.fullScroll(View.FOCUS_DOWN)
view?.post {
view.requestFocus()
private fun scrollToView(view: View?) {
view?.post {
view.requestFocus()
scrollView?.post {
scrollView?.smoothScrollTo(0, view.bottom)
}
}
}
override fun onNewCustomFieldApproved(label: String) {
val customFieldView = entryEditContentsView?.putCustomField(label, ProtectedString())
scrollToView(customFieldView, true)
scrollToView(customFieldView)
}
override fun onNewCustomFieldCanceled(label: String) {}
@@ -495,7 +492,7 @@ class EntryEditActivity : LockingActivity(),
val otpField = OtpEntryFields.buildOtpField(otpElement,
mEntry?.title, mEntry?.username)
val otpCustomView = entryEditContentsView?.putCustomField(otpField.name, otpField.protectedValue)
scrollToView(otpCustomView, false)
scrollToView(otpCustomView)
mEntry?.putExtraField(otpField.name, otpField.protectedValue)
}

View File

@@ -28,6 +28,7 @@ import android.text.TextWatcher
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.EditText
@@ -152,6 +153,28 @@ class SetOTPDialogFragment : DialogFragment() {
otpCounterTextView?.setOnTouchListener(mOnTouchListener)
otpDigitsTextView?.setOnTouchListener(mOnTouchListener)
// To manage focus
otpPeriodTextView?.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_NEXT) {
otpDigitsTextView?.requestFocus()
true
} else
false
}
otpCounterTextView?.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_NEXT) {
otpDigitsTextView?.requestFocus()
true
} else
false
}
otpCounterTextView?.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_NEXT) {
root?.requestFocus(View.FOCUS_DOWN)
true
} else
false
}
// HOTP / TOTP Type selection
val otpTypeArray = OtpType.values()

View File

@@ -20,6 +20,7 @@
package com.kunzisoft.keepass.view
import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
@@ -101,6 +102,11 @@ class EntryEditCustomField @JvmOverloads constructor(context: Context,
valueView.applyFontVisibility()
}
override fun requestFocus(direction: Int, previouslyFocusedRect: Rect?): Boolean {
valueView.requestFocus(direction, previouslyFocusedRect)
return true
}
private fun deleteViewFromParent() {
try {
val parent = parent as ViewGroup

View File

@@ -142,6 +142,7 @@
tools:text="30"
android:maxLength="3"
android:digits="0123456789"
android:imeOptions="actionNext"
tools:targetApi="jelly_bean" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
@@ -161,6 +162,7 @@
android:importantForAutofill="no"
android:hint="@string/otp_counter"
tools:text="1"
android:imeOptions="actionNext"
tools:targetApi="jelly_bean" />
</com.google.android.material.textfield.TextInputLayout>
@@ -190,6 +192,7 @@
tools:text="6"
android:maxLength="2"
android:digits="0123456789"
android:imeOptions="actionNext"
tools:targetApi="jelly_bean" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>