Merge "Support for 600dp & custom clings" into jb-dev
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user