Search in sources :

Example 61 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project Neo-Launcher by NeoApplications.

the class AlphabeticalAppsList method onAppsUpdated.

/**
 * Updates internals when the set of apps are updated.
 */
@Override
public void onAppsUpdated() {
    // Sort the list of apps
    mApps.clear();
    for (AppInfo app : mAllAppsStore.getApps()) {
        if (mItemFilter == null || mItemFilter.matches(app, null) || hasFilter()) {
            mApps.add(app);
        }
    }
    // Collections.sort(mApps, mAppNameComparator);
    Context context = mLauncher.getApplicationContext();
    OmegaPreferences prefs = Utilities.getOmegaPrefs(context);
    sortApps(prefs.getSortMode());
    // As a special case for some languages (currently only Simplified Chinese), we may need to
    // coalesce sections
    Locale curLocale = mLauncher.getResources().getConfiguration().locale;
    boolean localeRequiresSectionSorting = curLocale.equals(Locale.SIMPLIFIED_CHINESE);
    if (localeRequiresSectionSorting) {
        // Compute the section headers. We use a TreeMap with the section name comparator to
        // ensure that the sections are ordered when we iterate over it later
        TreeMap<String, ArrayList<AppInfo>> sectionMap = new TreeMap<>(new LabelComparator());
        for (AppInfo info : mApps) {
            // Add the section to the cache
            String sectionName = getAndUpdateCachedSectionName(info);
            // Add it to the mapping
            ArrayList<AppInfo> sectionApps = sectionMap.get(sectionName);
            if (sectionApps == null) {
                sectionApps = new ArrayList<>();
                sectionMap.put(sectionName, sectionApps);
            }
            sectionApps.add(info);
        }
        // Add each of the section apps to the list in order
        mApps.clear();
        for (Map.Entry<String, ArrayList<AppInfo>> entry : sectionMap.entrySet()) {
            mApps.addAll(entry.getValue());
        }
    }
    // Recompose the set of adapter items from the current set of apps
    updateAdapterItems();
}
Also used : Context(android.content.Context) Locale(java.util.Locale) ArrayList(java.util.ArrayList) LabelComparator(com.android.launcher3.util.LabelComparator) OmegaPreferences(com.saggitt.omega.OmegaPreferences) TreeMap(java.util.TreeMap) AppInfo(com.android.launcher3.AppInfo) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 62 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project Neo-Launcher by NeoApplications.

the class AlphabeticalAppsList method getFiltersAppInfos.

private List<AppInfo> getFiltersAppInfos() {
    if (mSearchResults == null) {
        return mApps;
    }
    LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(mLauncher);
    UserHandle user = Process.myUserHandle();
    IconCache iconCache = LauncherAppState.getInstance(mLauncher).getIconCache();
    boolean quietMode = UserManagerCompat.getInstance(mLauncher).isQuietModeEnabled(user);
    ArrayList<AppInfo> result = new ArrayList<>();
    for (ComponentKey key : mSearchResults) {
        AppInfo match = mAllAppsStore.getApp(key);
        if (match != null) {
            result.add(match);
        } else {
            for (LauncherActivityInfo info : launcherApps.getActivityList(key.componentName.getPackageName(), user)) {
                if (info.getComponentName().equals(key.componentName)) {
                    AppInfo appInfo = new AppInfo(info, user, quietMode);
                    iconCache.getTitleAndIcon(appInfo, false);
                    result.add(appInfo);
                    break;
                }
            }
        }
    }
    return result;
}
Also used : LauncherAppsCompat(com.android.launcher3.compat.LauncherAppsCompat) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache) ArrayList(java.util.ArrayList) ComponentKey(com.android.launcher3.util.ComponentKey) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) AppInfo(com.android.launcher3.AppInfo)

Example 63 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project Neo-Launcher by NeoApplications.

the class LauncherAccessibilityDelegate method performAction.

