Search in sources :

Example 16 with AdapterItem

use of com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem in project android_packages_apps_Launcher3 by crdroidandroid.

the class AlphabeticalAppsList method updateSearchAdapterItems.

void updateSearchAdapterItems(ArrayList<AdapterItem> list, int offset) {
    for (int i = 0; i < list.size(); i++) {
        AdapterItem adapterItem = list.get(i);
        adapterItem.position = offset + i;
        mAdapterItems.add(adapterItem);
        if (adapterItem.isCountedForAccessibility()) {
            mAccessibilityResultsCount++;
        }
    }
}
Also used : AdapterItem(com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem)

Example 17 with AdapterItem

use of com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem in project android_packages_apps_Launcher3 by crdroidandroid.

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)

Example 18 with AdapterItem

use of com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem 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 19 with AdapterItem

use of com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem in project android_packages_apps_Launcher3 by ArrowOS.

the class AlphabeticalAppsList method updateSearchAdapterItems.

void updateSearchAdapterItems(ArrayList<AdapterItem> list, int offset) {
    for (int i = 0; i < list.size(); i++) {
        AdapterItem adapterItem = list.get(i);
        adapterItem.position = offset + i;
        mAdapterItems.add(adapterItem);
        if (adapterItem.isCountedForAccessibility()) {
            mAccessibilityResultsCount++;
        }
    }
}
Also used : AdapterItem(com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem)

Example 20 with AdapterItem

use of com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem in project android_packages_apps_Launcher3 by ArrowOS.

the class AllAppsGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case VIEW_TYPE_ICON:
            AdapterItem adapterItem = mApps.getAdapterItems().get(position);
            BubbleTextView icon = (BubbleTextView) holder.itemView;
            icon.reset();
            if (adapterItem.itemInfo instanceof AppInfo) {
                icon.applyFromApplicationInfo((AppInfo) adapterItem.itemInfo);
            } else {
                icon.applyFromItemInfoWithIcon(adapterItem.itemInfo);
            }
            break;
        case VIEW_TYPE_EMPTY_SEARCH:
            TextView emptyViewText = (TextView) holder.itemView;
            emptyViewText.setText(mEmptySearchMessage);
            emptyViewText.setGravity(mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
            break;
        case VIEW_TYPE_SEARCH_MARKET:
            TextView searchView = (TextView) holder.itemView;
            if (mMarketSearchIntent != null) {
                searchView.setVisibility(View.VISIBLE);
            } else {
                searchView.setVisibility(View.GONE);
            }
            break;
        case VIEW_TYPE_ALL_APPS_DIVIDER:
            // nothing to do
            break;
        default:
            BaseAdapterProvider adapterProvider = getAdapterProvider(holder.getItemViewType());
            if (adapterProvider != null) {
                adapterProvider.onBindView(holder, position);
            }
    }
}
Also used : BubbleTextView(com.android.launcher3.BubbleTextView) TextView(android.widget.TextView) BubbleTextView(com.android.launcher3.BubbleTextView) AppInfo(com.android.launcher3.model.data.AppInfo)

Aggregations

AppInfo (com.android.launcher3.model.data.AppInfo)16 AdapterItem (com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem)15 TextView (android.widget.TextView)5 AnyThread (androidx.annotation.AnyThread)5 BubbleTextView (com.android.launcher3.BubbleTextView)5 StringMatcherUtility (com.android.launcher3.search.StringMatcherUtility)5 ArrayList (java.util.ArrayList)5 AppInfo (com.android.launcher3.AppInfo)1 ComponentKey (com.android.launcher3.util.ComponentKey)1 DrawerFolderInfo (com.saggitt.omega.groups.DrawerFolderInfo)1