org.chromium.chrome.browser.snackbar.Snackbar Java Examples

The following examples show how to use org.chromium.chrome.browser.snackbar.Snackbar. 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: TranslateCompactInfoBar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void closeInfobar(boolean explicitly) {
    // Check if we should trigger the auto "never translate" if infobar is closed explicitly.
    if (explicitly && mNativeTranslateInfoBarPtr != 0
            && nativeShouldAutoNeverTranslate(mNativeTranslateInfoBarPtr, mMenuExpanded)) {
        createAndShowSnackbar(getContext().getString(R.string.translate_snackbar_language_never,
                                      mOptions.sourceLanguageName()),
                Snackbar.UMA_TRANSLATE_NEVER, ACTION_AUTO_NEVER_LANGUAGE);
        // Postpone the infobar dismiss until the snackbar finished showing.  Otherwise, the
        // reference to the native infobar is killed and there is no way for the snackbar to
        // perform the action.
        return;
    }
    recordInfobarAction(INFOBAR_CLOSE);
    // This line will dismiss this infobar.
    super.onCloseButtonClicked();
}
 
Example #3
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 #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: 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 #6
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 #7
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 #8
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 #9
Source File: UndoBarController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Shows an undo bar. Based on user actions, this will cause a call to either
 * {@link TabModel#commitTabClosure(int)} or {@link TabModel#cancelTabClosure(int)} to be called
 * for {@code tabId}.
 *
 * @param tabId The id of the tab.
 * @param content The title of the tab.
 */
private void showUndoBar(int tabId, String content) {
    RecordHistogram.recordEnumeratedHistogram("AndroidTabCloseUndo.Toast",
            mSnackbarManager.isShowing() ? TAB_CLOSE_UNDO_TOAST_SHOWN_WARM
                                         : TAB_CLOSE_UNDO_TOAST_SHOWN_COLD,
            TAB_CLOSE_UNDO_TOAST_COUNT);
    mSnackbarManager.showSnackbar(
            Snackbar.make(content, this, Snackbar.TYPE_ACTION, Snackbar.UMA_TAB_CLOSE_UNDO)
                    .setTemplateText(mContext.getString(R.string.undo_bar_close_message))
                    .setAction(mContext.getString(R.string.undo), tabId));
}
 
Example #10
Source File: GeolocationSnackbarController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) return;
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = AccessibilityUtil.isAccessibilityEnabled()
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example #11
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 #12
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 #13
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 #14
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void showReloadSnackbar(Context context, SnackbarManager snackbarManager,
        final SnackbarController snackbarController, int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return;

    Log.d(TAG, "showReloadSnackbar called with controller " + snackbarController);
    Snackbar snackbar =
            Snackbar.make(context.getString(R.string.offline_pages_viewing_offline_page),
                            snackbarController, Snackbar.TYPE_ACTION,
                            Snackbar.UMA_OFFLINE_PAGE_RELOAD)
                    .setSingleLine(false)
                    .setAction(context.getString(R.string.reload), tabId);
    snackbar.setDuration(sSnackbarDurationMs);
    snackbarManager.showSnackbar(snackbar);
}
 
Example #15
Source File: UndoBarController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Shows an undo bar. Based on user actions, this will cause a call to either
 * {@link TabModel#commitTabClosure(int)} or {@link TabModel#cancelTabClosure(int)} to be called
 * for {@code tabId}.
 *
 * @param tabId The id of the tab.
 * @param content The title of the tab.
 */
private void showUndoBar(int tabId, String content) {
    RecordHistogram.recordEnumeratedHistogram("AndroidTabCloseUndo.Toast",
            mSnackbarManager.isShowing() ? TAB_CLOSE_UNDO_TOAST_SHOWN_WARM
                                         : TAB_CLOSE_UNDO_TOAST_SHOWN_COLD,
            TAB_CLOSE_UNDO_TOAST_COUNT);
    mSnackbarManager.showSnackbar(
            Snackbar.make(content, this, Snackbar.TYPE_ACTION, Snackbar.UMA_TAB_CLOSE_UNDO)
                    .setTemplateText(mContext.getString(R.string.undo_bar_close_message))
                    .setAction(mContext.getString(R.string.undo), tabId));
}
 
Example #16
Source File: GeolocationSnackbarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) return;
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext())
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example #17
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 #18
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 #19
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the "reload" snackbar for the given tab.
 * @param activity The activity owning the tab.
 * @param snackbarController Class to show the snackbar.
 */
