summaryrefslogtreecommitdiff
path: root/core/java/android/app/MediaRouteButton.java
diff options
context:
space:
mode:
authorVladislav Kaznacheev <kaznacheev@google.com>2016-11-22 15:41:27 -0800
committerVladislav Kaznacheev <kaznacheev@google.com>2016-12-06 11:41:58 -0800
commitb265617b810082ec743389fa0468d1df91d66f68 (patch)
treea88fc39847fd0a66bfa53d602a91e341953d4e6c /core/java/android/app/MediaRouteButton.java
parent784c9deeb4f58169a9d904bcc71fbc58a21fd104 (diff)
Replace Toast-based cheat sheets with tooltips
Currently ActionMenuItemView, MediaRouteButton and ScrollingTabContainerView each have their own implementation of a Toast-based long-press tooltips (the last two apparently copy/pasted from the first). Replacing those with the recently introduced tooltips supported by the framework. Bug: 31516506 Test: manual in ApiDemos Change-Id: Ibcb8c5a43577a8b4d30f1a26e48ddcfde015d1dc
Diffstat (limited to 'core/java/android/app/MediaRouteButton.java')
-rw-r--r--core/java/android/app/MediaRouteButton.java58
1 files changed, 4 insertions, 54 deletions
diff --git a/core/java/android/app/MediaRouteButton.java b/core/java/android/app/MediaRouteButton.java
index 70a5e15c6c27..09e95dfa3044 100644
--- a/core/java/android/app/MediaRouteButton.java
+++ b/core/java/android/app/MediaRouteButton.java
@@ -24,18 +24,13 @@ 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.view.Gravity;
-import android.view.HapticFeedbackConstants;
import android.view.SoundEffectConstants;
import android.view.View;
-import android.widget.Toast;
public class MediaRouteButton extends View {
private final MediaRouter mRouter;
@@ -47,7 +42,6 @@ public class MediaRouteButton extends View {
private Drawable mRemoteIndicator;
private boolean mRemoteActive;
- private boolean mCheatSheetEnabled;
private boolean mIsConnecting;
private int mMinWidth;
@@ -98,7 +92,6 @@ public class MediaRouteButton extends View {
a.recycle();
setClickable(true);
- setLongClickable(true);
setRouteTypes(routeTypes);
}
@@ -178,12 +171,10 @@ public class MediaRouteButton extends View {
throw new IllegalStateException("The MediaRouteButton's Context is not an Activity.");
}
- /**
- * Sets whether to enable showing a toast with the content descriptor of the
- * button when the button is long pressed.
- */
- void setCheatSheetEnabled(boolean enable) {
- mCheatSheetEnabled = enable;
+ @Override
+ public void setContentDescription(CharSequence contentDescription) {
+ super.setContentDescription(contentDescription);
+ setTooltip(contentDescription);
}
@Override
@@ -197,47 +188,6 @@ public class MediaRouteButton extends View {
}
@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;
- }
-
- @Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);