OSDN Git Service

Ensuring that we use the screen width more optimally in AllApps.
authorWinson Chung <winsonc@google.com>
Mon, 1 Jun 2015 21:38:24 +0000 (14:38 -0700)
committerWinson Chung <winsonc@google.com>
Fri, 5 Jun 2015 16:49:12 +0000 (09:49 -0700)
- Fixing issue with prediction bar height being calculated incorrectly
- Fixing issue where the prediction bar divider was not drawn exactly
  between the bar and the first row of apps
- Removing padding to allow scrollbars to reach full height

Bug: 20222023
Bug: 21335377
Change-Id: I2c0614a36e2294d0d6184a6bff4847876ffe971e

res/layout/all_apps_container.xml
res/layout/all_apps_icon.xml
res/layout/all_apps_prediction_bar_icon.xml
res/values/dimens.xml
src/com/android/launcher3/BubbleTextView.java
src/com/android/launcher3/DeviceProfile.java
src/com/android/launcher3/FolderPagedView.java
src/com/android/launcher3/InvariantDeviceProfile.java
src/com/android/launcher3/Utilities.java
src/com/android/launcher3/allapps/AllAppsContainerView.java
src/com/android/launcher3/allapps/AllAppsGridAdapter.java

index a20ab46..fc77cd3 100644 (file)
@@ -38,6 +38,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="@dimen/all_apps_search_bar_height"
+        android:paddingBottom="@dimen/all_apps_prediction_bar_bottom_padding"
         android:orientation="horizontal"
         android:descendantFocusability="afterDescendants"
         android:focusable="true"
index 10ed25c..0985e95 100644 (file)
@@ -20,7 +20,7 @@
     android:id="@+id/icon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
-    android:layout_gravity="left|center_vertical"
+    android:layout_gravity="center"
     android:paddingTop="@dimen/all_apps_icon_top_bottom_padding"
     android:paddingBottom="@dimen/all_apps_icon_top_bottom_padding"
     android:focusable="true"
index 1e75d14..5f63f6b 100644 (file)
@@ -19,7 +19,7 @@
     style="@style/Icon.AllApps"
     android:id="@+id/icon"
     android:layout_width="0dp"
-    android:layout_height="match_parent"
+    android:layout_height="wrap_content"
     android:layout_gravity="center"
     android:layout_weight="1"
     android:focusable="true"
index 63edd88..2184ead 100644 (file)
     <dimen name="all_apps_grid_section_y_offset">8dp</dimen>
     <dimen name="all_apps_grid_section_text_size">24sp</dimen>
     <dimen name="all_apps_search_bar_height">52dp</dimen>
+    <dimen name="all_apps_search_bar_prediction_bar_padding">8dp</dimen>
     <dimen name="all_apps_icon_top_bottom_padding">8dp</dimen>
-    <dimen name="all_apps_icon_left_right_padding">18dp</dimen>
-    <dimen name="all_apps_prediction_icon_top_bottom_padding">12dp</dimen>
+    <dimen name="all_apps_icon_width_gap">24dp</dimen>
+    <dimen name="all_apps_prediction_bar_bottom_padding">16dp</dimen>
 
     <dimen name="all_apps_fast_scroll_bar_width">4dp</dimen>
     <dimen name="all_apps_fast_scroll_scrubber_touch_inset">-16dp</dimen>
