Set max chars

This commit is contained in:
J-Jamet
2021-07-09 13:54:46 +02:00
parent 32b8c505d9
commit 876e749b31
4 changed files with 44 additions and 9 deletions

View File

@@ -20,6 +20,7 @@
package com.kunzisoft.keepass.view
import android.content.Context
import android.text.InputFilter
import android.text.util.Linkify
import android.util.AttributeSet
import android.view.LayoutInflater
@@ -87,15 +88,26 @@ class TextFieldView @JvmOverloads constructor(context: Context,
changeProtectedValueParameters()
}
fun setMaxChars(numberChars: Int) {
when {
numberChars <= 0 -> {
valueView.filters += InputFilter.LengthFilter(MAX_CHARS_LIMIT)
}
else -> {
val chars = if (numberChars > MAX_CHARS_LIMIT) MAX_CHARS_LIMIT else numberChars
valueView.filters += InputFilter.LengthFilter(chars)
}
}
}
fun setMaxLines(numberLines: Int) {
when {
numberLines <= 0 -> {
valueView.maxEms = 40
valueView.maxLines = 40
valueView.maxLines = MAX_LINES_LIMIT
}
else -> {
valueView.maxEms = numberLines
valueView.maxLines = numberLines
val lines = if (numberLines > MAX_LINES_LIMIT) MAX_LINES_LIMIT else numberLines
valueView.maxLines = lines
}
}
}
@@ -202,4 +214,9 @@ class TextFieldView @JvmOverloads constructor(context: Context,
enum class ButtonState {
ACTIVATE, DEACTIVATE, GONE
}
companion object {
const val MAX_CHARS_LIMIT = Integer.MAX_VALUE
const val MAX_LINES_LIMIT = 40
}
}