Skip to content

Commit

Permalink
fix: setTextListeners() function deleted because editetxt is not focu…
Browse files Browse the repository at this point in the history
…sable
  • Loading branch information
Aitorbp committed Sep 18, 2024
1 parent 813b7c5 commit 62de37c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import android.net.Uri
import android.text.method.LinkMovementMethod
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.inputmethod.InputMethodManager
import android.webkit.MimeTypeMap
import android.widget.Button
import android.widget.LinearLayout
Expand Down Expand Up @@ -273,6 +274,17 @@ private fun makeIntent(file: File?, context: Context): Intent {
return sendIntent
}

fun Activity.hideSoftKeyboard() {
val focusedView = currentFocus
focusedView?.let {
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(
focusedView.windowToken,
0
)
}
}

fun Activity.checkPasscodeEnforced(securityEnforced: SecurityEnforced) {
val sharedPreferencesProvider = OCSharedPreferencesProvider(this)
val mdmProvider by inject<MdmProvider>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import android.text.Editable
import android.view.KeyEvent
import android.view.MenuItem
import android.view.View
import android.view.View.OnFocusChangeListener
import android.view.WindowManager
import android.widget.EditText
import android.widget.LinearLayout
Expand Down Expand Up @@ -162,8 +161,6 @@ class PassCodeActivity : AppCompatActivity(), NumberKeyboardListener, EnableBiom
throw IllegalArgumentException(R.string.illegal_argument_exception_message.toString() + " ")
}
}

setTextListeners()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
Expand All @@ -187,41 +184,6 @@ class PassCodeActivity : AppCompatActivity(), NumberKeyboardListener, EnableBiom
passCodeEditTexts.first()?.requestFocus()
}

/**
* Binds the appropriate listeners to the input boxes receiving each digit of the pass code.
*/
private fun setTextListeners() {
val numberOfPasscodeDigits = (passCodeViewModel.getPassCode()?.length ?: passCodeViewModel.getNumberOfPassCodeDigits())
for (i in 0 until numberOfPasscodeDigits) {

passCodeEditTexts[i]?.setOnKeyListener { v, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_TAB && event.action == KeyEvent.ACTION_DOWN) {
val focusDirection = if (passCodeEditTexts.indexOf(v) == 0) {
View.FOCUS_DOWN
} else {
View.FOCUS_RIGHT
}
v.focusSearch(focusDirection)?.requestFocus()
true
} else {
false
}
}

passCodeEditTexts[i]?.onFocusChangeListener = OnFocusChangeListener { _: View, _: Boolean ->
// Return the focus to the first EditText without number
for (j in 0 until i) {
if (passCodeEditTexts[j]?.text.toString() == "") { // TODO WIP validation
// could be done in a global way, with a single OnFocusChangeListener for all the
// input fields
passCodeEditTexts[j]?.requestFocus()
break
}
}
}
}
}

override fun onNumberClicked(number: Int) {
passCodeViewModel.onNumberClicked(number)
}
Expand Down

0 comments on commit 62de37c

Please sign in to comment.