diff options
Diffstat (limited to 'src/com/android/launcher3/allapps/AlphabeticalAppsList.java')
-rw-r--r-- | src/com/android/launcher3/allapps/AlphabeticalAppsList.java | 172 |
1 files changed, 22 insertions, 150 deletions
diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java index 173065be2..8b7a6ba4d 100644 --- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java +++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java @@ -23,8 +23,8 @@ import com.android.launcher3.Launcher; import com.android.launcher3.compat.AlphabeticIndexCompat; import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.config.ProviderConfig; -import com.android.launcher3.model.AppNameComparator; import com.android.launcher3.util.ComponentKey; +import com.android.launcher3.util.LabelComparator; import java.util.ArrayList; import java.util.Collections; @@ -49,18 +49,6 @@ public class AlphabeticalAppsList { private final int mFastScrollDistributionMode = FAST_SCROLL_FRACTION_DISTRIBUTE_BY_NUM_SECTIONS; /** - * Info about a section in the alphabetic list - */ - public static class SectionInfo { - // The number of applications in this section - public int numApps; - // The section break AdapterItem for this section - public AdapterItem sectionBreakItem; - // The first app AdapterItem for this section - public AdapterItem firstAppItem; - } - - /** * Info about a fast scroller section, depending if sections are merged, the fast scroller * sections will not be the same set as the section headers. */ @@ -87,16 +75,10 @@ public class AlphabeticalAppsList { // The type of this item public int viewType; - /** Section & App properties */ - // The section for this item - public SectionInfo sectionInfo; - /** App-only properties */ // The section name of this app. Note that there can be multiple items with different // sectionNames in the same section public String sectionName = null; - // The index of this app in the section - public int sectionAppIndex = -1; // The row that this item shows up on public int rowIndex; // The index of this app in the row @@ -106,30 +88,19 @@ public class AlphabeticalAppsList { // The index of this app not including sections public int appIndex = -1; - public static AdapterItem asSectionBreak(int pos, SectionInfo section) { - AdapterItem item = new AdapterItem(); - item.viewType = AllAppsGridAdapter.VIEW_TYPE_SECTION_BREAK; - item.position = pos; - item.sectionInfo = section; - section.sectionBreakItem = item; - return item; - } - - public static AdapterItem asPredictedApp(int pos, SectionInfo section, String sectionName, - int sectionAppIndex, AppInfo appInfo, int appIndex) { - AdapterItem item = asApp(pos, section, sectionName, sectionAppIndex, appInfo, appIndex); + public static AdapterItem asPredictedApp(int pos, String sectionName, AppInfo appInfo, + int appIndex) { + AdapterItem item = asApp(pos, sectionName, appInfo, appIndex); item.viewType = AllAppsGridAdapter.VIEW_TYPE_PREDICTION_ICON; return item; } - public static AdapterItem asApp(int pos, SectionInfo section, String sectionName, - int sectionAppIndex, AppInfo appInfo, int appIndex) { + public static AdapterItem asApp(int pos, String sectionName, AppInfo appInfo, + int appIndex) { AdapterItem item = new AdapterItem(); item.viewType = AllAppsGridAdapter.VIEW_TYPE_ICON; item.position = pos; - item.sectionInfo = section; item.sectionName = sectionName; - item.sectionAppIndex = sectionAppIndex; item.appInfo = appInfo; item.appIndex = appIndex; return item; @@ -149,7 +120,7 @@ public class AlphabeticalAppsList { return item; } - public static AdapterItem asSearchDivder(int pos) { + public static AdapterItem asSearchDivider(int pos) { AdapterItem item = new AdapterItem(); item.viewType = AllAppsGridAdapter.VIEW_TYPE_SEARCH_DIVIDER; item.position = pos; @@ -171,14 +142,6 @@ public class AlphabeticalAppsList { } } - /** - * Common interface for different merging strategies. - */ - public interface MergeAlgorithm { - boolean continueMerging(SectionInfo section, SectionInfo withSection, - int sectionAppCount, int numAppsPerRow, int mergeCount); - } - private Launcher mLauncher; // The set of apps from the system not including predictions @@ -189,8 +152,6 @@ public class AlphabeticalAppsList { private List<AppInfo> mFilteredApps = new ArrayList<>(); // The current set of adapter items private List<AdapterItem> mAdapterItems = new ArrayList<>(); - // The set of sections for the apps with the current filter - private List<SectionInfo> mSections = new ArrayList<>(); // The set of sections that we allow fast-scrolling to (includes non-merged sections) private List<FastScrollSectionInfo> mFastScrollerSections = new ArrayList<>(); // The set of predicted app component names @@ -202,8 +163,7 @@ public class AlphabeticalAppsList { private HashMap<CharSequence, String> mCachedSectionNames = new HashMap<>(); private AllAppsGridAdapter mAdapter; private AlphabeticIndexCompat mIndexer; - private AppNameComparator mAppNameComparator; - private MergeAlgorithm mMergeAlgorithm; + private AppInfoComparator mAppNameComparator; private int mNumAppsPerRow; private int mNumPredictedAppsPerRow; private int mNumAppRowsInAdapter; @@ -211,17 +171,15 @@ public class AlphabeticalAppsList { public AlphabeticalAppsList(Context context) { mLauncher = Launcher.getLauncher(context); mIndexer = new AlphabeticIndexCompat(context); - mAppNameComparator = new AppNameComparator(context); + mAppNameComparator = new AppInfoComparator(context); } /** * Sets the number of apps per row. */ - public void setNumAppsPerRow(int numAppsPerRow, int numPredictedAppsPerRow, - MergeAlgorithm mergeAlgorithm) { + public void setNumAppsPerRow(int numAppsPerRow, int numPredictedAppsPerRow) { mNumAppsPerRow = numAppsPerRow; mNumPredictedAppsPerRow = numPredictedAppsPerRow; - mMergeAlgorithm = mergeAlgorithm; updateAdapterItems(); } @@ -241,13 +199,6 @@ public class AlphabeticalAppsList { } /** - * Returns sections of all the current filtered applications. - */ - public List<SectionInfo> getSections() { - return mSections; - } - - /** * Returns fast scroller sections of all the current filtered applications. */ public List<FastScrollSectionInfo> getFastScrollerSections() { @@ -354,17 +305,16 @@ public class AlphabeticalAppsList { // Sort the list of apps mApps.clear(); mApps.addAll(mComponentToAppMap.values()); - Collections.sort(mApps, mAppNameComparator.getAppInfoComparator()); + Collections.sort(mApps, mAppNameComparator); // As a special case for some languages (currently only Simplified Chinese), we may need to // coalesce sections Locale curLocale = mLauncher.getResources().getConfiguration().locale; - TreeMap<String, ArrayList<AppInfo>> sectionMap = null; boolean localeRequiresSectionSorting = curLocale.equals(Locale.SIMPLIFIED_CHINESE); if (localeRequiresSectionSorting) { - // Compute the section headers. We use a TreeMap with the section name comparator to + // 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 - sectionMap = new TreeMap<>(mAppNameComparator.getSectionNameComparator()); + TreeMap<String, ArrayList<AppInfo>> sectionMap = new TreeMap<>(new LabelComparator()); for (AppInfo info : mApps) { // Add the section to the cache String sectionName = getAndUpdateCachedSectionName(info.title); @@ -379,13 +329,10 @@ public class AlphabeticalAppsList { } // Add each of the section apps to the list in order - List<AppInfo> allApps = new ArrayList<>(mApps.size()); + mApps.clear(); for (Map.Entry<String, ArrayList<AppInfo>> entry : sectionMap.entrySet()) { - allApps.addAll(entry.getValue()); + mApps.addAll(entry.getValue()); } - - mApps.clear(); - mApps.addAll(allApps); } else { // Just compute the section headers for use below for (AppInfo info : mApps) { @@ -403,7 +350,6 @@ public class AlphabeticalAppsList { * mCachedSectionNames to have been calculated for the set of all apps in mApps. */ private void updateAdapterItems() { - SectionInfo lastSectionInfo = null; String lastSectionName = null; FastScrollSectionInfo lastFastScrollerSectionInfo = null; int position = 0; @@ -413,7 +359,6 @@ public class AlphabeticalAppsList { mFilteredApps.clear(); mFastScrollerSections.clear(); mAdapterItems.clear(); - mSections.clear(); if (DEBUG_PREDICTIONS) { if (mPredictedAppComponents.isEmpty() && !mApps.isEmpty()) { @@ -429,7 +374,7 @@ public class AlphabeticalAppsList { } // Add the search divider - mAdapterItems.add(AdapterItem.asSearchDivder(position++)); + mAdapterItems.add(AdapterItem.asSearchDivider(position++)); // Process the predicted app components mPredictedApps.clear(); @@ -451,19 +396,14 @@ public class AlphabeticalAppsList { if (!mPredictedApps.isEmpty()) { // Add a section for the predictions - lastSectionInfo = new SectionInfo(); lastFastScrollerSectionInfo = new FastScrollSectionInfo(""); - AdapterItem sectionItem = AdapterItem.asSectionBreak(position++, lastSectionInfo); - mSections.add(lastSectionInfo); mFastScrollerSections.add(lastFastScrollerSectionInfo); - mAdapterItems.add(sectionItem); // Add the predicted app items for (AppInfo info : mPredictedApps) { - AdapterItem appItem = AdapterItem.asPredictedApp(position++, lastSectionInfo, - "", lastSectionInfo.numApps++, info, appIndex++); - if (lastSectionInfo.firstAppItem == null) { - lastSectionInfo.firstAppItem = appItem; + AdapterItem appItem = AdapterItem.asPredictedApp(position++, "", info, + appIndex++); + if (lastFastScrollerSectionInfo.fastScrollToItem == null) { lastFastScrollerSectionInfo.fastScrollToItem = appItem; } mAdapterItems.add(appItem); @@ -480,25 +420,15 @@ public class AlphabeticalAppsList { String sectionName = getAndUpdateCachedSectionName(info.title); // Create a new section if the section names do not match - if (lastSectionInfo == null || !sectionName.equals(lastSectionName)) { + if (!sectionName.equals(lastSectionName)) { lastSectionName = sectionName; - lastSectionInfo = new SectionInfo(); lastFastScrollerSectionInfo = new FastScrollSectionInfo(sectionName); - mSections.add(lastSectionInfo); mFastScrollerSections.add(lastFastScrollerSectionInfo); - - // Create a new section item to break the flow of items in the list - if (!hasFilter()) { - AdapterItem sectionItem = AdapterItem.asSectionBreak(position++, lastSectionInfo); - mAdapterItems.add(sectionItem); - } } // Create an app item - AdapterItem appItem = AdapterItem.asApp(position++, lastSectionInfo, sectionName, - lastSectionInfo.numApps++, info, appIndex++); - if (lastSectionInfo.firstAppItem == null) { - lastSectionInfo.firstAppItem = appItem; + AdapterItem appItem = AdapterItem.asApp(position++, sectionName, info, appIndex++); + if (lastFastScrollerSectionInfo.fastScrollToItem == null) { lastFastScrollerSectionInfo.fastScrollToItem = appItem; } mAdapterItems.add(appItem); @@ -515,9 +445,6 @@ public class AlphabeticalAppsList { mAdapterItems.add(AdapterItem.asMarketSearch(position++)); } - // Merge multiple sections together as requested by the merge strategy for this device - mergeSections(); - 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) @@ -594,61 +521,6 @@ public class AlphabeticalAppsList { } /** - * Merges multiple sections to reduce visual raggedness. - */ - private void mergeSections() { - // Ignore merging until we have an algorithm and a valid row size - if (mMergeAlgorithm == null || mNumAppsPerRow == 0) { - return; - } - - // Go through each section and try and merge some of the sections - if (!hasFilter()) { - int sectionAppCount = 0; - for (int i = 0; i < mSections.size() - 1; i++) { - SectionInfo section = mSections.get(i); - sectionAppCount = section.numApps; - int mergeCount = 1; - - // Merge rows based on the current strategy - while (i < (mSections.size() - 1) && - mMergeAlgorithm.continueMerging(section, mSections.get(i + 1), - sectionAppCount, mNumAppsPerRow, mergeCount)) { - SectionInfo nextSection = mSections.remove(i + 1); - - // Remove the next section break - mAdapterItems.remove(nextSection.sectionBreakItem); - int pos = mAdapterItems.indexOf(section.firstAppItem); - - // Point the section for these new apps to the merged section - int nextPos = pos + section.numApps; - for (int j = nextPos; j < (nextPos + nextSection.numApps); j++) { - AdapterItem item = mAdapterItems.get(j); - item.sectionInfo = section; - item.sectionAppIndex += section.numApps; - } - - // Update the following adapter items of the removed section item - pos = mAdapterItems.indexOf(nextSection.firstAppItem); - for (int j = pos; j < mAdapterItems.size(); j++) { - AdapterItem item = mAdapterItems.get(j); - item.position--; - } - section.numApps += nextSection.numApps; - sectionAppCount += nextSection.numApps; - - if (DEBUG) { - Log.d(TAG, "Merging: " + nextSection.firstAppItem.sectionName + - " to " + section.firstAppItem.sectionName + - " mergedNumRows: " + (sectionAppCount / mNumAppsPerRow)); - } - mergeCount++; - } - } - } - } - - /** * Returns the cached section name for the given title, recomputing and updating the cache if * the title has no cached section name. */ |