use of android.support.v4.graphics.drawable.IconCompat in project focus-android by mozilla-mobile.
the class HomeScreen method installShortCutViaManager.
/**
* Create a shortcut via the AppCompat's shortcut manager.
* <p>
* On Android versions up to 7 shortcut will be created via system broadcast internally.
* <p>
* On Android 8+ the user will have the ability to add the shortcut manually
* or let the system place it automatically.
*/
private static void installShortCutViaManager(Context context, Bitmap bitmap, String url, String title, boolean blockingEnabled) {
if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) {
final IconCompat icon = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ? IconCompat.createWithAdaptiveBitmap(bitmap) : IconCompat.createWithBitmap(bitmap);
final ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(context, UUID.randomUUID().toString()).setShortLabel(title).setLongLabel(title).setIcon(icon).setIntent(createShortcutIntent(context, url, blockingEnabled)).build();
ShortcutManagerCompat.requestPinShortcut(context, shortcut, null);
}
}
use of android.support.v4.graphics.drawable.IconCompat in project orgzly-android by orgzly.
the class BookChooserActivity method onBookClicked.
@Override
public void onBookClicked(long bookId) {
if (action != null && action.equals(Intent.ACTION_CREATE_SHORTCUT)) {
// Get Book by its ID
Shelf shelf = new Shelf(this);
Book book = shelf.getBook(bookId);
if (book == null) {
Toast.makeText(this, R.string.book_does_not_exist_anymore, Toast.LENGTH_SHORT).show();
setResult(RESULT_CANCELED);
finish();
return;
}
String id = "notebook-" + bookId;
String name = book.getName();
String title = BookUtils.getFragmentTitleForBook(book);
Intent launchIntent = createLaunchIntent(book);
IconCompat icon = createIcon();
ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, id).setShortLabel(name).setLongLabel(title).setIcon(icon).setIntent(launchIntent).build();
setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
finish();
}
}
Aggregations