summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2015-06-12 14:18:55 -0700
committerWinson Chung <winsonc@google.com>2015-06-16 00:55:02 +0000
commitfbc5b18626ae2e158e39c59606455124cfa8127d (patch)
treeaa4ccb95ad93e5cd9143bb4a84713b032d0a0dd5 /src/com/android/launcher3/allapps/AlphabeticalAppsList.java
parentc332934e27527107c7f9c50ba6b7af93979b8126 (diff)
downloadandroid_packages_apps_Trebuchet-fbc5b18626ae2e158e39c59606455124cfa8127d.tar.gz
android_packages_apps_Trebuchet-fbc5b18626ae2e158e39c59606455124cfa8127d.tar.bz2
android_packages_apps_Trebuchet-fbc5b18626ae2e158e39c59606455124cfa8127d.zip
Refactored section names to only draw when there is space.
- This CL removes all space for section names in both phones and tablets. And when there are no section names, the layout will automatically fully merge the sections. Bug: 20222023 Change-Id: Ic7c751d86f095e5cbd690bfd4f94bb5b00ff8ae4
Diffstat (limited to 'src/com/android/launcher3/allapps/AlphabeticalAppsList.java')
-rw-r--r--src/com/android/launcher3/allapps/AlphabeticalAppsList.java87
1 files changed, 8 insertions, 79 deletions
diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
index a0cf5b6dc..4f29e0c7a 100644
--- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
+++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
@@ -19,18 +19,13 @@ import android.content.ComponentName;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
-
import com.android.launcher3.AppInfo;
-import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.compat.AlphabeticIndexCompat;
import com.android.launcher3.model.AbstractUserComparator;
import com.android.launcher3.model.AppNameComparator;
-import com.android.launcher3.util.Thunk;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -144,70 +139,11 @@ public class AlphabeticalAppsList {
/**
* Common interface for different merging strategies.
*/
- private interface MergeAlgorithm {
+ public interface MergeAlgorithm {
boolean continueMerging(SectionInfo section, SectionInfo withSection,
int sectionAppCount, int numAppsPerRow, int mergeCount);
}
- /**
- * The logic we use to merge sections on tablets. Currently, we don't show section names on
- * tablet layouts, so just merge all the sections indiscriminately.
- */
- @Thunk static class TabletMergeAlgorithm implements MergeAlgorithm {
-
- @Override
- public boolean continueMerging(SectionInfo section, SectionInfo withSection,
- int sectionAppCount, int numAppsPerRow, int mergeCount) {
- // Merge EVERYTHING
- return true;
- }
- }
-
- /**
- * The logic we use to merge sections on phones. We only merge sections when their final row
- * contains less than a certain number of icons, and stop at a specified max number of merges.
- * In addition, we will try and not merge sections that identify apps from different scripts.
- */
- private static class PhoneMergeAlgorithm implements MergeAlgorithm {
-
- private int mMinAppsPerRow;
- private int mMinRowsInMergedSection;
- private int mMaxAllowableMerges;
- private CharsetEncoder mAsciiEncoder;
-
- public PhoneMergeAlgorithm(int minAppsPerRow, int minRowsInMergedSection, int maxNumMerges) {
- mMinAppsPerRow = minAppsPerRow;
- mMinRowsInMergedSection = minRowsInMergedSection;
- mMaxAllowableMerges = maxNumMerges;
- mAsciiEncoder = Charset.forName("US-ASCII").newEncoder();
- }
-
- @Override
- public boolean continueMerging(SectionInfo section, SectionInfo withSection,
- int sectionAppCount, int numAppsPerRow, int mergeCount) {
- // Continue merging if the number of hanging apps on the final row is less than some
- // fixed number (ragged), the merged rows has yet to exceed some minimum row count,
- // and while the number of merged sections is less than some fixed number of merges
- int rows = sectionAppCount / numAppsPerRow;
- int cols = sectionAppCount % numAppsPerRow;
-
- // Ensure that we do not merge across scripts, currently we only allow for english and
- // native scripts so we can test if both can just be ascii encoded
- boolean isCrossScript = false;
- if (section.firstAppItem != null && withSection.firstAppItem != null) {
- isCrossScript = mAsciiEncoder.canEncode(section.firstAppItem.sectionName) !=
- mAsciiEncoder.canEncode(withSection.firstAppItem.sectionName);
- }
- return (0 < cols && cols < mMinAppsPerRow) &&
- rows < mMinRowsInMergedSection &&
- mergeCount < mMaxAllowableMerges &&
- !isCrossScript;
- }
- }
-
- private static final int MIN_ROWS_IN_MERGED_SECTION_PHONE = 3;
- private static final int MAX_NUM_MERGES_PHONE = 2;
-
private Launcher mLauncher;
// The set of apps from the system not including predictions
@@ -249,20 +185,13 @@ public class AlphabeticalAppsList {
}
/**
- * Sets the number of apps per row. Used only for AppsContainerView.SECTIONED_GRID_COALESCED.
+ * Sets the number of apps per row.
*/
- public void setNumAppsPerRow(int numAppsPerRow, int numPredictedAppsPerRow) {
- // Update the merge algorithm
- DeviceProfile grid = mLauncher.getDeviceProfile();
- if (grid.isPhone) {
- mMergeAlgorithm = new PhoneMergeAlgorithm((int) Math.ceil(numAppsPerRow / 2f),
- MIN_ROWS_IN_MERGED_SECTION_PHONE, MAX_NUM_MERGES_PHONE);
- } else {
- mMergeAlgorithm = new TabletMergeAlgorithm();
- }
-
+ public void setNumAppsPerRow(int numAppsPerRow, int numPredictedAppsPerRow,
+ MergeAlgorithm mergeAlgorithm) {
mNumAppsPerRow = numAppsPerRow;
mNumPredictedAppsPerRow = numPredictedAppsPerRow;
+ mMergeAlgorithm = mergeAlgorithm;
updateAdapterItems();
}
@@ -599,13 +528,13 @@ public class AlphabeticalAppsList {
* Merges multiple sections to reduce visual raggedness.
*/
private void mergeSections() {
- // Ignore merging until we have a valid row size
- if (mNumAppsPerRow == 0) {
+ // 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 (AllAppsContainerView.GRID_MERGE_SECTIONS && !hasFilter()) {
+ if (!hasFilter()) {
int sectionAppCount = 0;
for (int i = 0; i < mSections.size() - 1; i++) {
SectionInfo section = mSections.get(i);