OSDN Git Service

Sharesheet - Merge EXTRA_INITIAL_INTENTS + Ranked apps
authorMatt Pietal <mpietal@google.com>
Tue, 16 Apr 2019 16:53:28 +0000 (12:53 -0400)
committerMatt Pietal <mpietal@google.com>
Tue, 16 Apr 2019 19:15:22 +0000 (15:15 -0400)
Organize app-supplied EXTRA_INITIAL_INTENTS plus the highest ranked
apps into a single row (4 in portrait, 8 landscape)

Bug: 130429746
Test: Visual inspection
Change-Id: Icd0755d25b2801b42ea2c3a8c984e9e1f0c7987e

core/java/com/android/internal/app/ChooserActivity.java

index 4d4fe03..26141c4 100644 (file)
@@ -2591,12 +2591,24 @@ public class ChooserActivity extends ResolverActivity {
             }
         }
 
+        /**
+         * Need to merge CALLER + ranked STANDARD into a single row. All other types
+         * are placed into their own row as determined by their target type, and dividers
+         * are added in the list to separate each type.
+         */
+        int getRowType(int rowPosition) {
+            int positionType = mChooserListAdapter.getPositionTargetType(rowPosition);
+            if (positionType == ChooserListAdapter.TARGET_CALLER) {
+                return ChooserListAdapter.TARGET_STANDARD;
+            }
+
+            return positionType;
+        }
+
         void bindViewHolder(int rowPosition, RowViewHolder holder) {
             final int start = getFirstRowPosition(rowPosition);
-            final int startType = mChooserListAdapter.getPositionTargetType(start);
-
-            final int lastStartType = mChooserListAdapter.getPositionTargetType(
-                    getFirstRowPosition(rowPosition - 1));
+            final int startType = getRowType(start);
+            final int lastStartType = getRowType(getFirstRowPosition(rowPosition - 1));
 
             final ViewGroup row = holder.getViewGroup();
 
@@ -2608,7 +2620,7 @@ public class ChooserActivity extends ResolverActivity {
 
             int columnCount = holder.getColumnCount();
             int end = start + columnCount - 1;
-            while (mChooserListAdapter.getPositionTargetType(end) != startType && end >= start) {
+            while (getRowType(end) != startType && end >= start) {
                 end--;
             }
 
@@ -2660,14 +2672,15 @@ public class ChooserActivity extends ResolverActivity {
                 return row * getMaxTargetsPerRow();
             }
 
-            final int callerCount = mChooserListAdapter.getCallerTargetCount();
-            final int callerRows = (int) Math.ceil((float) callerCount / getMaxTargetsPerRow());
-            if (row < callerRows + serviceRows) {
+            final int callerAndRankedCount = mChooserListAdapter.getCallerTargetCount()
+                                                 + mChooserListAdapter.getRankedTargetCount();
+            final int callerAndRankedRows = getCallerAndRankedTargetRowCount();
+            if (row < callerAndRankedRows + serviceRows) {
                 return serviceCount + (row - serviceRows) * getMaxTargetsPerRow();
             }
 
-            return callerCount + serviceCount
-                    + (row - callerRows - serviceRows) * getMaxTargetsPerRow();
+            return callerAndRankedCount + serviceCount
+                    + (row - callerAndRankedRows - serviceRows) * getMaxTargetsPerRow();
         }
 
         public void handleScroll(View v, int y, int oldy) {