Search in sources :

Example 16 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project ADWLauncher2 by boombuler.

the class LauncherModel method infoFromShortcutIntent.

private ShortcutInfo infoFromShortcutIntent(Context context, Intent data) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Bitmap icon = null;
    ShortcutIconResource iconResource = null;
    if (bitmap != null && bitmap instanceof Bitmap) {
        icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap) bitmap), context);
    } else {
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra != null && extra instanceof ShortcutIconResource) {
            try {
                iconResource = (ShortcutIconResource) extra;
                final PackageManager packageManager = context.getPackageManager();
                Resources resources = packageManager.getResourcesForApplication(iconResource.packageName);
                final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                icon = Utilities.createIconBitmap(resources.getDrawable(id), context);
            } catch (Exception e) {
                Log.w(TAG, "Could not load shortcut icon: " + extra);
            }
        }
    }
    final ShortcutInfo info = new ShortcutInfo();
    info.setIcon(icon);
    info.setTitle(name);
    info.intent = intent;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) Parcelable(android.os.Parcelable) Resources(android.content.res.Resources) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException)

Example 17 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project ADWLauncher2 by boombuler.

the class Launcher method requestPickLiveFolder.

private void requestPickLiveFolder(boolean toDrawer) {
    // Insert extra item to handle inserting folder
    Bundle bundle = new Bundle();
    ArrayList<String> shortcutNames = new ArrayList<String>();
    shortcutNames.add(getString(R.string.group_folder));
    bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
    ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
    shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, R.drawable.ic_launcher_folder));
    bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
    Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
    pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
    pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_live_folder));
    pickIntent.putExtras(bundle);
    startActivityForResult(pickIntent, toDrawer ? REQUEST_PICK_LIVE_FOLDER_DRAWER : REQUEST_PICK_LIVE_FOLDER);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) LauncherIntent(mobi.intuitit.android.content.LauncherIntent)

Example 18 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project Launcher3 by chislon.

the class LauncherModel method infoFromShortcutIntent.

ShortcutInfo infoFromShortcutIntent(Context context, Intent data, Bitmap fallbackIcon) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    if (intent == null) {
        // If the intent is null, we can't construct a valid ShortcutInfo, so we return null
        Log.e(TAG, "Can't construct ShorcutInfo with null intent");
        return null;
    }
    Bitmap icon = null;
    boolean customIcon = false;
    ShortcutIconResource iconResource = null;
    if (bitmap != null && bitmap instanceof Bitmap) {
        icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap) bitmap), context);
        customIcon = true;
    } else {
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra != null && extra instanceof ShortcutIconResource) {
            try {
                iconResource = (ShortcutIconResource) extra;
                final PackageManager packageManager = context.getPackageManager();
                Resources resources = packageManager.getResourcesForApplication(iconResource.packageName);
                final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                icon = Utilities.createIconBitmap(mIconCache.getFullResIcon(resources, id), context);
            } catch (Exception e) {
                Log.w(TAG, "Could not load shortcut icon: " + extra);
            }
        }
    }
    final ShortcutInfo info = new ShortcutInfo();
    if (icon == null) {
        if (fallbackIcon != null) {
            icon = fallbackIcon;
        } else {
            icon = getFallbackIcon();
            info.usingFallbackIcon = true;
        }
    }
    info.setIcon(icon);
    info.title = name;
    info.intent = intent;
    info.customIcon = customIcon;
    info.iconResource = iconResource;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Parcelable(android.os.Parcelable) Resources(android.content.res.Resources) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException)

Example 19 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project android_packages_apps_Launcher2 by CyanogenMod.

the class LauncherModel method infoFromShortcutIntent.

