summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/MediaRouteActionProvider.java1
-rw-r--r--core/java/android/app/MediaRouteButton.java53
-rwxr-xr-xcore/res/res/values/strings.xml4
-rw-r--r--core/res/res/values/styles.xml4
4 files changed, 62 insertions, 0 deletions
diff --git a/core/java/android/app/MediaRouteActionProvider.java b/core/java/android/app/MediaRouteActionProvider.java
index 5b5506db221f..63b641cb708e 100644
--- a/core/java/android/app/MediaRouteActionProvider.java
+++ b/core/java/android/app/MediaRouteActionProvider.java
@@ -81,6 +81,7 @@ public class MediaRouteActionProvider extends ActionProvider {
}
mMenuItem = item;
mView = new MediaRouteButton(mContext);
+ mView.setCheatSheetEnabled(true);
mView.setRouteTypes(mRouteTypes);
mView.setExtendedSettingsClickListener(mExtendedSettingsListener);
mView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
diff --git a/core/java/android/app/MediaRouteButton.java b/core/java/android/app/MediaRouteButton.java
index b0bfe743fd89..cfc8bbd139e5 100644
--- a/core/java/android/app/MediaRouteButton.java
+++ b/core/java/android/app/MediaRouteButton.java
@@ -23,14 +23,19 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Canvas;
+import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.media.MediaRouter;
import android.media.MediaRouter.RouteGroup;
import android.media.MediaRouter.RouteInfo;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.Gravity;
+import android.view.HapticFeedbackConstants;
import android.view.SoundEffectConstants;
import android.view.View;
+import android.widget.Toast;
public class MediaRouteButton extends View {
private static final String TAG = "MediaRouteButton";
@@ -44,6 +49,7 @@ public class MediaRouteButton extends View {
private Drawable mRemoteIndicator;
private boolean mRemoteActive;
private boolean mToggleMode;
+ private boolean mCheatSheetEnabled;
private int mMinWidth;
private int mMinHeight;
@@ -82,6 +88,7 @@ public class MediaRouteButton extends View {
a.recycle();
setClickable(true);
+ setLongClickable(true);
setRouteTypes(routeTypes);
}
@@ -129,6 +136,52 @@ public class MediaRouteButton extends View {
return handled;
}
+ void setCheatSheetEnabled(boolean enable) {
+ mCheatSheetEnabled = enable;
+ }
+
+ @Override
+ public boolean performLongClick() {
+ if (super.performLongClick()) {
+ return true;
+ }
+
+ if (!mCheatSheetEnabled) {
+ return false;
+ }
+
+ final CharSequence contentDesc = getContentDescription();
+ if (TextUtils.isEmpty(contentDesc)) {
+ // Don't show the cheat sheet if we have no description
+ return false;
+ }
+
+ final int[] screenPos = new int[2];
+ final Rect displayFrame = new Rect();
+ getLocationOnScreen(screenPos);
+ getWindowVisibleDisplayFrame(displayFrame);
+
+ final Context context = getContext();
+ final int width = getWidth();
+ final int height = getHeight();
+ final int midy = screenPos[1] + height / 2;
+ final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
+
+ Toast cheatSheet = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
+ if (midy < displayFrame.height()) {
+ // Show along the top; follow action buttons
+ cheatSheet.setGravity(Gravity.TOP | Gravity.END,
+ screenWidth - screenPos[0] - width / 2, height);
+ } else {
+ // Show along the bottom center
+ cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
+ }
+ cheatSheet.show();
+ performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
+
+ return true;
+ }
+
public void setRouteTypes(int types) {
if (types == mRouteTypes) {
// Already registered; nothing to do.
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index a39d98de7e48..b757fe88bfd2 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -3606,4 +3606,8 @@
<!-- "Done" button for MediaRouter chooser dialog when grouping routes. [CHAR LIMIT=NONE] -->
<string name="media_route_chooser_grouping_done">Done</string>
+
+ <!-- Content description of a MediaRouteButton for accessibility support -->
+ <string name="media_route_button_content_description">Media output</string>
+
</resources>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index c490a2f070f0..a6236f76f2f3 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -2448,6 +2448,8 @@ please see styles_device_defaults.xml.
<item name="android:externalRouteEnabledDrawable">@drawable/ic_media_route_holo_dark</item>
<item name="android:minWidth">56dp</item>
<item name="android:minHeight">48dp</item>
+ <item name="android:focusable">true</item>
+ <item name="android:contentDescription">@android:string/media_route_button_content_description</item>
</style>
<style name="Widget.Holo.Light.MediaRouteButton">
@@ -2455,6 +2457,8 @@ please see styles_device_defaults.xml.
<item name="android:externalRouteEnabledDrawable">@drawable/ic_media_route_holo_light</item>
<item name="android:minWidth">56dp</item>
<item name="android:minHeight">48dp</item>
+ <item name="android:focusable">true</item>
+ <item name="android:contentDescription">@android:string/media_route_button_content_description</item>
</style>
</resources>