Search in sources :

Example 41 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project android_packages_apps_Launcher3 by AOSPA.

the class LauncherProvider method initializeExternalAdd.

private boolean initializeExternalAdd(ContentValues values) {
    // 1. Ensure that externally added items have a valid item id
    int id = mOpenHelper.generateNewItemId();
    values.put(LauncherSettings.Favorites._ID, id);
    // 2. In the case of an app widget, and if no app widget id is specified, we
    // attempt allocate and bind the widget.
    Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
    if (itemType != null && itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) {
        final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext());
        ComponentName cn = ComponentName.unflattenFromString(values.getAsString(Favorites.APPWIDGET_PROVIDER));
        if (cn != null) {
            try {
                AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
                int appWidgetId = widgetHost.allocateAppWidgetId();
                values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
                if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn)) {
                    widgetHost.deleteAppWidgetId(appWidgetId);
                    return false;
                }
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to initialize external widget", e);
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : AppWidgetHost(android.appwidget.AppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 42 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project android_packages_apps_Launcher3 by ArrowOS.

the class LoaderCursor method getRestoredItemInfo.

/**
 * Make an WorkspaceItemInfo object for a restored application or shortcut item that points
 * to a package that is not yet installed on the system.
 */
public WorkspaceItemInfo getRestoredItemInfo(Intent intent) {
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.user = user;
    info.intent = intent;
    // the fallback icon
    if (!loadIcon(info)) {
        mIconCache.getTitleAndIcon(info, false);
    }
    if (hasRestoreFlag(WorkspaceItemInfo.FLAG_RESTORED_ICON)) {
        String title = getTitle();
        if (!TextUtils.isEmpty(title)) {
            info.title = Utilities.trim(title);
        }
    } else if (hasRestoreFlag(WorkspaceItemInfo.FLAG_AUTOINSTALL_ICON)) {
        if (TextUtils.isEmpty(info.title)) {
            info.title = getTitle();
        }
    } else {
        throw new InvalidParameterException("Invalid restoreType " + restoreFlag);
    }
    info.contentDescription = mPM.getUserBadgedLabel(info.title, info.user);
    info.itemType = itemType;
    info.status = restoreFlag;
    return info;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 43 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project android_packages_apps_Launcher3 by ArrowOS.

the class ItemInfo method buildProto.

/**
 * Creates {@link LauncherAtom.ItemInfo} with important fields and parent container info.
 */
public LauncherAtom.ItemInfo buildProto(FolderInfo fInfo) {
    LauncherAtom.ItemInfo.Builder itemBuilder = getDefaultItemInfoBuilder();
    Optional<ComponentName> nullableComponent = Optional.ofNullable(getTargetComponent());
    switch(itemType) {
        case ITEM_TYPE_APPLICATION:
            itemBuilder.setApplication(nullableComponent.map(component -> LauncherAtom.Application.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Application.newBuilder()));
            break;
        case ITEM_TYPE_DEEP_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> {
                Shortcut.Builder lsb = Shortcut.newBuilder().setShortcutName(component.flattenToShortString());
                Optional.ofNullable(getIntent()).map(i -> i.getStringExtra(EXTRA_SHORTCUT_ID)).ifPresent(lsb::setShortcutId);
                return lsb;
            }).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> LauncherAtom.Shortcut.newBuilder().setShortcutName(component.flattenToShortString())).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_APPWIDGET:
            itemBuilder.setWidget(nullableComponent.map(component -> LauncherAtom.Widget.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Widget.newBuilder()).setSpanX(spanX).setSpanY(spanY));
            break;
        case ITEM_TYPE_TASK:
            itemBuilder.setTask(LauncherAtom.Task.newBuilder().setComponentName(getTargetComponent().flattenToShortString()).setIndex(screenId));
            break;
        default:
            break;
    }
    if (fInfo != null) {
        LauncherAtom.FolderContainer.Builder folderBuilder = LauncherAtom.FolderContainer.newBuilder();
        folderBuilder.setGridX(cellX).setGridY(cellY).setPageIndex(screenId);
        switch(fInfo.container) {
            case CONTAINER_HOTSEAT:
            case CONTAINER_HOTSEAT_PREDICTION:
                folderBuilder.setHotseat(LauncherAtom.HotseatContainer.newBuilder().setIndex(fInfo.screenId));
                break;
            case CONTAINER_DESKTOP:
                folderBuilder.setWorkspace(LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(fInfo.screenId).setGridX(fInfo.cellX).setGridY(fInfo.cellY));
                break;
        }
        itemBuilder.setContainerInfo(ContainerInfo.newBuilder().setFolder(folderBuilder));
    } else {
        ContainerInfo containerInfo = getContainerInfo();
        if (!containerInfo.getContainerCase().equals(CONTAINER_NOT_SET)) {
            itemBuilder.setContainerInfo(containerInfo);
        }
    }
    return itemBuilder.build();
}
Also used : ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) CONTAINER_WIDGETS_TRAY(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) Intent(android.content.Intent) LauncherSettings(com.android.launcher3.LauncherSettings) Process(android.os.Process) AllAppsContainer(com.android.launcher3.logger.LauncherAtom.AllAppsContainer) SearchResultContainer(com.android.launcher3.logger.LauncherAtom.SearchResultContainer) CONTAINER_TASKSWITCHER(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_TASKSWITCHER) WallpapersContainer(com.android.launcher3.logger.LauncherAtom.WallpapersContainer) CONTAINER_HOTSEAT(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT) LauncherAtom(com.android.launcher3.logger.LauncherAtom) ITEM_TYPE_APPWIDGET(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) UserHandle(android.os.UserHandle) TaskSwitcherContainer(com.android.launcher3.logger.LauncherAtom.TaskSwitcherContainer) ExtendedContainers(com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) EXTRA_SHORTCUT_ID(com.android.launcher3.shortcuts.ShortcutKey.EXTRA_SHORTCUT_ID) Favorites(com.android.launcher3.LauncherSettings.Favorites) ComponentName(android.content.ComponentName) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) ITEM_TYPE_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) CONTAINER_DESKTOP(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP) CONTAINER_SEARCH_RESULTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SEARCH_RESULTS) CONTAINER_HOTSEAT_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) ShortcutsContainer(com.android.launcher3.logger.LauncherAtom.ShortcutsContainer) CONTAINER_WALLPAPERS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WALLPAPERS) Nullable(androidx.annotation.Nullable) PredictionContainer(com.android.launcher3.logger.LauncherAtom.PredictionContainer) ITEM_TYPE_TASK(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_TASK) ContentWriter(com.android.launcher3.util.ContentWriter) EXTENDED_CONTAINERS(com.android.launcher3.LauncherSettings.Favorites.EXTENDED_CONTAINERS) CONTAINER_SETTINGS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SETTINGS) CONTAINER_NOT_SET(com.android.launcher3.logger.LauncherAtom.ContainerInfo.ContainerCase.CONTAINER_NOT_SET) Optional(java.util.Optional) Workspace(com.android.launcher3.Workspace) CONTAINER_ALL_APPS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS) ContentValues(android.content.ContentValues) CONTAINER_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PREDICTION) SettingsContainer(com.android.launcher3.logger.LauncherAtom.SettingsContainer) ModelWriter(com.android.launcher3.model.ModelWriter) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) ComponentName(android.content.ComponentName)

