Java Code Examples for org.chromium.ui.widget.Toast#show()

The following examples show how to use org.chromium.ui.widget.Toast#show() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolbarLayout.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the content description toast for items on the toolbar.
 * @param view The view to anchor the toast.
 * @param description The string shown in the toast.
 * @return Whether a toast has been shown successfully.
 */
protected boolean showAccessibilityToast(View view, CharSequence description) {
    if (description == null) return false;

    final int screenWidth = getResources().getDisplayMetrics().widthPixels;
    final int[] screenPos = new int[2];
    view.getLocationOnScreen(screenPos);
    final int width = view.getWidth();

    Toast toast = Toast.makeText(getContext(), description, Toast.LENGTH_SHORT);
    toast.setGravity(
            Gravity.TOP | Gravity.END,
            screenWidth - screenPos[0] - width / 2,
            screenPos[1] + getHeight() / 2);
    toast.show();
    return true;
}
 
Example 2
Source File: ToolbarLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the content description toast for items on the toolbar.
 * @param view The view to anchor the toast.
 * @param description The string shown in the toast.
 * @return Whether a toast has been shown successfully.
 */
protected boolean showAccessibilityToast(View view, CharSequence description) {
    if (description == null) return false;

    final int screenWidth = getResources().getDisplayMetrics().widthPixels;
    final int[] screenPos = new int[2];
    view.getLocationOnScreen(screenPos);
    final int width = view.getWidth();

    Toast toast = Toast.makeText(getContext(), description, Toast.LENGTH_SHORT);
    toast.setGravity(
            Gravity.TOP | Gravity.END,
            screenWidth - screenPos[0] - width / 2,
            screenPos[1] + getHeight() / 2);
    toast.show();
    return true;
}
 
Example 3
Source File: AccessibilityUtil.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the content description toast for items on the toolbar.
 * @param context The context to use for the toast.
 * @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;
}
 
Example 4
Source File: AbstractMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
protected void showCastError(String routeName) {
    Toast toast = Toast.makeText(
            getContext(),
            getContext().getString(R.string.cast_error_playing_video, routeName),
            Toast.LENGTH_SHORT);
    toast.show();
}
 
Example 5
Source File: AbstractMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
protected void showCastError(String routeName) {
    Toast toast = Toast.makeText(
            getContext(),
            getContext().getString(R.string.cast_error_playing_video, routeName),
            Toast.LENGTH_SHORT);
    toast.show();
}
 
Example 6
Source File: AbstractMediaRouteController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
protected void showCastError(String routeName) {
    Toast toast = Toast.makeText(
            getContext(),
            getContext().getString(R.string.cast_error_playing_video, routeName),
            Toast.LENGTH_SHORT);
    toast.show();
}
 
Example 7
Source File: RemoteMediaPlayerController.java    From delion with Apache License 2.0 4 votes vote down vote up
private void showMessageToast(String message) {
    Toast toast = Toast.makeText(mCastContextApplicationContext, message, Toast.LENGTH_SHORT);
    toast.show();
}
 
Example 8
Source File: RemoteMediaPlayerController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void showMessageToast(String message) {
    Toast toast = Toast.makeText(mCastContextApplicationContext, message, Toast.LENGTH_SHORT);
    toast.show();
}
 
Example 9
Source File: AccountChooserDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void showTooltip(View view, String message, int layoutId) {
    Context context = view.getContext();
    Resources resources = context.getResources();
    LayoutInflater inflater = LayoutInflater.from(context);

    TextView text = (TextView) inflater.inflate(layoutId, null);
    text.setText(message);
    text.announceForAccessibility(message);

    // This is a work-around for a bug on Android versions KitKat and below
    // (http://crbug.com/693076). The tooltip wouldn't be shown otherwise.
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
        text.setSingleLine(false);
    }

    // The tooltip should be shown above and to the left (right for RTL) of the info button.
    // In order to do so the tooltip's location on the screen is determined. This location is
    // specified with regard to the top left corner and ignores RTL layouts. For this reason the
    // location of the tooltip is also specified as offsets to the top left corner of the
    // screen. Since the tooltip should be shown above the info button, the height of the
    // tooltip needs to be measured. Furthermore, the height of the statusbar is ignored when
    // obtaining the icon's screen location, but must be considered when specifying a y offset.
    // In addition, the measured width is needed in LTR layout, so that the right end of the
    // tooltip aligns with the right end of the info icon.
    final int[] screenPos = new int[2];
    view.getLocationOnScreen(screenPos);

    text.measure(MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

    final int width = view.getWidth();

    final int xOffset = ApiCompatibilityUtils.isLayoutRtl(view)
            ? screenPos[0]
            : screenPos[0] + width - text.getMeasuredWidth();

    final int statusBarHeightResourceId =
            resources.getIdentifier("status_bar_height", "dimen", "android");

    final int statusBarHeight = statusBarHeightResourceId > 0
            ? resources.getDimensionPixelSize(statusBarHeightResourceId)
            : 0;

    final int tooltipMargin = resources.getDimensionPixelSize(R.dimen.psl_info_tooltip_margin);

    final int yOffset =
            screenPos[1] - tooltipMargin - statusBarHeight - text.getMeasuredHeight();

    // The xOffset is with regard to the left edge of the screen. Gravity.LEFT is deprecated,
    // which is why the following line is necessary.
    final int xGravity = ApiCompatibilityUtils.isLayoutRtl(view) ? Gravity.END : Gravity.START;

    Toast toast = new Toast(context);
    toast.setGravity(Gravity.TOP | xGravity, xOffset, yOffset);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(text);
    toast.show();
}
 
Example 10
Source File: RemoteMediaPlayerController.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void showMessageToast(String message) {
    Toast toast = Toast.makeText(mCastContextApplicationContext, message, Toast.LENGTH_SHORT);
    toast.show();
}