Search in sources :

Example 31 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project Neo-Launcher by NeoApplications.

the class LoaderCursor method loadIcon.

/**
 * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
 */
protected boolean loadIcon(WorkspaceItemInfo info, LauncherIcons li) {
    if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
        String packageName = getString(iconPackageIndex);
        String resourceName = getString(iconResourceIndex);
        if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
            info.iconResource = new ShortcutIconResource();
            info.iconResource.packageName = packageName;
            info.iconResource.resourceName = resourceName;
            BitmapInfo iconInfo = li.createIconBitmap(info.iconResource);
            if (iconInfo != null) {
                info.applyFrom(iconInfo);
                return true;
            }
        }
    }
    // Failed to load from resource, try loading from DB.
    byte[] data = getBlob(iconIndex);
    try {
        info.applyFrom(li.createIconBitmap(BitmapFactory.decodeByteArray(data, 0, data.length)));
        return true;
    } catch (Exception e) {
        Log.e(TAG, "Failed to decode byte array for info " + info, e);
        return false;
    }
}
Also used : ShortcutIconResource(android.content.Intent.ShortcutIconResource) BitmapInfo(com.android.launcher3.icons.BitmapInfo) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(java.security.InvalidParameterException)

Example 32 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project Neo-Launcher by NeoApplications.

the class LoaderCursor method loadSimpleWorkspaceItem.

public WorkspaceItemInfo loadSimpleWorkspaceItem() {
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    // Non-app shortcuts are only supported for current user.
    info.user = user;
    info.itemType = itemType;
    info.title = getTitle();
    // the fallback icon
    if (!loadIcon(info)) {
        info.applyFrom(mIconCache.getDefaultIcon(info.user));
    }
    return info;
}
Also used : WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 33 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project Neo-Launcher by NeoApplications.

the class UserEventDispatcher method logTaskLaunchOrDismiss.

@Deprecated
public void logTaskLaunchOrDismiss(int action, int direction, int taskIndex, ComponentKey componentKey) {
    LauncherEvent event = newLauncherEvent(// TAP or SWIPE or FLING
    newTouchAction(action), newTarget(Target.Type.ITEM));
    if (action == Action.Touch.SWIPE || action == Action.Touch.FLING) {
        // Direction DOWN means the task was launched, UP means it was dismissed.
        event.action.dir = direction;
    }
    event.srcTarget[0].itemType = LauncherLogProto.ItemType.TASK;
    event.srcTarget[0].pageIndex = taskIndex;
    fillComponentInfo(event.srcTarget[0], componentKey.componentName);
    dispatchUserEvent(event, null);
    mAppOrTaskLaunch = true;
}
Also used : LauncherEvent(com.android.launcher3.userevent.nano.LauncherLogProto.LauncherEvent) LoggerUtils.newLauncherEvent(com.android.launcher3.logging.LoggerUtils.newLauncherEvent)

Example 34 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project Neo-Launcher by NeoApplications.

the class FolderNameProvider method getSuggestedFolderName.

/**
 * Returns suggested folder name.
 */
public CharSequence getSuggestedFolderName(Context context, ArrayList<WorkspaceItemInfo> workspaceItemInfos, CharSequence[] suggestName) {
    // candidate folder name should be rewritten.
    if (workspaceItemInfos.size() == 2) {
        ComponentName cmp1 = workspaceItemInfos.get(0).getTargetComponent();
        ComponentName cmp2 = workspaceItemInfos.get(1).getTargetComponent();
        String pkgName0 = cmp1 == null ? "" : cmp1.getPackageName();
        String pkgName1 = cmp2 == null ? "" : cmp2.getPackageName();
        // then assign the main icon's name
        if (pkgName0.equals(pkgName1)) {
            WorkspaceItemInfo wInfo0 = workspaceItemInfos.get(0);
            WorkspaceItemInfo wInfo1 = workspaceItemInfos.get(1);
            if (workspaceItemInfos.get(0).itemType == Favorites.ITEM_TYPE_APPLICATION) {
                suggestName[0] = wInfo0.title;
            } else if (wInfo1.itemType == Favorites.ITEM_TYPE_APPLICATION) {
                suggestName[0] = wInfo1.title;
            }
            return suggestName[0];
        // two icons are all shortcuts. Don't assign title
        }
    }
    return suggestName[0];
}
Also used : ComponentName(android.content.ComponentName) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 35 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project android_packages_apps_Trebuchet by LineageOS.

