org.chromium.ui.widget.Toast Java Examples

The following examples show how to use org.chromium.ui.widget.Toast. 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: TranslatePreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_translate),
                        Profile.getLastUsedProfile(), null);
        return true;
    } else if (itemId == R.id.menu_id_reset) {
        PrefServiceBridge.getInstance().resetTranslateDefaults();
        Toast.makeText(getActivity(), getString(
                R.string.translate_prefs_toast_description),
                Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #2
Source File: DownloadHistoryItemWrapper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void open() {
    Context context = ContextUtils.getApplicationContext();

    if (mItem.hasBeenExternallyRemoved()) {
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                Toast.LENGTH_SHORT).show();
        return;
    }

    if (DownloadUtils.openFile(getFile(), getMimeType(),
                mItem.getDownloadInfo().getDownloadGuid(), isOffTheRecord())) {
        recordOpenSuccess();
    } else {
        recordOpenFailure();
    }
}
 
Example #3
Source File: TranslateCompactInfoBar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@CalledByNative
private void onPageTranslated(int errorType) {
    incrementAndRecordTranslationsPerPageCount();
    if (mTabLayout != null) {
        mTabLayout.hideProgressBar();
        if (errorType != 0) {
            Toast.makeText(getContext(), R.string.translate_infobar_error, Toast.LENGTH_SHORT)
                    .show();
            // Disable OnTabSelectedListener then revert selection.
            mTabLayout.removeOnTabSelectedListener(this);
            mTabLayout.getTabAt(SOURCE_TAB_INDEX).select();
            // Add OnTabSelectedListener back.
            mTabLayout.addOnTabSelectedListener(this);
        }
    }
}
 
Example #4
Source File: CustomTabToolbar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (v == mCloseButton) {
        return showAccessibilityToast(v, getResources().getString(R.string.close_tab));
    } else if (v == mCustomActionButton) {
        return showAccessibilityToast(v, mCustomActionButton.getContentDescription());
    } else if (v == mTitleUrlContainer) {
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        Tab tab = getCurrentTab();
        if (tab == null) return false;
        String url = tab.getOriginalUrl();
        ClipData clip = ClipData.newPlainText("url", url);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #5
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 #6
Source File: CustomTabToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (v == mCloseButton) {
        return AccessibilityUtil.showAccessibilityToast(
                getContext(), v, getResources().getString(R.string.close_tab));
    } else if (v == mCustomActionButton) {
        return AccessibilityUtil.showAccessibilityToast(
                getContext(), v, mCustomActionButton.getContentDescription());
    } else if (v == mTitleUrlContainer) {
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        Tab tab = getCurrentTab();
        if (tab == null) return false;
        String url = tab.getOriginalUrl();
        ClipData clip = ClipData.newPlainText("url", url);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #7
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 #8
Source File: TranslatePreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_translate),
                        Profile.getLastUsedProfile(), null);
        return true;
    } else if (itemId == R.id.menu_id_reset) {
        PrefServiceBridge.getInstance().resetTranslateDefaults();
        Toast.makeText(getActivity(), getString(
                R.string.translate_prefs_toast_description),
                Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #9
Source File: LanguagePreferences.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_id_targeted_help) {
        HelpAndFeedback.getInstance(getActivity())
                .show(getActivity(), getString(R.string.help_context_translate),
                        Profile.getLastUsedProfile(), null);
        return true;
    } else if (itemId == R.id.menu_id_reset) {
        PrefServiceBridge.getInstance().resetTranslateDefaults();
        Toast.makeText(getActivity(), getString(
                R.string.translate_prefs_toast_description),
                Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #10
Source File: DownloadHistoryItemWrapper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void open() {
    Context context = ContextUtils.getApplicationContext();

    if (mItem.hasBeenExternallyRemoved()) {
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                Toast.LENGTH_SHORT).show();
        return;
    }

    if (DownloadUtils.openFile(getFile(), getMimeType(), isOffTheRecord())) {
        recordOpenSuccess();
    } else {
        recordOpenFailure();
    }
}
 
Example #11
Source File: CustomTabToolbar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (v == mCloseButton) {
        return showAccessibilityToast(v, getResources().getString(R.string.close_tab));
    } else if (v == mCustomActionButton) {
        return showAccessibilityToast(v, mCustomActionButton.getContentDescription());
    } else if (v == mTitleUrlContainer) {
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("url", mUrlBar.getText());
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}
 
Example #12
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 #13
Source File: UiConfig.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void debug(DisplayStyle displayStyle, int widthDp, int heightDp) {
    String horizontalStyleName;
    String verticalStyleName;

    switch (displayStyle.horizontal) {
        case HorizontalDisplayStyle.NARROW:
            horizontalStyleName = "NARROW";
            break;
        case HorizontalDisplayStyle.REGULAR:
            horizontalStyleName = "REGULAR";
            break;
        case HorizontalDisplayStyle.WIDE:
            horizontalStyleName = "WIDE";
            break;
        default:
            throw new IllegalStateException();
    }

    switch (displayStyle.vertical) {
        case VerticalDisplayStyle.FLAT:
            verticalStyleName = "FLAT";
            break;
        case VerticalDisplayStyle.REGULAR:
            verticalStyleName = "REGULAR";
            break;
        default:
            throw new IllegalStateException();
    }

    String debugString = String.format(Locale.US, "%s | %s (w=%ddp, h=%ddp)",
            horizontalStyleName, verticalStyleName, widthDp, heightDp);
    Log.d(TAG, debugString);
    Toast.makeText(mContext, debugString, Toast.LENGTH_SHORT).show();
}
 
Example #14
Source File: DownloadManagerService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a download fails.
 *
 * @param fileName Name of the download file.
 * @param reason Reason of failure reported by android DownloadManager
 */
protected void onDownloadFailed(String fileName, int reason) {
    String failureMessage = getDownloadFailureMessage(fileName, reason);
    if (mDownloadSnackbarController.getSnackbarManager() != null) {
        mDownloadSnackbarController.onDownloadFailed(
                failureMessage,
                reason == DownloadManager.ERROR_FILE_ALREADY_EXISTS);
    } else {
        Toast.makeText(mContext, failureMessage, Toast.LENGTH_SHORT).show();
    }
}
 
Example #15
Source File: SuggestionsBottomSheetContent.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateContextualSuggestions(String url) {
    mSuggestionsUiDelegate.getSuggestionsSource().fetchContextualSuggestions(
            url, new Callback<List<SnippetArticle>>() {
                @Override
                public void onResult(List<SnippetArticle> result) {
                    String text = String.format(
                            Locale.US, "Received %d contextual suggestions", result.size());
                    Toast.makeText(mRecyclerView.getContext(), text, Toast.LENGTH_SHORT).show();
                }
            });
}
 
Example #16
Source File: DataReductionPromoInfoBarDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Enables the data reduction proxy, records uma, and shows a confirmation toast.
 *
 * @param isPrimaryButton Whether the primary infobar button was clicked.
 * @param context An Android context.
 */
@CalledByNative
private static void accept() {
    Context context = ContextUtils.getApplicationContext();
    DataReductionProxyUma
            .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_ENABLED);
    DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
            context, true);
    Toast.makeText(context,
            context.getString(R.string.data_reduction_enabled_toast),
            Toast.LENGTH_LONG).show();
}
 
