diff options
author | Andrew Flynn <flynn@google.com> | 2012-05-12 17:00:35 -0700 |
---|---|---|
committer | Andrew Flynn <flynn@google.com> | 2012-05-13 16:31:16 -0700 |
commit | 2f5f945704a958470a51214399af9aee7bf6568d (patch) | |
tree | 60698e7c1d03ebb84f1d9bcd91221b2cc3e6a677 /src/com/android/launcher2/Cling.java | |
parent | 28b952ad3ec46ba9d14063797c1c96984ade8deb (diff) | |
download | android_packages_apps_Trebuchet-2f5f945704a958470a51214399af9aee7bf6568d.tar.gz android_packages_apps_Trebuchet-2f5f945704a958470a51214399af9aee7bf6568d.tar.bz2 android_packages_apps_Trebuchet-2f5f945704a958470a51214399af9aee7bf6568d.zip |
Support for 600dp & custom clings
Change-Id: Ifea85be6ff062c61664a3f0ec6c1c24a1fc7b559
Diffstat (limited to 'src/com/android/launcher2/Cling.java')
-rw-r--r-- | src/com/android/launcher2/Cling.java | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/src/com/android/launcher2/Cling.java b/src/com/android/launcher2/Cling.java index f9a0681f6..6f2d02116 100644 --- a/src/com/android/launcher2/Cling.java +++ b/src/com/android/launcher2/Cling.java @@ -40,13 +40,16 @@ public class Cling extends FrameLayout { private static String WORKSPACE_PORTRAIT = "workspace_portrait"; private static String WORKSPACE_LANDSCAPE = "workspace_landscape"; + private static String WORKSPACE_LARGE = "workspace_large"; + private static String WORKSPACE_CUSTOM = "workspace_custom"; + private static String ALLAPPS_PORTRAIT = "all_apps_portrait"; private static String ALLAPPS_LANDSCAPE = "all_apps_landscape"; + private static String ALLAPPS_LARGE = "all_apps_large"; + private static String FOLDER_PORTRAIT = "folder_portrait"; private static String FOLDER_LANDSCAPE = "folder_landscape"; - private static String WORKSPACE_LARGE = "workspace_large"; private static String FOLDER_LARGE = "folder_large"; - private static String ALLAPPS_LARGE = "all_apps_large"; private Launcher mLauncher; private boolean mIsInitialized; @@ -59,6 +62,7 @@ public class Cling extends FrameLayout { private int mButtonBarHeight; private float mRevealRadius; private int[] mPositionData; + private int[] mCustomPositionData; private Paint mErasePaint; @@ -84,11 +88,23 @@ public class Cling extends FrameLayout { mPositionData = positionData; Resources r = getContext().getResources(); + + // If we have custom punch through data from resources + TypedArray punchThroughCoords = r.obtainTypedArray(R.array.punch_through_coords); + + if (punchThroughCoords != null) { + int len = punchThroughCoords.length(); + mCustomPositionData = new int[len]; + for (int i = 0; i < len; i++) { + mCustomPositionData[i] = punchThroughCoords.getDimensionPixelSize(i, 0); + } + } + mPunchThroughGraphic = r.getDrawable(R.drawable.cling); mPunchThroughGraphicCenterRadius = r.getDimensionPixelSize(R.dimen.clingPunchThroughGraphicCenterRadius); mAppIconSize = r.getDimensionPixelSize(R.dimen.app_icon_size); - mRevealRadius = mAppIconSize * 1f; + mRevealRadius = r.getDimensionPixelSize(R.dimen.reveal_radius) * 1f; mButtonBarHeight = r.getDimensionPixelSize(R.dimen.button_bar_height); mErasePaint = new Paint(); @@ -107,7 +123,7 @@ public class Cling extends FrameLayout { mIsInitialized = false; } - private int[] getPunchThroughPosition() { + private int[] getPunchThroughPositions() { if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT)) { return new int[]{getMeasuredWidth() / 2, getMeasuredHeight() - (mButtonBarHeight / 2)}; } else if (mDrawIdentifier.equals(WORKSPACE_LANDSCAPE)) { @@ -117,6 +133,8 @@ public class Cling extends FrameLayout { final int cornerXOffset = (int) (scale * 15); final int cornerYOffset = (int) (scale * 10); return new int[]{getMeasuredWidth() - cornerXOffset, cornerYOffset}; + } else if (mDrawIdentifier.equals(WORKSPACE_CUSTOM)) { + return mCustomPositionData; } else if (mDrawIdentifier.equals(ALLAPPS_PORTRAIT) || mDrawIdentifier.equals(ALLAPPS_LANDSCAPE) || mDrawIdentifier.equals(ALLAPPS_LARGE)) { @@ -130,14 +148,18 @@ public class Cling extends FrameLayout { if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) || mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || mDrawIdentifier.equals(WORKSPACE_LARGE) || + mDrawIdentifier.equals(WORKSPACE_CUSTOM) || mDrawIdentifier.equals(ALLAPPS_PORTRAIT) || mDrawIdentifier.equals(ALLAPPS_LANDSCAPE) || mDrawIdentifier.equals(ALLAPPS_LARGE)) { - int[] pos = getPunchThroughPosition(); - double diff = Math.sqrt(Math.pow(event.getX() - pos[0], 2) + - Math.pow(event.getY() - pos[1], 2)); - if (diff < mRevealRadius) { - return false; + + int[] positions = getPunchThroughPositions(); + for (int i = 0; i < positions.length; i += 2) { + double diff = Math.sqrt(Math.pow(event.getX() - positions[i], 2) + + Math.pow(event.getY() - positions[i + 1], 2)); + if (diff < mRevealRadius) { + return false; + } } } else if (mDrawIdentifier.equals(FOLDER_PORTRAIT) || mDrawIdentifier.equals(FOLDER_LANDSCAPE) || @@ -168,8 +190,9 @@ public class Cling extends FrameLayout { // Draw the background if (mBackground == null) { if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) || - mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || - mDrawIdentifier.equals(WORKSPACE_LARGE)) { + mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || + mDrawIdentifier.equals(WORKSPACE_LARGE) || + mDrawIdentifier.equals(WORKSPACE_CUSTOM)) { mBackground = getResources().getDrawable(R.drawable.bg_cling1); } else if (mDrawIdentifier.equals(ALLAPPS_PORTRAIT) || mDrawIdentifier.equals(ALLAPPS_LANDSCAPE) || @@ -196,13 +219,15 @@ public class Cling extends FrameLayout { int dh = (int) (scale * mPunchThroughGraphic.getIntrinsicHeight()); // Determine where to draw the punch through graphic - int[] pos = getPunchThroughPosition(); - cx = pos[0]; - cy = pos[1]; - if (cx > -1 && cy > -1) { - c.drawCircle(cx, cy, mRevealRadius, mErasePaint); - mPunchThroughGraphic.setBounds(cx - dw/2, cy - dh/2, cx + dw/2, cy + dh/2); - mPunchThroughGraphic.draw(c); + int[] positions = getPunchThroughPositions(); + for (int i = 0; i < positions.length; i += 2) { + cx = positions[i]; + cy = positions[i + 1]; + if (cx > -1 && cy > -1) { + c.drawCircle(cx, cy, mRevealRadius, mErasePaint); + mPunchThroughGraphic.setBounds(cx - dw/2, cy - dh/2, cx + dw/2, cy + dh/2); + mPunchThroughGraphic.draw(c); + } } // Draw the hand graphic in All Apps |