Search in sources :

Example 76 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Launcher3 by AOSPA.

the class ModelUtils method fromLegacyShortcutIntent.

/**
 * Creates a workspace item info for the legacy shortcut intent
 */
@SuppressWarnings("deprecation")
public static WorkspaceItemInfo fromLegacyShortcutIntent(Context context, Intent data) {
    if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.class)) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {
        Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }
    Intent launchIntent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String label = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (launchIntent == null || label == null) {
        Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.user = Process.myUserHandle();
    BitmapInfo iconInfo = null;
    try (LauncherIcons li = LauncherIcons.obtain(context)) {
        Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
        if (bitmap != null) {
            iconInfo = li.createIconBitmap(bitmap);
        } else {
            info.iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (info.iconResource != null) {
                iconInfo = li.createIconBitmap(info.iconResource);
            }
        }
    }
    if (iconInfo == null) {
        Log.e(TAG, "Invalid icon by the app");
        return null;
    }
    info.bitmap = iconInfo;
    info.contentDescription = info.title = Utilities.trim(label);
    info.intent = launchIntent;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Intent(android.content.Intent) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 77 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Launcher3 by AOSPA.

the class ModelUtils method getMissingHotseatRanks.

/**
 * Iterates though current workspace items and returns available hotseat ranks for prediction.
 */
public static IntArray getMissingHotseatRanks(List<ItemInfo> items, int len) {
    IntSet seen = new IntSet();
    items.stream().filter(info -> info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT).forEach(i -> seen.add(i.screenId));
    IntArray result = new IntArray(len);
    IntStream.range(0, len).filter(i -> !seen.contains(i)).forEach(result::add);
    return result;
}
Also used : Utilities(com.android.launcher3.Utilities) IntStream(java.util.stream.IntStream) Context(android.content.Context) IntArray(com.android.launcher3.util.IntArray) Utilities.isValidExtraType(com.android.launcher3.Utilities.isValidExtraType) ItemInfo(com.android.launcher3.model.data.ItemInfo) TestProtocol(com.android.launcher3.testing.TestProtocol) Intent(android.content.Intent) FeatureFlags(com.android.launcher3.config.FeatureFlags) LauncherSettings(com.android.launcher3.LauncherSettings) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Process(android.os.Process) ArrayList(java.util.ArrayList) BitmapInfo(com.android.launcher3.icons.BitmapInfo) Objects(java.util.Objects) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) IntSet(com.android.launcher3.util.IntSet) List(java.util.List) Bitmap(android.graphics.Bitmap) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Collections(java.util.Collections) Log(android.util.Log) IntArray(com.android.launcher3.util.IntArray) IntSet(com.android.launcher3.util.IntSet)

Example 78 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Launcher3 by AOSPA.

the class UserLockStateChangedTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
    if (mIsUserUnlocked) {
        QueryResult shortcuts = new ShortcutRequest(context, mUser).query(ShortcutRequest.PINNED);
        if (shortcuts.wasSuccess()) {
            for (ShortcutInfo shortcut : shortcuts) {
                pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut);
            }
        } else {
            // Shortcut manager can fail due to some race condition when the lock state
            // changes too frequently. For the purpose of the update,
            // consider it as still locked.
            mIsUserUnlocked = false;
        }
    }
    // Update the workspace to reflect the changes to updated shortcuts residing on it.
    ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>();
    HashSet<ShortcutKey> removedKeys = new HashSet<>();
    synchronized (dataModel) {
        dataModel.forAllWorkspaceItemInfos(mUser, si -> {
            if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                if (mIsUserUnlocked) {
                    ShortcutKey key = ShortcutKey.fromItemInfo(si);
                    ShortcutInfo shortcut = pinnedShortcuts.get(key);
                    // (probably due to clear data), delete the workspace item as well
                    if (shortcut == null) {
                        removedKeys.add(key);
                        return;
                    }
                    si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
                    si.updateFromDeepShortcutInfo(shortcut, context);
                    app.getIconCache().getShortcutIcon(si, shortcut);
                } else {
                    si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
                }
                updatedWorkspaceItemInfos.add(si);
            }
        });
    }
    bindUpdatedWorkspaceItems(updatedWorkspaceItemInfos);
    if (!removedKeys.isEmpty()) {
        deleteAndBindComponentsRemoved(ItemInfoMatcher.ofShortcutKeys(removedKeys));
    }
    // Remove shortcut id map for that user
    Iterator<ComponentKey> keysIter = dataModel.deepShortcutMap.keySet().iterator();
    while (keysIter.hasNext()) {
        if (keysIter.next().user.equals(mUser)) {
            keysIter.remove();
        }
    }
    if (mIsUserUnlocked) {
        dataModel.updateDeepShortcutCounts(null, mUser, new ShortcutRequest(context, mUser).query(ShortcutRequest.ALL));
    }
    bindDeepShortcuts(dataModel);
}
Also used : Context(android.content.Context) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) ShortcutKey(com.android.launcher3.shortcuts.ShortcutKey) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) QueryResult(com.android.launcher3.shortcuts.ShortcutRequest.QueryResult) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) HashSet(java.util.HashSet)

