summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2010-07-26 22:02:18 -0700
committerAdam Cohen <adamcohen@google.com>2010-08-04 11:03:47 -0700
commitd22015cd37ea6ef53762eca5be57daca123ff607 (patch)
treefcb6a85e600ec2a4f2dd377900a0c08eac6f5116 /src
parent7ef4f752e1eee17389ca41791f83d4ac21714419 (diff)
downloadandroid_packages_apps_Trebuchet-d22015cd37ea6ef53762eca5be57daca123ff607.tar.gz
android_packages_apps_Trebuchet-d22015cd37ea6ef53762eca5be57daca123ff607.tar.bz2
android_packages_apps_Trebuchet-d22015cd37ea6ef53762eca5be57daca123ff607.zip
Cleaning up grid size specification in Launcher
This commit eliminates the notion of in-place rotations and a bunch of associated complexities (including the notion of canonical coordinates). Further, the number of x and y cells per workspace screen is now being stored in a single location in the XML definition of Workspace. This fixes a couple bugs where incorrect values were being used. Finally, eliminated the notion of "shortAxis" and "longAxis" in terms of padding and cell count. These have been translated to corresponding x and y axis values. Change-Id: I30cfed66f82d739355b3f01730b28b6c0437989c
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/CellLayout.java153
-rw-r--r--src/com/android/launcher2/InstallShortcutReceiver.java4
-rw-r--r--src/com/android/launcher2/Launcher.java8
-rw-r--r--src/com/android/launcher2/LauncherModel.java116
-rw-r--r--src/com/android/launcher2/LauncherModelOrientationHelper.java180
-rw-r--r--src/com/android/launcher2/Workspace.java86
6 files changed, 83 insertions, 464 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 16f8135f1..2a8c5732e 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -53,18 +53,13 @@ public class CellLayout extends ViewGroup {
private int mCellWidth;
private int mCellHeight;
- private int mLongAxisStartPadding;
- private int mLongAxisEndPadding;
- private int mShortAxisStartPadding;
- private int mShortAxisEndPadding;
-
private int mLeftPadding;
private int mRightPadding;
private int mTopPadding;
private int mBottomPadding;
- private int mShortAxisCells;
- private int mLongAxisCells;
+ private int mCountX;
+ private int mCountY;
private int mWidthGap;
private int mHeightGap;
@@ -132,17 +127,17 @@ public class CellLayout extends ViewGroup {
mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
- mLongAxisStartPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_longAxisStartPadding, 10);
- mLongAxisEndPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_longAxisEndPadding, 10);
- mShortAxisStartPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_shortAxisStartPadding, 10);
- mShortAxisEndPadding =
- a.getDimensionPixelSize(R.styleable.CellLayout_shortAxisEndPadding, 10);
+ mLeftPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_xAxisStartPadding, 10);
+ mRightPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_xAxisEndPadding, 10);
+ mTopPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_yAxisStartPadding, 10);
+ mBottomPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_yAxisEndPadding, 10);
- mShortAxisCells = a.getInt(R.styleable.CellLayout_shortAxisCells, 4);
- mLongAxisCells = a.getInt(R.styleable.CellLayout_longAxisCells, 4);
+ mCountX = LauncherModel.getCellCountX();
+ mCountY = LauncherModel.getCellCountY();
a.recycle();
@@ -196,11 +191,11 @@ public class CellLayout extends ViewGroup {
}
int getCountX() {
- return mPortrait ? mShortAxisCells : mLongAxisCells;
+ return mCountX;
}
int getCountY() {
- return mPortrait ? mLongAxisCells : mShortAxisCells;
+ return mCountY;
}
// Takes canonical layout parameters
@@ -209,11 +204,11 @@ public class CellLayout extends ViewGroup {
// Generate an id for each view, this assumes we have at most 256x256 cells
// per workspace screen
- if (lp.cellX >= 0 && lp.cellX <= getCountX() - 1 && lp.cellY >= 0 && lp.cellY <= getCountY() - 1) {
+ if (lp.cellX >= 0 && lp.cellX <= mCountX - 1 && lp.cellY >= 0 && lp.cellY <= mCountY - 1) {
// If the horizontal or vertical span is set to -1, it is taken to
// mean that it spans the extent of the CellLayout
- if (lp.cellHSpan < 0) lp.cellHSpan = getCountX();
- if (lp.cellVSpan < 0) lp.cellVSpan = getCountY();
+ if (lp.cellHSpan < 0) lp.cellHSpan = mCountX;
+ if (lp.cellVSpan < 0) lp.cellVSpan = mCountY;
child.setId(childId);
@@ -287,8 +282,8 @@ public class CellLayout extends ViewGroup {
pointToCellExact(x, y, cellXY);
final boolean portrait = mPortrait;
- final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
- final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+ final int xCount = mCountX;
+ final int yCount = mCountY;
final boolean[][] occupied = mOccupied;
findOccupiedCells(xCount, yCount, occupied, null, true);
@@ -340,9 +335,8 @@ public class CellLayout extends ViewGroup {
public CellInfo getTag() {
final CellInfo info = (CellInfo) super.getTag();
if (mDirtyTag && info.valid) {
- final boolean portrait = mPortrait;
- final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
- final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+ final int xCount = mCountX;
+ final int yCount = mCountY;
final boolean[][] occupied = mOccupied;
findOccupiedCells(xCount, yCount, occupied, null, true);
@@ -452,9 +446,8 @@ public class CellLayout extends ViewGroup {
}
CellInfo findAllVacantCells(boolean[] occupiedCells, View ignoreView) {
- final boolean portrait = mPortrait;
- final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
- final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+ final int xCount = mCountX;
+ final int yCount = mCountY;
boolean[][] occupied = mOccupied;
@@ -507,16 +500,14 @@ public class CellLayout extends ViewGroup {
* @param result Array of 2 ints to hold the x and y coordinate of the cell
*/
void pointToCellExact(int x, int y, int[] result) {
- final boolean portrait = mPortrait;
-
final int hStartPadding = getLeftPadding();
final int vStartPadding = getTopPadding();
result[0] = (x - hStartPadding) / (mCellWidth + mWidthGap);
result[1] = (y - vStartPadding) / (mCellHeight + mHeightGap);
- final int xAxis = portrait ? mShortAxisCells : mLongAxisCells;
- final int yAxis = portrait ? mLongAxisCells : mShortAxisCells;
+ final int xAxis = mCountX;
+ final int yAxis = mCountY;
if (result[0] < 0) result[0] = 0;
if (result[0] >= xAxis) result[0] = xAxis - 1;
@@ -588,75 +579,24 @@ public class CellLayout extends ViewGroup {
throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions");
}
- final int shortAxisCells = mShortAxisCells;
- final int longAxisCells = mLongAxisCells;
final int cellWidth = mCellWidth;
final int cellHeight = mCellHeight;
- boolean portrait = heightSpecSize > widthSpecSize;
- if (portrait != mPortrait || mOccupied == null) {
- if (portrait) {
- mOccupied = new boolean[mShortAxisCells][mLongAxisCells];
- } else {
- mOccupied = new boolean[mLongAxisCells][mShortAxisCells];
- }
+ if (mOccupied == null) {
+ mOccupied = new boolean[mCountX][mCountY];
}
- mPortrait = portrait;
-
- int numShortGaps = shortAxisCells - 1;
- int numLongGaps = longAxisCells - 1;
-
- if (mPortrait) {
- int vSpaceLeft = heightSpecSize - mLongAxisStartPadding
- - mLongAxisEndPadding - (cellHeight * longAxisCells);
- mHeightGap = vSpaceLeft / numLongGaps;
-
- int hSpaceLeft = widthSpecSize - mShortAxisStartPadding
- - mShortAxisEndPadding - (cellWidth * shortAxisCells);
- if (numShortGaps > 0) {
- mWidthGap = hSpaceLeft / numShortGaps;
- } else {
- mWidthGap = 0;
- }
- if (LauncherApplication.isInPlaceRotationEnabled()) {
- mWidthGap = mHeightGap = Math.min(mHeightGap, mWidthGap);
- mLeftPadding = mRightPadding = (widthSpecSize - cellWidth
- * shortAxisCells - (shortAxisCells - 1) * mWidthGap) / 2;
- mTopPadding = mBottomPadding = (heightSpecSize - cellHeight
- * longAxisCells - (longAxisCells - 1) * mHeightGap) / 2;
- } else {
- mLeftPadding = mShortAxisStartPadding;
- mRightPadding = mShortAxisEndPadding;
- mTopPadding = mLongAxisStartPadding;
- mBottomPadding = mLongAxisEndPadding;
- }
- } else {
- int hSpaceLeft = widthSpecSize - mLongAxisStartPadding
- - mLongAxisEndPadding - (cellWidth * longAxisCells);
- mWidthGap = hSpaceLeft / numLongGaps;
-
- int vSpaceLeft = heightSpecSize - mShortAxisStartPadding
- - mShortAxisEndPadding - (cellHeight * shortAxisCells);
- if (numShortGaps > 0) {
- mHeightGap = vSpaceLeft / numShortGaps;
- } else {
- mHeightGap = 0;
- }
+ int numWidthGaps = mCountX - 1;
+ int numHeightGaps = mCountY - 1;
+
+ int vSpaceLeft = heightSpecSize - mTopPadding
+ - mBottomPadding - (cellHeight * mCountY);
+ mHeightGap = vSpaceLeft / numHeightGaps;
+
+ int hSpaceLeft = widthSpecSize - mLeftPadding
+ - mRightPadding - (cellWidth * mCountX);
+ mWidthGap = hSpaceLeft / numWidthGaps;
- if (LauncherApplication.isScreenXLarge()) {
- mWidthGap = mHeightGap = Math.min(mHeightGap, mWidthGap);
- mLeftPadding = mRightPadding = (widthSpecSize - cellWidth
- * longAxisCells - (longAxisCells - 1) * mWidthGap) / 2 ;
- mTopPadding = mBottomPadding = (heightSpecSize - cellHeight
- * shortAxisCells - (shortAxisCells - 1) * mHeightGap) / 2;
- } else {
- mLeftPadding = mLongAxisStartPadding;
- mRightPadding = mLongAxisEndPadding;
- mTopPadding = mShortAxisStartPadding;
- mBottomPadding = mShortAxisEndPadding;
- }
- }
int count = getChildCount();
for (int i = 0; i < count; i++) {
@@ -821,8 +761,8 @@ public class CellLayout extends ViewGroup {
* @param result The estimated drop cell X and Y.
*/
void estimateDropCell(int originX, int originY, int spanX, int spanY, int[] result) {
- final int countX = getCountX();
- final int countY = getCountY();
+ final int countX = mCountX;
+ final int countY = mCountY;
pointToCellRounded(originX, originY, result);
@@ -861,8 +801,8 @@ public class CellLayout extends ViewGroup {
bottomRight[0] += mCellWidth;
bottomRight[1] += mCellHeight;
- final int countX = mPortrait ? mShortAxisCells : mLongAxisCells;
- final int countY = mPortrait ? mLongAxisCells : mShortAxisCells;
+ final int countX = mCountX;
+ final int countY = mCountY;
// TODO: It's not necessary to do this every time, but it's not especially expensive
findOccupiedCells(countX, countY, mOccupied, view, false);
@@ -987,7 +927,6 @@ public class CellLayout extends ViewGroup {
* @param resultRect Rect into which to put the results
*/
public void cellToRect(int cellX, int cellY, int cellHSpan, int cellVSpan, RectF resultRect) {
- final boolean portrait = mPortrait;
final int cellWidth = mCellWidth;
final int cellHeight = mCellHeight;
final int widthGap = mWidthGap;
@@ -1043,9 +982,8 @@ public class CellLayout extends ViewGroup {
* @return True if a vacant cell was found
*/
public boolean getVacantCell(int[] vacant, int spanX, int spanY) {
- final boolean portrait = mPortrait;
- final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
- final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+ final int xCount = mCountX;
+ final int yCount = mCountY;
final boolean[][] occupied = mOccupied;
findOccupiedCells(xCount, yCount, occupied, null, true);
@@ -1081,9 +1019,8 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
* Update the array of occupied cells (mOccupied), and return a flattened copy of the array.
*/
boolean[] getOccupiedCellsFlattened() {
- final boolean portrait = mPortrait;
- final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
- final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+ final int xCount = mCountX;
+ final int yCount = mCountY;
final boolean[][] occupied = mOccupied;
findOccupiedCells(xCount, yCount, occupied, null, true);
diff --git a/src/com/android/launcher2/InstallShortcutReceiver.java b/src/com/android/launcher2/InstallShortcutReceiver.java
index 36380540d..992bab151 100644
--- a/src/com/android/launcher2/InstallShortcutReceiver.java
+++ b/src/com/android/launcher2/InstallShortcutReceiver.java
@@ -84,8 +84,8 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
}
private static boolean findEmptyCell(Context context, int[] xy, int screen) {
- final int xCount = Launcher.NUMBER_CELLS_X;
- final int yCount = Launcher.NUMBER_CELLS_Y;
+ final int xCount = LauncherModel.getCellCountX();
+ final int yCount = LauncherModel.getCellCountY();
boolean[][] occupied = new boolean[xCount][yCount];
ArrayList<ItemInfo> items = LauncherModel.getItemsInLocalCoordinates(context);
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 83fe11470..ee8543668 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -128,8 +128,6 @@ public final class Launcher extends Activity
static final int SCREEN_COUNT = 5;
static final int DEFAULT_SCREEN = 2;
- static final int NUMBER_CELLS_X = 4;
- static final int NUMBER_CELLS_Y = 4;
static final int DIALOG_CREATE_SHORTCUT = 1;
static final int DIALOG_RENAME_FOLDER = 2;
@@ -294,12 +292,6 @@ public final class Launcher extends Activity
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
-
- if (LauncherApplication.isInPlaceRotationEnabled()) {
- mModel.updateOrientation();
- mWorkspace.refreshWorkspaceChildren();
- mWorkspace.rotateCurrentScreensChildren();
- }
}
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index 45cef437c..6c3ddd22f 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -90,7 +90,8 @@ public class LauncherModel extends BroadcastReceiver {
private Bitmap mDefaultIcon;
- private static LauncherModelOrientationHelper mModelOrientationHelper;
+ private static int mCellCountX;
+ private static int mCellCountY;
public interface Callbacks {
public int getCurrentWorkspaceScreen();
@@ -110,7 +111,6 @@ public class LauncherModel extends BroadcastReceiver {
mApp = app;
mAllAppsList = new AllAppsList(iconCache);
mIconCache = iconCache;
- mModelOrientationHelper = new LauncherModelOrientationHelper(mApp);
mDefaultIcon = Utilities.createIconBitmap(
app.getPackageManager().getDefaultActivityIcon(), app);
@@ -143,14 +143,6 @@ public class LauncherModel extends BroadcastReceiver {
}
}
- static int getCurrentOrientation() {
- return mModelOrientationHelper.getCurrentOrientation();
- }
-
- static int getPreviousOrientationRelativeToCurrent() {
- return mModelOrientationHelper.getPreviousOrientationRelativeToCurrent();
- }
-
/**
* Move an item in the DB to a new <container, screen, cellX, cellY>
*/
@@ -164,11 +156,10 @@ public class LauncherModel extends BroadcastReceiver {
final ContentValues values = new ContentValues();
final ContentResolver cr = context.getContentResolver();
- final LauncherModelOrientationHelper.Coordinates coord = mModelOrientationHelper.getCanonicalCoordinates(item);
values.put(LauncherSettings.Favorites.CONTAINER, item.container);
- values.put(LauncherSettings.Favorites.CELLX, coord.x);
- values.put(LauncherSettings.Favorites.CELLY, coord.y);
+ values.put(LauncherSettings.Favorites.CELLX, cellX);
+ values.put(LauncherSettings.Favorites.CELLY, cellY);
values.put(LauncherSettings.Favorites.SCREEN, item.screen);
cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null);
@@ -264,13 +255,12 @@ public class LauncherModel extends BroadcastReceiver {
break;
}
- final LauncherModelOrientationHelper.Coordinates coord = mModelOrientationHelper.getLocalCoordinates(c.getInt(cellXIndex), c.getInt(cellYIndex), 1, 1);
folderInfo.title = c.getString(titleIndex);
folderInfo.id = id;
folderInfo.container = c.getInt(containerIndex);
folderInfo.screen = c.getInt(screenIndex);
- folderInfo.cellX = coord.x;
- folderInfo.cellY = coord.y;
+ folderInfo.cellX = c.getInt(cellXIndex);
+ folderInfo.cellY = c.getInt(cellYIndex);
return folderInfo;
}
@@ -296,9 +286,7 @@ public class LauncherModel extends BroadcastReceiver {
final ContentResolver cr = context.getContentResolver();
item.onAddToDatabase(values);
- // update the values to be written with their canonical counterparts
- final LauncherModelOrientationHelper.Coordinates coord = mModelOrientationHelper.getCanonicalCoordinates(item);
- item.updateValuesWithCoordinates(values, coord.x, coord.y);
+ item.updateValuesWithCoordinates(values, cellX, cellY);
Uri result = cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
@@ -311,31 +299,16 @@ public class LauncherModel extends BroadcastReceiver {
/**
* Creates a new unique child id, for a given cell span across all layouts.
*/
- static int getCanonicalCellLayoutChildId(int cellId, int screen, int localCellX, int localCellY, int spanX, int spanY) {
- if (LauncherApplication.isInPlaceRotationEnabled()) {
- LauncherModelOrientationHelper.Coordinates coord = mModelOrientationHelper.getCanonicalCoordinates(localCellX, localCellY, spanX, spanY);
- return ((screen & 0xFF) << 16) | (coord.x & 0xFF) << 8 | (coord.y & 0xFF);
- } else {
- return ((cellId & 0xFF) << 16) | (localCellX & 0xFF) << 8 | (localCellY & 0xFF);
- }
- }
-
- /*
- * Convenience functions to help return the local device width and height.
- */
- static int getLocalDeviceWidth() {
- return mModelOrientationHelper.getLocalDeviceWidth();
+ static int getCellLayoutChildId(int cellId, int screen, int localCellX, int localCellY, int spanX, int spanY) {
+ return ((cellId & 0xFF) << 16) | (localCellX & 0xFF) << 8 | (localCellY & 0xFF);
}
- static int getLocalDeviceHeight() {
- return mModelOrientationHelper.getLocalDeviceHeight();
+ static int getCellCountX() {
+ return mCellCountX;
}
- /**
- * Return the new local coordinates given the local coordinates from the previous orientation.
- */
- static LauncherModelOrientationHelper.Coordinates getLocalCoordinatesFromPreviousLocalCoordinates(CellLayout.LayoutParams lp) {
- return mModelOrientationHelper.getLocalCoordinatesFromPreviousLocalCoordinates(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan);
+ static int getCellCountY() {
+ return mCellCountY;
}
/**
@@ -343,7 +316,8 @@ public class LauncherModel extends BroadcastReceiver {
* when performing local/canonical coordinate transformations.
*/
static void updateWorkspaceLayoutCells(int shortAxisCellCount, int longAxisCellCount) {
- mModelOrientationHelper.updateDeviceDimensions(shortAxisCellCount, longAxisCellCount);
+ mCellCountX = shortAxisCellCount;
+ mCellCountY = longAxisCellCount;
}
/**
@@ -354,10 +328,7 @@ public class LauncherModel extends BroadcastReceiver {
final ContentResolver cr = context.getContentResolver();
item.onAddToDatabase(values);
-
- // update the values to be written with their canonical counterparts
- final LauncherModelOrientationHelper.Coordinates coord = mModelOrientationHelper.getCanonicalCoordinates(item);
- item.updateValuesWithCoordinates(values, coord.x, coord.y);
+ item.updateValuesWithCoordinates(values, item.cellX, item.cellY);
cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null);
}
@@ -393,11 +364,6 @@ public class LauncherModel extends BroadcastReceiver {
}
}
- public void updateOrientation() {
- // we update the LauncherModelOrientationHelper orientation whenever we re-initialize
- mModelOrientationHelper.updateOrientation(mApp);
- }
-
/**
* Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
* ACTION_PACKAGE_CHANGED.
@@ -712,7 +678,8 @@ public class LauncherModel extends BroadcastReceiver {
final Cursor c = contentResolver.query(
LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
- final ItemInfo occupied[][][] = new ItemInfo[Launcher.SCREEN_COUNT][Launcher.NUMBER_CELLS_X][Launcher.NUMBER_CELLS_Y];
+ final ItemInfo occupied[][][] =
+ new ItemInfo[Launcher.SCREEN_COUNT][mCellCountX][mCellCountY];
try {
final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
@@ -747,11 +714,6 @@ public class LauncherModel extends BroadcastReceiver {
final int displayModeIndex = c.getColumnIndexOrThrow(
LauncherSettings.Favorites.DISPLAY_MODE);
-
- LauncherModelOrientationHelper.Coordinates localCoords;
- int cellX;
- int cellY;
-
ShortcutInfo info;
String intentDescription;
LauncherAppWidgetInfo appWidgetInfo;
@@ -785,17 +747,13 @@ public class LauncherModel extends BroadcastReceiver {
if (info != null) {
updateSavedIcon(context, info, c, iconIndex);
- cellX = c.getInt(cellXIndex);
- cellY = c.getInt(cellYIndex);
- localCoords = mModelOrientationHelper.getLocalCoordinates(cellX, cellY, 1, 1);
-
info.intent = intent;
info.id = c.getLong(idIndex);
container = c.getInt(containerIndex);
info.container = container;
info.screen = c.getInt(screenIndex);
- info.cellX = localCoords.x;
- info.cellY = localCoords.y;
+ info.cellX = c.getInt(cellXIndex);
+ info.cellY = c.getInt(cellYIndex);
// check & update map of what's occupied
if (!checkItemPlacement(occupied, info)) {
@@ -829,17 +787,13 @@ public class LauncherModel extends BroadcastReceiver {
id = c.getLong(idIndex);
UserFolderInfo folderInfo = findOrMakeUserFolder(mFolders, id);
- cellX = c.getInt(cellXIndex);
- cellY = c.getInt(cellYIndex);
- localCoords = mModelOrientationHelper.getLocalCoordinates(cellX, cellY, 1, 1);
-
folderInfo.title = c.getString(titleIndex);
folderInfo.id = id;
container = c.getInt(containerIndex);
folderInfo.container = container;
folderInfo.screen = c.getInt(screenIndex);
- folderInfo.cellX = localCoords.x;
- folderInfo.cellY = localCoords.y;
+ folderInfo.cellX = c.getInt(cellXIndex);
+ folderInfo.cellY = c.getInt(cellYIndex);
// check & update map of what's occupied
if (!checkItemPlacement(occupied, folderInfo)) {
@@ -877,18 +831,14 @@ public class LauncherModel extends BroadcastReceiver {
}
}
- cellX = c.getInt(cellXIndex);
- cellY = c.getInt(cellYIndex);
- localCoords = mModelOrientationHelper.getLocalCoordinates(cellX, cellY, 1, 1);
-
liveFolderInfo.title = c.getString(titleIndex);
liveFolderInfo.id = id;
liveFolderInfo.uri = uri;
container = c.getInt(containerIndex);
liveFolderInfo.container = container;
liveFolderInfo.screen = c.getInt(screenIndex);
- liveFolderInfo.cellX = localCoords.x;
- liveFolderInfo.cellY = localCoords.y;
+ liveFolderInfo.cellX = c.getInt(cellXIndex);
+ liveFolderInfo.cellY = c.getInt(cellYIndex);
liveFolderInfo.baseIntent = intent;
liveFolderInfo.displayMode = c.getInt(displayModeIndex);
@@ -923,19 +873,13 @@ public class LauncherModel extends BroadcastReceiver {
+ id + " appWidgetId=" + appWidgetId);
itemsToRemove.add(id);
} else {
- cellX = c.getInt(cellXIndex);
- cellY = c.getInt(cellYIndex);
- int spanX = c.getInt(spanXIndex);
- int spanY = c.getInt(spanYIndex);
- localCoords = mModelOrientationHelper.getLocalCoordinates(cellX, cellY, spanX, spanY);
-
appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
appWidgetInfo.id = id;
appWidgetInfo.screen = c.getInt(screenIndex);
- appWidgetInfo.cellX = localCoords.x;
- appWidgetInfo.cellY = localCoords.y;
- appWidgetInfo.spanX = spanX;
- appWidgetInfo.spanY = spanY;
+ appWidgetInfo.cellX = c.getInt(cellXIndex);
+ appWidgetInfo.cellY = c.getInt(cellYIndex);
+ appWidgetInfo.spanX = c.getInt(spanXIndex);
+ appWidgetInfo.spanY = c.getInt(spanYIndex);
container = c.getInt(containerIndex);
if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
@@ -983,13 +927,13 @@ public class LauncherModel extends BroadcastReceiver {
if (DEBUG_LOADERS) {
Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms");
Log.d(TAG, "workspace layout: ");
- for (int y = 0; y < Launcher.NUMBER_CELLS_Y; y++) {
+ for (int y = 0; y < mCellCountY; y++) {
String line = "";
for (int s = 0; s < Launcher.SCREEN_COUNT; s++) {
if (s > 0) {
line += " | ";
}
- for (int x = 0; x < Launcher.NUMBER_CELLS_X; x++) {
+ for (int x = 0; x < mCellCountX; x++) {
line += ((occupied[s][x][y] != null) ? "#" : ".");
}
}
diff --git a/src/com/android/launcher2/LauncherModelOrientationHelper.java b/src/com/android/launcher2/LauncherModelOrientationHelper.java
deleted file mode 100644
index 6a9473d86..000000000
--- a/src/com/android/launcher2/LauncherModelOrientationHelper.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher2;
-
-import android.content.Context;
-import android.view.Display;
-import android.view.Surface;
-import android.view.WindowManager;
-
-public class LauncherModelOrientationHelper {
-
- static final String TAG = "LauncherModelOrientationHelper";
-
- public class Coordinates {
- public Coordinates(int newX, int newY) {
- x = newX;
- y = newY;
- }
-
- public int x;
- public int y;
- }
-
- private int mOrientation;
- private int mLocalDeviceWidth;
- private int mLocalDeviceHeight;
- private int mPreviousOrientation;
- private int mPreviousLocalDeviceWidth;
- private int mPreviousLocalDeviceHeight;
- private int mCanonicalDeviceWidth;
- private int mCanonicalDeviceHeight;
-
- protected LauncherModelOrientationHelper(Context ctx) {
- updateOrientation(ctx);
- }
-
- public int getCurrentOrientation() {
- return mOrientation;
- }
-
- public int getPreviousOrientationRelativeToCurrent() {
- int orientationDifference = -(mOrientation - mPreviousOrientation);
-
- if (Math.abs(orientationDifference) > 180) {
- orientationDifference = (int) -Math.signum(orientationDifference)
- * (360 - Math.abs(orientationDifference));
- }
- return orientationDifference;
- }
-
- private void updateLocalDeviceDimensions() {
- mPreviousLocalDeviceHeight = mLocalDeviceHeight;
- mPreviousLocalDeviceWidth = mLocalDeviceWidth;
-
- if (mOrientation % 180 != 0) {
- mLocalDeviceWidth = mCanonicalDeviceHeight;
- mLocalDeviceHeight = mCanonicalDeviceWidth;
- } else {
- mLocalDeviceWidth = mCanonicalDeviceWidth;
- mLocalDeviceHeight = mCanonicalDeviceHeight;
- }
- }
-
- public void updateOrientation(Context ctx) {
- Display display = ((WindowManager) ctx
- .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
-
- mPreviousOrientation = mOrientation;
- switch (display.getRotation()) {
- case Surface.ROTATION_0:
- mOrientation = 0;
- break;
- case Surface.ROTATION_90:
- mOrientation = 90;
- break;
- case Surface.ROTATION_180:
- mOrientation = 180;
- break;
- case Surface.ROTATION_270:
- mOrientation = 270;
- break;
- }
- updateLocalDeviceDimensions();
- }
-
- public void updateDeviceDimensions(int deviceWidth, int deviceHeight) {
- mCanonicalDeviceWidth = deviceWidth;
- mCanonicalDeviceHeight = deviceHeight;
-
- updateLocalDeviceDimensions();
- }
-
- public Coordinates getLocalCoordinatesFromPreviousLocalCoordinates(
- int cellX, int cellY, int spanX, int spanY) {
- return getTransformedLayoutParams(cellX, cellY, spanX, spanY,
- getPreviousOrientationRelativeToCurrent(),
- mPreviousLocalDeviceWidth, mPreviousLocalDeviceHeight);
- }
-
- public Coordinates getCanonicalCoordinates(ItemInfo localItem) {
- return getTransformedLayoutParams(localItem.cellX, localItem.cellY,
- localItem.spanX, localItem.spanY, mOrientation,
- mLocalDeviceWidth, mLocalDeviceHeight);
- }
-
- public Coordinates getCanonicalCoordinates(int cellX, int cellY,
- int spanX, int spanY) {
- return getTransformedLayoutParams(cellX, cellY, spanX, spanY,
- mOrientation, mLocalDeviceWidth, mLocalDeviceHeight);
- }
-
- public Coordinates getLocalCoordinates(int cellX, int cellY, int spanX,
- int spanY) {
- return getTransformedLayoutParams(cellX, cellY, spanX, spanY,
- -mOrientation, mCanonicalDeviceWidth, mCanonicalDeviceHeight);
- }
-
- public int getLocalDeviceWidth() {
- return mLocalDeviceWidth;
- }
-
- public int getLocalDeviceHeight() {
- return mLocalDeviceHeight;
- }
-
- /**
- * Transform the coordinates based on the current device rotation
- */
- private Coordinates getTransformedLayoutParams(int cellX, int cellY,
- int spanX, int spanY, int deviceRotationClockwise,
- int initialDeviceWidth, int initialDeviceHeight) {
- if (LauncherApplication.isScreenXLarge()) {
- int x = cellX;
- int y = cellY;
- int width = spanX;
- int height = spanY;
- int finalDeviceWidth = initialDeviceWidth;
- int finalDeviceHeight = initialDeviceHeight;
-
- // item rotation is opposite of device rotation to maintain an
- // absolute
- // spatial layout
- double phi = Math.toRadians(-deviceRotationClockwise);
-
- double x1 = x + width / 2.0f - initialDeviceWidth / 2.0f;
- double y1 = y + height / 2.0f - initialDeviceHeight / 2.0f;
-
- // multiply x and y by a clockwise rotation matrix
- double x2 = x1 * Math.cos(phi) + y1 * Math.sin(phi);
- double y2 = -x1 * Math.sin(phi) + y1 * Math.cos(phi);
-
- // Get the rotated device dimensions
- if (deviceRotationClockwise % 180 != 0) {
- finalDeviceWidth = initialDeviceHeight;
- finalDeviceHeight = initialDeviceWidth;
- }
-
- x2 = x2 + finalDeviceWidth / 2.0f - width / 2.0f;
- y2 = y2 + finalDeviceHeight / 2.0f - height / 2.0f;
-
- return new Coordinates((int) Math.round(x2), (int) Math.round(y2));
- } else {
- return new Coordinates(cellX, cellY);
- }
- }
-}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index cb37b9231..6d94eaa9c 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -136,6 +136,8 @@ public class Workspace extends ViewGroup
private int mMaximumVelocity;
private static final int INVALID_POINTER = -1;
+ private static final int DEFAULT_CELL_COUNT_X = 4;
+ private static final int DEFAULT_CELL_COUNT_Y = 4;
private int mActivePointerId = INVALID_POINTER;
@@ -208,13 +210,12 @@ public class Workspace extends ViewGroup
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.Workspace, defStyle, 0);
- int canonicalDeviceWidth = a.getInt(R.styleable.Workspace_canonicalDeviceWidth, 4);
- int canonicalDeviceHeight = a.getInt(R.styleable.Workspace_canonicalDeviceHeight, 4);
+ int cellCountX = a.getInt(R.styleable.Workspace_cellCountX, DEFAULT_CELL_COUNT_X);
+ int cellCountY = a.getInt(R.styleable.Workspace_cellCountY, DEFAULT_CELL_COUNT_Y);
mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);
a.recycle();
- LauncherModel.updateWorkspaceLayoutCells(canonicalDeviceWidth,
- canonicalDeviceHeight);
+ LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY);
setHapticFeedbackEnabled(false);
initWorkspace();
}
@@ -416,81 +417,6 @@ public class Workspace extends ViewGroup
addInScreen(child, screen, 0, 0, -1, -1);
}
- public void rotateCurrentScreensChildren() {
-
- // close all the folders first
- final ArrayList<Folder> openFolders = getOpenFolders();
-
- WorkspaceOvershootInterpolator wi = new WorkspaceOvershootInterpolator();
- RotateAnimation ra = new RotateAnimation((float) LauncherModel
- .getPreviousOrientationRelativeToCurrent(), 0,
- Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
- 0.5f);
- ra.setInterpolator(wi);
- CellLayout currentScreen = (CellLayout) getChildAt(mCurrentScreen);
- ra.setStartOffset(150);
- ra.setDuration(650 + (int) (Math.random() * 400) - 200);
-
- CellLayout.CellLayoutAnimationController animationController = new CellLayout.CellLayoutAnimationController(
- ra, 0.0f);
- currentScreen.setLayoutAnimation(animationController);
- currentScreen.setLayoutAnimationListener(new AnimationListener() {
- public void onAnimationStart(Animation animation) {
- // do nothing
- }
-
- public void onAnimationRepeat(Animation animation) {
- // do nothing
- }
-
- public void onAnimationEnd(Animation animation) {
- for (int j = 0; j < openFolders.size(); ++j) {
- Folder folder = openFolders.get(j);
- if (!folder.getInfo().opened) {
- mLauncher.openFolder(folder.getInfo());
- }
- }
- }
- });
- animationController.start();
-
- for (int j = 0; j < openFolders.size(); ++j) {
- mLauncher.closeFolder(openFolders.get(j));
- }
- }
-
- public void refreshWorkspaceChildren() {
- final int screenCount = getChildCount();
- View child;
-
- CellLayout.LayoutParams lp;
- int widthMeasureSpec = MeasureSpec.makeMeasureSpec(LauncherModel
- .getLocalDeviceWidth(), MeasureSpec.EXACTLY);
- int heightMeasureSpec = MeasureSpec.makeMeasureSpec(LauncherModel
- .getLocalDeviceHeight(), MeasureSpec.EXACTLY);
-
- clearVacantCache();
-
- for (int i = 0; i < screenCount; i++) {
- final CellLayout layout = (CellLayout) getChildAt(i);
- final int count = layout.getChildCount();
-
- // save reference to all current children
- for (int j = 0; j < count; j++) {
- child = layout.getChildAt(j);
-
- lp = (CellLayout.LayoutParams) child.getLayoutParams();
- LauncherModelOrientationHelper.Coordinates localCoord = LauncherModel
- .getLocalCoordinatesFromPreviousLocalCoordinates(lp);
-
- lp.cellX = localCoord.x;
- lp.cellY = localCoord.y;
- }
-
- layout.measure(widthMeasureSpec, heightMeasureSpec);
- }
- }
-
/**
* Adds the specified child in the specified screen. The position and dimension of
* the child are defined by x, y, spanX and spanY.
@@ -524,7 +450,7 @@ public class Workspace extends ViewGroup
}
// Get the canonical child id to uniquely represent this view in this screen
- int childId = LauncherModel.getCanonicalCellLayoutChildId(child.getId(), screen, x, y, spanX, spanY);
+ int childId = LauncherModel.getCellLayoutChildId(child.getId(), screen, x, y, spanX, spanY);
if (!group.addViewToCellLayout(child, insert ? 0 : -1, childId, lp)) {
// TODO: This branch occurs when the workspace is adding views
// outside of the defined grid