public static void showReloadSnackbar(Context context, SnackbarManager snackbarManager,
        final SnackbarController snackbarController, int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return;

    Log.d(TAG, "showReloadSnackbar called with controller " + snackbarController);
    Snackbar snackbar =
            Snackbar.make(context.getString(R.string.offline_pages_viewing_offline_page),
                    snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_OFFLINE_PAGE_RELOAD)
                    .setSingleLine(false).setAction(context.getString(R.string.reload), tabId);
    snackbar.setDuration(sSnackbarDurationMs);
    snackbarManager.showSnackbar(snackbar);
}
 
Example #20
Source File: UndoBarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows an undo close all bar. Based on user actions, this will cause a call to either
 * {@link TabModel#commitTabClosure(int)} or {@link TabModel#cancelTabClosure(int)} to be called
 * for each tab in {@code closedTabIds}. This will happen unless
 * {@code SnackbarManager#removeFromStackForData(Object)} is called.
 *
 * @param closedTabIds A list of ids corresponding to tabs that were closed
 */
private void showUndoCloseAllBar(List<Integer> closedTabIds) {
    String content = String.format(Locale.getDefault(), "%d", closedTabIds.size());
    mSnackbarManager.showSnackbar(
            Snackbar.make(content, this, Snackbar.TYPE_ACTION, Snackbar.UMA_TAB_CLOSE_ALL_UNDO)
            .setTemplateText(mContext.getString(R.string.undo_bar_close_all_message))
            .setAction(mContext.getString(R.string.undo), closedTabIds));

}
 
Example #21
Source File: UndoBarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows an undo bar. Based on user actions, this will cause a call to either
 * {@link TabModel#commitTabClosure(int)} or {@link TabModel#cancelTabClosure(int)} to be called
 * for {@code tabId}.
 *
 * @param tabId The id of the tab.
 * @param content The title of the tab.
 */
private void showUndoBar(int tabId, String content) {
    RecordHistogram.recordEnumeratedHistogram("AndroidTabCloseUndo.Toast",
            mSnackbarManager.isShowing() ? TAB_CLOSE_UNDO_TOAST_SHOWN_WARM
                                         : TAB_CLOSE_UNDO_TOAST_SHOWN_COLD,
            TAB_CLOSE_UNDO_TOAST_COUNT);
    mSnackbarManager.showSnackbar(
            Snackbar.make(content, this, Snackbar.TYPE_ACTION, Snackbar.UMA_TAB_CLOSE_UNDO)
                    .setTemplateText(mContext.getString(R.string.undo_bar_close_message))
                    .setAction(mContext.getString(R.string.undo), tabId));
}
 
Example #22
Source File: GeolocationSnackbarController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
 * is currently relevant: i.e. the default search engine is Google, location is enabled
 * for Chrome, the tab is not incognito, etc.
 *
 * @param snackbarManager The SnackbarManager used to show the snackbar.
 * @param view Any view that's attached to the view hierarchy.
 * @param isIncognito Whether the currently visible tab is incognito.
 * @param delayMs The delay in ms before the snackbar should be shown. This is intended to
 *                give the keyboard time to animate in.
 */
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view,
        boolean isIncognito, int delayMs) {
    final Context context = view.getContext();
    if (getGeolocationSnackbarShown(context)) return;

    // If in incognito mode, don't show the snackbar now, but maybe show it later.
    if (isIncognito) return;

    if (neverShowSnackbar(context)) {
        setGeolocationSnackbarShown(context);
        return;
    }

    Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
    TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
    String messageWithoutSpans = context.getResources().getString(
            R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
    SpannableString message = SpanApplier.applySpans(messageWithoutSpans,
            new SpanInfo("<b>", "</b>", robotoMediumSpan));
    String settings = context.getResources().getString(R.string.preferences);
    int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext())
            ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
    final GeolocationSnackbarController controller = new GeolocationSnackbarController();
    final Snackbar snackbar = Snackbar
            .make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION)
            .setAction(settings, view)
            .setSingleLine(false)
            .setDuration(durationMs);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbarManager.dismissSnackbars(controller);
            snackbarManager.showSnackbar(snackbar);
            setGeolocationSnackbarShown(context);
        }
    }, delayMs);
}
 
