summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/Utilities.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r--src/com/android/launcher3/Utilities.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index bf11aa19e..8ffc471a3 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -39,6 +39,7 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
+import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -706,6 +707,39 @@ public final class Utilities {
size, metrics));
}
+ public static Point caluclateFolderContentDimensions(int count, int maxCountX, int maxCountY) {
+ final Point point = new Point();
+ final int maxItemsPerPage = maxCountX * maxCountY;
+ boolean done;
+ if (count >= maxItemsPerPage) {
+ point.x = maxCountX;
+ point.y = maxCountY;
+ done = true;
+ } else {
+ done = false;
+ }
+
+ while (!done) {
+ int oldCountX = point.x;
+ int oldCountY = point.y;
+ if (point.x * point.y < count) {
+ // Current grid is too small, expand it
+ if ((point.x <= point.y || point.y == maxCountY) && point.x < maxCountX) {
+ point.x++;
+ } else if (point.y < maxCountY) {
+ point.y++;
+ }
+ if (point.y == 0) point.y++;
+ } else if ((point.y - 1) * point.x >= count && point.y >= point.x) {
+ point.y = Math.max(0, point.y - 1);
+ } else if ((point.x - 1) * point.y >= count) {
+ point.x = Math.max(0, point.x - 1);
+ }
+ done = point.x == oldCountX && point.y == oldCountY;
+ }
+ return point;
+ }
+
public static String createDbSelectionQuery(String columnName, Iterable<?> values) {
return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, TextUtils.join(", ", values));
}