Java Code Examples for com.google.android.material.snackbar.Snackbar#addCallback()
The following examples show how to use
com.google.android.material.snackbar.Snackbar#addCallback() .
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: 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 2
Source File: CodeRecordsFragment.java From SmsCode with GNU General Public License v3.0 | 6 votes |
private void removeSelectedItems() { final List<SmsMsg> itemsToRemove = mCodeRecordAdapter.removeSelectedItems(); String text = getString(R.string.some_items_removed, itemsToRemove.size()); Snackbar snackbar = SnackbarHelper.makeLong(mRecyclerView, text); snackbar.addCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { if (event != DISMISS_EVENT_ACTION) { try { DBManager.get(mActivity).removeSmsMsgList(itemsToRemove); } catch (Exception e) { XLog.e("Error occurs when remove SMS records", e); } } } }); snackbar.setAction(R.string.revoke, v -> mCodeRecordAdapter.addItems(itemsToRemove)); snackbar.show(); mCurrentMode = RECORD_MODE_NORMAL; refreshActionBarByMode(); }
Example 3
Source File: SnackbarUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 设置 Snackbar 展示完成、隐藏完成 的监听 * @param callback {@link Snackbar.Callback} * @return {@link SnackbarUtils} */ public SnackbarUtils setCallback(final Snackbar.Callback callback) { Snackbar snackbar = getSnackbar(); if (snackbar != null) { snackbar.addCallback(callback); } return this; }
Example 4
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 5
Source File: SnackbarUtils.java From Dexter with Apache License 2.0 | 5 votes |
public static void show(View view, String text, int duration, String buttonText, View.OnClickListener onButtonClickListener, BaseTransientBottomBar.BaseCallback<Snackbar> snackbarCallback) { Snackbar snackbar = Snackbar.make(view, text, duration); if (buttonText != null && onButtonClickListener != null) { snackbar.setAction(buttonText, onButtonClickListener); } if (snackbarCallback != null) { snackbar.addCallback(snackbarCallback); } snackbar.show(); }
Example 6
Source File: BaseActivity.java From Jockey with Apache License 2.0 | 5 votes |
private void showPrivacyPolicySnackbar() { if (_mPreferenceStore.showFirstStart()) { return; } Snackbar snackbar = Snackbar.make( findViewById(getSnackbarContainerViewId()), R.string.alert_privacy_policy_updated, Snackbar.LENGTH_INDEFINITE ); snackbar.setAction(R.string.action_read_privacy_policy, v -> { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(getString(R.string.url_privacy_policy))); startActivity(intent); }); snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { switch (event) { case DISMISS_EVENT_ACTION: case DISMISS_EVENT_MANUAL: case DISMISS_EVENT_SWIPE: _mPrivacyPolicyManager.onLatestPrivacyPolicyConfirmed(); } } }); _mPrivacyPolicyManager.onPrivacyPolicyUpdateNotified(); snackbar.show(); }
Example 7
Source File: CourseOutlineFragment.java From edx-app-android with Apache License 2.0 | 4 votes |
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.item_delete: final int checkedItemPosition = listView.getCheckedItemPosition(); // Change the icon to download icon immediately final View rowView = listView.getChildAt(checkedItemPosition - listView.getFirstVisiblePosition()); if (rowView != null) { // rowView will be null, if the user scrolls away from the checked item ((IconImageView) rowView.findViewById(R.id.bulk_download)).setIcon(FontAwesomeIcons.fa_download); } final CourseOutlineAdapter.SectionRow rowItem = adapter.getItem(checkedItemPosition); final List<CourseComponent> videos = rowItem.component.getVideos(true); final int totalVideos = videos.size(); if (isOnCourseOutline) { environment.getAnalyticsRegistry().trackSubsectionVideosDelete( courseData.getCourse().getId(), rowItem.component.getId()); } else { environment.getAnalyticsRegistry().trackUnitVideoDelete( courseData.getCourse().getId(), rowItem.component.getId()); } /* The android docs have NOT been updated yet, but if you jump into the source code you'll notice that the parameter to the method setDuration(int duration) can either be one of LENGTH_SHORT, LENGTH_LONG, LENGTH_INDEFINITE or a custom duration in milliseconds. https://stackoverflow.com/a/30552666 https://github.com/material-components/material-components-android/commit/2cb77c9331cc3c6a5034aace0238b96508acf47d */ @SuppressLint("WrongConstant") final Snackbar snackbar = Snackbar.make(listView, getResources().getQuantityString(R.plurals.delete_video_snackbar_msg, totalVideos, totalVideos), SNACKBAR_SHOWTIME_MS); snackbar.setAction(R.string.label_undo, new View.OnClickListener() { @Override public void onClick(View v) { // No need of implementation as we'll handle the action in SnackBar's // onDismissed callback. } }); snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { super.onDismissed(transientBottomBar, event); // SnackBar is being dismissed by any action other than its action button's press if (event != DISMISS_EVENT_ACTION) { final IStorage storage = environment.getStorage(); for (CourseComponent video : videos) { final VideoBlockModel videoBlockModel = (VideoBlockModel) video; final DownloadEntry downloadEntry = videoBlockModel.getDownloadEntry(storage); if (downloadEntry.isDownloaded()) { // This check is necessary because, this callback gets // called multiple times when SnackBar is about to dismiss // and the activity finishes storage.removeDownload(downloadEntry); } else { return; } } } else { if (isOnCourseOutline) { environment.getAnalyticsRegistry().trackUndoingSubsectionVideosDelete( courseData.getCourse().getId(), rowItem.component.getId()); } else { environment.getAnalyticsRegistry().trackUndoingUnitVideoDelete( courseData.getCourse().getId(), rowItem.component.getId()); } } adapter.notifyDataSetChanged(); } }); snackbar.show(); mode.finish(); return true; default: return false; } }