implement char clearing at the dialpad

This commit is contained in:
tibbi 2018-09-23 10:58:51 +02:00
parent 96c6e8cd5a
commit 9b86c694ff
2 changed files with 35 additions and 2 deletions

View File

@ -1,8 +1,11 @@
package com.simplemobiletools.contacts.activities
import android.os.Bundle
import android.text.SpannableStringBuilder
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.extensions.config
import kotlinx.android.synthetic.main.activity_dialpad.*
class DialpadActivity : SimpleActivity() {
@ -22,14 +25,30 @@ class DialpadActivity : SimpleActivity() {
dialpad_9.setOnClickListener { dialpadPressed("9") }
dialpad_asterisk.setOnClickListener { dialpadPressed("*") }
dialpad_hashtag.setOnClickListener { dialpadPressed("#") }
dialpad_clear_char.setOnClickListener { clearChar() }
dialpad_clear_char.setOnLongClickListener { clearInput(); true }
}
override fun onResume() {
super.onResume()
updateTextColors(dialpad_wrapper)
dialpad_clear_char.applyColorFilter(config.textColor)
}
private fun dialpadPressed(char: String) {
dialpad_input.append(char)
}
private fun clearChar() {
val curPostion = dialpad_input.selectionEnd
val reducedPos = Math.max(curPostion - 1, 0)
val selectedString = SpannableStringBuilder(dialpad_input.text)
selectedString.replace(reducedPos, curPostion, "")
dialpad_input.text = selectedString
dialpad_input.setSelection(reducedPos)
}
private fun clearInput() {
dialpad_input.setText("")
}
}

View File

@ -18,13 +18,27 @@
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/dialpad_input"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="phone"
android:textCursorDrawable="@null"
android:textSize="@dimen/dialpad_input_text_size"
app:layout_constraintBottom_toTopOf="@+id/dialpad_2"/>
app:layout_constraintBottom_toTopOf="@+id/dialpad_2"
app:layout_constraintEnd_toStartOf="@+id/dialpad_clear_char"
app:layout_constraintStart_toStartOf="parent"/>
<ImageView
android:id="@+id/dialpad_clear_char"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:src="@drawable/ic_clear_char"
app:layout_constraintBottom_toBottomOf="@+id/dialpad_input"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/dialpad_input"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/dialpad_1"