Search in sources :

Example 1 with IconCompat

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);
    }
}
Also used : IconCompat(android.support.v4.graphics.drawable.IconCompat) ShortcutInfoCompat(android.support.v4.content.pm.ShortcutInfoCompat)

Example 2 with IconCompat

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();
    }
}
Also used : Book(com.orgzly.android.Book) IconCompat(android.support.v4.graphics.drawable.IconCompat) Shelf(com.orgzly.android.Shelf) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent) ShortcutInfoCompat(android.support.v4.content.pm.ShortcutInfoCompat)

Aggregations

ShortcutInfoCompat (android.support.v4.content.pm.ShortcutInfoCompat)2 IconCompat (android.support.v4.graphics.drawable.IconCompat)2 Intent (android.content.Intent)1 AppIntent (com.orgzly.android.AppIntent)1 Book (com.orgzly.android.Book)1 Shelf (com.orgzly.android.Shelf)1