Example 44 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherProvider method initializeExternalAdd.

private boolean initializeExternalAdd(ContentValues values) {
    // 1. Ensure that externally added items have a valid item id
    int id = mOpenHelper.generateNewItemId();
    values.put(LauncherSettings.Favorites._ID, id);
    // 2. In the case of an app widget, and if no app widget id is specified, we
    // attempt allocate and bind the widget.
    Integer itemType = values.getAsInteger(LauncherSettings.Favorites.ITEM_TYPE);
    if (itemType != null && itemType.intValue() == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && !values.containsKey(LauncherSettings.Favorites.APPWIDGET_ID)) {
        final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext());
        ComponentName cn = ComponentName.unflattenFromString(values.getAsString(Favorites.APPWIDGET_PROVIDER));
        if (cn != null) {
            try {
                AppWidgetHost widgetHost = mOpenHelper.newLauncherWidgetHost();
                int appWidgetId = widgetHost.allocateAppWidgetId();
                values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
                if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn)) {
                    widgetHost.deleteAppWidgetId(appWidgetId);
                    return false;
                }
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to initialize external widget", e);
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : AppWidgetHost(android.appwidget.AppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 45 with ItemType

use of com.android.launcher3.userevent.nano.LauncherLogProto.ItemType in project android_packages_apps_Launcher3 by ProtonAOSP.

the class Folder method acceptDrop.

@Override
public boolean acceptDrop(DragObject d) {
    final ItemInfo item = d.dragInfo;
    final int itemType = item.itemType;
    return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT || itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT));
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) SuppressLint(android.annotation.SuppressLint)

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