Search in sources :

Example 41 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class BaseLoaderResults method bindAppWidgets.

private void bindAppWidgets(ArrayList<LauncherAppWidgetInfo> appWidgets, Executor executor) {
    // Bind the widgets, one at a time
    int N;
    N = appWidgets.size();
    for (int i = 0; i < N; i++) {
        final ItemInfo widget = appWidgets.get(i);
        executeCallbacksTask(c -> c.bindItems(Collections.singletonList(widget), false), executor);
    }
}
Also used : ItemInfo(com.android.launcher3.ItemInfo)

Example 42 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class PopupContainerWithArrow method onWidgetsBound.

@Override
public void onWidgetsBound() {
    ItemInfo itemInfo = (ItemInfo) mOriginalIcon.getTag();
    SystemShortcut widgetInfo = new SystemShortcut.Widgets();
    View.OnClickListener onClickListener = widgetInfo.getOnClickListener(mLauncher, itemInfo);
    View widgetsView = null;
    int count = mSystemShortcutContainer.getChildCount();
    for (int i = 0; i < count; i++) {
        View systemShortcutView = mSystemShortcutContainer.getChildAt(i);
        if (systemShortcutView.getTag() instanceof SystemShortcut.Widgets) {
            widgetsView = systemShortcutView;
            break;
        }
    }
    if (onClickListener != null && widgetsView == null) {
        // We didn't have any widgets cached but now there are some, so enable the shortcut.
        if (mSystemShortcutContainer != this) {
            initializeSystemShortcut(R.layout.system_shortcut_icon_only, mSystemShortcutContainer, widgetInfo);
        } else {
            // If using the expanded system shortcut (as opposed to just the icon), we need to
            // reopen the container to ensure measurements etc. all work out. While this could
            // be quite janky, in practice the user would typically see a small flicker as the
            // animation restarts partway through, and this is a very rare edge case anyway.
            close(false);
            PopupContainerWithArrow.showForIcon(mOriginalIcon);
        }
    } else if (onClickListener == null && widgetsView != null) {
        // No widgets exist, but we previously added the shortcut so remove it.
        if (mSystemShortcutContainer != this) {
            mSystemShortcutContainer.removeView(widgetsView);
        } else {
            close(false);
            PopupContainerWithArrow.showForIcon(mOriginalIcon);
        }
    }
}
Also used : ItemInfo(com.android.launcher3.ItemInfo) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) NotificationItemView(com.android.launcher3.notification.NotificationItemView) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) DragView(com.android.launcher3.dragndrop.DragView) Point(android.graphics.Point)