Example #17
Source File: DataReductionPromoScreen.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void handleEnableButtonPressed() {
    DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
            getContext(), true);
    dismiss();
    Toast.makeText(getContext(), getContext().getString(R.string.data_reduction_enabled_toast),
            Toast.LENGTH_LONG).show();
}
 
Example #18
Source File: BeamCallback.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Trigger an error about NFC if we don't want to send anything. Also
 * records a UMA stat. On ICS we only show the error if they attempt to
 * beam, since the recipient will receive the market link. On JB we'll
 * always show the error, since the beam animation won't trigger, which
 * could be confusing to the user.
 *
 * @param errorStringId The resid of the string to display as error.
 */
private void onInvalidBeam(final int errorStringId) {
    RecordUserAction.record("MobileBeamInvalidAppState");
    Runnable errorRunnable = new Runnable() {
        @Override
        public void run() {
            Toast.makeText(mActivity, errorStringId, Toast.LENGTH_SHORT).show();
        }
    };
    if (NFC_BUGS_ACTIVE) {
        mErrorRunnableIfBeamSent = errorRunnable;
    } else {
        ThreadUtils.runOnUiThread(errorRunnable);
    }
}
 
Example #19
Source File: DownloadUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Opens a file in Chrome or in another app if appropriate.
 * @param file path to the file to open.
 * @param mimeType mime type of the file.
 * @param downloadGuid The associated download GUID.
 * @param isOffTheRecord whether we are in an off the record context.
 * @return whether the file could successfully be opened.
 */
