diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-04-24 15:20:43 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-04-24 15:28:20 -0700 |
commit | f7a29e83f06909b378dba39c83a522375682710a (patch) | |
tree | 8b42bc5a30c2e0c87a638048d29a9094366bf4ba /src/com/android/launcher3/Utilities.java | |
parent | e2df0620c13b9dc7e63224153b98fdbb48546f9b (diff) | |
download | android_packages_apps_Trebuchet-f7a29e83f06909b378dba39c83a522375682710a.tar.gz android_packages_apps_Trebuchet-f7a29e83f06909b378dba39c83a522375682710a.tar.bz2 android_packages_apps_Trebuchet-f7a29e83f06909b378dba39c83a522375682710a.zip |
Removing some unused method params from CellLayout
> Replacing various distance calculations with Math.hypot
> Moving findVacantCell to Utilities
Change-Id: I0cb194b603e52b3bb2b29a095bb4da2bb408ab13
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 22677c8ea..2dbf078a4 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -583,4 +583,37 @@ public final class Utilities { return lhs.rank - rhs.rank; } }; + + /** + * Find the first vacant cell, if there is one. + * + * @param vacant Holds the x and y coordinate of the vacant cell + * @param spanX Horizontal cell span. + * @param spanY Vertical cell span. + * + * @return true if a vacant cell was found + */ + public static boolean findVacantCell(int[] vacant, int spanX, int spanY, + int xCount, int yCount, boolean[][] occupied) { + + for (int y = 0; (y + spanY) <= yCount; y++) { + for (int x = 0; (x + spanX) <= xCount; x++) { + boolean available = !occupied[x][y]; + out: for (int i = x; i < x + spanX; i++) { + for (int j = y; j < y + spanY; j++) { + available = available && !occupied[i][j]; + if (!available) break out; + } + } + + if (available) { + vacant[0] = x; + vacant[1] = y; + return true; + } + } + } + + return false; + } } |