Example 79 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Launcher3 by AOSPA.

the class DragLayer method setup.

public void setup(DragController dragController, Workspace workspace) {
    mDragController = dragController;
    recreateControllers();
    mWorkspaceDragScrim = new Scrim(this);
}
Also used : Scrim(com.android.launcher3.graphics.Scrim)

Example 80 with Workspace

use of com.android.launcher3.tapl.Workspace in project android_packages_apps_Launcher3 by AOSPA.

the class LauncherDelegate method replaceFolderWithFinalItem.

boolean replaceFolderWithFinalItem(Folder folder) {
    // Add the last remaining child to the workspace in place of the folder
    Runnable onCompleteRunnable = new Runnable() {

        @Override
        public void run() {
            int itemCount = folder.getItemCount();
            FolderInfo info = folder.mInfo;
            if (itemCount <= 1) {
                View newIcon = null;
                WorkspaceItemInfo finalItem = null;
                if (itemCount == 1) {
                    // Move the item from the folder to the workspace, in the position of the
                    // folder
                    CellLayout cellLayout = mLauncher.getCellLayout(info.container, info.screenId);
                    finalItem = info.contents.remove(0);
                    newIcon = mLauncher.createShortcut(cellLayout, finalItem);
                    mLauncher.getModelWriter().addOrMoveItemInDatabase(finalItem, info.container, info.screenId, info.cellX, info.cellY);
                }
                // Remove the folder
                mLauncher.removeItem(folder.mFolderIcon, info, true);
                if (folder.mFolderIcon instanceof DropTarget) {
                    folder.mDragController.removeDropTarget((DropTarget) folder.mFolderIcon);
                }
                if (newIcon != null) {
                    // We add the child after removing the folder to prevent both from existing
                    // at the same time in the CellLayout.  We need to add the new item with
                    // addInScreenFromBind() to ensure that hotseat items are placed correctly.
                    mLauncher.getWorkspace().addInScreenFromBind(newIcon, info);
                    // Focus the newly created child
                    newIcon.requestFocus();
                }
                if (finalItem != null) {
                    StatsLogger logger = mLauncher.getStatsLogManager().logger().withItemInfo(finalItem);
                    ((Optional<InstanceId>) folder.mDragController.getLogInstanceId()).map(logger::withInstanceId).orElse(logger).log(LAUNCHER_FOLDER_CONVERTED_TO_ICON);
                }
            }
        }
    };
    View finalChild = folder.mContent.getLastItem();
    if (finalChild != null) {
        folder.mFolderIcon.performDestroyAnimation(onCompleteRunnable);
    } else {
        onCompleteRunnable.run();
    }
    return true;
}
Also used : StatsLogger(com.android.launcher3.logging.StatsLogManager.StatsLogger) CellLayout(com.android.launcher3.CellLayout) Optional(java.util.Optional) DropTarget(com.android.launcher3.DropTarget) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

View (android.view.View)143 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)124 Point (android.graphics.Point)115 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)97 Rect (android.graphics.Rect)93 ArrayList (java.util.ArrayList)91 ItemInfo (com.android.launcher3.model.data.ItemInfo)86 DragView (com.android.launcher3.dragndrop.DragView)77 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)73 AppWidgetHostView (android.appwidget.AppWidgetHostView)72 Workspace (com.android.launcher3.Workspace)63 SuppressLint (android.annotation.SuppressLint)58 DraggableView (com.android.launcher3.dragndrop.DraggableView)58 Test (org.junit.Test)57 FolderInfo (com.android.launcher3.model.data.FolderInfo)55 CellLayout (com.android.launcher3.CellLayout)51 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)47 IntArray (com.android.launcher3.util.IntArray)45 Intent (android.content.Intent)43 ValueAnimator (android.animation.ValueAnimator)41