Java Code Examples for com.google.android.material.snackbar.Snackbar#Duration

The following examples show how to use com.google.android.material.snackbar.Snackbar#Duration . 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: DynamicHintUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Make a themed snack bar with text and action.
 *
 * @param view The view to show the snack bar.
 * @param text The text to show. Can be formatted text.
 * @param backgroundColor The snack bar background color.
 * @param tintColor The snack bar tint color based on the background. It will automatically
 *                  check for the contrast to provide bes visibility.
 * @param duration The duration of the snack bar.
 *                 <p>Can be {@link Snackbar#LENGTH_SHORT}, {@link Snackbar#LENGTH_LONG}
 *                 or {@link Snackbar#LENGTH_INDEFINITE}.
 *
 * @return The snack bar with the supplied parameters.
 *         <p>Use {@link Snackbar#show()} to display the snack bar.
 */
public static @NonNull Snackbar getSnackBar(@NonNull View view,
        @NonNull CharSequence text, @ColorInt int backgroundColor,
        @ColorInt int tintColor, @Snackbar.Duration int duration) {
    if (DynamicTheme.getInstance().get().isBackgroundAware()) {
        backgroundColor = DynamicColorUtils.getContrastColor(backgroundColor,
                DynamicTheme.getInstance().get().getBackgroundColor());
        tintColor = DynamicColorUtils.getContrastColor(tintColor, backgroundColor);
    }

    Snackbar snackbar = Snackbar.make(view, text, duration);
    DynamicDrawableUtils.setBackground(snackbar.getView(),
            DynamicDrawableUtils.getCornerDrawable(DynamicTheme.getInstance()
                    .get().getCornerSizeDp(), backgroundColor));
    ((TextView) snackbar.getView().findViewById(
            R.id.snackbar_text)).setTextColor(tintColor);
    ((TextView) snackbar.getView().findViewById(
            R.id.snackbar_text)).setMaxLines(Integer.MAX_VALUE);
    snackbar.setActionTextColor(tintColor);

    return snackbar;
}
 
Example 2
Source File: AccessibilityUtils.java    From science-journal with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the toast duration unless accessibility touch mode is enabled, in which case it returns
 * a longer duration (90 seconds).
 */
public static @Snackbar.Duration int getLongerToastDurationIfAccessibilityEnabled(
    Context context, Snackbar bar) {
  if (isAccessibilityManagerEnabled(context)) {
    return SNACKBAR_TIMEOUT_EXTRA_LONG;
  }
  return bar.getDuration();
}
 
Example 3
Source File: DynamicActivity.java    From dynamic-support with Apache License 2.0 3 votes vote down vote up
/**
 * Make a themed snack bar with text and action. Background will be the tint background color
 * to blend it smoothly and it will automatically use its tint color for the text and action
 * to provide best visibility.
 *
 * @param text The text to show. Can be formatted text.
 * @param duration The duration of the snack bar.
 *                 <p>{@link Snackbar#LENGTH_SHORT}, {@link Snackbar#LENGTH_LONG}
 *                 or {@link Snackbar#LENGTH_INDEFINITE}.
 *
 * @return The snack bar with the supplied parameters.
 *         <p>Use {@link Snackbar#show()} to display the snack bar.
 */
public @NonNull Snackbar getSnackBar(@NonNull CharSequence text,
        @Snackbar.Duration int duration) {
    return DynamicHintUtils.getSnackBar(mCoordinatorLayout, text,
            DynamicTheme.getInstance().get().getTintBackgroundColor(),
            DynamicTheme.getInstance().get().getBackgroundColor(), duration);
}
 
Example 4
Source File: DynamicHintUtils.java    From dynamic-support with Apache License 2.0 2 votes vote down vote up
/**
 * Make a themed snack bar with text and action. Background will be primary color from the
 * theme and it will automatically use its tint color for the text and action to provide
 * best visibility.
 *
 * @param view The view to show the snack bar.
 * @param text The text to show. Can be formatted text.
 * @param duration The duration of the snack bar.
 *                 <p>Can be {@link Snackbar#LENGTH_SHORT}, {@link Snackbar#LENGTH_LONG}
 *                 or {@link Snackbar#LENGTH_INDEFINITE}.
 *
 * @return The snack bar with the supplied parameters.
 *         <p>Use {@link Snackbar#show()} to display the snack bar.
 */
public static @NonNull Snackbar getSnackBar(@NonNull View view,
        @NonNull CharSequence text, @Snackbar.Duration int duration) {
    return getSnackBar(view, text, DynamicTheme.getInstance().get().getPrimaryColor(),
            DynamicTheme.getInstance().get().getTintPrimaryColor(), duration);
}
 
Example 5
Source File: DynamicActivity.java    From dynamic-support with Apache License 2.0 2 votes vote down vote up
/**
 * Make a themed snack bar with text and action. Background will be the tint background color
 * to blend it smoothly and it will automatically use its tint color for the text and action
 * to provide best visibility.
 *
 * @param stringRes The string resource for the snack bar.
 * @param duration The duration of the snack bar.
 *                 <p>{@link Snackbar#LENGTH_SHORT}, {@link Snackbar#LENGTH_LONG}
 *                 or {@link Snackbar#LENGTH_INDEFINITE}.
 *
 * @return The snack bar with the supplied parameters.
 *         <p>Use {@link Snackbar#show()} to display the snack bar.
 */
public @NonNull Snackbar getSnackBar(@StringRes int stringRes,
        @Snackbar.Duration int duration) {
    return getSnackBar(getString(stringRes), duration);
}