Search in sources :

Example 16 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by AOSPA.

the class ItemClickHandler method onClickPendingWidget.

/**
 * Event handler for the app widget view which has not fully restored.
 */
private static void onClickPendingWidget(PendingAppWidgetHostView v, Launcher launcher) {
    if (launcher.getPackageManager().isSafeMode()) {
        Toast.makeText(launcher, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
        return;
    }
    final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
    if (v.isReadyForClickSetup()) {
        LauncherAppWidgetProviderInfo appWidgetInfo = new WidgetManagerHelper(launcher).findProvider(info.providerName, info.user);
        if (appWidgetInfo == null) {
            return;
        }
        WidgetAddFlowHandler addFlowHandler = new WidgetAddFlowHandler(appWidgetInfo);
        if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
                // This should not happen, as we make sure that an Id is allocated during bind.
                return;
            }
            addFlowHandler.startBindFlow(launcher, info.appWidgetId, info, REQUEST_BIND_PENDING_APPWIDGET);
        } else {
            addFlowHandler.startConfigActivity(launcher, info, REQUEST_RECONFIGURE_APPWIDGET);
        }
    } else {
        final String packageName = info.providerName.getPackageName();
        onClickPendingAppItem(v, launcher, packageName, info.installProgress >= 0);
    }
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler)

Example 17 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by AOSPA.

the class ItemClickHandler method onClick.

private static void onClick(View v) {
    // view has detached (it's possible for this to happen if the view is removed mid touch).
    if (v.getWindowToken() == null)
        return;
    Launcher launcher = Launcher.getLauncher(v.getContext());
    if (!launcher.getWorkspace().isFinishedSwitchingState())
        return;
    Object tag = v.getTag();
    if (tag instanceof WorkspaceItemInfo) {
        onClickAppShortcut(v, (WorkspaceItemInfo) tag, launcher);
    } else if (tag instanceof FolderInfo) {
        if (v instanceof FolderIcon) {
            onClickFolderIcon(v);
        }
    } else if (tag instanceof AppInfo) {
        startAppShortcutOrInfoActivity(v, (AppInfo) tag, launcher);
    } else if (tag instanceof LauncherAppWidgetInfo) {
        if (v instanceof PendingAppWidgetHostView) {
            onClickPendingWidget((PendingAppWidgetHostView) v, launcher);
        }
    } else if (tag instanceof SearchActionItemInfo) {
        onClickSearchAction(launcher, (SearchActionItemInfo) tag);
    }
}
Also used : FolderIcon(com.android.launcher3.folder.FolderIcon) Launcher(com.android.launcher3.Launcher) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 18 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by AOSPA.

the class Workspace method updateWorkspaceWidgetsSizes.

private void updateWorkspaceWidgetsSizes() {
    int numberOfScreens = mScreenOrder.size();
    for (int i = 0; i < numberOfScreens; i++) {
        ShortcutAndWidgetContainer shortcutAndWidgetContainer = mWorkspaceScreens.get(mScreenOrder.get(i)).getShortcutsAndWidgets();
        int shortcutsAndWidgetCount = shortcutAndWidgetContainer.getChildCount();
        for (int j = 0; j < shortcutsAndWidgetCount; j++) {
            View view = shortcutAndWidgetContainer.getChildAt(j);
            if (view instanceof LauncherAppWidgetHostView && view.getTag() instanceof LauncherAppWidgetInfo) {
                LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) view.getTag();
                WidgetSizes.updateWidgetSizeRanges((LauncherAppWidgetHostView) view, mLauncher, launcherAppWidgetInfo.spanX, launcherAppWidgetInfo.spanY);
            }
        }
    }
}
Also used : LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 19 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by AOSPA.

the class WidgetUtils method createWidgetInfo.

/**
 * Creates a LauncherAppWidgetInfo corresponding to {@param info}
 *
 * @param bindWidget if true the info is bound and a valid widgetId is assigned to
 *                   the LauncherAppWidgetInfo
 */
public static LauncherAppWidgetInfo createWidgetInfo(LauncherAppWidgetProviderInfo info, Context targetContext, boolean bindWidget) {
    LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(LauncherAppWidgetInfo.NO_ID, info.provider);
    item.spanX = info.minSpanX;
    item.spanY = info.minSpanY;
    item.minSpanX = info.minSpanX;
    item.minSpanY = info.minSpanY;
    item.user = info.getProfile();
    item.cellX = 0;
    item.cellY = 1;
    item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    if (bindWidget) {
        PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(info, LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY);
        pendingInfo.spanX = item.spanX;
        pendingInfo.spanY = item.spanY;
        pendingInfo.minSpanX = item.minSpanX;
        pendingInfo.minSpanY = item.minSpanY;
        Bundle options = pendingInfo.getDefaultSizeOptions(targetContext);
        AppWidgetHost host = new LauncherAppWidgetHost(targetContext);
        int widgetId = host.allocateAppWidgetId();
        if (!new WidgetManagerHelper(targetContext).bindAppWidgetIdIfAllowed(widgetId, info, options)) {
            host.deleteAppWidgetId(widgetId);
            throw new IllegalArgumentException("Unable to bind widget id");
        }
        item.appWidgetId = widgetId;
    }
    return item;
}
Also used : PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) AppWidgetHost(android.appwidget.AppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) Bundle(android.os.Bundle) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo)

Example 20 with LauncherAppWidgetInfo

use of com.android.launcher3.model.data.LauncherAppWidgetInfo in project android_packages_apps_Launcher3 by AOSPA.

the class BindWidgetTest method getInvalidWidgetInfo.

/**
 * Returns a LauncherAppWidgetInfo with package name which is not present on the device
 */
private LauncherAppWidgetInfo getInvalidWidgetInfo() {
    String invalidPackage = "com.invalidpackage";
    int count = 0;
    String pkg = invalidPackage;
    Set<String> activePackage = getOnUiThread(() -> {
        Set<String> packages = new HashSet<>();
        InstallSessionHelper.INSTANCE.get(mTargetContext).getActiveSessions().keySet().forEach(packageUserKey -> packages.add(packageUserKey.mPackageName));
        return packages;
    });
    while (true) {
        try {
            mTargetContext.getPackageManager().getPackageInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (Exception e) {
            if (!activePackage.contains(pkg)) {
                break;
            }
        }
        pkg = invalidPackage + count;
        count++;
    }
    LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(10, new ComponentName(pkg, "com.test.widgetprovider"));
    item.spanX = 2;
    item.spanY = 2;
    item.minSpanX = 2;
    item.minSpanY = 2;
    item.cellX = 0;
    item.cellY = 1;
    item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    return item;
}
Also used : LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet)

Aggregations

LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)201 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)73 LargeTest (androidx.test.filters.LargeTest)70 AbstractLauncherUiTest (com.android.launcher3.ui.AbstractLauncherUiTest)70 Test (org.junit.Test)70 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)68 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)61 ItemInfo (com.android.launcher3.model.data.ItemInfo)56 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)55 ArrayList (java.util.ArrayList)54 AppWidgetHostView (android.appwidget.AppWidgetHostView)53 View (android.view.View)50 FolderInfo (com.android.launcher3.model.data.FolderInfo)48 DragView (com.android.launcher3.dragndrop.DragView)41 HashSet (java.util.HashSet)38 AppInfo (com.android.launcher3.model.data.AppInfo)37 ComponentName (android.content.ComponentName)33 IntArray (com.android.launcher3.util.IntArray)31 Point (android.graphics.Point)30 Bundle (android.os.Bundle)30