Search in sources :

Example 1 with AdapterItem

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

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);
            AppInfo info = adapterItem.appInfo;
            BubbleTextView icon = (BubbleTextView) holder.itemView;
            icon.reset();
            icon.applyFromApplicationInfo(info);
            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)

Example 2 with AdapterItem

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

the class DefaultAppSearchAlgorithm method getTitleMatchResult.

/**
 * Filters {@link AppInfo}s matching specified query
 */
@AnyThread
public static ArrayList<AdapterItem> getTitleMatchResult(List<AppInfo> apps, String query) {
    // Do an intersection of the words in the query and each title, and filter out all the
    // apps that don't match all of the words in the query.
    final String queryTextLower = query.toLowerCase();
    final ArrayList<AdapterItem> result = new ArrayList<>();
    StringMatcherUtility.StringMatcher matcher = StringMatcherUtility.StringMatcher.getInstance();
    int resultCount = 0;
    int total = apps.size();
    for (int i = 0; i < total && resultCount < MAX_RESULTS_COUNT; i++) {
        AppInfo info = apps.get(i);
        if (StringMatcherUtility.matches(queryTextLower, info.title.toString(), matcher)) {
            AdapterItem appItem = AdapterItem.asApp(resultCount, "", info, resultCount);
            result.add(appItem);
            resultCount++;
        }
    }
    return result;
}
Also used : StringMatcherUtility(com.android.launcher3.search.StringMatcherUtility) ArrayList(java.util.ArrayList) AdapterItem(com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem) AppInfo(com.android.launcher3.model.data.AppInfo) AnyThread(androidx.annotation.AnyThread)

Example 3 with AdapterItem

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

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)

Example 4 with AdapterItem

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

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 5 with AdapterItem

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

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)

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