diff --git a/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt b/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt index 8f32610..094da61 100644 --- a/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt +++ b/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt @@ -41,6 +41,9 @@ class MainActivity : AppCompatActivity() { private lateinit var form: Form + private lateinit var toast: Toast + + private val charPool: List = ('a'..'z') + ('A'..'Z') private val INPUTS_ID = "INPUTS_ID" private val stringValues = arrayOf( @@ -64,11 +67,11 @@ class MainActivity : AppCompatActivity() { private val validateActionCallback = object : ActionCallback, Form.Callback { override fun successCallback() { - Toast.makeText(this@MainActivity, "Validate OK", Toast.LENGTH_SHORT).show() + showMessage("Validate OK") } override fun errorCallback(message: String?) { - Toast.makeText(this@MainActivity, "Validate not ok $message", Toast.LENGTH_SHORT).show() + showMessage("Validate not ok $message") } override fun callback() { @@ -76,39 +79,32 @@ class MainActivity : AppCompatActivity() { } } + private fun showMessage(message: String) { + toast.setText(message) + toast.show() + } + private val showToastActionCallback = object : ActionCallback { override fun callback() { - Toast.makeText(this@MainActivity, "Action performed", Toast.LENGTH_SHORT).show() + showMessage("Action performed") } } private val showToastCheckboxCallback = object : CheckboxCallback { - private var toast: Toast? = null override fun callback(checked: Boolean) { - toast?.cancel() - toast = Toast.makeText(this@MainActivity, "Selected: $checked", Toast.LENGTH_SHORT) - toast?.show() + showMessage("Selected: $checked") } } private val showToastStringValueCallback = object : ValueCallback { - private var toast: Toast? = null override fun callback(value: String) { - toast?.cancel() - toast = Toast.makeText(this@MainActivity, value, Toast.LENGTH_SHORT) - toast?.show() + showMessage(value) } } private val showToastDateTimeValueCallback = object : ValueCallback { - private var toast: Toast? = null override fun callback(value: Date) { - toast?.cancel() - toast = Toast.makeText( - this@MainActivity, - SimpleDateFormat("dd.MM.yyyy - HH:mm", Locale.getDefault()).format(value), - Toast.LENGTH_SHORT - ) - toast?.show() + showMessage(SimpleDateFormat("dd.MM.yyyy - HH:mm", Locale.getDefault()).format(value)) + } } @@ -116,6 +112,7 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + toast = Toast.makeText(this, "Toast", Toast.LENGTH_SHORT) form = buildForm() form.draw() //how to get inout data?? @@ -217,7 +214,7 @@ class MainActivity : AppCompatActivity() { "Edit text element text", valueChangeListener = object : ValueCallback { override fun callback(value: String) { - Toast.makeText(applicationContext, value, Toast.LENGTH_SHORT).show() + showMessage(value) } }, password = false, @@ -232,7 +229,7 @@ class MainActivity : AppCompatActivity() { fewStringValues, valueCallback = object : ValueCallback { override fun callback(value: String) { - Toast.makeText(applicationContext, value, Toast.LENGTH_SHORT).show() + showMessage(value) } } ), true, @@ -250,7 +247,7 @@ class MainActivity : AppCompatActivity() { "Edit text element text", valueChangeListener = object : ValueCallback { override fun callback(value: String) { - Toast.makeText(applicationContext, value, Toast.LENGTH_SHORT).show() + showMessage(value) } }, password = false, @@ -262,7 +259,7 @@ class MainActivity : AppCompatActivity() { "Password", "password", valueChangeListener = object : ValueCallback { override fun callback(value: String) { - Toast.makeText(applicationContext, value, Toast.LENGTH_SHORT).show() + showMessage(value) } }, password = true, formValidators = arrayListOf(notEmptyValidator) ), true @@ -270,7 +267,7 @@ class MainActivity : AppCompatActivity() { addElement(LabelInputElement("Email", "test@test.cz", "", object : ValueCallback { override fun callback(value: String) { - Toast.makeText(applicationContext, value, Toast.LENGTH_SHORT).show() + showMessage(value) } }, arrayListOf(emailValidator)), true) addElement( diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt index da46742..7115244 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt @@ -2,6 +2,7 @@ package cz.qase.android.formbuilderlibrary.element import android.content.Context import android.text.Editable +import android.text.InputType import android.text.TextWatcher import android.view.LayoutInflater import android.view.View @@ -77,6 +78,8 @@ class LabelInputElement( textInputLayout.addView(textInputEditText) textInputEditText?.setTextColorResourceId(context, formStyleBundle.secondaryTextColor) textInputEditText?.setText(value) + textInputEditText?.maxLines = 1 + textInputEditText?.inputType = InputType.TYPE_CLASS_TEXT textInputEditText?.addTextChangedListener( object : TextWatcher { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {