Java Code Examples for org.chromium.chrome.browser.snackbar.Snackbar#setAction()

The following examples show how to use org.chromium.chrome.browser.snackbar.Snackbar#setAction() . 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: DownloadSnackbarController.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Called to display the download succeeded snackbar.
 *
 * @param downloadInfo Info of the download.
 * @param notificationId Notification Id of the successful download.
 * @param downloadId Id of the download from Android DownloadManager.
 * @param canBeResolved Whether the download can be resolved to any activity.
 */
public void onDownloadSucceeded(
        DownloadInfo downloadInfo, int notificationId, long downloadId, boolean canBeResolved) {
    if (getSnackbarManager() == null) return;
    Snackbar snackbar = Snackbar.make(
            mContext.getString(R.string.download_succeeded_message, downloadInfo.getFileName()),
            this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCCEEDED);
    // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
    snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(false);
    ActionDataInfo info = null;
    if (canBeResolved) {
        info = new ActionDataInfo(downloadInfo, notificationId, downloadId);
    }
    // Show downloads app if the download cannot be resolved to any activity.
    snackbar.setAction(
            mContext.getString(R.string.open_downloaded_label), info);
    getSnackbarManager().showSnackbar(snackbar);
}
 
Example 2
Source File: DownloadSnackbarController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called to display the download succeeded snackbar.
 *
 * @param downloadInfo Info of the download.
 * @param notificationId Notification Id of the successful download.
 * @param downloadId Id of the download from Android DownloadManager.
 * @param canBeResolved Whether the download can be resolved to any activity.
 */
public void onDownloadSucceeded(
        DownloadInfo downloadInfo, int notificationId, long downloadId, boolean canBeResolved) {
    if (getSnackbarManager() == null) return;
    Snackbar snackbar = Snackbar.make(
            mContext.getString(R.string.download_succeeded_message, downloadInfo.getFileName()),
            this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCCEEDED);
    // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
    snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(false);
    ActionDataInfo info = null;
    if (canBeResolved || downloadInfo.isOfflinePage()) {
        info = new ActionDataInfo(downloadInfo, notificationId, downloadId);
    }
    // Show downloads app if the download cannot be resolved to any activity.
    snackbar.setAction(
            mContext.getString(R.string.open_downloaded_label), info);
    getSnackbarManager().showSnackbar(snackbar);
}
 
Example 3
Source File: DownloadManagerUi.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void deleteSelectedItems() {
    List<DownloadHistoryItemWrapper> selectedItems =
            mBackendProvider.getSelectionDelegate().getSelectedItems();
    final List<DownloadHistoryItemWrapper> itemsToDelete = getItemsForDeletion();

    mBackendProvider.getSelectionDelegate().clearSelection();

    if (itemsToDelete.isEmpty()) return;

    mHistoryAdapter.removeItemsFromAdapter(itemsToDelete);

    dismissUndoDeletionSnackbars();

    boolean singleItemDeleted = selectedItems.size() == 1;
    String snackbarText = singleItemDeleted ? selectedItems.get(0).getDisplayFileName() :
            String.format(Locale.getDefault(), "%d", selectedItems.size());
    int snackbarTemplateId = singleItemDeleted ? R.string.undo_bar_delete_message
            : R.string.undo_bar_multiple_downloads_delete_message;

    Snackbar snackbar = Snackbar.make(snackbarText, mUndoDeletionSnackbarController,
            Snackbar.TYPE_ACTION, Snackbar.UMA_DOWNLOAD_DELETE_UNDO);
    snackbar.setAction(mActivity.getString(R.string.undo), itemsToDelete);
    snackbar.setTemplateText(mActivity.getString(snackbarTemplateId));

    ((SnackbarManageable) mActivity).getSnackbarManager().showSnackbar(snackbar);
}
 
Example 4
Source File: DownloadManagerUi.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void deleteSelectedItems() {
    List<DownloadHistoryItemWrapper> selectedItems =
            mBackendProvider.getSelectionDelegate().getSelectedItems();
    final List<DownloadHistoryItemWrapper> itemsToDelete = getItemsForDeletion();

    mBackendProvider.getSelectionDelegate().clearSelection();

    if (itemsToDelete.isEmpty()) return;

    mHistoryAdapter.markItemsForDeletion(itemsToDelete);

    boolean singleItemDeleted = selectedItems.size() == 1;
    String snackbarText = singleItemDeleted ? selectedItems.get(0).getDisplayFileName() :
            String.format(Locale.getDefault(), "%d", selectedItems.size());
    int snackbarTemplateId = singleItemDeleted ? R.string.undo_bar_delete_message
            : R.string.undo_bar_multiple_downloads_delete_message;

    Snackbar snackbar = Snackbar.make(snackbarText, mUndoDeletionSnackbarController,
            Snackbar.TYPE_ACTION, Snackbar.UMA_DOWNLOAD_DELETE_UNDO);
    snackbar.setAction(mActivity.getString(R.string.undo), itemsToDelete);
    snackbar.setTemplateText(mActivity.getString(snackbarTemplateId));

    mSnackbarManager.showSnackbar(snackbar);
}
 
Example 5
Source File: DownloadSnackbarController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called to display the download failed snackbar.
 *
 * @param errorMessage     The message to show on the snackbar.
 * @param showAllDownloads Whether to show all downloads in case the failure is caused by
 *                         duplicated files.
 */
