-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from Futsch1/319-alarm-sounds-while-phone-is-…
…muted 319 alarm sounds while phone is muted
- Loading branch information
Showing
162 changed files
with
235 additions
and
50 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
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
91 changes: 91 additions & 0 deletions
91
app/src/main/java/com/futsch1/medtimer/reminders/NotificationSoundManager.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,91 @@ | ||
package com.futsch1.medtimer.reminders | ||
|
||
import android.app.NotificationManager | ||
import android.content.Context | ||
import android.media.AudioManager | ||
import android.os.Build | ||
import android.os.Handler | ||
import android.os.Looper | ||
import androidx.preference.PreferenceManager | ||
import com.futsch1.medtimer.PreferencesNames | ||
|
||
class NotificationSoundManager(val context: Context) { | ||
private val notificationManager: NotificationManager = | ||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
private val audioManager: AudioManager = | ||
context.getSystemService(Context.AUDIO_SERVICE) as AudioManager | ||
|
||
init { | ||
if (notificationManager.isNotificationPolicyAccessGranted() && PreferenceManager.getDefaultSharedPreferences( | ||
context | ||
) | ||
.getBoolean(PreferencesNames.OVERRIDE_DND, false) | ||
) { | ||
loadPendingRingerMode(audioManager, notificationManager) | ||
} | ||
} | ||
|
||
fun restore() { | ||
restorePendingRingerMode(audioManager) | ||
} | ||
|
||
companion object { | ||
private var pending = false | ||
private var pendingWasMuted = false | ||
private var scheduledRunnable: Runnable? = null | ||
private val handler = Handler(Looper.getMainLooper()) | ||
|
||
@Synchronized | ||
fun loadPendingRingerMode( | ||
audioManager: AudioManager, | ||
notificationManager: NotificationManager | ||
) { | ||
if (!pending) { | ||
pending = true | ||
if (audioManager.isStreamMute(AudioManager.STREAM_RING) && notificationManager.currentInterruptionFilter == NotificationManager.INTERRUPTION_FILTER_ALL) { | ||
audioManager.adjustStreamVolume( | ||
AudioManager.STREAM_RING, | ||
AudioManager.ADJUST_UNMUTE, | ||
0 | ||
) | ||
pendingWasMuted = true | ||
} | ||
val policy = notificationManager.notificationPolicy | ||
notificationManager.notificationPolicy = NotificationManager.Policy( | ||
policy.priorityCategories or NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS, | ||
policy.priorityCallSenders, | ||
policy.priorityMessageSenders, | ||
0 | ||
) | ||
} | ||
} | ||
|
||
@Synchronized | ||
fun restorePendingRingerMode( | ||
audioManager: AudioManager | ||
) { | ||
if (pending && scheduledRunnable == null) { | ||
scheduledRunnable = createRunnable(audioManager) | ||
} | ||
if (scheduledRunnable != null) { | ||
handler.removeCallbacks(scheduledRunnable!!) | ||
handler.postDelayed(scheduledRunnable!!, 5000) | ||
} | ||
} | ||
|
||
private fun createRunnable(audioManager: AudioManager) = Runnable { | ||
if (pendingWasMuted) { | ||
audioManager.adjustStreamVolume( | ||
AudioManager.STREAM_RING, | ||
AudioManager.ADJUST_MUTE, | ||
0 | ||
) | ||
if (Build.VERSION.SDK_INT > 28) { | ||
audioManager.ringerMode = AudioManager.RINGER_MODE_VIBRATE | ||
} | ||
} | ||
pending = false | ||
scheduledRunnable = null | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:width="16dp" | ||
android:height="16dp" | ||
android:viewportWidth="16" | ||
android:viewportHeight="16"> | ||
<path | ||
android:pathData="M14,4.5L14,14a2,2 0,0 1,-2 2h-1v-1h1a1,1 0,0 0,1 -1L13,4.5h-2A1.5,1.5 0,0 1,9.5 3L9.5,1L4,1a1,1 0,0 0,-1 1v9L2,11L2,2a2,2 0,0 1,2 -2h5.5zM3.517,14.841a1.13,1.13 0,0 0,0.401 0.823q0.195,0.162 0.478,0.252 0.284,0.091 0.665,0.091 0.507,0 0.859,-0.158 0.354,-0.158 0.539,-0.44 0.187,-0.284 0.187,-0.656 0,-0.336 -0.134,-0.56a1,1 0,0 0,-0.375 -0.357,2 2,0 0,0 -0.566,-0.21l-0.621,-0.144a1,1 0,0 1,-0.404 -0.176,0.37 0.37,0 0,1 -0.144,-0.299q0,-0.234 0.185,-0.384 0.188,-0.152 0.512,-0.152 0.214,0 0.37,0.068a0.6,0.6 0,0 1,0.246 0.181,0.56 0.56,0 0,1 0.12,0.258h0.75a1.1,1.1 0,0 0,-0.2 -0.566,1.2 1.2,0 0,0 -0.5,-0.41 1.8,1.8 0,0 0,-0.78 -0.152q-0.439,0 -0.776,0.15 -0.337,0.149 -0.527,0.421 -0.19,0.273 -0.19,0.639 0,0.302 0.122,0.524 0.124,0.223 0.352,0.367 0.228,0.143 0.539,0.213l0.618,0.144q0.31,0.073 0.463,0.193a0.39,0.39 0,0 1,0.152 0.326,0.5 0.5,0 0,1 -0.085,0.29 0.56,0.56 0,0 1,-0.255 0.193q-0.167,0.07 -0.413,0.07 -0.175,0 -0.32,-0.04a0.8,0.8 0,0 1,-0.248 -0.115,0.58 0.58,0 0,1 -0.255,-0.384zM0.806,13.693q0,-0.373 0.102,-0.633a0.87,0.87 0,0 1,0.302 -0.399,0.8 0.8,0 0,1 0.475,-0.137q0.225,0 0.398,0.097a0.7,0.7 0,0 1,0.272 0.26,0.85 0.85,0 0,1 0.12,0.381h0.765v-0.072a1.33,1.33 0,0 0,-0.466 -0.964,1.4 1.4,0 0,0 -0.489,-0.272 1.8,1.8 0,0 0,-0.606 -0.097q-0.534,0 -0.911,0.223 -0.375,0.222 -0.572,0.632 -0.195,0.41 -0.196,0.979v0.498q0,0.568 0.193,0.976 0.197,0.407 0.572,0.626 0.375,0.217 0.914,0.217 0.439,0 0.785,-0.164t0.55,-0.454a1.27,1.27 0,0 0,0.226 -0.674v-0.076h-0.764a0.8,0.8 0,0 1,-0.118 0.363,0.7 0.7,0 0,1 -0.272,0.25 0.9,0.9 0,0 1,-0.401 0.087,0.85 0.85,0 0,1 -0.478,-0.132 0.83,0.83 0,0 1,-0.299 -0.392,1.7 1.7,0 0,1 -0.102,-0.627zM9.045,15.931h-0.953l-1.338,-3.999h0.917l0.896,3.138h0.038l0.888,-3.138h0.879z" | ||
android:fillColor="?android:colorForeground" | ||
android:fillType="evenOdd"/> | ||
android:fillType="evenOdd" | ||
tools:ignore="VectorPath" /> | ||
</vector> |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:width="16dp" | ||
android:height="16dp" | ||
android:viewportWidth="16" | ||
android:viewportHeight="16"> | ||
<path | ||
android:pathData="M14,4.5L14,14a2,2 0,0 1,-2 2h-1v-1h1a1,1 0,0 0,1 -1L13,4.5h-2A1.5,1.5 0,0 1,9.5 3L9.5,1L4,1a1,1 0,0 0,-1 1v9L2,11L2,2a2,2 0,0 1,2 -2h5.5zM1.6,11.85L0,11.85v3.999h0.791v-1.342h0.803q0.43,0 0.732,-0.173 0.305,-0.175 0.463,-0.474a1.4,1.4 0,0 0,0.161 -0.677q0,-0.375 -0.158,-0.677a1.2,1.2 0,0 0,-0.46 -0.477q-0.3,-0.18 -0.732,-0.179m0.545,1.333a0.8,0.8 0,0 1,-0.085 0.38,0.57 0.57,0 0,1 -0.238,0.241 0.8,0.8 0,0 1,-0.375 0.082L0.788,13.886L0.788,12.48h0.66q0.327,0 0.512,0.181 0.185,0.183 0.185,0.522m1.217,-1.333v3.999h1.46q0.602,0 0.998,-0.237a1.45,1.45 0,0 0,0.595 -0.689q0.196,-0.45 0.196,-1.084 0,-0.63 -0.196,-1.075a1.43,1.43 0,0 0,-0.589 -0.68q-0.396,-0.234 -1.005,-0.234zM4.153,12.495h0.563q0.371,0 0.609,0.152a0.9,0.9 0,0 1,0.354 0.454q0.118,0.302 0.118,0.753a2.3,2.3 0,0 1,-0.068 0.592,1.1 1.1,0 0,1 -0.196,0.422 0.8,0.8 0,0 1,-0.334 0.252,1.3 1.3,0 0,1 -0.483,0.082h-0.563zM7.896,14.258v1.591h-0.79L7.106,11.85h2.548v0.653L7.896,12.503v1.117h1.606v0.638z" | ||
android:fillColor="?android:colorForeground" | ||
android:fillType="evenOdd"/> | ||
android:fillType="evenOdd" | ||
tools:ignore="VectorPath" /> | ||
</vector> |
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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
Oops, something went wrong.