public boolean performAction(final View host, final ItemInfo item, int action) {
    if (action == ACTION_LONG_CLICK && ShortcutUtil.isDeepShortcut(item)) {
        CustomActionsPopup popup = new CustomActionsPopup(mLauncher, host);
        if (popup.canShow()) {
            popup.show();
            return true;
        }
    }
    if (action == MOVE) {
        beginAccessibleDrag(host, item);
    } else if (action == ADD_TO_WORKSPACE) {
        final int[] coordinates = new int[2];
        final int screenId = findSpaceOnWorkspace(item, coordinates);
        mLauncher.getStateManager().goToState(NORMAL, true, new Runnable() {

            @Override
            public void run() {
                if (item instanceof AppInfo) {
                    WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
                    mLauncher.getModelWriter().addItemToDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]);
                    ArrayList<ItemInfo> itemList = new ArrayList<>();
                    itemList.add(info);
                    mLauncher.bindItems(itemList, true);
                } 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);
                }
                announceConfirmation(R.string.item_added_to_workspace);
            }
        });
        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);
        mLauncher.getModelWriter().moveItemInDatabase(info, LauncherSettings.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(new Runnable() {

            @Override
            public void run() {
                ArrayList<ItemInfo> itemList = new ArrayList<>();
                itemList.add(item);
                mLauncher.bindItems(itemList, true);
                announceConfirmation(R.string.item_moved);
            }
        });
    } else if (action == RESIZE) {
        final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
        final IntArray actions = getSupportedResizeActions(host, info);
        CharSequence[] labels = new CharSequence[actions.size()];
        for (int i = 0; i < actions.size(); i++) {
            labels[i] = mLauncher.getText(actions.get(i));
        }
        new AlertDialog.Builder(mLauncher).setTitle(R.string.action_resize).setItems(labels, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                performResizeAction(actions.get(which), host, info);
                dialog.dismiss();
            }
        }).show();
        return true;
    } else if (action == DEEP_SHORTCUTS) {
        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 : CustomActionsPopup(com.android.launcher3.keyboard.CustomActionsPopup) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ItemInfo(com.android.launcher3.ItemInfo) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Handler(android.os.Handler) LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) Folder(com.android.launcher3.folder.Folder) AppInfo(com.android.launcher3.AppInfo) IntArray(com.android.launcher3.util.IntArray) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) ButtonDropTarget(com.android.launcher3.ButtonDropTarget) BubbleTextView(com.android.launcher3.BubbleTextView) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) Workspace(com.android.launcher3.Workspace)

Example 64 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project Neo-Launcher by NeoApplications.

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 : ItemInfo(com.android.launcher3.ItemInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) View(android.view.View) FolderInfo(com.android.launcher3.FolderInfo) AppInfo(com.android.launcher3.AppInfo) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo)

Example 65 with AppInfo

use of com.android.launcher3.model.data.AppInfo in project Neo-Launcher by NeoApplications.

the class Folder method onDrop.

@Override
public void onDrop(DragObject d, DragOptions options) {
    // the target location again such that the icon is placed of the final page.
    if (!mContent.rankOnCurrentPage(mEmptyCellRank)) {
        // Reorder again.
        mTargetRank = getTargetRank(d, null);
        // Rearrange items immediately.
        mReorderAlarmListener.onAlarm(mReorderAlarm);
        mOnScrollHintAlarm.cancelAlarm();
        mScrollPauseAlarm.cancelAlarm();
    }
    mContent.completePendingPageChanges();
    PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo ? (PendingAddShortcutInfo) d.dragInfo : null;
    WorkspaceItemInfo pasiSi = pasi != null ? pasi.activityInfo.createWorkspaceItemInfo() : null;
    if (pasi != null && pasiSi == null) {
        // There is no WorkspaceItemInfo, so we have to go through a configuration activity.
        pasi.container = mInfo.id;
        pasi.rank = mEmptyCellRank;
        mLauncher.addPendingItem(pasi, pasi.container, pasi.screenId, null, pasi.spanX, pasi.spanY);
        d.deferDragViewCleanupPostAnimation = false;
        mRearrangeOnClose = true;
    } else {
        final WorkspaceItemInfo si;
        if (pasiSi != null) {
            si = pasiSi;
        } else if (d.dragInfo instanceof AppInfo) {
            // Came from all apps -- make a copy.
            si = ((AppInfo) d.dragInfo).makeWorkspaceItem();
        } else {
            // WorkspaceItemInfo
            si = (WorkspaceItemInfo) d.dragInfo;
        }
        View currentDragView;
        if (mIsExternalDrag) {
            currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
            // Actually move the item in the database if it was an external drag. Call this
            // before creating the view, so that WorkspaceItemInfo is updated appropriately.
            mLauncher.getModelWriter().addOrMoveItemInDatabase(si, mInfo.id, 0, si.cellX, si.cellY);
            mIsExternalDrag = false;
        } else {
            currentDragView = mCurrentDragView;
            mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
        }
        if (d.dragView.hasDrawn()) {
            // Temporarily reset the scale such that the animation target gets calculated
            // correctly.
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, null);
            setScaleX(scaleX);
            setScaleY(scaleY);
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            currentDragView.setVisibility(VISIBLE);
        }
        mItemsInvalidated = true;
        rearrangeChildren();
        // Temporarily suppress the listener, as we did all the work already here.
        try (SuppressInfoChanges s = new SuppressInfoChanges()) {
            mInfo.add(si, mEmptyCellRank, false);
        }
        // #onDropCompleted.
        if (d.dragSource != this) {
            updateItemLocationsInDatabaseBatch();
        }
    }
    // Clear the drag info, as it is no longer being dragged.
    mDragInProgress = false;
    if (mContent.getPageCount() > 1) {
        // The animation has already been shown while opening the folder.
        mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher.getModelWriter());
    }
    mLauncher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
    if (d.stateAnnouncer != null) {
        d.stateAnnouncer.completeAction(R.string.item_moved);
    }
}
Also used : PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) WorkspaceItemInfo(com.android.launcher3.WorkspaceItemInfo) AppInfo(com.android.launcher3.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