Java Code Examples for com.google.android.material.snackbar.Snackbar#show()
The following examples show how to use
com.google.android.material.snackbar.Snackbar#show() .
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: OdysseyMainActivity.java From odyssey with GNU General Public License v3.0 | 6 votes |
@Override public void onStartSleepTimer(final long durationMS, final boolean stopAfterCurrent) { try { // save used duration to initialize the duration picker next time with this value SharedPreferences.Editor sharedPrefEditor = PreferenceManager.getDefaultSharedPreferences(this).edit(); sharedPrefEditor.putLong(getString(R.string.pref_last_used_sleep_timer_key), durationMS); sharedPrefEditor.putBoolean(getString(R.string.pref_last_used_sleep_timer_stop_after_current_key), stopAfterCurrent); sharedPrefEditor.apply(); getPlaybackService().startSleepTimer(durationMS, stopAfterCurrent); // show a snackbar to inform the user that the sleep timer is now set View layout = findViewById(R.id.drawer_layout); if (layout != null) { Snackbar sb = Snackbar.make(layout, R.string.snackbar_sleep_timer_confirmation_message, Snackbar.LENGTH_SHORT); // style the snackbar text TextView sbText = sb.getView().findViewById(com.google.android.material.R.id.snackbar_text); sbText.setTextColor(ThemeUtils.getThemeColor(this, R.attr.odyssey_color_text_accent)); sb.show(); } } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example 2
Source File: ComicFragment.java From Easy_xkcd with Apache License 2.0 | 6 votes |
protected boolean setAltText(boolean fromMenu) { //If the user selected the menu item for the first time, show the toast if (fromMenu && prefHelper.showAltTip()) { Snackbar snackbar = Snackbar.make(requireActivity().findViewById(android.R.id.content), R.string.action_alt_tip, BaseTransientBottomBar.LENGTH_LONG); snackbar.setAction(R.string.got_it, view -> prefHelper.setShowAltTip(false)); snackbar.show(); } //Show alt text int index; if (this instanceof FavoritesFragment) index = favoriteIndex; else index = lastComicNumber - 1; TextView tvAlt = (TextView) pager.findViewWithTag(index).findViewById(R.id.tvAlt); if (prefHelper.classicAltStyle()) { toggleVisibility(tvAlt); } else { //androidx.appcompat.app.AlertDialog.Builder dialog = new androidx.appcompat.app.AlertDialog.Builder(getActivity()); //dialog.setMessage(tvAlt.getText()); //dialog.show(); //ImmersiveDialogFragment.getInstance(String.valueOf(tvAlt.getText())).showImmersive(((MainActivity) getActivity())); ImmersiveDialogFragment.getInstance(String.valueOf(tvAlt.getText())).showImmersive(getMainActivity()); } return true; }
Example 3
Source File: MainActivity.java From arcgis-runtime-samples-android with Apache License 2.0 | 6 votes |
/** * Called if sketch is invalid. Reports to user why the sketch was invalid. */ private void reportNotValid() { String validIf; if (mSketchEditor.getSketchCreationMode() == SketchCreationMode.POINT) { validIf = "Point only valid if it contains an x & y coordinate."; } else if (mSketchEditor.getSketchCreationMode() == SketchCreationMode.MULTIPOINT) { validIf = "Multipoint only valid if it contains at least one vertex."; } else if (mSketchEditor.getSketchCreationMode() == SketchCreationMode.POLYLINE || mSketchEditor.getSketchCreationMode() == SketchCreationMode.FREEHAND_LINE) { validIf = "Polyline only valid if it contains at least one part of 2 or more vertices."; } else if (mSketchEditor.getSketchCreationMode() == SketchCreationMode.POLYGON || mSketchEditor.getSketchCreationMode() == SketchCreationMode.FREEHAND_POLYGON) { validIf = "Polygon only valid if it contains at least one part of 3 or more vertices which form a closed ring."; } else { validIf = "No sketch creation mode selected."; } String report = "Sketch geometry invalid:\n" + validIf; Snackbar reportSnackbar = Snackbar.make(findViewById(R.id.toolbarInclude), report, Snackbar.LENGTH_INDEFINITE); reportSnackbar.setAction("Dismiss", view -> reportSnackbar.dismiss()); TextView snackbarTextView = reportSnackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text); snackbarTextView.setSingleLine(false); reportSnackbar.show(); Log.e(TAG, report); }
Example 4
Source File: RuleListFragment.java From SmsCode with GNU General Public License v3.0 | 6 votes |
private void removeItemAt(final int position) { final SmsCodeRule itemToRemove = mRuleAdapter.getItem(position); if (itemToRemove == null) { return; } mRuleAdapter.removeItemAt(position); Snackbar snackbar = SnackbarHelper.makeLong(mRecyclerView, R.string.removed); snackbar.addCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { if (event != DISMISS_EVENT_ACTION) { try { DBManager.get(mActivity).removeSmsCodeRule(itemToRemove); } catch (Exception e) { XLog.e("Remove " + itemToRemove.toString() + " failed", e); } } } }); snackbar.setAction(R.string.revoke, v -> mRuleAdapter.addRule(position, itemToRemove)); snackbar.show(); }
Example 5
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 6
Source File: ExportOptionsDialogFragment.java From science-journal with Apache License 2.0 | 6 votes |
private void updateProgress(ExportProgress progress) { progressBar.setVisibility( progress.getState() == ExportProgress.EXPORTING ? View.VISIBLE : View.INVISIBLE); exportButton.setEnabled(progress.getState() != ExportProgress.EXPORTING); if (progress.getState() == ExportProgress.EXPORTING) { progressBar.setProgress(progress.getProgress()); } else if (progress.getState() == ExportProgress.EXPORT_COMPLETE) { // Finish dialog and send the filename. if (getActivity() != null) { if (saveLocally) { requestDownload(progress); } else { requestExport(progress); } } } else if (progress.getState() == ExportProgress.ERROR) { if (getActivity() != null) { Snackbar bar = AccessibilityUtils.makeSnackbar( getView(), getString(R.string.export_error), Snackbar.LENGTH_LONG); bar.show(); } } }
Example 7
Source File: NotificationHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
public static void showActionSnackbar(@NonNull MysplashActivity activity, String content, String action, View.OnClickListener l) { View container = activity.provideSnackbarContainer(); if (container != null) { Snackbar snackbar = Snackbar .make(container, content, Snackbar.LENGTH_LONG) .setAction(action, l); 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)); Button actionBtn = snackbarLayout.findViewById(R.id.snackbar_action); actionBtn.setTextColor(ThemeManager.getTitleColor(activity)); snackbar.show(); } }
Example 8
Source File: SettingsNotificationsActivity.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { View containerView = findViewById(R.id.container_settings_notifications); if (containerView != null && !settings.isLoggedIn()) { Snackbar snackbar = Snackbar.make(containerView, getString(R.string.notifications_not_logged_in), Snackbar.LENGTH_LONG); snackbar.show(); } } }
Example 9
Source File: SendActivity.java From Lunary-Ethereum-Wallet with GNU General Public License v3.0 | 5 votes |
public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == QRScanActivity.REQUEST_CODE) { if (resultCode == RESULT_OK) { if (fragments == null || fragments[0] == null) return; ((FragmentChooseRecipient) fragments[0]).setRecipientAddress(data.getStringExtra("ADDRESS")); } else { Snackbar mySnackbar = Snackbar.make(coord, this.getResources().getString(R.string.main_ac_wallet_added_fatal), Snackbar.LENGTH_SHORT); mySnackbar.show(); } } }
Example 10
Source File: MessagesActivity.java From android with MIT License | 5 votes |
private void showDeletionSnackbar() { View view = swipeRefreshLayout; Snackbar snackbar = Snackbar.make(view, R.string.snackbar_deleted, Snackbar.LENGTH_LONG); snackbar.setAction(R.string.snackbar_undo, v -> undoDelete()); snackbar.addCallback(new SnackbarCallback()); snackbar.show(); }
Example 11
Source File: MainActivity.java From EhViewer with Apache License 2.0 | 5 votes |
private void checkClipboardUrlInternal() { String text = getTextFromClipboard(); int hashCode = text != null ? text.hashCode() : 0; if (text != null && hashCode != 0 && Settings.getClipboardTextHashCode() != hashCode) { Announcer announcer = createAnnouncerFromClipboardUrl(text); if (announcer != null && mDrawerLayout != null) { Snackbar snackbar = Snackbar.make(mDrawerLayout, R.string.clipboard_gallery_url_snack_message, Snackbar.LENGTH_INDEFINITE); snackbar.setAction(R.string.clipboard_gallery_url_snack_action, v -> startScene(announcer)); snackbar.show(); } } Settings.putClipboardTextHashCode(hashCode); }
Example 12
Source File: ErrorsFragment.java From Hentoid with Apache License 2.0 | 5 votes |
private void redownloadContent(@NonNull final List<Content> contentList, boolean reparseImages) { StatusContent targetImageStatus = reparseImages ? StatusContent.ERROR : null; for (Content c : contentList) if (c != null) viewModel.addContentToQueue(c, targetImageStatus); if (Preferences.isQueueAutostart()) ContentQueueManager.getInstance().resumeQueue(getContext()); String message = getResources().getQuantityString(R.plurals.add_to_queue, contentList.size(), contentList.size()); Snackbar snackbar = Snackbar.make(mEmptyText, message, BaseTransientBottomBar.LENGTH_LONG); snackbar.show(); }
Example 13
Source File: ProvisioningActivity.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onPinInputCanceled() { final String message = getString(R.string.provisioning_cancelled); final Snackbar snackbar = Snackbar.make(mCoordinatorLayout, message, Snackbar.LENGTH_LONG); snackbar.show(); disconnect(); }
Example 14
Source File: TxtRecordsAdapter.java From BonjourBrowser with Apache License 2.0 | 5 votes |
public void onItemClick(View view, int position){ Context context = view.getContext(); ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getKey(position), getValue(position)); clipboard.setPrimaryClip(clip); Snackbar snackbar = Snackbar.make(view, context.getResources().getString(R.string.copy_toast_message, getKey(position)), Snackbar.LENGTH_LONG); snackbar.getView().setBackgroundResource(R.color.accent); snackbar.show(); }
Example 15
Source File: MainActivity.java From Easy_xkcd with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") // it's actually used, just injected by Butter Knife @OnClick(R.id.fab) void onClick() { Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG); if (fragment instanceof OverviewBaseFragment) { ((OverviewBaseFragment) fragment).showRandomComic(); } else if (fragment instanceof ComicFragment) { if (prefHelper.showRandomTip()) { Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), R.string.random_tip, BaseTransientBottomBar.LENGTH_LONG); snackbar.setAction(R.string.got_it, view -> prefHelper.setShowRandomTip(false)); snackbar.show(); } ((ComicFragment) fragment).getRandomComic(); } }
Example 16
Source File: DetailActivity.java From android-popular-movies-app with Apache License 2.0 | 5 votes |
/** * Show a snackbar message when a movie added to MovieDatabase * * Reference: @see "https://stackoverflow.com/questions/34020891/how-to-change-background-color-of-the-snackbar" */ private void showSnackbarAdded() { Snackbar snackbar = Snackbar.make( mDetailBinding.coordinator, R.string.snackbar_added, Snackbar.LENGTH_SHORT); // Set background color of the snackbar View sbView = snackbar.getView(); sbView.setBackgroundColor(Color.WHITE); // Set text color of the snackbar TextView textView = sbView.findViewById(com.google.android.material.R.id.snackbar_text); textView.setTextColor(Color.BLACK); snackbar.show(); }
Example 17
Source File: NotificationHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
public static void showActionSnackbar(String content, String action, int duration, View.OnClickListener l) { if (Mysplash.getInstance().getActivityCount() > 0) { MysplashActivity a = Mysplash.getInstance().getTopActivity(); View container = a.provideSnackbarContainer(); Snackbar snackbar = Snackbar .make(container, content, duration) .setAction(action, l); Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView(); TextView contentTxt = (TextView) snackbarLayout.findViewById(R.id.snackbar_text); DisplayUtils.setTypeface(a, contentTxt); Button actionBtn = (Button) snackbarLayout.findViewById(R.id.snackbar_action); if (Mysplash.getInstance().isLightTheme()) { contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_light)); actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_light)); snackbarLayout.setBackgroundResource(R.color.colorRoot_light); } else { contentTxt.setTextColor(ContextCompat.getColor(a, R.color.colorTextContent_dark)); actionBtn.setTextColor(ContextCompat.getColor(a, R.color.colorTextTitle_dark)); snackbarLayout.setBackgroundResource(R.color.colorRoot_dark); } snackbar.show(); } }
Example 18
Source File: SecurityPickerSlide.java From Aegis with GNU General Public License v3.0 | 4 votes |
@Override public void onUserIllegallyRequestedNextPage() { Snackbar snackbar = Snackbar.make(getView(), getString(R.string.snackbar_authentication_method), Snackbar.LENGTH_LONG); snackbar.show(); }
Example 19
Source File: EventCaptureActivity.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void showSnackBar(int messageId) { Snackbar mySnackbar = Snackbar.make(binding.root, messageId, Snackbar.LENGTH_SHORT); mySnackbar.show(); }
Example 20
Source File: UserActivity.java From intra42 with Apache License 2.0 | 4 votes |
@Override protected void setViewContent() { if (user == null) setViewState(StatusCode.API_DATA_ERROR); else { selectedCursus = user.getCursusUsersToDisplay(this); super.setViewContent(); ThemeHelper.setTheme(this, user); ThemeHelper.setActionBar(actionBar, AppSettings.Theme.getEnumTheme(this, user)); TypedValue typedValue = new TypedValue(); Resources.Theme theme = getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); @ColorInt int color = typedValue.data; tabLayout.setSelectedTabIndicatorColor(color); } if (user != null && user.local_cachedAt != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(user.local_cachedAt); calendar.add(Calendar.HOUR, 1); Date timeout = calendar.getTime(); if (timeout.before(new Date())) { Snackbar snackbar = Snackbar.make(baseActivityContent, R.string.info_data_cached_long_time_ago, Snackbar.LENGTH_LONG); snackbar.setAction(R.string.refresh, new View.OnClickListener() { @Override public void onClick(View view) { final Snackbar snackbarRefreshing = Snackbar.make(baseActivityContent, R.string.refreshing, Snackbar.LENGTH_INDEFINITE); snackbarRefreshing.show(); refresh(new Runnable() { @Override public void run() { setViewState(StatusCode.CONTENT); snackbarRefreshing.dismiss(); } }); } }); snackbar.show(); } } }