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

The following examples show how to use android.support.design.widget.Snackbar#setCallback() . 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: ProfileActivity.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void showSnackBar(String msg, int length, @Nullable String actionText, @Nullable View.OnClickListener onClickListener, @Nullable Snackbar.Callback callback) {
    if(coordinatorLayout() != null){

        Snackbar snackbar = Snackbar.make(coordinatorLayout(), msg, length);

        if(actionText != null && onClickListener != null){
            snackbar.setAction(actionText, onClickListener);
        }

        if(callback != null) {
            snackbar.setCallback(callback);
        }
        //hide the panel before showing the snack bar
        snackbar.show();
    }
}
 
Example 2
Source File: MainActivity.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void showSnackBar(String msg, int length, @Nullable String actionText, @Nullable View.OnClickListener onClickListener, @Nullable Snackbar.Callback callback) {
    if(coordinatorLayout() != null){

        Snackbar snackbar = Snackbar.make(coordinatorLayout(), msg, length);

        if(actionText != null && onClickListener != null){
            snackbar.setAction(actionText, onClickListener);
        }

        if(callback != null) {
            snackbar.setCallback(callback);
        }else{
            snackbar.setCallback(new PanelSnackBarCallback());
        }
        //hide the panel before showing the snack bar
        setPanelHeight(0);
        snackbar.show();
    }
}
 
Example 3
Source File: ThreadActivity.java    From redgram-for-reddit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void showSnackBar(String msg, int length, @Nullable String actionText, @Nullable View.OnClickListener onClickListener, @Nullable Snackbar.Callback callback) {
    if(coordinatorLayout() != null){

        Snackbar snackbar = Snackbar.make(coordinatorLayout(), msg, length);

        if(actionText != null && onClickListener != null){
            snackbar.setAction(actionText, onClickListener);
        }

        if(callback != null) {
            snackbar.setCallback(callback);
        }
        //hide the panel before showing the snack bar
        snackbar.show();
    }
}
 
Example 4
Source File: RecycleBinFragment.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
private void deleteNote(final int position) {
    final NoteAllArray backUp = recycleBinNoteList.get(position);
    final long id = (recycleBinNoteList.get(position)).sdfId;
    recycleBinNoteList.remove(position);
    noteAdapter.notifyDataSetChanged();

    Snackbar snackBar = Snackbar.make(((MainActivity)getActivity()).getFloatingActionButton(),"正在永久删除这条笔记",Snackbar.LENGTH_LONG);
    snackBar.setAction("撤销", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            recycleBinNoteList.add(position,backUp);
            noteAdapter.notifyDataSetChanged();
        }
    });
    snackBar.setCallback(new Snackbar.Callback() {
        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            super.onDismissed(snackbar, event);
            EventBus.getDefault().post(new FadeGoneMainFABEvent());

            if (event == DISMISS_EVENT_SWIPE || event == DISMISS_EVENT_TIMEOUT || event ==
                    DISMISS_EVENT_CONSECUTIVE) {
                RecycleBinController.removeRecycleBinNote(id);
            }

        }
    });
    EventBus.getDefault().post(new FadeVisibleMainFABEvent());
    snackBar.show();
}
 
Example 5
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();
        }

    };
}