summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/trebuchet/Hotseat.java
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/com/cyanogenmod/trebuchet/Hotseat.java
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/com/cyanogenmod/trebuchet/Hotseat.java')
-rw-r--r--src/com/cyanogenmod/trebuchet/Hotseat.java115
1 files changed, 111 insertions, 4 deletions
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();