Added setting to have a small vibration when pressing keypad numbers
This commit is contained in:
parent
fb5a96dee8
commit
38d24fd113
6 changed files with 44 additions and 2 deletions
|
@ -20,11 +20,15 @@
|
|||
package org.linphone.activities.call.viewmodels
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.os.Vibrator
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import kotlin.math.max
|
||||
import org.linphone.LinphoneApplication
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.activities.main.dialer.NumpadDigitListener
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.Event
|
||||
|
@ -81,11 +85,17 @@ class ControlsViewModel : ViewModel() {
|
|||
|
||||
val somethingClickedEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
private val vibrator = coreContext.context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
|
||||
val onKeyClick: NumpadDigitListener = object : NumpadDigitListener {
|
||||
override fun handleClick(key: Char) {
|
||||
coreContext.core.playDtmf(key, 1)
|
||||
somethingClickedEvent.value = Event(true)
|
||||
coreContext.core.currentCall?.sendDtmf(key)
|
||||
|
||||
if (vibrator.hasVibrator() && LinphoneApplication.corePreferences.dtmfKeypadVibration) {
|
||||
Compatibility.eventVibration(vibrator)
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleLongClick(key: Char): Boolean {
|
||||
|
|
|
@ -19,11 +19,14 @@
|
|||
*/
|
||||
package org.linphone.activities.main.dialer.viewmodels
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Vibrator
|
||||
import android.provider.Settings
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.activities.main.dialer.NumpadDigitListener
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.Event
|
||||
|
@ -47,6 +50,8 @@ class DialerViewModel : LogsUploadViewModel() {
|
|||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
private val vibrator = coreContext.context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
|
||||
private var addressWaitingNetworkToBeCalled: String? = null
|
||||
private var timeAtWitchWeTriedToCall: Long = 0
|
||||
|
||||
|
@ -55,9 +60,12 @@ class DialerViewModel : LogsUploadViewModel() {
|
|||
enteredUri.value += key.toString()
|
||||
if (coreContext.core.callsNb == 0) {
|
||||
val contentResolver = coreContext.context.contentResolver
|
||||
val dtmfSetting = Settings.System.getInt(contentResolver, Settings.System.DTMF_TONE_WHEN_DIALING)
|
||||
if (dtmfSetting == 1) {
|
||||
if (Settings.System.getInt(contentResolver, Settings.System.DTMF_TONE_WHEN_DIALING) == 1) {
|
||||
coreContext.core.playDtmf(key, 1)
|
||||
|
||||
if (vibrator.hasVibrator() && corePreferences.dtmfKeypadVibration) {
|
||||
Compatibility.eventVibration(vibrator)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,11 @@ class Api21Compatibility {
|
|||
vibrator.vibrate(pattern, 1)
|
||||
}
|
||||
|
||||
fun eventVibration(vibrator: Vibrator) {
|
||||
val pattern = longArrayOf(0, 100, 100)
|
||||
vibrator.vibrate(pattern, -1)
|
||||
}
|
||||
|
||||
suspend fun addImageToMediaStore(context: Context, content: Content): Boolean {
|
||||
val filePath = content.filePath
|
||||
if (filePath == null) {
|
||||
|
|
|
@ -111,5 +111,13 @@ class Api26Compatibility {
|
|||
.build()
|
||||
vibrator.vibrate(effect, audioAttrs)
|
||||
}
|
||||
|
||||
fun eventVibration(vibrator: Vibrator) {
|
||||
val effect = VibrationEffect.createWaveform(longArrayOf(0L, 100L, 100L), intArrayOf(0, VibrationEffect.DEFAULT_AMPLITUDE, 0), -1)
|
||||
val audioAttrs = AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
|
||||
.build()
|
||||
vibrator.vibrate(effect, audioAttrs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,6 +115,14 @@ class Compatibility {
|
|||
}
|
||||
}
|
||||
|
||||
fun eventVibration(vibrator: Vibrator) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
Api26Compatibility.eventVibration(vibrator)
|
||||
} else {
|
||||
Api21Compatibility.eventVibration(vibrator)
|
||||
}
|
||||
}
|
||||
|
||||
/* Contacts */
|
||||
|
||||
fun createShortcutsToContacts(context: Context) {
|
||||
|
|
|
@ -290,6 +290,9 @@ class CorePreferences constructor(private val context: Context) {
|
|||
val hideCameraPreviewInPipMode: Boolean
|
||||
get() = config.getBool("app", "hide_camera_preview_in_pip_mode", false)
|
||||
|
||||
val dtmfKeypadVibration: Boolean
|
||||
get() = config.getBool("app", "dtmf_keypad_vibraton", false)
|
||||
|
||||
/* Tabs */
|
||||
|
||||
val showHistory: Boolean
|
||||
|
|
Loading…
Reference in a new issue