Improve accessibility of voice messages

Signed-off-by: Peter Vágner <pvdeejay@gmail.com>
This commit is contained in:
Peter Vágner 2021-08-01 14:51:00 +02:00 committed by Peter Vágner
parent 60caac4214
commit 8c590b50e3
5 changed files with 18 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import android.content.Context
import android.text.format.DateUtils
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
@ -476,12 +477,14 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
views.voiceMessagePlaybackTimerIndicator.isVisible = true
views.voicePlaybackControlButton.isVisible = false
views.voiceMessageSendButton.isVisible = true
views.voicePlaybackWaveform.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
renderToast(context.getString(R.string.voice_message_tap_to_stop_toast))
}
private fun showPlaybackViews() {
views.voiceMessagePlaybackTimerIndicator.isVisible = false
views.voicePlaybackControlButton.isVisible = true
views.voicePlaybackWaveform.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
callback?.onVoiceRecordingPlaybackModeOn()
}
@ -507,12 +510,14 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
}
is VoiceMessagePlaybackTracker.Listener.State.Playing -> {
views.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_pause)
views.voicePlaybackControlButton.contentDescription = resources.getString(R.string.a11y_pause_voice_message)
val formattedTimerText = DateUtils.formatElapsedTime((state.playbackTime / 1000).toLong())
views.voicePlaybackTime.text = formattedTimerText
}
is VoiceMessagePlaybackTracker.Listener.State.Paused,
is VoiceMessagePlaybackTracker.Listener.State.Idle -> {
views.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
views.voicePlaybackControlButton.contentDescription = resources.getString(R.string.a11y_play_voice_message)
}
}
}

View File

@ -98,16 +98,19 @@ abstract class MessageVoiceItem : AbsMessageItem<MessageVoiceItem.Holder>() {
private fun renderIdleState(holder: Holder) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
holder.voicePlaybackControlButton.contentDescription = holder.view.context.resources.getString(R.string.a11y_play_voice_message)
holder.voicePlaybackTime.text = formatPlaybackTime(duration)
}
private fun renderPlayingState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Playing) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_pause)
holder.voicePlaybackControlButton.contentDescription = holder.view.context.resources.getString(R.string.a11y_pause_voice_message)
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
}
private fun renderPausedState(holder: Holder, state: VoiceMessagePlaybackTracker.Listener.State.Paused) {
holder.voicePlaybackControlButton.setImageResource(R.drawable.ic_play_pause_play)
holder.voicePlaybackControlButton.contentDescription = holder.view.context.resources.getString(R.string.a11y_play_voice_message)
holder.voicePlaybackTime.text = formatPlaybackTime(state.playbackTime)
}

View File

@ -53,6 +53,7 @@
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:importantForAccessibility="no"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/voicePlaybackTime"
@ -77,4 +78,4 @@
app:layout_constraintTop_toBottomOf="@+id/voicePlaybackLayout"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -107,7 +107,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:contentDescription="@string/a11y_lock_voice_message"
android:importantForAccessibility="no"
android:src="@drawable/ic_voice_message_unlocked"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@id/voiceMessageMicButton"
@ -215,6 +215,8 @@
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:contentDescription="@string/a11y_stop_voice_message"
android:importantForAccessibility="no"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/voicePlaybackTime"
@ -231,10 +233,11 @@
android:layout_height="wrap_content"
android:layout_marginBottom="84dp"
android:visibility="gone"
android:accessibilityLiveRegion="polite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="@string/voice_message_release_to_send_toast"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -3460,13 +3460,13 @@
<string name="error_failed_to_join_room">Sorry, an error occurred while trying to join: %s</string>
<string name="a11y_start_voice_message">Start Voice Message</string>
<string name="a11y_start_voice_message">Record Voice Message</string>
<string name="voice_message_slide_to_cancel">Slide to cancel</string>
<string name="a11y_lock_voice_message">Voice Message Lock</string>
<string name="a11y_play_voice_message">Play Voice Message</string>
<string name="a11y_pause_voice_message">Pause Voice Message</string>
<string name="a11y_stop_voice_message">Stop Recording</string>
<string name="a11y_recording_voice_message">Recording voice message</string>
<string name="a11y_delete_recorded_voice_message">Delete recorded voice message</string>
<string name="a11y_delete_recorded_voice_message">Delete recording</string>
<string name="voice_message_release_to_send_toast">Hold to record, release to send</string>
<string name="voice_message_n_seconds_warning_toast">%1$ds left</string>
<string name="voice_message_tap_to_stop_toast">Tap on your recording to stop or listen</string>