Example 43 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class PackageUpdatedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList) {
    if (TestProtocol.sDebugTracing) {
        Log.d(TestProtocol.APP_NOT_DISABLED, "PackageUpdatedTask: " + mOp + ", " + Arrays.toString(mPackages));
    }
    final Context context = app.getContext();
    final IconCache iconCache = app.getIconCache();
    final String[] packages = mPackages;
    final int N = packages.length;
    FlagOp flagOp = FlagOp.NO_OP;
    final HashSet<String> packageSet = new HashSet<>(Arrays.asList(packages));
    ItemInfoMatcher matcher = ItemInfoMatcher.ofPackages(packageSet, mUser);
    final HashSet<ComponentName> removedComponents = new HashSet<>();
    switch(mOp) {
        case OP_ADD:
            {
                for (int i = 0; i < N; i++) {
                    if (DEBUG)
                        Log.d(TAG, "mAllAppsList.addPackage " + packages[i]);
                    iconCache.updateIconsForPkg(packages[i], mUser);
                    if (FeatureFlags.LAUNCHER3_PROMISE_APPS_IN_ALL_APPS) {
                        appsList.removePackage(packages[i], mUser);
                    }
                    appsList.addPackage(context, packages[i], mUser);
                    OmegaPreferences prefs = Utilities.getOmegaPrefs(context);
                    // Automatically add homescreen icon for work profile apps for below O device.
                    if (Utilities.ATLEAST_OREO && prefs.getAutoAddInstalled() && !OmegaUtilsKt.workspaceContains(dataModel, packages[i])) {
                        SessionCommitReceiver.queueAppIconAddition(context, packages[i], mUser);
                    } else if (!Utilities.ATLEAST_OREO && !Process.myUserHandle().equals(mUser)) {
                        SessionCommitReceiver.queueAppIconAddition(context, packages[i], mUser);
                    }
                }
                flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
                break;
            }
        case OP_UPDATE:
            try (SafeCloseable t = appsList.trackRemoves(a -> removedComponents.add(a.componentName))) {
                for (String aPackage : packages) {
                    if (DEBUG)
                        Log.d(TAG, "mAllAppsList.updatePackage " + aPackage);
                    iconCache.updateIconsForPkg(aPackage, mUser);
                    appsList.updatePackage(context, aPackage, mUser);
                    app.getWidgetCache().removePackage(aPackage, mUser);
                }
            }
            // Since package was just updated, the target must be available now.
            flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
            break;
        case OP_REMOVE:
            {
                for (String aPackage : packages) {
                    FileLog.d(TAG, "Removing app icon" + aPackage);
                    iconCache.removeIconsForPkg(aPackage, mUser);
                }
            // Fall through
            }
        case OP_UNAVAILABLE:
            for (int i = 0; i < N; i++) {
                if (DEBUG)
                    Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
                appsList.removePackage(packages[i], mUser);
                app.getWidgetCache().removePackage(packages[i], mUser);
            }
            flagOp = FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
            break;
        case OP_SUSPEND:
        case OP_UNSUSPEND:
            flagOp = mOp == OP_SUSPEND ? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED) : FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_SUSPENDED);
            if (DEBUG)
                Log.d(TAG, "mAllAppsList.(un)suspend " + N);
            appsList.updateDisabledFlags(matcher, flagOp);
            break;
        case OP_USER_AVAILABILITY_CHANGE:
            flagOp = UserManagerCompat.getInstance(context).isQuietModeEnabled(mUser) ? FlagOp.addFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER) : FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_QUIET_USER);
            // We want to update all packages for this user.
            matcher = ItemInfoMatcher.ofUser(mUser);
            appsList.updateDisabledFlags(matcher, flagOp);
            break;
        case OP_RELOAD:
            if (DEBUG)
                Log.d(TAG, "mAllAppsList.reloadPackages");
            appsList.reloadPackages(context, mUser);
            break;
    }
    bindApplicationsIfNeeded();
    final IntSparseArrayMap<Boolean> removedShortcuts = new IntSparseArrayMap<>();
    // Update shortcut infos
    if (mOp == OP_ADD || flagOp != FlagOp.NO_OP) {
        final ArrayList<WorkspaceItemInfo> updatedWorkspaceItems = new ArrayList<>();
        final ArrayList<LauncherAppWidgetInfo> widgets = new ArrayList<>();
        // For system apps, package manager send OP_UPDATE when an app is enabled.
        final boolean isNewApkAvailable = mOp == OP_ADD || mOp == OP_UPDATE;
        synchronized (dataModel) {
            for (ItemInfo info : dataModel.itemsIdMap) {
                if (info instanceof WorkspaceItemInfo && mUser.equals(info.user)) {
                    WorkspaceItemInfo si = (WorkspaceItemInfo) info;
                    boolean infoUpdated = false;
                    boolean shortcutUpdated = false;
                    // Update shortcuts which use iconResource.
                    if ((si.iconResource != null) && packageSet.contains(si.iconResource.packageName)) {
                        LauncherIcons li = LauncherIcons.obtain(context);
                        BitmapInfo iconInfo = li.createIconBitmap(si.iconResource);
                        li.recycle();
                        if (iconInfo != null) {
                            si.applyFrom(iconInfo);
                            infoUpdated = true;
                        }
                    }
                    ComponentName cn = si.getTargetComponent();
                    if (cn != null && matcher.matches(si, cn)) {
                        String packageName = cn.getPackageName();
                        if (si.hasStatusFlag(WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI)) {
                            removedShortcuts.put(si.id, false);
                            if (mOp == OP_REMOVE) {
                                continue;
                            }
                        }
                        if (si.isPromise() && isNewApkAvailable) {
                            boolean isTargetValid = true;
                            if (si.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                                List<ShortcutInfo> shortcut = DeepShortcutManager.getInstance(context).queryForPinnedShortcuts(cn.getPackageName(), Arrays.asList(si.getDeepShortcutId()), mUser);
                                if (shortcut.isEmpty()) {
                                    isTargetValid = false;
                                } else {
                                    si.updateFromDeepShortcutInfo(shortcut.get(0), context);
                                    infoUpdated = true;
                                }
                            } else if (!cn.getClassName().equals(IconCache.EMPTY_CLASS_NAME)) {
                                isTargetValid = LauncherAppsCompat.getInstance(context).isActivityEnabledForProfile(cn, mUser);
                            }
                            if (si.hasStatusFlag(FLAG_RESTORED_ICON | FLAG_AUTOINSTALL_ICON)) {
                                if (updateWorkspaceItemIntent(context, si, packageName)) {
                                    infoUpdated = true;
                                } else if (si.hasPromiseIconUi()) {
                                    removedShortcuts.put(si.id, true);
                                    continue;
                                }
                            } else if (!isTargetValid) {
                                removedShortcuts.put(si.id, true);
                                FileLog.e(TAG, "Restored shortcut no longer valid " + si.intent);
                                continue;
                            } else {
                                si.status = WorkspaceItemInfo.DEFAULT;
                                infoUpdated = true;
                            }
                        } else if (isNewApkAvailable && removedComponents.contains(cn)) {
                            if (updateWorkspaceItemIntent(context, si, packageName)) {
                                infoUpdated = true;
                            }
                        }
                        if (isNewApkAvailable && si.itemType == Favorites.ITEM_TYPE_APPLICATION) {
                            iconCache.getTitleAndIcon(si, si.usingLowResIcon());
                            infoUpdated = true;
                        }
                        int oldRuntimeFlags = si.runtimeStatusFlags;
                        si.runtimeStatusFlags = flagOp.apply(si.runtimeStatusFlags);
                        if (si.runtimeStatusFlags != oldRuntimeFlags) {
                            shortcutUpdated = true;
                        }
                    }
                    if (infoUpdated || shortcutUpdated) {
                        updatedWorkspaceItems.add(si);
                    }
                    if (infoUpdated) {
                        getModelWriter().updateItemInDatabase(si);
                    }
                } else if (info instanceof LauncherAppWidgetInfo && isNewApkAvailable) {
                    LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) info;
                    if (mUser.equals(widgetInfo.user) && widgetInfo.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) && packageSet.contains(widgetInfo.providerName.getPackageName())) {
                        widgetInfo.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY & ~LauncherAppWidgetInfo.FLAG_RESTORE_STARTED;
                        // adding this flag ensures that launcher shows 'click to setup'
                        // if the widget has a config activity. In case there is no config
                        // activity, it will be marked as 'restored' during bind.
                        widgetInfo.restoreStatus |= LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
                        widgets.add(widgetInfo);
                        getModelWriter().updateItemInDatabase(widgetInfo);
                    }
                }
            }
        }
        bindUpdatedWorkspaceItems(updatedWorkspaceItems);
        if (!removedShortcuts.isEmpty()) {
            deleteAndBindComponentsRemoved(ItemInfoMatcher.ofItemIds(removedShortcuts, false));
        }
        if (!widgets.isEmpty()) {
            scheduleCallbackTask(c -> c.bindWidgetsRestored(widgets));
        }
    }
    final HashSet<String> removedPackages = new HashSet<>();
    if (mOp == OP_REMOVE) {
        // Mark all packages in the broadcast to be removed
        Collections.addAll(removedPackages, packages);
    // No need to update the removedComponents as
    // removedPackages is a super-set of removedComponents
    } else if (mOp == OP_UPDATE) {
        // Mark disabled packages in the broadcast to be removed
        final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
        for (int i = 0; i < N; i++) {
            if (!launcherApps.isPackageEnabledForProfile(packages[i], mUser)) {
                removedPackages.add(packages[i]);
            }
        }
    }
    if (!removedPackages.isEmpty() || !removedComponents.isEmpty()) {
        ItemInfoMatcher removeMatch = ItemInfoMatcher.ofPackages(removedPackages, mUser).or(ItemInfoMatcher.ofComponents(removedComponents, mUser)).and(ItemInfoMatcher.ofItemIds(removedShortcuts, true));
        deleteAndBindComponentsRemoved(removeMatch);
        // Remove any queued items from the install queue
        InstallShortcutReceiver.removeFromInstallQueue(context, removedPackages, mUser);
    }
    if (Utilities.ATLEAST_OREO && mOp == OP_ADD) {
        // AppWidgetHost events, this is just to initialize the long-press options.
        for (int i = 0; i < N; i++) {
            dataModel.widgetsModel.update(app, new PackageUserKey(packages[i], mUser));
        }
        bindUpdatedWidgets(dataModel);
    }
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) ItemInfo(com.android.launcher3.ItemInfo) IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) ArrayList(java.util.ArrayList) OmegaPreferences(com.saggitt.omega.OmegaPreferences) IconCache(com.android.launcher3.icons.IconCache) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) ComponentName(android.content.ComponentName) FlagOp(com.android.launcher3.util.FlagOp) HashSet(java.util.HashSet) Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) LauncherIcons(com.android.launcher3.icons.LauncherIcons) SafeCloseable(com.android.launcher3.util.SafeCloseable) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 44 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class AbstractLauncherUiTest method checkLauncherIntegrity.

