mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 02:38:20 +00:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user