diff --git a/core/java/android/app/MediaRouteActionProvider.java b/core/java/android/app/MediaRouteActionProvider.java index 5b5506db221fe..63b641cb708e9 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 b0bfe743fd891..cfc8bbd139e5b 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 a39d98de7e488..b757fe88bfd28 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3606,4 +3606,8 @@ Done + + + Media output + diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index c490a2f070f06..a6236f76f2f33 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. @drawable/ic_media_route_holo_dark 56dp 48dp + true + @android:string/media_route_button_content_description