Improved text setting
This commit is contained in:
parent
fe9f9cbecc
commit
b87cd8ad5b
3 changed files with 77 additions and 2 deletions
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
package org.linphone.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
|
@ -29,6 +30,8 @@ import android.util.Patterns
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.*
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
@ -186,6 +189,23 @@ fun editTextSetting(view: EditText, lambda: () -> Unit) {
|
|||
})
|
||||
}
|
||||
|
||||
@BindingAdapter("onSettingImeDone")
|
||||
fun editTextImeDone(view: EditText, lambda: () -> Unit) {
|
||||
view.setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
lambda()
|
||||
|
||||
view.clearFocus()
|
||||
|
||||
val imm = view.context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
|
||||
return@setOnEditorActionListener true
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("onFocusChangeVisibilityOf")
|
||||
fun setEditTextOnFocusChangeVisibilityOf(editText: EditText, view: View) {
|
||||
editText.setOnFocusChangeListener { _, hasFocus ->
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2021 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-android
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.linphone.views
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import org.linphone.activities.main.settings.SettingListener
|
||||
|
||||
class SettingTextInputEditText : TextInputEditText {
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
fun fakeImeDone(listener: SettingListener) {
|
||||
listener.onTextValueChanged(text.toString())
|
||||
|
||||
// Send IME action DONE to trigger onSettingImeDone binding adapter, but that doesn't work...
|
||||
// val inputConnection = BaseInputConnection(this, true)
|
||||
// inputConnection.performEditorAction(EditorInfo.IME_ACTION_DONE)
|
||||
|
||||
// Will make check icon to disappear thanks to onFocusChangeVisibilityOf binding adapter
|
||||
clearFocus()
|
||||
|
||||
// Hide keyboard
|
||||
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(windowToken, 0)
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/settings_commit_input"
|
||||
android:onClick="@{() -> listener.onTextValueChanged(settingsInput.getText().toString())}"
|
||||
android:onClick="@{() -> settingsInput.fakeImeDone(listener)}"
|
||||
android:visibility="invisible"
|
||||
android:contentDescription="@string/content_description_confirm_contact_edit"
|
||||
android:layout_width="20dp"
|
||||
|
@ -54,9 +54,10 @@
|
|||
app:helperText="@{subtitle}"
|
||||
app:helperTextEnabled="@{subtitle.length() > 0}">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<org.linphone.views.SettingTextInputEditText
|
||||
android:id="@+id/settings_input"
|
||||
onFocusChangeVisibilityOf="@{settingsCommitInput}"
|
||||
onSettingImeDone="@{() -> listener.onTextValueChanged(settingsInput.getText().toString())}"
|
||||
android:text="@{defaultValue}"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="@{inputType ?? InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS}"
|
||||
|
|
Loading…
Reference in a new issue