Java Code Examples for android.support.design.widget.Snackbar#dismiss()

The following examples show how to use android.support.design.widget.Snackbar#dismiss() . 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: SnackbarBuilderTest.java    From SnackbarBuilder with Apache License 2.0 6 votes vote down vote up
@Test
public void givenCallback_whenBuild_thenCallbackSet() {
  RuntimeEnvironment.application.setTheme(R.style.TestSnackbarBuilder_AppTheme);
  CoordinatorLayout parent = new CoordinatorLayout(RuntimeEnvironment.application);

  Snackbar snackbar = new SnackbarBuilder(parent)
      .message("message")
      .actionText("action")
      .duration(Snackbar.LENGTH_SHORT)
      .callback(callback)
      .build();
  snackbar.show();

  snackbar.dismiss();
  verify(callback).onDismissed(snackbar, Callback.DISMISS_EVENT_MANUAL);
}
 
Example 2
Source File: SnackbarBuilderTest.java    From SnackbarBuilder with Apache License 2.0 6 votes vote down vote up
@Test
public void givenSnackbarCallback_whenBuild_thenSnackbarCallbackSet() {
  RuntimeEnvironment.application.setTheme(R.style.TestSnackbarBuilder_AppTheme);
  CoordinatorLayout parent = new CoordinatorLayout(RuntimeEnvironment.application);

  Snackbar snackbar = new SnackbarBuilder(parent)
      .message("message")
      .actionText("action")
      .duration(Snackbar.LENGTH_SHORT)
      .snackbarCallback(snackbarCallback)
      .build();
  snackbar.show();

  snackbar.dismiss();
  verify(snackbarCallback).onSnackbarManuallyDismissed(snackbar);
}
 
Example 3
Source File: SnackbarManager.java    From pandroid with Apache License 2.0 4 votes vote down vote up
private ToastNotifier makeCustomNotification(Activity activity, ToastType toastType, String label, String btnLabel, int drawableRes, int style, int duration, boolean undefinedLoad, final ToastListener listener) {
    if (duration < 0)
        duration = Snackbar.LENGTH_INDEFINITE;
    final Snackbar notif = Snackbar.make(activity.findViewById(android.R.id.content), label, duration);
    if (style == 0) {
        style = R.style.Toast;
    }
    TypedArray attributes = activity.obtainStyledAttributes(style, R.styleable.ToastAppearance);
    int textColor = attributes.getColor(R.styleable.ToastAppearance_toastTextColor, ContextCompat.getColor(activity, R.color.white));
    int buttonTextColor = attributes.getColor(R.styleable.ToastAppearance_toastButtonTextColor, ContextCompat.getColor(activity, R.color.pandroid_green_dark));
    int backgroundColor = attributes.getColor(R.styleable.ToastAppearance_toastBackground, ContextCompat.getColor(activity, R.color.pandroid_green));
    notif.getView().setBackgroundColor(backgroundColor);
    ((TextView) notif.getView().findViewById(android.support.design.R.id.snackbar_text)).setTextColor(textColor);
    TextView actionView = ((TextView) notif.getView().findViewById(android.support.design.R.id.snackbar_action));
    actionView.setTextColor(buttonTextColor);
    attributes.recycle();

    notif.setCallback(new Snackbar.Callback() {
        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            super.onDismissed(snackbar, event);
            if (listener != null)
                listener.onDismiss();
        }
    });

    Drawable drawable = null;
    if (drawableRes > 0) {
        drawable = ContextCompat.getDrawable(activity, drawableRes);
    }
    actionView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, drawable, null);
    if (toastType == ToastType.ACTION && btnLabel != null) {
        notif.setAction(btnLabel, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null)
                    listener.onActionClicked();
            }
        });
    } else if (drawableRes > 0) {
        actionView.setVisibility(View.VISIBLE);
        actionView.setClickable(false);
        actionView.setFocusableInTouchMode(false);
        actionView.setFocusable(false);
        actionView.setEnabled(false);
    }

    if (toastType == ToastType.LOADER) {
        ProgressWheel progressWheel = new ProgressWheel(activity);
        progressWheel.setId(R.id.snakebar_loader);
        if (undefinedLoad)
            progressWheel.spin();

        progressWheel.setBarWidth((int) DeviceUtils.dpToPx(activity, 4));
        progressWheel.setCircleRadius((int) DeviceUtils.dpToPx(activity, 30));
        progressWheel.setBarColor(buttonTextColor);
        progressWheel.setLinearProgress(true);
        ((Snackbar.SnackbarLayout) notif.getView()).addView(progressWheel, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }
    notif.show();
    lastShowNotif = notif;
    return new ToastNotifier() {
        @Override
        public void setProgress(int progress) {
            ProgressWheel loader = (ProgressWheel) notif.getView().findViewById(R.id.snakebar_loader);
            if (loader != null) {
                loader.setProgress(progress / 100f);
            }
        }

        @Override
        public void dismiss() {
            notif.dismiss();
        }

    };
}
 
Example 4
Source File: ItemAdapter.java    From RecyclerViewUndoSwipe with Apache License 2.0 4 votes vote down vote up
@Override
public void onItemDismiss(final int position) {

    final Item item =new Item();
    item.setItemName(itemList.get(position).getItemName());

    notifyItemRemoved(position);
    itemList.remove(position);
    notifyItemRangeChanged(0, getItemCount());
    tvNumber.setText(String.valueOf(itemList.size()));

    final Snackbar snackbar =  Snackbar

            .make(tvNumber,context.getResources().getString(R.string.item_deleted), Snackbar.LENGTH_LONG)
            .setActionTextColor(ContextCompat.getColor(context, R.color.white))
            .setAction(context.getResources().getString(R.string.item_undo), new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                   itemList.add(position, item);
                    notifyItemInserted(position);
                    tvNumber.setText(String.valueOf(itemList.size()));

                }
            });


    View snackBarView = snackbar.getView();
    snackBarView.setBackgroundColor(ContextCompat.getColor(context, R.color.colorAccent));
    TextView tvSnack = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_text);
    TextView tvSnackAction = (TextView) snackbar.getView().findViewById( android.support.design.R.id.snackbar_action );
    tvSnack.setTextColor(Color.WHITE);
    tvSnack.setTypeface(Typefaces.getRobotoMedium(context));
    tvSnackAction.setTypeface(Typefaces.getRobotoMedium(context));
    snackbar.show();


   Runnable runnableUndo = new Runnable() {

        @Override
        public void run() {
            tvNumber.setText(String.valueOf(itemList.size()));
            snackbar.dismiss();
        }
    };
    Handler handlerUndo=new Handler();handlerUndo.postDelayed(runnableUndo,2500);
}