Java Code Examples for com.google.android.material.snackbar.Snackbar#getDuration()

The following examples show how to use com.google.android.material.snackbar.Snackbar#getDuration() . 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: 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 2
Source File: DeletedLabel.java    From science-journal with Apache License 2.0 4 votes vote down vote up
public void deleteAndDisplayUndoBar(
    View view,
    AppAccount appAccount,
    final Experiment experiment,
    LabelListHolder labelHolder,
    Runnable uiChangeOnUndo) {
  Context context = view.getContext();
  final DataController dc = AppSingleton.getInstance(context).getDataController(appAccount);
  Snackbar bar =
      AccessibilityUtils.makeSnackbar(
          view, context.getResources().getString(R.string.snackbar_note_deleted), UNDO_DELAY_MS);

  RxEvent undoneEvent = new RxEvent();

  // On undo, re-add the item to the database and the pinned note list.
  bar.setAction(
      R.string.snackbar_undo,
      new View.OnClickListener() {
        boolean undone = false;

        @Override
        public void onClick(View v) {
          if (this.undone) {
            return;
          }
          undoneEvent.onHappened();
          this.undone = true;
          labelHolder.addLabel(experiment, label);

          dc.updateExperiment(
              experiment.getExperimentId(),
              new LoggingConsumer<Success>(TAG, "re-add deleted label") {
                @Override
                public void success(Success value) {
                  uiChangeOnUndo.run();
                }
              });
        }
      });
  bar.show();

  // Add just a bit of extra time to be sure
  long delayWithBuffer = (long) (bar.getDuration() * 1.1);

  Context appContext = view.getContext().getApplicationContext();
  Observable.timer(delayWithBuffer, TimeUnit.MILLISECONDS)
      .takeUntil(undoneEvent.happens())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(o -> assetDeleter.accept(appContext));
}