diff options
author | Winson Chung <winsonc@google.com> | 2011-09-16 20:14:36 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2011-09-18 18:38:11 -0700 |
commit | 7d7541e7b48fdc114c24b3b0aa75e70d7228041e (patch) | |
tree | 4b210341894a5e14d00d91009ac0b3874b76ac15 /src/com/android/launcher2/Cling.java | |
parent | 23409c2a1247a7531348ab1c114eca959d78b37f (diff) | |
download | android_packages_apps_Trebuchet-7d7541e7b48fdc114c24b3b0aa75e70d7228041e.tar.gz android_packages_apps_Trebuchet-7d7541e7b48fdc114c24b3b0aa75e70d7228041e.tar.bz2 android_packages_apps_Trebuchet-7d7541e7b48fdc114c24b3b0aa75e70d7228041e.zip |
Updating Clings. (5057945, 5056643)
Change-Id: Ifb2d37e92495aeddf9d4b3277eb8d2a846f4aa99
Diffstat (limited to 'src/com/android/launcher2/Cling.java')
-rw-r--r-- | src/com/android/launcher2/Cling.java | 296 |
1 files changed, 111 insertions, 185 deletions
diff --git a/src/com/android/launcher2/Cling.java b/src/com/android/launcher2/Cling.java index ae8dd4319..4f37cb9e0 100644 --- a/src/com/android/launcher2/Cling.java +++ b/src/com/android/launcher2/Cling.java @@ -19,9 +19,12 @@ package com.android.launcher2; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; +import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; -import android.graphics.Point; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.DisplayMetrics; @@ -32,23 +35,36 @@ import com.android.launcher.R; public class Cling extends FrameLayout { + static final String WORKSPACE_CLING_DISMISSED_KEY = "cling.workspace.dismissed"; + static final String ALLAPPS_CLING_DISMISSED_KEY = "cling.allapps.dismissed"; + static final String FOLDER_CLING_DISMISSED_KEY = "cling.folder.dismissed"; + private static String WORKSPACE_PORTRAIT = "workspace_portrait"; private static String WORKSPACE_LANDSCAPE = "workspace_landscape"; private static String ALLAPPS_PORTRAIT = "all_apps_portrait"; private static String ALLAPPS_LANDSCAPE = "all_apps_landscape"; + private static String FOLDER_PORTRAIT = "folder_portrait"; + private static String FOLDER_LANDSCAPE = "folder_landscape"; private Launcher mLauncher; private boolean mIsInitialized; private String mDrawIdentifier; + private Drawable mBackground; private Drawable mPunchThroughGraphic; + private Drawable mHandTouchGraphic; private int mPunchThroughGraphicCenterRadius; private int mAppIconSize; private int mTabBarHeight; private int mTabBarHorizontalPadding; + private int mButtonBarHeight; + private float mRevealRadius; + private int[] mPositionData; + + private Paint mErasePaint; - View mWorkspaceDesc1; - View mWorkspaceDesc2; - View mAllAppsDesc; + private View mWorkspaceDesc1; + private View mWorkspaceDesc2; + private View mAllAppsDesc; public Cling(Context context) { this(context, null, 0); @@ -66,238 +82,148 @@ public class Cling extends FrameLayout { a.recycle(); } - void init(Launcher l) { + void init(Launcher l, int[] positionData) { if (!mIsInitialized) { mLauncher = l; + mPositionData = positionData; Resources r = getContext().getResources(); mPunchThroughGraphic = r.getDrawable(R.drawable.cling); mPunchThroughGraphicCenterRadius = r.getDimensionPixelSize(R.dimen.clingPunchThroughGraphicCenterRadius); mAppIconSize = r.getDimensionPixelSize(R.dimen.app_icon_size); + mRevealRadius = mAppIconSize * 1f; mTabBarHeight = r.getDimensionPixelSize(R.dimen.apps_customize_tab_bar_height); mTabBarHorizontalPadding = r.getDimensionPixelSize(R.dimen.toolbar_button_horizontal_padding); + mButtonBarHeight = r.getDimensionPixelSize(R.dimen.button_bar_height); mWorkspaceDesc1 = findViewById(R.id.workspace_cling_move_item); mWorkspaceDesc2 = findViewById(R.id.workspace_cling_open_all_apps); mAllAppsDesc = findViewById(R.id.all_apps_cling_add_item); + + mErasePaint = new Paint(); + mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); + mErasePaint.setColor(0xFFFFFF); + mErasePaint.setAlpha(0); + mIsInitialized = true; } } void cleanup() { + mBackground = null; mPunchThroughGraphic = null; + mHandTouchGraphic = null; + mIsInitialized = false; + } + + private int[] getPunchThroughPosition() { + if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT)) { + return new int[]{getMeasuredWidth() / 2, getMeasuredHeight() - (mButtonBarHeight / 2)}; + } else if (mDrawIdentifier.equals(WORKSPACE_LANDSCAPE)) { + return new int[]{getMeasuredWidth() - (mButtonBarHeight / 2), getMeasuredHeight() / 2}; + } else if (mDrawIdentifier.equals(ALLAPPS_PORTRAIT) || + mDrawIdentifier.equals(ALLAPPS_LANDSCAPE)) { + return mPositionData; + } + return new int[]{-1, -1}; } @Override public boolean onTouchEvent(android.view.MotionEvent event) { - // Do nothing + if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) || + mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || + mDrawIdentifier.equals(ALLAPPS_PORTRAIT) || + mDrawIdentifier.equals(ALLAPPS_LANDSCAPE)) { + int[] pos = getPunchThroughPosition(); + double diff = Math.sqrt(Math.pow(event.getX() - pos[0], 2) + + Math.pow(event.getY() - pos[1], 2)); + if (diff < mRevealRadius) { + if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT)) { + // Do nothing + } else if (mDrawIdentifier.equals(ALLAPPS_PORTRAIT)) { + // Do nothing + } + return false; + } + } else if (mDrawIdentifier.equals(FOLDER_PORTRAIT) || + mDrawIdentifier.equals(FOLDER_LANDSCAPE)) { + Folder f = mLauncher.getWorkspace().getOpenFolder(); + if (f != null) { + Rect r = new Rect(); + f.getHitRect(r); + if (r.contains((int) event.getX(), (int) event.getY())) { + return false; + } + } + } return true; }; @Override protected void dispatchDraw(Canvas canvas) { - // Draw the rest of the cling - super.dispatchDraw(canvas); - if (mIsInitialized) { DisplayMetrics metrics = new DisplayMetrics(); mLauncher.getWindowManager().getDefaultDisplay().getMetrics(metrics); - int dotRadius = (int) (6f * metrics.density); - - Paint p = new Paint(); - p.setAntiAlias(true); - p.setColor(0xFF49C0EC); - - if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT)) { - /* Draw the all apps line */ { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) - mWorkspaceDesc2.getLayoutParams(); - int[] loc = new int[2]; - mWorkspaceDesc2.getLocationInWindow(loc); - int x = loc[0]; - int xOffset = (int) (10f * metrics.density); - int y = loc[1]; - int yOffset = (int) (30f * metrics.density); - int w = mWorkspaceDesc2.getWidth(); - int h = mWorkspaceDesc2.getHeight(); - - Point p1 = new Point(x + w + xOffset, y - (2 * dotRadius)); - Point p2 = new Point(getMeasuredWidth() / 2, getMeasuredHeight() - - mAppIconSize / 2 - yOffset); - canvas.drawCircle(p1.x, p1.y, dotRadius, p); - canvas.drawCircle(p2.x, p2.y, dotRadius, p); - - Point p3 = new Point(p1.x, (int) (p1.y + (p2.y - p1.y) * 0.30f)); - Point p4 = new Point(p2.x, (int) (p1.y + (p2.y - p1.y) * 0.55f)); - canvas.drawLine(p1.x, p1.y, p3.x, p3.y, p); - canvas.drawLine(p3.x, p3.y, p4.x, p4.y, p); - canvas.drawLine(p4.x, p4.y, p2.x, p2.y, p); - } - - /* Draw the move line */ { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) - mWorkspaceDesc1.getLayoutParams(); - int[] loc = new int[2]; - mWorkspaceDesc1.getLocationInWindow(loc); - int x = loc[0]; - int y = loc[1]; - int w = mWorkspaceDesc1.getWidth(); - int h = mWorkspaceDesc1.getHeight(); - - Point p1 = new Point(x + w, y - (2 * dotRadius)); - Point p2 = new Point(x + w, getMeasuredHeight() - (4 * mAppIconSize)); - canvas.drawCircle(p1.x, p1.y, dotRadius, p); - canvas.drawCircle(p2.x, p2.y, dotRadius, p); - canvas.drawLine(p1.x, p1.y, p2.x, p2.y, p); - } - } else if (mDrawIdentifier.equals(WORKSPACE_LANDSCAPE)) { - int xOffset = (int) (1.5f * mAppIconSize); - /* Draw the all apps line */ { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) - mWorkspaceDesc2.getLayoutParams(); - int[] loc = new int[2]; - mWorkspaceDesc2.getLocationInWindow(loc); - int x = loc[0]; - int y = loc[1]; - int w = mWorkspaceDesc2.getWidth(); - int h = mWorkspaceDesc2.getHeight(); - - Point p1 = new Point(x + w, y - (2 * dotRadius)); - Point p2 = new Point(getMeasuredWidth() - xOffset, - getMeasuredHeight() / 2); - canvas.drawCircle(p1.x, p1.y, dotRadius, p); - canvas.drawCircle(p2.x, p2.y, dotRadius, p); - - Point p3 = new Point((int) (p1.x + (p2.x - p1.x) * 0.6f), p1.y); - Point p4 = new Point((int) (p1.x + (p2.x - p1.x) * 0.75f), p2.y); - canvas.drawLine(p1.x, p1.y, p3.x, p3.y, p); - canvas.drawLine(p3.x, p3.y, p4.x, p4.y, p); - canvas.drawLine(p4.x, p4.y, p2.x, p2.y, p); - } - /* Draw the move line */ { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) - mWorkspaceDesc1.getLayoutParams(); - int[] loc = new int[2]; - mWorkspaceDesc1.getLocationInWindow(loc); - int x = loc[0]; - int y = loc[1]; - int w = mWorkspaceDesc1.getWidth(); - int h = mWorkspaceDesc1.getHeight(); - - Point p1 = new Point(x + w, y - (2 * dotRadius)); - Point p2 = new Point(getMeasuredWidth() - xOffset, y - (2 * dotRadius)); - canvas.drawCircle(p1.x, p1.y, dotRadius, p); - canvas.drawCircle(p2.x, p2.y, dotRadius, p); - canvas.drawLine(p1.x, p1.y, p2.x, p2.y, p); - } - } else if (mDrawIdentifier.equals(ALLAPPS_PORTRAIT)) { - float r = mAppIconSize * 1.1f; - float scale = r / mPunchThroughGraphicCenterRadius; - int dw = (int) (scale * mPunchThroughGraphic.getIntrinsicWidth()); - int dh = (int) (scale * mPunchThroughGraphic.getIntrinsicHeight()); - int cx = getMeasuredWidth() / 2; - int cy = mTabBarHeight + ((getMeasuredHeight() - mTabBarHeight) / 2); - mPunchThroughGraphic.setBounds(cx - dw/2, cy - dh/2, cx + dw/2, cy + dh/2); - mPunchThroughGraphic.draw(canvas); - - /* Draw the line */ { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) - mAllAppsDesc.getLayoutParams(); - int[] loc = new int[2]; - mAllAppsDesc.getLocationInWindow(loc); - int x = loc[0]; - int y = loc[1]; - int yOffset = (int) (2.5f * metrics.density); - int w = mAllAppsDesc.getWidth(); - int h = mAllAppsDesc.getHeight(); - - Point p1 = new Point(getMeasuredWidth() / 2, y + h + yOffset); - Point p2 = new Point(cx, cy); - canvas.drawCircle(p1.x, p1.y, dotRadius, p); - canvas.drawCircle(p2.x, p2.y, dotRadius, p); - canvas.drawLine(p1.x, p1.y, p2.x, p2.y, p); - } - } else if (mDrawIdentifier.equals(ALLAPPS_LANDSCAPE)) { - float r = mAppIconSize * 1.1f; - float scale = r / mPunchThroughGraphicCenterRadius; - int dw = (int) (scale * mPunchThroughGraphic.getIntrinsicWidth()); - int dh = (int) (scale * mPunchThroughGraphic.getIntrinsicHeight()); - int cx = getMeasuredWidth() / 2 + getMeasuredWidth() / 4; - int cy = mTabBarHeight + ((getMeasuredHeight() - mTabBarHeight) / 2); - mPunchThroughGraphic.setBounds(cx - dw/2, cy - dh/2, cx + dw/2, cy + dh/2); - mPunchThroughGraphic.draw(canvas); - - /* Draw the line */ { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) - mAllAppsDesc.getLayoutParams(); - int[] loc = new int[2]; - mAllAppsDesc.getLocationInWindow(loc); - int x = loc[0]; - int y = loc[1]; - int w = mAllAppsDesc.getWidth(); - int h = mAllAppsDesc.getHeight(); - - Point p1 = new Point(x + w, y); - Point p2 = new Point(cx, cy); - canvas.drawCircle(p1.x, p1.y, dotRadius, p); - canvas.drawCircle(p2.x, p2.y, dotRadius, p); - canvas.drawLine(p1.x, p1.y, p2.x, p2.y, p); - } - } - - /* // Draw the background Bitmap b = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); - c.drawColor(0xD4000000); - Paint p = new Paint(); - p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); - p.setColor(0xFFFFFF); - p.setAlpha(0); + + // Draw the background + if (mBackground == null) { + if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT)) { + mBackground = getResources().getDrawable(R.drawable.bg_cling1); + } else if (mDrawIdentifier.equals(ALLAPPS_PORTRAIT)) { + mBackground = getResources().getDrawable(R.drawable.bg_cling2); + } else if (mDrawIdentifier.equals(FOLDER_PORTRAIT)) { + mBackground = getResources().getDrawable(R.drawable.bg_cling3); + } + } + if (mBackground != null) { + mBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); + mBackground.draw(c); + } else { + c.drawColor(0x99000000); + } int cx = -1; int cy = -1; - float r = mAppIconSize * 1.4f; - float scale = r / mPunchThroughGraphicCenterRadius; + float scale = mRevealRadius / mPunchThroughGraphicCenterRadius; int dw = (int) (scale * mPunchThroughGraphic.getIntrinsicWidth()); int dh = (int) (scale * mPunchThroughGraphic.getIntrinsicHeight()); - if (mDrawIdentifier.equals("workspace_portrait")) { - cx = getMeasuredWidth() / 2; - cy = getMeasuredHeight() - mAppIconSize / 2; - } else if (mDrawIdentifier.equals("workspace_landscape")) { - cx = getMeasuredWidth() - mAppIconSize / 2; - cy = getMeasuredHeight() / 2; - } else if (mDrawIdentifier.equals("large_workspace_landscape") || - mDrawIdentifier.equals("large_workspace_portrait")) { - cx = getMeasuredWidth() - mTabBarHorizontalPadding; - cy = 0; - } else if (mDrawIdentifier.equals("all_apps_portrait")) { - cx = getMeasuredWidth() / 2; - cy = mTabBarHeight + ((getMeasuredHeight() - mTabBarHeight) / 2); - } else if (mDrawIdentifier.equals("all_apps_landscape")) { - cx = getMeasuredWidth() / 2 + getMeasuredWidth() / 4; - cy = mTabBarHeight + ((getMeasuredHeight() - mTabBarHeight) / 2); - } else if (mDrawIdentifier.equals("large_all_apps_portrait")) { - cx = getMeasuredWidth() / 2; - cy = mTabBarHeight + (int) ((getMeasuredHeight() - mTabBarHeight) * 2f / 5f); - } else if (mDrawIdentifier.equals("large_all_apps_landscape")) { - cx = getMeasuredWidth() / 2 + getMeasuredWidth() / 6; - cy = mTabBarHeight + (int) ((getMeasuredHeight() - mTabBarHeight) * 2f / 5f); - } + // 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, r, p); + 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 + if (mDrawIdentifier.equals(ALLAPPS_PORTRAIT) || + mDrawIdentifier.equals(ALLAPPS_LANDSCAPE)) { + if (mHandTouchGraphic == null) { + mHandTouchGraphic = getResources().getDrawable(R.drawable.hand); + } + int offset = -mAppIconSize / 4; + mHandTouchGraphic.setBounds(cx + offset, cy + offset, + cx + mHandTouchGraphic.getIntrinsicWidth() + offset, + cy + mHandTouchGraphic.getIntrinsicHeight() + offset); + mHandTouchGraphic.draw(c); + } + canvas.drawBitmap(b, 0, 0, null); c.setBitmap(null); b = null; - */ } + + // Draw the rest of the cling + super.dispatchDraw(canvas); }; } |