Java Code Examples for com.android.launcher3.util.CursorIconInfo

The following are top voted examples for showing how to use com.android.launcher3.util.CursorIconInfo. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Trebuchet   File: LauncherModel.java   Source Code and License 6 votes vote down vote up
/**
 * Make an ShortcutInfo object for a shortcut that isn't an application.
 */
@Thunk ShortcutInfo getShortcutInfo(Cursor c, Context context,
        int titleIndex, CursorIconInfo iconInfo) {
    final ShortcutInfo info = new ShortcutInfo();
    // Non-app shortcuts are only supported for current user.
    info.user = UserHandleCompat.myUserHandle();
    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;

    // TODO: If there's an explicit component and we can't install that, delete it.

    info.title = Utilities.trim(c.getString(titleIndex));

    Bitmap icon = iconInfo.loadIcon(c, info, context);
    // the fallback icon
    if (icon == null) {
        icon = mIconCache.getDefaultIcon(info.user);
        info.usingFallbackIcon = true;
    }
    info.setIcon(icon);
    return info;
}
 
Example 2
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Make an ShortcutInfo object for a restored application or shortcut item that points
 * to a package that is not yet installed on the system.
 */
public ShortcutInfo getRestoredItemInfo(Cursor c, Intent intent,
        int promiseType, int itemType, CursorIconInfo iconInfo) {
    final ShortcutInfo info = new ShortcutInfo();
    info.user = UserHandleCompat.myUserHandle();

    Bitmap icon = iconInfo.loadIcon(c, info);
    // the fallback icon
    if (icon == null) {
        mIconCache.getTitleAndIcon(info, intent, info.user, false /* useLowResIcon */);
    } else {
        info.setIcon(icon);
    }

    if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) {
        String title = iconInfo.getTitle(c);
        if (!TextUtils.isEmpty(title)) {
            info.title = Utilities.trim(title);
        }
    } else if  ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) {
        if (TextUtils.isEmpty(info.title)) {
            info.title = iconInfo.getTitle(c);
        }
    } else {
        throw new InvalidParameterException("Invalid restoreType " + promiseType);
    }

    info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
    info.itemType = itemType;
    info.promisedIntent = intent;
    info.status = promiseType;
    return info;
}
 
Example 3
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Make an ShortcutInfo object for a shortcut that isn't an application.
 */
@Thunk ShortcutInfo getShortcutInfo(Cursor c, CursorIconInfo iconInfo) {
    final ShortcutInfo info = new ShortcutInfo();
    // Non-app shortcuts are only supported for current user.
    info.user = UserHandleCompat.myUserHandle();
    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;

    // TODO: If there's an explicit component and we can't install that, delete it.

    loadInfoFromCursor(info, c, iconInfo);
    return info;
}
 
Example 4
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Make an ShortcutInfo object for a shortcut that isn't an application.
 */
public void loadInfoFromCursor(ShortcutInfo info, Cursor c, CursorIconInfo iconInfo) {
    info.title = iconInfo.getTitle(c);
    Bitmap icon = iconInfo.loadIcon(c, info);
    // the fallback icon
    if (icon == null) {
        icon = mIconCache.getDefaultIcon(info.user);
        info.usingFallbackIcon = true;
    }
    info.setIcon(icon);
}
 
Example 5
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Make an ShortcutInfo object for a restored application or shortcut item that points
 * to a package that is not yet installed on the system.
 */
public ShortcutInfo getRestoredItemInfo(Cursor c, Intent intent,
        int promiseType, int itemType, CursorIconInfo iconInfo) {
    final ShortcutInfo info = new ShortcutInfo();
    info.user = UserHandleCompat.myUserHandle();

    Bitmap icon = iconInfo.loadIcon(c, info);
    // the fallback icon
    if (icon == null) {
        mIconCache.getTitleAndIcon(info, intent, info.user, false /* useLowResIcon */);
    } else {
        info.setIcon(icon);
    }

    if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) {
        String title = iconInfo.getTitle(c);
        if (!TextUtils.isEmpty(title)) {
            info.title = Utilities.trim(title);
        }
    } else if  ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) {
        if (TextUtils.isEmpty(info.title)) {
            info.title = iconInfo.getTitle(c);
        }
    } else {
        throw new InvalidParameterException("Invalid restoreType " + promiseType);
    }

    info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
    info.itemType = itemType;
    info.promisedIntent = intent;
    info.status = promiseType;
    return info;
}
 
Example 6
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Make an ShortcutInfo object for a shortcut that isn't an application.
 */
@Thunk ShortcutInfo getShortcutInfo(Cursor c, CursorIconInfo iconInfo) {
    final ShortcutInfo info = new ShortcutInfo();
    // Non-app shortcuts are only supported for current user.
    info.user = UserHandleCompat.myUserHandle();
    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;

    // TODO: If there's an explicit component and we can't install that, delete it.

    loadInfoFromCursor(info, c, iconInfo);
    return info;
}
 
Example 7
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Make an ShortcutInfo object for a shortcut that isn't an application.
 */
public void loadInfoFromCursor(ShortcutInfo info, Cursor c, CursorIconInfo iconInfo) {
    info.title = iconInfo.getTitle(c);
    Bitmap icon = iconInfo.loadIcon(c, info);
    // the fallback icon
    if (icon == null) {
        icon = mIconCache.getDefaultIcon(info.user);
        info.usingFallbackIcon = true;
    }
    info.setIcon(icon);
}
 
