Search in sources :

Example 1 with DrawerFolderInfo

use of com.saggitt.omega.groups.DrawerFolderInfo in project Neo-Launcher by NeoApplications.

the class AlphabeticalAppsList method refillAdapterItems.

private void refillAdapterItems() {
    String lastSectionName = null;
    FastScrollSectionInfo lastFastScrollerSectionInfo = null;
    int position = 0;
    int appIndex = 0;
    int folderIndex = 0;
    // Prepare to update the list of sections, filtered apps, etc.
    mFilteredApps.clear();
    mFastScrollerSections.clear();
    mAdapterItems.clear();
    // Search suggestions should be all the way to the top
    if (hasFilter() && hasSuggestions()) {
        for (String suggestion : mSearchSuggestions) {
            mAdapterItems.add(AdapterItem.asSearchSuggestion(position++, suggestion));
        }
    }
    // Drawer folders are arranged before all the apps
    if (!hasFilter()) {
        for (DrawerFolderInfo info : getFolderInfos()) {
            String sectionName = "#";
            // Create a new section if the section names do not match
            if (!sectionName.equals(lastSectionName)) {
                lastSectionName = sectionName;
                lastFastScrollerSectionInfo = new FastScrollSectionInfo(sectionName, Color.WHITE);
                mFastScrollerSections.add(lastFastScrollerSectionInfo);
            }
            info.setAppsStore(mAllAppsStore);
            // Create an folder item
            AdapterItem appItem = AdapterItem.asFolder(position++, sectionName, info, folderIndex++);
            if (lastFastScrollerSectionInfo.fastScrollToItem == null) {
                lastFastScrollerSectionInfo.fastScrollToItem = appItem;
            }
            mAdapterItems.add(appItem);
        }
    }
    Set<ComponentKey> folderFilters = getFolderFilteredApps();
    // ordered set of sections
    for (AppInfo info : getFiltersAppInfos()) {
        if (!hasFilter() && folderFilters.contains(info.toComponentKey())) {
            continue;
        }
        String sectionName = getAndUpdateCachedSectionName(info);
        // Create a new section if the section names do not match
        if (!sectionName.equals(lastSectionName)) {
            lastSectionName = sectionName;
            int color = 0;
            if (prefs.getSortMode() == SORT_BY_COLOR) {
                color = info.iconColor;
            }
            lastFastScrollerSectionInfo = new FastScrollSectionInfo(sectionName, color);
            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);
        mFilteredApps.add(info);
    }
    if (hasFilter()) {
        // Append the search market item
        if (hasNoFilteredResults() && !hasSuggestions()) {
            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;
        }
    }
    // Add the work profile footer if required.
    if (shouldShowWorkFooter()) {
        mAdapterItems.add(AdapterItem.asWorkTabFooter(position++));
    }
}
Also used : DrawerFolderInfo(com.saggitt.omega.groups.DrawerFolderInfo) ComponentKey(com.android.launcher3.util.ComponentKey) AppInfo(com.android.launcher3.AppInfo)

Example 2 with DrawerFolderInfo

use of com.saggitt.omega.groups.DrawerFolderInfo in project Neo-Launcher by NeoApplications.

the class FolderIcon method fromXml.

public static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group, FolderInfo folderInfo) {
    // suppress dead code warning
    @SuppressWarnings("all") final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION;
    if (error) {
        throw new IllegalStateException("DROP_IN_ANIMATION_DURATION must be greater than " + "INITIAL_ITEM_ANIMATION_DURATION, as sequencing of adding first two items " + "is dependent on this");
    }
    DeviceProfile grid = launcher.getWallpaperDeviceProfile();
    FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext()).inflate(resId, group, false);
    icon.setClipToPadding(false);
    icon.mFolderName = icon.findViewById(R.id.folder_icon_name);
    icon.mFolderName.setText(folderInfo.title);
    icon.mFolderName.setCompoundDrawablePadding(0);
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) icon.mFolderName.getLayoutParams();
    if (folderInfo instanceof DrawerFolderInfo) {
        lp.topMargin = grid.allAppsIconSizePx + grid.allAppsIconDrawablePaddingPx;
        icon.mBackground = new PreviewBackground(true);
        ((DrawerFolderInfo) folderInfo).getAppsStore().registerFolderIcon(icon);
    } else {
        lp.topMargin = grid.iconSizePx + grid.iconDrawablePaddingPx;
    }
    icon.setTag(folderInfo);
    icon.setOnClickListener(ItemClickHandler.INSTANCE);
    icon.mInfo = folderInfo;
    icon.mLauncher = launcher;
    icon.mDotRenderer = grid.mDotRendererWorkSpace;
    icon.setContentDescription(launcher.getString(R.string.folder_name_format, folderInfo.title));
    Folder folder = Folder.fromXml(launcher);
    folder.setDragController(launcher.getDragController());
    folder.setFolderIcon(icon);
    folder.bind(folderInfo);
    icon.setFolder(folder);
    icon.setAccessibilityDelegate(launcher.getAccessibilityDelegate());
    folderInfo.addListener(icon);
    icon.setOnFocusChangeListener(launcher.mFocusHandler);
    return icon;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) FrameLayout(android.widget.FrameLayout) DrawerFolderInfo(com.saggitt.omega.groups.DrawerFolderInfo)

Example 3 with DrawerFolderInfo

use of com.saggitt.omega.groups.DrawerFolderInfo in project Neo-Launcher by NeoApplications.

the class Folder method closeComplete.

private void closeComplete(boolean wasAnimated) {
    // TODO: Clear all active animations.
    DragLayer parent = (DragLayer) getParent();
    if (parent != null) {
        parent.removeView(this);
    }
    mDragController.removeDropTarget(this);
    clearFocus();
    if (mFolderIcon != null) {
        mFolderIcon.setVisibility(View.VISIBLE);
        mFolderIcon.setIconVisible(true);
        mFolderIcon.mFolderName.setTextVisibility(true);
        if (wasAnimated) {
            mFolderIcon.animateBgShadowAndStroke();
            mFolderIcon.onFolderClose(mContent.getCurrentPage());
            if (mFolderIcon.hasDot()) {
                mFolderIcon.animateDotScale(0f, 1f);
            }
            mFolderIcon.requestFocus();
        }
    }
    if (mRearrangeOnClose) {
        rearrangeChildren();
        mRearrangeOnClose = false;
    }
    if (getItemCount() <= 1) {
        if (!mDragInProgress && !mSuppressFolderDeletion && !isInAppDrawer()) {
            replaceFolderWithFinalItem();
        } else if (mDragInProgress) {
            mDeleteFolderOnDropCompleted = true;
        }
    }
    mSuppressFolderDeletion = false;
    clearDragInfo();
    mState = STATE_SMALL;
    mContent.setCurrentPage(0);
    if (mInfo instanceof DrawerFolderInfo) {
        ((DrawerFolderInfo) mInfo).onCloseComplete();
    }
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) DrawerFolderInfo(com.saggitt.omega.groups.DrawerFolderInfo)

Aggregations

DrawerFolderInfo (com.saggitt.omega.groups.DrawerFolderInfo)3 FrameLayout (android.widget.FrameLayout)1 AppInfo (com.android.launcher3.AppInfo)1 DeviceProfile (com.android.launcher3.DeviceProfile)1 DragLayer (com.android.launcher3.dragndrop.DragLayer)1 ComponentKey (com.android.launcher3.util.ComponentKey)1