Search in sources :

Example 91 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by ArrowOS.

the class WidgetsListHeaderViewHolderBinderTest method generateSampleAppHeader.

private WidgetsListHeaderEntry generateSampleAppHeader(String appName, String packageName, int numOfWidgets) {
    PackageItemInfo appInfo = new PackageItemInfo(packageName, UserHandle.CURRENT);
    appInfo.title = appName;
    appInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
    return new WidgetsListHeaderEntry(appInfo, /* titleSectionName= */
    "", generateWidgetItems(packageName, numOfWidgets));
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Example 92 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class SecondaryDisplayLauncher method onIconClicked.

private void onIconClicked(View v) {
    // view has detached (it's possible for this to happen if the view is removed mid touch).
    if (v.getWindowToken() == null)
        return;
    Object tag = v.getTag();
    if (tag instanceof ItemInfo) {
        ItemInfo item = (ItemInfo) tag;
        Intent intent;
        if (item instanceof ItemInfoWithIcon && (((ItemInfoWithIcon) item).runtimeStatusFlags & ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE) != 0) {
            ItemInfoWithIcon appInfo = (ItemInfoWithIcon) item;
            intent = appInfo.getMarketIntent(this);
        } else {
            intent = item.getIntent();
        }
        if (intent == null) {
            throw new IllegalArgumentException("Input must have a valid intent");
        }
        startActivitySafely(v, intent, item);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) Intent(android.content.Intent) ItemInfoWithIcon(com.android.launcher3.model.data.ItemInfoWithIcon)

Example 93 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class LauncherAccessibilityDelegate method performAction.

/**
 * Performs the provided action on the host
 */
protected boolean performAction(final View host, final ItemInfo item, int action, boolean fromKeyboard) {
    if (action == ACTION_LONG_CLICK) {
        if (PopupContainerWithArrow.canShow(host, item)) {
            // Long press should be consumed for workspace items, and it should invoke the
            // Shortcuts / Notifications / Actions pop-up menu, and not start a drag as the
            // standard long press path does.
            PopupContainerWithArrow.showForIcon((BubbleTextView) host);
            return true;
        }
    } else if (action == MOVE) {
        return beginAccessibleDrag(host, item, fromKeyboard);
    } else if (action == ADD_TO_WORKSPACE) {
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        if (screenId == -1) {
            return false;
        }
        mLauncher.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
            if (item instanceof AppInfo) {
                WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
                mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
                mLauncher.bindItems(Collections.singletonList(info), /* forceAnimateIcons= */
                true, /* focusFirstItemForAccessibility= */
                true);
                announceConfirmation(R.string.item_added_to_workspace);
            } else if (item instanceof PendingAddItemInfo) {
                PendingAddItemInfo info = (PendingAddItemInfo) item;
                Workspace workspace = mLauncher.getWorkspace();
                workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
                mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates, info.spanX, info.spanY);
            } else if (item instanceof WorkspaceItemInfo) {
                WorkspaceItemInfo info = ((WorkspaceItemInfo) item).clone();
                mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
                mLauncher.bindItems(Collections.singletonList(info), true, true);
            }
        }));
        return true;
    } else if (action == MOVE_TO_WORKSPACE) {
        Folder folder = Folder.getOpen(mLauncher);
        folder.close(true);
        WorkspaceItemInfo info = (WorkspaceItemInfo) item;
        folder.getInfo().remove(info, false);
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        if (screenId == -1) {
            return false;
        }
        mLauncher.getModelWriter().moveItemInDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
        // Bind the item in next frame so that if a new workspace page was created,
        // it will get laid out.
        new Handler().post(() -> {
            mLauncher.bindItems(Collections.singletonList(item), true);
            announceConfirmation(R.string.item_moved);
        });
        return true;
    } else if (action == RESIZE) {
        final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
        List<OptionItem> actions = getSupportedResizeActions(host, info);
        Rect pos = new Rect();
        mLauncher.getDragLayer().getDescendantRectRelativeToSelf(host, pos);
        ArrowPopup popup = OptionsPopupView.show(mLauncher, new RectF(pos), actions, false);
        popup.requestFocus();
        popup.setOnCloseCallback(host::requestFocus);
        return true;
    } else if (action == DEEP_SHORTCUTS || action == SHORTCUTS_AND_NOTIFICATIONS) {
        return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
    } else {
        for (ButtonDropTarget dropTarget : mLauncher.getDropTargetBar().getDropTargets()) {
            if (dropTarget.supportsAccessibilityDrop(item, host) && action == dropTarget.getAccessibilityAction()) {
                dropTarget.onAccessibilityDrop(host, item);
                return true;
            }
        }
    }
    return false;
}
Also used : Rect(android.graphics.Rect) OptionItem(com.android.launcher3.views.OptionsPopupView.OptionItem) ArrowPopup(com.android.launcher3.popup.ArrowPopup) Handler(android.os.Handler) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) Folder(com.android.launcher3.folder.Folder) Point(android.graphics.Point) AppInfo(com.android.launcher3.model.data.AppInfo) RectF(android.graphics.RectF) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Workspace(com.android.launcher3.Workspace)

Example 94 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WorkspaceAccessibilityHelper method getConfirmationForIconDrop.