private static void checkLauncherIntegrity(Launcher launcher, ContainerType expectedContainerType) {
    if (launcher != null) {
        final LauncherStateManager stateManager = launcher.getStateManager();
        final LauncherState stableState = stateManager.getCurrentStableState();
        assertTrue("Stable state != state: " + stableState.getClass().getSimpleName() + ", " + stateManager.getState().getClass().getSimpleName(), stableState == stateManager.getState());
        final boolean isResumed = launcher.hasBeenResumed();
        assertTrue("hasBeenResumed() != isStarted(), hasBeenResumed(): " + isResumed, isResumed == launcher.isStarted());
        assertTrue("hasBeenResumed() != isUserActive(), hasBeenResumed(): " + isResumed, isResumed == launcher.isUserActive());
        final int ordinal = stableState.ordinal;
        switch(expectedContainerType) {
            case WORKSPACE:
            case WIDGETS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            case ALL_APPS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.ALL_APPS_STATE_ORDINAL);
                    break;
                }
            case OVERVIEW:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.OVERVIEW_STATE_ORDINAL);
                    break;
                }
            case BACKGROUND:
                {
                    assertTrue("Launcher is resumed in state: " + expectedContainerType, !isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            default:
                throw new IllegalArgumentException("Illegal container: " + expectedContainerType);
        }
    } else {
        assertTrue("Container type is not BACKGROUND or FALLBACK_OVERVIEW: " + expectedContainerType, expectedContainerType == ContainerType.BACKGROUND || expectedContainerType == ContainerType.FALLBACK_OVERVIEW);
    }
}
Also used : LauncherState(com.android.launcher3.LauncherState) LauncherStateManager(com.android.launcher3.LauncherStateManager)

