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