@Override
protected String getConfirmationForIconDrop(int id) {
    int x = id % mView.getCountX();
    int y = id / mView.getCountX();
    LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
    View child = mView.getChildAt(x, y);
    if (child == null || child == dragInfo.item) {
        return mContext.getString(R.string.item_moved);
    } else {
        ItemInfo info = (ItemInfo) child.getTag();
        if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) {
            return mContext.getString(R.string.folder_created);
        } else if (info instanceof FolderInfo) {
            return mContext.getString(R.string.added_to_folder);
        }
    }
    return "";
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) View(android.view.View) FolderInfo(com.android.launcher3.model.data.FolderInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 95 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project android_packages_apps_Launcher3 by ProtonAOSP.

the class AlphabeticalAppsList method refillAdapterItems.

private void refillAdapterItems() {
    String lastSectionName = null;
    FastScrollSectionInfo lastFastScrollerSectionInfo = null;
    int position = 0;
    int appIndex = 0;
    // Prepare to update the list of sections, filtered apps, etc.
    mAccessibilityResultsCount = 0;
    mFastScrollerSections.clear();
    mAdapterItems.clear();
    if (!hasFilter()) {
        mAccessibilityResultsCount = mApps.size();
        if (mWorkAdapterProvider != null) {
            position += mWorkAdapterProvider.addWorkItems(mAdapterItems);
            if (!mWorkAdapterProvider.shouldShowWorkApps()) {
                return;
            }
        }
        for (AppInfo info : mApps) {
            String sectionName = info.sectionName;
            // Create a new section if the section names do not match
            if (!sectionName.equals(lastSectionName)) {
                lastSectionName = sectionName;
                lastFastScrollerSectionInfo = new FastScrollSectionInfo(sectionName);
                mFastScrollerSections.add(lastFastScrollerSectionInfo);
            }
            // Create an app item
            AdapterItem appItem = AdapterItem.asApp(position++, sectionName, info, appIndex++);
            if (lastFastScrollerSectionInfo.fastScrollToItem == null) {
                lastFastScrollerSectionInfo.fastScrollToItem = appItem;
            }
            mAdapterItems.add(appItem);
        }
    } else {
        updateSearchAdapterItems(mSearchResults, 0);
        if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
            // Append the search market item
            if (hasNoFilteredResults()) {
                mAdapterItems.add(AdapterItem.asEmptySearch(position++));
            } else {
                mAdapterItems.add(AdapterItem.asAllAppsDivider(position++));
            }
            mAdapterItems.add(AdapterItem.asMarketSearch(position++));
        }
    }
    if (mNumAppsPerRow != 0) {
        // Update the number of rows in the adapter after we do all the merging (otherwise, we
        // would have to shift the values again)
        int numAppsInSection = 0;
        int numAppsInRow = 0;
        int rowIndex = -1;
        for (AdapterItem item : mAdapterItems) {
            item.rowIndex = 0;
            if (AllAppsGridAdapter.isDividerViewType(item.viewType)) {
                numAppsInSection = 0;
            } else if (AllAppsGridAdapter.isIconViewType(item.viewType)) {
                if (numAppsInSection % mNumAppsPerRow == 0) {
                    numAppsInRow = 0;
                    rowIndex++;
                }
                item.rowIndex = rowIndex;
                item.rowAppIndex = numAppsInRow;
                numAppsInSection++;
                numAppsInRow++;
            }
        }
        mNumAppRowsInAdapter = rowIndex + 1;
        // Pre-calculate all the fast scroller fractions
        switch(mFastScrollDistributionMode) {
            case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_ROWS_FRACTION:
                float rowFraction = 1f / mNumAppRowsInAdapter;
                for (FastScrollSectionInfo info : mFastScrollerSections) {
                    AdapterItem item = info.fastScrollToItem;
                    if (!AllAppsGridAdapter.isIconViewType(item.viewType)) {
                        info.touchFraction = 0f;
                        continue;
                    }
                    float subRowFraction = item.rowAppIndex * (rowFraction / mNumAppsPerRow);
                    info.touchFraction = item.rowIndex * rowFraction + subRowFraction;
                }
                break;
            case FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS:
                float perSectionTouchFraction = 1f / mFastScrollerSections.size();
                float cumulativeTouchFraction = 0f;
                for (FastScrollSectionInfo info : mFastScrollerSections) {
                    AdapterItem item = info.fastScrollToItem;
                    if (!AllAppsGridAdapter.isIconViewType(item.viewType)) {
                        info.touchFraction = 0f;
                        continue;
                    }
                    info.touchFraction = cumulativeTouchFraction;
                    cumulativeTouchFraction += perSectionTouchFraction;
                }
                break;
        }
    }
}
Also used : AdapterItem(com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem) AppInfo(com.android.launcher3.model.data.AppInfo)

Aggregations

AppInfo (com.android.launcher3.model.data.AppInfo)181 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)86 ItemInfo (com.android.launcher3.model.data.ItemInfo)46 ArrayList (java.util.ArrayList)46 ComponentName (android.content.ComponentName)36 AppInfo (com.android.launcher3.AppInfo)33 View (android.view.View)32 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)31 Intent (android.content.Intent)30 FolderInfo (com.android.launcher3.model.data.FolderInfo)30 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)30 UserHandle (android.os.UserHandle)21 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)21 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)21 Point (android.graphics.Point)19 BubbleTextView (com.android.launcher3.BubbleTextView)19 LauncherApps (android.content.pm.LauncherApps)17 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)17 PendingAddItemInfo (com.android.launcher3.PendingAddItemInfo)15 AppWidgetHostView (android.appwidget.AppWidgetHostView)14