Example #23
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 #24
Source File: OfflinePageUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the "reload" snackbar for the given tab.
 * @param activity The activity owning the tab.
 * @param snackbarController Class to show the snackbar.
 */
public static void showReloadSnackbar(Context context, SnackbarManager snackbarManager,
        final SnackbarController snackbarController, int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return;

    Log.d(TAG, "showReloadSnackbar called with controller " + snackbarController);
    Snackbar snackbar =
            Snackbar.make(context.getString(R.string.offline_pages_viewing_offline_page),
                    snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_OFFLINE_PAGE_RELOAD)
                    .setSingleLine(false).setAction(context.getString(R.string.reload), tabId);
    snackbar.setDuration(SNACKBAR_DURATION);
    snackbarManager.showSnackbar(snackbar);
}
 
Example #25
Source File: UndoBarController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Shows an undo close all bar. Based on user actions, this will cause a call to either
 * {@link TabModel#commitTabClosure(int)} or {@link TabModel#cancelTabClosure(int)} to be called
 * for each tab in {@code closedTabIds}. This will happen unless
 * {@code SnackbarManager#removeFromStackForData(Object)} is called.
 *
 * @param closedTabIds A list of ids corresponding to tabs that were closed
 */
private void showUndoCloseAllBar(List<Integer> closedTabIds) {
    String content = String.format(Locale.getDefault(), "%d", closedTabIds.size());
    mSnackbarManager.showSnackbar(
            Snackbar.make(content, this, Snackbar.TYPE_ACTION, Snackbar.UMA_TAB_CLOSE_ALL_UNDO)
            .setTemplateText(mContext.getString(R.string.undo_bar_close_all_message))
            .setAction(mContext.getString(R.string.undo), closedTabIds));

}
 
Example #26
Source File: BlimpMessageBuilder.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected Snackbar getSnackbarForTest() {
    return mSnackbar;
}
 
Example #27
Source File: TranslateCompactInfoBar.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
private void setAutoAlwaysTranslate() {
    createAndShowSnackbar(getContext().getString(R.string.translate_snackbar_always_translate,
                                  mOptions.sourceLanguageName(), mOptions.targetLanguageName()),
            Snackbar.UMA_TRANSLATE_ALWAYS, ACTION_AUTO_ALWAYS_TRANSLATE);
}
 
Example #28
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;
}
 
Example #29
Source File: UndoBarController.java    From 365browser with Apache License 2.0 3 votes vote down vote up
/**
 * Shows an undo close all bar. Based on user actions, this will cause a call to either
 * {@link TabModel#commitTabClosure(int)} or {@link TabModel#cancelTabClosure(int)} to be called
 * for each tab in {@code closedTabIds}. This will happen unless
 * {@code SnackbarManager#removeFromStackForData(Object)} is called.
 *
 * @param closedTabs A list of tabs that were closed.
 */
private void showUndoCloseAllBar(List<Tab> closedTabs) {
    String content = String.format(Locale.getDefault(), "%d", closedTabs.size());
    mSnackbarManager.showSnackbar(
            Snackbar.make(content, this, Snackbar.TYPE_ACTION, Snackbar.UMA_TAB_CLOSE_ALL_UNDO)
                    .setTemplateText(mContext.getString(R.string.undo_bar_close_all_message))
                    .setAction(mContext.getString(R.string.undo), closedTabs));
}