diff options
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index b51ef168a..da72a7b76 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; @@ -705,6 +706,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)); } |