Search in sources :

Example 61 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo 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 62 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by AOSPA.

the class PackageUpdatedTask method updateWorkspaceItemIntent.

/**
 * Updates {@param si}'s intent to point to a new ComponentName.
 * @return Whether the shortcut intent was changed.
 */
private boolean updateWorkspaceItemIntent(Context context, WorkspaceItemInfo si, String packageName) {
    if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        // about the shortcut.
        return false;
    }
    // Try to find the best match activity.
    Intent intent = new PackageManagerHelper(context).getAppLaunchIntent(packageName, mUser);
    if (intent != null) {
        si.intent = intent;
        si.status = WorkspaceItemInfo.DEFAULT;
        return true;
    }
    return false;
}
Also used : Intent(android.content.Intent) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper)

Example 63 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by AOSPA.

the class IconRequestInfo method loadWorkspaceIcon.

/**
 * Loads
 */
public boolean loadWorkspaceIcon(Context context) {
    if (!(itemInfo instanceof WorkspaceItemInfo)) {
        throw new IllegalStateException("loadWorkspaceIcon should only be use for a WorkspaceItemInfos: " + itemInfo);
    }
    try (LauncherIcons li = LauncherIcons.obtain(context)) {
        WorkspaceItemInfo info = (WorkspaceItemInfo) itemInfo;
        if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
            if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
                info.iconResource = new Intent.ShortcutIconResource();
                info.iconResource.packageName = packageName;
                info.iconResource.resourceName = resourceName;
                BitmapInfo iconInfo = li.createIconBitmap(info.iconResource);
                if (iconInfo != null) {
                    info.bitmap = iconInfo;
                    return true;
                }
            }
        }
        // Failed to load from resource, try loading from DB.
        try {
            if (iconBlob == null) {
                return false;
            }
            info.bitmap = li.createIconBitmap(decodeByteArray(iconBlob, 0, iconBlob.length));
            return true;
        } catch (Exception e) {
            Log.e(TAG, "Failed to decode byte array for info " + info, e);
            return false;
        }
    }
}
Also used : LauncherIcons(com.android.launcher3.icons.LauncherIcons) Intent(android.content.Intent) BitmapInfo(com.android.launcher3.icons.BitmapInfo)

Example 64 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo in project android_packages_apps_Launcher3 by AOSPA.

the class PinRequestHelper method createWorkspaceItemFromPinItemRequest.

/**
 * request.accept() will initiate the following flow:
 *      -> go-to-system-process for actual processing (a)
 *      -> callback-to-launcher on UI thread (b)
 *      -> post callback on the worker thread (c)
 *      -> Update model and unpin (in system) any shortcut not in out model. (d)
 *
 * Note that (b) will take at-least one frame as it involves posting callback from binder
 * thread to UI thread.
 * If (d) happens before we add this shortcut to our model, we will end up unpinning
 * the shortcut in the system.
 * Here its the caller's responsibility to add the newly created WorkspaceItemInfo immediately
 * to the model (which may involves a single post-to-worker-thread). That will guarantee
 * that (d) happens after model is updated.
 */
@Nullable
@TargetApi(Build.VERSION_CODES.O)
public static WorkspaceItemInfo createWorkspaceItemFromPinItemRequest(Context context, final PinItemRequest request, final long acceptDelay) {
    if (request != null && request.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT && request.isValid()) {
        if (acceptDelay <= 0) {
            if (!request.accept()) {
                return null;
            }
        } else {
            // Block the worker thread until the accept() is called.
            MODEL_EXECUTOR.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(acceptDelay);
                    } catch (InterruptedException e) {
                    // Ignore
                    }
                    if (request.isValid()) {
                        request.accept();
                    }
                }
            });
        }
        ShortcutInfo si = request.getShortcutInfo();
        WorkspaceItemInfo info = new WorkspaceItemInfo(si, context);
        // Apply the unbadged icon synchronously using the caching logic directly and
        // fetch the actual icon asynchronously.
        info.bitmap = new ShortcutCachingLogic().loadIcon(context, si);
        LauncherAppState.getInstance(context).getModel().updateAndBindWorkspaceItem(info, si);
        return info;
    } else {
        return null;
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutCachingLogic(com.android.launcher3.icons.ShortcutCachingLogic) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) TargetApi(android.annotation.TargetApi) Nullable(androidx.annotation.Nullable)

Example 65 with WorkspaceItemInfo

use of com.android.launcher3.WorkspaceItemInfo 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)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)418 View (android.view.View)168 ArrayList (java.util.ArrayList)145 ItemInfo (com.android.launcher3.model.data.ItemInfo)125 Intent (android.content.Intent)119 FolderInfo (com.android.launcher3.model.data.FolderInfo)100 AppInfo (com.android.launcher3.model.data.AppInfo)94 BubbleTextView (com.android.launcher3.BubbleTextView)87 AppWidgetHostView (android.appwidget.AppWidgetHostView)84 SuppressLint (android.annotation.SuppressLint)78 DragView (com.android.launcher3.dragndrop.DragView)78 ComponentName (android.content.ComponentName)76 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)73 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)72 Rect (android.graphics.Rect)68 FolderIcon (com.android.launcher3.folder.FolderIcon)68 Context (android.content.Context)62 HashSet (java.util.HashSet)62 Point (android.graphics.Point)59 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)57