diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-08-20 12:33:21 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-08-20 12:56:58 -0700 |
commit | 756cd26592dee6b956becdc24d60995c64de9153 (patch) | |
tree | 3d415a7820c619e6c85f78000016f4403c346f2b /src/com/android/launcher3/AppWidgetResizeFrame.java | |
parent | 7b7d6d09eec6b9f65273f597b2d93fc53a9069ff (diff) | |
download | android_packages_apps_Trebuchet-756cd26592dee6b956becdc24d60995c64de9153.tar.gz android_packages_apps_Trebuchet-756cd26592dee6b956becdc24d60995c64de9153.tar.bz2 android_packages_apps_Trebuchet-756cd26592dee6b956becdc24d60995c64de9153.zip |
General code refactoring
> Removing utility method for isAttachedToWindow
> Moving logic to calculate cell size from workspace to DeviceProfile
> Replacing some constants with xml resource variables
> Saving the item info using content values for better compatibility with other methods
Change-Id: Idd612633d97a6241cb31148df9466031374bd5a0
Diffstat (limited to 'src/com/android/launcher3/AppWidgetResizeFrame.java')
-rw-r--r-- | src/com/android/launcher3/AppWidgetResizeFrame.java | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java index 2846b55e0..6818929f7 100644 --- a/src/com/android/launcher3/AppWidgetResizeFrame.java +++ b/src/com/android/launcher3/AppWidgetResizeFrame.java @@ -11,6 +11,7 @@ import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import android.content.res.Resources; +import android.graphics.Point; import android.graphics.Rect; import android.view.Gravity; import android.widget.FrameLayout; @@ -21,7 +22,10 @@ public class AppWidgetResizeFrame extends FrameLayout { private static final float DIMMED_HANDLE_ALPHA = 0f; private static final float RESIZE_THRESHOLD = 0.66f; - private static Rect sTmpRect = new Rect(); + private static final Rect sTmpRect = new Rect(); + + // Represents the cell size on the grid in the two orientations. + private static Point[] sCellSize; private final Launcher mLauncher; private final LauncherAppWidgetHostView mWidgetView; @@ -343,28 +347,27 @@ public class AppWidgetResizeFrame extends FrameLayout { } public static Rect getWidgetSizeRanges(Launcher launcher, int spanX, int spanY, Rect rect) { + if (sCellSize == null) { + InvariantDeviceProfile inv = LauncherAppState.getInstance().getInvariantDeviceProfile(); + + // Initiate cell sizes. + sCellSize = new Point[2]; + sCellSize[0] = inv.landscapeProfile.getCellSize(); + sCellSize[1] = inv.portraitProfile.getCellSize(); + } + if (rect == null) { rect = new Rect(); } - Rect landMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.LANDSCAPE); - Rect portMetrics = Workspace.getCellLayoutMetrics(launcher, CellLayout.PORTRAIT); final float density = launcher.getResources().getDisplayMetrics().density; // Compute landscape size - int cellWidth = landMetrics.left; - int cellHeight = landMetrics.top; - int widthGap = landMetrics.right; - int heightGap = landMetrics.bottom; - int landWidth = (int) ((spanX * cellWidth + (spanX - 1) * widthGap) / density); - int landHeight = (int) ((spanY * cellHeight + (spanY - 1) * heightGap) / density); + int landWidth = (int) ((spanX * sCellSize[0].x) / density); + int landHeight = (int) ((spanY * sCellSize[0].y) / density); // Compute portrait size - cellWidth = portMetrics.left; - cellHeight = portMetrics.top; - widthGap = portMetrics.right; - heightGap = portMetrics.bottom; - int portWidth = (int) ((spanX * cellWidth + (spanX - 1) * widthGap) / density); - int portHeight = (int) ((spanY * cellHeight + (spanY - 1) * heightGap) / density); + int portWidth = (int) ((spanX * sCellSize[1].x) / density); + int portHeight = (int) ((spanY * sCellSize[1].y) / density); rect.set(portWidth, landHeight, landWidth, portHeight); return rect; } |