mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-04-22 14:07:20 +02:00
Add dialpad tones, vibration preferences
This commit is contained in:
parent
a8d0a23178
commit
c5aa7d6a91
@ -18,6 +18,7 @@
|
|||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
<uses-permission android:name="android.telecom.action.CONFIGURE_PHONE_ACCOUNT" />
|
<uses-permission android:name="android.telecom.action.CONFIGURE_PHONE_ACCOUNT" />
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
|
@ -164,12 +164,13 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun dialpadPressed(char: Char, view: View?) {
|
private fun dialpadPressed(char: Char, view: View?) {
|
||||||
dialpad_input.addCharacter(char)
|
dialpad_input.addCharacter(char)
|
||||||
view?.performHapticFeedback()
|
maybePerformDialpadHapticFeedback(view)
|
||||||
|
maybePlayDialpadTone(char)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearChar(view: View) {
|
private fun clearChar(view: View) {
|
||||||
dialpad_input.dispatchKeyEvent(dialpad_input.getKeyEvent(KeyEvent.KEYCODE_DEL))
|
dialpad_input.dispatchKeyEvent(dialpad_input.getKeyEvent(KeyEvent.KEYCODE_DEL))
|
||||||
view.performHapticFeedback()
|
maybePerformDialpadHapticFeedback(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearInput() {
|
private fun clearInput() {
|
||||||
@ -271,6 +272,7 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun speedDial(id: Int) {
|
private fun speedDial(id: Int) {
|
||||||
|
maybePlayDialpadTone(id.digitToChar())
|
||||||
if (dialpad_input.value.isEmpty()) {
|
if (dialpad_input.value.isEmpty()) {
|
||||||
val speedDial = speedDialValues.firstOrNull { it.id == id }
|
val speedDial = speedDialValues.firstOrNull { it.id == id }
|
||||||
if (speedDial?.isValid() == true) {
|
if (speedDial?.isValid() == true) {
|
||||||
@ -289,4 +291,21 @@ class DialpadActivity : SimpleActivity() {
|
|||||||
russianCharsMap['ш'] = 8; russianCharsMap['щ'] = 8; russianCharsMap['ъ'] = 8; russianCharsMap['ы'] = 8
|
russianCharsMap['ш'] = 8; russianCharsMap['щ'] = 8; russianCharsMap['ъ'] = 8; russianCharsMap['ы'] = 8
|
||||||
russianCharsMap['ь'] = 9; russianCharsMap['э'] = 9; russianCharsMap['ю'] = 9; russianCharsMap['я'] = 9
|
russianCharsMap['ь'] = 9; russianCharsMap['э'] = 9; russianCharsMap['ю'] = 9; russianCharsMap['я'] = 9
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun maybePlayDialpadTone(char: Char) {
|
||||||
|
if (config.dialpadBeeps) {
|
||||||
|
if (char == '+') {
|
||||||
|
// 0 is being long pressed
|
||||||
|
playOnetimeTone('0')
|
||||||
|
} else {
|
||||||
|
playOnetimeTone(char)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun maybePerformDialpadHapticFeedback(view: View?) {
|
||||||
|
if (config.dialpadVibration) {
|
||||||
|
view?.performHapticFeedback()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
setupDialPadOpen()
|
setupDialPadOpen()
|
||||||
setupGroupSubsequentCalls()
|
setupGroupSubsequentCalls()
|
||||||
setupStartNameWithSurname()
|
setupStartNameWithSurname()
|
||||||
|
setupDialpadVibrations()
|
||||||
|
setupDialpadBeeps()
|
||||||
setupShowCallConfirmation()
|
setupShowCallConfirmation()
|
||||||
setupDisableProximitySensor()
|
setupDisableProximitySensor()
|
||||||
setupDisableSwipeToAnswer()
|
setupDisableSwipeToAnswer()
|
||||||
@ -206,6 +208,22 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupDialpadVibrations() {
|
||||||
|
settings_dialpad_vibration.isChecked = config.dialpadVibration
|
||||||
|
settings_dialpad_vibration_holder.setOnClickListener {
|
||||||
|
settings_dialpad_vibration.toggle()
|
||||||
|
config.dialpadVibration = settings_dialpad_vibration.isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupDialpadBeeps() {
|
||||||
|
settings_dialpad_beeps.isChecked = config.dialpadBeeps
|
||||||
|
settings_dialpad_beeps_holder.setOnClickListener {
|
||||||
|
settings_dialpad_beeps.toggle()
|
||||||
|
config.dialpadBeeps = settings_dialpad_beeps.isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupShowCallConfirmation() {
|
private fun setupShowCallConfirmation() {
|
||||||
settings_show_call_confirmation.isChecked = config.showCallConfirmation
|
settings_show_call_confirmation.isChecked = config.showCallConfirmation
|
||||||
settings_show_call_confirmation_holder.setOnClickListener {
|
settings_show_call_confirmation_holder.setOnClickListener {
|
||||||
|
@ -7,6 +7,7 @@ import android.net.Uri
|
|||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import com.simplemobiletools.commons.extensions.telecomManager
|
import com.simplemobiletools.commons.extensions.telecomManager
|
||||||
import com.simplemobiletools.dialer.helpers.Config
|
import com.simplemobiletools.dialer.helpers.Config
|
||||||
|
import com.simplemobiletools.dialer.helpers.ToneGeneratorHelper
|
||||||
import com.simplemobiletools.dialer.models.SIMAccount
|
import com.simplemobiletools.dialer.models.SIMAccount
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
@ -44,3 +45,11 @@ fun Context.areMultipleSIMsAvailable(): Boolean {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var toneGeneratorHelperInstance: ToneGeneratorHelper? = null
|
||||||
|
fun Context.playOnetimeTone(char: Char) {
|
||||||
|
if (toneGeneratorHelperInstance == null) {
|
||||||
|
toneGeneratorHelperInstance = ToneGeneratorHelper(this)
|
||||||
|
}
|
||||||
|
toneGeneratorHelperInstance?.playTone(char)
|
||||||
|
}
|
||||||
|
@ -71,4 +71,12 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var wasOverlaySnackbarConfirmed: Boolean
|
var wasOverlaySnackbarConfirmed: Boolean
|
||||||
get() = prefs.getBoolean(WAS_OVERLAY_SNACKBAR_CONFIRMED, false)
|
get() = prefs.getBoolean(WAS_OVERLAY_SNACKBAR_CONFIRMED, false)
|
||||||
set(wasOverlaySnackbarConfirmed) = prefs.edit().putBoolean(WAS_OVERLAY_SNACKBAR_CONFIRMED, wasOverlaySnackbarConfirmed).apply()
|
set(wasOverlaySnackbarConfirmed) = prefs.edit().putBoolean(WAS_OVERLAY_SNACKBAR_CONFIRMED, wasOverlaySnackbarConfirmed).apply()
|
||||||
|
|
||||||
|
var dialpadVibration: Boolean
|
||||||
|
get() = prefs.getBoolean(DIALPAD_VIBRATION, true)
|
||||||
|
set(dialpadVibration) = prefs.edit().putBoolean(DIALPAD_VIBRATION, dialpadVibration).apply()
|
||||||
|
|
||||||
|
var dialpadBeeps: Boolean
|
||||||
|
get() = prefs.getBoolean(DIALPAD_BEEPS, false)
|
||||||
|
set(dialpadBeeps) = prefs.edit().putBoolean(DIALPAD_BEEPS, dialpadBeeps).apply()
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.simplemobiletools.dialer.helpers
|
package com.simplemobiletools.dialer.helpers
|
||||||
|
|
||||||
|
import com.simplemobiletools.commons.helpers.TAB_CALL_HISTORY
|
||||||
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
|
import com.simplemobiletools.commons.helpers.TAB_CONTACTS
|
||||||
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
|
import com.simplemobiletools.commons.helpers.TAB_FAVORITES
|
||||||
import com.simplemobiletools.commons.helpers.TAB_CALL_HISTORY
|
|
||||||
|
|
||||||
// shared prefs
|
// shared prefs
|
||||||
const val SPEED_DIAL = "speed_dial"
|
const val SPEED_DIAL = "speed_dial"
|
||||||
@ -15,7 +15,8 @@ const val SHOW_TABS = "show_tabs"
|
|||||||
const val FAVORITES_CONTACTS_ORDER = "favorites_contacts_order"
|
const val FAVORITES_CONTACTS_ORDER = "favorites_contacts_order"
|
||||||
const val FAVORITES_CUSTOM_ORDER_SELECTED = "favorites_custom_order_selected"
|
const val FAVORITES_CUSTOM_ORDER_SELECTED = "favorites_custom_order_selected"
|
||||||
const val WAS_OVERLAY_SNACKBAR_CONFIRMED = "was_overlay_snackbar_confirmed"
|
const val WAS_OVERLAY_SNACKBAR_CONFIRMED = "was_overlay_snackbar_confirmed"
|
||||||
|
const val DIALPAD_VIBRATION = "touch_vibration"
|
||||||
|
const val DIALPAD_BEEPS = "dialpad_beeps"
|
||||||
const val ALL_TABS_MASK = TAB_CONTACTS or TAB_FAVORITES or TAB_CALL_HISTORY
|
const val ALL_TABS_MASK = TAB_CONTACTS or TAB_FAVORITES or TAB_CALL_HISTORY
|
||||||
|
|
||||||
val tabsList = arrayListOf(TAB_CONTACTS, TAB_FAVORITES, TAB_CALL_HISTORY)
|
val tabsList = arrayListOf(TAB_CONTACTS, TAB_FAVORITES, TAB_CALL_HISTORY)
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.simplemobiletools.dialer.helpers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.media.AudioManager
|
||||||
|
import android.media.AudioManager.STREAM_DTMF
|
||||||
|
import android.media.ToneGenerator
|
||||||
|
|
||||||
|
class ToneGeneratorHelper(context: Context) {
|
||||||
|
private val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
|
private val toneGenerator = ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME)
|
||||||
|
|
||||||
|
private val isSilent: Boolean
|
||||||
|
get() = audioManager.ringerMode in arrayOf(AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE)
|
||||||
|
|
||||||
|
fun playTone(char: Char) = playTone(charToTone[char] ?: -1)
|
||||||
|
|
||||||
|
fun playTone(tone: Int, durationMs: Int = TONE_LENGTH_MS) {
|
||||||
|
if (tone != -1 && !isSilent) {
|
||||||
|
toneGenerator.stopTone()
|
||||||
|
toneGenerator.startTone(tone, durationMs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TONE_LENGTH_MS = 150 // The length of DTMF tones in milliseconds
|
||||||
|
const val TONE_RELATIVE_VOLUME = 80 // The DTMF tone volume relative to other sounds in the stream
|
||||||
|
const val DIAL_TONE_STREAM_TYPE = STREAM_DTMF
|
||||||
|
|
||||||
|
private val charToTone by lazy {
|
||||||
|
HashMap<Char, Int>().apply {
|
||||||
|
put('0', ToneGenerator.TONE_DTMF_0)
|
||||||
|
put('1', ToneGenerator.TONE_DTMF_1)
|
||||||
|
put('2', ToneGenerator.TONE_DTMF_2)
|
||||||
|
put('3', ToneGenerator.TONE_DTMF_3)
|
||||||
|
put('4', ToneGenerator.TONE_DTMF_4)
|
||||||
|
put('5', ToneGenerator.TONE_DTMF_5)
|
||||||
|
put('6', ToneGenerator.TONE_DTMF_6)
|
||||||
|
put('7', ToneGenerator.TONE_DTMF_7)
|
||||||
|
put('8', ToneGenerator.TONE_DTMF_8)
|
||||||
|
put('9', ToneGenerator.TONE_DTMF_9)
|
||||||
|
put('#', ToneGenerator.TONE_DTMF_P)
|
||||||
|
put('*', ToneGenerator.TONE_DTMF_S)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -189,7 +189,7 @@
|
|||||||
style="@style/SettingsHolderCheckboxStyle"
|
style="@style/SettingsHolderCheckboxStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/ripple_bottom_corners">
|
android:background="@drawable/ripple_background">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
android:id="@+id/settings_start_name_with_surname"
|
android:id="@+id/settings_start_name_with_surname"
|
||||||
@ -199,6 +199,38 @@
|
|||||||
android:text="@string/start_name_with_surname" />
|
android:text="@string/start_name_with_surname" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/settings_dialpad_vibration_holder"
|
||||||
|
style="@style/SettingsHolderCheckboxStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/ripple_background">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
|
android:id="@+id/settings_dialpad_vibration"
|
||||||
|
style="@style/SettingsCheckboxStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/dialpad_vibrations" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/settings_dialpad_beeps_holder"
|
||||||
|
style="@style/SettingsHolderCheckboxStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/ripple_bottom_corners">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
|
android:id="@+id/settings_dialpad_beeps"
|
||||||
|
style="@style/SettingsCheckboxStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/dialpad_beeps" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
Loading…
x
Reference in New Issue
Block a user