mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-04-04 21:31:06 +02:00
implement microphone and speaker toggling via the audiomanager
This commit is contained in:
parent
390c4f8b54
commit
2a0cbe9b4f
app/src/main
AndroidManifest.xml
kotlin/com/simplemobiletools/contacts/pro
@ -15,6 +15,7 @@
|
|||||||
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
|
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||||
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
|
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
|
||||||
|
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||||
|
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
|
@ -5,6 +5,7 @@ import android.app.*
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.*
|
import android.graphics.*
|
||||||
|
import android.media.AudioManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
@ -20,6 +21,7 @@ import com.simplemobiletools.commons.helpers.isOreoMr1Plus
|
|||||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||||
import com.simplemobiletools.commons.helpers.isQPlus
|
import com.simplemobiletools.commons.helpers.isQPlus
|
||||||
import com.simplemobiletools.contacts.pro.R
|
import com.simplemobiletools.contacts.pro.R
|
||||||
|
import com.simplemobiletools.contacts.pro.extensions.audioManager
|
||||||
import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL
|
import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL
|
||||||
import com.simplemobiletools.contacts.pro.helpers.CallManager
|
import com.simplemobiletools.contacts.pro.helpers.CallManager
|
||||||
import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL
|
import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL
|
||||||
@ -88,12 +90,14 @@ class CallActivity : SimpleActivity() {
|
|||||||
isSpeakerOn = !isSpeakerOn
|
isSpeakerOn = !isSpeakerOn
|
||||||
val drawable = if (isSpeakerOn) R.drawable.ic_speaker_on_vector else R.drawable.ic_speaker_off_vector
|
val drawable = if (isSpeakerOn) R.drawable.ic_speaker_on_vector else R.drawable.ic_speaker_off_vector
|
||||||
call_toggle_speaker.setImageDrawable(getDrawable(drawable))
|
call_toggle_speaker.setImageDrawable(getDrawable(drawable))
|
||||||
|
audioManager.isSpeakerphoneOn = isSpeakerOn
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleMicrophone() {
|
private fun toggleMicrophone() {
|
||||||
isMicrophoneOn = !isMicrophoneOn
|
isMicrophoneOn = !isMicrophoneOn
|
||||||
val drawable = if (isMicrophoneOn) R.drawable.ic_microphone_vector else R.drawable.ic_microphone_off_vector
|
val drawable = if (isMicrophoneOn) R.drawable.ic_microphone_vector else R.drawable.ic_microphone_off_vector
|
||||||
call_toggle_microphone.setImageDrawable(getDrawable(drawable))
|
call_toggle_microphone.setImageDrawable(getDrawable(drawable))
|
||||||
|
audioManager.isMicrophoneMute = !isMicrophoneOn
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateOtherPersonsInfo() {
|
private fun updateOtherPersonsInfo() {
|
||||||
@ -126,6 +130,7 @@ class CallActivity : SimpleActivity() {
|
|||||||
incoming_call_holder.beGone()
|
incoming_call_holder.beGone()
|
||||||
ongoing_call_holder.beVisible()
|
ongoing_call_holder.beVisible()
|
||||||
proximityWakeLock?.acquire(10 * MINUTE_SECONDS * 1000L)
|
proximityWakeLock?.acquire(10 * MINUTE_SECONDS * 1000L)
|
||||||
|
audioManager.mode = AudioManager.MODE_IN_CALL
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun endCall() {
|
private fun endCall() {
|
||||||
@ -133,6 +138,7 @@ class CallActivity : SimpleActivity() {
|
|||||||
if (proximityWakeLock?.isHeld == true) {
|
if (proximityWakeLock?.isHeld == true) {
|
||||||
proximityWakeLock!!.release()
|
proximityWakeLock!!.release()
|
||||||
}
|
}
|
||||||
|
audioManager.mode = AudioManager.MODE_NORMAL
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package com.simplemobiletools.contacts.pro.extensions
|
package com.simplemobiletools.contacts.pro.extensions
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Context.AUDIO_SERVICE
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
|
import android.media.AudioManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
@ -32,6 +34,8 @@ val Context.contactsDB: ContactsDao get() = ContactsDatabase.getInstance(applica
|
|||||||
|
|
||||||
val Context.groupsDB: GroupsDao get() = ContactsDatabase.getInstance(applicationContext).GroupsDao()
|
val Context.groupsDB: GroupsDao get() = ContactsDatabase.getInstance(applicationContext).GroupsDao()
|
||||||
|
|
||||||
|
val Context.audioManager: AudioManager get() = getSystemService(AUDIO_SERVICE) as AudioManager
|
||||||
|
|
||||||
fun Context.getEmptyContact(): Contact {
|
fun Context.getEmptyContact(): Contact {
|
||||||
val originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
val originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||||
val organization = Organization("", "")
|
val organization = Organization("", "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user