summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornebkat <nebkat@teamhacksung.org>2012-12-25 19:42:51 +0000
committernebkat <nebkat@teamhacksung.org>2012-12-26 13:38:17 +0000
commit2fc141a085b6fbabce43b5245d85999bcc3b93ab (patch)
tree1ee4faa4c1c575d7ff1e00d254d98dcd2958a383 /src
parent10a574501d4f4426ab5cec0a613b60d1d0baed44 (diff)
downloadandroid_packages_apps_Trebuchet-2fc141a085b6fbabce43b5245d85999bcc3b93ab.tar.gz
android_packages_apps_Trebuchet-2fc141a085b6fbabce43b5245d85999bcc3b93ab.tar.bz2
android_packages_apps_Trebuchet-2fc141a085b6fbabce43b5245d85999bcc3b93ab.zip
Workspace: Hotseat fixes
Change-Id: Ieceed18c47bc3b6d6194506f0d7545c4513befa0
Diffstat (limited to 'src')
-rw-r--r--src/com/cyanogenmod/trebuchet/DragController.java2
-rw-r--r--src/com/cyanogenmod/trebuchet/DragLayer.java11
-rw-r--r--src/com/cyanogenmod/trebuchet/Hotseat.java115
-rw-r--r--src/com/cyanogenmod/trebuchet/Launcher.java2
-rw-r--r--src/com/cyanogenmod/trebuchet/SpringLoadedDragController.java10
-rw-r--r--src/com/cyanogenmod/trebuchet/Workspace.java60
6 files changed, 162 insertions, 38 deletions
diff --git a/src/com/cyanogenmod/trebuchet/DragController.java b/src/com/cyanogenmod/trebuchet/DragController.java
index 071948cdb..7e0dcdb88 100644
--- a/src/com/cyanogenmod/trebuchet/DragController.java
+++ b/src/com/cyanogenmod/trebuchet/DragController.java
@@ -324,7 +324,7 @@ public class DragController {
}
endDrag();
}
- public void onAppsRemoved(ArrayList<String> packageNames, Context context) {
+ public void onAppsRemoved(ArrayList<String> packageNames) {
// Cancel the current drag if we are removing an app that we are dragging
if (mDragObject != null) {
Object rawDragInfo = mDragObject.dragInfo;
diff --git a/src/com/cyanogenmod/trebuchet/DragLayer.java b/src/com/cyanogenmod/trebuchet/DragLayer.java
index 420dfd550..e26a2915a 100644
--- a/src/com/cyanogenmod/trebuchet/DragLayer.java
+++ b/src/com/cyanogenmod/trebuchet/DragLayer.java
@@ -27,6 +27,7 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
@@ -42,6 +43,7 @@ import android.widget.TextView;
import com.cyanogenmod.trebuchet.R;
import java.util.ArrayList;
+import java.util.Arrays;
/**
* A ViewGroup that coordinates dragging across its descendants
@@ -303,8 +305,8 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
pt[1] += view.getTop() - view.getScrollY();
viewParent = view.getParent();
}
- coord[0] = (int) Math.round(pt[0]);
- coord[1] = (int) Math.round(pt[1]);
+ coord[0] = Math.round(pt[0]);
+ coord[1] = Math.round(pt[1]);
return scale;
}
@@ -743,10 +745,11 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
if (mInScrollArea && !LauncherApplication.isScreenLarge()) {
Workspace workspace = mLauncher.getWorkspace();
int width = workspace.getWidth();
+ int page = workspace.getNextPage();
+
Rect childRect = new Rect();
- getDescendantRectRelativeToSelf(workspace.getChildAt(0), childRect);
+ getDescendantRectRelativeToSelf(workspace.getChildAt(page), childRect);
- int page = workspace.getNextPage();
CellLayout leftPage = (CellLayout) workspace.getChildAt(page - 1);
CellLayout rightPage = (CellLayout) workspace.getChildAt(page + 1);
diff --git a/src/com/cyanogenmod/trebuchet/Hotseat.java b/src/com/cyanogenmod/trebuchet/Hotseat.java
index d52cb0ca5..80656b60b 100644
--- a/src/com/cyanogenmod/trebuchet/Hotseat.java
+++ b/src/com/cyanogenmod/trebuchet/Hotseat.java
@@ -19,18 +19,25 @@ package com.cyanogenmod.trebuchet;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
+import android.graphics.Matrix;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import com.cyanogenmod.trebuchet.preference.PreferencesProvider;
+import java.util.Arrays;
+
public class Hotseat extends PagedView {
private int mCellCount;
private boolean mTransposeLayoutWithOrientation;
private boolean mIsLandscape;
+ private float[] mTempCellLayoutCenterCoordinates = new float[2];
+ private Matrix mTempInverseMatrix = new Matrix();
+
private static final int DEFAULT_CELL_COUNT = 5;
public Hotseat(Context context) {
@@ -82,10 +89,6 @@ public class Hotseat extends PagedView {
setOnKeyListener(new HotseatIconKeyEventListener());
}
- CellLayout getLayout() {
- return (CellLayout) getPageAt(mCurrentPage);
- }
-
public boolean hasPage(View view) {
for (int i = 0; i < getChildCount(); i++) {
if (view == getChildAt(i)) {
@@ -114,6 +117,110 @@ public class Hotseat extends PagedView {
return hasVerticalHotseat() ? (getChildCount() - screen - 1) : screen;
}
+ /*
+ *
+ * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's
+ * coordinate space. The argument xy is modified with the return result.
+ *
+ * if cachedInverseMatrix is not null, this method will just use that matrix instead of
+ * computing it itself; we use this to avoid redundant matrix inversions in
+ * findMatchingPageForDragOver
+ *
+ */
+ void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) {
+ if (cachedInverseMatrix == null) {
+ v.getMatrix().invert(mTempInverseMatrix);
+ cachedInverseMatrix = mTempInverseMatrix;
+ }
+ int scrollX = getScrollX();
+ if (mNextPage != INVALID_PAGE) {
+ scrollX = mScroller.getFinalX();
+ }
+ xy[0] = xy[0] + scrollX - v.getLeft();
+ xy[1] = xy[1] + getScrollY() - v.getTop();
+ cachedInverseMatrix.mapPoints(xy);
+ }
+
+ /**
+ * Convert the 2D coordinate xy from this CellLayout's coordinate space to
+ * the parent View's coordinate space. The argument xy is modified with the return result.
+ */
+ void mapPointFromChildToSelf(View v, float[] xy) {
+ v.getMatrix().mapPoints(xy);
+ int scrollX = getScrollX();
+ if (mNextPage != INVALID_PAGE) {
+ scrollX = mScroller.getFinalX();
+ }
+ xy[0] -= (scrollX - v.getLeft());
+ xy[1] -= (getScrollY() - v.getTop());
+ }
+
+ /**
+ * This method returns the CellLayout that is currently being dragged to. In order to drag
+ * to a CellLayout, either the touch point must be directly over the CellLayout, or as a second
+ * strategy, we see if the dragView is overlapping any CellLayout and choose the closest one
+ *
+ * Return null if no CellLayout is currently being dragged over
+ */
+ CellLayout findMatchingPageForDragOver(float originX, float originY, boolean exact) {
+ // We loop through all the screens (ie CellLayouts) and see which ones overlap
+ // with the item being dragged and then choose the one that's closest to the touch point
+ final int screenCount = getChildCount();
+ CellLayout bestMatchingScreen = null;
+ float smallestDistSoFar = Float.MAX_VALUE;
+
+ for (int i = 0; i < screenCount; i++) {
+ CellLayout cl = (CellLayout) getChildAt(i);
+
+ final float[] touchXy = {originX, originY};
+ // Transform the touch coordinates to the CellLayout's local coordinates
+ // If the touch point is within the bounds of the cell layout, we can return immediately
+ cl.getMatrix().invert(mTempInverseMatrix);
+ mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix);
+
+ if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() &&
+ touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) {
+ return cl;
+ }
+
+ if (!exact) {
+ // Get the center of the cell layout in screen coordinates
+ final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates;
+ cellLayoutCenter[0] = cl.getWidth()/2;
+ cellLayoutCenter[1] = cl.getHeight()/2;
+ mapPointFromChildToSelf(cl, cellLayoutCenter);
+
+ touchXy[0] = originX;
+ touchXy[1] = originY;
+
+ // Calculate the distance between the center of the CellLayout
+ // and the touch point
+ float dist = Workspace.squaredDistance(touchXy, cellLayoutCenter);
+
+ if (dist < smallestDistSoFar) {
+ smallestDistSoFar = dist;
+ bestMatchingScreen = cl;
+ }
+ }
+ }
+ return bestMatchingScreen;
+ }
+
+ public void setChildrenOutlineAlpha(float alpha) {
+ for (int i = 0; i < getChildCount(); i++) {
+ CellLayout cl = (CellLayout) getChildAt(i);
+ cl.setBackgroundAlpha(alpha);
+ }
+ }
+
+ /**
+ * Return the current {@link CellLayout}, correctly picking the destination
+ * screen while a scroll is in progress.
+ */
+ public CellLayout getCurrentDropLayout() {
+ return (CellLayout) getChildAt(getNextPage());
+ }
+
@Override
protected void onFinishInflate() {
super.onFinishInflate();
diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java
index 53187667d..8dceb3bbe 100644
--- a/src/com/cyanogenmod/trebuchet/Launcher.java
+++ b/src/com/cyanogenmod/trebuchet/Launcher.java
@@ -3997,7 +3997,7 @@ public final class Launcher extends Activity
}
// Notify the drag controller
- mDragController.onAppsRemoved(packageNames, this);
+ mDragController.onAppsRemoved(packageNames);
}
/**
diff --git a/src/com/cyanogenmod/trebuchet/SpringLoadedDragController.java b/src/com/cyanogenmod/trebuchet/SpringLoadedDragController.java
index e5b27981a..a48a1f473 100644
--- a/src/com/cyanogenmod/trebuchet/SpringLoadedDragController.java
+++ b/src/com/cyanogenmod/trebuchet/SpringLoadedDragController.java
@@ -16,6 +16,8 @@
package com.cyanogenmod.trebuchet;
+import android.util.Log;
+
public class SpringLoadedDragController implements OnAlarmListener {
// how long the user must hover over a mini-screen before it unshrinks
final long ENTER_SPRING_LOAD_HOVER_TIME = 500;
@@ -50,10 +52,10 @@ public class SpringLoadedDragController implements OnAlarmListener {
public void onAlarm(Alarm alarm) {
if (mScreen != null) {
// Snap to the screen that we are hovering over now
- Workspace w = mLauncher.getWorkspace();
- int page = w.indexOfChild(mScreen);
- if (page != w.getCurrentPage()) {
- w.snapToPage(page);
+ PagedView pagedView = (PagedView) mScreen.getParent();
+ int page = pagedView.indexOfChild(mScreen);
+ if (page != pagedView.getCurrentPage()) {
+ pagedView.snapToPage(page);
}
} else {
mLauncher.getDragController().cancelDrag();
diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java
index 81854d839..077cd5278 100644
--- a/src/com/cyanogenmod/trebuchet/Workspace.java
+++ b/src/com/cyanogenmod/trebuchet/Workspace.java
@@ -55,6 +55,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewParent;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
@@ -477,6 +478,7 @@ public class Workspace extends PagedView
updateChildrenLayersEnabled(false);
mLauncher.lockScreenOrientation();
setChildrenBackgroundAlphaMultipliers(1f);
+ mLauncher.getHotseat().setChildrenOutlineAlpha(1f);
// Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
InstallShortcutReceiver.enableInstallQueue();
UninstallShortcutReceiver.enableUninstallQueue();
@@ -486,6 +488,7 @@ public class Workspace extends PagedView
mIsDragOccuring = false;
updateChildrenLayersEnabled(false);
mLauncher.unlockScreenOrientation(false);
+ mLauncher.getHotseat().setChildrenOutlineAlpha(0f);
// Re-enable any Un/InstallShortcutReceiver and now process any queued items
InstallShortcutReceiver.disableAndFlushInstallQueue(getContext());
@@ -2784,7 +2787,7 @@ public class Workspace extends PagedView
// We want the point to be mapped to the dragTarget.
if (dropTargetLayout != null) {
if (mLauncher.isHotseatLayout(dropTargetLayout)) {
- mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
+ mLauncher.getHotseat().mapPointFromChildToSelf(dropTargetLayout, mDragViewVisualCenter);
} else {
mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null);
}
@@ -2864,6 +2867,8 @@ public class Workspace extends PagedView
if (mCurrentPage != screen && !hasMovedIntoHotseat) {
snapScreen = screen;
snapToPage(screen);
+ } else if (mLauncher.getHotseat().getCurrentPage() != screen && hasMovedIntoHotseat) {
+ mLauncher.getHotseat().snapToPage(screen);
}
if (foundCell) {
@@ -3043,10 +3048,12 @@ public class Workspace extends PagedView
// Here we store the final page that will be dropped to, if the workspace in fact
// receives the drop
if (mInScrollArea) {
- if (isPageMoving()) {
+ PagedView target = mDragInfo != null && mDragInfo.container == Favorites.CONTAINER_HOTSEAT ?
+ mLauncher.getHotseat() : this;
+ if (target.isPageMoving()) {
// If the user drops while the page is scrolling, we should use that page as the
// destination instead of the page that is being hovered over.
- mDropToLayout = (CellLayout) getPageAt(getNextPage());
+ mDropToLayout = (CellLayout) target.getPageAt(target.getNextPage());
} else {
mDropToLayout = mDragOverlappingLayout;
}
@@ -3086,6 +3093,10 @@ public class Workspace extends PagedView
setCurrentDropOverCell(-1, -1);
}
+ PagedView getCurrentDropTarget() {
+ return mLauncher.isHotseatLayout(mDragTargetLayout) ? mLauncher.getHotseat() : this;
+ }
+
void setCurrentDragOverlappingLayout(CellLayout layout) {
if (mDragOverlappingLayout != null) {
mDragOverlappingLayout.setIsDragOverlapping(false);
@@ -3190,9 +3201,9 @@ public class Workspace extends PagedView
void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) {
- hotseat.getLayout().getMatrix().invert(mTempInverseMatrix);
- xy[0] = xy[0] - hotseat.getLeft() - hotseat.getLayout().getLeft();
- xy[1] = xy[1] - hotseat.getTop() - hotseat.getLayout().getTop();
+ hotseat.getPageAt(hotseat.getNextPage()).getMatrix().invert(mTempInverseMatrix);
+ xy[0] = xy[0] - hotseat.getLeft() - hotseat.getPageAt(hotseat.getNextPage()).getLeft();
+ xy[1] = xy[1] - hotseat.getTop() - hotseat.getPageAt(hotseat.getNextPage()).getTop();
mTempInverseMatrix.mapPoints(xy);
}
@@ -3212,20 +3223,18 @@ public class Workspace extends PagedView
xy[1] -= (getScrollY() - v.getTop());
}
- static private float squaredDistance(float[] point1, float[] point2) {
+ static float squaredDistance(float[] point1, float[] point2) {
float distanceX = point1[0] - point2[0];
float distanceY = point2[1] - point2[1];
return distanceX * distanceX + distanceY * distanceY;
}
- /*
- *
+ /**
* This method returns the CellLayout that is currently being dragged to. In order to drag
* to a CellLayout, either the touch point must be directly over the CellLayout, or as a second
* strategy, we see if the dragView is overlapping any CellLayout and choose the closest one
*
* Return null if no CellLayout is currently being dragged over
- *
*/
private CellLayout findMatchingPageForDragOver(float originX, float originY, boolean exact) {
// We loop through all the screens (ie CellLayouts) and see which ones overlap
@@ -3330,7 +3339,7 @@ public class Workspace extends PagedView
if (mLauncher.getHotseat() != null && !isExternalDragWidget(d)) {
mLauncher.getHotseat().getHitRect(r);
if (r.contains(d.x, d.y)) {
- layout = mLauncher.getHotseat().getLayout();
+ layout = mLauncher.getHotseat().findMatchingPageForDragOver(d.x, d.y, false);
}
}
if (layout == null) {
@@ -3342,12 +3351,8 @@ public class Workspace extends PagedView
setCurrentDragOverlappingLayout(layout);
boolean isInSpringLoadedMode = (mState == State.SPRING_LOADED);
- if (isInSpringLoadedMode) {
- if (mLauncher.isHotseatLayout(layout)) {
- mSpringLoadedDragController.cancel();
- } else {
- mSpringLoadedDragController.setAlarm(mDragTargetLayout);
- }
+ if (isInSpringLoadedMode || mLauncher.isHotseatLayout(mDragTargetLayout)) {
+ mSpringLoadedDragController.setAlarm(mDragTargetLayout);
}
}
} else {
@@ -3355,7 +3360,7 @@ public class Workspace extends PagedView
if (mLauncher.getHotseat() != null && !isDragWidget(d)) {
mLauncher.getHotseat().getHitRect(r);
if (r.contains(d.x, d.y)) {
- layout = mLauncher.getHotseat().getLayout();
+ layout = mLauncher.getHotseat().findMatchingPageForDragOver(d.x, d.y, false);
}
}
if (layout == null) {
@@ -3364,6 +3369,10 @@ public class Workspace extends PagedView
if (layout != mDragTargetLayout) {
setCurrentDropLayout(layout);
setCurrentDragOverlappingLayout(layout);
+
+ if (mLauncher.isHotseatLayout(mDragTargetLayout)) {
+ mSpringLoadedDragController.setAlarm(mDragTargetLayout);
+ }
}
}
@@ -3371,7 +3380,7 @@ public class Workspace extends PagedView
if (mDragTargetLayout != null) {
// We want the point to be mapped to the dragTarget.
if (mLauncher.isHotseatLayout(mDragTargetLayout)) {
- mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
+ mLauncher.getHotseat().mapPointFromChildToSelf(mDragTargetLayout, mDragViewVisualCenter);
} else {
mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null);
}
@@ -3586,9 +3595,12 @@ public class Workspace extends PagedView
final int screen = mLauncher.isHotseatLayout(cellLayout) ?
mLauncher.getHotseat().indexOfChild(cellLayout) :
indexOfChild(cellLayout);
- if (!mLauncher.isHotseatLayout(cellLayout) && screen != mCurrentPage
- && mState != State.SPRING_LOADED) {
- snapToPage(screen);
+ if (mState != State.SPRING_LOADED) {
+ if (!mLauncher.isHotseatLayout(cellLayout) && screen != mCurrentPage) {
+ snapToPage(screen);
+ } else if (mLauncher.isHotseatLayout(cellLayout) && screen != mLauncher.getHotseat().getCurrentPage()) {
+ mLauncher.getHotseat().snapToPage(screen);
+ }
}
if (info instanceof PendingAddItemInfo) {
@@ -3939,7 +3951,7 @@ public class Workspace extends PagedView
} else if (mDragInfo != null) {
CellLayout cellLayout;
if (mLauncher.isHotseatLayout(target)) {
- cellLayout = mLauncher.getHotseat().getLayout();
+ cellLayout = (CellLayout) mLauncher.getHotseat().getChildAt(mDragInfo.screen);
} else {
cellLayout = (CellLayout) getChildAt(mDragInfo.screen);
}
@@ -3962,7 +3974,7 @@ public class Workspace extends PagedView
int container = Favorites.CONTAINER_DESKTOP;
if (mLauncher.isHotseatLayout(cl)) {
- screen = -1;
+ screen = mLauncher.getHotseat().indexOfChild(cl);
container = Favorites.CONTAINER_HOTSEAT;
}