Java Code Examples for com.google.android.material.snackbar.Snackbar#make()
The following examples show how to use
com.google.android.material.snackbar.Snackbar#make() .
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: ConversationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void showAudioRecordingDialog() { if (Utils.hasMarshmallow() && PermissionsUtils.checkSelfPermissionForAudioRecording(this)) { new ApplozicPermissions(this, layout).requestAudio(); } else if (PermissionsUtils.isAudioRecordingPermissionGranted(this)) { FragmentManager supportFragmentManager = getSupportFragmentManager(); DialogFragment fragment = AudioMessageFragment.newInstance(); FragmentTransaction fragmentTransaction = supportFragmentManager .beginTransaction().add(fragment, "AudioMessageFragment"); fragmentTransaction.addToBackStack(null); fragmentTransaction.commitAllowingStateLoss(); } else { if (alCustomizationSettings.getAudioPermissionNotFoundMsg() == null) { showSnackBar(R.string.applozic_audio_permission_missing); } else { snackbar = Snackbar.make(layout, alCustomizationSettings.getAudioPermissionNotFoundMsg(), Snackbar.LENGTH_SHORT); snackbar.show(); } } }
Example 2
Source File: ThreadDetailFragment.java From mimi-reader with Apache License 2.0 | 6 votes |
private void showPostStatus(final String status, final String html) { if (getActivity() != null) { final View v = getActivity().findViewById(android.R.id.content); if (postingSnackbar != null && postingSnackbar.isShown()) { postingSnackbar.dismiss(); } Snackbar snackbar = Snackbar.make(v, status, Snackbar.LENGTH_LONG); if (!TextUtils.isEmpty(html)) { snackbar.setAction(R.string.view, view -> WebActivity .start(getActivity(), html)) .setActionTextColor(ResourcesCompat.getColor(getResources(), R.color.md_green_400, getActivity().getTheme())); } snackbar.show(); } }
Example 3
Source File: ErrorStatsDialogFragment.java From Hentoid with Apache License 2.0 | 6 votes |
private LogUtil.LogInfo createLog() { CollectionDAO dao = new ObjectBoxDAO(getContext()); Content content = dao.selectContent(currentId); if (null == content) { Snackbar snackbar = Snackbar.make(rootView, R.string.content_not_found, BaseTransientBottomBar.LENGTH_LONG); snackbar.show(); return new LogUtil.LogInfo(); } List<LogUtil.LogEntry> log = new ArrayList<>(); LogUtil.LogInfo errorLogInfo = new LogUtil.LogInfo(); errorLogInfo.setLogName("Error"); errorLogInfo.setFileName("error_log" + content.getId()); errorLogInfo.setNoDataMessage("No error detected."); errorLogInfo.setLog(log); List<ErrorRecord> errorLog = content.getErrorLog(); if (errorLog != null) { errorLogInfo.setHeader("Error log for " + content.getTitle() + " [" + content.getUniqueSiteId() + "@" + content.getSite().getDescription() + "] : " + errorLog.size() + " errors"); for (ErrorRecord e : errorLog) log.add(new LogUtil.LogEntry(e.getTimestamp(), e.toString())); } return errorLogInfo; }
Example 4
Source File: UndoHelper.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
/** * Performs the action on the specified positions and displays a SnackBar to Undo * the operation. To customize the UPDATE event, please set a custom listener with * {@link #withAction(int)} method. * <p>By default the DELETE action will be performed.</p> * * @param positions the position to delete or update * @param mainView the view to find a parent from * @param message the text to show. Can be formatted text * @param actionText the action text to display * @param duration How long to display the message. Either {@link Snackbar#LENGTH_SHORT} or * {@link Snackbar#LENGTH_LONG} or any custom Integer. * @return The SnackBar instance * @see #start(List, View, int, int, int) */ @SuppressWarnings("WrongConstant") public Snackbar start(List<Integer> positions, @NonNull View mainView, CharSequence message, CharSequence actionText, @IntRange(from = -1) int duration) { Log.d("With %s", (mAction == Action.REMOVE ? "ACTION_REMOVE" : "ACTION_UPDATE")); this.mPositions = positions; if (!mAdapter.isPermanentDelete()) { mSnackbar = Snackbar.make(mainView, message, duration > 0 ? duration + 400 : duration) .setAction(actionText, new View.OnClickListener() { @Override public void onClick(View view) { if (mUndoListener != null) { Log.v("onActionCanceled event=1"); mUndoListener.onActionCanceled(mAction, mAdapter.getUndoPositions()); mAdapter.emptyBin(); } } }); if (mActionTextColor != Color.TRANSPARENT) { mSnackbar.setActionTextColor(mActionTextColor); } } else { mSnackbar = Snackbar.make(mainView, message, duration); } mSnackbar.addCallback(this); mSnackbar.show(); // Note: show is asynchronous! // Early perform action and eventually clear previous action performAction(); return mSnackbar; }
Example 5
Source File: MobicomLocationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void showSnackBar(int resId) { try { snackbar = Snackbar.make(layout, resId, Snackbar.LENGTH_SHORT); snackbar.show(); } catch (Exception e) { e.printStackTrace(); } }
Example 6
Source File: WalletFragment.java From zap-android with MIT License | 5 votes |
private void showError(String message, int duration) { Snackbar msg = Snackbar.make(getActivity().findViewById(R.id.mainContent), message, Snackbar.LENGTH_LONG); View sbView = msg.getView(); sbView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.superRed)); msg.setDuration(duration); msg.show(); }
Example 7
Source File: NotificationHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
public static void showSnackbar(@NonNull MysplashActivity activity, String content) { View container = activity.provideSnackbarContainer(); if (container != null) { Snackbar snackbar = Snackbar.make(container, content, Snackbar.LENGTH_SHORT); Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView(); snackbarLayout.setBackgroundColor(ThemeManager.getRootColor(activity)); TextView contentTxt = snackbarLayout.findViewById(R.id.snackbar_text); contentTxt.setTextColor(ThemeManager.getContentColor(activity)); snackbar.show(); } }
Example 8
Source File: BaseAppCompatActivity.java From zap-android with MIT License | 5 votes |
protected void showError(String message, int duration) { Snackbar msg = Snackbar.make(findViewById(android.R.id.content), message, Snackbar.LENGTH_LONG); View sbView = msg.getView(); sbView.setBackgroundColor(ContextCompat.getColor(this, R.color.superRed)); msg.setDuration(duration); msg.show(); }
Example 9
Source File: SnackbarHelper.java From XposedSmsCode with GNU General Public License v3.0 | 5 votes |
@NonNull private static Snackbar make(@NonNull View view, @NonNull CharSequence text, int duration) { // View snackView = snackbar.getView(); // TypedValue typedValue = new TypedValue(); // Context context = view.getContext(); // context.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); // @ColorInt int colorPrimary = typedValue.data; // colorPrimary = ColorUtils.gradientColor(colorPrimary, 1.2f); // snackView.setBackgroundColor(colorPrimary); return Snackbar.make(view, text, duration); }
Example 10
Source File: IndieAuthActivity.java From indigenous-android with GNU General Public License v3.0 | 5 votes |
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (Intent.ACTION_VIEW.equals(intent.getAction())) { Snackbar.make(layout, getString(R.string.validating_code), Snackbar.LENGTH_SHORT).show(); // Get the code and state. String code = intent.getData().getQueryParameter("code"); String returnedState = intent.getData().getQueryParameter("state"); if (code != null && code.length() > 0 && returnedState != null && returnedState.length() > 0) { validateCode(code, returnedState); } else { final Snackbar snack = Snackbar.make(layout, getString(R.string.no_code_found), Snackbar.LENGTH_INDEFINITE); snack.setAction(getString(R.string.close), new View.OnClickListener() { @Override public void onClick(View v) { snack.dismiss(); } } ); snack.show(); } } }
Example 11
Source File: ContributorsFragment.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
private void error() { if (isAdded()) { hideProgress(); mErrorBar = Snackbar.make(getRootView(), R.string.no_internet, Snackbar.LENGTH_INDEFINITE); mErrorBar.show(); } }
Example 12
Source File: SnackbarUtil.java From weather with Apache License 2.0 | 5 votes |
/** * Show the snackbar. */ public Snackbar show() { final View view = this.view; if (view == null) return null; if (messageColor != COLOR_DEFAULT) { SpannableString spannableString = new SpannableString(message); ForegroundColorSpan colorSpan = new ForegroundColorSpan(messageColor); spannableString.setSpan( colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ); sReference = new WeakReference<>(Snackbar.make(view, spannableString, duration)); } else { sReference = new WeakReference<>(Snackbar.make(view, message, duration)); } final Snackbar snackbar = sReference.get(); final View snackbarView = snackbar.getView(); if (bgResource != -1) { snackbarView.setBackgroundResource(bgResource); } else if (bgColor != COLOR_DEFAULT) { snackbarView.setBackgroundColor(bgColor); } if (bottomMargin != 0) { ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) snackbarView.getLayoutParams(); params.bottomMargin = bottomMargin; } if (actionText.length() > 0 && actionListener != null) { if (actionTextColor != COLOR_DEFAULT) { snackbar.setActionTextColor(actionTextColor); } snackbar.setAction(actionText, actionListener); } snackbar.show(); return snackbar; }
Example 13
Source File: SnackbarHelper.java From SmsCode with GNU General Public License v3.0 | 5 votes |
@NonNull private static Snackbar make(@NonNull View view, @NonNull CharSequence text, int duration) { // View snackView = snackbar.getView(); // TypedValue typedValue = new TypedValue(); // Context context = view.getContext(); // context.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); // @ColorInt int colorPrimary = typedValue.data; // colorPrimary = ColorUtils.gradientColor(colorPrimary, 1.2f); // snackView.setBackgroundColor(colorPrimary); return Snackbar.make(view, text, duration); }
Example 14
Source File: UpdateManager.java From InAppUpdater with MIT License | 5 votes |
private void popupSnackbarForCompleteUpdate() { Snackbar snackbar = Snackbar.make( getActivity().getWindow().getDecorView().findViewById(android.R.id.content), "An update has just been downloaded.", Snackbar.LENGTH_INDEFINITE); snackbar.setAction("RESTART", new View.OnClickListener() { @Override public void onClick(View v) { appUpdateManager.completeUpdate(); } }); snackbar.show(); }
Example 15
Source File: SnackbarErrorNotification.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Show the error notification as a persistent Snackbar, according to the provided details. * * @param errorResId The resource ID of the error message. * @param icon The error icon. This is ignored here, since Snackbar doesn't really support * icons. * @param actionTextResId The resource ID of the action button text. * @param actionListener The callback to be invoked when the action button is clicked. */ @Override public void showError(@StringRes final int errorResId, @Nullable final Icon icon, @StringRes final int actionTextResId, @Nullable final View.OnClickListener actionListener) { if (snackbar == null) { snackbar = Snackbar.make(view, errorResId, LENGTH_INDEFINITE); if (actionTextResId != 0) { // SnackBar automatically dimisses when the action item is pressed. // This workaround has been implemented to by pass that behaviour. snackbar.setAction(actionTextResId, new View.OnClickListener() { @Override public void onClick(View v) { } }); } snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { super.onDismissed(transientBottomBar, event); snackbar = null; } }); // By applying the listener to the button like we have done below, the Snackbar // doesn't automatically dismiss and we have to manually dismiss it. final Button actionButton = (Button) snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_action); actionButton.setOnClickListener(actionListener); snackbar.show(); } }
Example 16
Source File: SendActivity.java From Lunary-Ethereum-Wallet with GNU General Public License v3.0 | 4 votes |
public void snackError(String s, int length) { if (coord == null) return; Snackbar mySnackbar = Snackbar.make(coord, s, length); mySnackbar.show(); }
Example 17
Source File: ConversationActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void showSnackBar(int resId) { snackbar = Snackbar.make(layout, resId, Snackbar.LENGTH_SHORT); snackbar.show(); }
Example 18
Source File: DataSetSectionFragment.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void showSnackBar() { Snackbar mySnackbar = Snackbar.make(binding.getRoot(), R.string.datavalue_saved, Snackbar.LENGTH_SHORT); mySnackbar.show(); }
Example 19
Source File: ShowMessage.java From aptoide-client-v8 with GNU General Public License v3.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @NonNull private static Snackbar asSnackInternal(android.app.Fragment fragment, @StringRes int msg) { return Snackbar.make(fragment.getView(), msg, Snackbar.LENGTH_SHORT); }
Example 20
Source File: ChannelNameActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void showSnackBar(int resId) { snackbar = Snackbar.make(layout, resId, Snackbar.LENGTH_SHORT); snackbar.show(); }