diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index b93931d7e..ffbb4b1a3 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -13,7 +13,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; import android.support.annotation.ColorInt; -import android.support.text.emoji.EmojiCompat; import android.support.v4.content.ContextCompat; import android.text.Spannable; import android.text.SpannableString; @@ -33,6 +32,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; @@ -147,6 +147,14 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie updatePreferences(); } + public void flagScreenOn() { + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + + public void flagScreenOff() { + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + public void setOnContactPictureClicked(OnContactPictureClicked listener) { this.mOnContactPictureClickedListener = listener; } diff --git a/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java b/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java index 1b3d6747d..ebb904ea6 100644 --- a/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java +++ b/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java @@ -108,10 +108,12 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti if (player.isPlaying()) { viewHolder.progress.setEnabled(false); player.pause(); + messageAdapter.flagScreenOff(); viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_play_arrow_white_36dp : R.drawable.ic_play_arrow_black_36dp); } else { viewHolder.progress.setEnabled(true); player.start(); + messageAdapter.flagScreenOn(); this.stopRefresher(true); viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_pause_white_36dp : R.drawable.ic_pause_black_36dp); } @@ -126,10 +128,12 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti AudioPlayer.player.setOnCompletionListener(this); AudioPlayer.player.prepare(); AudioPlayer.player.start(); + messageAdapter.flagScreenOn(); viewHolder.progress.setEnabled(true); viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_pause_white_36dp : R.drawable.ic_pause_black_36dp); return true; } catch (Exception e) { + messageAdapter.flagScreenOff(); AudioPlayer.currentlyPlayingMessage = null; return false; } @@ -150,6 +154,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti AudioPlayer.player.stop(); } AudioPlayer.player.release(); + messageAdapter.flagScreenOff(); AudioPlayer.player = null; resetPlayerUi(); } @@ -183,6 +188,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti AudioPlayer.player = null; } mediaPlayer.release(); + messageAdapter.flagScreenOff(); resetPlayerUi(); } }