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