Search in sources :

Example 1 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project Fairphone by Kwamecorp.

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 2 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project Lazy by l123456789jy.

the class ShortCutUtils method addShortcut.

/**
     * 为程序创建桌面快捷方式
     *
     * @param activity Activity
     * @param res     res
     */
public static void addShortcut(Activity activity, int res) {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    // 快捷方式的名称
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(R.string.app_name));
    // 不允许重复创建
    shortcut.putExtra("duplicate", false);
    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(activity, activity.getClass().getName());
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    // 快捷方式的图标
    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(activity, res);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    activity.sendBroadcast(shortcut);
}
Also used : ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent)

Example 3 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project platform_packages_apps_launcher by android.

the class Launcher method infoFromShortcutIntent.

private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Drawable icon = null;
    boolean filtered = false;
    boolean customIcon = false;
    ShortcutIconResource iconResource = null;
    if (bitmap != null) {
        icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
        filtered = true;
        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 = resources.getDrawable(id);
            } catch (Exception e) {
                w(LOG_TAG, "Could not load shortcut icon: " + extra);
            }
        }
    }
    if (icon == null) {
        icon = context.getPackageManager().getDefaultActivityIcon();
    }
    final ApplicationInfo info = new ApplicationInfo();
    info.icon = icon;
    info.filtered = filtered;
    info.title = name;
    info.intent = intent;
    info.customIcon = customIcon;
    info.iconResource = iconResource;
    return info;
}
Also used : Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) Parcelable(android.os.Parcelable) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) Resources(android.content.res.Resources)

Example 4 with ShortcutIconResource

use of android.content.Intent.ShortcutIconResource in project platform_packages_apps_launcher by android.

the class Launcher method pickShortcut.

private void pickShortcut(int requestCode, int title) {
    Bundle bundle = new Bundle();
    ArrayList<String> shortcutNames = new ArrayList<String>();
    shortcutNames.add(getString(R.string.group_applications));
    bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
    ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
    shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, R.drawable.ic_launcher_application));
    bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
    Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
    pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
    pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
    pickIntent.putExtras(bundle);
    startActivityForResult(pickIntent, requestCode);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent)

Example 5 with ShortcutIconResource

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

the class ActivityPickerActivity method onChildClick.

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    ActivityInfo info = (ActivityInfo) getExpandableListAdapter().getChild(groupPosition, childPosition);
    Intent intent = new Intent();
    intent.setComponent(new ComponentName(info.applicationInfo.packageName, info.name));
    Intent mReturnData = new Intent();
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    mReturnData.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    // Set the name of the activity
    mReturnData.putExtra(Intent.EXTRA_SHORTCUT_NAME, info.loadLabel(mPackageManager));
    ShortcutIconResource iconResource = new ShortcutIconResource();
    iconResource.packageName = info.packageName;
    try {
        Resources resources = mPackageManager.getResourcesForApplication(iconResource.packageName);
        iconResource.resourceName = resources.getResourceName(info.getIconResource());
        mReturnData.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
    } catch (NameNotFoundException e) {
    } catch (Resources.NotFoundException e) {
    }
    setResult(RESULT_OK, mReturnData);
    finish();
    return true;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ShortcutIconResource(android.content.Intent.ShortcutIconResource) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Resources(android.content.res.Resources)

Aggregations

ShortcutIconResource (android.content.Intent.ShortcutIconResource)23 Intent (android.content.Intent)22 ArrayList (java.util.ArrayList)11 Resources (android.content.res.Resources)10 Bitmap (android.graphics.Bitmap)10 Bundle (android.os.Bundle)9 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