keep screen on during audio playback. fixes #2733
This commit is contained in:
parent
f2bbb6087c
commit
3c4ba7e0ce
|
@ -13,7 +13,6 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.text.emoji.EmojiCompat;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
|
@ -33,6 +32,7 @@ import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.View.OnLongClickListener;
|
import android.view.View.OnLongClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -147,6 +147,14 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
||||||
updatePreferences();
|
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) {
|
public void setOnContactPictureClicked(OnContactPictureClicked listener) {
|
||||||
this.mOnContactPictureClickedListener = listener;
|
this.mOnContactPictureClickedListener = listener;
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,10 +108,12 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
|
||||||
if (player.isPlaying()) {
|
if (player.isPlaying()) {
|
||||||
viewHolder.progress.setEnabled(false);
|
viewHolder.progress.setEnabled(false);
|
||||||
player.pause();
|
player.pause();
|
||||||
|
messageAdapter.flagScreenOff();
|
||||||
viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_play_arrow_white_36dp : R.drawable.ic_play_arrow_black_36dp);
|
viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_play_arrow_white_36dp : R.drawable.ic_play_arrow_black_36dp);
|
||||||
} else {
|
} else {
|
||||||
viewHolder.progress.setEnabled(true);
|
viewHolder.progress.setEnabled(true);
|
||||||
player.start();
|
player.start();
|
||||||
|
messageAdapter.flagScreenOn();
|
||||||
this.stopRefresher(true);
|
this.stopRefresher(true);
|
||||||
viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_pause_white_36dp : R.drawable.ic_pause_black_36dp);
|
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.setOnCompletionListener(this);
|
||||||
AudioPlayer.player.prepare();
|
AudioPlayer.player.prepare();
|
||||||
AudioPlayer.player.start();
|
AudioPlayer.player.start();
|
||||||
|
messageAdapter.flagScreenOn();
|
||||||
viewHolder.progress.setEnabled(true);
|
viewHolder.progress.setEnabled(true);
|
||||||
viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_pause_white_36dp : R.drawable.ic_pause_black_36dp);
|
viewHolder.playPause.setImageResource(viewHolder.darkBackground ? R.drawable.ic_pause_white_36dp : R.drawable.ic_pause_black_36dp);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
messageAdapter.flagScreenOff();
|
||||||
AudioPlayer.currentlyPlayingMessage = null;
|
AudioPlayer.currentlyPlayingMessage = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -150,6 +154,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
|
||||||
AudioPlayer.player.stop();
|
AudioPlayer.player.stop();
|
||||||
}
|
}
|
||||||
AudioPlayer.player.release();
|
AudioPlayer.player.release();
|
||||||
|
messageAdapter.flagScreenOff();
|
||||||
AudioPlayer.player = null;
|
AudioPlayer.player = null;
|
||||||
resetPlayerUi();
|
resetPlayerUi();
|
||||||
}
|
}
|
||||||
|
@ -183,6 +188,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
|
||||||
AudioPlayer.player = null;
|
AudioPlayer.player = null;
|
||||||
}
|
}
|
||||||
mediaPlayer.release();
|
mediaPlayer.release();
|
||||||
|
messageAdapter.flagScreenOff();
|
||||||
resetPlayerUi();
|
resetPlayerUi();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue