add haptic feedback to dialpad buttons

This commit is contained in:
tibbi 2018-09-26 23:45:27 +02:00
parent 4b645b70b3
commit 5a9513b75d
1 changed files with 19 additions and 19 deletions

View File

@ -8,10 +8,8 @@ import android.text.InputType
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.extensions.value
import android.view.View
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.adapters.ContactsAdapter
@ -30,19 +28,19 @@ class DialpadActivity : SimpleActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dialpad)
dialpad_0.setOnClickListener { dialpadPressed("0") }
dialpad_1.setOnClickListener { dialpadPressed("1") }
dialpad_2.setOnClickListener { dialpadPressed("2") }
dialpad_3.setOnClickListener { dialpadPressed("3") }
dialpad_4.setOnClickListener { dialpadPressed("4") }
dialpad_5.setOnClickListener { dialpadPressed("5") }
dialpad_6.setOnClickListener { dialpadPressed("6") }
dialpad_7.setOnClickListener { dialpadPressed("7") }
dialpad_8.setOnClickListener { dialpadPressed("8") }
dialpad_9.setOnClickListener { dialpadPressed("9") }
dialpad_asterisk.setOnClickListener { dialpadPressed("*") }
dialpad_hashtag.setOnClickListener { dialpadPressed("#") }
dialpad_clear_char.setOnClickListener { clearChar() }
dialpad_0.setOnClickListener { dialpadPressed("0", it) }
dialpad_1.setOnClickListener { dialpadPressed("1", it) }
dialpad_2.setOnClickListener { dialpadPressed("2", it) }
dialpad_3.setOnClickListener { dialpadPressed("3", it) }
dialpad_4.setOnClickListener { dialpadPressed("4", it) }
dialpad_5.setOnClickListener { dialpadPressed("5", it) }
dialpad_6.setOnClickListener { dialpadPressed("6", it) }
dialpad_7.setOnClickListener { dialpadPressed("7", it) }
dialpad_8.setOnClickListener { dialpadPressed("8", it) }
dialpad_9.setOnClickListener { dialpadPressed("9", it) }
dialpad_asterisk.setOnClickListener { dialpadPressed("*", it) }
dialpad_hashtag.setOnClickListener { dialpadPressed("#", it) }
dialpad_clear_char.setOnClickListener { clearChar(it) }
dialpad_clear_char.setOnLongClickListener { clearInput(); true }
dialpad_input.afterTextChanged { dialpadValueChanged(it) }
ContactsHelper(this).getContacts { gotContacts(it) }
@ -81,12 +79,14 @@ class DialpadActivity : SimpleActivity() {
}
}
private fun dialpadPressed(char: String) {
private fun dialpadPressed(char: String, view: View) {
dialpad_input.dispatchKeyEvent(getKeyEvent(getCharKeyCode(char)))
view.performHapticFeedback()
}
private fun clearChar() {
private fun clearChar(view: View) {
dialpad_input.dispatchKeyEvent(getKeyEvent(KeyEvent.KEYCODE_DEL))
view.performHapticFeedback()
}
private fun clearInput() {