ShortcutInfo infoFromShortcutIntent(Context context, Intent data, Bitmap fallbackIcon) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    if (intent == null) {
        // If the intent is null, we can't construct a valid ShortcutInfo, so we return null
        Log.e(TAG, "Can't construct ShorcutInfo with null intent");
        return null;
    }
    Bitmap icon = null;
    boolean customIcon = false;
    ShortcutIconResource iconResource = null;
    if (bitmap != null && bitmap instanceof Bitmap) {
        icon = Utilities.createIconBitmap(new FastBitmapDrawable((Bitmap) bitmap), context);
        customIcon = true;
    } else {
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra != null && extra instanceof ShortcutIconResource) {
            try {
                iconResource = (ShortcutIconResource) extra;
                final PackageManager packageManager = context.getPackageManager();
                Resources resources = packageManager.getResourcesForApplication(iconResource.packageName);
                final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                icon = Utilities.createIconBitmap(mIconCache.getFullResIcon(resources, id), context);
            } catch (Exception e) {
                Log.w(TAG, "Could not load shortcut icon: " + extra);
            }
        }
    }
    final ShortcutInfo info = new ShortcutInfo();
    if (icon == null) {
        if (fallbackIcon != null) {
            icon = fallbackIcon;
        } else {
            icon = getFallbackIcon();
            info.usingFallbackIcon = true;
        }
    }
    info.setIcon(icon);
    info.title = name;
    info.intent = intent;
    info.customIcon = customIcon;
    info.iconResource = iconResource;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) Parcelable(android.os.Parcelable) Resources(android.content.res.Resources) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException)

Example 20 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project KISS by Neamar.

the class InstallShortcutHandler method onReceive.

@Override
public void onReceive(Context context, Intent data) {
    DataHandler dh = KissApplication.getDataHandler(context);
    ShortcutsProvider sp = dh.getShortcutsProvider();
    if (sp == null)
        return;
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Log.d("onReceive", "Received shortcut " + name);
    Intent target = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (target.getAction() == null) {
        target.setAction(Intent.ACTION_VIEW);
    }
    ShortcutsPojo pojo = createPojo(name);
    // convert target intent to parsable uri
    pojo.intentUri = target.toUri(0);
    //get embedded icon
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    if (icon != null) {
        Log.d("onReceive", "Shortcut " + name + " has embedded icon");
        pojo.icon = icon;
    } else {
        ShortcutIconResource sir = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (sir != null) {
            Log.d("onReceive", "Received icon package name " + sir.packageName);
            Log.d("onReceive", "Received icon resource name " + sir.resourceName);
            pojo.packageName = sir.packageName;
            pojo.resourceName = sir.resourceName;
        } else {
            //invalid shortcut
            Log.d("onReceive", "Invalid shortcut " + name + ", ignoring");
            return;
        }
    }
    try {
        Intent intent = Intent.parseUri(pojo.intentUri, 0);
        if (intent.getCategories() != null && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER) && intent.getAction().equals(Intent.ACTION_MAIN)) {
            // The Play Store has an option to create shortcut for new apps,
            // However, KISS already displays all apps, so we discard the shortcut to avoid duplicates.
            Log.d("onReceive", "Shortcut for launcher app, discarded.");
            return;
        }
    } catch (URISyntaxException e) {
        // Invalid intentUri: skip
        // (should logically not happen)
        e.printStackTrace();
        return;
    }
    dh.addShortcut(pojo);
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) Bitmap(android.graphics.Bitmap) ShortcutsProvider(fr.neamar.kiss.dataprovider.ShortcutsProvider) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) DataHandler(fr.neamar.kiss.DataHandler) URISyntaxException(java.net.URISyntaxException)

Aggregations

ShortcutIconResource (android.content.Intent.ShortcutIconResource)24 Intent (android.content.Intent)23 ArrayList (java.util.ArrayList)12 Resources (android.content.res.Resources)10 Bitmap (android.graphics.Bitmap)10 Bundle (android.os.Bundle)10 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)8 PackageManager (android.content.pm.PackageManager)7 Parcelable (android.os.Parcelable)7 RemoteException (android.os.RemoteException)5 URISyntaxException (java.net.URISyntaxException)5 Drawable (android.graphics.drawable.Drawable)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 ComponentName (android.content.ComponentName)2 ActivityInfo (android.content.pm.ActivityInfo)2 Paint (android.graphics.Paint)2 PaintDrawable (android.graphics.drawable.PaintDrawable)2 LauncherIntent (mobi.intuitit.android.content.LauncherIntent)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1