index f4e306a..9a59feb 100644 (file)
@@ -52,7 +52,6 @@ public class BubbleTextView extends TextView {
     private static final float SHADOW_Y_OFFSET = 2.0f;
     private static final int SHADOW_LARGE_COLOUR = 0xDD000000;
     private static final int SHADOW_SMALL_COLOUR = 0xCC000000;
-    static final float PADDING_V = 3.0f;
 
     private static final int DISPLAY_WORKSPACE = 0;
     private static final int DISPLAY_ALL_APPS = 1;
index 82be409..9c59dab 100644 (file)
@@ -230,12 +230,12 @@ public class DeviceProfile {
     public boolean updateAppsViewNumCols(Resources res, int containerWidth) {
         int appsViewLeftMarginPx =
                 res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
-        int allAppsCellPaddingPx =
-                res.getDimensionPixelSize(R.dimen.all_apps_icon_left_right_padding);
+        int allAppsCellWidthGap =
+                res.getDimensionPixelSize(R.dimen.all_apps_icon_width_gap);
         int availableAppsWidthPx = (containerWidth > 0) ? containerWidth : availableWidthPx;
         int numAppsCols = (availableAppsWidthPx - appsViewLeftMarginPx) /
-                (allAppsIconSizePx + 2 * allAppsCellPaddingPx);
-        int numPredictiveAppCols = isPhone ? 4 : numAppsCols;
+                (allAppsIconSizePx + allAppsCellWidthGap);
+        int numPredictiveAppCols = Math.max(inv.minAllAppsPredictionColumns, numAppsCols);
         if ((numAppsCols != allAppsNumCols) ||
                 (numPredictiveAppCols != allAppsNumPredictiveCols)) {
             allAppsNumCols = numAppsCols;
index 7d90ba2..b7a5aa8 100644 (file)
@@ -87,8 +87,8 @@ public class FolderPagedView extends PagedView {
         LauncherAppState app = LauncherAppState.getInstance();
 
         InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
-        mMaxCountX = (int) profile.numFolderColumns;
-        mMaxCountY = (int) profile.numFolderRows;
+        mMaxCountX = profile.numFolderColumns;
+        mMaxCountY = profile.numFolderRows;
 
         mMaxItemsPerPage = mMaxCountX * mMaxCountY;
 
index fcaf834..ae204c4 100644 (file)
@@ -57,6 +57,11 @@ public class InvariantDeviceProfile {
     public int numColumns;
 
     /**
+     * The minimum number of predicted apps in all apps.
+     */
+    int minAllAppsPredictionColumns;
+
+    /**
      * Number of icons per row and column in the folder.
      */
     public int numFolderRows;
@@ -84,11 +89,12 @@ public class InvariantDeviceProfile {
 
     public InvariantDeviceProfile(InvariantDeviceProfile p) {
         this(p.name, p.minWidthDps, p.minHeightDps, p.numRows, p.numColumns,
-                p.numFolderRows, p.numFolderColumns, p.iconSize, p.iconTextSize, p.numHotseatIcons,
-                p.hotseatIconSize, p.defaultLayoutId);
+                p.numFolderRows, p.numFolderColumns, p.minAllAppsPredictionColumns,
+                p.iconSize, p.iconTextSize, p.numHotseatIcons, p.hotseatIconSize,
+                p.defaultLayoutId);
     }
 
-    InvariantDeviceProfile(String n, float w, float h, int r, int c, int fr, int fc,
+    InvariantDeviceProfile(String n, float w, float h, int r, int c, int fr, int fc, int maapc,
             float is, float its, float hs, float his, int dlId) {
         // Ensure that we have an odd number of hotseat items (since we need to place all apps)
         if (hs % 2 == 0) {
@@ -102,6 +108,7 @@ public class InvariantDeviceProfile {
         numColumns = c;
         numFolderRows = fr;
         numFolderColumns = fc;
+        minAllAppsPredictionColumns = maapc;
         iconSize = is;
         iconTextSize = its;
         numHotseatIcons = hs;
@@ -137,6 +144,7 @@ public class InvariantDeviceProfile {
         defaultLayoutId = closestProfile.defaultLayoutId;
         numFolderRows = closestProfile.numFolderRows;
         numFolderColumns = closestProfile.numFolderColumns;
+        minAllAppsPredictionColumns = closestProfile.minAllAppsPredictionColumns;
 
         iconSize = interpolatedDeviceProfileOut.iconSize;
         iconBitmapSize = Utilities.pxFromDp(iconSize, dm);
@@ -166,30 +174,30 @@ public class InvariantDeviceProfile {
         // width, height, #rows, #columns, #folder rows, #folder columns,
         // iconSize, iconTextSize, #hotseat, #hotseatIconSize, defaultLayoutId.
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Super Short Stubby",
-                255, 300,     2, 3, 2, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));
+                255, 300,     2, 3, 2, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Shorter Stubby",
-                255, 400,     3, 3, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));
+                255, 400,     3, 3, 3, 3, 3, 48, 13, 3, 48, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Short Stubby",
-                275, 420,     3, 4, 3, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));
+                275, 420,     3, 4, 3, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Stubby",
-                255, 450,     3, 4, 3, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));
+                255, 450,     3, 4, 3, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus S",
-                296, 491.33f, 4, 4, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));
+                296, 491.33f, 4, 4, 4, 4, 4, 48, 13, 5, 48, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 4",
-                335, 567,     4, 4, 4, 4, DEFAULT_ICON_SIZE_DP, 13, 5, 56, R.xml.default_workspace_4x4));
+                335, 567,     4, 4, 4, 4, 4, DEFAULT_ICON_SIZE_DP, 13, 5, 56, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 5",
-                359, 567,     4, 4, 4, 4, DEFAULT_ICON_SIZE_DP, 13, 5, 56, R.xml.default_workspace_4x4));
+                359, 567,     4, 4, 4, 4, 4, DEFAULT_ICON_SIZE_DP, 13, 5, 56, R.xml.default_workspace_4x4));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Large Phone",
-                406, 694,     5, 5, 4, 4,  64, 14.4f,  5, 56, R.xml.default_workspace_5x5));
+                406, 694,     5, 5, 4, 4, 4, 64, 14.4f,  5, 56, R.xml.default_workspace_5x5));
         // The tablet profile is odd in that the landscape orientation
         // also includes the nav bar on the side
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 7",
-                575, 904,     5, 6, 4, 5, 72, 14.4f,  7, 60, R.xml.default_workspace_5x6));
+                575, 904,     5, 6, 4, 5, 4, 72, 14.4f,  7, 60, R.xml.default_workspace_5x6));
         // Larger tablet profiles always have system bars on the top & bottom
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("Nexus 10",
-                727, 1207,    5, 6, 4, 5, 76, 14.4f,  7, 64, R.xml.default_workspace_5x6));
+                727, 1207,    5, 6, 4, 5, 4, 76, 14.4f,  7, 64, R.xml.default_workspace_5x6));
         predefinedDeviceProfiles.add(new InvariantDeviceProfile("20-inch Tablet",
-                1527, 2527,   7, 7, 6, 6, 100, 20,  7, 72, R.xml.default_workspace_4x4));
+                1527, 2527,   7, 7, 6, 6, 4, 100, 20,  7, 72, R.xml.default_workspace_4x4));
         return predefinedDeviceProfiles;
     }
 