Example 8
Project: Trebuchet   File: LauncherModel.java   Source Code and License 5 votes vote down vote up
/**
 * Make an ShortcutInfo object for a restored application or shortcut item that points
 * to a package that is not yet installed on the system.
 */
public ShortcutInfo getRestoredItemInfo(Cursor c, int titleIndex, Intent intent,
        int promiseType, int itemType, CursorIconInfo iconInfo, Context context) {
    final ShortcutInfo info = new ShortcutInfo();
    info.user = UserHandleCompat.myUserHandle();

    Bitmap icon = iconInfo.loadIcon(c, info, context);
    // the fallback icon
    if (icon == null) {
        mIconCache.getTitleAndIcon(info, intent, info.user, false /* useLowResIcon */);
    } else {
        info.setIcon(icon);
    }

    if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) {
        String title = (c != null) ? c.getString(titleIndex) : null;
        if (!TextUtils.isEmpty(title)) {
            info.title = Utilities.trim(title);
        }
    } else if  ((promiseType & ShortcutInfo.FLAG_AUTOINTALL_ICON) != 0) {
        if (TextUtils.isEmpty(info.title)) {
            info.title = (c != null) ? Utilities.trim(c.getString(titleIndex)) : "";
        }
    } else {
        throw new InvalidParameterException("Invalid restoreType " + promiseType);
    }

    info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
    info.itemType = itemType;
    info.promisedIntent = intent;
    info.status = promiseType;
    return info;
}
 
Example 9
Project: FlickLauncher   File: LauncherModel.java   Source Code and License 4 votes vote down vote up
/**
 * Make an ShortcutInfo object for a shortcut that is an application.
 *
 * If c is not null, then it will be used to fill in missing data like the title and icon.
 */
public ShortcutInfo getAppShortcutInfo(Intent intent,
        UserHandleCompat user, Cursor c, CursorIconInfo iconInfo,
        boolean allowMissingTarget, boolean useLowResIcon) {
    if (user == null) {
        Log.d(TAG, "Null user found in getShortcutInfo");
        return null;
    }

    ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        Log.d(TAG, "Missing component found in getShortcutInfo");
        return null;
    }

    Intent newIntent = new Intent(intent.getAction(), null);
    newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    newIntent.setComponent(componentName);
    LauncherActivityInfoCompat lai = mLauncherApps.resolveActivity(newIntent, user);
    if ((lai == null) && !allowMissingTarget) {
        Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName);
        return null;
    }

    final ShortcutInfo info = new ShortcutInfo();
    mIconCache.getTitleAndIcon(info, componentName, lai, user, false, useLowResIcon);
    if (mIconCache.isDefaultIcon(info.getIcon(mIconCache), user) && c != null) {
        Bitmap icon = iconInfo.loadIcon(c);
        info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon);
    }

    if (lai != null && PackageManagerHelper.isAppSuspended(lai.getApplicationInfo())) {
        info.isDisabled = ShortcutInfo.FLAG_DISABLED_SUSPENDED;
    }

    // from the db
    if (TextUtils.isEmpty(info.title) && c != null) {
        info.title = iconInfo.getTitle(c);
    }

    // fall back to the class name of the activity
    if (info.title == null) {
        info.title = componentName.getClassName();
    }

    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
    info.user = user;
    info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
    if (lai != null) {
        info.flags = AppInfo.initFlags(lai);
    }
    return info;
}
 
Example 10
Project: SimpleUILauncher   File: LauncherModel.java   Source Code and License 4 votes vote down vote up
/**
 * Make an ShortcutInfo object for a shortcut that is an application.
 *
 * If c is not null, then it will be used to fill in missing data like the title and icon.
 */
public ShortcutInfo getAppShortcutInfo(Intent intent,
        UserHandleCompat user, Cursor c, CursorIconInfo iconInfo,
        boolean allowMissingTarget, boolean useLowResIcon) {
    if (user == null) {
        Log.d(TAG, "Null user found in getShortcutInfo");
        return null;
    }

    ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        Log.d(TAG, "Missing component found in getShortcutInfo");
        return null;
    }

    Intent newIntent = new Intent(intent.getAction(), null);
    newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    newIntent.setComponent(componentName);
    LauncherActivityInfoCompat lai = mLauncherApps.resolveActivity(newIntent, user);
    if ((lai == null) && !allowMissingTarget) {
        Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName);
        return null;
    }

    final ShortcutInfo info = new ShortcutInfo();
    mIconCache.getTitleAndIcon(info, componentName, lai, user, false, useLowResIcon);
    if (mIconCache.isDefaultIcon(info.getIcon(mIconCache), user) && c != null) {
        Bitmap icon = iconInfo.loadIcon(c);
        info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon);
    }

    if (lai != null && PackageManagerHelper.isAppSuspended(lai.getApplicationInfo())) {
        info.isDisabled = ShortcutInfo.FLAG_DISABLED_SUSPENDED;
    }

    // from the db
    if (TextUtils.isEmpty(info.title) && c != null) {
        info.title = iconInfo.getTitle(c);
    }

    // fall back to the class name of the activity
    if (info.title == null) {
        info.title = componentName.getClassName();
    }

    info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
    info.user = user;
    info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
    if (lai != null) {
        info.flags = AppInfo.initFlags(lai);
    }
    return info;
}