Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java b/chrome/android/java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java |
| index 9d4a6ce167c56335f3b9d19a3dbfb85245c9ec53..64ede6e80f592d72404714f0db4e9f95930b7ef4 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java |
| @@ -10,12 +10,15 @@ import android.content.DialogInterface; |
| import android.content.Intent; |
| import android.net.Uri; |
| import android.support.v7.app.AlertDialog; |
| +import android.view.Gravity; |
| +import android.view.View; |
| import android.view.accessibility.AccessibilityManager; |
| import org.chromium.base.ContextUtils; |
| import org.chromium.base.PackageUtils; |
| import org.chromium.base.TraceEvent; |
| import org.chromium.chrome.R; |
| +import org.chromium.ui.widget.Toast; |
| import java.util.List; |
| @@ -115,4 +118,30 @@ public class AccessibilityUtil { |
| AlertDialog dialog = builder.create(); |
| dialog.show(); |
| } |
| + |
| + /** |
| + * Shows the content description toast for items on the toolbar. |
| + * @param context the context to use for the toast |
|
mdjones
2017/05/16 21:53:57
nit: "the" -> "The" and punctuation.
huayinz
2017/05/16 22:59:42
Done.
|
| + * @param view The view to anchor the toast. |
| + * @param description The string shown in the toast. |
| + * @return Whether a toast has been shown successfully. |
| + */ |
| + public static boolean showAccessibilityToast( |
| + Context context, View view, CharSequence description) { |
| + if (description == null) return false; |
| + |
| + final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; |
| + final int screenHeight = context.getResources().getDisplayMetrics().heightPixels; |
| + final int[] screenPos = new int[2]; |
| + view.getLocationOnScreen(screenPos); |
| + final int width = view.getWidth(); |
| + final int height = view.getHeight(); |
| + |
| + Toast toast = Toast.makeText(context, description, Toast.LENGTH_SHORT); |
| + toast.setGravity(Gravity.TOP | Gravity.END, screenWidth - screenPos[0] - width / 2, |
| + (screenPos[1] < screenHeight / 2) ? screenPos[1] + height / 2 |
| + : screenPos[1] - height * 3 / 2); |
| + toast.show(); |
| + return true; |
| + } |
| } |