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

The following examples show how to use android.support.design.widget.Snackbar#setAction() . 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: ClientDetailActivity.java    From faveo-helpdesk-android-app with Open Software License 3.0 6 votes vote down vote up
/**
 * Display the snackbar if network connection is not there.
 *
 * @param isConnected is a boolean value of network connection.
 */
private void showSnackIfNoInternet(boolean isConnected) {
    if (!isConnected) {
        final Snackbar snackbar = Snackbar
                .make(findViewById(android.R.id.content), R.string.sry_not_connected_to_internet, Snackbar.LENGTH_INDEFINITE);

        View sbView = snackbar.getView();
        TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setTextColor(Color.RED);
        snackbar.setAction("X", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.show();
    }

}
 
Example 2
Source File: AgentWebX5Utils.java    From AgentWebX5 with Apache License 2.0 6 votes vote down vote up
public static void show(View parent,
                        CharSequence text,
                        int duration,
                        @ColorInt int textColor,
                        @ColorInt int bgColor,
                        CharSequence actionText,
                        @ColorInt int actionTextColor,
                        View.OnClickListener listener) {
    SpannableString spannableString = new SpannableString(text);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
    spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
    Snackbar snackbar = snackbarWeakReference.get();
    View view = snackbar.getView();
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbar.setActionTextColor(actionTextColor);
        snackbar.setAction(actionText, listener);
    }
    snackbar.show();

}
 
Example 3
Source File: ContactViewFragment.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showErroredSnackBar(String message){
    if (getView() != null) {
        final Snackbar snackbar = Snackbar.make(getView(), message, ERROR_SNACKBAR_DURATION * 1000);

        snackbar.setAction(getString(R.string.dismiss_button), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.setActionTextColor(getResources().getColor(R.color.brightRedText));

        View snackbarView = snackbar.getView();
        TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setMaxLines(5);

        snackbar.show();
    }
}
 
Example 4
Source File: AgentWebUtils.java    From AgentWeb with Apache License 2.0 6 votes vote down vote up
static void show(View parent,
                 CharSequence text,
                 int duration,
                 @ColorInt int textColor,
                 @ColorInt int bgColor,
                 CharSequence actionText,
                 @ColorInt int actionTextColor,
                 View.OnClickListener listener) {
	SpannableString spannableString = new SpannableString(text);
	ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
	spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
	Snackbar snackbar = snackbarWeakReference.get();
	View view = snackbar.getView();
	view.setBackgroundColor(bgColor);
	if (actionText != null && actionText.length() > 0 && listener != null) {
		snackbar.setActionTextColor(actionTextColor);
		snackbar.setAction(actionText, listener);
	}
	snackbar.show();
}
 
Example 5
Source File: ForgotPasswordActivity.java    From faveo-helpdesk-android-app with Open Software License 3.0 6 votes vote down vote up
private void showSnackIfNoInternet(boolean isConnected) {
    if (!isConnected) {
        final Snackbar snackbar = Snackbar
                .make(findViewById(android.R.id.content), "Sorry! Not connected to internet", Snackbar.LENGTH_INDEFINITE);

        View sbView = snackbar.getView();
        TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
        textView.setTextColor(Color.RED);
        snackbar.setAction("X", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.show();
    }

}
 
Example 6
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 7
Source File: MainActivity.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_STORAGE) {
        for (int i = 0; i < permissions.length; i++) {
            if (Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[i])) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    bindCaptureService();
                } else {
                    Snackbar snackbar = Snackbar.make(getWindow().getDecorView(), "需要允许读写SD卡的权限!", Snackbar.LENGTH_INDEFINITE);
                    snackbar.setAction("去设置", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            intent.setData(Uri.parse("package:"+getPackageName()));
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            finish();
                        }
                    });
                    snackbar.show();
                }
            }
        }
    }
}
 
Example 8
Source File: SightActivity.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
private void updateSnackbar(Status status, long statusTime, long waitTime) {
    if (!snackbarEnabled()) return;
    if (status == Status.CONNECTED) {
        dismissSnackbar();
    } else if (status == Status.CONNECTING) {
        showSnackbar(Snackbar.make(getRootView(), R.string.connecting, Snackbar.LENGTH_INDEFINITE));
    } else if (status == Status.WAITING) {
        double leftOverWaitTime = waitTime - (System.currentTimeMillis() - statusTime);
        int delay = (int) Math.round(leftOverWaitTime / 1000D);
        delay = Math.max(delay, 0);
        Snackbar snackbar = Snackbar.make(getRootView(), getResources().getQuantityString(R.plurals.waiting, delay, delay), Snackbar.LENGTH_INDEFINITE);
        snackbar.setAction(R.string.connect_now, v -> sightServiceConnector.forceConnect());
        showSnackbar(snackbar);
    }
}
 
Example 9
Source File: BrowsingActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void showSnackBarBookNotDownloaded(int bookId) {
    CoordinatorLayout coordinatorLayout = findViewById(R.id.browsing_coordinator_layout);
    Snackbar mySnackbar = Snackbar.make(coordinatorLayout,
            getResources().getString(R.string.book_not_download, mBooksInformationDbHelper.getBookName(bookId)),
            Snackbar.LENGTH_LONG);
    mySnackbar.setAction(R.string.redownload,
            v -> {
                bookCardEventsCallback.startDownloadingBook(mBooksInformationDbHelper.getBookInfo(bookId));
                bookCardEventsCallback.notifyBookDownloadStatusUpdate(bookId, DownloadsConstants.STATUS_DOWNLOAD_REQUESTED);
            }
    );
    mySnackbar.show();
}
 
