diff --git a/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java b/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java index 4e745773d..360612a9f 100644 --- a/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java +++ b/src/org/thoughtcrime/securesms/audio/AudioSlidePlayer.java @@ -1,12 +1,15 @@ package org.thoughtcrime.securesms.audio; +import android.app.Activity; import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; import android.net.Uri; import android.os.Handler; import android.os.Message; import android.util.Log; import android.util.Pair; +import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -151,6 +154,7 @@ public class AudioSlidePlayer { setPlaying(AudioSlidePlayer.this); } + keepScreenOn(true); notifyOnStart(); progressEventHandler.sendEmptyMessage(0); break; @@ -163,6 +167,7 @@ public class AudioSlidePlayer { mediaPlayer = null; } + keepScreenOn(false); notifyOnStop(); progressEventHandler.removeMessages(0); } @@ -200,6 +205,7 @@ public class AudioSlidePlayer { public synchronized void stop() { Log.i(TAG, "Stop called!"); + keepScreenOn(false); removePlaying(this); if (this.mediaPlayer != null) { @@ -285,6 +291,16 @@ public class AudioSlidePlayer { }; } + public void keepScreenOn(boolean keepOn) { + if (context instanceof Activity) { + if (keepOn) { + ((Activity) context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } else { + ((Activity) context).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + } + } + private synchronized static void setPlaying(@NonNull AudioSlidePlayer player) { if (playing.isPresent() && playing.get() != player) { playing.get().notifyOnStop();