use of org.chromium.chrome.browser.snackbar.Snackbar in project AndroidChromium by JackyAndroid.
the class LocaleManager method showSnackbar.
private void showSnackbar(CharSequence title) {
SnackbarManager manager = mSnackbarManager.get();
if (manager == null)
return;
Context context = ContextUtils.getApplicationContext();
Snackbar snackbar = Snackbar.make(title, mSnackbarController, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_SPECIAL_LOCALE);
snackbar.setDuration(SNACKBAR_DURATION_MS);
snackbar.setAction(context.getString(R.string.preferences), null);
manager.showSnackbar(snackbar);
}
use of org.chromium.chrome.browser.snackbar.Snackbar in project AndroidChromium by JackyAndroid.
the class GeolocationSnackbarController method maybeShowSnackbar.
/**
* Shows the geolocation snackbar if it hasn't already been shown and the geolocation snackbar
* is currently relevant: i.e. the default search engine is Google, location is enabled
* for Chrome, the tab is not incognito, etc.
*
* @param snackbarManager The SnackbarManager used to show the snackbar.
* @param view Any view that's attached to the view hierarchy.
* @param isIncognito Whether the currently visible tab is incognito.
* @param delayMs The delay in ms before the snackbar should be shown. This is intended to
* give the keyboard time to animate in.
*/
public static void maybeShowSnackbar(final SnackbarManager snackbarManager, View view, boolean isIncognito, int delayMs) {
final Context context = view.getContext();
if (getGeolocationSnackbarShown(context))
return;
// If in incognito mode, don't show the snackbar now, but maybe show it later.
if (isIncognito)
return;
if (neverShowSnackbar(context)) {
setGeolocationSnackbarShown(context);
return;
}
Uri searchUri = Uri.parse(TemplateUrlService.getInstance().getUrlForSearchQuery("foo"));
TypefaceSpan robotoMediumSpan = new TypefaceSpan("sans-serif-medium");
String messageWithoutSpans = context.getResources().getString(R.string.omnibox_geolocation_disclosure, "<b>" + searchUri.getHost() + "</b>");
SpannableString message = SpanApplier.applySpans(messageWithoutSpans, new SpanInfo("<b>", "</b>", robotoMediumSpan));
String settings = context.getResources().getString(R.string.preferences);
int durationMs = DeviceClassManager.isAccessibilityModeEnabled(view.getContext()) ? ACCESSIBILITY_SNACKBAR_DURATION_MS : SNACKBAR_DURATION_MS;
final GeolocationSnackbarController controller = new GeolocationSnackbarController();
final Snackbar snackbar = Snackbar.make(message, controller, Snackbar.TYPE_ACTION, Snackbar.UMA_OMNIBOX_GEOLOCATION).setAction(settings, view).setSingleLine(false).setDuration(durationMs);
view.postDelayed(new Runnable() {
@Override
public void run() {
snackbarManager.dismissSnackbars(controller);
snackbarManager.showSnackbar(snackbar);
setGeolocationSnackbarShown(context);
}
}, delayMs);
}
use of org.chromium.chrome.browser.snackbar.Snackbar in project AndroidChromium by JackyAndroid.
the class BookmarkUtils method addOrEditBookmark.
/**
* If the tab has already been bookmarked, start {@link BookmarkEditActivity} for the
* bookmark. If not, add the bookmark to bookmarkmodel, and show a snackbar notifying the user.
*
* Note: Takes ownership of bookmarkModel, and will call |destroy| on it when finished.
*
* @param existingBookmarkId The bookmark ID if the tab has already been bookmarked.
* @param bookmarkModel The bookmark model.
* @param tab The tab to add or edit a bookmark.
* @param snackbarManager The SnackbarManager used to show the snackbar.
* @param activity Current activity.
* @return Bookmark ID of the bookmark. Could be <code>null</code> if bookmark didn't exist
* and bookmark model failed to create it.
*/
public static BookmarkId addOrEditBookmark(long existingBookmarkId, BookmarkModel bookmarkModel, Tab tab, SnackbarManager snackbarManager, Activity activity) {
if (existingBookmarkId != Tab.INVALID_BOOKMARK_ID) {
BookmarkId bookmarkId = new BookmarkId(existingBookmarkId, BookmarkType.NORMAL);
startEditActivity(activity, bookmarkId);
bookmarkModel.destroy();
return bookmarkId;
}
BookmarkId parent = getLastUsedParent(activity);
if (parent == null || !bookmarkModel.doesBookmarkExist(parent)) {
parent = bookmarkModel.getDefaultFolder();
}
String url = tab.getOriginalUrl();
BookmarkId bookmarkId = bookmarkModel.addBookmark(parent, bookmarkModel.getChildCount(parent), tab.getTitle(), url);
Snackbar snackbar = null;
if (bookmarkId == null) {
snackbar = Snackbar.make(activity.getString(R.string.bookmark_page_failed), new SnackbarController() {
@Override
public void onDismissNoAction(Object actionData) {
}
@Override
public void onAction(Object actionData) {
}
}, Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_BOOKMARK_ADDED).setSingleLine(false);
RecordUserAction.record("EnhancedBookmarks.AddingFailed");
} else {
String folderName = bookmarkModel.getBookmarkTitle(bookmarkModel.getBookmarkById(bookmarkId).getParentId());
SnackbarController snackbarController = createSnackbarControllerForEditButton(activity, bookmarkId);
if (getLastUsedParent(activity) == null) {
snackbar = Snackbar.make(activity.getString(R.string.bookmark_page_saved), snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_BOOKMARK_ADDED);
} else {
snackbar = Snackbar.make(folderName, snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_BOOKMARK_ADDED).setTemplateText(activity.getString(R.string.bookmark_page_saved_folder));
}
snackbar.setSingleLine(false).setAction(activity.getString(R.string.bookmark_item_edit), null);
}
snackbarManager.showSnackbar(snackbar);
bookmarkModel.destroy();
return bookmarkId;
}
use of org.chromium.chrome.browser.snackbar.Snackbar in project AndroidChromium by JackyAndroid.
the class DownloadManagerUi method deleteSelectedItems.
private void deleteSelectedItems() {
List<DownloadHistoryItemWrapper> selectedItems = mBackendProvider.getSelectionDelegate().getSelectedItems();
final List<DownloadHistoryItemWrapper> itemsToDelete = getItemsForDeletion();
mBackendProvider.getSelectionDelegate().clearSelection();
if (itemsToDelete.isEmpty())
return;
mHistoryAdapter.removeItemsFromAdapter(itemsToDelete);
dismissUndoDeletionSnackbars();
boolean singleItemDeleted = selectedItems.size() == 1;
String snackbarText = singleItemDeleted ? selectedItems.get(0).getDisplayFileName() : String.format(Locale.getDefault(), "%d", selectedItems.size());
int snackbarTemplateId = singleItemDeleted ? R.string.undo_bar_delete_message : R.string.undo_bar_multiple_downloads_delete_message;
Snackbar snackbar = Snackbar.make(snackbarText, mUndoDeletionSnackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_DOWNLOAD_DELETE_UNDO);
snackbar.setAction(mActivity.getString(R.string.undo), itemsToDelete);
snackbar.setTemplateText(mActivity.getString(snackbarTemplateId));
((SnackbarManageable) mActivity).getSnackbarManager().showSnackbar(snackbar);
}
Aggregations