Example 45 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class WidgetsModel method setWidgetsAndShortcuts.

private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts, LauncherAppState app, @Nullable PackageUserKey packageUser) {
    if (DEBUG) {
        Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
    }
    // Temporary list for {@link PackageItemInfos} to avoid having to go through
    // {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
    HashMap<String, PackageItemInfo> tmpPackageItemInfos = new HashMap<>();
    // clear the lists.
    if (packageUser == null) {
        mWidgetsList.clear();
    } else {
        // Only clear the widgets for the given package/user.
        PackageItemInfo packageItem = null;
        for (PackageItemInfo item : mWidgetsList.keySet()) {
            if (item.packageName.equals(packageUser.mPackageName)) {
                packageItem = item;
                break;
            }
        }
        if (packageItem != null) {
            // We want to preserve the user that was on the packageItem previously,
            // so add it to tmpPackageItemInfos here to avoid creating a new entry.
            tmpPackageItemInfos.put(packageItem.packageName, packageItem);
            Iterator<WidgetItem> widgetItemIterator = mWidgetsList.get(packageItem).iterator();
            while (widgetItemIterator.hasNext()) {
                WidgetItem nextWidget = widgetItemIterator.next();
                if (nextWidget.componentName.getPackageName().equals(packageUser.mPackageName) && nextWidget.user.equals(packageUser.mUser)) {
                    widgetItemIterator.remove();
                }
            }
        }
    }
    InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
    UserHandle myUser = Process.myUserHandle();
    // add and update.
    for (WidgetItem item : rawWidgetsShortcuts) {
        if (item.widgetInfo != null) {
            if ((item.widgetInfo.getWidgetFeatures() & WIDGET_FEATURE_HIDE_FROM_PICKER) != 0) {
                // Widget is hidden from picker
                continue;
            }
            // Ensure that all widgets we show can be added on a workspace of this size
            int minSpanX = Math.min(item.widgetInfo.spanX, item.widgetInfo.minSpanX);
            int minSpanY = Math.min(item.widgetInfo.spanY, item.widgetInfo.minSpanY);
            if (minSpanX > idp.numColumns || minSpanY > idp.numRows) {
                if (DEBUG) {
                    Log.d(TAG, String.format("Widget %s : (%d X %d) can't fit on this device", item.componentName, minSpanX, minSpanY));
                }
                continue;
            }
        }
        if (mAppFilter == null) {
            mAppFilter = AppFilter.newInstance(app.getContext());
        }
        if (!mAppFilter.shouldShowApp(item.componentName, item.user)) {
            if (DEBUG) {
                Log.d(TAG, String.format("%s is filtered and not added to the widget tray.", item.componentName));
            }
            continue;
        }
        String packageName = item.componentName.getPackageName();
        PackageItemInfo pInfo = tmpPackageItemInfos.get(packageName);
        if (pInfo == null) {
            pInfo = new PackageItemInfo(packageName);
            pInfo.user = item.user;
            tmpPackageItemInfos.put(packageName, pInfo);
        } else if (!myUser.equals(pInfo.user)) {
            // Keep updating the user, until we get the primary user.
            pInfo.user = item.user;
        }
        mWidgetsList.addToList(pInfo, item);
    }
    // Update each package entry
    IconCache iconCache = app.getIconCache();
    for (PackageItemInfo p : tmpPackageItemInfos.values()) {
        iconCache.getTitleAndIconForApp(p, true);
    }
}
Also used : HashMap(java.util.HashMap) MultiHashMap(com.android.launcher3.util.MultiHashMap) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache)

Aggregations

ArrayList (java.util.ArrayList)64 Test (org.junit.Test)64 WidgetItem (com.android.launcher3.model.WidgetItem)54 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)54 PackageUserKey (com.android.launcher3.util.PackageUserKey)50 List (java.util.List)50 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)46 SmallTest (androidx.test.filters.SmallTest)44 ComponentName (android.content.ComponentName)42 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)41 Point (android.graphics.Point)40 View (android.view.View)37 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)32 Collectors (java.util.stream.Collectors)31 Context (android.content.Context)29 IconCache (com.android.launcher3.icons.IconCache)29 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)29 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)29 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)27 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)27