diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/AbsMusicServiceFragment.java b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/AbsMusicServiceFragment.java
index 78847652a..28ef497d0 100644
--- a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/AbsMusicServiceFragment.java
+++ b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/AbsMusicServiceFragment.java
@@ -5,9 +5,13 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
import com.kabouzeid.gramophone.interfaces.MusicServiceEventListener;
import com.kabouzeid.gramophone.ui.activities.base.AbsMusicServiceActivity;
+import com.kabouzeid.gramophone.util.PreferenceUtil;
/**
* @author Karim Abou Zeid (kabouzeid)
@@ -43,6 +47,24 @@ public void onDestroyView() {
activity.removeMusicServiceEventListener(this);
}
+ @Override
+ public void onResume() {
+ super.onResume();
+ updateScreenOnState(requireActivity().getWindow());
+ }
+
+ private void updateScreenOnState(Window window){
+ if (isKeepScreenOnWhilePlaying() && MusicPlayerRemote.isPlaying()) {
+ window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ } else {
+ window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+ }
+
+ private boolean isKeepScreenOnWhilePlaying(){
+ return PreferenceUtil.getInstance(requireActivity()).keepScreenOnWhilePlaying();
+ }
+
@Override
public void onPlayingMetaChanged() {
@@ -65,7 +87,7 @@ public void onQueueChanged() {
@Override
public void onPlayStateChanged() {
-
+ updateScreenOnState(requireActivity().getWindow());
}
@Override
diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/MiniPlayerFragment.java b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/MiniPlayerFragment.java
index 37b730d17..b83ef887a 100644
--- a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/MiniPlayerFragment.java
+++ b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/MiniPlayerFragment.java
@@ -4,16 +4,19 @@
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.os.Bundle;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
import com.kabouzeid.appthemehelper.ThemeStore;
import com.kabouzeid.appthemehelper.util.ATHUtil;
import com.kabouzeid.gramophone.R;
@@ -21,6 +24,7 @@
import com.kabouzeid.gramophone.helper.MusicProgressViewUpdateHelper;
import com.kabouzeid.gramophone.helper.PlayPauseButtonOnClickHandler;
import com.kabouzeid.gramophone.ui.fragments.AbsMusicServiceFragment;
+import com.kabouzeid.gramophone.util.PreferenceUtil;
import com.kabouzeid.gramophone.views.PlayPauseDrawable;
import butterknife.BindView;
@@ -102,6 +106,7 @@ public void onPlayingMetaChanged() {
@Override
public void onPlayStateChanged() {
+ super.onPlayStateChanged();
updatePlayPauseDrawableState(true);
}
@@ -123,6 +128,8 @@ public void onPause() {
progressViewUpdateHelper.stop();
}
+
+
private static class FlingPlayBackController implements View.OnTouchListener {
GestureDetector flingPlayBackController;
diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerPlaybackControlsFragment.java b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerPlaybackControlsFragment.java
index d0cdc1e72..22217dcab 100644
--- a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerPlaybackControlsFragment.java
+++ b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/card/CardPlayerPlaybackControlsFragment.java
@@ -108,6 +108,7 @@ public void onServiceConnected() {
@Override
public void onPlayStateChanged() {
+ super.onPlayStateChanged();
updatePlayPauseDrawableState(true);
}
diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerPlaybackControlsFragment.java b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerPlaybackControlsFragment.java
index b24ef929b..cd5cb6069 100644
--- a/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerPlaybackControlsFragment.java
+++ b/app/src/main/java/com/kabouzeid/gramophone/ui/fragments/player/flat/FlatPlayerPlaybackControlsFragment.java
@@ -116,6 +116,7 @@ public void onServiceConnected() {
@Override
public void onPlayStateChanged() {
+ super.onPlayStateChanged();
updatePlayPauseDrawableState(true);
}
diff --git a/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtil.java b/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtil.java
index 66e4234f4..e793f802b 100644
--- a/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtil.java
+++ b/app/src/main/java/com/kabouzeid/gramophone/util/PreferenceUtil.java
@@ -83,6 +83,8 @@ public final class PreferenceUtil {
public static final String SYNCHRONIZED_LYRICS_SHOW = "synchronized_lyrics_show";
+ public static final String KEEP_SCREEN_ON = "keep_screen_on";
+
public static final String INITIALIZED_BLACKLIST = "initialized_blacklist";
public static final String LIBRARY_CATEGORIES = "library_categories";
@@ -489,6 +491,10 @@ public final boolean synchronizedLyricsShow() {
return mPreferences.getBoolean(SYNCHRONIZED_LYRICS_SHOW, true);
}
+ public final boolean keepScreenOnWhilePlaying(){
+ return mPreferences.getBoolean(KEEP_SCREEN_ON,false);
+ }
+
public void setInitializedBlacklist() {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(INITIALIZED_BLACKLIST, true);
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index ad45b71db..eeae0f437 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -132,6 +132,7 @@
音频焦点丢失时降低音量
最近添加播放列表间隔
显示同步歌词
+ 播放时屏幕常亮
记住最后打开页面
记住随机播放开关
没有找到均衡器。
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index bded8aa70..93822e985 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -132,6 +132,7 @@
Reduce volume on focus loss
Last added playlist interval
Show synchronized lyrics
+ Keep Screen On While Playing
Remember last tab
Remember shuffle
No equalizer found.
diff --git a/app/src/main/res/xml/pref_now_playing_screen.xml b/app/src/main/res/xml/pref_now_playing_screen.xml
index 78b993ea6..0d2fed78e 100644
--- a/app/src/main/res/xml/pref_now_playing_screen.xml
+++ b/app/src/main/res/xml/pref_now_playing_screen.xml
@@ -15,6 +15,11 @@
android:key="synchronized_lyrics_show"
android:summary="@string/pref_summary_synchronized_lyrics_show"
android:title="@string/pref_title_synchronized_lyrics_show" />
+