-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
63 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/chooloo/www/koler/util/audio/AudioManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.chooloo.www.koler.util.audio | ||
|
||
import android.content.Context | ||
import android.content.Context.AUDIO_SERVICE | ||
import android.media.AudioManager | ||
|
||
class AudioManager(private val context: Context) { | ||
private val _audioManager by lazy { context.getSystemService(AUDIO_SERVICE) as AudioManager } | ||
|
||
enum class AudioMode(val mode: Int) { | ||
MODE_NORMAL(AudioManager.MODE_NORMAL), | ||
MODE_IN_CALL(AudioManager.MODE_IN_CALL), | ||
MODE_CURRENT(AudioManager.MODE_CURRENT), | ||
MODE_RINGTONE(AudioManager.MODE_RINGTONE), | ||
MODE_IN_COMMUNICATION(AudioManager.MODE_IN_COMMUNICATION) | ||
} | ||
|
||
val isPhoneSilent: Boolean | ||
get() = _audioManager.ringerMode == AudioManager.RINGER_MODE_SILENT || | ||
_audioManager.ringerMode == AudioManager.RINGER_MODE_VIBRATE | ||
|
||
var audioMode: AudioMode | ||
get() = AudioMode.values().associateBy(AudioMode::mode) | ||
.getOrDefault(_audioManager.mode, AudioMode.MODE_NORMAL) | ||
set(value) { | ||
_audioManager.mode = value.mode | ||
} | ||
|
||
var isSpeakerOn: Boolean | ||
get() = _audioManager.isSpeakerphoneOn | ||
set(value) { | ||
_audioManager.isSpeakerphoneOn = value | ||
} | ||
|
||
var isMuted: Boolean | ||
get() = _audioManager.isMicrophoneMute | ||
set(value) { | ||
_audioManager.isMicrophoneMute = value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters