diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/AppsCustomizePagedView.java | 17 | ||||
-rw-r--r-- | src/com/android/launcher2/AppsCustomizeTabHost.java | 13 | ||||
-rw-r--r-- | src/com/android/launcher2/Cling.java | 296 | ||||
-rw-r--r-- | src/com/android/launcher2/DragLayer.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher2/Folder.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 132 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedView.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedViewCellLayout.java | 8 |
8 files changed, 248 insertions, 226 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index b208e88..96859d3 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -174,6 +174,10 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen private ArrayList<ApplicationInfo> mApps; private ArrayList<Object> mWidgets; + // Cling + private int mClingFocusedX; + private int mClingFocusedY; + // Caching private Canvas mCanvas; private Drawable mDefaultWidgetBackground; @@ -234,6 +238,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellHeightGap, 0); mWidgetCountX = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountX, 2); mWidgetCountY = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountY, 2); + mClingFocusedX = a.getInt(R.styleable.AppsCustomizePagedView_clingFocusedX, 0); + mClingFocusedY = a.getInt(R.styleable.AppsCustomizePagedView_clingFocusedY, 0); a.recycle(); mWidgetSpacingLayout = new PagedViewCellLayout(getContext()); @@ -375,6 +381,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mContentWidth = mWidgetSpacingLayout.getContentWidth(); invalidatePageData(Math.max(0, mRestorePage)); mRestorePage = -1; + + int[] offset = new int[2]; + int[] pos = mWidgetSpacingLayout.estimateCellPosition(mClingFocusedX, mClingFocusedY); + mLauncher.getDragLayer().getLocationInDragLayer(this, offset); + pos[0] += (getMeasuredWidth() - mWidgetSpacingLayout.getMeasuredWidth()) / 2 + offset[0]; + pos[1] += (getMeasuredHeight() - mWidgetSpacingLayout.getMeasuredHeight()) / 2 + offset[1]; + mLauncher.showFirstRunAllAppsCling(pos); + } @Override @@ -533,6 +547,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } @Override protected boolean beginDragging(View v) { + // Dismiss the cling + mLauncher.dismissAllAppsCling(null); + if (!super.beginDragging(v)) return false; // Go into spring loaded mode (must happen before we startDrag()) diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java index 124cf73..8b7b956 100644 --- a/src/com/android/launcher2/AppsCustomizeTabHost.java +++ b/src/com/android/launcher2/AppsCustomizeTabHost.java @@ -271,7 +271,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona /* LauncherTransitionable overrides */ @Override - public void onLauncherTransitionStart(Animator animation, boolean toWorkspace) { + public void onLauncherTransitionStart(Launcher l, Animator animation, boolean toWorkspace) { mInTransition = true; // isHardwareAccelerated() checks if we're attached to a window and if that // window is HW accelerated-- we were sometimes not attached to a window @@ -294,14 +294,19 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona } @Override - public void onLauncherTransitionEnd(Animator animation, boolean toWorkspace) { + public void onLauncherTransitionEnd(Launcher l, Animator animation, boolean toWorkspace) { mInTransition = false; if (animation != null) { setLayerType(LAYER_TYPE_NONE, null); } - if (!toWorkspace && !LauncherApplication.isScreenLarge()) { - mAppsCustomizePane.hideScrollingIndicator(false); + if (!toWorkspace) { + // Dismiss the cling if necessary + l.dismissWorkspaceCling(null); + + if (!LauncherApplication.isScreenLarge()) { + mAppsCustomizePane.hideScrollingIndicator(false); + } } } diff --git a/src/com/android/launcher2/Cling.java b/src/com/android/launcher2/Cling.java index ae8dd43..4f37cb9 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); }; } diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java index d0d4bad..28ef6a5 100644 --- a/src/com/android/launcher2/DragLayer.java +++ b/src/com/android/launcher2/DragLayer.java @@ -108,7 +108,7 @@ public class DragLayer extends FrameLayout { } Folder currentFolder = mLauncher.getWorkspace().getOpenFolder(); - if (currentFolder != null && intercept) { + if (currentFolder != null && !mLauncher.isFolderClingVisible() && intercept) { if (currentFolder.isEditingName()) { getDescendantRectRelativeToSelf(currentFolder.getEditTextRegion(), hitRect); if (!hitRect.contains(x, y)) { diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java index a0342cf..a1aa670 100644 --- a/src/com/android/launcher2/Folder.java +++ b/src/com/android/launcher2/Folder.java @@ -208,6 +208,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList return false; } + mLauncher.dismissFolderCling(null); + mLauncher.getWorkspace().onDragStartedWithItem(v); mLauncher.getWorkspace().beginDragShared(v, this); mIconDrawable = ((TextView) v).getCompoundDrawables()[1]; diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 29f3f25..482f086 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -75,11 +75,12 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.Surface; import android.view.View; +import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.view.WindowManager; -import android.view.View.OnLongClickListener; import android.view.accessibility.AccessibilityEvent; import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; import android.view.inputmethod.InputMethodManager; import android.widget.Advanceable; @@ -161,7 +162,8 @@ public final class Launcher extends Activity static final int APPWIDGET_HOST_ID = 1024; private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600; - private static final int DISMISS_CLING_DURATION = 300; + private static final int SHOW_CLING_DURATION = 250; + private static final int DISMISS_CLING_DURATION = 250; private static final Object sLock = new Object(); private static int sScreen = DEFAULT_SCREEN; @@ -271,7 +273,7 @@ public final class Launcher extends Activity checkForLocaleChange(); setContentView(R.layout.launcher); setupViews(); - enableClingsIfNecessary(); + showFirstRunWorkspaceCling(); registerContentObservers(); @@ -1770,6 +1772,8 @@ public final class Launcher extends Activity final FolderInfo info = folderIcon.mInfo; Folder openFolder = mWorkspace.getFolderForTag(info); + Cling cling = showFirstRunFoldersCling(); + // If the folder info reports that the associated folder is open, then verify that // it is actually opened. There have been a few instances where this gets out of sync. if (info.opened && openFolder == null) { @@ -1798,6 +1802,10 @@ public final class Launcher extends Activity } } } + + if (cling != null) { + cling.bringToFront(); + } } private void growAndFadeOutFolderIcon(FolderIcon fi) { @@ -1874,6 +1882,9 @@ public final class Launcher extends Activity Folder folder = mWorkspace.getOpenFolder(); if (folder != null) { closeFolder(folder); + + // Dismiss the folder cling + dismissFolderCling(null); } } @@ -2119,6 +2130,7 @@ public final class Launcher extends Activity */ private void cameraZoomOut(State toState, boolean animated, final boolean springLoaded) { final Resources res = getResources(); + final Launcher instance = this; final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); @@ -2159,7 +2171,8 @@ public final class Launcher extends Activity alphaAnim.start(); if (toView instanceof LauncherTransitionable) { - ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim, false); + ((LauncherTransitionable) toView).onLauncherTransitionStart(instance, scaleAnim, + false); } scaleAnim.addListener(new AnimatorListenerAdapter() { boolean animationCancelled = false; @@ -2181,7 +2194,8 @@ public final class Launcher extends Activity toView.setScaleX(1.0f); toView.setScaleY(1.0f); if (toView instanceof LauncherTransitionable) { - ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim, false); + ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance, + scaleAnim, false); } if (!springLoaded && !LauncherApplication.isScreenLarge()) { @@ -2214,8 +2228,8 @@ public final class Launcher extends Activity toView.setVisibility(View.VISIBLE); toView.bringToFront(); if (toView instanceof LauncherTransitionable) { - ((LauncherTransitionable) toView).onLauncherTransitionStart(null, false); - ((LauncherTransitionable) toView).onLauncherTransitionEnd(null, false); + ((LauncherTransitionable) toView).onLauncherTransitionStart(instance, null, false); + ((LauncherTransitionable) toView).onLauncherTransitionEnd(instance, null, false); if (!springLoaded && !LauncherApplication.isScreenLarge()) { // Hide the workspace scrollbar @@ -2235,6 +2249,7 @@ public final class Launcher extends Activity */ private void cameraZoomIn(State fromState, boolean animated, final boolean springLoaded) { Resources res = getResources(); + final Launcher instance = this; final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); final float scaleFactor = (float) @@ -2270,7 +2285,8 @@ public final class Launcher extends Activity } }); if (fromView instanceof LauncherTransitionable) { - ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim, true); + ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, alphaAnim, + true); } alphaAnim.addListener(new AnimatorListenerAdapter() { @Override @@ -2278,7 +2294,8 @@ public final class Launcher extends Activity updateWallpaperVisibility(true); fromView.setVisibility(View.GONE); if (fromView instanceof LauncherTransitionable) { - ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim,true); + ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance, + alphaAnim, true); } mWorkspace.hideScrollingIndicator(false); } @@ -2289,8 +2306,8 @@ public final class Launcher extends Activity } else { fromView.setVisibility(View.GONE); if (fromView instanceof LauncherTransitionable) { - ((LauncherTransitionable) fromView).onLauncherTransitionStart(null, true); - ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null, true); + ((LauncherTransitionable) fromView).onLauncherTransitionStart(instance, null, true); + ((LauncherTransitionable) fromView).onLauncherTransitionEnd(instance, null, true); } } } @@ -3067,33 +3084,40 @@ public final class Launcher extends Activity } /* Cling related */ - private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling.workspace.dismissed"; - private static final String ALLAPPS_CLING_DISMISSED_KEY = "cling.allapps.dismissed"; - private void enableClingsIfNecessary() { + private static final String PREFS_KEY = "com.android.launcher2.prefs"; + private boolean isClingsEnabled() { // TEMPORARY: DISABLE CLINGS ON LARGE UI - if (LauncherApplication.isScreenLarge()) return; - + if (LauncherApplication.isScreenLarge()) return false; // disable clings when running in a test harness - if(ActivityManager.isRunningInTestHarness()) return; + if(ActivityManager.isRunningInTestHarness()) return false; - // Enable the clings only if they have not been dismissed before - SharedPreferences prefs = - getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE); - if (!prefs.getBoolean(WORKSPACE_CLING_DISMISSED_KEY, false)) { - Cling cling = (Cling) findViewById(R.id.workspace_cling); - cling.init(this); - cling.setVisibility(View.VISIBLE); - } - if (!prefs.getBoolean(ALLAPPS_CLING_DISMISSED_KEY, false)) { - Cling cling = (Cling) findViewById(R.id.all_apps_cling); - cling.init(this); + return true; + } + private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) { + Cling cling = (Cling) findViewById(clingId); + if (cling != null) { + cling.init(this, positionData); cling.setVisibility(View.VISIBLE); + cling.setLayerType(View.LAYER_TYPE_HARDWARE, null); + if (animate) { + cling.buildLayer(); + cling.setAlpha(0f); + cling.animate() + .alpha(1f) + .setInterpolator(new DecelerateInterpolator()) + .setDuration(SHOW_CLING_DURATION) + .setStartDelay(delay) + .start(); + } else { + cling.setAlpha(1f); + } } + return cling; } - private void dismissCling(final Cling cling, final String flag) { + private void dismissCling(final Cling cling, final String flag, int duration) { if (cling != null) { ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f); - anim.setDuration(DISMISS_CLING_DURATION); + anim.setDuration(duration); anim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { cling.setVisibility(View.GONE); @@ -3108,13 +3132,53 @@ public final class Launcher extends Activity anim.start(); } } + public void showFirstRunWorkspaceCling() { + if (!isClingsEnabled()) return; + + // Enable the clings only if they have not been dismissed before + SharedPreferences prefs = + getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); + if (!prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) { + initCling(R.id.workspace_cling, null, false, 0); + } + } + public void showFirstRunAllAppsCling(int[] position) { + if (!isClingsEnabled()) return; + + // Enable the clings only if they have not been dismissed before + SharedPreferences prefs = + getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); + if (!prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) { + initCling(R.id.all_apps_cling, position, true, 0); + } + } + public Cling showFirstRunFoldersCling() { + if (!isClingsEnabled()) return null; + + // Enable the clings only if they have not been dismissed before + SharedPreferences prefs = + getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE); + Cling cling = null; + if (!prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) { + cling = initCling(R.id.folder_cling, null, true, 0); + } + return cling; + } + public boolean isFolderClingVisible() { + Cling cling = (Cling) findViewById(R.id.folder_cling); + return cling.getVisibility() == View.VISIBLE; + } public void dismissWorkspaceCling(View v) { Cling cling = (Cling) findViewById(R.id.workspace_cling); - dismissCling(cling, WORKSPACE_CLING_DISMISSED_KEY); + dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); } public void dismissAllAppsCling(View v) { Cling cling = (Cling) findViewById(R.id.all_apps_cling); - dismissCling(cling, ALLAPPS_CLING_DISMISSED_KEY); + dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); + } + public void dismissFolderCling(View v) { + Cling cling = (Cling) findViewById(R.id.folder_cling); + dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); } /** @@ -3138,6 +3202,6 @@ public final class Launcher extends Activity } interface LauncherTransitionable { - void onLauncherTransitionStart(Animator animation, boolean toWorkspace); - void onLauncherTransitionEnd(Animator animation, boolean toWorkspace); + void onLauncherTransitionStart(Launcher l, Animator animation, boolean toWorkspace); + void onLauncherTransitionEnd(Launcher l, Animator animation, boolean toWorkspace); } diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java index 9a105d1..d7e9e06 100644 --- a/src/com/android/launcher2/PagedView.java +++ b/src/com/android/launcher2/PagedView.java @@ -204,9 +204,9 @@ public abstract class PagedView extends ViewGroup { mPageLayoutPaddingRight = a.getDimensionPixelSize( R.styleable.PagedView_pageLayoutPaddingRight, 0); mPageLayoutWidthGap = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutWidthGap, -1); + R.styleable.PagedView_pageLayoutWidthGap, 0); mPageLayoutHeightGap = a.getDimensionPixelSize( - R.styleable.PagedView_pageLayoutHeightGap, -1); + R.styleable.PagedView_pageLayoutHeightGap, 0); mScrollIndicatorPaddingLeft = a.getDimensionPixelSize(R.styleable.PagedView_scrollIndicatorPaddingLeft, 0); mScrollIndicatorPaddingRight = diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java index 29dc352..5e87b46 100644 --- a/src/com/android/launcher2/PagedViewCellLayout.java +++ b/src/com/android/launcher2/PagedViewCellLayout.java @@ -352,6 +352,14 @@ public class PagedViewCellLayout extends ViewGroup implements Page { return n; } + /** Returns an estimated center position of the cell at the specified index */ + public int[] estimateCellPosition(int x, int y) { + return new int[] { + mPaddingLeft + (x * mCellWidth) + (x * mWidthGap) + (mCellWidth / 2), + mPaddingTop + (y * mCellHeight) + (y * mHeightGap) + (mCellHeight / 2) + }; + } + public void calculateCellCount(int width, int height, int maxCellCountX, int maxCellCountY) { mCellCountX = Math.min(maxCellCountX, estimateCellHSpan(width)); mCellCountY = Math.min(maxCellCountY, estimateCellVSpan(height)); |