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

The following examples show how to use org.chromium.chrome.browser.snackbar.Snackbar#make() . 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: AutoSigninSnackbarController.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Displays Auto sign-in snackbar, which communicates to the users that they
 * were signed in to the web site.
 */
@CalledByNative
private static void showSnackbar(Tab tab, String text) {
    SnackbarManager snackbarManager = tab.getSnackbarManager();
    if (snackbarManager == null) return;
    AutoSigninSnackbarController snackbarController =
            new AutoSigninSnackbarController(snackbarManager, tab);
    Snackbar snackbar = Snackbar.make(text, snackbarController, Snackbar.TYPE_NOTIFICATION,
            Snackbar.UMA_AUTO_LOGIN);
    Resources resources = tab.getWindowAndroid().getActivity().get().getResources();
    int backgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.light_active_color);
    Bitmap icon = BitmapFactory.decodeResource(
            resources, R.drawable.account_management_no_picture);
    snackbar.setSingleLine(false).setBackgroundColor(backgroundColor).setProfileImage(icon);
    snackbarManager.showSnackbar(snackbar);
}
 
Example 2
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 3
Source File: AutoSigninSnackbarController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Displays Auto sign-in snackbar, which communicates to the users that they
 * were signed in to the web site.
 */
@CalledByNative
private static void showSnackbar(Tab tab, String text) {
    SnackbarManager snackbarManager = tab.getSnackbarManager();
    if (snackbarManager == null) return;
    AutoSigninSnackbarController snackbarController =
            new AutoSigninSnackbarController(snackbarManager, tab);
    Snackbar snackbar = Snackbar.make(text, snackbarController, Snackbar.TYPE_NOTIFICATION,
            Snackbar.UMA_AUTO_LOGIN);
    Resources resources = tab.getWindowAndroid().getActivity().get().getResources();
    int backgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.light_active_color);
    Bitmap icon = BitmapFactory.decodeResource(
            resources, R.drawable.account_management_no_picture);
    snackbar.setSingleLine(false).setBackgroundColor(backgroundColor).setProfileImage(icon);
    snackbarManager.showSnackbar(snackbar);
}
 
Example 4
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 5
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 6
Source File: AutoSigninSnackbarController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Displays Auto sign-in snackbar, which communicates to the users that they
 * were signed in to the web site.
 */
@CalledByNative
private static void showSnackbar(Tab tab, String text) {
    SnackbarManager snackbarManager = tab.getSnackbarManager();
    if (snackbarManager == null) return;
    AutoSigninSnackbarController snackbarController =
            new AutoSigninSnackbarController(snackbarManager, tab);
    Snackbar snackbar = Snackbar.make(text, snackbarController, Snackbar.TYPE_NOTIFICATION,
            Snackbar.UMA_AUTO_LOGIN);
    Resources resources = tab.getWindowAndroid().getActivity().get().getResources();
    int backgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.light_active_color);
    Bitmap icon = BitmapFactory.decodeResource(
            resources, R.drawable.account_management_no_picture);
    snackbar.setSingleLine(false).setBackgroundColor(backgroundColor).setProfileImage(icon);
    snackbarManager.showSnackbar(snackbar);
}
 
Example 7
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 8
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 9
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 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);
}
 
Example 11
Source File: HistoryManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    mToolbar.hideOverflowMenu();

    if (item.getItemId() == R.id.close_menu_id && isDisplayedInSeparateActivity()) {
        mActivity.finish();
        return true;
    } else if (item.getItemId() == R.id.selection_mode_open_in_new_tab) {
        openItemsInNewTabs(mSelectionDelegate.getSelectedItems(), false);
        mSelectionDelegate.clearSelection();
        return true;
    } else if (item.getItemId() == R.id.selection_mode_copy_link) {
        recordUserActionWithOptionalSearch("CopyLink");
        Clipboard.getInstance().setText(mSelectionDelegate.getSelectedItems().get(0).getUrl());
        mSelectionDelegate.clearSelection();
        Snackbar snackbar = Snackbar.make(mActivity.getString(R.string.copied), this,
                Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_HISTORY_LINK_COPIED);
        mSnackbarManager.showSnackbar(snackbar);
        return true;
    } else if (item.getItemId() == R.id.selection_mode_open_in_incognito) {
        openItemsInNewTabs(mSelectionDelegate.getSelectedItems(), true);
        mSelectionDelegate.clearSelection();
        return true;
    } else if (item.getItemId() == R.id.selection_mode_delete_menu_id) {
        recordSelectionCountHistorgram("Remove");
        recordUserActionWithOptionalSearch("RemoveSelected");

        for (HistoryItem historyItem : mSelectionDelegate.getSelectedItems()) {
            mHistoryAdapter.markItemForRemoval(historyItem);
        }
        mHistoryAdapter.removeItems();
        mSelectionDelegate.clearSelection();
        return true;
    } else if (item.getItemId() == R.id.search_menu_id) {
        mHistoryAdapter.removeHeader();
        mToolbar.showSearchView();
        mSelectableListLayout.onStartSearch();
        recordUserAction("Search");
        mIsSearching = true;
        return true;
    }
    return false;
}