The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 20 | import android.animation.AnimatorSet; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 21 | import android.animation.ObjectAnimator; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 22 | import android.animation.TimeInterpolator; |
| 23 | import android.animation.ValueAnimator; |
| 24 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 25 | import android.app.WallpaperManager; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 26 | import android.appwidget.AppWidgetHostView; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 27 | import android.appwidget.AppWidgetManager; |
| 28 | import android.appwidget.AppWidgetProviderInfo; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 32 | import android.content.SharedPreferences; |
Patrick Dubroy | 7247f63 | 2010-08-04 16:02:59 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 34 | import android.content.res.TypedArray; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 35 | import android.graphics.Bitmap; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 36 | import android.graphics.Camera; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | import android.graphics.Canvas; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 38 | import android.graphics.Matrix; |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 39 | import android.graphics.Paint; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 40 | import android.graphics.Point; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 41 | import android.graphics.PointF; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.graphics.Rect; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 43 | import android.graphics.Region.Op; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 44 | import android.graphics.drawable.Drawable; |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 45 | import android.os.IBinder; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 46 | import android.os.Parcelable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 47 | import android.util.AttributeSet; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 48 | import android.util.DisplayMetrics; |
Daniel Sandler | 291ad12 | 2010-05-24 16:03:53 -0400 | [diff] [blame] | 49 | import android.util.Log; |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 50 | import android.view.Display; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 51 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | import android.view.View; |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 53 | import android.view.ViewGroup; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 54 | import android.view.animation.DecelerateInterpolator; |
Winson Chung | a6427b1 | 2011-07-27 10:53:39 -0700 | [diff] [blame] | 55 | import android.widget.ImageView; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 56 | import android.widget.TextView; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 58 | import com.android.launcher.R; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 59 | import com.android.launcher2.FolderIcon.FolderRingAnimator; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 60 | import com.android.launcher2.LauncherSettings.Favorites; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 61 | |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 62 | import java.net.URISyntaxException; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 63 | import java.util.ArrayList; |
| 64 | import java.util.HashSet; |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 65 | import java.util.Iterator; |
| 66 | import java.util.Set; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 67 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 68 | /** |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 69 | * The workspace is a wide area with a wallpaper and a finite number of pages. |
| 70 | * Each page contains a number of icons, folders or widgets the user can |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 71 | * interact with. A workspace is meant to be used with a fixed width only. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 73 | public class Workspace extends SmoothPagedView |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 74 | implements DropTarget, DragSource, DragScroller, View.OnTouchListener, |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 75 | DragController.DragListener, LauncherTransitionable, ViewGroup.OnHierarchyChangeListener { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 76 | private static final String TAG = "Launcher.Workspace"; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 77 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 78 | // Y rotation to apply to the workspace screens |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 79 | private static final float WORKSPACE_OVERSCROLL_ROTATION = 24f; |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 80 | private static float CAMERA_DISTANCE = 6500; |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 81 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 82 | private static final int CHILDREN_OUTLINE_FADE_OUT_DELAY = 0; |
| 83 | private static final int CHILDREN_OUTLINE_FADE_OUT_DURATION = 375; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 84 | private static final int CHILDREN_OUTLINE_FADE_IN_DURATION = 100; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 85 | |
Winson Chung | f135c6c | 2010-11-18 16:32:08 -0800 | [diff] [blame] | 86 | private static final int BACKGROUND_FADE_OUT_DURATION = 350; |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 87 | private static final int ADJACENT_SCREEN_DROP_DURATION = 300; |
Adam Cohen | 265b9a6 | 2011-12-07 14:37:18 -0800 | [diff] [blame] | 88 | private static final int FLING_THRESHOLD_VELOCITY = 500; |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 89 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 90 | // These animators are used to fade the children's outlines |
| 91 | private ObjectAnimator mChildrenOutlineFadeInAnimation; |
| 92 | private ObjectAnimator mChildrenOutlineFadeOutAnimation; |
| 93 | private float mChildrenOutlineAlpha = 0; |
| 94 | |
| 95 | // These properties refer to the background protection gradient used for AllApps and Customize |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 96 | private ValueAnimator mBackgroundFadeInAnimation; |
| 97 | private ValueAnimator mBackgroundFadeOutAnimation; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 98 | private Drawable mBackground; |
Michael Jurka | 25356e7 | 2011-03-03 14:53:11 -0800 | [diff] [blame] | 99 | boolean mDrawBackground = true; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 100 | private float mBackgroundAlpha = 0; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 101 | private float mOverScrollMaxBackgroundAlpha = 0.0f; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 102 | |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 103 | private float mWallpaperScrollRatio = 1.0f; |
| 104 | |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 105 | private final WallpaperManager mWallpaperManager; |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 106 | private IBinder mWindowToken; |
Michael Jurka | 1670698 | 2011-09-26 16:39:22 -0700 | [diff] [blame] | 107 | private static final float WALLPAPER_SCREENS_SPAN = 2f; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 108 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 109 | private int mDefaultPage; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 111 | /** |
| 112 | * CellInfo for the cell that is currently being dragged |
| 113 | */ |
| 114 | private CellLayout.CellInfo mDragInfo; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 115 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 116 | /** |
| 117 | * Target drop area calculated during last acceptDrop call. |
| 118 | */ |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 119 | private int[] mTargetCell = new int[2]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 120 | private int mDragOverX = -1; |
| 121 | private int mDragOverY = -1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 122 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 123 | static Rect mLandscapeCellLayoutMetrics = null; |
| 124 | static Rect mPortraitCellLayoutMetrics = null; |
| 125 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 126 | /** |
| 127 | * The CellLayout that is currently being dragged over |
| 128 | */ |
| 129 | private CellLayout mDragTargetLayout = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 130 | /** |
| 131 | * The CellLayout that we will show as glowing |
| 132 | */ |
| 133 | private CellLayout mDragOverlappingLayout = null; |
| 134 | |
| 135 | /** |
| 136 | * The CellLayout which will be dropped to |
| 137 | */ |
| 138 | private CellLayout mDropToLayout = null; |
| 139 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 140 | private Launcher mLauncher; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 141 | private IconCache mIconCache; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 142 | private DragController mDragController; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 143 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 144 | // These are temporary variables to prevent having to allocate a new object just to |
| 145 | // return an (x, y) value from helper functions. Do NOT use them to maintain other state. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | private int[] mTempCell = new int[2]; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 147 | private int[] mTempEstimate = new int[2]; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 148 | private float[] mDragViewVisualCenter = new float[2]; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 149 | private float[] mTempDragCoordinates = new float[2]; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 150 | private float[] mTempCellLayoutCenterCoordinates = new float[2]; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 151 | private float[] mTempDragBottomRightCoordinates = new float[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 152 | private Matrix mTempInverseMatrix = new Matrix(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 153 | |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 154 | private SpringLoadedDragController mSpringLoadedDragController; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 155 | private float mSpringLoadedShrinkFactor; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 156 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 157 | private static final int DEFAULT_CELL_COUNT_X = 4; |
| 158 | private static final int DEFAULT_CELL_COUNT_Y = 4; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 159 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 160 | // State variable that indicates whether the pages are small (ie when you're |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 161 | // in all apps or customize mode) |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 162 | |
| 163 | enum State { NORMAL, SPRING_LOADED, SMALL }; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 164 | private State mState = State.NORMAL; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 165 | private boolean mIsSwitchingState = false; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 166 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 167 | boolean mAnimatingViewIntoPlace = false; |
| 168 | boolean mIsDragOccuring = false; |
| 169 | boolean mChildrenLayersEnabled = true; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 170 | |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 171 | /** Is the user is dragging an item near the edge of a page? */ |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 172 | private boolean mInScrollArea = false; |
| 173 | |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 174 | private final HolographicOutlineHelper mOutlineHelper = new HolographicOutlineHelper(); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 175 | private Bitmap mDragOutline = null; |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 176 | private final Rect mTempRect = new Rect(); |
| 177 | private final int[] mTempXY = new int[2]; |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 178 | private float mOverscrollFade = 0; |
Michael Jurka | b06d95f | 2012-04-02 06:26:53 -0700 | [diff] [blame] | 179 | private boolean mOverscrollTransformsSet; |
Michael Jurka | f8304f0 | 2012-04-26 13:33:26 -0700 | [diff] [blame] | 180 | public static final int DRAG_BITMAP_PADDING = 2; |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 181 | private boolean mWorkspaceFadeInAdjacentScreens; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 182 | |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 183 | // Camera and Matrix used to determine the final position of a neighboring CellLayout |
| 184 | private final Matrix mMatrix = new Matrix(); |
| 185 | private final Camera mCamera = new Camera(); |
| 186 | private final float mTempFloat2[] = new float[2]; |
| 187 | |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 188 | enum WallpaperVerticalOffset { TOP, MIDDLE, BOTTOM }; |
| 189 | int mWallpaperWidth; |
| 190 | int mWallpaperHeight; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 191 | WallpaperOffsetInterpolator mWallpaperOffset; |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 192 | boolean mUpdateWallpaperOffsetImmediately = false; |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 193 | private Runnable mDelayedResizeRunnable; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 194 | private Runnable mDelayedSnapToPageRunnable; |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 195 | private Point mDisplaySize = new Point(); |
Michael Jurka | 9551537 | 2012-02-29 14:13:01 -0800 | [diff] [blame] | 196 | private boolean mIsStaticWallpaper; |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 197 | private int mWallpaperTravelWidth; |
Winson Chung | 8aad610 | 2012-05-11 16:27:49 -0700 | [diff] [blame] | 198 | private int mSpringLoadedPageSpacing; |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 199 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 200 | // Variables relating to the creation of user folders by hovering shortcuts over shortcuts |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 201 | private static final int FOLDER_CREATION_TIMEOUT = 0; |
| 202 | private static final int REORDER_TIMEOUT = 250; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 203 | private final Alarm mFolderCreationAlarm = new Alarm(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 204 | private final Alarm mReorderAlarm = new Alarm(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 205 | private FolderRingAnimator mDragFolderRingAnimator = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 206 | private FolderIcon mDragOverFolderIcon = null; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 207 | private boolean mCreateUserFolderOnDrop = false; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 208 | private boolean mAddToExistingFolderOnDrop = false; |
| 209 | private DropTarget.DragEnforcer mDragEnforcer; |
Adam Cohen | 3aff81c | 2012-05-16 21:01:01 -0700 | [diff] [blame] | 210 | private float mMaxDistanceForFolderCreation; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 211 | |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 212 | // Variables relating to touch disambiguation (scrolling workspace vs. scrolling a widget) |
| 213 | private float mXDown; |
| 214 | private float mYDown; |
| 215 | final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6; |
| 216 | final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3; |
| 217 | final static float TOUCH_SLOP_DAMPING_FACTOR = 4; |
| 218 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 219 | // Relating to the animation of items being dropped externally |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 220 | public static final int ANIMATE_INTO_POSITION_AND_DISAPPEAR = 0; |
| 221 | public static final int ANIMATE_INTO_POSITION_AND_REMAIN = 1; |
| 222 | public static final int ANIMATE_INTO_POSITION_AND_RESIZE = 2; |
| 223 | public static final int COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION = 3; |
| 224 | public static final int CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION = 4; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 225 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 226 | // Related to dragging, folder creation and reordering |
| 227 | private static final int DRAG_MODE_NONE = 0; |
| 228 | private static final int DRAG_MODE_CREATE_FOLDER = 1; |
| 229 | private static final int DRAG_MODE_ADD_TO_FOLDER = 2; |
| 230 | private static final int DRAG_MODE_REORDER = 3; |
| 231 | private int mDragMode = DRAG_MODE_NONE; |
| 232 | private int mLastReorderX = -1; |
| 233 | private int mLastReorderY = -1; |
| 234 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 235 | // These variables are used for storing the initial and final values during workspace animations |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 236 | private int mSavedScrollX; |
| 237 | private float mSavedRotationY; |
| 238 | private float mSavedTranslationX; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 239 | private float mCurrentScaleX; |
| 240 | private float mCurrentScaleY; |
| 241 | private float mCurrentRotationY; |
| 242 | private float mCurrentTranslationX; |
| 243 | private float mCurrentTranslationY; |
| 244 | private float[] mOldTranslationXs; |
| 245 | private float[] mOldTranslationYs; |
| 246 | private float[] mOldScaleXs; |
| 247 | private float[] mOldScaleYs; |
| 248 | private float[] mOldBackgroundAlphas; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 249 | private float[] mOldAlphas; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 250 | private float[] mNewTranslationXs; |
| 251 | private float[] mNewTranslationYs; |
| 252 | private float[] mNewScaleXs; |
| 253 | private float[] mNewScaleYs; |
| 254 | private float[] mNewBackgroundAlphas; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 255 | private float[] mNewAlphas; |
| 256 | private float[] mNewRotationYs; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 257 | private float mTransitionProgress; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 258 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 259 | /** |
| 260 | * Used to inflate the Workspace from XML. |
| 261 | * |
| 262 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 263 | * @param attrs The attributes set containing the Workspace's customization values. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 264 | */ |
| 265 | public Workspace(Context context, AttributeSet attrs) { |
| 266 | this(context, attrs, 0); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Used to inflate the Workspace from XML. |
| 271 | * |
| 272 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 273 | * @param attrs The attributes set containing the Workspace's customization values. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 274 | * @param defStyle Unused. |
| 275 | */ |
| 276 | public Workspace(Context context, AttributeSet attrs, int defStyle) { |
| 277 | super(context, attrs, defStyle); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 278 | mContentIsRefreshable = false; |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 279 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 280 | mDragEnforcer = new DropTarget.DragEnforcer(context); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 281 | // With workspace, data is available straight from the get-go |
| 282 | setDataIsReady(); |
| 283 | |
Winson Chung | 867ca62 | 2012-02-21 15:48:35 -0800 | [diff] [blame] | 284 | final Resources res = getResources(); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 285 | mWorkspaceFadeInAdjacentScreens = res.getBoolean(R.bool.config_workspaceFadeAdjacentScreens); |
| 286 | mFadeInAdjacentScreens = false; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 287 | mWallpaperManager = WallpaperManager.getInstance(context); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 288 | |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 289 | int cellCountX = DEFAULT_CELL_COUNT_X; |
| 290 | int cellCountY = DEFAULT_CELL_COUNT_Y; |
| 291 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 292 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 293 | R.styleable.Workspace, defStyle, 0); |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 294 | |
| 295 | if (LauncherApplication.isScreenLarge()) { |
Michael Jurka | f61249b | 2011-05-27 16:27:15 -0700 | [diff] [blame] | 296 | // Determine number of rows/columns dynamically |
| 297 | // TODO: This code currently fails on tablets with an aspect ratio < 1.3. |
| 298 | // Around that ratio we should make cells the same size in portrait and |
| 299 | // landscape |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 300 | TypedArray actionBarSizeTypedArray = |
| 301 | context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); |
Winson Chung | a61dc42 | 2012-02-14 14:45:18 -0800 | [diff] [blame] | 302 | DisplayMetrics displayMetrics = res.getDisplayMetrics(); |
Michael Jurka | f61249b | 2011-05-27 16:27:15 -0700 | [diff] [blame] | 303 | final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f); |
| 304 | final float systemBarHeight = res.getDimension(R.dimen.status_bar_height); |
Winson Chung | a61dc42 | 2012-02-14 14:45:18 -0800 | [diff] [blame] | 305 | final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp * |
| 306 | displayMetrics.density; |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 307 | |
Michael Jurka | f61249b | 2011-05-27 16:27:15 -0700 | [diff] [blame] | 308 | cellCountX = 1; |
| 309 | while (CellLayout.widthInPortrait(res, cellCountX + 1) <= smallestScreenDim) { |
| 310 | cellCountX++; |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 311 | } |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 312 | |
Michael Jurka | f61249b | 2011-05-27 16:27:15 -0700 | [diff] [blame] | 313 | cellCountY = 1; |
| 314 | while (actionBarHeight + CellLayout.heightInLandscape(res, cellCountY + 1) |
| 315 | <= smallestScreenDim - systemBarHeight) { |
| 316 | cellCountY++; |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 317 | } |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 320 | mSpringLoadedShrinkFactor = |
| 321 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; |
Winson Chung | 8aad610 | 2012-05-11 16:27:49 -0700 | [diff] [blame] | 322 | mSpringLoadedPageSpacing = |
| 323 | res.getDimensionPixelSize(R.dimen.workspace_spring_loaded_page_spacing); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 324 | |
Michael Jurka | f6440da | 2011-04-05 14:50:34 -0700 | [diff] [blame] | 325 | // if the value is manually specified, use that instead |
| 326 | cellCountX = a.getInt(R.styleable.Workspace_cellCountX, cellCountX); |
| 327 | cellCountY = a.getInt(R.styleable.Workspace_cellCountY, cellCountY); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 328 | mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 329 | a.recycle(); |
| 330 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 331 | setOnHierarchyChangeListener(this); |
| 332 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 333 | LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 334 | setHapticFeedbackEnabled(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 335 | |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 336 | mLauncher = (Launcher) context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 337 | initWorkspace(); |
Winson Chung | c35afb2 | 2011-02-23 13:01:49 -0800 | [diff] [blame] | 338 | |
| 339 | // Disable multitouch across the workspace/all apps/customize tray |
| 340 | setMotionEventSplittingEnabled(true); |
Svetoslav Ganov | 08055f6 | 2012-05-15 11:06:36 -0700 | [diff] [blame] | 341 | |
| 342 | // Unless otherwise specified this view is important for accessibility. |
| 343 | if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 344 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 345 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 348 | // estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each |
| 349 | // dimension if unsuccessful |
| 350 | public int[] estimateItemSize(int hSpan, int vSpan, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 351 | ItemInfo itemInfo, boolean springLoaded) { |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 352 | int[] size = new int[2]; |
| 353 | if (getChildCount() > 0) { |
| 354 | CellLayout cl = (CellLayout) mLauncher.getWorkspace().getChildAt(0); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 355 | Rect r = estimateItemPosition(cl, itemInfo, 0, 0, hSpan, vSpan); |
| 356 | size[0] = r.width(); |
| 357 | size[1] = r.height(); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 358 | if (springLoaded) { |
| 359 | size[0] *= mSpringLoadedShrinkFactor; |
| 360 | size[1] *= mSpringLoadedShrinkFactor; |
| 361 | } |
| 362 | return size; |
| 363 | } else { |
| 364 | size[0] = Integer.MAX_VALUE; |
| 365 | size[1] = Integer.MAX_VALUE; |
| 366 | return size; |
| 367 | } |
| 368 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 369 | public Rect estimateItemPosition(CellLayout cl, ItemInfo pendingInfo, |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 370 | int hCell, int vCell, int hSpan, int vSpan) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 371 | Rect r = new Rect(); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 372 | cl.cellToRect(hCell, vCell, hSpan, vSpan, r); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 373 | return r; |
| 374 | } |
| 375 | |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 376 | public void buildPageHardwareLayers() { |
| 377 | if (getWindowToken() != null) { |
| 378 | final int childCount = getChildCount(); |
| 379 | for (int i = 0; i < childCount; i++) { |
| 380 | CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 381 | cl.getShortcutsAndWidgets().buildLayer(); |
Michael Jurka | c1f5d26 | 2011-09-30 19:32:27 -0700 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 386 | public void onDragStart(DragSource source, Object info, int dragAction) { |
| 387 | mIsDragOccuring = true; |
| 388 | updateChildrenLayersEnabled(); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 389 | mLauncher.lockScreenOrientation(); |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 390 | setChildrenBackgroundAlphaMultipliers(1f); |
Winson Chung | f561bdf | 2012-05-03 11:20:19 -0700 | [diff] [blame] | 391 | // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging |
| 392 | InstallShortcutReceiver.enableInstallQueue(); |
| 393 | UninstallShortcutReceiver.enableUninstallQueue(); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | public void onDragEnd() { |
| 397 | mIsDragOccuring = false; |
| 398 | updateChildrenLayersEnabled(); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 399 | mLauncher.unlockScreenOrientation(false); |
Winson Chung | f561bdf | 2012-05-03 11:20:19 -0700 | [diff] [blame] | 400 | |
| 401 | // Re-enable any Un/InstallShortcutReceiver and now process any queued items |
| 402 | InstallShortcutReceiver.disableAndFlushInstallQueue(getContext()); |
| 403 | UninstallShortcutReceiver.disableAndFlushUninstallQueue(getContext()); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 404 | } |
| 405 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 406 | /** |
| 407 | * Initializes various states for this workspace. |
| 408 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 409 | protected void initWorkspace() { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 410 | Context context = getContext(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 411 | mCurrentPage = mDefaultPage; |
| 412 | Launcher.setScreen(mCurrentPage); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 413 | LauncherApplication app = (LauncherApplication)context.getApplicationContext(); |
| 414 | mIconCache = app.getIconCache(); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 415 | setWillNotDraw(false); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 416 | setChildrenDrawnWithCacheEnabled(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 417 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 418 | final Resources res = getResources(); |
Winson Chung | b4b7fa7 | 2010-11-18 14:38:53 -0800 | [diff] [blame] | 419 | try { |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 420 | mBackground = res.getDrawable(R.drawable.apps_customize_bg); |
Winson Chung | b4b7fa7 | 2010-11-18 14:38:53 -0800 | [diff] [blame] | 421 | } catch (Resources.NotFoundException e) { |
| 422 | // In this case, we will skip drawing background protection |
| 423 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 424 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 425 | mWallpaperOffset = new WallpaperOffsetInterpolator(); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 426 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 427 | display.getSize(mDisplaySize); |
| 428 | mWallpaperTravelWidth = (int) (mDisplaySize.x * |
| 429 | wallpaperTravelToScreenWidthRatio(mDisplaySize.x, mDisplaySize.y)); |
Adam Cohen | 265b9a6 | 2011-12-07 14:37:18 -0800 | [diff] [blame] | 430 | |
Adam Cohen | 3aff81c | 2012-05-16 21:01:01 -0700 | [diff] [blame] | 431 | mMaxDistanceForFolderCreation = (0.55f * res.getDimensionPixelSize(R.dimen.app_icon_size)); |
Adam Cohen | 265b9a6 | 2011-12-07 14:37:18 -0800 | [diff] [blame] | 432 | mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 433 | } |
| 434 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 435 | @Override |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 436 | protected int getScrollMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 437 | return SmoothPagedView.X_LARGE_MODE; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Michael Jurka | 08ee770 | 2011-08-11 16:53:35 -0700 | [diff] [blame] | 440 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 441 | public void onChildViewAdded(View parent, View child) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 442 | if (!(child instanceof CellLayout)) { |
| 443 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 444 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 445 | CellLayout cl = ((CellLayout) child); |
| 446 | cl.setOnInterceptTouchListener(this); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 447 | cl.setClickable(true); |
| 448 | cl.enableHardwareLayers(); |
alanv | 51944f1 | 2012-05-07 17:31:32 -0700 | [diff] [blame] | 449 | cl.setContentDescription(getContext().getString( |
| 450 | R.string.workspace_description_format, getChildCount())); |
Michael Jurka | e5fb0f2 | 2011-04-11 13:27:46 -0700 | [diff] [blame] | 451 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 452 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 453 | @Override |
| 454 | public void onChildViewRemoved(View parent, View child) { |
| 455 | } |
| 456 | |
Michael Jurka | 920d7f4 | 2012-05-14 16:29:55 -0700 | [diff] [blame] | 457 | protected boolean shouldDrawChild(View child) { |
| 458 | final CellLayout cl = (CellLayout) child; |
| 459 | return super.shouldDrawChild(child) && |
| 460 | (cl.getShortcutsAndWidgets().getAlpha() > 0 || |
| 461 | cl.getBackgroundAlpha() > 0); |
| 462 | } |
| 463 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 464 | /** |
| 465 | * @return The open folder on the current screen, or null if there is none |
| 466 | */ |
| 467 | Folder getOpenFolder() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 468 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 469 | int count = dragLayer.getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 470 | for (int i = 0; i < count; i++) { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 471 | View child = dragLayer.getChildAt(i); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 472 | if (child instanceof Folder) { |
| 473 | Folder folder = (Folder) child; |
| 474 | if (folder.getInfo().opened) |
| 475 | return folder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | return null; |
| 479 | } |
| 480 | |
Patrick Dubroy | a0aa012 | 2011-02-24 11:42:23 -0800 | [diff] [blame] | 481 | boolean isTouchActive() { |
| 482 | return mTouchState != TOUCH_STATE_REST; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 486 | * Adds the specified child in the specified screen. The position and dimension of |
| 487 | * the child are defined by x, y, spanX and spanY. |
| 488 | * |
| 489 | * @param child The child to add in one of the workspace's screens. |
| 490 | * @param screen The screen in which to add the child. |
| 491 | * @param x The X position of the child in the screen's grid. |
| 492 | * @param y The Y position of the child in the screen's grid. |
| 493 | * @param spanX The number of cells spanned horizontally by the child. |
| 494 | * @param spanY The number of cells spanned vertically by the child. |
| 495 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 496 | void addInScreen(View child, long container, int screen, int x, int y, int spanX, int spanY) { |
| 497 | addInScreen(child, container, screen, x, y, spanX, spanY, false); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 498 | } |
| 499 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 500 | /** |
| 501 | * Adds the specified child in the specified screen. The position and dimension of |
| 502 | * the child are defined by x, y, spanX and spanY. |
| 503 | * |
| 504 | * @param child The child to add in one of the workspace's screens. |
| 505 | * @param screen The screen in which to add the child. |
| 506 | * @param x The X position of the child in the screen's grid. |
| 507 | * @param y The Y position of the child in the screen's grid. |
| 508 | * @param spanX The number of cells spanned horizontally by the child. |
| 509 | * @param spanY The number of cells spanned vertically by the child. |
| 510 | * @param insert When true, the child is inserted at the beginning of the children list. |
| 511 | */ |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 512 | void addInScreen(View child, long container, int screen, int x, int y, int spanX, int spanY, |
| 513 | boolean insert) { |
| 514 | if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
| 515 | if (screen < 0 || screen >= getChildCount()) { |
| 516 | Log.e(TAG, "The screen must be >= 0 and < " + getChildCount() |
| 517 | + " (was " + screen + "); skipping child"); |
| 518 | return; |
| 519 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 522 | final CellLayout layout; |
| 523 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 524 | layout = mLauncher.getHotseat().getLayout(); |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 525 | child.setOnKeyListener(null); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 526 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 527 | // Hide folder title in the hotseat |
| 528 | if (child instanceof FolderIcon) { |
| 529 | ((FolderIcon) child).setTextVisible(false); |
| 530 | } |
| 531 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 532 | if (screen < 0) { |
| 533 | screen = mLauncher.getHotseat().getOrderInHotseat(x, y); |
| 534 | } else { |
| 535 | // Note: We do this to ensure that the hotseat is always laid out in the orientation |
| 536 | // of the hotseat in order regardless of which orientation they were added |
| 537 | x = mLauncher.getHotseat().getCellXFromOrder(screen); |
| 538 | y = mLauncher.getHotseat().getCellYFromOrder(screen); |
| 539 | } |
| 540 | } else { |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 541 | // Show folder title if not in the hotseat |
| 542 | if (child instanceof FolderIcon) { |
| 543 | ((FolderIcon) child).setTextVisible(true); |
| 544 | } |
| 545 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 546 | layout = (CellLayout) getChildAt(screen); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 547 | child.setOnKeyListener(new IconKeyEventListener()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 550 | LayoutParams genericLp = child.getLayoutParams(); |
| 551 | CellLayout.LayoutParams lp; |
| 552 | if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 553 | lp = new CellLayout.LayoutParams(x, y, spanX, spanY); |
| 554 | } else { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 555 | lp = (CellLayout.LayoutParams) genericLp; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 556 | lp.cellX = x; |
| 557 | lp.cellY = y; |
| 558 | lp.cellHSpan = spanX; |
| 559 | lp.cellVSpan = spanY; |
| 560 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 561 | |
Adam Cohen | 7f4eabe | 2011-04-21 16:19:16 -0700 | [diff] [blame] | 562 | if (spanX < 0 && spanY < 0) { |
| 563 | lp.isLockedToGrid = false; |
| 564 | } |
| 565 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 566 | // Get the canonical child id to uniquely represent this view in this screen |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 567 | int childId = LauncherModel.getCellLayoutChildId(container, screen, x, y, spanX, spanY); |
Michael Jurka | f3ca3ab | 2010-10-20 17:08:24 -0700 | [diff] [blame] | 568 | boolean markCellsAsOccupied = !(child instanceof Folder); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 569 | if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 570 | // TODO: This branch occurs when the workspace is adding views |
| 571 | // outside of the defined grid |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 572 | // maybe we should be deleting these items from the LauncherModel? |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 573 | Log.w(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout"); |
| 574 | } |
| 575 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 576 | if (!(child instanceof Folder)) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 577 | child.setHapticFeedbackEnabled(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 578 | child.setOnLongClickListener(mLongClickListener); |
| 579 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 580 | if (child instanceof DropTarget) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 581 | mDragController.addDropTarget((DropTarget) child); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 582 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Patrick Dubroy | d0ce1ec | 2011-01-19 18:47:27 -0800 | [diff] [blame] | 585 | /** |
| 586 | * Check if the point (x, y) hits a given page. |
| 587 | */ |
| 588 | private boolean hitsPage(int index, float x, float y) { |
| 589 | final View page = getChildAt(index); |
| 590 | if (page != null) { |
| 591 | float[] localXY = { x, y }; |
| 592 | mapPointFromSelfToChild(page, localXY); |
| 593 | return (localXY[0] >= 0 && localXY[0] < page.getWidth() |
| 594 | && localXY[1] >= 0 && localXY[1] < page.getHeight()); |
| 595 | } |
| 596 | return false; |
| 597 | } |
| 598 | |
| 599 | @Override |
| 600 | protected boolean hitsPreviousPage(float x, float y) { |
| 601 | // mNextPage is set to INVALID_PAGE whenever we are stationary. |
| 602 | // Calculating "next page" this way ensures that you scroll to whatever page you tap on |
| 603 | final int current = (mNextPage == INVALID_PAGE) ? mCurrentPage : mNextPage; |
Michael Jurka | b72094f | 2011-09-14 14:53:19 -0700 | [diff] [blame] | 604 | |
| 605 | // Only allow tap to next page on large devices, where there's significant margin outside |
| 606 | // the active workspace |
| 607 | return LauncherApplication.isScreenLarge() && hitsPage(current - 1, x, y); |
Patrick Dubroy | d0ce1ec | 2011-01-19 18:47:27 -0800 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | @Override |
| 611 | protected boolean hitsNextPage(float x, float y) { |
| 612 | // mNextPage is set to INVALID_PAGE whenever we are stationary. |
| 613 | // Calculating "next page" this way ensures that you scroll to whatever page you tap on |
| 614 | final int current = (mNextPage == INVALID_PAGE) ? mCurrentPage : mNextPage; |
Michael Jurka | b72094f | 2011-09-14 14:53:19 -0700 | [diff] [blame] | 615 | |
| 616 | // Only allow tap to next page on large devices, where there's significant margin outside |
| 617 | // the active workspace |
| 618 | return LauncherApplication.isScreenLarge() && hitsPage(current + 1, x, y); |
Patrick Dubroy | d0ce1ec | 2011-01-19 18:47:27 -0800 | [diff] [blame] | 619 | } |
| 620 | |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 621 | /** |
| 622 | * Called directly from a CellLayout (not by the framework), after we've been added as a |
| 623 | * listener via setOnInterceptTouchEventListener(). This allows us to tell the CellLayout |
| 624 | * that it should intercept touch events, which is not something that is normally supported. |
| 625 | */ |
| 626 | @Override |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 627 | public boolean onTouch(View v, MotionEvent event) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 628 | return (isSmall() || !isFinishedSwitchingState()); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 631 | public boolean isSwitchingState() { |
| 632 | return mIsSwitchingState; |
| 633 | } |
| 634 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 635 | /** This differs from isSwitchingState in that we take into account how far the transition |
| 636 | * has completed. */ |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 637 | public boolean isFinishedSwitchingState() { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 638 | return !mIsSwitchingState || (mTransitionProgress > 0.5f); |
| 639 | } |
| 640 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 641 | protected void onWindowVisibilityChanged (int visibility) { |
| 642 | mLauncher.onWindowVisibilityChanged(visibility); |
| 643 | } |
| 644 | |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 645 | @Override |
| 646 | public boolean dispatchUnhandledMove(View focused, int direction) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 647 | if (isSmall() || !isFinishedSwitchingState()) { |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 648 | // when the home screens are shrunken, shouldn't allow side-scrolling |
| 649 | return false; |
| 650 | } |
| 651 | return super.dispatchUnhandledMove(focused, direction); |
| 652 | } |
| 653 | |
| 654 | @Override |
| 655 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 656 | switch (ev.getAction() & MotionEvent.ACTION_MASK) { |
| 657 | case MotionEvent.ACTION_DOWN: |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 658 | mXDown = ev.getX(); |
| 659 | mYDown = ev.getY(); |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 660 | break; |
| 661 | case MotionEvent.ACTION_POINTER_UP: |
| 662 | case MotionEvent.ACTION_UP: |
| 663 | if (mTouchState == TOUCH_STATE_REST) { |
| 664 | final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage); |
| 665 | if (!currentPage.lastDownOnOccupiedCell()) { |
| 666 | onWallpaperTap(ev); |
| 667 | } |
| 668 | } |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 669 | } |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 670 | return super.onInterceptTouchEvent(ev); |
| 671 | } |
| 672 | |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 673 | @Override |
| 674 | protected void determineScrollingStart(MotionEvent ev) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 675 | if (isSmall()) return; |
| 676 | if (!isFinishedSwitchingState()) return; |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 677 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 678 | float deltaX = Math.abs(ev.getX() - mXDown); |
| 679 | float deltaY = Math.abs(ev.getY() - mYDown); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 680 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 681 | if (Float.compare(deltaX, 0f) == 0) return; |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 682 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 683 | float slope = deltaY / deltaX; |
| 684 | float theta = (float) Math.atan(slope); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 685 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 686 | if (deltaX > mTouchSlop || deltaY > mTouchSlop) { |
| 687 | cancelCurrentPageLongPress(); |
| 688 | } |
| 689 | |
| 690 | if (theta > MAX_SWIPE_ANGLE) { |
| 691 | // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace |
| 692 | return; |
| 693 | } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) { |
| 694 | // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to |
| 695 | // increase the touch slop to make it harder to begin scrolling the workspace. This |
| 696 | // results in vertically scrolling widgets to more easily. The higher the angle, the |
| 697 | // more we increase touch slop. |
| 698 | theta -= START_DAMPING_TOUCH_SLOP_ANGLE; |
| 699 | float extraRatio = (float) |
| 700 | Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE))); |
| 701 | super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio); |
| 702 | } else { |
| 703 | // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special |
| 704 | super.determineScrollingStart(ev); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 705 | } |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 708 | @Override |
| 709 | protected boolean isScrollingIndicatorEnabled() { |
Winson Chung | 4884647 | 2012-03-27 15:38:05 -0700 | [diff] [blame] | 710 | return super.isScrollingIndicatorEnabled() && (mState != State.SPRING_LOADED); |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 713 | protected void onPageBeginMoving() { |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 714 | super.onPageBeginMoving(); |
| 715 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 716 | if (isHardwareAccelerated()) { |
| 717 | updateChildrenLayersEnabled(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 718 | } else { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 719 | if (mNextPage != INVALID_PAGE) { |
| 720 | // we're snapping to a particular screen |
| 721 | enableChildrenCache(mCurrentPage, mNextPage); |
| 722 | } else { |
| 723 | // this is when user is actively dragging a particular screen, they might |
| 724 | // swipe it either left or right (but we won't advance by more than one screen) |
| 725 | enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1); |
| 726 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 727 | } |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 728 | |
| 729 | // Only show page outlines as we pan if we are on large screen |
| 730 | if (LauncherApplication.isScreenLarge()) { |
| 731 | showOutlines(); |
Michael Jurka | 9551537 | 2012-02-29 14:13:01 -0800 | [diff] [blame] | 732 | mIsStaticWallpaper = mWallpaperManager.getWallpaperInfo() == null; |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 733 | } |
Winson Chung | 1afedc3 | 2012-01-23 16:14:56 -0800 | [diff] [blame] | 734 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 735 | // If we are not fading in adjacent screens, we still need to restore the alpha in case the |
| 736 | // user scrolls while we are transitioning (should not affect dispatchDraw optimizations) |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 737 | if (!mWorkspaceFadeInAdjacentScreens) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 738 | for (int i = 0; i < getChildCount(); ++i) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 739 | ((CellLayout) getPageAt(i)).setShortcutAndWidgetAlpha(1f); |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
Winson Chung | 1afedc3 | 2012-01-23 16:14:56 -0800 | [diff] [blame] | 743 | // Show the scroll indicator as you pan the page |
| 744 | showScrollingIndicator(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 745 | } |
| 746 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 747 | protected void onPageEndMoving() { |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 748 | super.onPageEndMoving(); |
| 749 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 750 | if (isHardwareAccelerated()) { |
| 751 | updateChildrenLayersEnabled(); |
| 752 | } else { |
| 753 | clearChildrenCache(); |
| 754 | } |
| 755 | |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 756 | |
| 757 | if (mDragController.isDragging()) { |
| 758 | if (isSmall()) { |
| 759 | // If we are in springloaded mode, then force an event to check if the current touch |
| 760 | // is under a new page (to scroll to) |
| 761 | mDragController.forceMoveEvent(); |
| 762 | } |
| 763 | } else { |
| 764 | // If we are not mid-dragging, hide the page outlines if we are on a large screen |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 765 | if (LauncherApplication.isScreenLarge()) { |
| 766 | hideOutlines(); |
| 767 | } |
Winson Chung | 1afedc3 | 2012-01-23 16:14:56 -0800 | [diff] [blame] | 768 | |
| 769 | // Hide the scroll indicator as you pan the page |
| 770 | if (!mDragController.isDragging()) { |
| 771 | hideScrollingIndicator(false); |
| 772 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 773 | } |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 774 | mOverScrollMaxBackgroundAlpha = 0.0f; |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 775 | |
| 776 | if (mDelayedResizeRunnable != null) { |
| 777 | mDelayedResizeRunnable.run(); |
| 778 | mDelayedResizeRunnable = null; |
| 779 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 780 | |
| 781 | if (mDelayedSnapToPageRunnable != null) { |
| 782 | mDelayedSnapToPageRunnable.run(); |
| 783 | mDelayedSnapToPageRunnable = null; |
| 784 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Override |
| 788 | protected void notifyPageSwitchListener() { |
| 789 | super.notifyPageSwitchListener(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 790 | Launcher.setScreen(mCurrentPage); |
| 791 | }; |
| 792 | |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 793 | // As a ratio of screen height, the total distance we want the parallax effect to span |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 794 | // horizontally |
| 795 | private float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 796 | float aspectRatio = width / (float) height; |
| 797 | |
| 798 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 799 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 800 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 801 | // to span (ie travel) at any aspect ratio: |
| 802 | |
| 803 | final float ASPECT_RATIO_LANDSCAPE = 16/10f; |
| 804 | final float ASPECT_RATIO_PORTRAIT = 10/16f; |
| 805 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 806 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 807 | |
| 808 | // To find out the desired width at different aspect ratios, we use the following two |
| 809 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 810 | // (16/10)x + y = 1.5 |
| 811 | // (10/16)x + y = 1.2 |
| 812 | // We solve for x and y and end up with a final formula: |
| 813 | final float x = |
| 814 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
| 815 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 816 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 817 | return x * aspectRatio + y; |
| 818 | } |
| 819 | |
| 820 | // The range of scroll values for Workspace |
| 821 | private int getScrollRange() { |
| 822 | return getChildOffset(getChildCount() - 1) - getChildOffset(0); |
| 823 | } |
| 824 | |
| 825 | protected void setWallpaperDimension() { |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 826 | DisplayMetrics displayMetrics = new DisplayMetrics(); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 827 | mLauncher.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 828 | final int maxDim = Math.max(displayMetrics.widthPixels, displayMetrics.heightPixels); |
| 829 | final int minDim = Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 830 | |
| 831 | // We need to ensure that there is enough extra space in the wallpaper for the intended |
| 832 | // parallax effects |
Michael Jurka | a647180 | 2011-09-22 14:39:16 -0700 | [diff] [blame] | 833 | if (LauncherApplication.isScreenLarge()) { |
| 834 | mWallpaperWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim)); |
Michael Jurka | 193080b | 2011-10-28 16:08:53 -0700 | [diff] [blame] | 835 | mWallpaperHeight = maxDim; |
Michael Jurka | a647180 | 2011-09-22 14:39:16 -0700 | [diff] [blame] | 836 | } else { |
Michael Jurka | 1670698 | 2011-09-26 16:39:22 -0700 | [diff] [blame] | 837 | mWallpaperWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim); |
Michael Jurka | a647180 | 2011-09-22 14:39:16 -0700 | [diff] [blame] | 838 | mWallpaperHeight = maxDim; |
| 839 | } |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 840 | new Thread("setWallpaperDimension") { |
| 841 | public void run() { |
| 842 | mWallpaperManager.suggestDesiredDimensions(mWallpaperWidth, mWallpaperHeight); |
| 843 | } |
| 844 | }.start(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 847 | private float wallpaperOffsetForCurrentScroll() { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 848 | // Set wallpaper offset steps (1 / (number of screens - 1)) |
Michael Jurka | 193080b | 2011-10-28 16:08:53 -0700 | [diff] [blame] | 849 | mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 1.0f); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 850 | |
Michael Jurka | 193080b | 2011-10-28 16:08:53 -0700 | [diff] [blame] | 851 | // For the purposes of computing the scrollRange and overScrollOffset, we assume |
| 852 | // that mLayoutScale is 1. This means that when we're in spring-loaded mode, |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 853 | // there's no discrepancy between the wallpaper offset for a given page. |
| 854 | float layoutScale = mLayoutScale; |
| 855 | mLayoutScale = 1f; |
Michael Jurka | 09d6eb0 | 2011-01-28 16:05:09 -0800 | [diff] [blame] | 856 | int scrollRange = getScrollRange(); |
Michael Jurka | 09d6eb0 | 2011-01-28 16:05:09 -0800 | [diff] [blame] | 857 | |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 858 | // Again, we adjust the wallpaper offset to be consistent between values of mLayoutScale |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 859 | float adjustedScrollX = Math.max(0, Math.min(getScrollX(), mMaxScrollX)); |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 860 | adjustedScrollX *= mWallpaperScrollRatio; |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 861 | mLayoutScale = layoutScale; |
| 862 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 863 | float scrollProgress = |
Michael Jurka | 193080b | 2011-10-28 16:08:53 -0700 | [diff] [blame] | 864 | adjustedScrollX / (float) scrollRange; |
Michael Jurka | 9551537 | 2012-02-29 14:13:01 -0800 | [diff] [blame] | 865 | |
| 866 | if (LauncherApplication.isScreenLarge() && mIsStaticWallpaper) { |
| 867 | // The wallpaper travel width is how far, from left to right, the wallpaper will move |
| 868 | // at this orientation. On tablets in portrait mode we don't move all the way to the |
| 869 | // edges of the wallpaper, or otherwise the parallax effect would be too strong. |
| 870 | int wallpaperTravelWidth = Math.min(mWallpaperTravelWidth, mWallpaperWidth); |
| 871 | |
| 872 | float offsetInDips = wallpaperTravelWidth * scrollProgress + |
| 873 | (mWallpaperWidth - wallpaperTravelWidth) / 2; // center it |
| 874 | float offset = offsetInDips / (float) mWallpaperWidth; |
| 875 | return offset; |
| 876 | } else { |
| 877 | return scrollProgress; |
| 878 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 879 | } |
Michael Jurka | 9551537 | 2012-02-29 14:13:01 -0800 | [diff] [blame] | 880 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 881 | private void syncWallpaperOffsetWithScroll() { |
Winson Chung | b46a2d1 | 2011-04-22 14:13:05 -0700 | [diff] [blame] | 882 | final boolean enableWallpaperEffects = isHardwareAccelerated(); |
| 883 | if (enableWallpaperEffects) { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 884 | mWallpaperOffset.setFinalX(wallpaperOffsetForCurrentScroll()); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | public void updateWallpaperOffsetImmediately() { |
| 889 | mUpdateWallpaperOffsetImmediately = true; |
| 890 | } |
| 891 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 892 | private void updateWallpaperOffsets() { |
| 893 | boolean updateNow = false; |
| 894 | boolean keepUpdating = true; |
| 895 | if (mUpdateWallpaperOffsetImmediately) { |
| 896 | updateNow = true; |
| 897 | keepUpdating = false; |
| 898 | mWallpaperOffset.jumpToFinal(); |
| 899 | mUpdateWallpaperOffsetImmediately = false; |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 900 | } else { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 901 | updateNow = keepUpdating = mWallpaperOffset.computeScrollOffset(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 902 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 903 | if (updateNow) { |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 904 | if (mWindowToken != null) { |
| 905 | mWallpaperManager.setWallpaperOffsets(mWindowToken, |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 906 | mWallpaperOffset.getCurrX(), mWallpaperOffset.getCurrY()); |
| 907 | } |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 908 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 909 | if (keepUpdating) { |
Michael Jurka | 7372c59 | 2012-01-16 04:21:35 -0800 | [diff] [blame] | 910 | invalidate(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 911 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 912 | } |
| 913 | |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 914 | @Override |
| 915 | protected void updateCurrentPageScroll() { |
| 916 | super.updateCurrentPageScroll(); |
Adam Cohen | 5037a0b | 2011-09-01 13:10:40 -0700 | [diff] [blame] | 917 | computeWallpaperScrollRatio(mCurrentPage); |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | @Override |
| 921 | protected void snapToPage(int whichPage) { |
| 922 | super.snapToPage(whichPage); |
Adam Cohen | 5037a0b | 2011-09-01 13:10:40 -0700 | [diff] [blame] | 923 | computeWallpaperScrollRatio(whichPage); |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 924 | } |
| 925 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 926 | @Override |
| 927 | protected void snapToPage(int whichPage, int duration) { |
| 928 | super.snapToPage(whichPage, duration); |
| 929 | computeWallpaperScrollRatio(whichPage); |
| 930 | } |
| 931 | |
| 932 | protected void snapToPage(int whichPage, Runnable r) { |
| 933 | if (mDelayedSnapToPageRunnable != null) { |
| 934 | mDelayedSnapToPageRunnable.run(); |
| 935 | } |
| 936 | mDelayedSnapToPageRunnable = r; |
| 937 | snapToPage(whichPage, SLOW_PAGE_SNAP_ANIMATION_DURATION); |
| 938 | } |
| 939 | |
Adam Cohen | 5037a0b | 2011-09-01 13:10:40 -0700 | [diff] [blame] | 940 | private void computeWallpaperScrollRatio(int page) { |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 941 | // Here, we determine what the desired scroll would be with and without a layout scale, |
| 942 | // and compute a ratio between the two. This allows us to adjust the wallpaper offset |
| 943 | // as though there is no layout scale. |
| 944 | float layoutScale = mLayoutScale; |
Adam Cohen | 5037a0b | 2011-09-01 13:10:40 -0700 | [diff] [blame] | 945 | int scaled = getChildOffset(page) - getRelativeChildOffset(page); |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 946 | mLayoutScale = 1.0f; |
Adam Cohen | 5037a0b | 2011-09-01 13:10:40 -0700 | [diff] [blame] | 947 | float unscaled = getChildOffset(page) - getRelativeChildOffset(page); |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 948 | mLayoutScale = layoutScale; |
| 949 | if (scaled > 0) { |
| 950 | mWallpaperScrollRatio = (1.0f * unscaled) / scaled; |
| 951 | } else { |
| 952 | mWallpaperScrollRatio = 1f; |
| 953 | } |
| 954 | } |
| 955 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 956 | class WallpaperOffsetInterpolator { |
| 957 | float mFinalHorizontalWallpaperOffset = 0.0f; |
| 958 | float mFinalVerticalWallpaperOffset = 0.5f; |
| 959 | float mHorizontalWallpaperOffset = 0.0f; |
| 960 | float mVerticalWallpaperOffset = 0.5f; |
| 961 | long mLastWallpaperOffsetUpdateTime; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 962 | boolean mIsMovingFast; |
| 963 | boolean mOverrideHorizontalCatchupConstant; |
| 964 | float mHorizontalCatchupConstant = 0.35f; |
| 965 | float mVerticalCatchupConstant = 0.35f; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 966 | |
| 967 | public WallpaperOffsetInterpolator() { |
| 968 | } |
| 969 | |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 970 | public void setOverrideHorizontalCatchupConstant(boolean override) { |
| 971 | mOverrideHorizontalCatchupConstant = override; |
| 972 | } |
| 973 | |
| 974 | public void setHorizontalCatchupConstant(float f) { |
| 975 | mHorizontalCatchupConstant = f; |
| 976 | } |
| 977 | |
| 978 | public void setVerticalCatchupConstant(float f) { |
| 979 | mVerticalCatchupConstant = f; |
| 980 | } |
| 981 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 982 | public boolean computeScrollOffset() { |
| 983 | if (Float.compare(mHorizontalWallpaperOffset, mFinalHorizontalWallpaperOffset) == 0 && |
| 984 | Float.compare(mVerticalWallpaperOffset, mFinalVerticalWallpaperOffset) == 0) { |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 985 | mIsMovingFast = false; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 986 | return false; |
| 987 | } |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 988 | boolean isLandscape = mDisplaySize.x > mDisplaySize.y; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 989 | |
| 990 | long currentTime = System.currentTimeMillis(); |
| 991 | long timeSinceLastUpdate = currentTime - mLastWallpaperOffsetUpdateTime; |
| 992 | timeSinceLastUpdate = Math.min((long) (1000/30f), timeSinceLastUpdate); |
| 993 | timeSinceLastUpdate = Math.max(1L, timeSinceLastUpdate); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 994 | |
| 995 | float xdiff = Math.abs(mFinalHorizontalWallpaperOffset - mHorizontalWallpaperOffset); |
| 996 | if (!mIsMovingFast && xdiff > 0.07) { |
| 997 | mIsMovingFast = true; |
| 998 | } |
| 999 | |
| 1000 | float fractionToCatchUpIn1MsHorizontal; |
| 1001 | if (mOverrideHorizontalCatchupConstant) { |
| 1002 | fractionToCatchUpIn1MsHorizontal = mHorizontalCatchupConstant; |
| 1003 | } else if (mIsMovingFast) { |
| 1004 | fractionToCatchUpIn1MsHorizontal = isLandscape ? 0.5f : 0.75f; |
| 1005 | } else { |
| 1006 | // slow |
| 1007 | fractionToCatchUpIn1MsHorizontal = isLandscape ? 0.27f : 0.5f; |
| 1008 | } |
| 1009 | float fractionToCatchUpIn1MsVertical = mVerticalCatchupConstant; |
| 1010 | |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1011 | fractionToCatchUpIn1MsHorizontal /= 33f; |
| 1012 | fractionToCatchUpIn1MsVertical /= 33f; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1013 | |
| 1014 | final float UPDATE_THRESHOLD = 0.00001f; |
| 1015 | float hOffsetDelta = mFinalHorizontalWallpaperOffset - mHorizontalWallpaperOffset; |
| 1016 | float vOffsetDelta = mFinalVerticalWallpaperOffset - mVerticalWallpaperOffset; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1017 | boolean jumpToFinalValue = Math.abs(hOffsetDelta) < UPDATE_THRESHOLD && |
| 1018 | Math.abs(vOffsetDelta) < UPDATE_THRESHOLD; |
Michael Jurka | a647180 | 2011-09-22 14:39:16 -0700 | [diff] [blame] | 1019 | |
| 1020 | // Don't have any lag between workspace and wallpaper on non-large devices |
| 1021 | if (!LauncherApplication.isScreenLarge() || jumpToFinalValue) { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1022 | mHorizontalWallpaperOffset = mFinalHorizontalWallpaperOffset; |
| 1023 | mVerticalWallpaperOffset = mFinalVerticalWallpaperOffset; |
| 1024 | } else { |
| 1025 | float percentToCatchUpVertical = |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1026 | Math.min(1.0f, timeSinceLastUpdate * fractionToCatchUpIn1MsVertical); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1027 | float percentToCatchUpHorizontal = |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1028 | Math.min(1.0f, timeSinceLastUpdate * fractionToCatchUpIn1MsHorizontal); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1029 | mHorizontalWallpaperOffset += percentToCatchUpHorizontal * hOffsetDelta; |
| 1030 | mVerticalWallpaperOffset += percentToCatchUpVertical * vOffsetDelta; |
| 1031 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1032 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1033 | mLastWallpaperOffsetUpdateTime = System.currentTimeMillis(); |
| 1034 | return true; |
| 1035 | } |
| 1036 | |
| 1037 | public float getCurrX() { |
| 1038 | return mHorizontalWallpaperOffset; |
| 1039 | } |
| 1040 | |
| 1041 | public float getFinalX() { |
| 1042 | return mFinalHorizontalWallpaperOffset; |
| 1043 | } |
| 1044 | |
| 1045 | public float getCurrY() { |
| 1046 | return mVerticalWallpaperOffset; |
| 1047 | } |
| 1048 | |
| 1049 | public float getFinalY() { |
| 1050 | return mFinalVerticalWallpaperOffset; |
| 1051 | } |
| 1052 | |
| 1053 | public void setFinalX(float x) { |
| 1054 | mFinalHorizontalWallpaperOffset = Math.max(0f, Math.min(x, 1.0f)); |
| 1055 | } |
| 1056 | |
| 1057 | public void setFinalY(float y) { |
| 1058 | mFinalVerticalWallpaperOffset = Math.max(0f, Math.min(y, 1.0f)); |
| 1059 | } |
| 1060 | |
| 1061 | public void jumpToFinal() { |
| 1062 | mHorizontalWallpaperOffset = mFinalHorizontalWallpaperOffset; |
| 1063 | mVerticalWallpaperOffset = mFinalVerticalWallpaperOffset; |
| 1064 | } |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 1065 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1066 | |
Michael Jurka | 340c5f3 | 2010-10-21 16:49:19 -0700 | [diff] [blame] | 1067 | @Override |
| 1068 | public void computeScroll() { |
| 1069 | super.computeScroll(); |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 1070 | syncWallpaperOffsetWithScroll(); |
Michael Jurka | 340c5f3 | 2010-10-21 16:49:19 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1073 | void showOutlines() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1074 | if (!isSmall() && !mIsSwitchingState) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1075 | if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel(); |
| 1076 | if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel(); |
| 1077 | mChildrenOutlineFadeInAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 1.0f); |
| 1078 | mChildrenOutlineFadeInAnimation.setDuration(CHILDREN_OUTLINE_FADE_IN_DURATION); |
| 1079 | mChildrenOutlineFadeInAnimation.start(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1080 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1083 | void hideOutlines() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1084 | if (!isSmall() && !mIsSwitchingState) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1085 | if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel(); |
| 1086 | if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel(); |
| 1087 | mChildrenOutlineFadeOutAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 0.0f); |
| 1088 | mChildrenOutlineFadeOutAnimation.setDuration(CHILDREN_OUTLINE_FADE_OUT_DURATION); |
| 1089 | mChildrenOutlineFadeOutAnimation.setStartDelay(CHILDREN_OUTLINE_FADE_OUT_DELAY); |
| 1090 | mChildrenOutlineFadeOutAnimation.start(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1091 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1094 | public void showOutlinesTemporarily() { |
| 1095 | if (!mIsPageMoving && !isTouchActive()) { |
| 1096 | snapToPage(mCurrentPage); |
| 1097 | } |
| 1098 | } |
| 1099 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1100 | public void setChildrenOutlineAlpha(float alpha) { |
| 1101 | mChildrenOutlineAlpha = alpha; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1102 | for (int i = 0; i < getChildCount(); i++) { |
| 1103 | CellLayout cl = (CellLayout) getChildAt(i); |
| 1104 | cl.setBackgroundAlpha(alpha); |
| 1105 | } |
| 1106 | } |
| 1107 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1108 | public float getChildrenOutlineAlpha() { |
| 1109 | return mChildrenOutlineAlpha; |
| 1110 | } |
| 1111 | |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1112 | void disableBackground() { |
| 1113 | mDrawBackground = false; |
| 1114 | } |
| 1115 | void enableBackground() { |
| 1116 | mDrawBackground = true; |
| 1117 | } |
| 1118 | |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1119 | private void animateBackgroundGradient(float finalAlpha, boolean animated) { |
Winson Chung | b4b7fa7 | 2010-11-18 14:38:53 -0800 | [diff] [blame] | 1120 | if (mBackground == null) return; |
Michael Jurka | b9e1497 | 2011-07-25 17:57:40 -0700 | [diff] [blame] | 1121 | if (mBackgroundFadeInAnimation != null) { |
| 1122 | mBackgroundFadeInAnimation.cancel(); |
| 1123 | mBackgroundFadeInAnimation = null; |
| 1124 | } |
| 1125 | if (mBackgroundFadeOutAnimation != null) { |
| 1126 | mBackgroundFadeOutAnimation.cancel(); |
| 1127 | mBackgroundFadeOutAnimation = null; |
| 1128 | } |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1129 | float startAlpha = getBackgroundAlpha(); |
| 1130 | if (finalAlpha != startAlpha) { |
| 1131 | if (animated) { |
| 1132 | mBackgroundFadeOutAnimation = ValueAnimator.ofFloat(startAlpha, finalAlpha); |
| 1133 | mBackgroundFadeOutAnimation.addUpdateListener(new AnimatorUpdateListener() { |
| 1134 | public void onAnimationUpdate(ValueAnimator animation) { |
| 1135 | setBackgroundAlpha(((Float) animation.getAnimatedValue()).floatValue()); |
| 1136 | } |
| 1137 | }); |
| 1138 | mBackgroundFadeOutAnimation.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 1139 | mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION); |
| 1140 | mBackgroundFadeOutAnimation.start(); |
| 1141 | } else { |
| 1142 | setBackgroundAlpha(finalAlpha); |
| 1143 | } |
Michael Jurka | b9e1497 | 2011-07-25 17:57:40 -0700 | [diff] [blame] | 1144 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | public void setBackgroundAlpha(float alpha) { |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1148 | if (alpha != mBackgroundAlpha) { |
| 1149 | mBackgroundAlpha = alpha; |
| 1150 | invalidate(); |
| 1151 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1152 | } |
| 1153 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1154 | public float getBackgroundAlpha() { |
| 1155 | return mBackgroundAlpha; |
| 1156 | } |
| 1157 | |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1158 | /** |
| 1159 | * Due to 3D transformations, if two CellLayouts are theoretically touching each other, |
| 1160 | * on the xy plane, when one is rotated along the y-axis, the gap between them is perceived |
| 1161 | * as being larger. This method computes what offset the rotated view should be translated |
| 1162 | * in order to minimize this perceived gap. |
| 1163 | * @param degrees Angle of the view |
| 1164 | * @param width Width of the view |
| 1165 | * @param height Height of the view |
| 1166 | * @return Offset to be used in a View.setTranslationX() call |
| 1167 | */ |
| 1168 | private float getOffsetXForRotation(float degrees, int width, int height) { |
| 1169 | mMatrix.reset(); |
| 1170 | mCamera.save(); |
| 1171 | mCamera.rotateY(Math.abs(degrees)); |
| 1172 | mCamera.getMatrix(mMatrix); |
| 1173 | mCamera.restore(); |
| 1174 | |
| 1175 | mMatrix.preTranslate(-width * 0.5f, -height * 0.5f); |
| 1176 | mMatrix.postTranslate(width * 0.5f, height * 0.5f); |
| 1177 | mTempFloat2[0] = width; |
| 1178 | mTempFloat2[1] = height; |
| 1179 | mMatrix.mapPoints(mTempFloat2); |
| 1180 | return (width - mTempFloat2[0]) * (degrees > 0.0f ? 1.0f : -1.0f); |
| 1181 | } |
| 1182 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1183 | float backgroundAlphaInterpolator(float r) { |
| 1184 | float pivotA = 0.1f; |
| 1185 | float pivotB = 0.4f; |
| 1186 | if (r < pivotA) { |
| 1187 | return 0; |
| 1188 | } else if (r > pivotB) { |
| 1189 | return 1.0f; |
| 1190 | } else { |
| 1191 | return (r - pivotA)/(pivotB - pivotA); |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | float overScrollBackgroundAlphaInterpolator(float r) { |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 1196 | float threshold = 0.08f; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1197 | |
| 1198 | if (r > mOverScrollMaxBackgroundAlpha) { |
| 1199 | mOverScrollMaxBackgroundAlpha = r; |
| 1200 | } else if (r < mOverScrollMaxBackgroundAlpha) { |
| 1201 | r = mOverScrollMaxBackgroundAlpha; |
| 1202 | } |
| 1203 | |
| 1204 | return Math.min(r / threshold, 1.0f); |
| 1205 | } |
| 1206 | |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1207 | private void updatePageAlphaValues(int screenCenter) { |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1208 | boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX; |
| 1209 | if (mWorkspaceFadeInAdjacentScreens && |
| 1210 | mState == State.NORMAL && |
| 1211 | !mIsSwitchingState && |
| 1212 | !isInOverscroll) { |
| 1213 | for (int i = 0; i < getChildCount(); i++) { |
| 1214 | CellLayout child = (CellLayout) getChildAt(i); |
| 1215 | if (child != null) { |
| 1216 | float scrollProgress = getScrollProgress(screenCenter, child, i); |
Adam Cohen | 7389496 | 2011-10-31 13:17:17 -0700 | [diff] [blame] | 1217 | float alpha = 1 - Math.abs(scrollProgress); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1218 | child.getShortcutsAndWidgets().setAlpha(alpha); |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1219 | if (!mIsDragOccuring) { |
| 1220 | child.setBackgroundAlphaMultiplier( |
| 1221 | backgroundAlphaInterpolator(Math.abs(scrollProgress))); |
| 1222 | } else { |
| 1223 | child.setBackgroundAlphaMultiplier(1f); |
| 1224 | } |
Adam Cohen | 7389496 | 2011-10-31 13:17:17 -0700 | [diff] [blame] | 1225 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1226 | } |
| 1227 | } |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | private void setChildrenBackgroundAlphaMultipliers(float a) { |
| 1231 | for (int i = 0; i < getChildCount(); i++) { |
| 1232 | CellLayout child = (CellLayout) getChildAt(i); |
| 1233 | child.setBackgroundAlphaMultiplier(a); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | @Override |
| 1238 | protected void screenScrolled(int screenCenter) { |
| 1239 | super.screenScrolled(screenCenter); |
| 1240 | |
| 1241 | updatePageAlphaValues(screenCenter); |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1242 | |
Adam Cohen | ebea84d | 2011-11-09 17:20:41 -0800 | [diff] [blame] | 1243 | if (mOverScrollX < 0 || mOverScrollX > mMaxScrollX) { |
| 1244 | int index = mOverScrollX < 0 ? 0 : getChildCount() - 1; |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1245 | CellLayout cl = (CellLayout) getChildAt(index); |
| 1246 | float scrollProgress = getScrollProgress(screenCenter, cl, index); |
| 1247 | cl.setOverScrollAmount(Math.abs(scrollProgress), index == 0); |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1248 | float rotation = - WORKSPACE_OVERSCROLL_ROTATION * scrollProgress; |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1249 | cl.setRotationY(rotation); |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 1250 | setFadeForOverScroll(Math.abs(scrollProgress)); |
Michael Jurka | b06d95f | 2012-04-02 06:26:53 -0700 | [diff] [blame] | 1251 | if (!mOverscrollTransformsSet) { |
| 1252 | mOverscrollTransformsSet = true; |
| 1253 | cl.setCameraDistance(mDensity * CAMERA_DISTANCE); |
| 1254 | cl.setPivotX(cl.getMeasuredWidth() * (index == 0 ? 0.75f : 0.25f)); |
| 1255 | cl.setPivotY(cl.getMeasuredHeight() * 0.5f); |
| 1256 | cl.setOverscrollTransformsDirty(true); |
| 1257 | } |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1258 | } else { |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 1259 | if (mOverscrollFade != 0) { |
| 1260 | setFadeForOverScroll(0); |
| 1261 | } |
Michael Jurka | b06d95f | 2012-04-02 06:26:53 -0700 | [diff] [blame] | 1262 | if (mOverscrollTransformsSet) { |
| 1263 | mOverscrollTransformsSet = false; |
Adam Cohen | ebea84d | 2011-11-09 17:20:41 -0800 | [diff] [blame] | 1264 | ((CellLayout) getChildAt(0)).resetOverscrollTransforms(); |
| 1265 | ((CellLayout) getChildAt(getChildCount() - 1)).resetOverscrollTransforms(); |
Adam Cohen | 7842d7f | 2011-09-12 15:28:15 -0700 | [diff] [blame] | 1266 | } |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | @Override |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1271 | protected void overScroll(float amount) { |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1272 | acceleratedOverScroll(amount); |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1275 | protected void onAttachedToWindow() { |
| 1276 | super.onAttachedToWindow(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1277 | mWindowToken = getWindowToken(); |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 1278 | computeScroll(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1279 | mDragController.setWindowToken(mWindowToken); |
| 1280 | } |
| 1281 | |
| 1282 | protected void onDetachedFromWindow() { |
| 1283 | mWindowToken = null; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1286 | @Override |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 1287 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 1288 | if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) { |
| 1289 | mUpdateWallpaperOffsetImmediately = true; |
| 1290 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1291 | super.onLayout(changed, left, top, right, bottom); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | @Override |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1295 | protected void onDraw(Canvas canvas) { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1296 | updateWallpaperOffsets(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 1297 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1298 | // Draw the background gradient if necessary |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1299 | if (mBackground != null && mBackgroundAlpha > 0.0f && mDrawBackground) { |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1300 | int alpha = (int) (mBackgroundAlpha * 255); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1301 | mBackground.setAlpha(alpha); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 1302 | mBackground.setBounds(getScrollX(), 0, getScrollX() + getMeasuredWidth(), |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1303 | getMeasuredHeight()); |
| 1304 | mBackground.draw(canvas); |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1305 | } |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 1306 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1307 | super.onDraw(canvas); |
| 1308 | } |
| 1309 | |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 1310 | boolean isDrawingBackgroundGradient() { |
| 1311 | return (mBackground != null && mBackgroundAlpha > 0.0f && mDrawBackground); |
| 1312 | } |
| 1313 | |
Michael Jurka | dfab7f0 | 2011-11-18 13:01:04 -0800 | [diff] [blame] | 1314 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1315 | protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 1316 | if (!mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1317 | final Folder openFolder = getOpenFolder(); |
| 1318 | if (openFolder != null) { |
| 1319 | return openFolder.requestFocus(direction, previouslyFocusedRect); |
| 1320 | } else { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1321 | return super.onRequestFocusInDescendants(direction, previouslyFocusedRect); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | return false; |
| 1325 | } |
| 1326 | |
| 1327 | @Override |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1328 | public int getDescendantFocusability() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1329 | if (isSmall()) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1330 | return ViewGroup.FOCUS_BLOCK_DESCENDANTS; |
| 1331 | } |
| 1332 | return super.getDescendantFocusability(); |
| 1333 | } |
| 1334 | |
| 1335 | @Override |
Romain Guy | c2e24c0 | 2009-06-01 16:11:41 -0700 | [diff] [blame] | 1336 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 1337 | if (!mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1338 | final Folder openFolder = getOpenFolder(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1339 | if (openFolder != null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1340 | openFolder.addFocusables(views, direction); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1341 | } else { |
| 1342 | super.addFocusables(views, direction, focusableMode); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | } |
| 1346 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1347 | public boolean isSmall() { |
Adam Cohen | 3384c7b | 2011-07-17 15:48:21 -0700 | [diff] [blame] | 1348 | return mState == State.SMALL || mState == State.SPRING_LOADED; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1351 | void enableChildrenCache(int fromPage, int toPage) { |
| 1352 | if (fromPage > toPage) { |
| 1353 | final int temp = fromPage; |
| 1354 | fromPage = toPage; |
| 1355 | toPage = temp; |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 1356 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1357 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1358 | final int screenCount = getChildCount(); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1359 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1360 | fromPage = Math.max(fromPage, 0); |
| 1361 | toPage = Math.min(toPage, screenCount - 1); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1362 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1363 | for (int i = fromPage; i <= toPage; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1364 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1365 | layout.setChildrenDrawnWithCacheEnabled(true); |
| 1366 | layout.setChildrenDrawingCacheEnabled(true); |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | void clearChildrenCache() { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1371 | final int screenCount = getChildCount(); |
| 1372 | for (int i = 0; i < screenCount; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1373 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1374 | layout.setChildrenDrawnWithCacheEnabled(false); |
Adam Cohen | 8182e5b | 2011-08-01 15:43:31 -0700 | [diff] [blame] | 1375 | // In software mode, we don't want the items to continue to be drawn into bitmaps |
| 1376 | if (!isHardwareAccelerated()) { |
| 1377 | layout.setChildrenDrawingCacheEnabled(false); |
| 1378 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1382 | private void updateChildrenLayersEnabled() { |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 1383 | boolean small = mState == State.SMALL || mIsSwitchingState; |
| 1384 | boolean enableChildrenLayers = small || mAnimatingViewIntoPlace || isPageMoving(); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1385 | |
| 1386 | if (enableChildrenLayers != mChildrenLayersEnabled) { |
| 1387 | mChildrenLayersEnabled = enableChildrenLayers; |
Michael Jurka | 80c6985 | 2011-12-16 14:16:32 -0800 | [diff] [blame] | 1388 | for (int i = 0; i < getPageCount(); i++) { |
| 1389 | ((ViewGroup)getChildAt(i)).setChildrenLayersEnabled(mChildrenLayersEnabled); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1390 | } |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1391 | } |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
Jeff Brown | 1d0867c | 2010-12-02 18:27:39 -0800 | [diff] [blame] | 1394 | protected void onWallpaperTap(MotionEvent ev) { |
| 1395 | final int[] position = mTempCell; |
| 1396 | getLocationOnScreen(position); |
| 1397 | |
| 1398 | int pointerIndex = ev.getActionIndex(); |
| 1399 | position[0] += (int) ev.getX(pointerIndex); |
| 1400 | position[1] += (int) ev.getY(pointerIndex); |
| 1401 | |
| 1402 | mWallpaperManager.sendWallpaperCommand(getWindowToken(), |
| 1403 | ev.getAction() == MotionEvent.ACTION_UP |
| 1404 | ? WallpaperManager.COMMAND_TAP : WallpaperManager.COMMAND_SECONDARY_TAP, |
| 1405 | position[0], position[1], 0, null); |
| 1406 | } |
| 1407 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1408 | /* |
| 1409 | * This interpolator emulates the rate at which the perceived scale of an object changes |
| 1410 | * as its distance from a camera increases. When this interpolator is applied to a scale |
| 1411 | * animation on a view, it evokes the sense that the object is shrinking due to moving away |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 1412 | * from the camera. |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1413 | */ |
| 1414 | static class ZInterpolator implements TimeInterpolator { |
| 1415 | private float focalLength; |
| 1416 | |
| 1417 | public ZInterpolator(float foc) { |
| 1418 | focalLength = foc; |
| 1419 | } |
| 1420 | |
Adam Cohen | eed565d | 2010-11-15 11:30:05 -0800 | [diff] [blame] | 1421 | public float getInterpolation(float input) { |
| 1422 | return (1.0f - focalLength / (focalLength + input)) / |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1423 | (1.0f - focalLength / (focalLength + 1.0f)); |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1424 | } |
| 1425 | } |
| 1426 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1427 | /* |
| 1428 | * The exact reverse of ZInterpolator. |
| 1429 | */ |
| 1430 | static class InverseZInterpolator implements TimeInterpolator { |
| 1431 | private ZInterpolator zInterpolator; |
| 1432 | public InverseZInterpolator(float foc) { |
| 1433 | zInterpolator = new ZInterpolator(foc); |
| 1434 | } |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1435 | public float getInterpolation(float input) { |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1436 | return 1 - zInterpolator.getInterpolation(1 - input); |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1437 | } |
| 1438 | } |
| 1439 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1440 | /* |
| 1441 | * ZInterpolator compounded with an ease-out. |
| 1442 | */ |
| 1443 | static class ZoomOutInterpolator implements TimeInterpolator { |
Adam Cohen | b64d36e | 2011-10-17 21:48:02 -0700 | [diff] [blame] | 1444 | private final DecelerateInterpolator decelerate = new DecelerateInterpolator(0.75f); |
| 1445 | private final ZInterpolator zInterpolator = new ZInterpolator(0.13f); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1446 | |
| 1447 | public float getInterpolation(float input) { |
| 1448 | return decelerate.getInterpolation(zInterpolator.getInterpolation(input)); |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | /* |
| 1453 | * InvereZInterpolator compounded with an ease-out. |
| 1454 | */ |
| 1455 | static class ZoomInInterpolator implements TimeInterpolator { |
| 1456 | private final InverseZInterpolator inverseZInterpolator = new InverseZInterpolator(0.35f); |
| 1457 | private final DecelerateInterpolator decelerate = new DecelerateInterpolator(3.0f); |
| 1458 | |
| 1459 | public float getInterpolation(float input) { |
| 1460 | return decelerate.getInterpolation(inverseZInterpolator.getInterpolation(input)); |
| 1461 | } |
| 1462 | } |
| 1463 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1464 | private final ZoomInInterpolator mZoomInInterpolator = new ZoomInInterpolator(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1465 | |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1466 | /* |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 1467 | * |
| 1468 | * We call these methods (onDragStartedWithItemSpans/onDragStartedWithSize) whenever we |
| 1469 | * start a drag in Launcher, regardless of whether the drag has ever entered the Workspace |
| 1470 | * |
| 1471 | * These methods mark the appropriate pages as accepting drops (which alters their visual |
| 1472 | * appearance). |
| 1473 | * |
| 1474 | */ |
| 1475 | public void onDragStartedWithItem(View v) { |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 1476 | final Canvas canvas = new Canvas(); |
| 1477 | |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 1478 | // The outline is used to visualize where the item will land if dropped |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1479 | mDragOutline = createDragOutline(v, canvas, DRAG_BITMAP_PADDING); |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 1482 | public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, Paint alphaClipPaint) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1483 | final Canvas canvas = new Canvas(); |
| 1484 | |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 1485 | int[] size = estimateItemSize(info.spanX, info.spanY, info, false); |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 1486 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1487 | // The outline is used to visualize where the item will land if dropped |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1488 | mDragOutline = createDragOutline(b, canvas, DRAG_BITMAP_PADDING, size[0], |
| 1489 | size[1], alphaClipPaint); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1492 | public void exitWidgetResizeMode() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 1493 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 1494 | dragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1495 | } |
| 1496 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 1497 | private void initAnimationArrays() { |
| 1498 | final int childCount = getChildCount(); |
| 1499 | if (mOldTranslationXs != null) return; |
| 1500 | mOldTranslationXs = new float[childCount]; |
| 1501 | mOldTranslationYs = new float[childCount]; |
| 1502 | mOldScaleXs = new float[childCount]; |
| 1503 | mOldScaleYs = new float[childCount]; |
| 1504 | mOldBackgroundAlphas = new float[childCount]; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 1505 | mOldAlphas = new float[childCount]; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 1506 | mNewTranslationXs = new float[childCount]; |
| 1507 | mNewTranslationYs = new float[childCount]; |
| 1508 | mNewScaleXs = new float[childCount]; |
| 1509 | mNewScaleYs = new float[childCount]; |
| 1510 | mNewBackgroundAlphas = new float[childCount]; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 1511 | mNewAlphas = new float[childCount]; |
| 1512 | mNewRotationYs = new float[childCount]; |
| 1513 | } |
| 1514 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1515 | Animator getChangeStateAnimation(final State state, boolean animated) { |
| 1516 | return getChangeStateAnimation(state, animated, 0); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1519 | Animator getChangeStateAnimation(final State state, boolean animated, int delay) { |
Michael Jurka | bdf7855 | 2011-10-31 14:34:25 -0700 | [diff] [blame] | 1520 | if (mState == state) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1521 | return null; |
Michael Jurka | 99633da | 2011-07-27 22:40:17 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1524 | // Initialize animation arrays for the first time if necessary |
| 1525 | initAnimationArrays(); |
| 1526 | |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1527 | AnimatorSet anim = animated ? new AnimatorSet() : null; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1528 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1529 | // Stop any scrolling, move to the current page right away |
Winson Chung | 360e63f | 2012-04-27 13:48:05 -0700 | [diff] [blame] | 1530 | setCurrentPage(getNextPage()); |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 1531 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1532 | final State oldState = mState; |
| 1533 | final boolean oldStateIsNormal = (oldState == State.NORMAL); |
Michael Jurka | 4ff7d79 | 2012-04-02 03:46:50 -0700 | [diff] [blame] | 1534 | final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1535 | final boolean oldStateIsSmall = (oldState == State.SMALL); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1536 | mState = state; |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1537 | final boolean stateIsNormal = (state == State.NORMAL); |
| 1538 | final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); |
| 1539 | final boolean stateIsSmall = (state == State.SMALL); |
| 1540 | float finalScaleFactor = 1.0f; |
| 1541 | float finalBackgroundAlpha = stateIsSpringLoaded ? 1.0f : 0f; |
| 1542 | float translationX = 0; |
| 1543 | float translationY = 0; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1544 | boolean zoomIn = true; |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 1545 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1546 | if (state != State.NORMAL) { |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1547 | finalScaleFactor = mSpringLoadedShrinkFactor - (stateIsSmall ? 0.1f : 0); |
Winson Chung | 8aad610 | 2012-05-11 16:27:49 -0700 | [diff] [blame] | 1548 | setPageSpacing(mSpringLoadedPageSpacing); |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1549 | if (oldStateIsNormal && stateIsSmall) { |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1550 | zoomIn = false; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1551 | setLayoutScale(finalScaleFactor); |
| 1552 | updateChildrenLayersEnabled(); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1553 | } else { |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1554 | finalBackgroundAlpha = 1.0f; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1555 | setLayoutScale(finalScaleFactor); |
| 1556 | } |
| 1557 | } else { |
Winson Chung | 8aad610 | 2012-05-11 16:27:49 -0700 | [diff] [blame] | 1558 | setPageSpacing(PagedView.AUTOMATIC_PAGE_SPACING); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1559 | setLayoutScale(1.0f); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 1562 | final int duration = zoomIn ? |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1563 | getResources().getInteger(R.integer.config_workspaceUnshrinkTime) : |
| 1564 | getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1565 | for (int i = 0; i < getChildCount(); i++) { |
| 1566 | final CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1567 | float finalAlpha = (!mWorkspaceFadeInAdjacentScreens || stateIsSpringLoaded || |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1568 | (i == mCurrentPage)) ? 1f : 0f; |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1569 | float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); |
| 1570 | float initialAlpha = currentAlpha; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1571 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1572 | // Determine the pages alpha during the state transition |
| 1573 | if ((oldStateIsSmall && stateIsNormal) || |
| 1574 | (oldStateIsNormal && stateIsSmall)) { |
| 1575 | // To/from workspace - only show the current page unless the transition is not |
Michael Jurka | 4ff7d79 | 2012-04-02 03:46:50 -0700 | [diff] [blame] | 1576 | // animated and the animation end callback below doesn't run; |
| 1577 | // or, if we're in spring-loaded mode |
| 1578 | if (i == mCurrentPage || !animated || oldStateIsSpringLoaded) { |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1579 | finalAlpha = 1f; |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1580 | } else { |
| 1581 | initialAlpha = 0f; |
| 1582 | finalAlpha = 0f; |
| 1583 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1586 | mOldAlphas[i] = initialAlpha; |
| 1587 | mNewAlphas[i] = finalAlpha; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1588 | if (animated) { |
| 1589 | mOldTranslationXs[i] = cl.getTranslationX(); |
| 1590 | mOldTranslationYs[i] = cl.getTranslationY(); |
| 1591 | mOldScaleXs[i] = cl.getScaleX(); |
| 1592 | mOldScaleYs[i] = cl.getScaleY(); |
| 1593 | mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1594 | |
| 1595 | mNewTranslationXs[i] = translationX; |
| 1596 | mNewTranslationYs[i] = translationY; |
| 1597 | mNewScaleXs[i] = finalScaleFactor; |
| 1598 | mNewScaleYs[i] = finalScaleFactor; |
| 1599 | mNewBackgroundAlphas[i] = finalBackgroundAlpha; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1600 | } else { |
| 1601 | cl.setTranslationX(translationX); |
| 1602 | cl.setTranslationY(translationY); |
| 1603 | cl.setScaleX(finalScaleFactor); |
| 1604 | cl.setScaleY(finalScaleFactor); |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1605 | cl.setBackgroundAlpha(finalBackgroundAlpha); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1606 | cl.setShortcutAndWidgetAlpha(finalAlpha); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1607 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1608 | } |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1609 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1610 | if (animated) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 1611 | for (int index = 0; index < getChildCount(); index++) { |
| 1612 | final int i = index; |
| 1613 | final CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1614 | float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1615 | if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { |
Michael Jurka | 7372c59 | 2012-01-16 04:21:35 -0800 | [diff] [blame] | 1616 | cl.setTranslationX(mNewTranslationXs[i]); |
| 1617 | cl.setTranslationY(mNewTranslationYs[i]); |
| 1618 | cl.setScaleX(mNewScaleXs[i]); |
| 1619 | cl.setScaleY(mNewScaleYs[i]); |
| 1620 | cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1621 | cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); |
Michael Jurka | 7372c59 | 2012-01-16 04:21:35 -0800 | [diff] [blame] | 1622 | cl.setRotationY(mNewRotationYs[i]); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 1623 | } else { |
| 1624 | LauncherViewPropertyAnimator a = new LauncherViewPropertyAnimator(cl); |
| 1625 | a.translationX(mNewTranslationXs[i]) |
| 1626 | .translationY(mNewTranslationYs[i]) |
| 1627 | .scaleX(mNewScaleXs[i]) |
| 1628 | .scaleY(mNewScaleYs[i]) |
| 1629 | .setDuration(duration) |
| 1630 | .setInterpolator(mZoomInInterpolator); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 1631 | anim.play(a); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1632 | |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1633 | if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { |
Michael Jurka | 6c8a579 | 2012-03-22 05:24:37 -0700 | [diff] [blame] | 1634 | LauncherViewPropertyAnimator alphaAnim = |
| 1635 | new LauncherViewPropertyAnimator(cl.getShortcutsAndWidgets()); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1636 | alphaAnim.alpha(mNewAlphas[i]) |
| 1637 | .setDuration(duration) |
| 1638 | .setInterpolator(mZoomInInterpolator); |
| 1639 | anim.play(alphaAnim); |
| 1640 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 1641 | if (mOldBackgroundAlphas[i] != 0 || |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1642 | mNewBackgroundAlphas[i] != 0) { |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 1643 | ValueAnimator bgAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration); |
| 1644 | bgAnim.setInterpolator(mZoomInInterpolator); |
| 1645 | bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 1646 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | 7372c59 | 2012-01-16 04:21:35 -0800 | [diff] [blame] | 1647 | cl.setBackgroundAlpha( |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 1648 | a * mOldBackgroundAlphas[i] + |
| 1649 | b * mNewBackgroundAlphas[i]); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 1650 | } |
| 1651 | }); |
| 1652 | anim.play(bgAnim); |
| 1653 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1654 | } |
| 1655 | } |
Michael Jurka | b99d1af | 2012-04-25 17:28:27 -0700 | [diff] [blame] | 1656 | buildPageHardwareLayers(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1657 | anim.setStartDelay(delay); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 1660 | if (stateIsSpringLoaded) { |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1661 | // Right now we're covered by Apps Customize |
| 1662 | // Show the background gradient immediately, so the gradient will |
| 1663 | // be showing once AppsCustomize disappears |
| 1664 | animateBackgroundGradient(getResources().getInteger( |
| 1665 | R.integer.config_appsCustomizeSpringLoadedBgAlpha) / 100f, false); |
| 1666 | } else { |
| 1667 | // Fade the background gradient away |
| 1668 | animateBackgroundGradient(0f, true); |
| 1669 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 1670 | return anim; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 1673 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 1674 | public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 1675 | mIsSwitchingState = true; |
Michael Jurka | 72db6d7 | 2012-03-23 08:06:02 -0700 | [diff] [blame] | 1676 | cancelScrollingIndicatorAnimations(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 1680 | public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { |
| 1681 | } |
| 1682 | |
| 1683 | @Override |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1684 | public void onLauncherTransitionStep(Launcher l, float t) { |
| 1685 | mTransitionProgress = t; |
| 1686 | } |
| 1687 | |
| 1688 | @Override |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 1689 | public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { |
| 1690 | mIsSwitchingState = false; |
| 1691 | mWallpaperOffset.setOverrideHorizontalCatchupConstant(false); |
| 1692 | updateChildrenLayersEnabled(); |
| 1693 | // The code in getChangeStateAnimation to determine initialAlpha and finalAlpha will ensure |
| 1694 | // ensure that only the current page is visible during (and subsequently, after) the |
| 1695 | // transition animation. If fade adjacent pages is disabled, then re-enable the page |
| 1696 | // visibility after the transition animation. |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1697 | if (!mWorkspaceFadeInAdjacentScreens) { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 1698 | for (int i = 0; i < getChildCount(); i++) { |
| 1699 | final CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 1700 | cl.setShortcutAndWidgetAlpha(1f); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | @Override |
| 1706 | public View getContent() { |
| 1707 | return this; |
| 1708 | } |
| 1709 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1710 | /** |
| 1711 | * Draw the View v into the given Canvas. |
| 1712 | * |
| 1713 | * @param v the view to draw |
| 1714 | * @param destCanvas the canvas to draw on |
| 1715 | * @param padding the horizontal and vertical padding to use when drawing |
| 1716 | */ |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1717 | private void drawDragView(View v, Canvas destCanvas, int padding, boolean pruneToDrawable) { |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1718 | final Rect clipRect = mTempRect; |
| 1719 | v.getDrawingRect(clipRect); |
| 1720 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 1721 | boolean textVisible = false; |
| 1722 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1723 | destCanvas.save(); |
| 1724 | if (v instanceof TextView && pruneToDrawable) { |
| 1725 | Drawable d = ((TextView) v).getCompoundDrawables()[1]; |
| 1726 | clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding); |
| 1727 | destCanvas.translate(padding / 2, padding / 2); |
| 1728 | d.draw(destCanvas); |
| 1729 | } else { |
| 1730 | if (v instanceof FolderIcon) { |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 1731 | // For FolderIcons the text can bleed into the icon area, and so we need to |
| 1732 | // hide the text completely (which can't be achieved by clipping). |
| 1733 | if (((FolderIcon) v).getTextVisible()) { |
| 1734 | ((FolderIcon) v).setTextVisible(false); |
| 1735 | textVisible = true; |
| 1736 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1737 | } else if (v instanceof BubbleTextView) { |
| 1738 | final BubbleTextView tv = (BubbleTextView) v; |
| 1739 | clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V + |
| 1740 | tv.getLayout().getLineTop(0); |
| 1741 | } else if (v instanceof TextView) { |
| 1742 | final TextView tv = (TextView) v; |
| 1743 | clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding() + |
| 1744 | tv.getLayout().getLineTop(0); |
| 1745 | } |
| 1746 | destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); |
| 1747 | destCanvas.clipRect(clipRect, Op.REPLACE); |
| 1748 | v.draw(destCanvas); |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 1749 | |
| 1750 | // Restore text visibility of FolderIcon if necessary |
| 1751 | if (textVisible) { |
| 1752 | ((FolderIcon) v).setTextVisible(true); |
| 1753 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1754 | } |
| 1755 | destCanvas.restore(); |
| 1756 | } |
| 1757 | |
| 1758 | /** |
| 1759 | * Returns a new bitmap to show when the given View is being dragged around. |
| 1760 | * Responsibility for the bitmap is transferred to the caller. |
| 1761 | */ |
| 1762 | public Bitmap createDragBitmap(View v, Canvas canvas, int padding) { |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1763 | Bitmap b; |
| 1764 | |
| 1765 | if (v instanceof TextView) { |
| 1766 | Drawable d = ((TextView) v).getCompoundDrawables()[1]; |
| 1767 | b = Bitmap.createBitmap(d.getIntrinsicWidth() + padding, |
| 1768 | d.getIntrinsicHeight() + padding, Bitmap.Config.ARGB_8888); |
| 1769 | } else { |
| 1770 | b = Bitmap.createBitmap( |
| 1771 | v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1772 | } |
| 1773 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1774 | canvas.setBitmap(b); |
| 1775 | drawDragView(v, canvas, padding, true); |
Adam Cohen | aaf473c | 2011-08-03 12:02:47 -0700 | [diff] [blame] | 1776 | canvas.setBitmap(null); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1777 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1778 | return b; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | /** |
| 1782 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 1783 | * Responsibility for the bitmap is transferred to the caller. |
| 1784 | */ |
| 1785 | private Bitmap createDragOutline(View v, Canvas canvas, int padding) { |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 1786 | final int outlineColor = getResources().getColor(android.R.color.holo_blue_light); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1787 | final Bitmap b = Bitmap.createBitmap( |
| 1788 | v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); |
| 1789 | |
| 1790 | canvas.setBitmap(b); |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 1791 | drawDragView(v, canvas, padding, true); |
Adam Cohen | 5bb50bd | 2010-12-03 11:39:55 -0800 | [diff] [blame] | 1792 | mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor); |
Adam Cohen | aaf473c | 2011-08-03 12:02:47 -0700 | [diff] [blame] | 1793 | canvas.setBitmap(null); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1794 | return b; |
| 1795 | } |
| 1796 | |
| 1797 | /** |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1798 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 1799 | * Responsibility for the bitmap is transferred to the caller. |
| 1800 | */ |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 1801 | private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding, int w, int h, |
| 1802 | Paint alphaClipPaint) { |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 1803 | final int outlineColor = getResources().getColor(android.R.color.holo_blue_light); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 1804 | final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1805 | canvas.setBitmap(b); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 1806 | |
| 1807 | Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight()); |
| 1808 | float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(), |
| 1809 | (h - padding) / (float) orig.getHeight()); |
| 1810 | int scaledWidth = (int) (scaleFactor * orig.getWidth()); |
| 1811 | int scaledHeight = (int) (scaleFactor * orig.getHeight()); |
| 1812 | Rect dst = new Rect(0, 0, scaledWidth, scaledHeight); |
| 1813 | |
| 1814 | // center the image |
| 1815 | dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2); |
| 1816 | |
Winson Chung | 1120e03 | 2011-11-22 16:11:31 -0800 | [diff] [blame] | 1817 | canvas.drawBitmap(orig, src, dst, null); |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 1818 | mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor, |
| 1819 | alphaClipPaint); |
Adam Cohen | aaf473c | 2011-08-03 12:02:47 -0700 | [diff] [blame] | 1820 | canvas.setBitmap(null); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1821 | |
| 1822 | return b; |
| 1823 | } |
| 1824 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1825 | void startDrag(CellLayout.CellInfo cellInfo) { |
| 1826 | View child = cellInfo.cell; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1827 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1828 | // Make sure the drag was started by a long press as opposed to a long click. |
Bjorn Bringert | 7984c94 | 2009-12-09 15:38:25 +0000 | [diff] [blame] | 1829 | if (!child.isInTouchMode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1830 | return; |
| 1831 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1832 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1833 | mDragInfo = cellInfo; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1834 | child.setVisibility(INVISIBLE); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1835 | CellLayout layout = (CellLayout) child.getParent().getParent(); |
| 1836 | layout.prepareChildForDrag(child); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1837 | |
| 1838 | child.clearFocus(); |
| 1839 | child.setPressed(false); |
| 1840 | |
| 1841 | final Canvas canvas = new Canvas(); |
| 1842 | |
| 1843 | // The outline is used to visualize where the item will land if dropped |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1844 | mDragOutline = createDragOutline(child, canvas, DRAG_BITMAP_PADDING); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1845 | beginDragShared(child, this); |
| 1846 | } |
| 1847 | |
| 1848 | public void beginDragShared(View child, DragSource source) { |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 1849 | Resources r = getResources(); |
| 1850 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1851 | // The drag bitmap follows the touch point around on the screen |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1852 | final Bitmap b = createDragBitmap(child, new Canvas(), DRAG_BITMAP_PADDING); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1853 | |
| 1854 | final int bmpWidth = b.getWidth(); |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 1855 | final int bmpHeight = b.getHeight(); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1856 | |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 1857 | mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY); |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 1858 | int dragLayerX = |
| 1859 | Math.round(mTempXY[0] - (bmpWidth - child.getScaleX() * child.getWidth()) / 2); |
| 1860 | int dragLayerY = |
| 1861 | Math.round(mTempXY[1] - (bmpHeight - child.getScaleY() * bmpHeight) / 2 |
| 1862 | - DRAG_BITMAP_PADDING / 2); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1863 | |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 1864 | Point dragVisualizeOffset = null; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1865 | Rect dragRect = null; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 1866 | if (child instanceof BubbleTextView || child instanceof PagedViewIcon) { |
| 1867 | int iconSize = r.getDimensionPixelSize(R.dimen.app_icon_size); |
| 1868 | int iconPaddingTop = r.getDimensionPixelSize(R.dimen.app_icon_padding_top); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1869 | int top = child.getPaddingTop(); |
| 1870 | int left = (bmpWidth - iconSize) / 2; |
| 1871 | int right = left + iconSize; |
| 1872 | int bottom = top + iconSize; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 1873 | dragLayerY += top; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 1874 | // Note: The drag region is used to calculate drag layer offsets, but the |
| 1875 | // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1876 | dragVisualizeOffset = new Point(-DRAG_BITMAP_PADDING / 2, |
| 1877 | iconPaddingTop - DRAG_BITMAP_PADDING / 2); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1878 | dragRect = new Rect(left, top, right, bottom); |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 1879 | } else if (child instanceof FolderIcon) { |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 1880 | int previewSize = r.getDimensionPixelSize(R.dimen.folder_preview_size); |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 1881 | dragRect = new Rect(0, 0, child.getWidth(), previewSize); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 1882 | } |
| 1883 | |
Winson Chung | 1e9cbfe | 2011-09-30 16:52:26 -0700 | [diff] [blame] | 1884 | // Clear the pressed state if necessary |
| 1885 | if (child instanceof BubbleTextView) { |
| 1886 | BubbleTextView icon = (BubbleTextView) child; |
| 1887 | icon.clearPressedOrFocusedBackground(); |
| 1888 | } |
| 1889 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 1890 | mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 1891 | DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, child.getScaleX()); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 1892 | b.recycle(); |
Winson Chung | 1afedc3 | 2012-01-23 16:14:56 -0800 | [diff] [blame] | 1893 | |
| 1894 | // Show the scrolling indicator when you pick up an item |
| 1895 | showScrollingIndicator(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1896 | } |
| 1897 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1898 | void addApplicationShortcut(ShortcutInfo info, CellLayout target, long container, int screen, |
| 1899 | int cellX, int cellY, boolean insertAtFirst, int intersectX, int intersectY) { |
| 1900 | View view = mLauncher.createShortcut(R.layout.application, target, (ShortcutInfo) info); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 1901 | |
| 1902 | final int[] cellXY = new int[2]; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1903 | target.findCellForSpanThatIntersects(cellXY, 1, 1, intersectX, intersectY); |
| 1904 | addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1, insertAtFirst); |
| 1905 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screen, cellXY[0], |
| 1906 | cellXY[1]); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1907 | } |
| 1908 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 1909 | public boolean transitionStateShouldAllowDrop() { |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 1910 | return ((!isSwitchingState() || mTransitionProgress > 0.5f) && mState != State.SMALL); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1913 | /** |
| 1914 | * {@inheritDoc} |
| 1915 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 1916 | public boolean acceptDrop(DragObject d) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1917 | // If it's an external drop (e.g. from All Apps), check if it should be accepted |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1918 | CellLayout dropTargetLayout = mDropToLayout; |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 1919 | if (d.dragSource != this) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1920 | // Don't accept the drop if we're not over a screen at time of drop |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1921 | if (dropTargetLayout == null) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1922 | return false; |
| 1923 | } |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 1924 | if (!transitionStateShouldAllowDrop()) return false; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1925 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 1926 | mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, |
| 1927 | d.dragView, mDragViewVisualCenter); |
| 1928 | |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 1929 | // We want the point to be mapped to the dragTarget. |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1930 | if (mLauncher.isHotseatLayout(dropTargetLayout)) { |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 1931 | mapPointFromSelfToSibling(mLauncher.getHotseat(), mDragViewVisualCenter); |
| 1932 | } else { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1933 | mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 1936 | int spanX = 1; |
| 1937 | int spanY = 1; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 1938 | if (mDragInfo != null) { |
| 1939 | final CellLayout.CellInfo dragCellInfo = mDragInfo; |
| 1940 | spanX = dragCellInfo.spanX; |
| 1941 | spanY = dragCellInfo.spanY; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 1942 | } else { |
| 1943 | final ItemInfo dragInfo = (ItemInfo) d.dragInfo; |
| 1944 | spanX = dragInfo.spanX; |
| 1945 | spanY = dragInfo.spanY; |
| 1946 | } |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1947 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 1948 | int minSpanX = spanX; |
| 1949 | int minSpanY = spanY; |
| 1950 | if (d.dragInfo instanceof PendingAddWidgetInfo) { |
| 1951 | minSpanX = ((PendingAddWidgetInfo) d.dragInfo).minSpanX; |
| 1952 | minSpanY = ((PendingAddWidgetInfo) d.dragInfo).minSpanY; |
| 1953 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1954 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 1955 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1956 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout, |
Adam Cohen | f0777b9 | 2012-02-28 14:02:45 -0800 | [diff] [blame] | 1957 | mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1958 | float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1959 | mDragViewVisualCenter[1], mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1960 | if (willCreateUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1961 | mTargetCell, distance, true)) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 1962 | return true; |
| 1963 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1964 | if (willAddToExistingUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1965 | mTargetCell, distance)) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 1966 | return true; |
| 1967 | } |
| 1968 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1969 | int[] resultSpan = new int[2]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1970 | mTargetCell = dropTargetLayout.createArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1971 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, |
| 1972 | null, mTargetCell, resultSpan, CellLayout.MODE_ACCEPT_DROP); |
| 1973 | boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0; |
| 1974 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1975 | // Don't accept the drop if there's no room for the item |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1976 | if (!foundCell) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 1977 | // Don't show the message if we are dropping on the AllApps button and the hotseat |
| 1978 | // is full |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 1979 | boolean isHotseat = mLauncher.isHotseatLayout(dropTargetLayout); |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1980 | if (mTargetCell != null && isHotseat) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 1981 | Hotseat hotseat = mLauncher.getHotseat(); |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 1982 | if (hotseat.isAllAppsButtonRank( |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 1983 | hotseat.getOrderInHotseat(mTargetCell[0], mTargetCell[1]))) { |
| 1984 | return false; |
| 1985 | } |
| 1986 | } |
| 1987 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 1988 | mLauncher.showOutOfSpaceMessage(isHotseat); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1989 | return false; |
| 1990 | } |
| 1991 | } |
| 1992 | return true; |
| 1993 | } |
| 1994 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 1995 | boolean willCreateUserFolder(ItemInfo info, CellLayout target, int[] targetCell, float |
| 1996 | distance, boolean considerTimeout) { |
| 1997 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 1998 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
| 1999 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2000 | if (dropOverView != null) { |
| 2001 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams(); |
| 2002 | if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) { |
| 2003 | return false; |
| 2004 | } |
| 2005 | } |
| 2006 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2007 | boolean hasntMoved = false; |
| 2008 | if (mDragInfo != null) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2009 | hasntMoved = dropOverView == mDragInfo.cell; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2010 | } |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2011 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2012 | if (dropOverView == null || hasntMoved || (considerTimeout && !mCreateUserFolderOnDrop)) { |
| 2013 | return false; |
| 2014 | } |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2015 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2016 | boolean aboveShortcut = (dropOverView.getTag() instanceof ShortcutInfo); |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2017 | boolean willBecomeShortcut = |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2018 | (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 2019 | info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT); |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2020 | |
| 2021 | return (aboveShortcut && willBecomeShortcut); |
| 2022 | } |
| 2023 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2024 | boolean willAddToExistingUserFolder(Object dragInfo, CellLayout target, int[] targetCell, |
| 2025 | float distance) { |
| 2026 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2027 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2028 | |
| 2029 | if (dropOverView != null) { |
| 2030 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams(); |
| 2031 | if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) { |
| 2032 | return false; |
| 2033 | } |
| 2034 | } |
| 2035 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2036 | if (dropOverView instanceof FolderIcon) { |
| 2037 | FolderIcon fi = (FolderIcon) dropOverView; |
| 2038 | if (fi.acceptDrop(dragInfo)) { |
| 2039 | return true; |
| 2040 | } |
| 2041 | } |
| 2042 | return false; |
| 2043 | } |
| 2044 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2045 | boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2046 | int[] targetCell, float distance, boolean external, DragView dragView, |
| 2047 | Runnable postAnimationRunnable) { |
| 2048 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2049 | View v = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2050 | |
Winson Chung | ec9a0a4 | 2011-07-20 20:42:13 -0700 | [diff] [blame] | 2051 | boolean hasntMoved = false; |
| 2052 | if (mDragInfo != null) { |
| 2053 | CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell); |
| 2054 | hasntMoved = (mDragInfo.cellX == targetCell[0] && |
| 2055 | mDragInfo.cellY == targetCell[1]) && (cellParent == target); |
| 2056 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2057 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2058 | if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false; |
| 2059 | mCreateUserFolderOnDrop = false; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2060 | final int screen = (targetCell == null) ? mDragInfo.screen : indexOfChild(target); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2061 | |
| 2062 | boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo); |
| 2063 | boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo); |
| 2064 | |
| 2065 | if (aboveShortcut && willBecomeShortcut) { |
| 2066 | ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag(); |
| 2067 | ShortcutInfo destInfo = (ShortcutInfo) v.getTag(); |
| 2068 | // if the drag started here, we need to remove it from the workspace |
| 2069 | if (!external) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2070 | getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 2073 | Rect folderLocation = new Rect(); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2074 | float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2075 | target.removeView(v); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 2076 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2077 | FolderIcon fi = |
| 2078 | mLauncher.addFolder(target, container, screen, targetCell[0], targetCell[1]); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2079 | destInfo.cellX = -1; |
| 2080 | destInfo.cellY = -1; |
| 2081 | sourceInfo.cellX = -1; |
| 2082 | sourceInfo.cellY = -1; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 2083 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 2084 | // If the dragView is null, we can't animate |
| 2085 | boolean animate = dragView != null; |
| 2086 | if (animate) { |
| 2087 | fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale, |
| 2088 | postAnimationRunnable); |
| 2089 | } else { |
| 2090 | fi.addItem(destInfo); |
| 2091 | fi.addItem(sourceInfo); |
| 2092 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2093 | return true; |
| 2094 | } |
| 2095 | return false; |
| 2096 | } |
| 2097 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2098 | boolean addToExistingFolderIfNecessary(View newView, CellLayout target, int[] targetCell, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2099 | float distance, DragObject d, boolean external) { |
| 2100 | if (distance > mMaxDistanceForFolderCreation) return false; |
| 2101 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2102 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2103 | if (!mAddToExistingFolderOnDrop) return false; |
| 2104 | mAddToExistingFolderOnDrop = false; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2105 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2106 | if (dropOverView instanceof FolderIcon) { |
| 2107 | FolderIcon fi = (FolderIcon) dropOverView; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 2108 | if (fi.acceptDrop(d.dragInfo)) { |
| 2109 | fi.onDrop(d); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2110 | |
| 2111 | // if the drag started here, we need to remove it from the workspace |
| 2112 | if (!external) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2113 | getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2114 | } |
| 2115 | return true; |
| 2116 | } |
| 2117 | } |
| 2118 | return false; |
| 2119 | } |
| 2120 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2121 | public void onDrop(final DragObject d) { |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2122 | mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2123 | mDragViewVisualCenter); |
| 2124 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2125 | CellLayout dropTargetLayout = mDropToLayout; |
| 2126 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2127 | // We want the point to be mapped to the dragTarget. |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2128 | if (dropTargetLayout != null) { |
| 2129 | if (mLauncher.isHotseatLayout(dropTargetLayout)) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2130 | mapPointFromSelfToSibling(mLauncher.getHotseat(), mDragViewVisualCenter); |
| 2131 | } else { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2132 | mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2133 | } |
Adam Cohen | ba78161 | 2011-05-09 14:37:39 -0700 | [diff] [blame] | 2134 | } |
Michael Jurka | c6ee42e | 2010-09-30 12:04:50 -0700 | [diff] [blame] | 2135 | |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 2136 | int snapScreen = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2137 | boolean resizeOnDrop = false; |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2138 | if (d.dragSource != this) { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2139 | final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], |
| 2140 | (int) mDragViewVisualCenter[1] }; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 2141 | onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d); |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2142 | } else if (mDragInfo != null) { |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2143 | final View cell = mDragInfo.cell; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2144 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2145 | Runnable resizeRunnable = null; |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 2146 | if (dropTargetLayout != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2147 | // Move internally |
Winson Chung | 40e882b | 2011-07-21 19:01:11 -0700 | [diff] [blame] | 2148 | boolean hasMovedLayouts = (getParentCellLayoutForView(cell) != dropTargetLayout); |
| 2149 | boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout); |
| 2150 | long container = hasMovedIntoHotseat ? |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2151 | LauncherSettings.Favorites.CONTAINER_HOTSEAT : |
| 2152 | LauncherSettings.Favorites.CONTAINER_DESKTOP; |
| 2153 | int screen = (mTargetCell[0] < 0) ? |
| 2154 | mDragInfo.screen : indexOfChild(dropTargetLayout); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2155 | int spanX = mDragInfo != null ? mDragInfo.spanX : 1; |
| 2156 | int spanY = mDragInfo != null ? mDragInfo.spanY : 1; |
| 2157 | // First we find the cell nearest to point at which the item is |
| 2158 | // dropped, without any consideration to whether there is an item there. |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2159 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2160 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) |
| 2161 | mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2162 | float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 2163 | mDragViewVisualCenter[1], mTargetCell); |
| 2164 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2165 | // If the item being dropped is a shortcut and the nearest drop |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 2166 | // cell also contains a shortcut, then create a folder with the two shortcuts. |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 2167 | if (!mInScrollArea && createUserFolderIfNecessary(cell, container, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2168 | dropTargetLayout, mTargetCell, distance, false, d.dragView, null)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2169 | return; |
| 2170 | } |
| 2171 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2172 | if (addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, |
| 2173 | distance, d, false)) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2174 | return; |
| 2175 | } |
| 2176 | |
| 2177 | // Aside from the special case where we're dropping a shortcut onto a shortcut, |
| 2178 | // we need to find the nearest cell location that is vacant |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2179 | ItemInfo item = (ItemInfo) d.dragInfo; |
| 2180 | int minSpanX = item.spanX; |
| 2181 | int minSpanY = item.spanY; |
| 2182 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 2183 | minSpanX = item.minSpanX; |
| 2184 | minSpanY = item.minSpanY; |
| 2185 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2186 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2187 | int[] resultSpan = new int[2]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2188 | mTargetCell = dropTargetLayout.createArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2189 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, |
| 2190 | mTargetCell, resultSpan, CellLayout.MODE_ON_DROP); |
| 2191 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2192 | boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0; |
| 2193 | if (foundCell && (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY)) { |
| 2194 | resizeOnDrop = true; |
| 2195 | item.spanX = resultSpan[0]; |
| 2196 | item.spanY = resultSpan[1]; |
| 2197 | } |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2198 | |
Michael Jurka | 7cfc282 | 2011-08-02 20:19:24 -0700 | [diff] [blame] | 2199 | if (mCurrentPage != screen && !hasMovedIntoHotseat) { |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 2200 | snapScreen = screen; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2201 | snapToPage(screen); |
| 2202 | } |
| 2203 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2204 | if (foundCell) { |
| 2205 | final ItemInfo info = (ItemInfo) cell.getTag(); |
Winson Chung | 40e882b | 2011-07-21 19:01:11 -0700 | [diff] [blame] | 2206 | if (hasMovedLayouts) { |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2207 | // Reparent the view |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2208 | getParentCellLayoutForView(cell).removeView(cell); |
| 2209 | addInScreen(cell, container, screen, mTargetCell[0], mTargetCell[1], |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2210 | info.spanX, info.spanY); |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | // update the item's position after drop |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2214 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2215 | lp.cellX = lp.tmpCellX = mTargetCell[0]; |
| 2216 | lp.cellY = lp.tmpCellY = mTargetCell[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2217 | lp.cellHSpan = item.spanX; |
| 2218 | lp.cellVSpan = item.spanY; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2219 | lp.isLockedToGrid = true; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2220 | cell.setId(LauncherModel.getCellLayoutChildId(container, mDragInfo.screen, |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2221 | mTargetCell[0], mTargetCell[1], mDragInfo.spanX, mDragInfo.spanY)); |
| 2222 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2223 | if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 2224 | cell instanceof LauncherAppWidgetHostView) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2225 | final CellLayout cellLayout = dropTargetLayout; |
| 2226 | // We post this call so that the widget has a chance to be placed |
| 2227 | // in its final location |
| 2228 | |
| 2229 | final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell; |
| 2230 | AppWidgetProviderInfo pinfo = hostView.getAppWidgetInfo(); |
Adam Cohen | c0a5df9 | 2012-04-02 16:53:26 -0700 | [diff] [blame] | 2231 | if (pinfo != null && |
| 2232 | pinfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2233 | final Runnable addResizeFrame = new Runnable() { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2234 | public void run() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 2235 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2236 | dragLayer.addResizeFrame(info, hostView, cellLayout); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2237 | } |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2238 | }; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2239 | resizeRunnable = (new Runnable() { |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2240 | public void run() { |
| 2241 | if (!isPageMoving()) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2242 | addResizeFrame.run(); |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2243 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2244 | mDelayedResizeRunnable = addResizeFrame; |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2245 | } |
| 2246 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2247 | }); |
| 2248 | } |
| 2249 | } |
| 2250 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2251 | LauncherModel.moveItemInDatabase(mLauncher, info, container, screen, lp.cellX, |
| 2252 | lp.cellY); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2253 | } else { |
| 2254 | // If we can't find a drop location, we return the item to its original position |
| 2255 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); |
| 2256 | mTargetCell[0] = lp.cellX; |
| 2257 | mTargetCell[1] = lp.cellY; |
Adam Cohen | f1dcdf6 | 2012-05-10 16:51:52 -0700 | [diff] [blame] | 2258 | CellLayout layout = (CellLayout) cell.getParent().getParent(); |
| 2259 | layout.markCellsAsOccupiedForView(cell); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2260 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2261 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2262 | |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 2263 | final CellLayout parent = (CellLayout) cell.getParent().getParent(); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2264 | final Runnable finalResizeRunnable = resizeRunnable; |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2265 | // Prepare it to be animated into its new position |
| 2266 | // This must be called after the view has been re-parented |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2267 | final Runnable onCompleteRunnable = new Runnable() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 2268 | @Override |
| 2269 | public void run() { |
| 2270 | mAnimatingViewIntoPlace = false; |
| 2271 | updateChildrenLayersEnabled(); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2272 | if (finalResizeRunnable != null) { |
| 2273 | finalResizeRunnable.run(); |
| 2274 | } |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 2275 | } |
| 2276 | }; |
| 2277 | mAnimatingViewIntoPlace = true; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2278 | if (d.dragView.hasDrawn()) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2279 | final ItemInfo info = (ItemInfo) cell.getTag(); |
| 2280 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) { |
| 2281 | int animationType = resizeOnDrop ? ANIMATE_INTO_POSITION_AND_RESIZE : |
| 2282 | ANIMATE_INTO_POSITION_AND_DISAPPEAR; |
| 2283 | animateWidgetDrop(info, parent, d.dragView, |
| 2284 | onCompleteRunnable, animationType, cell, false); |
| 2285 | } else { |
Adam Cohen | 85b467b | 2012-02-29 15:38:46 -0800 | [diff] [blame] | 2286 | int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION; |
| 2287 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, |
| 2288 | onCompleteRunnable, this); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2289 | } |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2290 | } else { |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 2291 | d.deferDragViewCleanupPostAnimation = false; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2292 | cell.setVisibility(VISIBLE); |
| 2293 | } |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 2294 | parent.onDropChild(cell); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2295 | } |
| 2296 | } |
| 2297 | |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 2298 | public void setFinalScrollForPageChange(int screen) { |
| 2299 | if (screen >= 0) { |
| 2300 | mSavedScrollX = getScrollX(); |
| 2301 | CellLayout cl = (CellLayout) getChildAt(screen); |
| 2302 | mSavedTranslationX = cl.getTranslationX(); |
| 2303 | mSavedRotationY = cl.getRotationY(); |
| 2304 | final int newX = getChildOffset(screen) - getRelativeChildOffset(screen); |
| 2305 | setScrollX(newX); |
| 2306 | cl.setTranslationX(0f); |
| 2307 | cl.setRotationY(0f); |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | public void resetFinalScrollForPageChange(int screen) { |
| 2312 | if (screen >= 0) { |
| 2313 | CellLayout cl = (CellLayout) getChildAt(screen); |
| 2314 | setScrollX(mSavedScrollX); |
| 2315 | cl.setTranslationX(mSavedTranslationX); |
| 2316 | cl.setRotationY(mSavedRotationY); |
| 2317 | } |
| 2318 | } |
| 2319 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 2320 | public void getViewLocationRelativeToSelf(View v, int[] location) { |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 2321 | getLocationInWindow(location); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2322 | int x = location[0]; |
| 2323 | int y = location[1]; |
| 2324 | |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 2325 | v.getLocationInWindow(location); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2326 | int vX = location[0]; |
| 2327 | int vY = location[1]; |
| 2328 | |
| 2329 | location[0] = vX - x; |
| 2330 | location[1] = vY - y; |
| 2331 | } |
| 2332 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2333 | public void onDragEnter(DragObject d) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2334 | mDragEnforcer.onDragEnter(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2335 | mCreateUserFolderOnDrop = false; |
| 2336 | mAddToExistingFolderOnDrop = false; |
| 2337 | |
| 2338 | mDropToLayout = null; |
| 2339 | CellLayout layout = getCurrentDropLayout(); |
| 2340 | setCurrentDropLayout(layout); |
| 2341 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 2342 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2343 | // Because we don't have space in the Phone UI (the CellLayouts run to the edge) we |
| 2344 | // don't need to show the outlines |
| 2345 | if (LauncherApplication.isScreenLarge()) { |
| 2346 | showOutlines(); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2347 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2348 | } |
| 2349 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2350 | static Rect getCellLayoutMetrics(Launcher launcher, int orientation) { |
| 2351 | Resources res = launcher.getResources(); |
| 2352 | Display display = launcher.getWindowManager().getDefaultDisplay(); |
| 2353 | Point smallestSize = new Point(); |
| 2354 | Point largestSize = new Point(); |
| 2355 | display.getCurrentSizeRange(smallestSize, largestSize); |
| 2356 | if (orientation == CellLayout.LANDSCAPE) { |
| 2357 | if (mLandscapeCellLayoutMetrics == null) { |
| 2358 | int paddingLeft = res.getDimensionPixelSize(R.dimen.workspace_left_padding_land); |
| 2359 | int paddingRight = res.getDimensionPixelSize(R.dimen.workspace_right_padding_land); |
| 2360 | int paddingTop = res.getDimensionPixelSize(R.dimen.workspace_top_padding_land); |
| 2361 | int paddingBottom = res.getDimensionPixelSize(R.dimen.workspace_bottom_padding_land); |
| 2362 | int width = largestSize.x - paddingLeft - paddingRight; |
| 2363 | int height = smallestSize.y - paddingTop - paddingBottom; |
| 2364 | mLandscapeCellLayoutMetrics = new Rect(); |
| 2365 | CellLayout.getMetrics(mLandscapeCellLayoutMetrics, res, |
| 2366 | width, height, LauncherModel.getCellCountX(), LauncherModel.getCellCountY(), |
| 2367 | orientation); |
| 2368 | } |
| 2369 | return mLandscapeCellLayoutMetrics; |
| 2370 | } else if (orientation == CellLayout.PORTRAIT) { |
| 2371 | if (mPortraitCellLayoutMetrics == null) { |
| 2372 | int paddingLeft = res.getDimensionPixelSize(R.dimen.workspace_left_padding_land); |
| 2373 | int paddingRight = res.getDimensionPixelSize(R.dimen.workspace_right_padding_land); |
| 2374 | int paddingTop = res.getDimensionPixelSize(R.dimen.workspace_top_padding_land); |
| 2375 | int paddingBottom = res.getDimensionPixelSize(R.dimen.workspace_bottom_padding_land); |
| 2376 | int width = smallestSize.x - paddingLeft - paddingRight; |
| 2377 | int height = largestSize.y - paddingTop - paddingBottom; |
| 2378 | mPortraitCellLayoutMetrics = new Rect(); |
| 2379 | CellLayout.getMetrics(mPortraitCellLayoutMetrics, res, |
| 2380 | width, height, LauncherModel.getCellCountX(), LauncherModel.getCellCountY(), |
| 2381 | orientation); |
| 2382 | } |
| 2383 | return mPortraitCellLayoutMetrics; |
| 2384 | } |
| 2385 | return null; |
| 2386 | } |
| 2387 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2388 | public void onDragExit(DragObject d) { |
| 2389 | mDragEnforcer.onDragExit(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2390 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2391 | // Here we store the final page that will be dropped to, if the workspace in fact |
| 2392 | // receives the drop |
| 2393 | if (mInScrollArea) { |
| 2394 | mDropToLayout = mDragOverlappingLayout; |
| 2395 | } else { |
| 2396 | mDropToLayout = mDragTargetLayout; |
| 2397 | } |
| 2398 | |
| 2399 | if (mDragMode == DRAG_MODE_CREATE_FOLDER) { |
| 2400 | mCreateUserFolderOnDrop = true; |
| 2401 | } else if (mDragMode == DRAG_MODE_ADD_TO_FOLDER) { |
| 2402 | mAddToExistingFolderOnDrop = true; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2405 | // Reset the scroll area and previous drag target |
| 2406 | onResetScrollArea(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2407 | setCurrentDropLayout(null); |
| 2408 | setCurrentDragOverlappingLayout(null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2409 | |
Adam Cohen | 74c28d1 | 2011-11-18 14:17:11 -0800 | [diff] [blame] | 2410 | mSpringLoadedDragController.cancel(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2411 | |
| 2412 | if (!mIsPageMoving) { |
| 2413 | hideOutlines(); |
| 2414 | } |
| 2415 | } |
| 2416 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2417 | void setCurrentDropLayout(CellLayout layout) { |
| 2418 | if (mDragTargetLayout != null) { |
| 2419 | mDragTargetLayout.revertTempState(); |
| 2420 | mDragTargetLayout.onDragExit(); |
| 2421 | } |
| 2422 | mDragTargetLayout = layout; |
| 2423 | if (mDragTargetLayout != null) { |
| 2424 | mDragTargetLayout.onDragEnter(); |
| 2425 | } |
| 2426 | cleanupReorder(true); |
| 2427 | cleanupFolderCreation(); |
| 2428 | setCurrentDropOverCell(-1, -1); |
| 2429 | } |
| 2430 | |
| 2431 | void setCurrentDragOverlappingLayout(CellLayout layout) { |
| 2432 | if (mDragOverlappingLayout != null) { |
| 2433 | mDragOverlappingLayout.setIsDragOverlapping(false); |
| 2434 | } |
| 2435 | mDragOverlappingLayout = layout; |
| 2436 | if (mDragOverlappingLayout != null) { |
| 2437 | mDragOverlappingLayout.setIsDragOverlapping(true); |
| 2438 | } |
| 2439 | invalidate(); |
| 2440 | } |
| 2441 | |
| 2442 | void setCurrentDropOverCell(int x, int y) { |
| 2443 | if (x != mDragOverX || y != mDragOverY) { |
| 2444 | mDragOverX = x; |
| 2445 | mDragOverY = y; |
| 2446 | setDragMode(DRAG_MODE_NONE); |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | void setDragMode(int dragMode) { |
| 2451 | if (dragMode != mDragMode) { |
| 2452 | if (dragMode == DRAG_MODE_NONE) { |
| 2453 | cleanupAddToFolder(); |
| 2454 | // We don't want to cancel the re-order alarm every time the target cell changes |
| 2455 | // as this feels to slow / unresponsive. |
| 2456 | cleanupReorder(false); |
| 2457 | cleanupFolderCreation(); |
| 2458 | } else if (dragMode == DRAG_MODE_ADD_TO_FOLDER) { |
| 2459 | cleanupReorder(true); |
| 2460 | cleanupFolderCreation(); |
| 2461 | } else if (dragMode == DRAG_MODE_CREATE_FOLDER) { |
| 2462 | cleanupAddToFolder(); |
| 2463 | cleanupReorder(true); |
| 2464 | } else if (dragMode == DRAG_MODE_REORDER) { |
| 2465 | cleanupAddToFolder(); |
| 2466 | cleanupFolderCreation(); |
| 2467 | } |
| 2468 | mDragMode = dragMode; |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | private void cleanupFolderCreation() { |
| 2473 | if (mDragFolderRingAnimator != null) { |
| 2474 | mDragFolderRingAnimator.animateToNaturalState(); |
| 2475 | } |
| 2476 | mFolderCreationAlarm.cancelAlarm(); |
| 2477 | } |
| 2478 | |
| 2479 | private void cleanupAddToFolder() { |
| 2480 | if (mDragOverFolderIcon != null) { |
| 2481 | mDragOverFolderIcon.onDragExit(null); |
| 2482 | mDragOverFolderIcon = null; |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | private void cleanupReorder(boolean cancelAlarm) { |
| 2487 | // Any pending reorders are canceled |
| 2488 | if (cancelAlarm) { |
| 2489 | mReorderAlarm.cancelAlarm(); |
| 2490 | } |
| 2491 | mLastReorderX = -1; |
| 2492 | mLastReorderY = -1; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2495 | public DropTarget getDropTargetDelegate(DragObject d) { |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 2496 | return null; |
| 2497 | } |
| 2498 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2499 | /* |
| 2500 | * |
| 2501 | * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's |
| 2502 | * coordinate space. The argument xy is modified with the return result. |
| 2503 | * |
| 2504 | */ |
| 2505 | void mapPointFromSelfToChild(View v, float[] xy) { |
| 2506 | mapPointFromSelfToChild(v, xy, null); |
| 2507 | } |
| 2508 | |
| 2509 | /* |
| 2510 | * |
| 2511 | * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's |
| 2512 | * coordinate space. The argument xy is modified with the return result. |
| 2513 | * |
| 2514 | * if cachedInverseMatrix is not null, this method will just use that matrix instead of |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2515 | * computing it itself; we use this to avoid redundant matrix inversions in |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2516 | * findMatchingPageForDragOver |
| 2517 | * |
| 2518 | */ |
| 2519 | void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) { |
| 2520 | if (cachedInverseMatrix == null) { |
| 2521 | v.getMatrix().invert(mTempInverseMatrix); |
| 2522 | cachedInverseMatrix = mTempInverseMatrix; |
| 2523 | } |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2524 | int scrollX = getScrollX(); |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 2525 | if (mNextPage != INVALID_PAGE) { |
| 2526 | scrollX = mScroller.getFinalX(); |
| 2527 | } |
| 2528 | xy[0] = xy[0] + scrollX - v.getLeft(); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2529 | xy[1] = xy[1] + getScrollY() - v.getTop(); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2530 | cachedInverseMatrix.mapPoints(xy); |
| 2531 | } |
| 2532 | |
| 2533 | /* |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2534 | * Maps a point from the Workspace's coordinate system to another sibling view's. (Workspace |
| 2535 | * covers the full screen) |
| 2536 | */ |
| 2537 | void mapPointFromSelfToSibling(View v, float[] xy) { |
| 2538 | xy[0] = xy[0] - v.getLeft(); |
| 2539 | xy[1] = xy[1] - v.getTop(); |
| 2540 | } |
| 2541 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2542 | void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) { |
| 2543 | xy[0] = xy[0] - hotseat.getLeft() - hotseat.getLayout().getLeft(); |
| 2544 | xy[1] = xy[1] - hotseat.getTop() - hotseat.getLayout().getTop(); |
| 2545 | } |
| 2546 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2547 | /* |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2548 | * |
| 2549 | * Convert the 2D coordinate xy from this CellLayout's coordinate space to |
| 2550 | * the parent View's coordinate space. The argument xy is modified with the return result. |
| 2551 | * |
| 2552 | */ |
| 2553 | void mapPointFromChildToSelf(View v, float[] xy) { |
| 2554 | v.getMatrix().mapPoints(xy); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2555 | int scrollX = getScrollX(); |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 2556 | if (mNextPage != INVALID_PAGE) { |
| 2557 | scrollX = mScroller.getFinalX(); |
| 2558 | } |
| 2559 | xy[0] -= (scrollX - v.getLeft()); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 2560 | xy[1] -= (getScrollY() - v.getTop()); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2563 | static private float squaredDistance(float[] point1, float[] point2) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2564 | float distanceX = point1[0] - point2[0]; |
| 2565 | float distanceY = point2[1] - point2[1]; |
| 2566 | return distanceX * distanceX + distanceY * distanceY; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2567 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2568 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2569 | /* |
| 2570 | * |
| 2571 | * Returns true if the passed CellLayout cl overlaps with dragView |
| 2572 | * |
| 2573 | */ |
| 2574 | boolean overlaps(CellLayout cl, DragView dragView, |
| 2575 | int dragViewX, int dragViewY, Matrix cachedInverseMatrix) { |
| 2576 | // Transform the coordinates of the item being dragged to the CellLayout's coordinates |
| 2577 | final float[] draggedItemTopLeft = mTempDragCoordinates; |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2578 | draggedItemTopLeft[0] = dragViewX; |
| 2579 | draggedItemTopLeft[1] = dragViewY; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2580 | final float[] draggedItemBottomRight = mTempDragBottomRightCoordinates; |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2581 | draggedItemBottomRight[0] = draggedItemTopLeft[0] + dragView.getDragRegionWidth(); |
| 2582 | draggedItemBottomRight[1] = draggedItemTopLeft[1] + dragView.getDragRegionHeight(); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2583 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2584 | // Transform the dragged item's top left coordinates |
| 2585 | // to the CellLayout's local coordinates |
| 2586 | mapPointFromSelfToChild(cl, draggedItemTopLeft, cachedInverseMatrix); |
| 2587 | float overlapRegionLeft = Math.max(0f, draggedItemTopLeft[0]); |
| 2588 | float overlapRegionTop = Math.max(0f, draggedItemTopLeft[1]); |
| 2589 | |
| 2590 | if (overlapRegionLeft <= cl.getWidth() && overlapRegionTop >= 0) { |
| 2591 | // Transform the dragged item's bottom right coordinates |
| 2592 | // to the CellLayout's local coordinates |
| 2593 | mapPointFromSelfToChild(cl, draggedItemBottomRight, cachedInverseMatrix); |
| 2594 | float overlapRegionRight = Math.min(cl.getWidth(), draggedItemBottomRight[0]); |
| 2595 | float overlapRegionBottom = Math.min(cl.getHeight(), draggedItemBottomRight[1]); |
| 2596 | |
| 2597 | if (overlapRegionRight >= 0 && overlapRegionBottom <= cl.getHeight()) { |
| 2598 | float overlap = (overlapRegionRight - overlapRegionLeft) * |
| 2599 | (overlapRegionBottom - overlapRegionTop); |
| 2600 | if (overlap > 0) { |
| 2601 | return true; |
| 2602 | } |
| 2603 | } |
| 2604 | } |
| 2605 | return false; |
| 2606 | } |
| 2607 | |
| 2608 | /* |
| 2609 | * |
| 2610 | * This method returns the CellLayout that is currently being dragged to. In order to drag |
| 2611 | * to a CellLayout, either the touch point must be directly over the CellLayout, or as a second |
| 2612 | * strategy, we see if the dragView is overlapping any CellLayout and choose the closest one |
| 2613 | * |
| 2614 | * Return null if no CellLayout is currently being dragged over |
| 2615 | * |
| 2616 | */ |
| 2617 | private CellLayout findMatchingPageForDragOver( |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 2618 | DragView dragView, float originX, float originY, boolean exact) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2619 | // We loop through all the screens (ie CellLayouts) and see which ones overlap |
| 2620 | // with the item being dragged and then choose the one that's closest to the touch point |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2621 | final int screenCount = getChildCount(); |
| 2622 | CellLayout bestMatchingScreen = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2623 | float smallestDistSoFar = Float.MAX_VALUE; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2624 | |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2625 | for (int i = 0; i < screenCount; i++) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2626 | CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2627 | |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 2628 | final float[] touchXy = {originX, originY}; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2629 | // Transform the touch coordinates to the CellLayout's local coordinates |
| 2630 | // If the touch point is within the bounds of the cell layout, we can return immediately |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2631 | cl.getMatrix().invert(mTempInverseMatrix); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2632 | mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2633 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2634 | if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && |
| 2635 | touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) { |
| 2636 | return cl; |
| 2637 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2638 | |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2639 | if (!exact) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2640 | // Get the center of the cell layout in screen coordinates |
| 2641 | final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates; |
| 2642 | cellLayoutCenter[0] = cl.getWidth()/2; |
| 2643 | cellLayoutCenter[1] = cl.getHeight()/2; |
| 2644 | mapPointFromChildToSelf(cl, cellLayoutCenter); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2645 | |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 2646 | touchXy[0] = originX; |
| 2647 | touchXy[1] = originY; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2648 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2649 | // Calculate the distance between the center of the CellLayout |
| 2650 | // and the touch point |
| 2651 | float dist = squaredDistance(touchXy, cellLayoutCenter); |
| 2652 | |
| 2653 | if (dist < smallestDistSoFar) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2654 | smallestDistSoFar = dist; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2655 | bestMatchingScreen = cl; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2656 | } |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2657 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2658 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2659 | return bestMatchingScreen; |
| 2660 | } |
| 2661 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2662 | // This is used to compute the visual center of the dragView. This point is then |
| 2663 | // used to visualize drop locations and determine where to drop an item. The idea is that |
| 2664 | // the visual center represents the user's interpretation of where the item is, and hence |
| 2665 | // is the appropriate point to use when determining drop location. |
| 2666 | private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset, |
| 2667 | DragView dragView, float[] recycle) { |
| 2668 | float res[]; |
| 2669 | if (recycle == null) { |
| 2670 | res = new float[2]; |
| 2671 | } else { |
| 2672 | res = recycle; |
| 2673 | } |
| 2674 | |
| 2675 | // First off, the drag view has been shifted in a way that is not represented in the |
| 2676 | // x and y values or the x/yOffsets. Here we account for that shift. |
| 2677 | x += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetX); |
| 2678 | y += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY); |
| 2679 | |
| 2680 | // These represent the visual top and left of drag view if a dragRect was provided. |
| 2681 | // If a dragRect was not provided, then they correspond to the actual view left and |
| 2682 | // top, as the dragRect is in that case taken to be the entire dragView. |
| 2683 | // R.dimen.dragViewOffsetY. |
| 2684 | int left = x - xOffset; |
| 2685 | int top = y - yOffset; |
| 2686 | |
| 2687 | // In order to find the visual center, we shift by half the dragRect |
| 2688 | res[0] = left + dragView.getDragRegion().width() / 2; |
| 2689 | res[1] = top + dragView.getDragRegion().height() / 2; |
| 2690 | |
| 2691 | return res; |
| 2692 | } |
| 2693 | |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 2694 | private boolean isDragWidget(DragObject d) { |
| 2695 | return (d.dragInfo instanceof LauncherAppWidgetInfo || |
| 2696 | d.dragInfo instanceof PendingAddWidgetInfo); |
| 2697 | } |
| 2698 | private boolean isExternalDragWidget(DragObject d) { |
| 2699 | return d.dragSource != this && isDragWidget(d); |
| 2700 | } |
| 2701 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2702 | public void onDragOver(DragObject d) { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2703 | // Skip drag over events while we are dragging over side pages |
Adam Cohen | 82ac8a2 | 2012-02-14 16:27:49 -0800 | [diff] [blame] | 2704 | if (mInScrollArea || mIsSwitchingState || mState == State.SMALL) return; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2705 | |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 2706 | Rect r = new Rect(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2707 | CellLayout layout = null; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2708 | ItemInfo item = (ItemInfo) d.dragInfo; |
| 2709 | |
| 2710 | // Ensure that we have proper spans for the item that we are dropping |
| 2711 | if (item.spanX < 0 || item.spanY < 0) throw new RuntimeException("Improper spans found"); |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 2712 | mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 2713 | d.dragView, mDragViewVisualCenter); |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 2714 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2715 | final View child = (mDragInfo == null) ? null : mDragInfo.cell; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2716 | // Identify whether we have dragged over a side page |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 2717 | if (isSmall()) { |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 2718 | if (mLauncher.getHotseat() != null && !isExternalDragWidget(d)) { |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 2719 | mLauncher.getHotseat().getHitRect(r); |
| 2720 | if (r.contains(d.x, d.y)) { |
| 2721 | layout = mLauncher.getHotseat().getLayout(); |
| 2722 | } |
| 2723 | } |
| 2724 | if (layout == null) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2725 | layout = findMatchingPageForDragOver(d.dragView, d.x, d.y, false); |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 2726 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2727 | if (layout != mDragTargetLayout) { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2728 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2729 | setCurrentDropLayout(layout); |
| 2730 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2731 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 2732 | boolean isInSpringLoadedMode = (mState == State.SPRING_LOADED); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2733 | if (isInSpringLoadedMode) { |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 2734 | if (mLauncher.isHotseatLayout(layout)) { |
| 2735 | mSpringLoadedDragController.cancel(); |
| 2736 | } else { |
| 2737 | mSpringLoadedDragController.setAlarm(mDragTargetLayout); |
| 2738 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2739 | } |
| 2740 | } |
| 2741 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2742 | // Test to see if we are over the hotseat otherwise just use the current page |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 2743 | if (mLauncher.getHotseat() != null && !isDragWidget(d)) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2744 | mLauncher.getHotseat().getHitRect(r); |
| 2745 | if (r.contains(d.x, d.y)) { |
| 2746 | layout = mLauncher.getHotseat().getLayout(); |
| 2747 | } |
| 2748 | } |
| 2749 | if (layout == null) { |
| 2750 | layout = getCurrentDropLayout(); |
| 2751 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2752 | if (layout != mDragTargetLayout) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2753 | setCurrentDropLayout(layout); |
| 2754 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | // Handle the drag over |
| 2759 | if (mDragTargetLayout != null) { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2760 | // We want the point to be mapped to the dragTarget. |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2761 | if (mLauncher.isHotseatLayout(mDragTargetLayout)) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2762 | mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2763 | } else { |
| 2764 | mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null); |
| 2765 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2766 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2767 | ItemInfo info = (ItemInfo) d.dragInfo; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 2768 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2769 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
| 2770 | (int) mDragViewVisualCenter[1], 1, 1, mDragTargetLayout, mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2771 | |
| 2772 | setCurrentDropOverCell(mTargetCell[0], mTargetCell[1]); |
| 2773 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2774 | float targetCellDistance = mDragTargetLayout.getDistanceFromCell( |
| 2775 | mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); |
| 2776 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2777 | final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], |
| 2778 | mTargetCell[1]); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 2779 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2780 | manageFolderFeedback(info, mDragTargetLayout, mTargetCell, |
| 2781 | targetCellDistance, dragOverView); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2782 | |
| 2783 | int minSpanX = item.spanX; |
| 2784 | int minSpanY = item.spanY; |
| 2785 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 2786 | minSpanX = item.minSpanX; |
| 2787 | minSpanY = item.minSpanY; |
| 2788 | } |
| 2789 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2790 | int[] reorderPosition = new int[2]; |
| 2791 | reorderPosition = findNearestArea((int) mDragViewVisualCenter[0], |
| 2792 | (int) mDragViewVisualCenter[1], item.spanX, item.spanY, mDragTargetLayout, |
| 2793 | reorderPosition); |
| 2794 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2795 | boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied((int) |
| 2796 | mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], item.spanX, |
| 2797 | item.spanY, child, mTargetCell); |
| 2798 | |
| 2799 | if (!nearestDropOccupied) { |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2800 | mDragTargetLayout.visualizeDropLocation(child, mDragOutline, |
| 2801 | (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], |
| 2802 | mTargetCell[0], mTargetCell[1], item.spanX, item.spanY, false, |
| 2803 | d.dragView.getDragVisualizeOffset(), d.dragView.getDragRegion()); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2804 | } else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER) |
| 2805 | && !mReorderAlarm.alarmPending() && (mLastReorderX != reorderPosition[0] || |
| 2806 | mLastReorderY != reorderPosition[1])) { |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2807 | // Otherwise, if we aren't adding to or creating a folder and there's no pending |
| 2808 | // reorder, then we schedule a reorder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2809 | ReorderAlarmListener listener = new ReorderAlarmListener(mDragViewVisualCenter, |
| 2810 | minSpanX, minSpanY, item.spanX, item.spanY, d.dragView, child); |
| 2811 | mReorderAlarm.setOnAlarmListener(listener); |
| 2812 | mReorderAlarm.setAlarm(REORDER_TIMEOUT); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | if (mDragMode == DRAG_MODE_CREATE_FOLDER || mDragMode == DRAG_MODE_ADD_TO_FOLDER || |
| 2816 | !nearestDropOccupied) { |
| 2817 | if (mDragTargetLayout != null) { |
| 2818 | mDragTargetLayout.revertTempState(); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2819 | } |
| 2820 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2821 | } |
| 2822 | } |
| 2823 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2824 | private void manageFolderFeedback(ItemInfo info, CellLayout targetLayout, |
| 2825 | int[] targetCell, float distance, View dragOverView) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2826 | boolean userFolderPending = willCreateUserFolder(info, targetLayout, targetCell, distance, |
| 2827 | false); |
| 2828 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2829 | if (mDragMode == DRAG_MODE_NONE && userFolderPending && |
| 2830 | !mFolderCreationAlarm.alarmPending()) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2831 | mFolderCreationAlarm.setOnAlarmListener(new |
| 2832 | FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1])); |
| 2833 | mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2834 | return; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | boolean willAddToFolder = |
| 2838 | willAddToExistingUserFolder(info, targetLayout, targetCell, distance); |
| 2839 | |
| 2840 | if (willAddToFolder && mDragMode == DRAG_MODE_NONE) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2841 | mDragOverFolderIcon = ((FolderIcon) dragOverView); |
| 2842 | mAddToExistingFolderOnDrop = true; |
| 2843 | mDragOverFolderIcon.onDragEnter(info); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2844 | if (targetLayout != null) { |
| 2845 | targetLayout.clearDragOutlines(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2846 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2847 | setDragMode(DRAG_MODE_ADD_TO_FOLDER); |
| 2848 | return; |
Patrick Dubroy | 976ebec | 2010-08-04 20:03:37 -0700 | [diff] [blame] | 2849 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2850 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2851 | if (mDragMode == DRAG_MODE_ADD_TO_FOLDER && !willAddToFolder) { |
| 2852 | setDragMode(DRAG_MODE_NONE); |
| 2853 | } |
| 2854 | if (mDragMode == DRAG_MODE_CREATE_FOLDER && !userFolderPending) { |
| 2855 | setDragMode(DRAG_MODE_NONE); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2856 | } |
| 2857 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2858 | return; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2861 | class FolderCreationAlarmListener implements OnAlarmListener { |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 2862 | CellLayout layout; |
| 2863 | int cellX; |
| 2864 | int cellY; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2865 | |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 2866 | public FolderCreationAlarmListener(CellLayout layout, int cellX, int cellY) { |
| 2867 | this.layout = layout; |
| 2868 | this.cellX = cellX; |
| 2869 | this.cellY = cellY; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | public void onAlarm(Alarm alarm) { |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2873 | if (mDragFolderRingAnimator == null) { |
| 2874 | mDragFolderRingAnimator = new FolderRingAnimator(mLauncher, null); |
| 2875 | } |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 2876 | mDragFolderRingAnimator.setCell(cellX, cellY); |
| 2877 | mDragFolderRingAnimator.setCellLayout(layout); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2878 | mDragFolderRingAnimator.animateToAcceptState(); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 2879 | layout.showFolderAccept(mDragFolderRingAnimator); |
| 2880 | layout.clearDragOutlines(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2881 | setDragMode(DRAG_MODE_CREATE_FOLDER); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2882 | } |
| 2883 | } |
| 2884 | |
| 2885 | class ReorderAlarmListener implements OnAlarmListener { |
| 2886 | float[] dragViewCenter; |
| 2887 | int minSpanX, minSpanY, spanX, spanY; |
| 2888 | DragView dragView; |
| 2889 | View child; |
| 2890 | |
| 2891 | public ReorderAlarmListener(float[] dragViewCenter, int minSpanX, int minSpanY, int spanX, |
| 2892 | int spanY, DragView dragView, View child) { |
| 2893 | this.dragViewCenter = dragViewCenter; |
| 2894 | this.minSpanX = minSpanX; |
| 2895 | this.minSpanY = minSpanY; |
| 2896 | this.spanX = spanX; |
| 2897 | this.spanY = spanY; |
| 2898 | this.child = child; |
| 2899 | this.dragView = dragView; |
| 2900 | } |
| 2901 | |
| 2902 | public void onAlarm(Alarm alarm) { |
| 2903 | int[] resultSpan = new int[2]; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2904 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
| 2905 | (int) mDragViewVisualCenter[1], spanX, spanY, mDragTargetLayout, mTargetCell); |
| 2906 | mLastReorderX = mTargetCell[0]; |
| 2907 | mLastReorderY = mTargetCell[1]; |
| 2908 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2909 | mTargetCell = mDragTargetLayout.createArea((int) mDragViewVisualCenter[0], |
| 2910 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, |
| 2911 | child, mTargetCell, resultSpan, CellLayout.MODE_DRAG_OVER); |
| 2912 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2913 | if (mTargetCell[0] < 0 || mTargetCell[1] < 0) { |
| 2914 | mDragTargetLayout.revertTempState(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2915 | } else { |
| 2916 | setDragMode(DRAG_MODE_REORDER); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2917 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2918 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2919 | boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY; |
| 2920 | mDragTargetLayout.visualizeDropLocation(child, mDragOutline, |
| 2921 | (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], |
| 2922 | mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, |
| 2923 | dragView.getDragVisualizeOffset(), dragView.getDragRegion()); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } |
| 2926 | |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 2927 | @Override |
| 2928 | public void getHitRect(Rect outRect) { |
| 2929 | // We want the workspace to have the whole area of the display (it will find the correct |
| 2930 | // cell layout to drop to in the existing drag/drop logic. |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 2931 | outRect.set(0, 0, mDisplaySize.x, mDisplaySize.y); |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 2932 | } |
| 2933 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2934 | /** |
| 2935 | * Add the item specified by dragInfo to the given layout. |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2936 | * @return true if successful |
| 2937 | */ |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 2938 | public boolean addExternalItemToScreen(ItemInfo dragInfo, CellLayout layout) { |
| 2939 | if (layout.findCellForSpan(mTempEstimate, dragInfo.spanX, dragInfo.spanY)) { |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 2940 | onDropExternal(dragInfo.dropPos, (ItemInfo) dragInfo, (CellLayout) layout, false); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2941 | return true; |
| 2942 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 2943 | mLauncher.showOutOfSpaceMessage(mLauncher.isHotseatLayout(layout)); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2944 | return false; |
| 2945 | } |
| 2946 | |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 2947 | private void onDropExternal(int[] touchXY, Object dragInfo, |
| 2948 | CellLayout cellLayout, boolean insertAtFirst) { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2949 | onDropExternal(touchXY, dragInfo, cellLayout, insertAtFirst, null); |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 2952 | /** |
| 2953 | * Drop an item that didn't originate on one of the workspace screens. |
| 2954 | * It may have come from Launcher (e.g. from all apps or customize), or it may have |
| 2955 | * come from another app altogether. |
| 2956 | * |
| 2957 | * NOTE: This can also be called when we are outside of a drag event, when we want |
| 2958 | * to add an item to one of the workspace screens. |
| 2959 | */ |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2960 | private void onDropExternal(final int[] touchXY, final Object dragInfo, |
| 2961 | final CellLayout cellLayout, boolean insertAtFirst, DragObject d) { |
| 2962 | final Runnable exitSpringLoadedRunnable = new Runnable() { |
| 2963 | @Override |
| 2964 | public void run() { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 2965 | mLauncher.exitSpringLoadedDragModeDelayed(true, false, null); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2966 | } |
| 2967 | }; |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 2968 | |
| 2969 | ItemInfo info = (ItemInfo) dragInfo; |
| 2970 | int spanX = info.spanX; |
| 2971 | int spanY = info.spanY; |
| 2972 | if (mDragInfo != null) { |
| 2973 | spanX = mDragInfo.spanX; |
| 2974 | spanY = mDragInfo.spanY; |
| 2975 | } |
| 2976 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2977 | final long container = mLauncher.isHotseatLayout(cellLayout) ? |
| 2978 | LauncherSettings.Favorites.CONTAINER_HOTSEAT : |
| 2979 | LauncherSettings.Favorites.CONTAINER_DESKTOP; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2980 | final int screen = indexOfChild(cellLayout); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2981 | if (!mLauncher.isHotseatLayout(cellLayout) && screen != mCurrentPage |
| 2982 | && mState != State.SPRING_LOADED) { |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 2983 | snapToPage(screen); |
| 2984 | } |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 2985 | |
| 2986 | if (info instanceof PendingAddItemInfo) { |
| 2987 | final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) dragInfo; |
| 2988 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 2989 | boolean findNearestVacantCell = true; |
| 2990 | if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { |
| 2991 | mTargetCell = findNearestArea((int) touchXY[0], (int) touchXY[1], spanX, spanY, |
| 2992 | cellLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2993 | float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 2994 | mDragViewVisualCenter[1], mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2995 | if (willCreateUserFolder((ItemInfo) d.dragInfo, cellLayout, mTargetCell, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2996 | distance, true) || willAddToExistingUserFolder((ItemInfo) d.dragInfo, |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2997 | cellLayout, mTargetCell, distance)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 2998 | findNearestVacantCell = false; |
| 2999 | } |
| 3000 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3001 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3002 | final ItemInfo item = (ItemInfo) d.dragInfo; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3003 | if (findNearestVacantCell) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3004 | int minSpanX = item.spanX; |
| 3005 | int minSpanY = item.spanY; |
| 3006 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 3007 | minSpanX = item.minSpanX; |
| 3008 | minSpanY = item.minSpanY; |
| 3009 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3010 | int[] resultSpan = new int[2]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3011 | mTargetCell = cellLayout.createArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3012 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY, |
| 3013 | null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3014 | item.spanX = resultSpan[0]; |
| 3015 | item.spanY = resultSpan[1]; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3018 | Runnable onAnimationCompleteRunnable = new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3019 | @Override |
| 3020 | public void run() { |
| 3021 | // When dragging and dropping from customization tray, we deal with creating |
| 3022 | // widgets/shortcuts/folders in a slightly different way |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3023 | switch (pendingInfo.itemType) { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3024 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3025 | int span[] = new int[2]; |
| 3026 | span[0] = item.spanX; |
| 3027 | span[1] = item.spanY; |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3028 | mLauncher.addAppWidgetFromDrop((PendingAddWidgetInfo) pendingInfo, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3029 | container, screen, mTargetCell, span, null); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3030 | break; |
| 3031 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3032 | mLauncher.processShortcutFromDrop(pendingInfo.componentName, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3033 | container, screen, mTargetCell, null); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3034 | break; |
| 3035 | default: |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3036 | throw new IllegalStateException("Unknown item type: " + |
| 3037 | pendingInfo.itemType); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3038 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3039 | } |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3040 | }; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3041 | View finalView = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET |
| 3042 | ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null; |
| 3043 | int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR; |
| 3044 | if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && |
| 3045 | ((PendingAddWidgetInfo) pendingInfo).info.configure != null) { |
| 3046 | animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN; |
| 3047 | } |
| 3048 | animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable, |
| 3049 | animationStyle, finalView, true); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 3050 | } else { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3051 | // This is for other drag/drop cases, like dragging from All Apps |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3052 | View view = null; |
| 3053 | |
| 3054 | switch (info.itemType) { |
| 3055 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 3056 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 3057 | if (info.container == NO_ID && info instanceof ApplicationInfo) { |
| 3058 | // Came from all apps -- make a copy |
Michael Jurka | c9d95c5 | 2011-08-29 14:03:34 -0700 | [diff] [blame] | 3059 | info = new ShortcutInfo((ApplicationInfo) info); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3060 | } |
| 3061 | view = mLauncher.createShortcut(R.layout.application, cellLayout, |
| 3062 | (ShortcutInfo) info); |
| 3063 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3064 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3065 | view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout, |
| 3066 | (FolderInfo) info, mIconCache); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3067 | break; |
| 3068 | default: |
| 3069 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 3070 | } |
| 3071 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3072 | // First we find the cell nearest to point at which the item is |
| 3073 | // dropped, without any consideration to whether there is an item there. |
| 3074 | if (touchXY != null) { |
| 3075 | mTargetCell = findNearestArea((int) touchXY[0], (int) touchXY[1], spanX, spanY, |
| 3076 | cellLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3077 | float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 3078 | mDragViewVisualCenter[1], mTargetCell); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3079 | d.postAnimationRunnable = exitSpringLoadedRunnable; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3080 | if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, |
| 3081 | true, d.dragView, d.postAnimationRunnable)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3082 | return; |
| 3083 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3084 | if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, |
| 3085 | true)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3086 | return; |
| 3087 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 3090 | if (touchXY != null) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3091 | // when dragging and dropping, just find the closest free spot |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3092 | mTargetCell = cellLayout.createArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3093 | (int) mDragViewVisualCenter[1], 1, 1, 1, 1, |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 3094 | null, mTargetCell, null, CellLayout.MODE_ON_DROP_EXTERNAL); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3095 | } else { |
| 3096 | cellLayout.findCellForSpan(mTargetCell, 1, 1); |
| 3097 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3098 | addInScreen(view, container, screen, mTargetCell[0], mTargetCell[1], info.spanX, |
| 3099 | info.spanY, insertAtFirst); |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 3100 | cellLayout.onDropChild(view); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 3101 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams(); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3102 | cellLayout.getShortcutsAndWidgets().measureChild(view); |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 3103 | |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 3104 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3105 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screen, |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3106 | lp.cellX, lp.cellY); |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 3107 | |
| 3108 | if (d.dragView != null) { |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3109 | // We wrap the animation call in the temporary set and reset of the current |
| 3110 | // cellLayout to its final transform -- this means we animate the drag view to |
| 3111 | // the correct final location. |
| 3112 | setFinalTransitionTransform(cellLayout); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3113 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3114 | exitSpringLoadedRunnable); |
| 3115 | resetTransitionTransform(cellLayout); |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 3116 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3117 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3118 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3119 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3120 | public Bitmap createWidgetBitmap(ItemInfo widgetInfo, View layout) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3121 | int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(widgetInfo.spanX, |
| 3122 | widgetInfo.spanY, widgetInfo, false); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3123 | int visibility = layout.getVisibility(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3124 | layout.setVisibility(VISIBLE); |
| 3125 | |
| 3126 | int width = MeasureSpec.makeMeasureSpec(unScaledSize[0], MeasureSpec.EXACTLY); |
| 3127 | int height = MeasureSpec.makeMeasureSpec(unScaledSize[1], MeasureSpec.EXACTLY); |
| 3128 | Bitmap b = Bitmap.createBitmap(unScaledSize[0], unScaledSize[1], |
| 3129 | Bitmap.Config.ARGB_8888); |
| 3130 | Canvas c = new Canvas(b); |
| 3131 | |
| 3132 | layout.measure(width, height); |
| 3133 | layout.layout(0, 0, unScaledSize[0], unScaledSize[1]); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3134 | layout.draw(c); |
| 3135 | c.setBitmap(null); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3136 | layout.setVisibility(visibility); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3137 | return b; |
| 3138 | } |
| 3139 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3140 | private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 3141 | DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3142 | boolean external) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3143 | // Now we animate the dragView, (ie. the widget or shortcut preview) into its final |
| 3144 | // location and size on the home screen. |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3145 | int spanX = info.spanX; |
| 3146 | int spanY = info.spanY; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3147 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3148 | Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY); |
| 3149 | loc[0] = r.left; |
| 3150 | loc[1] = r.top; |
| 3151 | |
| 3152 | setFinalTransitionTransform(layout); |
| 3153 | float cellLayoutScale = |
| 3154 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc); |
| 3155 | resetTransitionTransform(layout); |
| 3156 | float dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth(); |
| 3157 | float dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight(); |
| 3158 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3159 | // The animation will scale the dragView about its center, so we need to center about |
| 3160 | // the final location. |
| 3161 | loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2; |
| 3162 | loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2; |
| 3163 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3164 | scaleXY[0] = dragViewScaleX * cellLayoutScale; |
| 3165 | scaleXY[1] = dragViewScaleY * cellLayoutScale; |
| 3166 | } |
| 3167 | |
| 3168 | public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView, |
| 3169 | final Runnable onCompleteRunnable, int animationType, final View finalView, |
| 3170 | boolean external) { |
| 3171 | Rect from = new Rect(); |
| 3172 | mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from); |
| 3173 | |
| 3174 | int[] finalPos = new int[2]; |
| 3175 | float scaleXY[] = new float[2]; |
| 3176 | getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 3177 | external); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3178 | |
| 3179 | Resources res = mLauncher.getResources(); |
| 3180 | int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200; |
| 3181 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3182 | // In the case where we've prebound the widget, we remove it from the DragLayer |
| 3183 | if (finalView instanceof AppWidgetHostView && external) { |
| 3184 | mLauncher.getDragLayer().removeView(finalView); |
| 3185 | } |
| 3186 | if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null) { |
| 3187 | Bitmap crossFadeBitmap = createWidgetBitmap(info, finalView); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3188 | dragView.setCrossFadeBitmap(crossFadeBitmap); |
| 3189 | dragView.crossFade((int) (duration * 0.8f)); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3190 | } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET && external) { |
| 3191 | scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3192 | } |
| 3193 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3194 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 3195 | if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3196 | mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3197 | DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration); |
| 3198 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3199 | int endStyle; |
| 3200 | if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) { |
| 3201 | endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE; |
| 3202 | } else { |
| 3203 | endStyle = DragLayer.ANIMATION_END_DISAPPEAR;; |
| 3204 | } |
| 3205 | |
| 3206 | Runnable onComplete = new Runnable() { |
| 3207 | @Override |
| 3208 | public void run() { |
| 3209 | if (finalView != null) { |
| 3210 | finalView.setVisibility(VISIBLE); |
| 3211 | } |
| 3212 | if (onCompleteRunnable != null) { |
| 3213 | onCompleteRunnable.run(); |
| 3214 | } |
| 3215 | } |
| 3216 | }; |
| 3217 | dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], |
| 3218 | finalPos[1], 1, 1, 1, scaleXY[0], scaleXY[1], onComplete, endStyle, |
| 3219 | duration, this); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3223 | public void setFinalTransitionTransform(CellLayout layout) { |
| 3224 | if (isSwitchingState()) { |
| 3225 | int index = indexOfChild(layout); |
| 3226 | mCurrentScaleX = layout.getScaleX(); |
| 3227 | mCurrentScaleY = layout.getScaleY(); |
| 3228 | mCurrentTranslationX = layout.getTranslationX(); |
| 3229 | mCurrentTranslationY = layout.getTranslationY(); |
| 3230 | mCurrentRotationY = layout.getRotationY(); |
| 3231 | layout.setScaleX(mNewScaleXs[index]); |
| 3232 | layout.setScaleY(mNewScaleYs[index]); |
| 3233 | layout.setTranslationX(mNewTranslationXs[index]); |
| 3234 | layout.setTranslationY(mNewTranslationYs[index]); |
| 3235 | layout.setRotationY(mNewRotationYs[index]); |
| 3236 | } |
| 3237 | } |
| 3238 | public void resetTransitionTransform(CellLayout layout) { |
| 3239 | if (isSwitchingState()) { |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3240 | mCurrentScaleX = layout.getScaleX(); |
| 3241 | mCurrentScaleY = layout.getScaleY(); |
| 3242 | mCurrentTranslationX = layout.getTranslationX(); |
| 3243 | mCurrentTranslationY = layout.getTranslationY(); |
| 3244 | mCurrentRotationY = layout.getRotationY(); |
| 3245 | layout.setScaleX(mCurrentScaleX); |
| 3246 | layout.setScaleY(mCurrentScaleY); |
| 3247 | layout.setTranslationX(mCurrentTranslationX); |
| 3248 | layout.setTranslationY(mCurrentTranslationY); |
| 3249 | layout.setRotationY(mCurrentRotationY); |
| 3250 | } |
| 3251 | } |
| 3252 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3253 | /** |
| 3254 | * Return the current {@link CellLayout}, correctly picking the destination |
| 3255 | * screen while a scroll is in progress. |
| 3256 | */ |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3257 | public CellLayout getCurrentDropLayout() { |
Winson Chung | 360e63f | 2012-04-27 13:48:05 -0700 | [diff] [blame] | 3258 | return (CellLayout) getChildAt(getNextPage()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3261 | /** |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3262 | * Return the current CellInfo describing our current drag; this method exists |
| 3263 | * so that Launcher can sync this object with the correct info when the activity is created/ |
| 3264 | * destroyed |
| 3265 | * |
| 3266 | */ |
| 3267 | public CellLayout.CellInfo getDragInfo() { |
| 3268 | return mDragInfo; |
| 3269 | } |
| 3270 | |
| 3271 | /** |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3272 | * Calculate the nearest cell where the given object would be dropped. |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3273 | * |
| 3274 | * pixelX and pixelY should be in the coordinate system of layout |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3275 | */ |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3276 | private int[] findNearestArea(int pixelX, int pixelY, |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3277 | int spanX, int spanY, CellLayout layout, int[] recycle) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3278 | return layout.findNearestArea( |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3279 | pixelX, pixelY, spanX, spanY, recycle); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 3282 | void setup(DragController dragController) { |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 3283 | mSpringLoadedDragController = new SpringLoadedDragController(mLauncher); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3284 | mDragController = dragController; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3285 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3286 | // hardware layers on children are enabled on startup, but should be disabled until |
| 3287 | // needed |
| 3288 | updateChildrenLayersEnabled(); |
| 3289 | setWallpaperDimension(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3290 | } |
| 3291 | |
Patrick Dubroy | e3887cc | 2011-01-20 10:43:40 -0800 | [diff] [blame] | 3292 | /** |
| 3293 | * Called at the end of a drag which originated on the workspace. |
| 3294 | */ |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 3295 | public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, |
| 3296 | boolean success) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3297 | if (success) { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3298 | if (target != this) { |
| 3299 | if (mDragInfo != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3300 | getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3301 | if (mDragInfo.cell instanceof DropTarget) { |
| 3302 | mDragController.removeDropTarget((DropTarget) mDragInfo.cell); |
| 3303 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3304 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3305 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 3306 | } else if (mDragInfo != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3307 | CellLayout cellLayout; |
| 3308 | if (mLauncher.isHotseatLayout(target)) { |
| 3309 | cellLayout = mLauncher.getHotseat().getLayout(); |
| 3310 | } else { |
| 3311 | cellLayout = (CellLayout) getChildAt(mDragInfo.screen); |
| 3312 | } |
| 3313 | cellLayout.onDropChild(mDragInfo.cell); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3314 | } |
Adam Cohen | 36cc09b | 2011-09-29 17:33:15 -0700 | [diff] [blame] | 3315 | if (d.cancelled && mDragInfo.cell != null) { |
| 3316 | mDragInfo.cell.setVisibility(VISIBLE); |
| 3317 | } |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 3318 | mDragOutline = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3319 | mDragInfo = null; |
Winson Chung | 1afedc3 | 2012-01-23 16:14:56 -0800 | [diff] [blame] | 3320 | |
| 3321 | // Hide the scrolling indicator after you pick up an item |
| 3322 | hideScrollingIndicator(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3323 | } |
| 3324 | |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 3325 | void updateItemLocationsInDatabase(CellLayout cl) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3326 | int count = cl.getShortcutsAndWidgets().getChildCount(); |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 3327 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3328 | int screen = indexOfChild(cl); |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 3329 | int container = Favorites.CONTAINER_DESKTOP; |
| 3330 | |
| 3331 | if (mLauncher.isHotseatLayout(cl)) { |
| 3332 | screen = -1; |
| 3333 | container = Favorites.CONTAINER_HOTSEAT; |
| 3334 | } |
| 3335 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3336 | for (int i = 0; i < count; i++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3337 | View v = cl.getShortcutsAndWidgets().getChildAt(i); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3338 | ItemInfo info = (ItemInfo) v.getTag(); |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 3339 | // Null check required as the AllApps button doesn't have an item info |
| 3340 | if (info != null) { |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 3341 | LauncherModel.modifyItemInDatabase(mLauncher, info, container, screen, info.cellX, |
| 3342 | info.cellY, info.spanX, info.spanY); |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 3343 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3344 | } |
| 3345 | } |
| 3346 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 3347 | @Override |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 3348 | public boolean supportsFlingToDelete() { |
| 3349 | return true; |
| 3350 | } |
| 3351 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 3352 | @Override |
| 3353 | public void onFlingToDelete(DragObject d, int x, int y, PointF vec) { |
| 3354 | // Do nothing |
| 3355 | } |
| 3356 | |
| 3357 | @Override |
| 3358 | public void onFlingToDeleteCompleted() { |
| 3359 | // Do nothing |
| 3360 | } |
| 3361 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3362 | public boolean isDropEnabled() { |
| 3363 | return true; |
| 3364 | } |
| 3365 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3366 | @Override |
| 3367 | protected void onRestoreInstanceState(Parcelable state) { |
| 3368 | super.onRestoreInstanceState(state); |
| 3369 | Launcher.setScreen(mCurrentPage); |
| 3370 | } |
| 3371 | |
| 3372 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3373 | public void scrollLeft() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3374 | if (!isSmall() && !mIsSwitchingState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3375 | super.scrollLeft(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3376 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 3377 | Folder openFolder = getOpenFolder(); |
| 3378 | if (openFolder != null) { |
| 3379 | openFolder.completeDragExit(); |
| 3380 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3383 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3384 | public void scrollRight() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3385 | if (!isSmall() && !mIsSwitchingState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3386 | super.scrollRight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3387 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 3388 | Folder openFolder = getOpenFolder(); |
| 3389 | if (openFolder != null) { |
| 3390 | openFolder.completeDragExit(); |
| 3391 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3392 | } |
| 3393 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3394 | @Override |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3395 | public boolean onEnterScrollArea(int x, int y, int direction) { |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 3396 | // Ignore the scroll area if we are dragging over the hot seat |
Winson Chung | 10bfc6e | 2012-03-28 15:41:26 -0700 | [diff] [blame] | 3397 | boolean isPortrait = !LauncherApplication.isScreenLandscape(getContext()); |
| 3398 | if (mLauncher.getHotseat() != null && isPortrait) { |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 3399 | Rect r = new Rect(); |
| 3400 | mLauncher.getHotseat().getHitRect(r); |
| 3401 | if (r.contains(x, y)) { |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3402 | return false; |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 3403 | } |
| 3404 | } |
| 3405 | |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3406 | boolean result = false; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3407 | if (!isSmall() && !mIsSwitchingState) { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3408 | mInScrollArea = true; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3409 | |
Winson Chung | 360e63f | 2012-04-27 13:48:05 -0700 | [diff] [blame] | 3410 | final int page = getNextPage() + |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 3411 | (direction == DragController.SCROLL_LEFT ? -1 : 1); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3412 | |
| 3413 | // We always want to exit the current layout to ensure parity of enter / exit |
| 3414 | setCurrentDropLayout(null); |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3415 | |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 3416 | if (0 <= page && page < getChildCount()) { |
| 3417 | CellLayout layout = (CellLayout) getChildAt(page); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3418 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3419 | |
| 3420 | // Workspace is responsible for drawing the edge glow on adjacent pages, |
| 3421 | // so we need to redraw the workspace when this may have changed. |
| 3422 | invalidate(); |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3423 | result = true; |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3424 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3425 | } |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3426 | return result; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | @Override |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3430 | public boolean onExitScrollArea() { |
| 3431 | boolean result = false; |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3432 | if (mInScrollArea) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3433 | invalidate(); |
| 3434 | CellLayout layout = getCurrentDropLayout(); |
| 3435 | setCurrentDropLayout(layout); |
| 3436 | setCurrentDragOverlappingLayout(layout); |
| 3437 | |
Adam Cohen | 8a18afc | 2011-12-13 15:57:01 -0800 | [diff] [blame] | 3438 | result = true; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3439 | mInScrollArea = false; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3440 | } |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3441 | return result; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3444 | private void onResetScrollArea() { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3445 | setCurrentDragOverlappingLayout(null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3446 | mInScrollArea = false; |
| 3447 | } |
| 3448 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3449 | /** |
| 3450 | * Returns a specific CellLayout |
| 3451 | */ |
| 3452 | CellLayout getParentCellLayoutForView(View v) { |
| 3453 | ArrayList<CellLayout> layouts = getWorkspaceAndHotseatCellLayouts(); |
| 3454 | for (CellLayout layout : layouts) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3455 | if (layout.getShortcutsAndWidgets().indexOfChild(v) > -1) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3456 | return layout; |
| 3457 | } |
| 3458 | } |
| 3459 | return null; |
| 3460 | } |
| 3461 | |
| 3462 | /** |
| 3463 | * Returns a list of all the CellLayouts in the workspace. |
| 3464 | */ |
| 3465 | ArrayList<CellLayout> getWorkspaceAndHotseatCellLayouts() { |
| 3466 | ArrayList<CellLayout> layouts = new ArrayList<CellLayout>(); |
| 3467 | int screenCount = getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3468 | for (int screen = 0; screen < screenCount; screen++) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3469 | layouts.add(((CellLayout) getChildAt(screen))); |
| 3470 | } |
| 3471 | if (mLauncher.getHotseat() != null) { |
| 3472 | layouts.add(mLauncher.getHotseat().getLayout()); |
| 3473 | } |
| 3474 | return layouts; |
| 3475 | } |
| 3476 | |
| 3477 | /** |
| 3478 | * We should only use this to search for specific children. Do not use this method to modify |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3479 | * ShortcutsAndWidgetsContainer directly. Includes ShortcutAndWidgetContainers from |
| 3480 | * the hotseat and workspace pages |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3481 | */ |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3482 | ArrayList<ShortcutAndWidgetContainer> getAllShortcutAndWidgetContainers() { |
| 3483 | ArrayList<ShortcutAndWidgetContainer> childrenLayouts = |
| 3484 | new ArrayList<ShortcutAndWidgetContainer>(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3485 | int screenCount = getChildCount(); |
| 3486 | for (int screen = 0; screen < screenCount; screen++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3487 | childrenLayouts.add(((CellLayout) getChildAt(screen)).getShortcutsAndWidgets()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3488 | } |
| 3489 | if (mLauncher.getHotseat() != null) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3490 | childrenLayouts.add(mLauncher.getHotseat().getLayout().getShortcutsAndWidgets()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3491 | } |
| 3492 | return childrenLayouts; |
| 3493 | } |
| 3494 | |
| 3495 | public Folder getFolderForTag(Object tag) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3496 | ArrayList<ShortcutAndWidgetContainer> childrenLayouts = |
| 3497 | getAllShortcutAndWidgetContainers(); |
| 3498 | for (ShortcutAndWidgetContainer layout: childrenLayouts) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3499 | int count = layout.getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3500 | for (int i = 0; i < count; i++) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3501 | View child = layout.getChildAt(i); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3502 | if (child instanceof Folder) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3503 | Folder f = (Folder) child; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3504 | if (f.getInfo() == tag && f.getInfo().opened) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3505 | return f; |
| 3506 | } |
| 3507 | } |
| 3508 | } |
| 3509 | } |
| 3510 | return null; |
| 3511 | } |
| 3512 | |
| 3513 | public View getViewForTag(Object tag) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3514 | ArrayList<ShortcutAndWidgetContainer> childrenLayouts = |
| 3515 | getAllShortcutAndWidgetContainers(); |
| 3516 | for (ShortcutAndWidgetContainer layout: childrenLayouts) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3517 | int count = layout.getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3518 | for (int i = 0; i < count; i++) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3519 | View child = layout.getChildAt(i); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3520 | if (child.getTag() == tag) { |
| 3521 | return child; |
| 3522 | } |
| 3523 | } |
| 3524 | } |
| 3525 | return null; |
| 3526 | } |
| 3527 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3528 | void clearDropTargets() { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3529 | ArrayList<ShortcutAndWidgetContainer> childrenLayouts = |
| 3530 | getAllShortcutAndWidgetContainers(); |
| 3531 | for (ShortcutAndWidgetContainer layout: childrenLayouts) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3532 | int childCount = layout.getChildCount(); |
| 3533 | for (int j = 0; j < childCount; j++) { |
| 3534 | View v = layout.getChildAt(j); |
| 3535 | if (v instanceof DropTarget) { |
| 3536 | mDragController.removeDropTarget((DropTarget) v); |
| 3537 | } |
| 3538 | } |
| 3539 | } |
| 3540 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3541 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3542 | void removeItems(final ArrayList<ApplicationInfo> apps) { |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3543 | final AppWidgetManager widgets = AppWidgetManager.getInstance(getContext()); |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3544 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3545 | final HashSet<String> packageNames = new HashSet<String>(); |
| 3546 | final int appCount = apps.size(); |
| 3547 | for (int i = 0; i < appCount; i++) { |
| 3548 | packageNames.add(apps.get(i).componentName.getPackageName()); |
| 3549 | } |
| 3550 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3551 | ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); |
| 3552 | for (final CellLayout layoutParent: cellLayouts) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3553 | final ViewGroup layout = layoutParent.getShortcutsAndWidgets(); |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3554 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3555 | // Avoid ANRs by treating each screen separately |
| 3556 | post(new Runnable() { |
| 3557 | public void run() { |
| 3558 | final ArrayList<View> childrenToRemove = new ArrayList<View>(); |
| 3559 | childrenToRemove.clear(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3560 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3561 | int childCount = layout.getChildCount(); |
| 3562 | for (int j = 0; j < childCount; j++) { |
| 3563 | final View view = layout.getChildAt(j); |
| 3564 | Object tag = view.getTag(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3565 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3566 | if (tag instanceof ShortcutInfo) { |
| 3567 | final ShortcutInfo info = (ShortcutInfo) tag; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3568 | final Intent intent = info.intent; |
| 3569 | final ComponentName name = intent.getComponent(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3570 | |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 3571 | if (name != null) { |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 3572 | if (packageNames.contains(name.getPackageName())) { |
| 3573 | LauncherModel.deleteItemFromDatabase(mLauncher, info); |
| 3574 | childrenToRemove.add(view); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3575 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3576 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3577 | } else if (tag instanceof FolderInfo) { |
| 3578 | final FolderInfo info = (FolderInfo) tag; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3579 | final ArrayList<ShortcutInfo> contents = info.contents; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3580 | final int contentsCount = contents.size(); |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 3581 | final ArrayList<ShortcutInfo> appsToRemoveFromFolder = |
| 3582 | new ArrayList<ShortcutInfo>(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3583 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3584 | for (int k = 0; k < contentsCount; k++) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3585 | final ShortcutInfo appInfo = contents.get(k); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3586 | final Intent intent = appInfo.intent; |
| 3587 | final ComponentName name = intent.getComponent(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3588 | |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 3589 | if (name != null) { |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 3590 | if (packageNames.contains(name.getPackageName())) { |
| 3591 | appsToRemoveFromFolder.add(appInfo); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3592 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3593 | } |
| 3594 | } |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 3595 | for (ShortcutInfo item: appsToRemoveFromFolder) { |
| 3596 | info.remove(item); |
| 3597 | LauncherModel.deleteItemFromDatabase(mLauncher, item); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3598 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3599 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 3600 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag; |
Winson Chung | 11a4937 | 2012-04-27 15:12:38 -0700 | [diff] [blame] | 3601 | final ComponentName provider = info.providerName; |
Daniel Sandler | e1cc6c3 | 2010-05-07 11:49:29 -0400 | [diff] [blame] | 3602 | if (provider != null) { |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 3603 | if (packageNames.contains(provider.getPackageName())) { |
| 3604 | LauncherModel.deleteItemFromDatabase(mLauncher, info); |
| 3605 | childrenToRemove.add(view); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3606 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3607 | } |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3608 | } |
| 3609 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3610 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3611 | childCount = childrenToRemove.size(); |
| 3612 | for (int j = 0; j < childCount; j++) { |
| 3613 | View child = childrenToRemove.get(j); |
Winson Chung | 7a25a9e | 2011-01-30 13:33:56 -0800 | [diff] [blame] | 3614 | // Note: We can not remove the view directly from CellLayoutChildren as this |
| 3615 | // does not re-mark the spaces as unoccupied. |
| 3616 | layoutParent.removeViewInLayout(child); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3617 | if (child instanceof DropTarget) { |
| 3618 | mDragController.removeDropTarget((DropTarget)child); |
| 3619 | } |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3620 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3621 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3622 | if (childCount > 0) { |
| 3623 | layout.requestLayout(); |
| 3624 | layout.invalidate(); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 3625 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3626 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3627 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3628 | } |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 3629 | |
| 3630 | // It is no longer the case the BubbleTextViews correspond 1:1 with the workspace items in |
| 3631 | // the database (and LauncherModel) since shortcuts are not added and animated in until |
| 3632 | // the user returns to launcher. As a result, we really should be cleaning up the Db |
| 3633 | // regardless of whether the item was added or not (unlike the logic above). This is only |
| 3634 | // relevant for direct workspace items. |
| 3635 | post(new Runnable() { |
| 3636 | @Override |
| 3637 | public void run() { |
| 3638 | String spKey = LauncherApplication.getSharedPreferencesKey(); |
| 3639 | SharedPreferences sp = getContext().getSharedPreferences(spKey, |
| 3640 | Context.MODE_PRIVATE); |
| 3641 | Set<String> newApps = sp.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, |
| 3642 | null); |
| 3643 | |
| 3644 | for (String packageName: packageNames) { |
| 3645 | // Remove all items that have the same package, but were not removed above |
| 3646 | ArrayList<ShortcutInfo> infos = |
| 3647 | mLauncher.getModel().getShortcutInfosForPackage(packageName); |
| 3648 | for (ShortcutInfo info : infos) { |
| 3649 | LauncherModel.deleteItemFromDatabase(mLauncher, info); |
| 3650 | } |
| 3651 | // Remove all queued items that match the same package |
| 3652 | if (newApps != null) { |
| 3653 | for (String intentStr : newApps) { |
| 3654 | try { |
| 3655 | Intent intent = Intent.parseUri(intentStr, 0); |
Winson Chung | be36516 | 2012-05-07 10:34:12 -0700 | [diff] [blame] | 3656 | String pn = ItemInfo.getPackageName(intent); |
| 3657 | if (packageNames.contains(pn)) { |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 3658 | newApps.remove(intentStr); |
| 3659 | } |
| 3660 | } catch (URISyntaxException e) {} |
| 3661 | } |
| 3662 | } |
| 3663 | } |
| 3664 | } |
| 3665 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3666 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3667 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3668 | void updateShortcuts(ArrayList<ApplicationInfo> apps) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3669 | ArrayList<ShortcutAndWidgetContainer> childrenLayouts = getAllShortcutAndWidgetContainers(); |
| 3670 | for (ShortcutAndWidgetContainer layout: childrenLayouts) { |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3671 | int childCount = layout.getChildCount(); |
| 3672 | for (int j = 0; j < childCount; j++) { |
| 3673 | final View view = layout.getChildAt(j); |
| 3674 | Object tag = view.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3675 | if (tag instanceof ShortcutInfo) { |
Michael Jurka | e384aff | 2012-03-09 15:59:25 -0800 | [diff] [blame] | 3676 | ShortcutInfo info = (ShortcutInfo) tag; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3677 | // We need to check for ACTION_MAIN otherwise getComponent() might |
| 3678 | // return null for some shortcuts (for instance, for shortcuts to |
| 3679 | // web pages.) |
| 3680 | final Intent intent = info.intent; |
| 3681 | final ComponentName name = intent.getComponent(); |
| 3682 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3683 | Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { |
| 3684 | final int appCount = apps.size(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3685 | for (int k = 0; k < appCount; k++) { |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3686 | ApplicationInfo app = apps.get(k); |
| 3687 | if (app.componentName.equals(name)) { |
Michael Jurka | e384aff | 2012-03-09 15:59:25 -0800 | [diff] [blame] | 3688 | BubbleTextView shortcut = (BubbleTextView) view; |
| 3689 | info.updateIcon(mIconCache); |
| 3690 | info.title = app.title.toString(); |
| 3691 | shortcut.applyFromShortcutInfo(info, mIconCache); |
| 3692 | } |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3693 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | } |
| 3697 | } |
| 3698 | } |
| 3699 | |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 3700 | void moveToDefaultScreen(boolean animate) { |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 3701 | if (!isSmall()) { |
| 3702 | if (animate) { |
| 3703 | snapToPage(mDefaultPage); |
| 3704 | } else { |
| 3705 | setCurrentPage(mDefaultPage); |
| 3706 | } |
Joe Onorato | c45b168 | 2010-01-11 18:48:40 -0500 | [diff] [blame] | 3707 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3708 | getChildAt(mDefaultPage).requestFocus(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3709 | } |
| 3710 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3711 | @Override |
| 3712 | public void syncPages() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3713 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3714 | |
| 3715 | @Override |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 3716 | public void syncPageItems(int page, boolean immediate) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3717 | } |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 3718 | |
| 3719 | @Override |
| 3720 | protected String getCurrentPageDescription() { |
| 3721 | int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 3722 | return String.format(getContext().getString(R.string.workspace_scroll_format), |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 3723 | page + 1, getChildCount()); |
| 3724 | } |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 3725 | |
| 3726 | public void getLocationInDragLayer(int[] loc) { |
| 3727 | mLauncher.getDragLayer().getLocationInDragLayer(this, loc); |
| 3728 | } |
Winson Chung | 32174c8 | 2011-07-19 15:47:55 -0700 | [diff] [blame] | 3729 | |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 3730 | void setFadeForOverScroll(float fade) { |
| 3731 | if (!isScrollingIndicatorEnabled()) return; |
| 3732 | |
| 3733 | mOverscrollFade = fade; |
| 3734 | float reducedFade = 0.5f + 0.5f * (1 - fade); |
| 3735 | final ViewGroup parent = (ViewGroup) getParent(); |
Winson Chung | e96e5cb | 2011-11-28 13:02:56 -0800 | [diff] [blame] | 3736 | final ImageView qsbDivider = (ImageView) (parent.findViewById(R.id.qsb_divider)); |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 3737 | final ImageView dockDivider = (ImageView) (parent.findViewById(R.id.dock_divider)); |
Michael Jurka | afaa050 | 2011-12-13 18:22:50 -0800 | [diff] [blame] | 3738 | final View scrollIndicator = getScrollingIndicator(); |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 3739 | |
| 3740 | cancelScrollingIndicatorAnimations(); |
Winson Chung | e96e5cb | 2011-11-28 13:02:56 -0800 | [diff] [blame] | 3741 | if (qsbDivider != null) qsbDivider.setAlpha(reducedFade); |
| 3742 | if (dockDivider != null) dockDivider.setAlpha(reducedFade); |
Adam Cohen | 21b4110 | 2011-11-01 17:29:52 -0700 | [diff] [blame] | 3743 | scrollIndicator.setAlpha(1 - fade); |
| 3744 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3745 | } |