Loading core/java/android/app/MediaRouteActionProvider.java +1 −0 Original line number Diff line number Diff line Loading @@ -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, Loading core/java/android/app/MediaRouteButton.java +53 −0 Original line number Diff line number Diff line Loading @@ -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"; Loading @@ -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; Loading Loading @@ -82,6 +88,7 @@ public class MediaRouteButton extends View { a.recycle(); setClickable(true); setLongClickable(true); setRouteTypes(routeTypes); } Loading Loading @@ -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. Loading core/res/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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> core/res/res/values/styles.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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"> Loading @@ -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> Loading
core/java/android/app/MediaRouteActionProvider.java +1 −0 Original line number Diff line number Diff line Loading @@ -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, Loading
core/java/android/app/MediaRouteButton.java +53 −0 Original line number Diff line number Diff line Loading @@ -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"; Loading @@ -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; Loading Loading @@ -82,6 +88,7 @@ public class MediaRouteButton extends View { a.recycle(); setClickable(true); setLongClickable(true); setRouteTypes(routeTypes); } Loading Loading @@ -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. Loading
core/res/res/values/strings.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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>
core/res/res/values/styles.xml +4 −0 Original line number Diff line number Diff line Loading @@ -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"> Loading @@ -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>