Search in sources :

Example 41 with ShortcutManager

use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by DirtyUnicorns.

the class CreateShortcut method createResultIntent.

protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    ShortcutManager sm = getSystemService(ShortcutManager.class);
    ActivityInfo activityInfo = resolveInfo.activityInfo;
    Icon maskableIcon = activityInfo.icon != 0 ? Icon.createWithAdaptiveBitmap(createIcon(activityInfo.icon, R.layout.shortcut_badge_maskable, getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable))) : Icon.createWithResource(this, R.drawable.ic_launcher_settings);
    String shortcutId = SHORTCUT_ID_PREFIX + shortcutIntent.getComponent().flattenToShortString();
    ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId).setShortLabel(label).setIntent(shortcutIntent).setIcon(maskableIcon).build();
    Intent intent = sm.createShortcutResultIntent(info);
    if (intent == null) {
        intent = new Intent();
    }
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings));
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
    if (activityInfo.icon != 0) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon, R.layout.shortcut_badge, getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
    }
    return intent;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) Icon(android.graphics.drawable.Icon)

Example 42 with ShortcutManager

use of android.content.pm.ShortcutManager in project LibreraReader by foobnix.

the class RecentUpates method updateAll.

@TargetApi(25)
public static void updateAll(final Context c) {
    if (c == null) {
        return;
    }
    LOG.d("RecentUpates", "MUPDF!", c.getClass());
    try {
        {
            Intent intent = new Intent(c, RecentBooksWidget.class);
            intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
            c.sendBroadcast(intent);
        }
    } catch (Exception e) {
        LOG.e(e);
    }
    if (Build.VERSION.SDK_INT >= 25) {
        try {
            FileMeta recentLast = AppDB.get().getRecentLast();
            if (recentLast != null) {
                ShortcutManager shortcutManager = c.getSystemService(ShortcutManager.class);
                String url = IMG.toUrl(recentLast.getPath(), ImageExtractor.COVER_PAGE, IMG.getImageSize());
                Bitmap image = ImageLoader.getInstance().loadImageSync(url, IMG.displayCacheMemoryDisc);
                Intent lastBookIntent = new Intent(c, VerticalViewActivity.class);
                if (AppState.get().isAlwaysOpenAsMagazine) {
                    lastBookIntent = new Intent(c, HorizontalViewActivity.class);
                }
                lastBookIntent.setAction(Intent.ACTION_VIEW);
                lastBookIntent.setData(Uri.fromFile(new File(recentLast.getPath())));
                ShortcutInfo shortcut = // 
                new ShortcutInfo.Builder(c, "last").setShortLabel(// 
                recentLast.getTitle()).setLongLabel(// 
                TxtUtils.getFileMetaBookName(recentLast)).setIcon(// 
                Icon.createWithBitmap(image)).setIntent(// 
                lastBookIntent).build();
                Intent tTSIntent = new Intent(c, TTSActivity.class);
                tTSIntent.setData(Uri.fromFile(new File(recentLast.getPath())));
                tTSIntent.setAction(Intent.ACTION_VIEW);
                ShortcutInfo tts = // 
                new ShortcutInfo.Builder(c, "tts").setShortLabel(// 
                c.getString(R.string.reading_out_loud)).setLongLabel(// 
                c.getString(R.string.reading_out_loud)).setIcon(// 
                Icon.createWithBitmap(image)).setIntent(// 
                tTSIntent).build();
                shortcutManager.setDynamicShortcuts(Arrays.asList(tts, shortcut));
            // shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
            }
        } catch (Exception e) {
            LOG.e(e);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta) TargetApi(android.annotation.TargetApi)

Example 43 with ShortcutManager

use of android.content.pm.ShortcutManager in project android_packages_apps_Settings by crdroidandroid.

the class CreateShortcut method createResultIntent.

protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) {
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    ShortcutManager sm = getSystemService(ShortcutManager.class);
    ActivityInfo activityInfo = resolveInfo.activityInfo;
    Icon maskableIcon = activityInfo.icon != 0 ? Icon.createWithAdaptiveBitmap(createIcon(activityInfo.icon, R.layout.shortcut_badge_maskable, getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable))) : Icon.createWithResource(this, R.drawable.ic_launcher_settings);
    String shortcutId = SHORTCUT_ID_PREFIX + shortcutIntent.getComponent().flattenToShortString();
    ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId).setShortLabel(label).setIntent(shortcutIntent).setIcon(maskableIcon).build();
    Intent intent = sm.createShortcutResultIntent(info);
    if (intent == null) {
        intent = new Intent();
    }
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings));
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
    if (activityInfo.icon != 0) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon, R.layout.shortcut_badge, getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
    }
    return intent;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) Icon(android.graphics.drawable.Icon)

Example 44 with ShortcutManager

use of android.content.pm.ShortcutManager in project xabber-android by redsolution.

the class ShortcutBuilder method updateShortcuts.

public static void updateShortcuts(Context context, List<AbstractContact> contacts) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        List<ShortcutInfo> shortcuts = new ArrayList<>();
        int added = 0;
        for (AbstractContact contact : contacts) {
            if (added == 4)
                break;
            else if (!contact.getUser().equals(CrowdfundingChat.getDefaultUser())) {
                shortcuts.add(createShortcutInfo(context, contact));
                added++;
            }
        }
        ShortcutManager manager = context.getSystemService(ShortcutManager.class);
        if (manager != null && !shortcuts.isEmpty()) {
            manager.setDynamicShortcuts(shortcuts);
        }
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) AbstractContact(com.xabber.android.data.roster.AbstractContact)

Example 45 with ShortcutManager

use of android.content.pm.ShortcutManager in project xabber-android by redsolution.

the class ShortcutBuilder method createPinnedShortcut.

public static Intent createPinnedShortcut(Context context, AbstractContact contact) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        ShortcutManager manager = context.getSystemService(ShortcutManager.class);
        if (manager != null && manager.isRequestPinShortcutSupported()) {
            ShortcutInfo shortcutInfo = createShortcutInfo(context, contact);
            Intent callbackIntent = manager.createShortcutResultIntent(shortcutInfo);
            PendingIntent successCallback = PendingIntent.getBroadcast(context, 0, callbackIntent, 0);
            manager.requestPinShortcut(shortcutInfo, successCallback.getIntentSender());
            return null;
        }
    }
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, ChatActivity.createClearTopIntent(context, contact.getAccount(), contact.getUser()));
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, contact.getName());
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, getAvatar(contact));
    return intent;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

ShortcutManager (android.content.pm.ShortcutManager)55 ShortcutInfo (android.content.pm.ShortcutInfo)39 Intent (android.content.Intent)31 ArrayList (java.util.ArrayList)19 TargetApi (android.annotation.TargetApi)15 PendingIntent (android.app.PendingIntent)7 Icon (android.graphics.drawable.Icon)7 ActivityInfo (android.content.pm.ActivityInfo)6 Bundle (android.os.Bundle)6 ComponentName (android.content.ComponentName)5 ResolveInfo (android.content.pm.ResolveInfo)4 PackageManager (android.content.pm.PackageManager)3 WorkerThread (android.support.annotation.WorkerThread)3 SuppressLint (android.annotation.SuppressLint)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Cursor (android.database.Cursor)2 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 RequiresApi (android.support.annotation.RequiresApi)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2