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:
Sunny Goyal
2015-08-20 12:33:21 -07:00
parent 7b7d6d09ee
commit 756cd26592
15 changed files with 95 additions and 149 deletions

View File

@@ -48,7 +48,6 @@ import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.Choreographer;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -140,9 +139,6 @@ public class Workspace extends PagedView
private int mDragOverX = -1;
private int mDragOverY = -1;
private static Rect mLandscapeCellLayoutMetrics = null;
private static Rect mPortraitCellLayoutMetrics = null;
CustomContentCallbacks mCustomContentCallbacks;
boolean mCustomContentShowing;
private float mLastCustomContentScrollProgress = -1f;
@@ -2851,45 +2847,6 @@ public class Workspace extends PagedView
}
}
/** Return a rect that has the cellWidth/cellHeight (left, top), and
* widthGap/heightGap (right, bottom) */
static Rect getCellLayoutMetrics(Launcher launcher, int orientation) {
LauncherAppState app = LauncherAppState.getInstance();
InvariantDeviceProfile inv = app.getInvariantDeviceProfile();
Display display = launcher.getWindowManager().getDefaultDisplay();
Point smallestSize = new Point();
Point largestSize = new Point();
display.getCurrentSizeRange(smallestSize, largestSize);
int countX = (int) inv.numColumns;
int countY = (int) inv.numRows;
boolean isLayoutRtl = Utilities.isRtl(launcher.getResources());
if (orientation == CellLayout.LANDSCAPE) {
if (mLandscapeCellLayoutMetrics == null) {
Rect padding = inv.landscapeProfile.getWorkspacePadding(isLayoutRtl);
int width = largestSize.x - padding.left - padding.right;
int height = smallestSize.y - padding.top - padding.bottom;
mLandscapeCellLayoutMetrics = new Rect();
mLandscapeCellLayoutMetrics.set(
DeviceProfile.calculateCellWidth(width, countX),
DeviceProfile.calculateCellHeight(height, countY), 0, 0);
}
return mLandscapeCellLayoutMetrics;
} else if (orientation == CellLayout.PORTRAIT) {
if (mPortraitCellLayoutMetrics == null) {
Rect padding = inv.portraitProfile.getWorkspacePadding(isLayoutRtl);
int width = smallestSize.x - padding.left - padding.right;
int height = largestSize.y - padding.top - padding.bottom;
mPortraitCellLayoutMetrics = new Rect();
mPortraitCellLayoutMetrics.set(
DeviceProfile.calculateCellWidth(width, countX),
DeviceProfile.calculateCellHeight(height, countY), 0, 0);
}
return mPortraitCellLayoutMetrics;
}
return null;
}
@Override
public void onDragExit(DragObject d) {
if (ENFORCE_DRAG_EVENT_ORDER) {