public static boolean openFile(
        File file, String mimeType, String downloadGuid, boolean isOffTheRecord) {
    Context context = ContextUtils.getApplicationContext();
    DownloadManagerService service = DownloadManagerService.getDownloadManagerService();

    // Check if Chrome should open the file itself.
    if (service.isDownloadOpenableInBrowser(isOffTheRecord, mimeType)) {
        // Share URIs use the content:// scheme when able, which looks bad when displayed
        // in the URL bar.
        Uri fileUri = Uri.fromFile(file);
        Uri contentUri = getUriForItem(file);
        String normalizedMimeType = Intent.normalizeMimeType(mimeType);

        Intent intent =
                getMediaViewerIntentForDownloadItem(fileUri, contentUri, normalizedMimeType);
        IntentHandler.startActivityForTrustedIntent(intent);
        service.updateLastAccessTime(downloadGuid, isOffTheRecord);
        return true;
    }

    // Check if any apps can open the file.
    try {
        // TODO(qinmin): Move this to an AsyncTask so we don't need to temper with strict mode.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        Uri uri = ApiCompatibilityUtils.getUriForDownloadedFile(file);
        StrictMode.setThreadPolicy(oldPolicy);
        Intent viewIntent = createViewIntentForDownloadItem(uri, mimeType);
        context.startActivity(viewIntent);
        service.updateLastAccessTime(downloadGuid, isOffTheRecord);
        return true;
    } catch (ActivityNotFoundException e) {
        // Can't launch the Intent.
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                     Toast.LENGTH_SHORT)
                .show();
        return false;
    }
}
 
Example #20
Source File: CustomButtonParams.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Builds an {@link ImageButton} from the data in this params. Generated buttons should be
 * placed on the bottom bar. The button's tag will be its id.
 * @param parent The parent that the inflated {@link ImageButton}.
 * @param listener {@link OnClickListener} that should be used with the button.
 * @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid.
 */
ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) {
    if (mIsOnToolbar) return null;

    ImageButton button = (ImageButton) LayoutInflater.from(context)
            .inflate(R.layout.custom_tabs_bottombar_item, parent, false);
    button.setId(mId);
    button.setImageBitmap(mIcon);
    button.setContentDescription(mDescription);
    if (mPendingIntent == null) {
        button.setEnabled(false);
    } else {
        button.setOnClickListener(listener);
    }
    button.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            final int screenWidth = view.getResources().getDisplayMetrics().widthPixels;
            final int screenHeight = view.getResources().getDisplayMetrics().heightPixels;
            final int[] screenPos = new int[2];
            view.getLocationOnScreen(screenPos);
            final int width = view.getWidth();

            Toast toast = Toast.makeText(
                    view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.BOTTOM | Gravity.END,
                    screenWidth - screenPos[0] - width / 2,
                    screenHeight - screenPos[1]);
            toast.show();
            return true;
        }
    });
    return button;
}
 
