Skip to content

Commit

Permalink
Improved accessibility of player interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiGr committed Jul 1, 2023
1 parent d845a15 commit fdfc4df
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -531,18 +532,19 @@ public void onServiceStopped() {
////////////////////////////////////////////////////////////////////////////

private void onStateChanged(final int state) {
final ImageButton playPauseButton = queueControlBinding.controlPlayPause;
switch (state) {
case Player.STATE_PAUSED:
queueControlBinding.controlPlayPause
.setImageResource(R.drawable.ic_play_arrow);
playPauseButton.setImageResource(R.drawable.ic_play_arrow);
playPauseButton.setContentDescription(getString(R.string.play));
break;
case Player.STATE_PLAYING:
queueControlBinding.controlPlayPause
.setImageResource(R.drawable.ic_pause);
playPauseButton.setImageResource(R.drawable.ic_pause);
playPauseButton.setContentDescription(getString(R.string.pause));
break;
case Player.STATE_COMPLETED:
queueControlBinding.controlPlayPause
.setImageResource(R.drawable.ic_replay);
playPauseButton.setImageResource(R.drawable.ic_replay);
playPauseButton.setContentDescription(getString(R.string.replay));
break;
default:
break;
Expand Down
35 changes: 31 additions & 4 deletions app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.graphics.BitmapCompat;
import androidx.core.graphics.Insets;
Expand Down Expand Up @@ -103,6 +104,9 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa
// other constants (TODO remove playback speeds and use normal menu for popup, too)
private static final float[] PLAYBACK_SPEEDS = {0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f};

private enum PlayButtonAction {
PLAY, PAUSE, REPLAY
}

/*//////////////////////////////////////////////////////////////////////////
// Views
Expand Down Expand Up @@ -755,6 +759,29 @@ public boolean isFullscreen() {
// only MainPlayerUi can be in fullscreen, so overridden there
return false;
}

/**
* Update the play/pause button ({@link R.id.playPauseButton}) to reflect the action
* that will be performed when the button is clicked..
* @param action the action that is performed when the play/pause button is clicked
*/
private void updatePlayPauseButton(final PlayButtonAction action) {
final AppCompatImageButton button = binding.playPauseButton;
switch (action) {
case PLAY:
button.setContentDescription(context.getString(R.string.play));
button.setImageResource(R.drawable.ic_play_arrow);
break;
case PAUSE:
button.setContentDescription(context.getString(R.string.pause));
button.setImageResource(R.drawable.ic_pause);
break;
case REPLAY:
button.setContentDescription(context.getString(R.string.replay));
button.setImageResource(R.drawable.ic_replay);
break;
}
}
//endregion


Expand Down Expand Up @@ -785,7 +812,7 @@ public void onBlocked() {
animate(binding.loadingPanel, true, 0);
animate(binding.surfaceForeground, true, 100);

binding.playPauseButton.setImageResource(R.drawable.ic_play_arrow);
updatePlayPauseButton(PlayButtonAction.PLAY);
animatePlayButtons(false, 100);
binding.getRoot().setKeepScreenOn(false);
}
Expand All @@ -806,7 +833,7 @@ public void onPlaying() {

animate(binding.playPauseButton, false, 80, AnimationType.SCALE_AND_ALPHA, 0,
() -> {
binding.playPauseButton.setImageResource(R.drawable.ic_pause);
updatePlayPauseButton(PlayButtonAction.PAUSE);
animatePlayButtons(true, 200);
if (!isAnyListViewOpen()) {
binding.playPauseButton.requestFocus();
Expand Down Expand Up @@ -836,7 +863,7 @@ public void onPaused() {

animate(binding.playPauseButton, false, 80, AnimationType.SCALE_AND_ALPHA, 0,
() -> {
binding.playPauseButton.setImageResource(R.drawable.ic_play_arrow);
updatePlayPauseButton(PlayButtonAction.PLAY);
animatePlayButtons(true, 200);
if (!isAnyListViewOpen()) {
binding.playPauseButton.requestFocus();
Expand All @@ -860,7 +887,7 @@ public void onCompleted() {

animate(binding.playPauseButton, false, 0, AnimationType.SCALE_AND_ALPHA, 0,
() -> {
binding.playPauseButton.setImageResource(R.drawable.ic_replay);
updatePlayPauseButton(PlayButtonAction.REPLAY);
animatePlayButtons(true, DEFAULT_CONTROLS_DURATION);
});

Expand Down
14 changes: 7 additions & 7 deletions app/src/main/res/layout-land/activity_player_queue_control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
android:scaleType="fitCenter"
android:src="@drawable/exo_controls_rewind"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
android:contentDescription="@string/rewind" />

<ImageButton
android:id="@+id/control_play_pause"
Expand All @@ -140,7 +140,7 @@
android:scaleType="fitCenter"
android:src="@drawable/ic_pause"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
android:contentDescription="@string/pause" />

<ProgressBar
android:id="@+id/control_progress_bar"
Expand Down Expand Up @@ -173,7 +173,7 @@
android:scaleType="fitCenter"
android:src="@drawable/exo_controls_fastforward"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
android:contentDescription="@string/forward" />
</RelativeLayout>

<RelativeLayout
Expand Down Expand Up @@ -201,7 +201,7 @@
android:scaleType="fitCenter"
android:src="@drawable/ic_previous"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
android:contentDescription="@string/previous_stream" />

<ImageButton
android:id="@+id/control_repeat"
Expand All @@ -216,7 +216,7 @@
android:scaleType="fitXY"
android:src="@drawable/ic_repeat"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
android:contentDescription="@string/notification_action_repeat" />

<View
android:id="@+id/anchor"
Expand All @@ -237,7 +237,7 @@
android:scaleType="fitXY"
android:src="@drawable/ic_shuffle"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
android:contentDescription="@string/notification_action_shuffle" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/control_forward"
Expand All @@ -255,7 +255,7 @@
android:scaleType="fitCenter"
android:src="@drawable/ic_next"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
android:contentDescription="@string/next_stream" />
</RelativeLayout>
</RelativeLayout>

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/fragment_video_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@
android:gravity="center_vertical"
android:paddingLeft="@dimen/video_item_search_padding"
android:paddingRight="@dimen/video_item_search_padding"
android:scaleType="fitCenter" />
android:scaleType="fitCenter"
tools:ignore="ContentDescription" />

<LinearLayout
android:id="@+id/overlay_metadata_layout"
Expand Down Expand Up @@ -675,7 +676,7 @@
android:contentDescription="@string/title_activity_play_queue"
android:scaleType="center"
android:src="@drawable/ic_list"
tools:ignore="ContentDescription,RtlHardcoded" />
tools:ignore="RtlHardcoded" />

<ImageButton
android:id="@+id/overlay_play_pause_button"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/play_queue_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/duration_text_color"
android:textSize="@dimen/video_item_search_duration_text_size"
android:contentDescription="@string/duration"
app:layout_constraintBottom_toBottomOf="@+id/itemThumbnailView"
app:layout_constraintEnd_toEndOf="@+id/itemThumbnailView"
tools:text="1:09:10" />
Expand Down
39 changes: 24 additions & 15 deletions app/src/main/res/layout/player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
android:src="@drawable/ic_close"
android:visibility="gone"
app:tint="@color/white"
tools:ignore="ContentDescription,RtlHardcoded" />
android:contentDescription="@string/close"
tools:ignore="RtlHardcoded" />

<LinearLayout
android:id="@+id/metadataView"
Expand Down Expand Up @@ -217,7 +218,8 @@
android:src="@drawable/ic_list"
android:visibility="gone"
app:tint="@color/white"
tools:ignore="ContentDescription,RtlHardcoded" />
android:contentDescription="@string/open_play_queue"
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/segmentsButton"
Expand All @@ -235,7 +237,8 @@
android:src="@drawable/ic_menu_book"
android:visibility="gone"
app:tint="@color/white"
tools:ignore="ContentDescription,RtlHardcoded" />
android:contentDescription="@string/chapters"
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/moreOptionsButton"
Expand All @@ -248,7 +251,8 @@
android:scaleType="fitXY"
android:src="@drawable/ic_expand_more"
app:tint="@color/white"
tools:ignore="ContentDescription,RtlHardcoded" />
android:contentDescription="@string/more_options"
tools:ignore="RtlHardcoded" />

</LinearLayout>

Expand Down Expand Up @@ -368,9 +372,10 @@
android:padding="@dimen/player_main_buttons_padding"
android:scaleType="fitCenter"
android:src="@drawable/ic_fullscreen"
android:contentDescription="@string/toggle_fullscreen"
android:visibility="gone"
app:tint="@color/white"
tools:ignore="ContentDescription,RtlHardcoded"
tools:ignore="RtlHardcoded"
tools:visibility="visible" />

</LinearLayout>
Expand Down Expand Up @@ -493,8 +498,9 @@
android:scaleType="fitCenter"
android:src="@drawable/ic_fullscreen"
android:visibility="gone"
android:contentDescription="@string/toggle_screen_orientation"
app:tint="@color/white"
tools:ignore="ContentDescription,RtlHardcoded"
tools:ignore="RtlHardcoded"
tools:visibility="visible" />
</LinearLayout>
</RelativeLayout>
Expand All @@ -517,8 +523,8 @@
android:focusable="true"
android:scaleType="fitCenter"
android:src="@drawable/ic_previous"
app:tint="@color/white"
tools:ignore="ContentDescription" />
android:contentDescription="@string/previous_stream"
app:tint="@color/white" />


<androidx.appcompat.widget.AppCompatImageButton
Expand All @@ -529,8 +535,8 @@
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitCenter"
android:src="@drawable/ic_pause"
app:tint="@color/white"
tools:ignore="ContentDescription" />
android:contentDescription="@string/pause"
app:tint="@color/white" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/playNextButton"
Expand All @@ -543,8 +549,8 @@
android:focusable="true"
android:scaleType="fitCenter"
android:src="@drawable/ic_next"
app:tint="@color/white"
tools:ignore="ContentDescription" />
android:contentDescription="@string/next_stream"
app:tint="@color/white" />

</LinearLayout>

Expand Down Expand Up @@ -595,7 +601,8 @@
android:scaleType="fitXY"
android:src="@drawable/exo_controls_repeat_off"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription,RtlHardcoded" />
android:contentDescription="@string/notification_action_repeat"
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/shuffleButton"
Expand All @@ -610,7 +617,8 @@
android:scaleType="fitXY"
android:src="@drawable/ic_shuffle"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription,RtlHardcoded" />
android:contentDescription="@string/notification_action_shuffle"
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/itemsListHeaderDuration"
Expand All @@ -636,7 +644,8 @@
android:scaleType="fitXY"
android:src="@drawable/ic_playlist_add"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription,RtlHardcoded" />
android:contentDescription="@string/add_to_playlist"
tools:ignore="RtlHardcoded" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/itemsListClose"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/player_popup_close_overlay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="24dp"
android:src="@drawable/ic_close"
android:contentDescription="@string/close"
app:backgroundTint="@color/light_youtube_primary_color"
app:borderWidth="0dp"
app:fabSize="normal" />
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -790,4 +790,15 @@
<string name="audio_track_type_original">original</string>
<string name="audio_track_type_dubbed">dubbed</string>
<string name="audio_track_type_descriptive">descriptive</string>
<string name="open_play_queue">open play queue</string>
<string name="toggle_fullscreen">toggle fullscreen</string>
<string name="toggle_screen_orientation">toggle screen orientation</string>
<string name="previous_stream">previous stream</string>
<string name="next_stream">next stream</string>
<string name="play">play</string>
<string name="replay">replay</string>
<string name="more_options">more options</string>
<string name="duration">duration</string>
<string name="rewind">rewind</string>
<string name="forward">forward</string>
</resources>

0 comments on commit fdfc4df

Please sign in to comment.