use content description for play/pause button in audio player

This commit is contained in:
Daniel Gultsch 2020-08-31 17:42:03 +02:00
parent 81985ca7d7
commit 3281a93dc3
2 changed files with 12 additions and 1 deletions

View File

@ -112,17 +112,21 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
} }
viewHolder.playPause.setAlpha(viewHolder.darkBackground ? 0.7f : 0.57f); viewHolder.playPause.setAlpha(viewHolder.darkBackground ? 0.7f : 0.57f);
viewHolder.playPause.setOnClickListener(this); viewHolder.playPause.setOnClickListener(this);
final Context context = viewHolder.playPause.getContext();
if (message == currentlyPlayingMessage) { if (message == currentlyPlayingMessage) {
if (AudioPlayer.player != null && AudioPlayer.player.isPlaying()) { if (AudioPlayer.player != null && AudioPlayer.player.isPlaying()) {
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);
viewHolder.playPause.setContentDescription(context.getString(R.string.pause_audio));
viewHolder.progress.setEnabled(true); viewHolder.progress.setEnabled(true);
} else { } else {
viewHolder.playPause.setContentDescription(context.getString(R.string.play_audio));
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);
viewHolder.progress.setEnabled(false); viewHolder.progress.setEnabled(false);
} }
return true; return true;
} else { } else {
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);
viewHolder.playPause.setContentDescription(context.getString(R.string.play_audio));
viewHolder.runtime.setText(formatTime(message.getFileParams().runtime)); viewHolder.runtime.setText(formatTime(message.getFileParams().runtime));
viewHolder.progress.setProgress(0); viewHolder.progress.setProgress(0);
viewHolder.progress.setEnabled(false); viewHolder.progress.setEnabled(false);
@ -156,7 +160,8 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
} }
} }
private boolean playPauseCurrent(ViewHolder viewHolder) { private boolean playPauseCurrent(final ViewHolder viewHolder) {
final Context context = viewHolder.playPause.getContext();
viewHolder.playPause.setAlpha(viewHolder.darkBackground ? 0.7f : 0.57f); viewHolder.playPause.setAlpha(viewHolder.darkBackground ? 0.7f : 0.57f);
if (player.isPlaying()) { if (player.isPlaying()) {
viewHolder.progress.setEnabled(false); viewHolder.progress.setEnabled(false);
@ -164,6 +169,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
messageAdapter.flagScreenOff(); messageAdapter.flagScreenOff();
releaseProximityWakeLock(); releaseProximityWakeLock();
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);
viewHolder.playPause.setContentDescription(context.getString(R.string.play_audio));
} else { } else {
viewHolder.progress.setEnabled(true); viewHolder.progress.setEnabled(true);
player.start(); player.start();
@ -171,6 +177,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
acquireProximityWakeLock(); acquireProximityWakeLock();
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);
viewHolder.playPause.setContentDescription(context.getString(R.string.pause_audio));
} }
return false; return false;
} }
@ -194,6 +201,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
acquireProximityWakeLock(); acquireProximityWakeLock();
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);
viewHolder.playPause.setContentDescription(viewHolder.playPause.getContext().getString(R.string.pause_audio));
sensorManager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL); sensorManager.registerListener(this, proximitySensor, SensorManager.SENSOR_DELAY_NORMAL);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
@ -248,6 +256,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
} }
final ViewHolder viewHolder = ViewHolder.get(audioPlayer); final ViewHolder viewHolder = ViewHolder.get(audioPlayer);
final Message message = (Message) audioPlayer.getTag(); final Message message = (Message) audioPlayer.getTag();
viewHolder.playPause.setContentDescription(viewHolder.playPause.getContext().getString(R.string.play_audio));
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);
if (message != null) { if (message != null) {
viewHolder.runtime.setText(formatTime(message.getFileParams().runtime)); viewHolder.runtime.setText(formatTime(message.getFileParams().runtime));

View File

@ -935,6 +935,8 @@
<string name="not_encrypted">Not encrypted</string> <string name="not_encrypted">Not encrypted</string>
<string name="exit">Exit</string> <string name="exit">Exit</string>
<string name="record_voice_mail">Record voice mail</string> <string name="record_voice_mail">Record voice mail</string>
<string name="play_audio">Play audio</string>
<string name="pause_audio">Pause audio</string>
<plurals name="view_users"> <plurals name="view_users">
<item quantity="one">View %1$d Participant</item> <item quantity="one">View %1$d Participant</item>
<item quantity="other">View %1$d Participants</item> <item quantity="other">View %1$d Participants</item>