Search in sources :

Example 1 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatEduController method migrateToFolder.

/**
 * This migration places all non folder items in the hotseat into a folder and then moves
 * all folders in the hotseat to a workspace page that has enough empty spots.
 *
 * @return pageId that has accepted the items.
 */
private int migrateToFolder() {
    ArrayDeque<FolderInfo> folders = new ArrayDeque<>();
    ArrayList<WorkspaceItemInfo> putIntoFolder = new ArrayList<>();
    // separate folders and items that can get in folders
    for (int i = 0; i < mLauncher.getDeviceProfile().numShownHotseatIcons; i++) {
        View view = mHotseat.getChildAt(i, 0);
        if (view == null)
            continue;
        ItemInfo info = (ItemInfo) view.getTag();
        if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
            folders.add((FolderInfo) info);
        } else if (info instanceof WorkspaceItemInfo && info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
            putIntoFolder.add((WorkspaceItemInfo) info);
        }
    }
    // create a temp folder and add non folder items to it
    if (!putIntoFolder.isEmpty()) {
        ItemInfo firstItem = putIntoFolder.get(0);
        FolderInfo folderInfo = new FolderInfo();
        mLauncher.getModelWriter().addItemToDatabase(folderInfo, firstItem.container, firstItem.screenId, firstItem.cellX, firstItem.cellY);
        folderInfo.setTitle("", mLauncher.getModelWriter());
        folderInfo.contents.addAll(putIntoFolder);
        for (int i = 0; i < folderInfo.contents.size(); i++) {
            ItemInfo item = folderInfo.contents.get(i);
            item.rank = i;
            mLauncher.getModelWriter().moveItemInDatabase(item, folderInfo.id, 0, item.cellX, item.cellY);
        }
        folders.add(folderInfo);
    }
    mNewItems.addAll(folders);
    return placeFoldersInWorkspace(folders);
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ArrayList(java.util.ArrayList) FolderInfo(com.android.launcher3.model.data.FolderInfo) ArrowTipView(com.android.launcher3.views.ArrowTipView) View(android.view.View) ArrayDeque(java.util.ArrayDeque) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 2 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatEduDialog method populatePreview.

private void populatePreview(List<WorkspaceItemInfo> predictions) {
    for (int i = 0; i < mActivityContext.getDeviceProfile().numShownHotseatIcons; i++) {
        WorkspaceItemInfo info = predictions.get(i);
        PredictedAppIcon icon = PredictedAppIcon.createIcon(mSampleHotseat, info);
        icon.setEnabled(false);
        icon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
        icon.verifyHighRes();
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(i, 0, 1, 1);
        mSampleHotseat.addViewToCellLayout(icon, i, info.getViewId(), lp, true);
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 3 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class HotseatPredictionController method pinPrediction.

/**
 * Pins a predicted app icon into place.
 */
public void pinPrediction(ItemInfo info) {
    PredictedAppIcon icon = (PredictedAppIcon) mHotseat.getChildAt(mHotseat.getCellXFromOrder(info.rank), mHotseat.getCellYFromOrder(info.rank));
    if (icon == null) {
        return;
    }
    WorkspaceItemInfo workspaceItemInfo = new WorkspaceItemInfo((WorkspaceItemInfo) info);
    mLauncher.getModelWriter().addItemToDatabase(workspaceItemInfo, LauncherSettings.Favorites.CONTAINER_HOTSEAT, workspaceItemInfo.screenId, workspaceItemInfo.cellX, workspaceItemInfo.cellY);
    ObjectAnimator.ofFloat(icon, SCALE_PROPERTY, 1, 0.8f, 1).start();
    icon.pin(workspaceItemInfo);
    mLauncher.getStatsLogManager().logger().withItemInfo(workspaceItemInfo).log(LAUNCHER_HOTSEAT_PREDICTION_PINNED);
}
Also used : PredictedAppIcon(com.android.launcher3.uioverrides.PredictedAppIcon) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 4 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class LoaderCursor method loadIcon.

/**
 * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
 */
protected boolean loadIcon(WorkspaceItemInfo info) {
    try (LauncherIcons li = LauncherIcons.obtain(mContext)) {
        if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
            String packageName = getString(iconPackageIndex);
            String resourceName = getString(iconResourceIndex);
            if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
                info.iconResource = new 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.
        byte[] data = getBlob(iconIndex);
        try {
            info.bitmap = li.createIconBitmap(decodeByteArray(data, 0, data.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) ShortcutIconResource(android.content.Intent.ShortcutIconResource) BitmapInfo(com.android.launcher3.icons.BitmapInfo) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(java.security.InvalidParameterException)

Example 5 with WorkspaceItemInfo

use of com.android.launcher3.model.data.WorkspaceItemInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class LoaderCursor method getAppShortcutInfo.

/**
 * Make an WorkspaceItemInfo object for a shortcut that is an application.
 */
public WorkspaceItemInfo getAppShortcutInfo(Intent intent, boolean allowMissingTarget, boolean useLowResIcon) {
    if (user == null) {
        Log.d(TAG, "Null user found in getShortcutInfo");
        return null;
    }
    ComponentName componentName = intent.getComponent();
    if (componentName == null) {
        Log.d(TAG, "Missing component found in getShortcutInfo");
        return null;
    }
    Intent newIntent = new Intent(Intent.ACTION_MAIN, null);
    newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    newIntent.setComponent(componentName);
    mActivityInfo = mContext.getSystemService(LauncherApps.class).resolveActivity(newIntent, user);
    if ((mActivityInfo == null) && !allowMissingTarget) {
        Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName);
        return null;
    }
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.itemType = Favorites.ITEM_TYPE_APPLICATION;
    info.user = user;
    info.intent = newIntent;
    mIconCache.getTitleAndIcon(info, mActivityInfo, useLowResIcon);
    if (mIconCache.isDefaultIcon(info.bitmap, user)) {
        loadIcon(info);
    }
    if (mActivityInfo != null) {
        AppInfo.updateRuntimeFlagsForActivityTarget(info, mActivityInfo);
    }
    // from the db
    if (TextUtils.isEmpty(info.title)) {
        info.title = getTitle();
    }
    // fall back to the class name of the activity
    if (info.title == null) {
        info.title = componentName.getClassName();
    }
    info.contentDescription = mPM.getUserBadgedLabel(info.title, info.user);
    return info;
}
Also used : ComponentName(android.content.ComponentName) Intent(android.content.Intent) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)68 View (android.view.View)23 ArrayList (java.util.ArrayList)21 ItemInfo (com.android.launcher3.model.data.ItemInfo)20 Intent (android.content.Intent)17 AppInfo (com.android.launcher3.model.data.AppInfo)17 FolderInfo (com.android.launcher3.model.data.FolderInfo)17 SuppressLint (android.annotation.SuppressLint)12 AppWidgetHostView (android.appwidget.AppWidgetHostView)12 DragView (com.android.launcher3.dragndrop.DragView)12 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)12 ComponentName (android.content.ComponentName)11 Context (android.content.Context)10 Point (android.graphics.Point)10 Rect (android.graphics.Rect)10 FolderIcon (com.android.launcher3.folder.FolderIcon)10 UserHandle (android.os.UserHandle)9 BubbleTextView (com.android.launcher3.BubbleTextView)9 HashSet (java.util.HashSet)9 List (java.util.List)9