Example #21
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 #22
Source File: Clipboard.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public void setPrimaryClipNoException(ClipData clip) {
    try {
        mClipboardManager.setPrimaryClip(clip);
    } catch (Exception ex) {
        // Ignore any exceptions here as certain devices have bugs and will fail.
        String text = mContext.getString(R.string.copy_to_clipboard_failure_message);
        Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
    }
}
 
Example #23
Source File: SingleCategoryPreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void resetDeviceCredential() {
    MediaDrmCredentialManager.resetCredentials(new MediaDrmCredentialManagerCallback() {
        @Override
        public void onCredentialResetFinished(boolean succeeded) {
            if (succeeded) return;
            String message = getString(R.string.protected_content_reset_failed);
            Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
        }
    });
}
 
Example #24
Source File: OfflinePageNotificationBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a "Downloading ..." toast for the requested items already scheduled for download.
 */
@CalledByNative
public static void showDownloadingToast() {
    Toast.makeText(ContextUtils.getApplicationContext(), R.string.download_started,
                 Toast.LENGTH_SHORT)
            .show();
}
 
Example #25
Source File: BeamCallback.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Trigger an error about NFC if we don't want to send anything. Also
 * records a UMA stat. On ICS we only show the error if they attempt to
 * beam, since the recipient will receive the market link. On JB we'll
 * always show the error, since the beam animation won't trigger, which
 * could be confusing to the user.
 *
 * @param errorStringId The resid of the string to display as error.
 */
private void onInvalidBeam(final int errorStringId) {
    RecordUserAction.record("MobileBeamInvalidAppState");
    Runnable errorRunnable = new Runnable() {
        @Override
        public void run() {
            Toast.makeText(mActivity, errorStringId, Toast.LENGTH_SHORT).show();
        }
    };
    ThreadUtils.runOnUiThread(errorRunnable);
}
 
Example #26
Source File: FullscreenHtmlApiHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Create and show the fullscreen notification toast.
 */
private void showNotificationToast() {
    if (mNotificationToast == null) {
        int resId = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
                ? R.string.immersive_fullscreen_api_notification
                : R.string.fullscreen_api_notification;
        mNotificationToast = Toast.makeText(
                mWindow.getContext(), resId, Toast.LENGTH_LONG);
        mNotificationToast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 0);
    }
    mNotificationToast.show();
}
 
Example #27
Source File: DataReductionPromoInfoBarDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Enables the data reduction proxy, records uma, and shows a confirmation toast.
 *
 * @param isPrimaryButton Whether the primary infobar button was clicked.
 * @param context An Android context.
 */
@CalledByNative
private static void accept() {
    Context context = ContextUtils.getApplicationContext();
    DataReductionProxyUma
            .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_ENABLED);
    DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
            context, true);
    Toast.makeText(context,
            context.getString(R.string.data_reduction_enabled_toast),
            Toast.LENGTH_LONG).show();
}
 
Example #28
Source File: AppBannerInfoBarDelegateAndroid.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static void showWebApkInstallFailureToast() {
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Context applicationContext = ContextUtils.getApplicationContext();
            Toast toast = Toast.makeText(applicationContext, R.string.fail_to_install_webapk,
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    });
}
 
Example #29
Source File: DataReductionPromoScreen.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void handleEnableButtonPressed() {
    DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
            getContext(), true);
    dismiss();
    Toast.makeText(getContext(), getContext().getString(R.string.data_reduction_enabled_toast),
            Toast.LENGTH_LONG).show();
}
 
Example #30
Source File: SingleCategoryPreferences.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void resetDeviceCredential() {
    MediaDrmCredentialManager.resetCredentials(new MediaDrmCredentialManagerCallback() {
        @Override
        public void onCredentialResetFinished(boolean succeeded) {
            if (succeeded) return;
            String message = getString(R.string.protected_content_reset_failed);
            Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
        }
    });
}