public void onDownloadFailed(String errorMessage, boolean showAllDownloads) {
    if (getSnackbarManager() == null) return;
    // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
    Snackbar snackbar = Snackbar
            .make(errorMessage, this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_FAILED)
            .setSingleLine(false)
            .setDuration(SNACKBAR_DURATION_IN_MILLISECONDS);
    if (showAllDownloads) {
        snackbar.setAction(
                mContext.getString(R.string.open_downloaded_label),
                null);
    }
    getSnackbarManager().showSnackbar(snackbar);
}
 
Example 6
Source File: DownloadSnackbarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called to display the download failed snackbar.
 *
 * @param errorMessage     The message to show on the snackbar.
 * @param showAllDownloads Whether to show all downloads in case the failure is caused by
 *                         duplicated files.
 */
public void onDownloadFailed(String errorMessage, boolean showAllDownloads) {
    if (getSnackbarManager() == null) return;
    // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
    Snackbar snackbar = Snackbar
            .make(errorMessage, this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_FAILED)
            .setSingleLine(false)
            .setDuration(SNACKBAR_DURATION_IN_MILLISECONDS);
    if (showAllDownloads) {
        snackbar.setAction(
                mContext.getString(R.string.open_downloaded_label),
                null);
    }
    getSnackbarManager().showSnackbar(snackbar);
}
 
Example 7
Source File: LocaleManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void showSnackbar(CharSequence title) {
    SnackbarManager manager = mSnackbarManager.get();
    if (manager == null) return;

    Context context = ContextUtils.getApplicationContext();
    Snackbar snackbar = Snackbar.make(title, mSnackbarController, Snackbar.TYPE_NOTIFICATION,
            Snackbar.UMA_SPECIAL_LOCALE);
    snackbar.setDuration(SNACKBAR_DURATION_MS);
    snackbar.setAction(context.getString(R.string.preferences), null);
    manager.showSnackbar(snackbar);
}
 
Example 8
Source File: DownloadSnackbarController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called to display the download succeeded snackbar.
 *
 * @param downloadInfo Info of the download.
 * @param notificationId Notification Id of the successful download.
 * @param downloadId Id of the download from Android DownloadManager.
 * @param canBeResolved Whether the download can be resolved to any activity.
 * @param usesAndroidDownloadManager Whether the download uses Android DownloadManager.
 */
public void onDownloadSucceeded(
        DownloadInfo downloadInfo, int notificationId, long downloadId, boolean canBeResolved,
        boolean usesAndroidDownloadManager) {
    if (getSnackbarManager() == null) return;
    Snackbar snackbar;
    if (getActivity() instanceof CustomTabActivity) {
        String packageLabel = BuildInfo.getPackageLabel();
        snackbar = Snackbar.make(mContext.getString(R.string.download_succeeded_message,
                downloadInfo.getFileName(), packageLabel),
                this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCCEEDED);
    } else {
        snackbar = Snackbar.make(mContext.getString(R.string.download_succeeded_message_default,
                downloadInfo.getFileName()),
                this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_SUCCEEDED);
    }
    // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
    snackbar.setDuration(SNACKBAR_DURATION_IN_MILLISECONDS).setSingleLine(false);
    ActionDataInfo info = null;
    if (canBeResolved || !LegacyHelpers.isLegacyDownload(downloadInfo.getContentId())
            || usesAndroidDownloadManager) {
        info = new ActionDataInfo(downloadInfo, notificationId, downloadId,
                usesAndroidDownloadManager);
    }
    // Show downloads app if the download cannot be resolved to any activity.
    snackbar.setAction(
            mContext.getString(R.string.open_downloaded_label), info);
    getSnackbarManager().showSnackbar(snackbar);
}
 
Example 9
Source File: DownloadSnackbarController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called to display the download failed snackbar.
 *
 * @param errorMessage     The message to show on the snackbar.
 * @param showAllDownloads Whether to show all downloads in case the failure is caused by
 *                         duplicated files.
 */
public void onDownloadFailed(String errorMessage, boolean showAllDownloads) {
    if (getSnackbarManager() == null) return;
    // TODO(qinmin): Coalesce snackbars if multiple downloads finish at the same time.
    Snackbar snackbar = Snackbar
            .make(errorMessage, this, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DOWNLOAD_FAILED)
            .setSingleLine(false)
            .setDuration(SNACKBAR_DURATION_IN_MILLISECONDS);
    if (showAllDownloads) {
        snackbar.setAction(
                mContext.getString(R.string.open_downloaded_label),
                null);
    }
    getSnackbarManager().showSnackbar(snackbar);
}
 
Example 10
Source File: LocaleManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void showSnackbar(CharSequence title) {
    SnackbarManager manager = mSnackbarManager.get();
    if (manager == null) return;

    Context context = ContextUtils.getApplicationContext();
    Snackbar snackbar = Snackbar.make(title, mSnackbarController, Snackbar.TYPE_NOTIFICATION,
            Snackbar.UMA_SPECIAL_LOCALE);
    snackbar.setDuration(SNACKBAR_DURATION_MS);
    snackbar.setAction(context.getString(R.string.preferences), null);
    manager.showSnackbar(snackbar);
}