From a1503f47aa2fe140a5e83a4ea5d6478955ba97af Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 18 Aug 2016 17:01:24 -0700 Subject: [PATCH] Comparing widget sizes when sorting if the labels are same Bug: 21441837 Change-Id: Ib0e6d3b84389f900264a0d696d22057426973719 --- src/com/android/launcher3/model/WidgetItem.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/model/WidgetItem.java b/src/com/android/launcher3/model/WidgetItem.java index b3f0c8203d..0d7ba1e112 100644 --- a/src/com/android/launcher3/model/WidgetItem.java +++ b/src/com/android/launcher3/model/WidgetItem.java @@ -68,6 +68,17 @@ public class WidgetItem extends ComponentKey implements Comparable { return thisWorkProfile ? 1 : -1; } - return sCollator.compare(label, another.label); + int labelCompare = sCollator.compare(label, another.label); + if (labelCompare != 0) { + return labelCompare; + } + + // If the label is same, put the smaller widget before the larger widget. If the area is + // also same, put the widget with smaller height before. + int thisArea = spanX * spanY; + int otherArea = another.spanX * another.spanY; + return thisArea == otherArea + ? Integer.compare(spanY, another.spanY) + : Integer.compare(thisArea, otherArea); } }