diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-04-13 21:57:41 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-04-17 01:47:56 +0200 |
commit | 25350504863f87d88d3e86c58714275c963b8469 (patch) | |
tree | 89d5148cad8926b619670844bd6e919e6c761fad /src | |
parent | da04260b2994b38ebe58d794dae300470c14621f (diff) | |
download | packages_apps_trebuchet-25350504863f87d88d3e86c58714275c963b8469.zip packages_apps_trebuchet-25350504863f87d88d3e86c58714275c963b8469.tar.gz packages_apps_trebuchet-25350504863f87d88d3e86c58714275c963b8469.tar.bz2 |
Trebuchet: Hotseat fixes
This change fixes some of the bugs of HotSeat on landscape mode:
* Fixed distance algorithm for XY spatial (not only for X axis)
* Fixed cellX and cellY database handling when items are added in landscape mode
* Fixed cellX and cellY transtions when add new items
* Restore the current hotseat page on rotation
Patchset 2: Fixed create new folder in vertical hotseat
Patchset 3: Fixed broken mTransposeLayoutWithOrientation != true (large screen devices)
Fixed delete existing folder in vertical hotseat
Patchset 4: Fixed destroy animation when a folder is destroyed in vertical hotseat
Rebased
Change-Id: I8b0faa5b6fde42d80e0d98226fca07eead04223c
JIRA: CYAN-315
Issue: https://jira.cyanogenmod.org/browse/CYAN-315
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Folder.java | 20 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Hotseat.java | 20 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Launcher.java | 21 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherModel.java | 81 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Workspace.java | 53 |
5 files changed, 144 insertions, 51 deletions
diff --git a/src/com/cyanogenmod/trebuchet/Folder.java b/src/com/cyanogenmod/trebuchet/Folder.java index 181341b..cdb4dd3 100644 --- a/src/com/cyanogenmod/trebuchet/Folder.java +++ b/src/com/cyanogenmod/trebuchet/Folder.java @@ -953,16 +953,28 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList Runnable onCompleteRunnable = new Runnable() { @Override public void run() { - CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen); + final int screen = mInfo.screen; + if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + mInfo.screen = mLauncher.getHotseat().getScreenFromOrder(mInfo.screen); + } + + final CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen); - View child = null; + View child = null; // Move the item from the folder to the workspace, in the position of the folder if (getItemCount() == 1) { ShortcutInfo finalItem = mInfo.contents.get(0); child = mLauncher.createShortcut(R.layout.application, cellLayout, finalItem); + int x = mInfo.cellX, y = mInfo.cellY; + if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && + mLauncher.getHotseat().hasVerticalHotseat()) { + // Note: We need the correct position in order to save to db + y = mLauncher.getHotseat().getCellYFromOrder(x); + x = mLauncher.getHotseat().getCellXFromOrder(x); + } LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container, - mInfo.screen, mInfo.cellX, mInfo.cellY); + screen, x, y); } if (getItemCount() <= 1) { // Remove the folder @@ -976,7 +988,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList // We add the child after removing the folder to prevent both from existing at // the same time in the CellLayout. if (child != null) { - mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screen, + mLauncher.getWorkspace().addInScreen(child, mInfo.container, screen, mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); } } diff --git a/src/com/cyanogenmod/trebuchet/Hotseat.java b/src/com/cyanogenmod/trebuchet/Hotseat.java index f2e6d96..9795c71 100644 --- a/src/com/cyanogenmod/trebuchet/Hotseat.java +++ b/src/com/cyanogenmod/trebuchet/Hotseat.java @@ -103,7 +103,7 @@ public class Hotseat extends PagedView { return false; } - private boolean hasVerticalHotseat() { + boolean hasVerticalHotseat() { return (mIsLandscape && mTransposeLayoutWithOrientation); } @@ -118,9 +118,24 @@ public class Hotseat extends PagedView { int getCellYFromOrder(int rank) { return hasVerticalHotseat() ? (mCellCount - rank - 1) : 0; } + int getInverterCellXFromOrder(int rank) { + return hasVerticalHotseat() ? (mCellCount - rank - 1) : 0; + } + int getInverterCellYFromOrder(int rank) { + return hasVerticalHotseat() ? 0 : rank; + } int getScreenFromOrder(int screen) { return hasVerticalHotseat() ? (getChildCount() - screen - 1) : screen; } + int[] getDatabaseCellsFromLayout(int[] lpCells) { + if (!hasVerticalHotseat()) { + return lpCells; + } + // On landscape with vertical hotseat, the items are stored in y axis and from up to down, + // so we need to convert to x axis and left to right prior to save to database. In screen + // the item has the right coordinates + return new int[]{mCellCount - lpCells[1] - 1, lpCells[0]}; + } /* * @@ -200,7 +215,8 @@ public class Hotseat extends PagedView { // Calculate the distance between the center of the CellLayout // and the touch point - float dist = Workspace.squaredDistance(touchXy, cellLayoutCenter); + float dist = Workspace.squaredDistance( + touchXy, cellLayoutCenter, hasVerticalHotseat()); if (dist < smallestDistSoFar) { smallestDistSoFar = dist; diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index b8a3224..db4888e 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -168,6 +168,8 @@ public final class Launcher extends Activity // Type: int private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; // Type: int + private static final String RUNTIME_STATE_CURRENT_HOTSEAT_SCREEN = "launcher.hotseat.current_screen"; + // Type: int private static final String RUNTIME_STATE = "launcher.state"; // Type: int private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; @@ -890,6 +892,10 @@ public final class Launcher extends Activity if (currentScreen > -1) { mWorkspace.setCurrentPage(currentScreen); } + int currentHotseatScreen = savedState.getInt(RUNTIME_STATE_CURRENT_HOTSEAT_SCREEN, -1); + if (currentHotseatScreen > -1) { + mHotseat.setCurrentPage(mHotseat.getScreenFromOrder(currentHotseatScreen)); + } final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); @@ -1588,6 +1594,7 @@ public final class Launcher extends Activity @Override protected void onSaveInstanceState(Bundle outState) { outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage()); + outState.putInt(RUNTIME_STATE_CURRENT_HOTSEAT_SCREEN, mHotseat.getScreenFromOrder(mHotseat.getCurrentPage())); super.onSaveInstanceState(outState); outState.putInt(RUNTIME_STATE, mState.ordinal()); @@ -1984,8 +1991,18 @@ public final class Launcher extends Activity if (mHideIconLabels) { newFolder.setTextVisible(false); } - mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1, - isWorkspaceLocked()); + int x = cellX, y = cellY; + if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && + getHotseat().hasVerticalHotseat()) { + // Note: If the destination of the new folder is the hotseat and + // the hotseat is in vertical mode, then we need to invert the xy position, + // so the addInScreen method will use the correct values to draw the new folder + // in the correct position + // We use the y in both case to determine the new position + x = getHotseat().getInverterCellXFromOrder(y); + y = getHotseat().getInverterCellYFromOrder(y); + } + mWorkspace.addInScreen(newFolder, container, screen, x, y, 1, 1, isWorkspaceLocked()); return newFolder; } diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java index 501058e..a3d198c 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherModel.java +++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java @@ -368,16 +368,29 @@ public class LauncherModel extends BroadcastReceiver { */ static void moveItemInDatabase(Context context, final ItemInfo item, final long container, final int screen, final int cellX, final int cellY) { + + // We store hotseat items in canonical form which is this orientation invariant position + // in the hotseat + int screenEx = screen; + if (context instanceof Launcher && screen < 0 && + container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + screenEx = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); + } + int[] cells = {cellX, cellY}; + if (context instanceof Launcher && + container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + cells = ((Launcher)context).getHotseat(). + getDatabaseCellsFromLayout(new int[]{cellX, cellY}); + } + String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id + " (" + item.container + ", " + item.screen + ", " + item.cellX + ", " + item.cellY + - ") --> " + "(" + container + ", " + screen + ", " + cellX + ", " + cellY + ")"; + ") --> " + "(" + container + ", " + screenEx + ", " + cells[0] + ", " + cells[1] + ")"; Launcher.sDumpLogs.add(transaction); - Log.d(TAG, transaction); item.container = container; - item.cellX = cellX; - item.cellY = cellY; - - item.screen = screen; + item.cellX = cells[0]; + item.cellY = cells[1]; + item.screen = screenEx; final ContentValues values = new ContentValues(); values.put(LauncherSettings.Favorites.CONTAINER, item.container); @@ -393,25 +406,31 @@ public class LauncherModel extends BroadcastReceiver { */ static void modifyItemInDatabase(Context context, final ItemInfo item, final long container, final int screen, final int cellX, final int cellY, final int spanX, final int spanY) { - String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id + - " (" + item.container + ", " + item.screen + ", " + item.cellX + ", " + item.cellY + - ") --> " + "(" + container + ", " + screen + ", " + cellX + ", " + cellY + ")"; - Launcher.sDumpLogs.add(transaction); - Log.d(TAG, transaction); - item.cellX = cellX; - item.cellY = cellY; - item.spanX = spanX; - item.spanY = spanY; // We store hotseat items in canonical form which is this orientation invariant position // in the hotseat + int screenEx = screen; if (context instanceof Launcher && screen < 0 && container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); - } else { - item.screen = screen; + screenEx = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); + } + int[] cells = {cellX, cellY}; + if (context instanceof Launcher && + container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + cells = ((Launcher)context).getHotseat(). + getDatabaseCellsFromLayout(new int[]{cellX, cellY}); } + String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id + + " (" + item.container + ", " + item.screen + ", " + item.cellX + ", " + item.cellY + + ") --> " + "(" + container + ", " + screenEx + ", " + cells[0] + ", " + cells[1] + ")"; + Launcher.sDumpLogs.add(transaction); + item.cellX = cells[0]; + item.cellY = cells[1]; + item.spanX = spanX; + item.spanY = spanY; + item.screen = screenEx; + final ContentValues values = new ContentValues(); values.put(LauncherSettings.Favorites.CONTAINER, item.container); values.put(LauncherSettings.Favorites.CELLX, item.cellX); @@ -543,11 +562,25 @@ public class LauncherModel extends BroadcastReceiver { */ static void addItemToDatabase(Context context, final ItemInfo item, final long container, final int screen, final int cellX, final int cellY, final boolean notify) { - item.container = container; - item.cellX = cellX; - item.cellY = cellY; - item.screen = screen; + // We store hotseat items in canonical form which is this orientation invariant position + // in the hotseat + int screenEx = screen; + if (context instanceof Launcher && screen < 0 && + container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + screenEx = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); + } + int[] cells = {cellX, cellY}; + if (context instanceof Launcher && + container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + cells = ((Launcher)context).getHotseat(). + getDatabaseCellsFromLayout(new int[]{cellX, cellY}); + } + + item.container = container; + item.cellX = cells[0]; + item.cellY = cells[1]; + item.screen = screenEx; final ContentValues values = new ContentValues(); final ContentResolver cr = context.getContentResolver(); @@ -561,8 +594,8 @@ public class LauncherModel extends BroadcastReceiver { Runnable r = new Runnable() { public void run() { String transaction = "DbDebug Add item (" + item.title + ") to db, id: " - + item.id + " (" + container + ", " + screen + ", " + cellX + ", " - + cellY + ")"; + + item.id + " (" + container + ", " + item.screen + ", " + item.cellX + ", " + + item.cellY + ")"; Launcher.sDumpLogs.add(transaction); Log.d(TAG, transaction); diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java index 7e330eb..c6da8a9 100644 --- a/src/com/cyanogenmod/trebuchet/Workspace.java +++ b/src/com/cyanogenmod/trebuchet/Workspace.java @@ -2794,10 +2794,12 @@ public class Workspace extends PagedView if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false; mCreateUserFolderOnDrop = false; - final int screen = (targetCell == null) ? mDragInfo.screen : - (mLauncher.isHotseatLayout(target) ? - mLauncher.getHotseat().indexOfChild(target) : - indexOfChild(target)); + final int screen = + (targetCell == null) ? + mDragInfo.screen : + (mLauncher.isHotseatLayout(target) ? + mLauncher.getHotseat().getScreenFromOrder(mLauncher.getHotseat().indexOfChild(target)) : + indexOfChild(target)); boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo); boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo); @@ -2890,10 +2892,12 @@ public class Workspace extends PagedView long container = hasMovedIntoHotseat ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP; - int screen = (mTargetCell[0] < 0) ? - mDragInfo.screen : (hasMovedIntoHotseat ? - mLauncher.getHotseat().indexOfChild(dropTargetLayout) : - indexOfChild(dropTargetLayout)); + int screen = + (mTargetCell[0] < 0) ? + mDragInfo.screen : + (hasMovedIntoHotseat ? + mLauncher.getHotseat().getScreenFromOrder(mLauncher.getHotseat().indexOfChild(dropTargetLayout)) : + indexOfChild(dropTargetLayout)); int spanX = mDragInfo != null ? mDragInfo.spanX : 1; int spanY = mDragInfo != null ? mDragInfo.spanY : 1; // First we find the cell nearest to point at which the item is @@ -2947,7 +2951,8 @@ public class Workspace extends PagedView if (mCurrentPage != screen && !hasMovedIntoHotseat) { snapScreen = screen; snapToPage(screen); - } else if (mLauncher.getHotseat().getCurrentPage() != screen && hasMovedIntoHotseat) { + } else if (hasMovedIntoHotseat && + mLauncher.getHotseat().getScreenFromOrder(mLauncher.getHotseat().getCurrentPage()) != screen) { mLauncher.getHotseat().snapToPage(screen); } @@ -3295,10 +3300,17 @@ public class Workspace extends PagedView xy[1] -= (getScrollY() - v.getTop()); } - static float squaredDistance(float[] point1, float[] point2) { - float distanceX = point1[0] - point2[0]; - float distanceY = point2[1] - point2[1]; - return distanceX * distanceX + distanceY * distanceY; + static float squaredDistance(float[] point1, float[] point2, boolean spatial) { + // Horizontal + if (!spatial) { + float distanceX = point1[0] - point2[0]; + float distanceY = point2[1] - point2[1]; + return distanceX * distanceX + distanceY * distanceY; + } + // Spatial xy + double distanceX = Math.pow(point2[0] - point2[1], 2); + double distanceY = Math.pow(point2[1] - point2[0], 2); + return (float)Math.sqrt(distanceX + distanceY); } /** @@ -3341,7 +3353,7 @@ public class Workspace extends PagedView // Calculate the distance between the center of the CellLayout // and the touch point - float dist = squaredDistance(touchXy, cellLayoutCenter); + float dist = squaredDistance(touchXy, cellLayoutCenter, false); if (dist < smallestDistSoFar) { smallestDistSoFar = dist; @@ -3666,13 +3678,15 @@ public class Workspace extends PagedView final long container = mLauncher.isHotseatLayout(cellLayout) ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP; - final int screen = mLauncher.isHotseatLayout(cellLayout) ? - mLauncher.getHotseat().indexOfChild(cellLayout) : + final int screen = + mLauncher.isHotseatLayout(cellLayout) ? + mLauncher.getHotseat().getScreenFromOrder(mLauncher.getHotseat().indexOfChild(cellLayout)) : indexOfChild(cellLayout); if (mState != State.SPRING_LOADED) { if (!mLauncher.isHotseatLayout(cellLayout) && screen != mCurrentPage) { snapToPage(screen); - } else if (mLauncher.isHotseatLayout(cellLayout) && screen != mLauncher.getHotseat().getCurrentPage()) { + } else if (mLauncher.isHotseatLayout(cellLayout) && screen != + mLauncher.getHotseat().getScreenFromOrder(mLauncher.getHotseat().getCurrentPage())) { mLauncher.getHotseat().snapToPage(screen); } } @@ -3810,9 +3824,10 @@ public class Workspace extends PagedView info.spanY, insertAtFirst); cellLayout.onDropChild(view); CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams(); + lp.cellX = mTargetCell[0]; + lp.cellY = mTargetCell[1]; cellLayout.getShortcutsAndWidgets().measureChild(view); - LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screen, lp.cellX, lp.cellY); @@ -4045,7 +4060,7 @@ public class Workspace extends PagedView int container = Favorites.CONTAINER_DESKTOP; if (mLauncher.isHotseatLayout(cl)) { - screen = mLauncher.getHotseat().indexOfChild(cl); + screen = mLauncher.getHotseat().getScreenFromOrder(mLauncher.getHotseat().indexOfChild(cl)); container = Favorites.CONTAINER_HOTSEAT; } |