index cffcd34..0877b45 100644 (file)
@@ -54,7 +54,6 @@ import android.util.SparseArray;
 import android.util.TypedValue;
 import android.view.View;
 import android.widget.Toast;
-
 import junit.framework.Assert;
 
 import java.io.ByteArrayOutputStream;
@@ -625,6 +624,16 @@ public final class Utilities {
         return m.replaceAll("$1");
     }
 
+    /**
+     * Calculates the height of a given string at a specific text size.
+     */
+    public static float calculateTextHeight(float textSizePx) {
+        Paint p = new Paint();
+        p.setTextSize(textSizePx);
+        Paint.FontMetrics fm = p.getFontMetrics();
+        return -fm.top + fm.bottom;
+    }
+
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
     public static boolean isRtl(Resources res) {
         return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) &&
index 9386500..76ca963 100644 (file)
@@ -20,6 +20,7 @@ import android.annotation.TargetApi;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.Paint;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
@@ -239,11 +240,11 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
         mLauncher = (Launcher) context;
         DeviceProfile grid = mLauncher.getDeviceProfile();
 
-        mContainerInset = context.getResources().getDimensionPixelSize(
-                R.dimen.all_apps_container_inset);
-        mPredictionBarHeight = grid.allAppsIconSizePx + grid.iconDrawablePaddingOriginalPx +
-                grid.allAppsIconTextSizePx +
-                2 * res.getDimensionPixelSize(R.dimen.all_apps_prediction_icon_top_bottom_padding);
+        mContainerInset = res.getDimensionPixelSize(R.dimen.all_apps_container_inset);
+        mPredictionBarHeight = (int) (grid.allAppsIconSizePx + grid.iconDrawablePaddingOriginalPx +
+                Utilities.calculateTextHeight(grid.allAppsIconTextSizePx) +
+                2 * res.getDimensionPixelSize(R.dimen.all_apps_icon_top_bottom_padding) +
+                res.getDimensionPixelSize(R.dimen.all_apps_prediction_bar_bottom_padding));
 
         mLayoutInflater = LayoutInflater.from(context);
 
@@ -497,11 +498,11 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
         int startMargin = grid.isPhone ? mContentMarginStart : 0;
         int inset = mFixedBounds.isEmpty() ? mContainerInset : mFixedBoundsContainerInset;
         if (isRtl) {
-            mAppsRecyclerView.setPadding(inset + mAppsRecyclerView.getScrollbarWidth(), inset,
-                    inset + startMargin, inset);
+            mAppsRecyclerView.setPadding(inset + mAppsRecyclerView.getScrollbarWidth(), 0,
+                    inset + startMargin, 0);
         } else {
-            mAppsRecyclerView.setPadding(inset + startMargin, inset,
-                    inset + mAppsRecyclerView.getScrollbarWidth(), inset);
+            mAppsRecyclerView.setPadding(inset + startMargin, 0,
+                    inset + mAppsRecyclerView.getScrollbarWidth(), 0);
         }
 
         // Update the header bar
index 307d940..102e7ae 100644 (file)
@@ -139,7 +139,7 @@ class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.ViewHol
 
                 if (shouldDrawItemDivider(holder, items) && !hasDrawnPredictedAppsDivider) {
                     // Draw the divider under the predicted apps
-                    int top = child.getTop() + child.getHeight();
+                    int top = child.getTop() + child.getHeight() - mPredictionBarBottomPadding / 2;
                     c.drawLine(mBackgroundPadding.left, top,
                             parent.getWidth() - mBackgroundPadding.right, top,
                             mPredictedAppsDividerPaint);
@@ -294,6 +294,7 @@ class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.ViewHol
     private View.OnLongClickListener mIconLongClickListener;
     @Thunk final Rect mBackgroundPadding = new Rect();
     @Thunk int mPredictionBarHeight;
+    @Thunk int mPredictionBarBottomPadding;
     @Thunk int mAppsPerRow;
     @Thunk boolean mIsRtl;
     private String mEmptySearchText;
@@ -336,6 +337,8 @@ class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.ViewHol
         mPredictedAppsDividerPaint.setStrokeWidth(Utilities.pxFromDp(1f, res.getDisplayMetrics()));
         mPredictedAppsDividerPaint.setColor(0x1E000000);
         mPredictedAppsDividerPaint.setAntiAlias(true);
+        mPredictionBarBottomPadding =
+                res.getDimensionPixelSize(R.dimen.all_apps_prediction_bar_bottom_padding);
     }
 
     /**