/** 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++; } } } }
public static AdapterItem asApp( int pos, SectionInfo section, String sectionName, int sectionAppIndex, AppInfo appInfo, int appIndex) { AdapterItem item = new AdapterItem(); item.viewType = AllAppsGridAdapter.ICON_VIEW_TYPE; item.position = pos; item.sectionInfo = section; item.sectionName = sectionName; item.sectionAppIndex = sectionAppIndex; item.appInfo = appInfo; item.appIndex = appIndex; return item; }