Example 10
Source File: BaseActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public void showSnackBar(String text, int duration, String action, int actionColor){
    final Snackbar snackbar = Snackbar.make(findViewById(R.id.content_view), text, duration);
    snackbar.setAction(action, new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();
        }
    });
    snackbar.setActionTextColor(actionColor).show();
}
 
Example 11
Source File: MainActivity.java    From materialup with Apache License 2.0 5 votes vote down vote up
private void showLoginTips() {
    Snackbar sb = Snackbar.make(mViewPager, R.string.login_tips, Snackbar.LENGTH_INDEFINITE);
    sb.setAction(R.string.login, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Launcher.openLogin(MainActivity.this, LOGIN_CODE);
        }
    });
    sb.show();
}
 
Example 12
Source File: WorkflowFragment.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
@Override
public void showSnackBar(int message) {
    final Snackbar snackbar = Snackbar.make(mRecyclerView, getActivity().getString(message),
            Snackbar.LENGTH_SHORT);
    snackbar.setAction(getActivity().getString(R.string.ok), new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();
        }
    });
    snackbar.show();
}
 
Example 13
Source File: AppFileListFragment.java    From AppPlus with MIT License 5 votes vote down vote up
private void loadingDataEmpty(String emptyInfo) {
    final Snackbar errorSnack = Snackbar.make(mRecyclerView, emptyInfo, Snackbar.LENGTH_LONG);
    errorSnack.setAction(R.string.action_retry, new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            errorSnack.dismiss();
            fillData();
        }
    });
    errorSnack.show();
}
 
Example 14
Source File: MainActivity.java    From weekdays-buttons-bar with MIT License 5 votes vote down vote up
public Snackbar showSnackbar(@NonNull ViewGroup viewGroup, String message, String action, int length, View.OnClickListener onActionListener) {
    Snackbar snackbar = Snackbar.make(viewGroup, message, length);
    if (!TextUtils.isEmpty(action) && onActionListener != null)
        snackbar.setAction(action, onActionListener);
    snackbar.show();
    return snackbar;
}
 
Example 15
Source File: StatusActivity.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onError(Exception e) {
    if (!(e instanceof CancelledException) && !(e instanceof DisconnectedException)) {
        Snackbar snackbar = Snackbar.make(getRootView(), getString(R.string.error, e.getClass().getSimpleName()), Snackbar.LENGTH_INDEFINITE);
        snackbar.setAction(R.string.retry, view -> taskRunnerRunnable.run());
        showSnackbar(snackbar);
    }
}
 
Example 16
Source File: PlayerLoginFragment.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
@Override
public void showError(int stringID) {
    final Snackbar snackbar = Snackbar.make(mEditTextPassword, getString(stringID), Snackbar
            .LENGTH_LONG);
    snackbar.setAction("OK", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();
        }
    });

    snackbar.show();
}
 
Example 17
Source File: AnnouncementFragment.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
@Override
public void showSnackBar(int message) {
    final Snackbar snackbar = make(getActivity().findViewById(android.R.id.content),
            message, Snackbar.LENGTH_LONG);
    snackbar.setAction(getResources().getString(R.string.ok), new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();
        }
    });

    snackbar.show();
}
 
Example 18
Source File: BaseApplication.java    From MarkdownEditors with Apache License 2.0 5 votes vote down vote up
public static Snackbar showSnackbar(@NonNull View view, @NonNull String message, @Snackbar.Duration int duration, @Nullable View.OnClickListener listener, @Nullable String actionStr) {
    Snackbar snackbar = Snackbar.make(view, message, duration);
    if (listener != null && Check.isEmpty(actionStr)) {
        snackbar.setAction(actionStr, listener);
    }
    snackbar.show();
    return snackbar;
}
 
Example 19
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 20
Source File: AppListFragment.java    From AppPlus with MIT License 4 votes vote down vote up
private synchronized void fillData() {
    /**
     * should use mvp
     */
    Observable<List<AppEntity>> listObservable = null;
    switch (mType) {
        case TYPE_RECENT:
            if(Utils.isAndroidN()){
                //Check if permission enabled
                if (UStats.getUsageStatsList(getActivity()).isEmpty()){
                    listObservable = Observable.error(new PermissionException());
                }else{
                    listObservable = DataHelper.getAppList(getActivity());
                }
            }else{
                listObservable = DataHelper.getRunningAppEntity(getActivity());
            }
            break;
        case TYPE_INSTALLED:
            listObservable = DataHelper.getAllEntityByDbAsyn();
            break;
        case TYPE_FAVORITE:
            listObservable = DataHelper.getFavoriteEntityByDbAsyn();
            break;
    }

    if (listObservable == null) return;

    Subscriber<List<AppEntity>> subscriber = new Subscriber<List<AppEntity>>() {
        @Override
        public void onNext(List<AppEntity> appEntities) {
            loadingFinish();
            setData(appEntities, mType);
        }

        @Override
        public void onCompleted() {
            loadingFinish();
        }

        @Override
        public void onError(Throwable throwable) {
            loadingFinish();
            if(throwable instanceof PermissionException){
                final Snackbar errorSnack = Snackbar.make(mRecyclerView, "获取最近运行程序列表失败,请授予 AppPlus 相关权限。", Snackbar.LENGTH_INDEFINITE);
                errorSnack.setAction(R.string.action_grunt, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        errorSnack.dismiss();
                        Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
                        startActivityForResult(intent,GRUNT_RECENT_PREMISSION);
                    }
                });
                errorSnack.show();
            }else{
                throwable.printStackTrace();
            }

        }
    };

    listObservable
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(subscriber);

}