the class PredictionUiStateManager method getAllAppsRank.

/**
 * Returns ranking info for the app within all apps prediction.
 * Only applicable when {@link ItemInfo#itemType} is one of the followings:
 * {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
 * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
 * {@link LauncherSettings.Favorites#ITEM_TYPE_DEEP_SHORTCUT}
 */
public OptionalInt getAllAppsRank(@Nullable ItemInfo itemInfo) {
    if (itemInfo == null || itemInfo.getTargetComponent() == null || itemInfo.user == null) {
        return OptionalInt.empty();
    }
    if (itemInfo.itemType == ITEM_TYPE_APPLICATION || itemInfo.itemType == ITEM_TYPE_SHORTCUT || itemInfo.itemType == ITEM_TYPE_DEEP_SHORTCUT) {
        ComponentKey key = new ComponentKey(itemInfo.getTargetComponent(), itemInfo.user);
        final List<ComponentKeyMapper> apps = getCurrentState().apps;
        return IntStream.range(0, apps.size()).filter(index -> key.equals(apps.get(index).getComponentKey())).findFirst();
    }
    return OptionalInt.empty();
}
Also used : BACKGROUND_APP(com.android.launcher3.LauncherState.BACKGROUND_APP) LauncherLogProto(com.android.launcher3.userevent.nano.LauncherLogProto) IntStream(java.util.stream.IntStream) Context(android.content.Context) NonNull(androidx.annotation.NonNull) ItemInfo(com.android.launcher3.model.data.ItemInfo) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) HotseatPredictionController(com.android.launcher3.hybridhotseat.HotseatPredictionController) OVERVIEW(com.android.launcher3.LauncherState.OVERVIEW) LauncherSettings(com.android.launcher3.LauncherSettings) StateListener(com.android.launcher3.statemanager.StateManager.StateListener) OnUpdateListener(com.android.launcher3.allapps.AllAppsStore.OnUpdateListener) OptionalInt(java.util.OptionalInt) AppTarget(android.app.prediction.AppTarget) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ArrayList(java.util.ArrayList) Utilities(com.android.launcher3.Utilities) MainThreadInitializedObject(com.android.launcher3.util.MainThreadInitializedObject) AppPredictor(android.app.prediction.AppPredictor) Launcher(com.android.launcher3.Launcher) ItemInfoUpdateReceiver(com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver) ComponentName(android.content.ComponentName) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) LauncherAppState(com.android.launcher3.LauncherAppState) ITEM_TYPE_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) LauncherState(com.android.launcher3.LauncherState) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) List(java.util.List) Nullable(androidx.annotation.Nullable) ComponentKey(com.android.launcher3.util.ComponentKey) AllAppsContainerView(com.android.launcher3.allapps.AllAppsContainerView) OnIDPChangeListener(com.android.launcher3.InvariantDeviceProfile.OnIDPChangeListener) Collections(java.util.Collections) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon) ComponentKey(com.android.launcher3.util.ComponentKey)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)19 ComponentName (android.content.ComponentName)14 Intent (android.content.Intent)11 InvalidParameterException (java.security.InvalidParameterException)10 Nullable (androidx.annotation.Nullable)7 LauncherSettings (com.android.launcher3.LauncherSettings)7 ContainerInfo (com.android.launcher3.logger.LauncherAtom.ContainerInfo)7 SuppressLint (android.annotation.SuppressLint)6 Process (android.os.Process)6 ITEM_TYPE_APPLICATION (com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION)6 ITEM_TYPE_DEEP_SHORTCUT (com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)6 ITEM_TYPE_SHORTCUT (com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)6 ItemInfo (com.android.launcher3.model.data.ItemInfo)6 AppWidgetHost (android.appwidget.AppWidgetHost)5 AppWidgetManager (android.appwidget.AppWidgetManager)5 ContentValues (android.content.ContentValues)5 UserHandle (android.os.UserHandle)5 Favorites (com.android.launcher3.LauncherSettings.Favorites)5 CONTAINER_ALL_APPS (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS)5 CONTAINER_DESKTOP (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP)5