Add descriptions to MediaController buttons
This widget was missing some accessibility descriptions.
bug:16536697
Change-Id: I6f50fd1f4fc0a804151ff465b612128d71a1fde6
diff --git a/core/java/android/widget/MediaController.java b/core/java/android/widget/MediaController.java
index 546cc5f..f1aaa4d 100644
--- a/core/java/android/widget/MediaController.java
+++ b/core/java/android/widget/MediaController.java
@@ -17,6 +17,7 @@
package android.widget;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.media.AudioManager;
import android.os.Handler;
@@ -55,7 +56,7 @@
* <p>
* Functions like show() and hide() have no effect when MediaController
* is created in an xml layout.
- *
+ *
* MediaController will hide and
* show the buttons according to these rules:
* <ul>
@@ -70,32 +71,34 @@
*/
public class MediaController extends FrameLayout {
- private MediaPlayerControl mPlayer;
- private Context mContext;
- private View mAnchor;
- private View mRoot;
- private WindowManager mWindowManager;
- private Window mWindow;
- private View mDecor;
+ private MediaPlayerControl mPlayer;
+ private Context mContext;
+ private View mAnchor;
+ private View mRoot;
+ private WindowManager mWindowManager;
+ private Window mWindow;
+ private View mDecor;
private WindowManager.LayoutParams mDecorLayoutParams;
- private ProgressBar mProgress;
- private TextView mEndTime, mCurrentTime;
- private boolean mShowing;
- private boolean mDragging;
- private static final int sDefaultTimeout = 3000;
- private static final int FADE_OUT = 1;
- private static final int SHOW_PROGRESS = 2;
- private boolean mUseFastForward;
- private boolean mFromXml;
- private boolean mListenersSet;
+ private ProgressBar mProgress;
+ private TextView mEndTime, mCurrentTime;
+ private boolean mShowing;
+ private boolean mDragging;
+ private static final int sDefaultTimeout = 3000;
+ private static final int FADE_OUT = 1;
+ private static final int SHOW_PROGRESS = 2;
+ private boolean mUseFastForward;
+ private boolean mFromXml;
+ private boolean mListenersSet;
private View.OnClickListener mNextListener, mPrevListener;
- StringBuilder mFormatBuilder;
- Formatter mFormatter;
- private ImageButton mPauseButton;
- private ImageButton mFfwdButton;
- private ImageButton mRewButton;
- private ImageButton mNextButton;
- private ImageButton mPrevButton;
+ StringBuilder mFormatBuilder;
+ Formatter mFormatter;
+ private ImageButton mPauseButton;
+ private ImageButton mFfwdButton;
+ private ImageButton mRewButton;
+ private ImageButton mNextButton;
+ private ImageButton mPrevButton;
+ private CharSequence mPlayDescription;
+ private CharSequence mPauseDescription;
public MediaController(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -132,7 +135,7 @@
mDecor.setOnTouchListener(mTouchListener);
mWindow.setContentView(this);
mWindow.setBackgroundDrawableResource(android.R.color.transparent);
-
+
// While the media controller is up, the volume control keys should
// affect the media stream type
mWindow.setVolumeControlStream(AudioManager.STREAM_MUSIC);
@@ -201,7 +204,7 @@
return false;
}
};
-
+
public void setMediaPlayer(MediaPlayerControl player) {
mPlayer = player;
updatePausePlay();
@@ -249,6 +252,11 @@
}
private void initControllerView(View v) {
+ Resources res = mContext.getResources();
+ mPlayDescription = res
+ .getText(com.android.internal.R.string.lockscreen_transport_play_description);
+ mPauseDescription = res
+ .getText(com.android.internal.R.string.lockscreen_transport_pause_description);
mPauseButton = (ImageButton) v.findViewById(com.android.internal.R.id.pause);
if (mPauseButton != null) {
mPauseButton.requestFocus();
@@ -271,7 +279,7 @@
}
}
- // By default these are hidden. They will be enabled when setPrevNextListeners() is called
+ // By default these are hidden. They will be enabled when setPrevNextListeners() is called
mNextButton = (ImageButton) v.findViewById(com.android.internal.R.id.next);
if (mNextButton != null && !mFromXml && !mListenersSet) {
mNextButton.setVisibility(View.GONE);
@@ -328,7 +336,7 @@
// the buttons.
}
}
-
+
/**
* Show the controller on screen. It will go away
* automatically after 'timeout' milliseconds of inactivity.
@@ -347,7 +355,7 @@
mShowing = true;
}
updatePausePlay();
-
+
// cause the progress bar to be updated even if mShowing
// was already true. This happens, for example, if we're
// paused with the progress bar showing the user hits play.
@@ -359,7 +367,7 @@
mHandler.sendMessageDelayed(msg, timeout);
}
}
-
+
public boolean isShowing() {
return mShowing;
}
@@ -525,8 +533,10 @@
if (mPlayer.isPlaying()) {
mPauseButton.setImageResource(com.android.internal.R.drawable.ic_media_pause);
+ mPauseButton.setContentDescription(mPauseDescription);
} else {
mPauseButton.setImageResource(com.android.internal.R.drawable.ic_media_play);
+ mPauseButton.setContentDescription(mPlayDescription);
}
}
@@ -668,7 +678,7 @@
if (mRoot != null) {
installPrevNextListeners();
-
+
if (mNextButton != null && !mFromXml) {
mNextButton.setVisibility(View.VISIBLE);
}
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index c34560d..4bcf80d 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2540,15 +2540,19 @@
Contact your wireless service provider for another SIM card.</string>
<!-- Shown on transport control of lockscreen. Pressing button goes to previous track. -->
- <string name="lockscreen_transport_prev_description">Previous track button</string>
+ <string name="lockscreen_transport_prev_description">Previous track</string>
<!-- Shown on transport control of lockscreen. Pressing button goes to next track. -->
- <string name="lockscreen_transport_next_description">Next track button</string>
+ <string name="lockscreen_transport_next_description">Next track</string>
<!-- Shown on transport control of lockscreen. Pressing button pauses playback -->
- <string name="lockscreen_transport_pause_description">Pause button</string>
+ <string name="lockscreen_transport_pause_description">Pause</string>
<!-- Shown on transport control of lockscreen. Pressing button pauses playback -->
- <string name="lockscreen_transport_play_description">Play button</string>
+ <string name="lockscreen_transport_play_description">Play</string>
<!-- Shown on transport control of lockscreen. Pressing button pauses playback -->
- <string name="lockscreen_transport_stop_description">Stop button</string>
+ <string name="lockscreen_transport_stop_description">Stop</string>
+ <!-- Shown on transport control screens. Pressing button rewinds playback [CHAR LIMIT=NONE]-->
+ <string name="lockscreen_transport_rew_description">Rewind</string>
+ <!-- Shown on transport control screens. Pressing button fast forwards playback [CHAR LIMIT=NONE]-->
+ <string name="lockscreen_transport_ffw_description">Fast forward</string>
<!-- Shown in the lock screen when there is emergency calls only mode. -->
<string name="emergency_calls_only" msgid="2485604591272668370">Emergency calls only</string>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index a5cac6b..e693d91 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -1105,26 +1105,32 @@
<style name="MediaButton.Previous">
<item name="src">@drawable/ic_media_previous</item>
+ <item name="contentDescription">@string/lockscreen_transport_prev_description</item>
</style>
<style name="MediaButton.Next">
<item name="src">@drawable/ic_media_next</item>
+ <item name="contentDescription">@string/lockscreen_transport_next_description</item>
</style>
<style name="MediaButton.Play">
<item name="src">@drawable/ic_media_play</item>
+ <item name="contentDescription">@string/lockscreen_transport_play_description</item>
</style>
<style name="MediaButton.Ffwd">
<item name="src">@drawable/ic_media_ff</item>
+ <item name="contentDescription">@string/lockscreen_transport_ffw_description</item>
</style>
<style name="MediaButton.Rew">
<item name="src">@drawable/ic_media_rew</item>
+ <item name="contentDescription">@string/lockscreen_transport_rew_description</item>
</style>
<style name="MediaButton.Pause">
<item name="src">@drawable/ic_media_pause</item>
+ <item name="contentDescription">@string/lockscreen_transport_pause_description</item>
</style>
<style name="ZoomControls">
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 6030715..3956bdf 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -976,6 +976,8 @@
<java-symbol type="string" name="ssl_ca_cert_noti_by_unknown" />
<java-symbol type="string" name="ssl_ca_cert_noti_managed" />
<java-symbol type="string" name="ssl_ca_cert_warning" />
+ <java-symbol type="string" name="lockscreen_transport_play_description" />
+ <java-symbol type="string" name="lockscreen_transport_pause_description" />
<java-symbol type="plurals" name="abbrev_in_num_days" />
<java-symbol type="plurals" name="abbrev_in_num_hours" />