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; |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 20 | import android.animation.Animator.AnimatorListener; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 21 | import android.animation.AnimatorListenerAdapter; |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 22 | import android.animation.AnimatorSet; |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 23 | import android.animation.LayoutTransition; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 24 | import android.animation.ObjectAnimator; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 25 | import android.animation.PropertyValuesHolder; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 26 | import android.animation.TimeInterpolator; |
| 27 | import android.animation.ValueAnimator; |
| 28 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 29 | import android.app.WallpaperManager; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 30 | import android.appwidget.AppWidgetHostView; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 31 | import android.appwidget.AppWidgetProviderInfo; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 32 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | import android.content.Context; |
Michael Jurka | adc574c | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
Patrick Dubroy | 7247f63 | 2010-08-04 16:02:59 -0700 | [diff] [blame] | 35 | import android.content.res.Resources; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.content.res.TypedArray; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | import android.graphics.Canvas; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 39 | import android.graphics.Matrix; |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 40 | import android.graphics.Paint; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 41 | import android.graphics.Point; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 42 | import android.graphics.PointF; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.graphics.Rect; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 44 | import android.graphics.Region.Op; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.Drawable; |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 46 | import android.os.AsyncTask; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 47 | import android.os.Handler; |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 48 | import android.os.IBinder; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 49 | import android.os.Parcelable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | import android.util.AttributeSet; |
Daniel Sandler | 291ad12 | 2010-05-24 16:03:53 -0400 | [diff] [blame] | 51 | import android.util.Log; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 52 | import android.util.SparseArray; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 53 | import android.view.Choreographer; |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 54 | import android.view.Display; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 55 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 56 | import android.view.View; |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 57 | import android.view.ViewGroup; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 58 | import android.view.accessibility.AccessibilityManager; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 59 | import android.view.animation.DecelerateInterpolator; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 60 | import android.view.animation.Interpolator; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 61 | import android.widget.TextView; |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 62 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 63 | import com.android.launcher3.FolderIcon.FolderRingAnimator; |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 64 | import com.android.launcher3.Launcher.CustomContentCallbacks; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 65 | import com.android.launcher3.Launcher.LauncherOverlay; |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 66 | import com.android.launcher3.LauncherSettings.Favorites; |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 67 | import com.android.launcher3.compat.PackageInstallerCompat; |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 68 | import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 69 | import com.android.launcher3.compat.UserHandleCompat; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 70 | |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 71 | import java.util.ArrayList; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 72 | import java.util.HashMap; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 73 | import java.util.HashSet; |
Michael Jurka | 8bd65f5 | 2012-06-25 14:56:22 -0700 | [diff] [blame] | 74 | import java.util.Iterator; |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 75 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 76 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 77 | /** |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 78 | * The workspace is a wide area with a wallpaper and a finite number of pages. |
| 79 | * 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] | 80 | * 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] | 81 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 82 | public class Workspace extends SmoothPagedView |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 83 | implements DropTarget, DragSource, DragScroller, View.OnTouchListener, |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 84 | DragController.DragListener, LauncherTransitionable, ViewGroup.OnHierarchyChangeListener, |
| 85 | Insettable { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 86 | private static final String TAG = "Launcher.Workspace"; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 87 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 88 | private static final int CHILDREN_OUTLINE_FADE_OUT_DELAY = 0; |
| 89 | private static final int CHILDREN_OUTLINE_FADE_OUT_DURATION = 375; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 90 | private static final int CHILDREN_OUTLINE_FADE_IN_DURATION = 100; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 91 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 92 | protected static final int SNAP_OFF_EMPTY_SCREEN_DURATION = 400; |
| 93 | protected static final int FADE_EMPTY_SCREEN_DURATION = 150; |
| 94 | |
Winson Chung | f135c6c | 2010-11-18 16:32:08 -0800 | [diff] [blame] | 95 | private static final int BACKGROUND_FADE_OUT_DURATION = 350; |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 96 | private static final int ADJACENT_SCREEN_DROP_DURATION = 300; |
Adam Cohen | 265b9a6 | 2011-12-07 14:37:18 -0800 | [diff] [blame] | 97 | private static final int FLING_THRESHOLD_VELOCITY = 500; |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 98 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 99 | private static final float ALPHA_CUTOFF_THRESHOLD = 0.01f; |
| 100 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 101 | static final boolean MAP_NO_RECURSE = false; |
| 102 | static final boolean MAP_RECURSE = true; |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 103 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 104 | // These animators are used to fade the children's outlines |
| 105 | private ObjectAnimator mChildrenOutlineFadeInAnimation; |
| 106 | private ObjectAnimator mChildrenOutlineFadeOutAnimation; |
| 107 | private float mChildrenOutlineAlpha = 0; |
| 108 | |
| 109 | // 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] | 110 | private ValueAnimator mBackgroundFadeInAnimation; |
| 111 | private ValueAnimator mBackgroundFadeOutAnimation; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 112 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 113 | private static final long CUSTOM_CONTENT_GESTURE_DELAY = 200; |
| 114 | private long mTouchDownTime = -1; |
| 115 | private long mCustomContentShowTime = -1; |
| 116 | |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 117 | private LayoutTransition mLayoutTransition; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 118 | private final WallpaperManager mWallpaperManager; |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 119 | private IBinder mWindowToken; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 120 | |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 121 | private int mOriginalDefaultPage; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 122 | private int mDefaultPage; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 123 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 124 | private ShortcutAndWidgetContainer mDragSourceInternal; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 125 | private static boolean sAccessibilityEnabled; |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 126 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 127 | // The screen id used for the empty screen always present to the right. |
Adrian Roos | 8f3f683 | 2014-04-28 15:45:52 +0200 | [diff] [blame] | 128 | final static long EXTRA_EMPTY_SCREEN_ID = -201; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 129 | private final static long CUSTOM_CONTENT_SCREEN_ID = -301; |
| 130 | |
| 131 | private HashMap<Long, CellLayout> mWorkspaceScreens = new HashMap<Long, CellLayout>(); |
| 132 | private ArrayList<Long> mScreenOrder = new ArrayList<Long>(); |
| 133 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 134 | private Runnable mRemoveEmptyScreenRunnable; |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 135 | private boolean mDeferRemoveExtraEmptyScreen = false; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 136 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 137 | /** |
| 138 | * CellInfo for the cell that is currently being dragged |
| 139 | */ |
| 140 | private CellLayout.CellInfo mDragInfo; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 141 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 142 | /** |
| 143 | * Target drop area calculated during last acceptDrop call. |
| 144 | */ |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 145 | private int[] mTargetCell = new int[2]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 146 | private int mDragOverX = -1; |
| 147 | private int mDragOverY = -1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 148 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 149 | static Rect mLandscapeCellLayoutMetrics = null; |
| 150 | static Rect mPortraitCellLayoutMetrics = null; |
| 151 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 152 | CustomContentCallbacks mCustomContentCallbacks; |
| 153 | boolean mCustomContentShowing; |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 154 | private float mLastCustomContentScrollProgress = -1f; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 155 | private String mCustomContentDescription = ""; |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 156 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 157 | /** |
| 158 | * The CellLayout that is currently being dragged over |
| 159 | */ |
| 160 | private CellLayout mDragTargetLayout = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 161 | /** |
| 162 | * The CellLayout that we will show as glowing |
| 163 | */ |
| 164 | private CellLayout mDragOverlappingLayout = null; |
| 165 | |
| 166 | /** |
| 167 | * The CellLayout which will be dropped to |
| 168 | */ |
| 169 | private CellLayout mDropToLayout = null; |
| 170 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 171 | private Launcher mLauncher; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 172 | private IconCache mIconCache; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 173 | private DragController mDragController; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 174 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 175 | // These are temporary variables to prevent having to allocate a new object just to |
| 176 | // 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] | 177 | private int[] mTempCell = new int[2]; |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 178 | private int[] mTempPt = new int[2]; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 179 | private int[] mTempEstimate = new int[2]; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 180 | private float[] mDragViewVisualCenter = new float[2]; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 181 | private float[] mTempCellLayoutCenterCoordinates = new float[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 182 | private Matrix mTempInverseMatrix = new Matrix(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 183 | |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 184 | private SpringLoadedDragController mSpringLoadedDragController; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 185 | private float mSpringLoadedShrinkFactor; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 186 | private float mOverviewModeShrinkFactor; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 187 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 188 | // 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] | 189 | // in all apps or customize mode) |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 190 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 191 | enum State { NORMAL, NORMAL_HIDDEN, SPRING_LOADED, OVERVIEW, OVERVIEW_HIDDEN}; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 192 | private State mState = State.NORMAL; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 193 | private boolean mIsSwitchingState = false; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 194 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 195 | boolean mAnimatingViewIntoPlace = false; |
| 196 | boolean mIsDragOccuring = false; |
| 197 | boolean mChildrenLayersEnabled = true; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 198 | |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 199 | private boolean mStripScreensOnPageStopMoving = false; |
| 200 | |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 201 | /** 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] | 202 | private boolean mInScrollArea = false; |
| 203 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 204 | private HolographicOutlineHelper mOutlineHelper; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 205 | private Bitmap mDragOutline = null; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 206 | private static final Rect sTempRect = new Rect(); |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 207 | private final int[] mTempXY = new int[2]; |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 208 | private int[] mTempVisiblePagesRange = new int[2]; |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 209 | private boolean mOverscrollEffectSet; |
Michael Jurka | f8304f0 | 2012-04-26 13:33:26 -0700 | [diff] [blame] | 210 | public static final int DRAG_BITMAP_PADDING = 2; |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 211 | private boolean mWorkspaceFadeInAdjacentScreens; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 212 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 213 | WallpaperOffsetInterpolator mWallpaperOffset; |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 214 | private boolean mWallpaperIsLiveWallpaper; |
| 215 | private int mNumPagesForWallpaperParallax; |
| 216 | private float mLastSetWallpaperOffsetSteps = 0; |
| 217 | |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 218 | private Runnable mDelayedResizeRunnable; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 219 | private Runnable mDelayedSnapToPageRunnable; |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 220 | private Point mDisplaySize = new Point(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 221 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 222 | // 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] | 223 | private static final int FOLDER_CREATION_TIMEOUT = 0; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 224 | public static final int REORDER_TIMEOUT = 350; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 225 | private final Alarm mFolderCreationAlarm = new Alarm(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 226 | private final Alarm mReorderAlarm = new Alarm(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 227 | private FolderRingAnimator mDragFolderRingAnimator = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 228 | private FolderIcon mDragOverFolderIcon = null; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 229 | private boolean mCreateUserFolderOnDrop = false; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 230 | private boolean mAddToExistingFolderOnDrop = false; |
| 231 | private DropTarget.DragEnforcer mDragEnforcer; |
Adam Cohen | 3aff81c | 2012-05-16 21:01:01 -0700 | [diff] [blame] | 232 | private float mMaxDistanceForFolderCreation; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 233 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 234 | private final Canvas mCanvas = new Canvas(); |
| 235 | |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 236 | // Variables relating to touch disambiguation (scrolling workspace vs. scrolling a widget) |
| 237 | private float mXDown; |
| 238 | private float mYDown; |
| 239 | final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6; |
| 240 | final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3; |
| 241 | final static float TOUCH_SLOP_DAMPING_FACTOR = 4; |
| 242 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 243 | // Relating to the animation of items being dropped externally |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 244 | public static final int ANIMATE_INTO_POSITION_AND_DISAPPEAR = 0; |
| 245 | public static final int ANIMATE_INTO_POSITION_AND_REMAIN = 1; |
| 246 | public static final int ANIMATE_INTO_POSITION_AND_RESIZE = 2; |
| 247 | public static final int COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION = 3; |
| 248 | public static final int CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION = 4; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 249 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 250 | // Related to dragging, folder creation and reordering |
| 251 | private static final int DRAG_MODE_NONE = 0; |
| 252 | private static final int DRAG_MODE_CREATE_FOLDER = 1; |
| 253 | private static final int DRAG_MODE_ADD_TO_FOLDER = 2; |
| 254 | private static final int DRAG_MODE_REORDER = 3; |
| 255 | private int mDragMode = DRAG_MODE_NONE; |
| 256 | private int mLastReorderX = -1; |
| 257 | private int mLastReorderY = -1; |
| 258 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 259 | private SparseArray<Parcelable> mSavedStates; |
| 260 | private final ArrayList<Integer> mRestoredPages = new ArrayList<Integer>(); |
| 261 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 262 | // 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] | 263 | private int mSavedScrollX; |
| 264 | private float mSavedRotationY; |
| 265 | private float mSavedTranslationX; |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 266 | |
| 267 | private float mCurrentScale; |
| 268 | private float mNewScale; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 269 | private float[] mOldBackgroundAlphas; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 270 | private float[] mOldAlphas; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 271 | private float[] mNewBackgroundAlphas; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 272 | private float[] mNewAlphas; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 273 | private int mLastChildCount = -1; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 274 | private float mTransitionProgress; |
Adam Cohen | 08072c0 | 2014-11-18 17:53:44 -0800 | [diff] [blame] | 275 | private Animator mStateAnimator = null; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 276 | |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 277 | float mOverScrollEffect = 0f; |
| 278 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 279 | private Runnable mDeferredAction; |
| 280 | private boolean mDeferDropAfterUninstall; |
| 281 | private boolean mUninstallSuccessful; |
| 282 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 283 | // State related to Launcher Overlay |
| 284 | LauncherOverlay mLauncherOverlay; |
| 285 | boolean mScrollInteractionBegan; |
| 286 | boolean mStartedSendingScrollEvents; |
| 287 | boolean mShouldSendPageSettled; |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 288 | int mLastOverlaySroll = 0; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 289 | |
Romain Guy | eeacd56 | 2012-10-10 18:47:33 -0700 | [diff] [blame] | 290 | private final Runnable mBindPages = new Runnable() { |
| 291 | @Override |
| 292 | public void run() { |
| 293 | mLauncher.getModel().bindRemainingSynchronousPages(); |
| 294 | } |
| 295 | }; |
| 296 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 297 | /** |
| 298 | * Used to inflate the Workspace from XML. |
| 299 | * |
| 300 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 301 | * @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] | 302 | */ |
| 303 | public Workspace(Context context, AttributeSet attrs) { |
| 304 | this(context, attrs, 0); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Used to inflate the Workspace from XML. |
| 309 | * |
| 310 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 311 | * @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] | 312 | * @param defStyle Unused. |
| 313 | */ |
| 314 | public Workspace(Context context, AttributeSet attrs, int defStyle) { |
| 315 | super(context, attrs, defStyle); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 316 | mContentIsRefreshable = false; |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 317 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 318 | mOutlineHelper = HolographicOutlineHelper.obtain(context); |
| 319 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 320 | mDragEnforcer = new DropTarget.DragEnforcer(context); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 321 | // With workspace, data is available straight from the get-go |
| 322 | setDataIsReady(); |
| 323 | |
Michael Jurka | 8bc66c7 | 2012-06-21 08:36:45 -0700 | [diff] [blame] | 324 | mLauncher = (Launcher) context; |
Winson Chung | 867ca62 | 2012-02-21 15:48:35 -0800 | [diff] [blame] | 325 | final Resources res = getResources(); |
Adam Cohen | 3b185e2 | 2013-10-29 14:45:58 -0700 | [diff] [blame] | 326 | mWorkspaceFadeInAdjacentScreens = LauncherAppState.getInstance().getDynamicGrid(). |
| 327 | getDeviceProfile().shouldFadeAdjacentWorkspaceScreens(); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 328 | mFadeInAdjacentScreens = false; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 329 | mWallpaperManager = WallpaperManager.getInstance(context); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 330 | |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 331 | LauncherAppState app = LauncherAppState.getInstance(); |
| 332 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 333 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 334 | R.styleable.Workspace, defStyle, 0); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 335 | mSpringLoadedShrinkFactor = |
| 336 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 337 | mOverviewModeShrinkFactor = grid.getOverviewModeScale(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 338 | mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 339 | a.recycle(); |
| 340 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 341 | setOnHierarchyChangeListener(this); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 342 | setHapticFeedbackEnabled(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 343 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 344 | initWorkspace(); |
Winson Chung | c35afb2 | 2011-02-23 13:01:49 -0800 | [diff] [blame] | 345 | |
| 346 | // Disable multitouch across the workspace/all apps/customize tray |
| 347 | setMotionEventSplittingEnabled(true); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 348 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 349 | } |
| 350 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 351 | @Override |
| 352 | public void setInsets(Rect insets) { |
| 353 | mInsets.set(insets); |
Adam Cohen | 6400b84 | 2013-11-26 15:45:38 -0800 | [diff] [blame] | 354 | |
| 355 | CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); |
| 356 | if (customScreen != null) { |
| 357 | View customContent = customScreen.getShortcutsAndWidgets().getChildAt(0); |
| 358 | if (customContent instanceof Insettable) { |
| 359 | ((Insettable) customContent).setInsets(mInsets); |
| 360 | } |
| 361 | } |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 364 | // estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each |
| 365 | // dimension if unsuccessful |
| 366 | public int[] estimateItemSize(int hSpan, int vSpan, |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 367 | ItemInfo itemInfo, boolean springLoaded) { |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 368 | int[] size = new int[2]; |
| 369 | if (getChildCount() > 0) { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 370 | // Use the first non-custom page to estimate the child position |
| 371 | CellLayout cl = (CellLayout) getChildAt(numCustomPages()); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 372 | Rect r = estimateItemPosition(cl, itemInfo, 0, 0, hSpan, vSpan); |
| 373 | size[0] = r.width(); |
| 374 | size[1] = r.height(); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 375 | if (springLoaded) { |
| 376 | size[0] *= mSpringLoadedShrinkFactor; |
| 377 | size[1] *= mSpringLoadedShrinkFactor; |
| 378 | } |
| 379 | return size; |
| 380 | } else { |
| 381 | size[0] = Integer.MAX_VALUE; |
| 382 | size[1] = Integer.MAX_VALUE; |
| 383 | return size; |
| 384 | } |
| 385 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 386 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 387 | public Rect estimateItemPosition(CellLayout cl, ItemInfo pendingInfo, |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 388 | int hCell, int vCell, int hSpan, int vSpan) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 389 | Rect r = new Rect(); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 390 | cl.cellToRect(hCell, vCell, hSpan, vSpan, r); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 391 | return r; |
| 392 | } |
| 393 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 394 | public void onDragStart(final DragSource source, Object info, int dragAction) { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 395 | mIsDragOccuring = true; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 396 | updateChildrenLayersEnabled(false); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 397 | mLauncher.lockScreenOrientation(); |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 398 | mLauncher.onInteractionBegin(); |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 399 | setChildrenBackgroundAlphaMultipliers(1f); |
Winson Chung | f561bdf | 2012-05-03 11:20:19 -0700 | [diff] [blame] | 400 | // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging |
| 401 | InstallShortcutReceiver.enableInstallQueue(); |
| 402 | UninstallShortcutReceiver.enableUninstallQueue(); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 403 | post(new Runnable() { |
| 404 | @Override |
| 405 | public void run() { |
| 406 | if (mIsDragOccuring) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 407 | mDeferRemoveExtraEmptyScreen = false; |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 408 | addExtraEmptyScreenOnDrag(); |
| 409 | } |
| 410 | } |
| 411 | }); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 414 | |
| 415 | public void deferRemoveExtraEmptyScreen() { |
| 416 | mDeferRemoveExtraEmptyScreen = true; |
| 417 | } |
| 418 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 419 | public void onDragEnd() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 420 | if (!mDeferRemoveExtraEmptyScreen) { |
| 421 | removeExtraEmptyScreen(true, mDragSourceInternal != null); |
| 422 | } |
| 423 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 424 | mIsDragOccuring = false; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 425 | updateChildrenLayersEnabled(false); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 426 | mLauncher.unlockScreenOrientation(false); |
Winson Chung | f561bdf | 2012-05-03 11:20:19 -0700 | [diff] [blame] | 427 | |
| 428 | // Re-enable any Un/InstallShortcutReceiver and now process any queued items |
| 429 | InstallShortcutReceiver.disableAndFlushInstallQueue(getContext()); |
| 430 | UninstallShortcutReceiver.disableAndFlushUninstallQueue(getContext()); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 431 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 432 | mDragSourceInternal = null; |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 433 | mLauncher.onInteractionEnd(); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 434 | } |
| 435 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 436 | /** |
| 437 | * Initializes various states for this workspace. |
| 438 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 439 | protected void initWorkspace() { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 440 | mCurrentPage = mDefaultPage; |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 441 | LauncherAppState app = LauncherAppState.getInstance(); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 442 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 443 | mIconCache = app.getIconCache(); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 444 | setWillNotDraw(false); |
Romain Guy | ce3cbd1 | 2013-02-25 15:00:36 -0800 | [diff] [blame] | 445 | setClipChildren(false); |
| 446 | setClipToPadding(false); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 447 | setChildrenDrawnWithCacheEnabled(true); |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 448 | |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 449 | setMinScale(mOverviewModeShrinkFactor); |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 450 | setupLayoutTransition(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 451 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 452 | mWallpaperOffset = new WallpaperOffsetInterpolator(); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 453 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 454 | display.getSize(mDisplaySize); |
Adam Cohen | 265b9a6 | 2011-12-07 14:37:18 -0800 | [diff] [blame] | 455 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 456 | mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx); |
Adam Cohen | 265b9a6 | 2011-12-07 14:37:18 -0800 | [diff] [blame] | 457 | mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity); |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 458 | |
| 459 | // Set the wallpaper dimensions when Launcher starts up |
Adam Cohen | 824fcb3 | 2014-05-21 23:01:25 +0000 | [diff] [blame] | 460 | setWallpaperDimension(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 463 | private void setupLayoutTransition() { |
| 464 | // We want to show layout transitions when pages are deleted, to close the gap. |
| 465 | mLayoutTransition = new LayoutTransition(); |
| 466 | mLayoutTransition.enableTransitionType(LayoutTransition.DISAPPEARING); |
| 467 | mLayoutTransition.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 468 | mLayoutTransition.disableTransitionType(LayoutTransition.APPEARING); |
| 469 | mLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 470 | setLayoutTransition(mLayoutTransition); |
| 471 | } |
| 472 | |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 473 | void enableLayoutTransitions() { |
| 474 | setLayoutTransition(mLayoutTransition); |
| 475 | } |
| 476 | void disableLayoutTransitions() { |
| 477 | setLayoutTransition(null); |
| 478 | } |
| 479 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 480 | @Override |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 481 | protected int getScrollMode() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 482 | return SmoothPagedView.X_LARGE_MODE; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Michael Jurka | 08ee770 | 2011-08-11 16:53:35 -0700 | [diff] [blame] | 485 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 486 | public void onChildViewAdded(View parent, View child) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 487 | if (!(child instanceof CellLayout)) { |
| 488 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 489 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 490 | CellLayout cl = ((CellLayout) child); |
| 491 | cl.setOnInterceptTouchListener(this); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 492 | cl.setClickable(true); |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 493 | cl.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
Winson Chung | f70696d | 2013-06-25 16:19:53 -0700 | [diff] [blame] | 494 | super.onChildViewAdded(parent, child); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Michael Jurka | 920d7f4 | 2012-05-14 16:29:55 -0700 | [diff] [blame] | 497 | protected boolean shouldDrawChild(View child) { |
| 498 | final CellLayout cl = (CellLayout) child; |
| 499 | return super.shouldDrawChild(child) && |
Winson Chung | f4bd236 | 2013-10-07 17:11:27 -0700 | [diff] [blame] | 500 | (mIsSwitchingState || |
| 501 | cl.getShortcutsAndWidgets().getAlpha() > 0 || |
Michael Jurka | 920d7f4 | 2012-05-14 16:29:55 -0700 | [diff] [blame] | 502 | cl.getBackgroundAlpha() > 0); |
| 503 | } |
| 504 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 505 | /** |
| 506 | * @return The open folder on the current screen, or null if there is none |
| 507 | */ |
| 508 | Folder getOpenFolder() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 509 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 510 | int count = dragLayer.getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 511 | for (int i = 0; i < count; i++) { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 512 | View child = dragLayer.getChildAt(i); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 513 | if (child instanceof Folder) { |
| 514 | Folder folder = (Folder) child; |
| 515 | if (folder.getInfo().opened) |
| 516 | return folder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | return null; |
| 520 | } |
| 521 | |
Patrick Dubroy | a0aa012 | 2011-02-24 11:42:23 -0800 | [diff] [blame] | 522 | boolean isTouchActive() { |
| 523 | return mTouchState != TOUCH_STATE_REST; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 526 | public void removeAllWorkspaceScreens() { |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 527 | // Disable all layout transitions before removing all pages to ensure that we don't get the |
| 528 | // transition animations competing with us changing the scroll when we add pages or the |
| 529 | // custom content screen |
| 530 | disableLayoutTransitions(); |
| 531 | |
| 532 | // Since we increment the current page when we call addCustomContentPage via bindScreens |
| 533 | // (and other places), we need to adjust the current page back when we clear the pages |
| 534 | if (hasCustomContent()) { |
| 535 | removeCustomContentPage(); |
| 536 | } |
| 537 | |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 538 | // Remove the pages and clear the screen models |
| 539 | removeAllViews(); |
| 540 | mScreenOrder.clear(); |
| 541 | mWorkspaceScreens.clear(); |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 542 | |
| 543 | // Re-enable the layout transitions |
| 544 | enableLayoutTransitions(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 547 | public long insertNewWorkspaceScreenBeforeEmptyScreen(long screenId) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 548 | // Find the index to insert this view into. If the empty screen exists, then |
| 549 | // insert it before that. |
| 550 | int insertIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID); |
| 551 | if (insertIndex < 0) { |
| 552 | insertIndex = mScreenOrder.size(); |
| 553 | } |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 554 | return insertNewWorkspaceScreen(screenId, insertIndex); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 557 | public long insertNewWorkspaceScreen(long screenId) { |
| 558 | return insertNewWorkspaceScreen(screenId, getChildCount()); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 561 | public long insertNewWorkspaceScreen(long screenId, int insertIndex) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 562 | // Log to disk |
| 563 | Launcher.addDumpLog(TAG, "11683562 - insertNewWorkspaceScreen(): " + screenId + |
| 564 | " at index: " + insertIndex, true); |
| 565 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 566 | if (mWorkspaceScreens.containsKey(screenId)) { |
| 567 | throw new RuntimeException("Screen id " + screenId + " already exists!"); |
| 568 | } |
| 569 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 570 | CellLayout newScreen = (CellLayout) |
| 571 | mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null); |
| 572 | |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 573 | newScreen.setOnLongClickListener(mLongClickListener); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 574 | newScreen.setOnClickListener(mLauncher); |
Winson Chung | 837b241 | 2013-09-09 14:43:51 -0700 | [diff] [blame] | 575 | newScreen.setSoundEffectsEnabled(false); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 576 | mWorkspaceScreens.put(screenId, newScreen); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 577 | mScreenOrder.add(insertIndex, screenId); |
| 578 | addView(newScreen, insertIndex); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 579 | return screenId; |
| 580 | } |
| 581 | |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 582 | public void createCustomContentContainer() { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 583 | CellLayout customScreen = (CellLayout) |
Adam Cohen | 41eb470 | 2013-06-27 15:08:59 -0700 | [diff] [blame] | 584 | mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 585 | customScreen.disableBackground(); |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 586 | customScreen.disableDragTarget(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 587 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 588 | mWorkspaceScreens.put(CUSTOM_CONTENT_SCREEN_ID, customScreen); |
| 589 | mScreenOrder.add(0, CUSTOM_CONTENT_SCREEN_ID); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 590 | |
Adam Cohen | 2702ea0 | 2013-08-15 16:17:42 -0700 | [diff] [blame] | 591 | // We want no padding on the custom content |
| 592 | customScreen.setPadding(0, 0, 0, 0); |
| 593 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 594 | addFullScreenPage(customScreen); |
Michael Jurka | ee0ce2b | 2013-07-02 17:24:35 -0700 | [diff] [blame] | 595 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 596 | // Ensure that the current page and default page are maintained. |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 597 | mDefaultPage = mOriginalDefaultPage + 1; |
Winson Chung | 82e5c98 | 2013-10-09 12:04:50 -0700 | [diff] [blame] | 598 | |
| 599 | // Update the custom content hint |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 600 | if (mRestorePage != INVALID_RESTORE_PAGE) { |
| 601 | mRestorePage = mRestorePage + 1; |
| 602 | } else { |
| 603 | setCurrentPage(getCurrentPage() + 1); |
| 604 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 607 | public void removeCustomContentPage() { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 608 | CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); |
| 609 | if (customScreen == null) { |
| 610 | throw new RuntimeException("Expected custom content screen to exist"); |
| 611 | } |
| 612 | |
| 613 | mWorkspaceScreens.remove(CUSTOM_CONTENT_SCREEN_ID); |
| 614 | mScreenOrder.remove(CUSTOM_CONTENT_SCREEN_ID); |
| 615 | removeView(customScreen); |
Adam Cohen | bb6fda6 | 2013-10-10 12:48:52 -0700 | [diff] [blame] | 616 | |
| 617 | if (mCustomContentCallbacks != null) { |
| 618 | mCustomContentCallbacks.onScrollProgressChanged(0); |
| 619 | mCustomContentCallbacks.onHide(); |
| 620 | } |
| 621 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 622 | mCustomContentCallbacks = null; |
| 623 | |
| 624 | // Ensure that the current page and default page are maintained. |
| 625 | mDefaultPage = mOriginalDefaultPage - 1; |
Winson Chung | 82e5c98 | 2013-10-09 12:04:50 -0700 | [diff] [blame] | 626 | |
| 627 | // Update the custom content hint |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 628 | if (mRestorePage != INVALID_RESTORE_PAGE) { |
| 629 | mRestorePage = mRestorePage - 1; |
| 630 | } else { |
| 631 | setCurrentPage(getCurrentPage() - 1); |
| 632 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 633 | } |
| 634 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 635 | public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks, |
| 636 | String description) { |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 637 | if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) { |
| 638 | throw new RuntimeException("Expected custom content screen to exist"); |
| 639 | } |
| 640 | |
| 641 | // Add the custom content to the full screen custom page |
| 642 | CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); |
| 643 | int spanX = customScreen.getCountX(); |
| 644 | int spanY = customScreen.getCountY(); |
| 645 | CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY); |
| 646 | lp.canReorder = false; |
| 647 | lp.isFullscreen = true; |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 648 | if (customContent instanceof Insettable) { |
| 649 | ((Insettable)customContent).setInsets(mInsets); |
| 650 | } |
Adam Cohen | 166ebd4 | 2013-11-26 14:55:45 -0800 | [diff] [blame] | 651 | |
| 652 | // Verify that the child is removed from any existing parent. |
| 653 | if (customContent.getParent() instanceof ViewGroup) { |
| 654 | ViewGroup parent = (ViewGroup) customContent.getParent(); |
| 655 | parent.removeView(customContent); |
| 656 | } |
Adam Cohen | 225ad9b | 2013-10-07 13:03:00 -0700 | [diff] [blame] | 657 | customScreen.removeAllViews(); |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 658 | customScreen.addViewToCellLayout(customContent, 0, 0, lp, true); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 659 | mCustomContentDescription = description; |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 660 | |
| 661 | mCustomContentCallbacks = callbacks; |
| 662 | } |
| 663 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 664 | public void addExtraEmptyScreenOnDrag() { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 665 | // Log to disk |
| 666 | Launcher.addDumpLog(TAG, "11683562 - addExtraEmptyScreenOnDrag()", true); |
| 667 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 668 | boolean lastChildOnScreen = false; |
| 669 | boolean childOnFinalScreen = false; |
| 670 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 671 | // Cancel any pending removal of empty screen |
| 672 | mRemoveEmptyScreenRunnable = null; |
| 673 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 674 | if (mDragSourceInternal != null) { |
| 675 | if (mDragSourceInternal.getChildCount() == 1) { |
| 676 | lastChildOnScreen = true; |
| 677 | } |
| 678 | CellLayout cl = (CellLayout) mDragSourceInternal.getParent(); |
| 679 | if (indexOfChild(cl) == getChildCount() - 1) { |
| 680 | childOnFinalScreen = true; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | // If this is the last item on the final screen |
| 685 | if (lastChildOnScreen && childOnFinalScreen) { |
| 686 | return; |
| 687 | } |
| 688 | if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { |
| 689 | insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | public boolean addExtraEmptyScreen() { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 694 | // Log to disk |
| 695 | Launcher.addDumpLog(TAG, "11683562 - addExtraEmptyScreen()", true); |
| 696 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 697 | if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { |
| 698 | insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); |
| 699 | return true; |
| 700 | } |
| 701 | return false; |
| 702 | } |
| 703 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 704 | private void convertFinalScreenToEmptyScreenIfNecessary() { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 705 | // Log to disk |
| 706 | Launcher.addDumpLog(TAG, "11683562 - convertFinalScreenToEmptyScreenIfNecessary()", true); |
| 707 | |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 708 | if (mLauncher.isWorkspaceLoading()) { |
| 709 | // Invalid and dangerous operation if workspace is loading |
| 710 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 711 | return; |
| 712 | } |
| 713 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 714 | if (hasExtraEmptyScreen() || mScreenOrder.size() == 0) return; |
| 715 | long finalScreenId = mScreenOrder.get(mScreenOrder.size() - 1); |
| 716 | |
| 717 | if (finalScreenId == CUSTOM_CONTENT_SCREEN_ID) return; |
| 718 | CellLayout finalScreen = mWorkspaceScreens.get(finalScreenId); |
| 719 | |
| 720 | // If the final screen is empty, convert it to the extra empty screen |
Adam Cohen | 917e388 | 2013-10-31 15:03:35 -0700 | [diff] [blame] | 721 | if (finalScreen.getShortcutsAndWidgets().getChildCount() == 0 && |
| 722 | !finalScreen.isDropPending()) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 723 | mWorkspaceScreens.remove(finalScreenId); |
| 724 | mScreenOrder.remove(finalScreenId); |
| 725 | |
| 726 | // if this is the last non-custom content screen, convert it to the empty screen |
| 727 | mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, finalScreen); |
| 728 | mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID); |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 729 | |
Winson Chung | f0716b7 | 2013-11-18 16:09:54 -0800 | [diff] [blame] | 730 | // Update the model if we have changed any screens |
| 731 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 732 | Launcher.addDumpLog(TAG, "11683562 - extra empty screen: " + finalScreenId, true); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 736 | public void removeExtraEmptyScreen(final boolean animate, boolean stripEmptyScreens) { |
| 737 | removeExtraEmptyScreenDelayed(animate, null, 0, stripEmptyScreens); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 740 | public void removeExtraEmptyScreenDelayed(final boolean animate, final Runnable onComplete, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 741 | final int delay, final boolean stripEmptyScreens) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 742 | // Log to disk |
| 743 | Launcher.addDumpLog(TAG, "11683562 - removeExtraEmptyScreen()", true); |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 744 | if (mLauncher.isWorkspaceLoading()) { |
| 745 | // Don't strip empty screens if the workspace is still loading |
| 746 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 747 | return; |
| 748 | } |
| 749 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 750 | if (delay > 0) { |
| 751 | postDelayed(new Runnable() { |
| 752 | @Override |
| 753 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 754 | removeExtraEmptyScreenDelayed(animate, onComplete, 0, stripEmptyScreens); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 755 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 756 | }, delay); |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | convertFinalScreenToEmptyScreenIfNecessary(); |
| 761 | if (hasExtraEmptyScreen()) { |
| 762 | int emptyIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID); |
| 763 | if (getNextPage() == emptyIndex) { |
| 764 | snapToPage(getNextPage() - 1, SNAP_OFF_EMPTY_SCREEN_DURATION); |
| 765 | fadeAndRemoveEmptyScreen(SNAP_OFF_EMPTY_SCREEN_DURATION, FADE_EMPTY_SCREEN_DURATION, |
| 766 | onComplete, stripEmptyScreens); |
| 767 | } else { |
| 768 | fadeAndRemoveEmptyScreen(0, FADE_EMPTY_SCREEN_DURATION, |
| 769 | onComplete, stripEmptyScreens); |
| 770 | } |
| 771 | return; |
Adam Cohen | 3a14eeb | 2013-11-15 16:51:22 +0000 | [diff] [blame] | 772 | } else if (stripEmptyScreens) { |
| 773 | // If we're not going to strip the empty screens after removing |
| 774 | // the extra empty screen, do it right away. |
| 775 | stripEmptyScreens(); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 776 | } |
Adam Cohen | 3a14eeb | 2013-11-15 16:51:22 +0000 | [diff] [blame] | 777 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 778 | if (onComplete != null) { |
| 779 | onComplete.run(); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete, |
| 784 | final boolean stripEmptyScreens) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 785 | // Log to disk |
| 786 | // XXX: Do we need to update LM workspace screens below? |
| 787 | Launcher.addDumpLog(TAG, "11683562 - fadeAndRemoveEmptyScreen()", true); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 788 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f); |
| 789 | PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f); |
| 790 | |
| 791 | final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); |
| 792 | |
| 793 | mRemoveEmptyScreenRunnable = new Runnable() { |
| 794 | @Override |
| 795 | public void run() { |
| 796 | if (hasExtraEmptyScreen()) { |
| 797 | mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); |
| 798 | mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); |
| 799 | removeView(cl); |
| 800 | if (stripEmptyScreens) { |
| 801 | stripEmptyScreens(); |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | }; |
| 806 | |
| 807 | ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(cl, alpha, bgAlpha); |
| 808 | oa.setDuration(duration); |
| 809 | oa.setStartDelay(delay); |
| 810 | oa.addListener(new AnimatorListenerAdapter() { |
| 811 | @Override |
| 812 | public void onAnimationEnd(Animator animation) { |
| 813 | if (mRemoveEmptyScreenRunnable != null) { |
| 814 | mRemoveEmptyScreenRunnable.run(); |
| 815 | } |
| 816 | if (onComplete != null) { |
| 817 | onComplete.run(); |
| 818 | } |
| 819 | } |
| 820 | }); |
| 821 | oa.start(); |
| 822 | } |
| 823 | |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 824 | public boolean hasExtraEmptyScreen() { |
| 825 | int nScreens = getChildCount(); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 826 | nScreens = nScreens - numCustomPages(); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 827 | return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1; |
| 828 | } |
| 829 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 830 | public long commitExtraEmptyScreen() { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 831 | // Log to disk |
| 832 | Launcher.addDumpLog(TAG, "11683562 - commitExtraEmptyScreen()", true); |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 833 | if (mLauncher.isWorkspaceLoading()) { |
| 834 | // Invalid and dangerous operation if workspace is loading |
| 835 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 836 | return -1; |
| 837 | } |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 838 | |
Winson Chung | 89f9705 | 2013-09-20 11:32:26 -0700 | [diff] [blame] | 839 | int index = getPageIndexForScreenId(EXTRA_EMPTY_SCREEN_ID); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 840 | CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 841 | mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 842 | mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); |
| 843 | |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 844 | long newId = LauncherAppState.getLauncherProvider().generateNewScreenId(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 845 | mWorkspaceScreens.put(newId, cl); |
| 846 | mScreenOrder.add(newId); |
| 847 | |
Winson Chung | 89f9705 | 2013-09-20 11:32:26 -0700 | [diff] [blame] | 848 | // Update the page indicator marker |
| 849 | if (getPageIndicator() != null) { |
| 850 | getPageIndicator().updateMarker(index, getPageIndicatorMarker(index)); |
| 851 | } |
| 852 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 853 | // Update the model for the new screen |
| 854 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
| 855 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 856 | return newId; |
| 857 | } |
| 858 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 859 | public CellLayout getScreenWithId(long screenId) { |
| 860 | CellLayout layout = mWorkspaceScreens.get(screenId); |
| 861 | return layout; |
| 862 | } |
| 863 | |
| 864 | public long getIdForScreen(CellLayout layout) { |
| 865 | Iterator<Long> iter = mWorkspaceScreens.keySet().iterator(); |
| 866 | while (iter.hasNext()) { |
| 867 | long id = iter.next(); |
| 868 | if (mWorkspaceScreens.get(id) == layout) { |
| 869 | return id; |
| 870 | } |
| 871 | } |
| 872 | return -1; |
| 873 | } |
| 874 | |
| 875 | public int getPageIndexForScreenId(long screenId) { |
| 876 | return indexOfChild(mWorkspaceScreens.get(screenId)); |
| 877 | } |
| 878 | |
| 879 | public long getScreenIdForPageIndex(int index) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 880 | if (0 <= index && index < mScreenOrder.size()) { |
| 881 | return mScreenOrder.get(index); |
| 882 | } |
| 883 | return -1; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 886 | ArrayList<Long> getScreenOrder() { |
| 887 | return mScreenOrder; |
| 888 | } |
| 889 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 890 | public void stripEmptyScreens() { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 891 | // Log to disk |
| 892 | Launcher.addDumpLog(TAG, "11683562 - stripEmptyScreens()", true); |
| 893 | |
Adam Cohen | 65e4303 | 2014-03-03 11:37:21 -0800 | [diff] [blame] | 894 | if (mLauncher.isWorkspaceLoading()) { |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 895 | // Don't strip empty screens if the workspace is still loading. |
| 896 | // This is dangerous and can result in data loss. |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 897 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 898 | return; |
| 899 | } |
| 900 | |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 901 | if (isPageMoving()) { |
| 902 | mStripScreensOnPageStopMoving = true; |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | int currentPage = getNextPage(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 907 | ArrayList<Long> removeScreens = new ArrayList<Long>(); |
| 908 | for (Long id: mWorkspaceScreens.keySet()) { |
| 909 | CellLayout cl = mWorkspaceScreens.get(id); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 910 | if (id >= 0 && cl.getShortcutsAndWidgets().getChildCount() == 0) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 911 | removeScreens.add(id); |
| 912 | } |
| 913 | } |
| 914 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 915 | // We enforce at least one page to add new items to. In the case that we remove the last |
| 916 | // such screen, we convert the last screen to the empty screen |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 917 | int minScreens = 1 + numCustomPages(); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 918 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 919 | int pageShift = 0; |
| 920 | for (Long id: removeScreens) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 921 | Launcher.addDumpLog(TAG, "11683562 - removing id: " + id, true); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 922 | CellLayout cl = mWorkspaceScreens.get(id); |
| 923 | mWorkspaceScreens.remove(id); |
| 924 | mScreenOrder.remove(id); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 925 | |
| 926 | if (getChildCount() > minScreens) { |
| 927 | if (indexOfChild(cl) < currentPage) { |
| 928 | pageShift++; |
| 929 | } |
| 930 | removeView(cl); |
| 931 | } else { |
| 932 | // if this is the last non-custom content screen, convert it to the empty screen |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 933 | mRemoveEmptyScreenRunnable = null; |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 934 | mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, cl); |
| 935 | mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 936 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 937 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 938 | |
| 939 | if (!removeScreens.isEmpty()) { |
| 940 | // Update the model if we have changed any screens |
| 941 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
| 942 | } |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 943 | |
| 944 | if (pageShift >= 0) { |
| 945 | setCurrentPage(currentPage - pageShift); |
| 946 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | // See implementation for parameter definition. |
| 950 | void addInScreen(View child, long container, long screenId, |
| 951 | int x, int y, int spanX, int spanY) { |
| 952 | addInScreen(child, container, screenId, x, y, spanX, spanY, false, false); |
| 953 | } |
| 954 | |
| 955 | // At bind time, we use the rank (screenId) to compute x and y for hotseat items. |
| 956 | // See implementation for parameter definition. |
| 957 | void addInScreenFromBind(View child, long container, long screenId, int x, int y, |
| 958 | int spanX, int spanY) { |
| 959 | addInScreen(child, container, screenId, x, y, spanX, spanY, false, true); |
| 960 | } |
| 961 | |
| 962 | // See implementation for parameter definition. |
| 963 | void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, |
| 964 | boolean insert) { |
| 965 | addInScreen(child, container, screenId, x, y, spanX, spanY, insert, false); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 966 | } |
| 967 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 968 | /** |
| 969 | * Adds the specified child in the specified screen. The position and dimension of |
| 970 | * the child are defined by x, y, spanX and spanY. |
| 971 | * |
| 972 | * @param child The child to add in one of the workspace's screens. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 973 | * @param screenId The screen in which to add the child. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 974 | * @param x The X position of the child in the screen's grid. |
| 975 | * @param y The Y position of the child in the screen's grid. |
| 976 | * @param spanX The number of cells spanned horizontally by the child. |
| 977 | * @param spanY The number of cells spanned vertically by the child. |
| 978 | * @param insert When true, the child is inserted at the beginning of the children list. |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 979 | * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute |
| 980 | * the x and y position in which to place hotseat items. Otherwise |
| 981 | * we use the x and y position to compute the rank. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 982 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 983 | void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, |
| 984 | boolean insert, boolean computeXYFromRank) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 985 | if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 986 | if (getScreenWithId(screenId) == null) { |
| 987 | Log.e(TAG, "Skipping child, screenId " + screenId + " not found"); |
Winson Chung | 8481e32 | 2013-08-09 16:06:38 -0700 | [diff] [blame] | 988 | // DEBUGGING - Print out the stack trace to see where we are adding from |
| 989 | new Throwable().printStackTrace(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 990 | return; |
| 991 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 992 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 993 | if (screenId == EXTRA_EMPTY_SCREEN_ID) { |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 994 | // This should never happen |
| 995 | throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID"); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 998 | final CellLayout layout; |
| 999 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 1000 | layout = mLauncher.getHotseat().getLayout(); |
Sunny Goyal | b3726d9 | 2014-08-20 16:58:17 -0700 | [diff] [blame] | 1001 | child.setOnKeyListener(new HotseatIconKeyEventListener()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1002 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 1003 | // Hide folder title in the hotseat |
| 1004 | if (child instanceof FolderIcon) { |
| 1005 | ((FolderIcon) child).setTextVisible(false); |
| 1006 | } |
| 1007 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1008 | if (computeXYFromRank) { |
| 1009 | x = mLauncher.getHotseat().getCellXFromOrder((int) screenId); |
| 1010 | y = mLauncher.getHotseat().getCellYFromOrder((int) screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1011 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1012 | screenId = mLauncher.getHotseat().getOrderInHotseat(x, y); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1013 | } |
| 1014 | } else { |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 1015 | // Show folder title if not in the hotseat |
| 1016 | if (child instanceof FolderIcon) { |
| 1017 | ((FolderIcon) child).setTextVisible(true); |
| 1018 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1019 | layout = getScreenWithId(screenId); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1020 | child.setOnKeyListener(new IconKeyEventListener()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 1023 | ViewGroup.LayoutParams genericLp = child.getLayoutParams(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1024 | CellLayout.LayoutParams lp; |
| 1025 | if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1026 | lp = new CellLayout.LayoutParams(x, y, spanX, spanY); |
| 1027 | } else { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 1028 | lp = (CellLayout.LayoutParams) genericLp; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1029 | lp.cellX = x; |
| 1030 | lp.cellY = y; |
| 1031 | lp.cellHSpan = spanX; |
| 1032 | lp.cellVSpan = spanY; |
| 1033 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1034 | |
Adam Cohen | 7f4eabe | 2011-04-21 16:19:16 -0700 | [diff] [blame] | 1035 | if (spanX < 0 && spanY < 0) { |
| 1036 | lp.isLockedToGrid = false; |
| 1037 | } |
| 1038 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1039 | // Get the canonical child id to uniquely represent this view in this screen |
Adam Cohen | c76e1dd | 2013-11-14 11:09:14 +0000 | [diff] [blame] | 1040 | ItemInfo info = (ItemInfo) child.getTag(); |
| 1041 | int childId = mLauncher.getViewIdForItem(info); |
| 1042 | |
Michael Jurka | f3ca3ab | 2010-10-20 17:08:24 -0700 | [diff] [blame] | 1043 | boolean markCellsAsOccupied = !(child instanceof Folder); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1044 | if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1045 | // TODO: This branch occurs when the workspace is adding views |
| 1046 | // outside of the defined grid |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1047 | // maybe we should be deleting these items from the LauncherModel? |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 1048 | Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout", true); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1051 | if (!(child instanceof Folder)) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1052 | child.setHapticFeedbackEnabled(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1053 | child.setOnLongClickListener(mLongClickListener); |
| 1054 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1055 | if (child instanceof DropTarget) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1056 | mDragController.addDropTarget((DropTarget) child); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1057 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
Patrick Dubroy | d0ce1ec | 2011-01-19 18:47:27 -0800 | [diff] [blame] | 1060 | /** |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 1061 | * Called directly from a CellLayout (not by the framework), after we've been added as a |
| 1062 | * listener via setOnInterceptTouchEventListener(). This allows us to tell the CellLayout |
| 1063 | * that it should intercept touch events, which is not something that is normally supported. |
| 1064 | */ |
| 1065 | @Override |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1066 | public boolean onTouch(View v, MotionEvent event) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1067 | return (workspaceInModalState() || !isFinishedSwitchingState()) |
| 1068 | || (!workspaceInModalState() && indexOfChild(v) != mCurrentPage); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 1069 | } |
| 1070 | |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 1071 | public boolean isSwitchingState() { |
| 1072 | return mIsSwitchingState; |
| 1073 | } |
| 1074 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1075 | /** This differs from isSwitchingState in that we take into account how far the transition |
| 1076 | * has completed. */ |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 1077 | public boolean isFinishedSwitchingState() { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1078 | return !mIsSwitchingState || (mTransitionProgress > 0.5f); |
| 1079 | } |
| 1080 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1081 | protected void onWindowVisibilityChanged (int visibility) { |
| 1082 | mLauncher.onWindowVisibilityChanged(visibility); |
| 1083 | } |
| 1084 | |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1085 | @Override |
| 1086 | public boolean dispatchUnhandledMove(View focused, int direction) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1087 | if (workspaceInModalState() || !isFinishedSwitchingState()) { |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1088 | // when the home screens are shrunken, shouldn't allow side-scrolling |
| 1089 | return false; |
| 1090 | } |
| 1091 | return super.dispatchUnhandledMove(focused, direction); |
| 1092 | } |
| 1093 | |
| 1094 | @Override |
| 1095 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 1096 | switch (ev.getAction() & MotionEvent.ACTION_MASK) { |
| 1097 | case MotionEvent.ACTION_DOWN: |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1098 | mXDown = ev.getX(); |
| 1099 | mYDown = ev.getY(); |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1100 | mTouchDownTime = System.currentTimeMillis(); |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 1101 | break; |
| 1102 | case MotionEvent.ACTION_POINTER_UP: |
| 1103 | case MotionEvent.ACTION_UP: |
| 1104 | if (mTouchState == TOUCH_STATE_REST) { |
| 1105 | final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage); |
Adam Cohen | 83e5941 | 2014-09-17 16:46:55 -0700 | [diff] [blame] | 1106 | if (currentPage != null && !currentPage.lastDownOnOccupiedCell()) { |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 1107 | onWallpaperTap(ev); |
| 1108 | } |
| 1109 | } |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1110 | } |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1111 | return super.onInterceptTouchEvent(ev); |
| 1112 | } |
| 1113 | |
Jan-Willem Maarse | d3fbe68 | 2014-08-19 15:27:48 -0700 | [diff] [blame] | 1114 | @Override |
| 1115 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 1116 | // Ignore pointer scroll events if the custom content doesn't allow scrolling. |
| 1117 | if ((getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID) |
| 1118 | && (mCustomContentCallbacks != null) |
| 1119 | && !mCustomContentCallbacks.isScrollingAllowed()) { |
| 1120 | return false; |
| 1121 | } |
| 1122 | return super.onGenericMotionEvent(event); |
| 1123 | } |
| 1124 | |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1125 | protected void reinflateWidgetsIfNecessary() { |
| 1126 | final int clCount = getChildCount(); |
| 1127 | for (int i = 0; i < clCount; i++) { |
| 1128 | CellLayout cl = (CellLayout) getChildAt(i); |
| 1129 | ShortcutAndWidgetContainer swc = cl.getShortcutsAndWidgets(); |
| 1130 | final int itemCount = swc.getChildCount(); |
| 1131 | for (int j = 0; j < itemCount; j++) { |
| 1132 | View v = swc.getChildAt(j); |
| 1133 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1134 | if (v != null && v.getTag() instanceof LauncherAppWidgetInfo) { |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1135 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
| 1136 | LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) info.hostView; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1137 | if (lahv != null && lahv.isReinflateRequired()) { |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1138 | mLauncher.removeAppWidget(info); |
| 1139 | // Remove the current widget which is inflated with the wrong orientation |
| 1140 | cl.removeView(lahv); |
| 1141 | mLauncher.bindAppWidget(info); |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 1148 | @Override |
| 1149 | protected void determineScrollingStart(MotionEvent ev) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1150 | if (!isFinishedSwitchingState()) return; |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1151 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1152 | float deltaX = ev.getX() - mXDown; |
| 1153 | float absDeltaX = Math.abs(deltaX); |
| 1154 | float absDeltaY = Math.abs(ev.getY() - mYDown); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1155 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1156 | if (Float.compare(absDeltaX, 0f) == 0) return; |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1157 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1158 | float slope = absDeltaY / absDeltaX; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1159 | float theta = (float) Math.atan(slope); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1160 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1161 | if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1162 | cancelCurrentPageLongPress(); |
| 1163 | } |
| 1164 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1165 | boolean passRightSwipesToCustomContent = |
| 1166 | (mTouchDownTime - mCustomContentShowTime) > CUSTOM_CONTENT_GESTURE_DELAY; |
| 1167 | |
Adam Cohen | af9b0e5 | 2013-09-23 19:27:38 -0700 | [diff] [blame] | 1168 | boolean swipeInIgnoreDirection = isLayoutRtl() ? deltaX < 0 : deltaX > 0; |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1169 | boolean onCustomContentScreen = |
| 1170 | getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID; |
| 1171 | if (swipeInIgnoreDirection && onCustomContentScreen && passRightSwipesToCustomContent) { |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1172 | // Pass swipes to the right to the custom content page. |
| 1173 | return; |
| 1174 | } |
| 1175 | |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1176 | if (onCustomContentScreen && (mCustomContentCallbacks != null) |
| 1177 | && !mCustomContentCallbacks.isScrollingAllowed()) { |
| 1178 | // Don't allow workspace scrolling if the current custom content screen doesn't allow |
| 1179 | // scrolling. |
| 1180 | return; |
| 1181 | } |
| 1182 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1183 | if (theta > MAX_SWIPE_ANGLE) { |
| 1184 | // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace |
| 1185 | return; |
| 1186 | } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) { |
| 1187 | // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to |
| 1188 | // increase the touch slop to make it harder to begin scrolling the workspace. This |
| 1189 | // results in vertically scrolling widgets to more easily. The higher the angle, the |
| 1190 | // more we increase touch slop. |
| 1191 | theta -= START_DAMPING_TOUCH_SLOP_ANGLE; |
| 1192 | float extraRatio = (float) |
| 1193 | Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE))); |
| 1194 | super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio); |
| 1195 | } else { |
| 1196 | // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special |
| 1197 | super.determineScrollingStart(ev); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1198 | } |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 1201 | protected void onPageBeginMoving() { |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 1202 | super.onPageBeginMoving(); |
| 1203 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1204 | if (isHardwareAccelerated()) { |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1205 | updateChildrenLayersEnabled(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1206 | } else { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1207 | if (mNextPage != INVALID_PAGE) { |
| 1208 | // we're snapping to a particular screen |
| 1209 | enableChildrenCache(mCurrentPage, mNextPage); |
| 1210 | } else { |
| 1211 | // this is when user is actively dragging a particular screen, they might |
| 1212 | // swipe it either left or right (but we won't advance by more than one screen) |
| 1213 | enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1); |
| 1214 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 1218 | protected void onPageEndMoving() { |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 1219 | super.onPageEndMoving(); |
| 1220 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1221 | if (isHardwareAccelerated()) { |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1222 | updateChildrenLayersEnabled(false); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1223 | } else { |
| 1224 | clearChildrenCache(); |
| 1225 | } |
| 1226 | |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 1227 | if (mDragController.isDragging()) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1228 | if (workspaceInModalState()) { |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 1229 | // If we are in springloaded mode, then force an event to check if the current touch |
| 1230 | // is under a new page (to scroll to) |
Winson Chung | 25460a1 | 2013-04-01 18:21:28 -0700 | [diff] [blame] | 1231 | mDragController.forceTouchMove(); |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 1232 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 1233 | } |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 1234 | |
| 1235 | if (mDelayedResizeRunnable != null) { |
| 1236 | mDelayedResizeRunnable.run(); |
| 1237 | mDelayedResizeRunnable = null; |
| 1238 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1239 | |
| 1240 | if (mDelayedSnapToPageRunnable != null) { |
| 1241 | mDelayedSnapToPageRunnable.run(); |
| 1242 | mDelayedSnapToPageRunnable = null; |
| 1243 | } |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 1244 | if (mStripScreensOnPageStopMoving) { |
| 1245 | stripEmptyScreens(); |
| 1246 | mStripScreensOnPageStopMoving = false; |
| 1247 | } |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1248 | |
| 1249 | if (mShouldSendPageSettled) { |
| 1250 | mLauncherOverlay.onScrollSettled(); |
| 1251 | mShouldSendPageSettled = false; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | protected void onScrollInteractionBegin() { |
| 1256 | super.onScrollInteractionEnd(); |
| 1257 | mScrollInteractionBegan = true; |
| 1258 | } |
| 1259 | |
| 1260 | protected void onScrollInteractionEnd() { |
| 1261 | super.onScrollInteractionEnd(); |
| 1262 | mScrollInteractionBegan = false; |
| 1263 | if (mStartedSendingScrollEvents) { |
| 1264 | mStartedSendingScrollEvents = false; |
| 1265 | mLauncherOverlay.onScrollInteractionEnd(); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | public void setLauncherOverlay(LauncherOverlay overlay) { |
| 1270 | mLauncherOverlay = overlay; |
| 1271 | } |
| 1272 | |
| 1273 | @Override |
| 1274 | protected void overScroll(float amount) { |
| 1275 | boolean isRtl = isLayoutRtl(); |
| 1276 | boolean shouldOverScroll = (amount <= 0 && (!hasCustomContent() || isRtl)) || |
| 1277 | (amount >= 0 && (!hasCustomContent() || !isRtl)); |
| 1278 | |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1279 | boolean shouldScrollOverlay = mLauncherOverlay != null && |
| 1280 | ((amount <= 0 && !isRtl) || (amount >= 0 && isRtl)); |
| 1281 | |
| 1282 | boolean shouldZeroOverlay = mLauncherOverlay != null && mLastOverlaySroll != 0 && |
| 1283 | ((amount >= 0 && !isRtl) || (amount <= 0 && isRtl)); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1284 | |
| 1285 | if (shouldScrollOverlay) { |
| 1286 | if (!mStartedSendingScrollEvents && mScrollInteractionBegan) { |
| 1287 | mStartedSendingScrollEvents = true; |
| 1288 | mLauncherOverlay.onScrollInteractionBegin(); |
| 1289 | mShouldSendPageSettled = true; |
| 1290 | } |
| 1291 | int screenSize = getViewportWidth(); |
| 1292 | float f = (amount / screenSize); |
| 1293 | |
| 1294 | int progress = (int) Math.abs((f * 100)); |
| 1295 | |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1296 | mLastOverlaySroll = progress; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1297 | mLauncherOverlay.onScrollChange(progress, isRtl); |
| 1298 | } else if (shouldOverScroll) { |
| 1299 | dampedOverScroll(amount); |
| 1300 | mOverScrollEffect = acceleratedOverFactor(amount); |
| 1301 | } else { |
| 1302 | mOverScrollEffect = 0; |
| 1303 | } |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1304 | |
| 1305 | if (shouldZeroOverlay) { |
| 1306 | mLauncherOverlay.onScrollChange(0, isRtl); |
| 1307 | } |
Adam Cohen | 89cbbb9 | 2013-09-25 16:52:48 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | @Override |
| 1311 | protected void notifyPageSwitchListener() { |
| 1312 | super.notifyPageSwitchListener(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1313 | |
Adam Cohen | 6ad0e7d | 2013-07-24 13:55:41 -0700 | [diff] [blame] | 1314 | if (hasCustomContent() && getNextPage() == 0 && !mCustomContentShowing) { |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1315 | mCustomContentShowing = true; |
| 1316 | if (mCustomContentCallbacks != null) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1317 | mCustomContentCallbacks.onShow(false); |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1318 | mCustomContentShowTime = System.currentTimeMillis(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1319 | } |
Adam Cohen | 6ad0e7d | 2013-07-24 13:55:41 -0700 | [diff] [blame] | 1320 | } else if (hasCustomContent() && getNextPage() != 0 && mCustomContentShowing) { |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1321 | mCustomContentShowing = false; |
| 1322 | if (mCustomContentCallbacks != null) { |
| 1323 | mCustomContentCallbacks.onHide(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1326 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1327 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1328 | protected CustomContentCallbacks getCustomContentCallbacks() { |
| 1329 | return mCustomContentCallbacks; |
| 1330 | } |
| 1331 | |
Adam Cohen | 824fcb3 | 2014-05-21 23:01:25 +0000 | [diff] [blame] | 1332 | protected void setWallpaperDimension() { |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1333 | new AsyncTask<Void, Void, Void>() { |
| 1334 | public Void doInBackground(Void ... args) { |
| 1335 | String spKey = WallpaperCropActivity.getSharedPreferencesKey(); |
| 1336 | SharedPreferences sp = |
| 1337 | mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS); |
Adam Cohen | c29217b | 2014-05-18 03:17:15 +0000 | [diff] [blame] | 1338 | LauncherWallpaperPickerActivity.suggestWallpaperDimension(mLauncher.getResources(), |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 1339 | sp, mLauncher.getWindowManager(), mWallpaperManager, |
| 1340 | mLauncher.overrideWallpaperDimensions()); |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1341 | return null; |
| 1342 | } |
| 1343 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 1344 | } |
| 1345 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1346 | protected void snapToPage(int whichPage, Runnable r) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1347 | snapToPage(whichPage, SLOW_PAGE_SNAP_ANIMATION_DURATION, r); |
| 1348 | } |
| 1349 | |
| 1350 | protected void snapToPage(int whichPage, int duration, Runnable r) { |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1351 | if (mDelayedSnapToPageRunnable != null) { |
| 1352 | mDelayedSnapToPageRunnable.run(); |
| 1353 | } |
| 1354 | mDelayedSnapToPageRunnable = r; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1355 | snapToPage(whichPage, duration); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1356 | } |
| 1357 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 1358 | public void snapToScreenId(long screenId) { |
| 1359 | snapToScreenId(screenId, null); |
| 1360 | } |
| 1361 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1362 | protected void snapToScreenId(long screenId, Runnable r) { |
| 1363 | snapToPage(getPageIndexForScreenId(screenId), r); |
| 1364 | } |
| 1365 | |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1366 | class WallpaperOffsetInterpolator implements Choreographer.FrameCallback { |
| 1367 | float mFinalOffset = 0.0f; |
Michael Jurka | 046cf34 | 2013-09-14 16:40:34 +0200 | [diff] [blame] | 1368 | float mCurrentOffset = 0.5f; // to force an initial update |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1369 | boolean mWaitingForUpdate; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1370 | Choreographer mChoreographer; |
| 1371 | Interpolator mInterpolator; |
| 1372 | boolean mAnimating; |
| 1373 | long mAnimationStartTime; |
| 1374 | float mAnimationStartOffset; |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1375 | private final int ANIMATION_DURATION = 250; |
| 1376 | // Don't use all the wallpaper for parallax until you have at least this many pages |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1377 | private final int MIN_PARALLAX_PAGE_SPAN = 3; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1378 | int mNumScreens; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1379 | |
| 1380 | public WallpaperOffsetInterpolator() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1381 | mChoreographer = Choreographer.getInstance(); |
| 1382 | mInterpolator = new DecelerateInterpolator(1.5f); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1383 | } |
| 1384 | |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1385 | @Override |
| 1386 | public void doFrame(long frameTimeNanos) { |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1387 | updateOffset(false); |
| 1388 | } |
| 1389 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1390 | private void updateOffset(boolean force) { |
| 1391 | if (mWaitingForUpdate || force) { |
| 1392 | mWaitingForUpdate = false; |
Michael Jurka | 1bd90b0 | 2013-09-05 23:10:14 +0200 | [diff] [blame] | 1393 | if (computeScrollOffset() && mWindowToken != null) { |
| 1394 | try { |
| 1395 | mWallpaperManager.setWallpaperOffsets(mWindowToken, |
| 1396 | mWallpaperOffset.getCurrX(), 0.5f); |
| 1397 | setWallpaperOffsetSteps(); |
| 1398 | } catch (IllegalArgumentException e) { |
| 1399 | Log.e(TAG, "Error updating wallpaper offset: " + e); |
| 1400 | } |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1401 | } |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1402 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1405 | public boolean computeScrollOffset() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1406 | final float oldOffset = mCurrentOffset; |
| 1407 | if (mAnimating) { |
| 1408 | long durationSinceAnimation = System.currentTimeMillis() - mAnimationStartTime; |
| 1409 | float t0 = durationSinceAnimation / (float) ANIMATION_DURATION; |
| 1410 | float t1 = mInterpolator.getInterpolation(t0); |
| 1411 | mCurrentOffset = mAnimationStartOffset + |
| 1412 | (mFinalOffset - mAnimationStartOffset) * t1; |
| 1413 | mAnimating = durationSinceAnimation < ANIMATION_DURATION; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1414 | } else { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1415 | mCurrentOffset = mFinalOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1416 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1417 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1418 | if (Math.abs(mCurrentOffset - mFinalOffset) > 0.0000001f) { |
| 1419 | scheduleUpdate(); |
| 1420 | } |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1421 | if (Math.abs(oldOffset - mCurrentOffset) > 0.0000001f) { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1422 | return true; |
| 1423 | } |
| 1424 | return false; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1425 | } |
| 1426 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1427 | private float wallpaperOffsetForCurrentScroll() { |
| 1428 | if (getChildCount() <= 1) { |
| 1429 | return 0; |
| 1430 | } |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1431 | |
| 1432 | // Exclude the leftmost page |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1433 | int emptyExtraPages = numEmptyScreensToIgnore(); |
| 1434 | int firstIndex = numCustomPages(); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1435 | // Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages) |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1436 | int lastIndex = getChildCount() - 1 - emptyExtraPages; |
| 1437 | if (isLayoutRtl()) { |
| 1438 | int temp = firstIndex; |
| 1439 | firstIndex = lastIndex; |
| 1440 | lastIndex = temp; |
| 1441 | } |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1442 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1443 | int firstPageScrollX = getScrollForPage(firstIndex); |
| 1444 | int scrollRange = getScrollForPage(lastIndex) - firstPageScrollX; |
| 1445 | if (scrollRange == 0) { |
| 1446 | return 0; |
| 1447 | } else { |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1448 | // TODO: do different behavior if it's a live wallpaper? |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1449 | // Sometimes the left parameter of the pages is animated during a layout transition; |
| 1450 | // this parameter offsets it to keep the wallpaper from animating as well |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1451 | int adjustedScroll = |
Michael Jurka | 8fd3adc | 2013-10-16 13:50:24 -0700 | [diff] [blame] | 1452 | getScrollX() - firstPageScrollX - getLayoutTransitionOffsetForPage(0); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1453 | float offset = Math.min(1, adjustedScroll / (float) scrollRange); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1454 | offset = Math.max(0, offset); |
| 1455 | // Don't use up all the wallpaper parallax until you have at least |
| 1456 | // MIN_PARALLAX_PAGE_SPAN pages |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1457 | int numScrollingPages = getNumScreensExcludingEmptyAndCustom(); |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 1458 | int parallaxPageSpan; |
| 1459 | if (mWallpaperIsLiveWallpaper) { |
| 1460 | parallaxPageSpan = numScrollingPages - 1; |
| 1461 | } else { |
| 1462 | parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages - 1); |
| 1463 | } |
| 1464 | mNumPagesForWallpaperParallax = parallaxPageSpan; |
| 1465 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1466 | // On RTL devices, push the wallpaper offset to the right if we don't have enough |
| 1467 | // pages (ie if numScrollingPages < MIN_PARALLAX_PAGE_SPAN) |
| 1468 | int padding = isLayoutRtl() ? parallaxPageSpan - numScrollingPages + 1 : 0; |
| 1469 | return offset * (padding + numScrollingPages - 1) / parallaxPageSpan; |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1473 | private int numEmptyScreensToIgnore() { |
| 1474 | int numScrollingPages = getChildCount() - numCustomPages(); |
| 1475 | if (numScrollingPages >= MIN_PARALLAX_PAGE_SPAN && hasExtraEmptyScreen()) { |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1476 | return 1; |
| 1477 | } else { |
| 1478 | return 0; |
| 1479 | } |
| 1480 | } |
| 1481 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1482 | private int getNumScreensExcludingEmptyAndCustom() { |
| 1483 | int numScrollingPages = getChildCount() - numEmptyScreensToIgnore() - numCustomPages(); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1484 | return numScrollingPages; |
| 1485 | } |
| 1486 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1487 | public void syncWithScroll() { |
| 1488 | float offset = wallpaperOffsetForCurrentScroll(); |
| 1489 | mWallpaperOffset.setFinalX(offset); |
| 1490 | updateOffset(true); |
| 1491 | } |
| 1492 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1493 | public float getCurrX() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1494 | return mCurrentOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | public float getFinalX() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1498 | return mFinalOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1501 | private void animateToFinal() { |
| 1502 | mAnimating = true; |
| 1503 | mAnimationStartOffset = mCurrentOffset; |
| 1504 | mAnimationStartTime = System.currentTimeMillis(); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1505 | } |
| 1506 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1507 | private void setWallpaperOffsetSteps() { |
| 1508 | // Set wallpaper offset steps (1 / (number of screens - 1)) |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 1509 | float xOffset = 1.0f / mNumPagesForWallpaperParallax; |
| 1510 | if (xOffset != mLastSetWallpaperOffsetSteps) { |
| 1511 | mWallpaperManager.setWallpaperOffsetSteps(xOffset, 1.0f); |
| 1512 | mLastSetWallpaperOffsetSteps = xOffset; |
| 1513 | } |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1514 | } |
| 1515 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1516 | public void setFinalX(float x) { |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1517 | scheduleUpdate(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1518 | mFinalOffset = Math.max(0f, Math.min(x, 1.0f)); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1519 | if (getNumScreensExcludingEmptyAndCustom() != mNumScreens) { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1520 | if (mNumScreens > 0) { |
| 1521 | // Don't animate if we're going from 0 screens |
| 1522 | animateToFinal(); |
| 1523 | } |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1524 | mNumScreens = getNumScreensExcludingEmptyAndCustom(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1525 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1528 | private void scheduleUpdate() { |
| 1529 | if (!mWaitingForUpdate) { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1530 | mChoreographer.postFrameCallback(this); |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1531 | mWaitingForUpdate = true; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1532 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | public void jumpToFinal() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1536 | mCurrentOffset = mFinalOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1537 | } |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 1538 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1539 | |
Michael Jurka | 340c5f3 | 2010-10-21 16:49:19 -0700 | [diff] [blame] | 1540 | @Override |
| 1541 | public void computeScroll() { |
| 1542 | super.computeScroll(); |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1543 | mWallpaperOffset.syncWithScroll(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1544 | } |
| 1545 | |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 1546 | @Override |
| 1547 | public void announceForAccessibility(CharSequence text) { |
| 1548 | // Don't announce if apps is on top of us. |
| 1549 | if (!mLauncher.isAllAppsVisible()) { |
| 1550 | super.announceForAccessibility(text); |
| 1551 | } |
| 1552 | } |
| 1553 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1554 | void showOutlines() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1555 | if (!workspaceInModalState() && !mIsSwitchingState) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1556 | if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel(); |
| 1557 | if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel(); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 1558 | mChildrenOutlineFadeInAnimation = LauncherAnimUtils.ofFloat(this, "childrenOutlineAlpha", 1.0f); |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1559 | mChildrenOutlineFadeInAnimation.setDuration(CHILDREN_OUTLINE_FADE_IN_DURATION); |
| 1560 | mChildrenOutlineFadeInAnimation.start(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1561 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1564 | void hideOutlines() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1565 | if (!workspaceInModalState() && !mIsSwitchingState) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1566 | if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel(); |
| 1567 | if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel(); |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 1568 | mChildrenOutlineFadeOutAnimation = LauncherAnimUtils.ofFloat(this, "childrenOutlineAlpha", 0.0f); |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1569 | mChildrenOutlineFadeOutAnimation.setDuration(CHILDREN_OUTLINE_FADE_OUT_DURATION); |
| 1570 | mChildrenOutlineFadeOutAnimation.setStartDelay(CHILDREN_OUTLINE_FADE_OUT_DELAY); |
| 1571 | mChildrenOutlineFadeOutAnimation.start(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1572 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1575 | public void showOutlinesTemporarily() { |
| 1576 | if (!mIsPageMoving && !isTouchActive()) { |
| 1577 | snapToPage(mCurrentPage); |
| 1578 | } |
| 1579 | } |
| 1580 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1581 | public void setChildrenOutlineAlpha(float alpha) { |
| 1582 | mChildrenOutlineAlpha = alpha; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1583 | for (int i = 0; i < getChildCount(); i++) { |
| 1584 | CellLayout cl = (CellLayout) getChildAt(i); |
| 1585 | cl.setBackgroundAlpha(alpha); |
| 1586 | } |
| 1587 | } |
| 1588 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1589 | public float getChildrenOutlineAlpha() { |
| 1590 | return mChildrenOutlineAlpha; |
| 1591 | } |
| 1592 | |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1593 | private void animateBackgroundGradient(float finalAlpha, boolean animated) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1594 | final DragLayer dragLayer = mLauncher.getDragLayer(); |
| 1595 | |
Michael Jurka | b9e1497 | 2011-07-25 17:57:40 -0700 | [diff] [blame] | 1596 | if (mBackgroundFadeInAnimation != null) { |
| 1597 | mBackgroundFadeInAnimation.cancel(); |
| 1598 | mBackgroundFadeInAnimation = null; |
| 1599 | } |
| 1600 | if (mBackgroundFadeOutAnimation != null) { |
| 1601 | mBackgroundFadeOutAnimation.cancel(); |
| 1602 | mBackgroundFadeOutAnimation = null; |
| 1603 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1604 | float startAlpha = dragLayer.getBackgroundAlpha(); |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1605 | if (finalAlpha != startAlpha) { |
| 1606 | if (animated) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 1607 | mBackgroundFadeOutAnimation = |
| 1608 | LauncherAnimUtils.ofFloat(this, startAlpha, finalAlpha); |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1609 | mBackgroundFadeOutAnimation.addUpdateListener(new AnimatorUpdateListener() { |
| 1610 | public void onAnimationUpdate(ValueAnimator animation) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1611 | dragLayer.setBackgroundAlpha( |
| 1612 | ((Float)animation.getAnimatedValue()).floatValue()); |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1613 | } |
| 1614 | }); |
| 1615 | mBackgroundFadeOutAnimation.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 1616 | mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION); |
| 1617 | mBackgroundFadeOutAnimation.start(); |
| 1618 | } else { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1619 | dragLayer.setBackgroundAlpha(finalAlpha); |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 1620 | } |
Michael Jurka | b9e1497 | 2011-07-25 17:57:40 -0700 | [diff] [blame] | 1621 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1622 | } |
| 1623 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1624 | float backgroundAlphaInterpolator(float r) { |
| 1625 | float pivotA = 0.1f; |
| 1626 | float pivotB = 0.4f; |
| 1627 | if (r < pivotA) { |
| 1628 | return 0; |
| 1629 | } else if (r > pivotB) { |
| 1630 | return 1.0f; |
| 1631 | } else { |
| 1632 | return (r - pivotA)/(pivotB - pivotA); |
| 1633 | } |
| 1634 | } |
| 1635 | |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1636 | private void updatePageAlphaValues(int screenCenter) { |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1637 | boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX; |
| 1638 | if (mWorkspaceFadeInAdjacentScreens && |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 1639 | !workspaceInModalState() && |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1640 | !mIsSwitchingState && |
| 1641 | !isInOverscroll) { |
Adam Cohen | 84a465a | 2013-11-11 18:49:56 +0000 | [diff] [blame] | 1642 | for (int i = numCustomPages(); i < getChildCount(); i++) { |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1643 | CellLayout child = (CellLayout) getChildAt(i); |
| 1644 | if (child != null) { |
| 1645 | float scrollProgress = getScrollProgress(screenCenter, child, i); |
Adam Cohen | 7389496 | 2011-10-31 13:17:17 -0700 | [diff] [blame] | 1646 | float alpha = 1 - Math.abs(scrollProgress); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1647 | child.getShortcutsAndWidgets().setAlpha(alpha); |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 1648 | //child.setBackgroundAlphaMultiplier(1 - alpha); |
Adam Cohen | 7389496 | 2011-10-31 13:17:17 -0700 | [diff] [blame] | 1649 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | private void setChildrenBackgroundAlphaMultipliers(float a) { |
| 1655 | for (int i = 0; i < getChildCount(); i++) { |
| 1656 | CellLayout child = (CellLayout) getChildAt(i); |
| 1657 | child.setBackgroundAlphaMultiplier(a); |
| 1658 | } |
| 1659 | } |
| 1660 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 1661 | public boolean hasCustomContent() { |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1662 | return (mScreenOrder.size() > 0 && mScreenOrder.get(0) == CUSTOM_CONTENT_SCREEN_ID); |
| 1663 | } |
| 1664 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1665 | public int numCustomPages() { |
| 1666 | return hasCustomContent() ? 1 : 0; |
| 1667 | } |
| 1668 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1669 | public boolean isOnOrMovingToCustomContent() { |
| 1670 | return hasCustomContent() && getNextPage() == 0; |
| 1671 | } |
| 1672 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1673 | private void updateStateForCustomContent(int screenCenter) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1674 | float translationX = 0; |
| 1675 | float progress = 0; |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 1676 | if (hasCustomContent()) { |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1677 | int index = mScreenOrder.indexOf(CUSTOM_CONTENT_SCREEN_ID); |
Adam Cohen | 564a2e7 | 2013-10-09 14:47:32 -0700 | [diff] [blame] | 1678 | |
Adam Cohen | a45de07 | 2013-10-11 16:07:47 -0700 | [diff] [blame] | 1679 | int scrollDelta = getScrollX() - getScrollForPage(index) - |
| 1680 | getLayoutTransitionOffsetForPage(index); |
| 1681 | float scrollRange = getScrollForPage(index + 1) - getScrollForPage(index); |
| 1682 | translationX = scrollRange - scrollDelta; |
| 1683 | progress = (scrollRange - scrollDelta) / scrollRange; |
Adam Cohen | af9b0e5 | 2013-09-23 19:27:38 -0700 | [diff] [blame] | 1684 | |
| 1685 | if (isLayoutRtl()) { |
| 1686 | translationX = Math.min(0, translationX); |
| 1687 | } else { |
| 1688 | translationX = Math.max(0, translationX); |
| 1689 | } |
Adam Cohen | 955806d | 2013-07-19 16:36:43 -0700 | [diff] [blame] | 1690 | progress = Math.max(0, progress); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1691 | } |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1692 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1693 | if (Float.compare(progress, mLastCustomContentScrollProgress) == 0) return; |
Adam Cohen | 84add1d | 2013-10-14 16:29:02 -0700 | [diff] [blame] | 1694 | |
| 1695 | CellLayout cc = mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1696 | if (progress > 0 && cc.getVisibility() != VISIBLE && !workspaceInModalState()) { |
Adam Cohen | 84add1d | 2013-10-14 16:29:02 -0700 | [diff] [blame] | 1697 | cc.setVisibility(VISIBLE); |
| 1698 | } |
| 1699 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1700 | mLastCustomContentScrollProgress = progress; |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1701 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1702 | mLauncher.getDragLayer().setBackgroundAlpha(progress * 0.8f); |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 1703 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1704 | if (mLauncher.getHotseat() != null) { |
| 1705 | mLauncher.getHotseat().setTranslationX(translationX); |
| 1706 | } |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1707 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1708 | if (getPageIndicator() != null) { |
| 1709 | getPageIndicator().setTranslationX(translationX); |
| 1710 | } |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1711 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1712 | if (mCustomContentCallbacks != null) { |
| 1713 | mCustomContentCallbacks.onScrollProgressChanged(progress); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1714 | } |
| 1715 | } |
| 1716 | |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1717 | @Override |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1718 | protected OnClickListener getPageIndicatorClickListener() { |
| 1719 | AccessibilityManager am = (AccessibilityManager) |
| 1720 | getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 1721 | if (!am.isTouchExplorationEnabled()) { |
| 1722 | return null; |
| 1723 | } |
| 1724 | OnClickListener listener = new OnClickListener() { |
| 1725 | @Override |
| 1726 | public void onClick(View arg0) { |
| 1727 | enterOverviewMode(); |
| 1728 | } |
| 1729 | }; |
| 1730 | return listener; |
| 1731 | } |
| 1732 | |
| 1733 | @Override |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1734 | protected void screenScrolled(int screenCenter) { |
Winson Chung | 52aee60 | 2013-01-30 12:01:02 -0800 | [diff] [blame] | 1735 | final boolean isRtl = isLayoutRtl(); |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1736 | super.screenScrolled(screenCenter); |
| 1737 | |
| 1738 | updatePageAlphaValues(screenCenter); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1739 | updateStateForCustomContent(screenCenter); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1740 | enableHwLayersOnVisiblePages(); |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1741 | |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 1742 | boolean shouldOverScroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX; |
Adam Cohen | af9b0e5 | 2013-09-23 19:27:38 -0700 | [diff] [blame] | 1743 | |
| 1744 | if (shouldOverScroll) { |
Winson Chung | 52aee60 | 2013-01-30 12:01:02 -0800 | [diff] [blame] | 1745 | int index = 0; |
Winson Chung | 52aee60 | 2013-01-30 12:01:02 -0800 | [diff] [blame] | 1746 | final int lowerIndex = 0; |
| 1747 | final int upperIndex = getChildCount() - 1; |
Adam Cohen | a29f504 | 2013-09-26 14:29:35 -0700 | [diff] [blame] | 1748 | |
| 1749 | final boolean isLeftPage = mOverScrollX < 0; |
| 1750 | index = (!isRtl && isLeftPage) || (isRtl && !isLeftPage) ? lowerIndex : upperIndex; |
Winson Chung | 52aee60 | 2013-01-30 12:01:02 -0800 | [diff] [blame] | 1751 | |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1752 | CellLayout cl = (CellLayout) getChildAt(index); |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 1753 | float effect = Math.abs(mOverScrollEffect); |
| 1754 | cl.setOverScrollAmount(Math.abs(effect), isLeftPage); |
Adam Cohen | a29f504 | 2013-09-26 14:29:35 -0700 | [diff] [blame] | 1755 | |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 1756 | mOverscrollEffectSet = true; |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1757 | } else { |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 1758 | if (mOverscrollEffectSet && getChildCount() > 0) { |
| 1759 | mOverscrollEffectSet = false; |
| 1760 | ((CellLayout) getChildAt(0)).setOverScrollAmount(0, false); |
| 1761 | ((CellLayout) getChildAt(getChildCount() - 1)).setOverScrollAmount(0, false); |
Adam Cohen | 7842d7f | 2011-09-12 15:28:15 -0700 | [diff] [blame] | 1762 | } |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1763 | } |
| 1764 | } |
| 1765 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1766 | protected void onAttachedToWindow() { |
| 1767 | super.onAttachedToWindow(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1768 | mWindowToken = getWindowToken(); |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 1769 | computeScroll(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1770 | mDragController.setWindowToken(mWindowToken); |
| 1771 | } |
| 1772 | |
| 1773 | protected void onDetachedFromWindow() { |
Romain Guy | e666195 | 2013-08-08 19:13:22 -0700 | [diff] [blame] | 1774 | super.onDetachedFromWindow(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1775 | mWindowToken = null; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1776 | } |
| 1777 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1778 | protected void onResume() { |
| 1779 | if (getPageIndicator() != null) { |
| 1780 | // In case accessibility state has changed, we need to perform this on every |
| 1781 | // attach to window |
Adam Cohen | d36d947 | 2013-10-10 15:32:41 -0700 | [diff] [blame] | 1782 | OnClickListener listener = getPageIndicatorClickListener(); |
| 1783 | if (listener != null) { |
| 1784 | getPageIndicator().setOnClickListener(listener); |
| 1785 | } |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1786 | } |
| 1787 | AccessibilityManager am = (AccessibilityManager) |
| 1788 | getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 1789 | sAccessibilityEnabled = am.isEnabled(); |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1790 | |
| 1791 | // Update wallpaper dimensions if they were changed since last onResume |
| 1792 | // (we also always set the wallpaper dimensions in the constructor) |
| 1793 | if (LauncherAppState.getInstance().hasWallpaperChangedSinceLastCheck()) { |
Adam Cohen | 824fcb3 | 2014-05-21 23:01:25 +0000 | [diff] [blame] | 1794 | setWallpaperDimension(); |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1795 | } |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 1796 | mWallpaperIsLiveWallpaper = mWallpaperManager.getWallpaperInfo() != null; |
| 1797 | // Force the wallpaper offset steps to be set again, because another app might have changed |
| 1798 | // them |
| 1799 | mLastSetWallpaperOffsetSteps = 0f; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1802 | @Override |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 1803 | 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] | 1804 | if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) { |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1805 | mWallpaperOffset.syncWithScroll(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1806 | mWallpaperOffset.jumpToFinal(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 1807 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1808 | super.onLayout(changed, left, top, right, bottom); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | @Override |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1812 | protected void onDraw(Canvas canvas) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1813 | super.onDraw(canvas); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1814 | |
| 1815 | // Call back to LauncherModel to finish binding after the first draw |
Romain Guy | eeacd56 | 2012-10-10 18:47:33 -0700 | [diff] [blame] | 1816 | post(mBindPages); |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1817 | } |
| 1818 | |
Michael Jurka | dfab7f0 | 2011-11-18 13:01:04 -0800 | [diff] [blame] | 1819 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1820 | protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 1821 | if (!mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1822 | final Folder openFolder = getOpenFolder(); |
| 1823 | if (openFolder != null) { |
| 1824 | return openFolder.requestFocus(direction, previouslyFocusedRect); |
| 1825 | } else { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1826 | return super.onRequestFocusInDescendants(direction, previouslyFocusedRect); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | return false; |
| 1830 | } |
| 1831 | |
| 1832 | @Override |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1833 | public int getDescendantFocusability() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1834 | if (workspaceInModalState()) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1835 | return ViewGroup.FOCUS_BLOCK_DESCENDANTS; |
| 1836 | } |
| 1837 | return super.getDescendantFocusability(); |
| 1838 | } |
| 1839 | |
| 1840 | @Override |
Romain Guy | c2e24c0 | 2009-06-01 16:11:41 -0700 | [diff] [blame] | 1841 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 1842 | if (!mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1843 | final Folder openFolder = getOpenFolder(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1844 | if (openFolder != null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1845 | openFolder.addFocusables(views, direction); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1846 | } else { |
| 1847 | super.addFocusables(views, direction, focusableMode); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1848 | } |
| 1849 | } |
| 1850 | } |
| 1851 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1852 | public boolean workspaceInModalState() { |
| 1853 | return mState != State.NORMAL; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1856 | void enableChildrenCache(int fromPage, int toPage) { |
| 1857 | if (fromPage > toPage) { |
| 1858 | final int temp = fromPage; |
| 1859 | fromPage = toPage; |
| 1860 | toPage = temp; |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 1861 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1862 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1863 | final int screenCount = getChildCount(); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1864 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1865 | fromPage = Math.max(fromPage, 0); |
| 1866 | toPage = Math.min(toPage, screenCount - 1); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1867 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1868 | for (int i = fromPage; i <= toPage; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1869 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1870 | layout.setChildrenDrawnWithCacheEnabled(true); |
| 1871 | layout.setChildrenDrawingCacheEnabled(true); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | void clearChildrenCache() { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1876 | final int screenCount = getChildCount(); |
| 1877 | for (int i = 0; i < screenCount; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1878 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1879 | layout.setChildrenDrawnWithCacheEnabled(false); |
Adam Cohen | 8182e5b | 2011-08-01 15:43:31 -0700 | [diff] [blame] | 1880 | // In software mode, we don't want the items to continue to be drawn into bitmaps |
| 1881 | if (!isHardwareAccelerated()) { |
| 1882 | layout.setChildrenDrawingCacheEnabled(false); |
| 1883 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1884 | } |
| 1885 | } |
| 1886 | |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1887 | private void updateChildrenLayersEnabled(boolean force) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1888 | boolean small = mState == State.OVERVIEW || mIsSwitchingState; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1889 | boolean enableChildrenLayers = force || small || mAnimatingViewIntoPlace || isPageMoving(); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1890 | |
| 1891 | if (enableChildrenLayers != mChildrenLayersEnabled) { |
| 1892 | mChildrenLayersEnabled = enableChildrenLayers; |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1893 | if (mChildrenLayersEnabled) { |
| 1894 | enableHwLayersOnVisiblePages(); |
| 1895 | } else { |
| 1896 | for (int i = 0; i < getPageCount(); i++) { |
| 1897 | final CellLayout cl = (CellLayout) getChildAt(i); |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1898 | cl.enableHardwareLayer(false); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1899 | } |
| 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | private void enableHwLayersOnVisiblePages() { |
| 1905 | if (mChildrenLayersEnabled) { |
| 1906 | final int screenCount = getChildCount(); |
| 1907 | getVisiblePages(mTempVisiblePagesRange); |
| 1908 | int leftScreen = mTempVisiblePagesRange[0]; |
| 1909 | int rightScreen = mTempVisiblePagesRange[1]; |
| 1910 | if (leftScreen == rightScreen) { |
| 1911 | // make sure we're caching at least two pages always |
| 1912 | if (rightScreen < screenCount - 1) { |
| 1913 | rightScreen++; |
| 1914 | } else if (leftScreen > 0) { |
| 1915 | leftScreen--; |
| 1916 | } |
| 1917 | } |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1918 | |
| 1919 | final CellLayout customScreen = mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1920 | for (int i = 0; i < screenCount; i++) { |
Michael Jurka | 47639b9 | 2013-01-14 12:42:27 +0100 | [diff] [blame] | 1921 | final CellLayout layout = (CellLayout) getPageAt(i); |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1922 | |
| 1923 | // enable layers between left and right screen inclusive, except for the |
| 1924 | // customScreen, which may animate its content during transitions. |
| 1925 | boolean enableLayer = layout != customScreen && |
| 1926 | leftScreen <= i && i <= rightScreen && shouldDrawChild(layout); |
| 1927 | layout.enableHardwareLayer(enableLayer); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1928 | } |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1929 | } |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1930 | } |
| 1931 | |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1932 | public void buildPageHardwareLayers() { |
| 1933 | // force layers to be enabled just for the call to buildLayer |
| 1934 | updateChildrenLayersEnabled(true); |
| 1935 | if (getWindowToken() != null) { |
| 1936 | final int childCount = getChildCount(); |
| 1937 | for (int i = 0; i < childCount; i++) { |
| 1938 | CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1939 | cl.buildHardwareLayer(); |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1940 | } |
| 1941 | } |
| 1942 | updateChildrenLayersEnabled(false); |
| 1943 | } |
| 1944 | |
Jeff Brown | 1d0867c | 2010-12-02 18:27:39 -0800 | [diff] [blame] | 1945 | protected void onWallpaperTap(MotionEvent ev) { |
| 1946 | final int[] position = mTempCell; |
| 1947 | getLocationOnScreen(position); |
| 1948 | |
| 1949 | int pointerIndex = ev.getActionIndex(); |
| 1950 | position[0] += (int) ev.getX(pointerIndex); |
| 1951 | position[1] += (int) ev.getY(pointerIndex); |
| 1952 | |
| 1953 | mWallpaperManager.sendWallpaperCommand(getWindowToken(), |
| 1954 | ev.getAction() == MotionEvent.ACTION_UP |
| 1955 | ? WallpaperManager.COMMAND_TAP : WallpaperManager.COMMAND_SECONDARY_TAP, |
| 1956 | position[0], position[1], 0, null); |
| 1957 | } |
| 1958 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1959 | /* |
| 1960 | * This interpolator emulates the rate at which the perceived scale of an object changes |
| 1961 | * as its distance from a camera increases. When this interpolator is applied to a scale |
| 1962 | * 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] | 1963 | * from the camera. |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1964 | */ |
| 1965 | static class ZInterpolator implements TimeInterpolator { |
| 1966 | private float focalLength; |
| 1967 | |
| 1968 | public ZInterpolator(float foc) { |
| 1969 | focalLength = foc; |
| 1970 | } |
| 1971 | |
Adam Cohen | eed565d | 2010-11-15 11:30:05 -0800 | [diff] [blame] | 1972 | public float getInterpolation(float input) { |
| 1973 | return (1.0f - focalLength / (focalLength + input)) / |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1974 | (1.0f - focalLength / (focalLength + 1.0f)); |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1975 | } |
| 1976 | } |
| 1977 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1978 | /* |
| 1979 | * The exact reverse of ZInterpolator. |
| 1980 | */ |
| 1981 | static class InverseZInterpolator implements TimeInterpolator { |
| 1982 | private ZInterpolator zInterpolator; |
| 1983 | public InverseZInterpolator(float foc) { |
| 1984 | zInterpolator = new ZInterpolator(foc); |
| 1985 | } |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1986 | public float getInterpolation(float input) { |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1987 | return 1 - zInterpolator.getInterpolation(1 - input); |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1991 | /* |
| 1992 | * ZInterpolator compounded with an ease-out. |
| 1993 | */ |
| 1994 | static class ZoomOutInterpolator implements TimeInterpolator { |
Adam Cohen | b64d36e | 2011-10-17 21:48:02 -0700 | [diff] [blame] | 1995 | private final DecelerateInterpolator decelerate = new DecelerateInterpolator(0.75f); |
| 1996 | private final ZInterpolator zInterpolator = new ZInterpolator(0.13f); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1997 | |
| 1998 | public float getInterpolation(float input) { |
| 1999 | return decelerate.getInterpolation(zInterpolator.getInterpolation(input)); |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | /* |
| 2004 | * InvereZInterpolator compounded with an ease-out. |
| 2005 | */ |
| 2006 | static class ZoomInInterpolator implements TimeInterpolator { |
| 2007 | private final InverseZInterpolator inverseZInterpolator = new InverseZInterpolator(0.35f); |
| 2008 | private final DecelerateInterpolator decelerate = new DecelerateInterpolator(3.0f); |
| 2009 | |
| 2010 | public float getInterpolation(float input) { |
| 2011 | return decelerate.getInterpolation(inverseZInterpolator.getInterpolation(input)); |
| 2012 | } |
| 2013 | } |
| 2014 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 2015 | private final ZoomInInterpolator mZoomInInterpolator = new ZoomInInterpolator(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 2016 | |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 2017 | /* |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 2018 | * |
| 2019 | * We call these methods (onDragStartedWithItemSpans/onDragStartedWithSize) whenever we |
| 2020 | * start a drag in Launcher, regardless of whether the drag has ever entered the Workspace |
| 2021 | * |
| 2022 | * These methods mark the appropriate pages as accepting drops (which alters their visual |
| 2023 | * appearance). |
| 2024 | * |
| 2025 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2026 | private static Rect getDrawableBounds(Drawable d) { |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 2027 | Rect bounds = new Rect(); |
| 2028 | d.copyBounds(bounds); |
| 2029 | if (bounds.width() == 0 || bounds.height() == 0) { |
| 2030 | bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2031 | } else { |
| 2032 | bounds.offsetTo(0, 0); |
| 2033 | } |
| 2034 | if (d instanceof PreloadIconDrawable) { |
| 2035 | int inset = -((PreloadIconDrawable) d).getOutset(); |
| 2036 | bounds.inset(inset, inset); |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 2037 | } |
| 2038 | return bounds; |
| 2039 | } |
| 2040 | |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2041 | public void onExternalDragStartedWithItem(View v) { |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2042 | // Compose a drag bitmap with the view scaled to the icon size |
| 2043 | LauncherAppState app = LauncherAppState.getInstance(); |
| 2044 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 2045 | int iconSize = grid.iconSizePx; |
| 2046 | int bmpWidth = v.getMeasuredWidth(); |
| 2047 | int bmpHeight = v.getMeasuredHeight(); |
| 2048 | |
| 2049 | // If this is a text view, use its drawable instead |
| 2050 | if (v instanceof TextView) { |
| 2051 | TextView tv = (TextView) v; |
| 2052 | Drawable d = tv.getCompoundDrawables()[1]; |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 2053 | Rect bounds = getDrawableBounds(d); |
| 2054 | bmpWidth = bounds.width(); |
| 2055 | bmpHeight = bounds.height(); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | // Compose the bitmap to create the icon from |
| 2059 | Bitmap b = Bitmap.createBitmap(bmpWidth, bmpHeight, |
| 2060 | Bitmap.Config.ARGB_8888); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2061 | mCanvas.setBitmap(b); |
| 2062 | drawDragView(v, mCanvas, 0); |
| 2063 | mCanvas.setBitmap(null); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2064 | |
| 2065 | // The outline is used to visualize where the item will land if dropped |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2066 | mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, iconSize, iconSize, true); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2069 | public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) { |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 2070 | int[] size = estimateItemSize(info.spanX, info.spanY, info, false); |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 2071 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2072 | // The outline is used to visualize where the item will land if dropped |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2073 | mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, size[0], size[1], clipAlpha); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2076 | public void exitWidgetResizeMode() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 2077 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 2078 | dragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 2079 | } |
| 2080 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2081 | private void initAnimationArrays() { |
| 2082 | final int childCount = getChildCount(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2083 | if (mLastChildCount == childCount) return; |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 2084 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2085 | mOldBackgroundAlphas = new float[childCount]; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2086 | mOldAlphas = new float[childCount]; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2087 | mNewBackgroundAlphas = new float[childCount]; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2088 | mNewAlphas = new float[childCount]; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 2091 | Animator getChangeStateAnimation(final State state, boolean animated, |
| 2092 | ArrayList<View> layerViews) { |
| 2093 | return getChangeStateAnimation(state, animated, 0, -1, layerViews); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2096 | @Override |
Adam Cohen | 6f127a6 | 2014-06-12 14:54:41 -0700 | [diff] [blame] | 2097 | protected void getFreeScrollPageRange(int[] range) { |
| 2098 | getOverviewModePages(range); |
| 2099 | } |
| 2100 | |
| 2101 | private void getOverviewModePages(int[] range) { |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 2102 | int start = numCustomPages(); |
Adam Cohen | 1003be9 | 2013-09-16 14:09:28 -0700 | [diff] [blame] | 2103 | int end = getChildCount() - 1; |
| 2104 | |
| 2105 | range[0] = Math.max(0, Math.min(start, getChildCount() - 1)); |
| 2106 | range[1] = Math.max(0, end); |
Adam Cohen | 6f127a6 | 2014-06-12 14:54:41 -0700 | [diff] [blame] | 2107 | } |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2108 | |
| 2109 | protected void onStartReordering() { |
| 2110 | super.onStartReordering(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2111 | showOutlines(); |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 2112 | // Reordering handles its own animations, disable the automatic ones. |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 2113 | disableLayoutTransitions(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | protected void onEndReordering() { |
| 2117 | super.onEndReordering(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2118 | |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 2119 | if (mLauncher.isWorkspaceLoading()) { |
| 2120 | // Invalid and dangerous operation if workspace is loading |
| 2121 | return; |
| 2122 | } |
| 2123 | |
Adam Cohen | 2bf63d5 | 2013-09-29 17:46:49 -0700 | [diff] [blame] | 2124 | hideOutlines(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2125 | mScreenOrder.clear(); |
Adam Cohen | 2bf63d5 | 2013-09-29 17:46:49 -0700 | [diff] [blame] | 2126 | int count = getChildCount(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2127 | for (int i = 0; i < count; i++) { |
| 2128 | CellLayout cl = ((CellLayout) getChildAt(i)); |
| 2129 | mScreenOrder.add(getIdForScreen(cl)); |
| 2130 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 2131 | |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2132 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 2133 | |
| 2134 | // Re-enable auto layout transitions for page deletion. |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 2135 | enableLayoutTransitions(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2138 | public boolean isInOverviewMode() { |
| 2139 | return mState == State.OVERVIEW; |
| 2140 | } |
| 2141 | |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 2142 | public boolean enterOverviewMode() { |
| 2143 | if (mTouchState != TOUCH_STATE_REST) { |
| 2144 | return false; |
| 2145 | } |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2146 | enableOverviewMode(true, -1, true); |
Adam Cohen | 93c9756 | 2013-09-26 13:48:01 -0700 | [diff] [blame] | 2147 | return true; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2150 | public void exitOverviewMode(boolean animated) { |
| 2151 | exitOverviewMode(-1, animated); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2154 | public void exitOverviewMode(int snapPage, boolean animated) { |
| 2155 | enableOverviewMode(false, snapPage, animated); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2158 | private void enableOverviewMode(boolean enable, int snapPage, boolean animated) { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2159 | State finalState = Workspace.State.OVERVIEW; |
| 2160 | if (!enable) { |
| 2161 | finalState = Workspace.State.NORMAL; |
| 2162 | } |
| 2163 | |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2164 | Animator workspaceAnim = getChangeStateAnimation(finalState, animated, 0, snapPage); |
| 2165 | if (workspaceAnim != null) { |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2166 | onTransitionPrepare(); |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2167 | workspaceAnim.addListener(new AnimatorListenerAdapter() { |
| 2168 | @Override |
| 2169 | public void onAnimationEnd(Animator arg0) { |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2170 | onTransitionEnd(); |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2171 | } |
| 2172 | }); |
| 2173 | workspaceAnim.start(); |
| 2174 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2177 | int getOverviewModeTranslationY() { |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 2178 | LauncherAppState app = LauncherAppState.getInstance(); |
| 2179 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 2180 | Rect overviewBar = grid.getOverviewModeButtonBarRect(); |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2181 | |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 2182 | int availableHeight = getViewportHeight(); |
| 2183 | int scaledHeight = (int) (mOverviewModeShrinkFactor * getNormalChildHeight()); |
| 2184 | int offsetFromTopEdge = (availableHeight - scaledHeight) / 2; |
| 2185 | int offsetToCenterInOverview = (availableHeight - mInsets.top - overviewBar.height() |
| 2186 | - scaledHeight) / 2; |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2187 | |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 2188 | return -offsetFromTopEdge + mInsets.top + offsetToCenterInOverview; |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 2191 | public void updateInteractionForState() { |
| 2192 | if (mState != State.NORMAL) { |
| 2193 | mLauncher.onInteractionBegin(); |
| 2194 | } else { |
| 2195 | mLauncher.onInteractionEnd(); |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | private void setState(State state) { |
| 2200 | mState = state; |
| 2201 | updateInteractionForState(); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 2202 | updateAccessibilityFlags(); |
| 2203 | } |
| 2204 | |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 2205 | State getState() { |
| 2206 | return mState; |
| 2207 | } |
| 2208 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 2209 | private void updateAccessibilityFlags() { |
| 2210 | int accessible = mState == State.NORMAL ? |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 2211 | IMPORTANT_FOR_ACCESSIBILITY_YES : |
| 2212 | IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 2213 | setImportantForAccessibility(accessible); |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2216 | private static final int HIDE_WORKSPACE_DURATION = 100; |
| 2217 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2218 | Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 2219 | return getChangeStateAnimation(state, animated, delay, snapPage, null); |
| 2220 | } |
| 2221 | |
| 2222 | Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage, |
| 2223 | ArrayList<View> layerViews) { |
Michael Jurka | bdf7855 | 2011-10-31 14:34:25 -0700 | [diff] [blame] | 2224 | if (mState == state) { |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2225 | return null; |
Michael Jurka | 99633da | 2011-07-27 22:40:17 -0700 | [diff] [blame] | 2226 | } |
| 2227 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 2228 | // Initialize animation arrays for the first time if necessary |
| 2229 | initAnimationArrays(); |
| 2230 | |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 2231 | AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 2232 | |
Adam Cohen | 08072c0 | 2014-11-18 17:53:44 -0800 | [diff] [blame] | 2233 | // We only want a single instance of a workspace animation to be running at once, so |
| 2234 | // we cancel any incomplete transition. |
| 2235 | if (mStateAnimator != null) { |
| 2236 | mStateAnimator.cancel(); |
| 2237 | } |
| 2238 | mStateAnimator = anim; |
| 2239 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 2240 | final State oldState = mState; |
| 2241 | final boolean oldStateIsNormal = (oldState == State.NORMAL); |
Michael Jurka | 4ff7d79 | 2012-04-02 03:46:50 -0700 | [diff] [blame] | 2242 | final boolean oldStateIsSpringLoaded = (oldState == State.SPRING_LOADED); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2243 | final boolean oldStateIsNormalHidden = (oldState == State.NORMAL_HIDDEN); |
| 2244 | final boolean oldStateIsOverviewHidden = (oldState == State.OVERVIEW_HIDDEN); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2245 | final boolean oldStateIsOverview = (oldState == State.OVERVIEW); |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 2246 | setState(state); |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 2247 | final boolean stateIsNormal = (state == State.NORMAL); |
| 2248 | final boolean stateIsSpringLoaded = (state == State.SPRING_LOADED); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2249 | final boolean stateIsNormalHidden = (state == State.NORMAL_HIDDEN); |
| 2250 | final boolean stateIsOverviewHidden = (state == State.OVERVIEW_HIDDEN); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2251 | final boolean stateIsOverview = (state == State.OVERVIEW); |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 2252 | float finalBackgroundAlpha = (stateIsSpringLoaded || stateIsOverview) ? 1.0f : 0f; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2253 | float finalHotseatAndPageIndicatorAlpha = (stateIsNormal || stateIsSpringLoaded) ? 1f : 0f; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2254 | float finalOverviewPanelAlpha = stateIsOverview ? 1f : 0f; |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 2255 | float finalSearchBarAlpha = !stateIsNormal ? 0f : 1f; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2256 | float finalWorkspaceTranslationY = stateIsOverview || stateIsOverviewHidden ? |
| 2257 | getOverviewModeTranslationY() : 0; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2258 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2259 | boolean workspaceToAllApps = (oldStateIsNormal && stateIsNormalHidden); |
| 2260 | boolean overviewToAllApps = (oldStateIsOverview && stateIsOverviewHidden); |
| 2261 | boolean allAppsToWorkspace = (stateIsNormalHidden && stateIsNormal); |
Adam Cohen | 58993ad | 2013-10-11 17:57:38 -0700 | [diff] [blame] | 2262 | boolean workspaceToOverview = (oldStateIsNormal && stateIsOverview); |
| 2263 | boolean overviewToWorkspace = (oldStateIsOverview && stateIsNormal); |
| 2264 | |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 2265 | mNewScale = 1.0f; |
Adam Cohen | beff8c6 | 2011-08-31 17:46:01 -0700 | [diff] [blame] | 2266 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2267 | if (oldStateIsOverview) { |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 2268 | disableFreeScroll(); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2269 | } else if (stateIsOverview) { |
| 2270 | enableFreeScroll(); |
| 2271 | } |
| 2272 | |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2273 | if (state != State.NORMAL) { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2274 | if (stateIsSpringLoaded) { |
| 2275 | mNewScale = mSpringLoadedShrinkFactor; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2276 | } else if (stateIsOverview || stateIsOverviewHidden) { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2277 | mNewScale = mOverviewModeShrinkFactor; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2278 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2279 | } |
Winson Chung | f4bd236 | 2013-10-07 17:11:27 -0700 | [diff] [blame] | 2280 | |
Adam Cohen | fa2450a | 2013-10-11 18:20:27 -0700 | [diff] [blame] | 2281 | final int duration; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2282 | if (workspaceToAllApps || overviewToAllApps) { |
| 2283 | duration = HIDE_WORKSPACE_DURATION; //getResources().getInteger(R.integer.config_workspaceUnshrinkTime); |
Adam Cohen | fa2450a | 2013-10-11 18:20:27 -0700 | [diff] [blame] | 2284 | } else if (workspaceToOverview || overviewToWorkspace) { |
| 2285 | duration = getResources().getInteger(R.integer.config_overviewTransitionTime); |
| 2286 | } else { |
| 2287 | duration = getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime); |
| 2288 | } |
| 2289 | |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 2290 | if (snapPage == -1) { |
| 2291 | snapPage = getPageNearestToCenterOfScreen(); |
| 2292 | } |
| 2293 | snapToPage(snapPage, duration, mZoomInInterpolator); |
| 2294 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 2295 | for (int i = 0; i < getChildCount(); i++) { |
| 2296 | final CellLayout cl = (CellLayout) getChildAt(i); |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 2297 | boolean isCurrentPage = (i == snapPage); |
Winson Chung | 2d75f12 | 2013-09-23 16:53:31 -0700 | [diff] [blame] | 2298 | float initialAlpha = cl.getShortcutsAndWidgets().getAlpha(); |
Adam Cohen | 3b185e2 | 2013-10-29 14:45:58 -0700 | [diff] [blame] | 2299 | float finalAlpha; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2300 | if (stateIsNormalHidden || stateIsOverviewHidden) { |
Adam Cohen | 3b185e2 | 2013-10-29 14:45:58 -0700 | [diff] [blame] | 2301 | finalAlpha = 0f; |
| 2302 | } else if (stateIsNormal && mWorkspaceFadeInAdjacentScreens) { |
Adam Cohen | f961885 | 2013-11-08 06:45:03 -0800 | [diff] [blame] | 2303 | finalAlpha = (i == snapPage || i < numCustomPages()) ? 1f : 0f; |
Adam Cohen | 3b185e2 | 2013-10-29 14:45:58 -0700 | [diff] [blame] | 2304 | } else { |
| 2305 | finalAlpha = 1f; |
| 2306 | } |
Winson Chung | f4bd236 | 2013-10-07 17:11:27 -0700 | [diff] [blame] | 2307 | |
| 2308 | // If we are animating to/from the small state, then hide the side pages and fade the |
| 2309 | // current page in |
| 2310 | if (!mIsSwitchingState) { |
| 2311 | if (workspaceToAllApps || allAppsToWorkspace) { |
| 2312 | if (allAppsToWorkspace && isCurrentPage) { |
| 2313 | initialAlpha = 0f; |
| 2314 | } else if (!isCurrentPage) { |
| 2315 | initialAlpha = finalAlpha = 0f; |
| 2316 | } |
| 2317 | cl.setShortcutAndWidgetAlpha(initialAlpha); |
| 2318 | } |
| 2319 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2320 | |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 2321 | mOldAlphas[i] = initialAlpha; |
| 2322 | mNewAlphas[i] = finalAlpha; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2323 | if (animated) { |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2324 | mOldBackgroundAlphas[i] = cl.getBackgroundAlpha(); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2325 | mNewBackgroundAlphas[i] = finalBackgroundAlpha; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2326 | } else { |
Winson Chung | 1b7c1d3 | 2011-10-25 12:09:38 -0700 | [diff] [blame] | 2327 | cl.setBackgroundAlpha(finalBackgroundAlpha); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 2328 | cl.setShortcutAndWidgetAlpha(finalAlpha); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2329 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 2330 | } |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 2331 | |
Adam Cohen | 3d41198 | 2013-09-24 17:02:06 -0700 | [diff] [blame] | 2332 | final View searchBar = mLauncher.getQsbBar(); |
| 2333 | final View overviewPanel = mLauncher.getOverviewPanel(); |
| 2334 | final View hotseat = mLauncher.getHotseat(); |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2335 | final View pageIndicator = getPageIndicator(); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2336 | if (animated) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 2337 | LauncherViewPropertyAnimator scale = new LauncherViewPropertyAnimator(this); |
| 2338 | scale.scaleX(mNewScale) |
| 2339 | .scaleY(mNewScale) |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2340 | .translationY(finalWorkspaceTranslationY) |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2341 | .setDuration(duration) |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 2342 | .setInterpolator(mZoomInInterpolator); |
| 2343 | anim.play(scale); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2344 | for (int index = 0; index < getChildCount(); index++) { |
| 2345 | final int i = index; |
| 2346 | final CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 2347 | float currentAlpha = cl.getShortcutsAndWidgets().getAlpha(); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2348 | if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) { |
Michael Jurka | 7372c59 | 2012-01-16 04:21:35 -0800 | [diff] [blame] | 2349 | cl.setBackgroundAlpha(mNewBackgroundAlphas[i]); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 2350 | cl.setShortcutAndWidgetAlpha(mNewAlphas[i]); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2351 | } else { |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 2352 | if (layerViews != null) { |
| 2353 | layerViews.add(cl); |
| 2354 | } |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 2355 | if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) { |
Michael Jurka | 6c8a579 | 2012-03-22 05:24:37 -0700 | [diff] [blame] | 2356 | LauncherViewPropertyAnimator alphaAnim = |
| 2357 | new LauncherViewPropertyAnimator(cl.getShortcutsAndWidgets()); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 2358 | alphaAnim.alpha(mNewAlphas[i]) |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2359 | .setDuration(duration) |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 2360 | .setInterpolator(mZoomInInterpolator); |
| 2361 | anim.play(alphaAnim); |
| 2362 | } |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2363 | if (mOldBackgroundAlphas[i] != 0 || |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 2364 | mNewBackgroundAlphas[i] != 0) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 2365 | ValueAnimator bgAnim = |
Adam Cohen | fa2450a | 2013-10-11 18:20:27 -0700 | [diff] [blame] | 2366 | LauncherAnimUtils.ofFloat(cl, 0f, 1f); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2367 | bgAnim.setInterpolator(mZoomInInterpolator); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2368 | bgAnim.setDuration(duration); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2369 | bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 2370 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | 7372c59 | 2012-01-16 04:21:35 -0800 | [diff] [blame] | 2371 | cl.setBackgroundAlpha( |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2372 | a * mOldBackgroundAlphas[i] + |
| 2373 | b * mNewBackgroundAlphas[i]); |
Michael Jurka | 7407d2a | 2011-12-12 21:48:38 -0800 | [diff] [blame] | 2374 | } |
| 2375 | }); |
| 2376 | anim.play(bgAnim); |
| 2377 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2378 | } |
| 2379 | } |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2380 | Animator pageIndicatorAlpha = null; |
| 2381 | if (pageIndicator != null) { |
| 2382 | pageIndicatorAlpha = new LauncherViewPropertyAnimator(pageIndicator) |
| 2383 | .alpha(finalHotseatAndPageIndicatorAlpha).withLayer(); |
Michael Jurka | 1c00fd0 | 2013-12-02 16:11:22 -0800 | [diff] [blame] | 2384 | pageIndicatorAlpha.addListener(new AlphaUpdateListener(pageIndicator)); |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2385 | } else { |
| 2386 | // create a dummy animation so we don't need to do null checks later |
| 2387 | pageIndicatorAlpha = ValueAnimator.ofFloat(0, 0); |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 2388 | } |
Michael Jurka | 1c00fd0 | 2013-12-02 16:11:22 -0800 | [diff] [blame] | 2389 | |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2390 | Animator hotseatAlpha = new LauncherViewPropertyAnimator(hotseat) |
| 2391 | .alpha(finalHotseatAndPageIndicatorAlpha).withLayer(); |
Michael Jurka | 1c00fd0 | 2013-12-02 16:11:22 -0800 | [diff] [blame] | 2392 | hotseatAlpha.addListener(new AlphaUpdateListener(hotseat)); |
| 2393 | |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2394 | Animator overviewPanelAlpha = new LauncherViewPropertyAnimator(overviewPanel) |
| 2395 | .alpha(finalOverviewPanelAlpha).withLayer(); |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2396 | overviewPanelAlpha.addListener(new AlphaUpdateListener(overviewPanel)); |
Adam Cohen | 3d41198 | 2013-09-24 17:02:06 -0700 | [diff] [blame] | 2397 | |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 2398 | // For animation optimations, we may need to provide the Launcher transition |
| 2399 | // with a set of views on which to force build layers in certain scenarios. |
| 2400 | hotseat.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 2401 | overviewPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 2402 | if (layerViews != null) { |
| 2403 | layerViews.add(hotseat); |
Adam Cohen | 2854d25 | 2014-08-27 16:04:07 -0700 | [diff] [blame] | 2404 | layerViews.add(overviewPanel); |
| 2405 | } |
| 2406 | |
Adam Cohen | 58993ad | 2013-10-11 17:57:38 -0700 | [diff] [blame] | 2407 | if (workspaceToOverview) { |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2408 | pageIndicatorAlpha.setInterpolator(new DecelerateInterpolator(2)); |
Adam Cohen | 58993ad | 2013-10-11 17:57:38 -0700 | [diff] [blame] | 2409 | hotseatAlpha.setInterpolator(new DecelerateInterpolator(2)); |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2410 | overviewPanelAlpha.setInterpolator(null); |
Adam Cohen | 58993ad | 2013-10-11 17:57:38 -0700 | [diff] [blame] | 2411 | } else if (overviewToWorkspace) { |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2412 | pageIndicatorAlpha.setInterpolator(null); |
| 2413 | hotseatAlpha.setInterpolator(null); |
Adam Cohen | 58993ad | 2013-10-11 17:57:38 -0700 | [diff] [blame] | 2414 | overviewPanelAlpha.setInterpolator(new DecelerateInterpolator(2)); |
| 2415 | } |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2416 | |
| 2417 | overviewPanelAlpha.setDuration(duration); |
| 2418 | pageIndicatorAlpha.setDuration(duration); |
| 2419 | hotseatAlpha.setDuration(duration); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 2420 | |
| 2421 | if (searchBar != null) { |
| 2422 | Animator searchBarAlpha = new LauncherViewPropertyAnimator(searchBar) |
| 2423 | .alpha(finalSearchBarAlpha).withLayer(); |
| 2424 | searchBarAlpha.addListener(new AlphaUpdateListener(searchBar)); |
| 2425 | searchBar.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 2426 | if (layerViews != null) { |
| 2427 | layerViews.add(searchBar); |
| 2428 | } |
| 2429 | searchBarAlpha.setDuration(duration); |
| 2430 | anim.play(searchBarAlpha); |
| 2431 | } |
Adam Cohen | 3d41198 | 2013-09-24 17:02:06 -0700 | [diff] [blame] | 2432 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2433 | anim.play(overviewPanelAlpha); |
| 2434 | anim.play(hotseatAlpha); |
| 2435 | anim.play(pageIndicatorAlpha); |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2436 | anim.setStartDelay(delay); |
Adam Cohen | 08072c0 | 2014-11-18 17:53:44 -0800 | [diff] [blame] | 2437 | anim.addListener(new AnimatorListenerAdapter() { |
| 2438 | @Override |
| 2439 | public void onAnimationEnd(Animator animation) { |
| 2440 | mStateAnimator = null; |
| 2441 | } |
| 2442 | }); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2443 | } else { |
Adam Cohen | 3d41198 | 2013-09-24 17:02:06 -0700 | [diff] [blame] | 2444 | overviewPanel.setAlpha(finalOverviewPanelAlpha); |
| 2445 | AlphaUpdateListener.updateVisibility(overviewPanel); |
| 2446 | hotseat.setAlpha(finalHotseatAndPageIndicatorAlpha); |
| 2447 | AlphaUpdateListener.updateVisibility(hotseat); |
Michael Jurka | 853f5a4 | 2013-11-25 14:32:21 +0100 | [diff] [blame] | 2448 | if (pageIndicator != null) { |
| 2449 | pageIndicator.setAlpha(finalHotseatAndPageIndicatorAlpha); |
| 2450 | AlphaUpdateListener.updateVisibility(pageIndicator); |
Winson Chung | 6670073 | 2013-08-20 16:56:15 -0700 | [diff] [blame] | 2451 | } |
Sunny Goyal | 416541c | 2014-11-14 11:59:57 -0800 | [diff] [blame] | 2452 | if (searchBar != null) { |
| 2453 | searchBar.setAlpha(finalSearchBarAlpha); |
| 2454 | AlphaUpdateListener.updateVisibility(searchBar); |
| 2455 | } |
Adam Cohen | 3f452c8 | 2013-09-19 11:57:17 -0700 | [diff] [blame] | 2456 | updateCustomContentVisibility(); |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2457 | setScaleX(mNewScale); |
| 2458 | setScaleY(mNewScale); |
| 2459 | setTranslationY(finalWorkspaceTranslationY); |
Adam Cohen | dbdff6b | 2013-09-18 19:09:15 -0700 | [diff] [blame] | 2460 | } |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 2461 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2462 | if (stateIsNormal) { |
Adam Cohen | ed307df | 2013-10-02 09:37:31 -0700 | [diff] [blame] | 2463 | animateBackgroundGradient(0f, animated); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2464 | } else { |
| 2465 | animateBackgroundGradient(getResources().getInteger( |
| 2466 | R.integer.config_workspaceScrimAlpha) / 100f, animated); |
Michael Jurka | 7bdb25a | 2011-08-03 15:16:44 -0700 | [diff] [blame] | 2467 | } |
Michael Jurka | 2a4b1a8 | 2011-12-07 14:00:02 -0800 | [diff] [blame] | 2468 | return anim; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 2471 | static class AlphaUpdateListener implements AnimatorUpdateListener, AnimatorListener { |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2472 | View view; |
| 2473 | public AlphaUpdateListener(View v) { |
| 2474 | view = v; |
| 2475 | } |
| 2476 | |
| 2477 | @Override |
| 2478 | public void onAnimationUpdate(ValueAnimator arg0) { |
Michael Jurka | 336fd4f | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 2479 | updateVisibility(view); |
| 2480 | } |
| 2481 | |
| 2482 | public static void updateVisibility(View view) { |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 2483 | // We want to avoid the extra layout pass by setting the views to GONE unless |
| 2484 | // accessibility is on, in which case not setting them to GONE causes a glitch. |
| 2485 | int invisibleState = sAccessibilityEnabled ? GONE : INVISIBLE; |
| 2486 | if (view.getAlpha() < ALPHA_CUTOFF_THRESHOLD && view.getVisibility() != invisibleState) { |
| 2487 | view.setVisibility(invisibleState); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2488 | } else if (view.getAlpha() > ALPHA_CUTOFF_THRESHOLD |
| 2489 | && view.getVisibility() != VISIBLE) { |
| 2490 | view.setVisibility(VISIBLE); |
| 2491 | } |
| 2492 | } |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 2493 | |
| 2494 | @Override |
| 2495 | public void onAnimationCancel(Animator arg0) { |
| 2496 | } |
| 2497 | |
| 2498 | @Override |
| 2499 | public void onAnimationEnd(Animator arg0) { |
| 2500 | updateVisibility(view); |
| 2501 | } |
| 2502 | |
| 2503 | @Override |
| 2504 | public void onAnimationRepeat(Animator arg0) { |
| 2505 | } |
| 2506 | |
| 2507 | @Override |
| 2508 | public void onAnimationStart(Animator arg0) { |
| 2509 | // We want the views to be visible for animation, so fade-in/out is visible |
| 2510 | view.setVisibility(VISIBLE); |
| 2511 | } |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2514 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 2515 | public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) { |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2516 | onTransitionPrepare(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 2520 | public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { |
| 2521 | } |
| 2522 | |
| 2523 | @Override |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 2524 | public void onLauncherTransitionStep(Launcher l, float t) { |
| 2525 | mTransitionProgress = t; |
| 2526 | } |
| 2527 | |
| 2528 | @Override |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2529 | public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2530 | onTransitionEnd(); |
| 2531 | } |
| 2532 | |
| 2533 | private void onTransitionPrepare() { |
| 2534 | mIsSwitchingState = true; |
Winson Chung | f4bd236 | 2013-10-07 17:11:27 -0700 | [diff] [blame] | 2535 | |
| 2536 | // Invalidate here to ensure that the pages are rendered during the state change transition. |
| 2537 | invalidate(); |
| 2538 | |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2539 | updateChildrenLayersEnabled(false); |
Adam Cohen | 3f452c8 | 2013-09-19 11:57:17 -0700 | [diff] [blame] | 2540 | hideCustomContentIfNecessary(); |
| 2541 | } |
| 2542 | |
| 2543 | void updateCustomContentVisibility() { |
| 2544 | int visibility = mState == Workspace.State.NORMAL ? VISIBLE : INVISIBLE; |
| 2545 | if (hasCustomContent()) { |
| 2546 | mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(visibility); |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | void showCustomContentIfNecessary() { |
| 2551 | boolean show = mState == Workspace.State.NORMAL; |
| 2552 | if (show && hasCustomContent()) { |
| 2553 | mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(VISIBLE); |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | void hideCustomContentIfNecessary() { |
| 2558 | boolean hide = mState != Workspace.State.NORMAL; |
| 2559 | if (hide && hasCustomContent()) { |
Adam Cohen | 1774a8a | 2013-11-15 10:56:16 +0000 | [diff] [blame] | 2560 | disableLayoutTransitions(); |
Adam Cohen | 3f452c8 | 2013-09-19 11:57:17 -0700 | [diff] [blame] | 2561 | mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(INVISIBLE); |
Adam Cohen | 1774a8a | 2013-11-15 10:56:16 +0000 | [diff] [blame] | 2562 | enableLayoutTransitions(); |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2563 | } |
| 2564 | } |
| 2565 | |
| 2566 | private void onTransitionEnd() { |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2567 | mIsSwitchingState = false; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 2568 | updateChildrenLayersEnabled(false); |
Adam Cohen | 3f452c8 | 2013-09-19 11:57:17 -0700 | [diff] [blame] | 2569 | showCustomContentIfNecessary(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | @Override |
| 2573 | public View getContent() { |
| 2574 | return this; |
| 2575 | } |
| 2576 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2577 | /** |
| 2578 | * Draw the View v into the given Canvas. |
| 2579 | * |
| 2580 | * @param v the view to draw |
| 2581 | * @param destCanvas the canvas to draw on |
| 2582 | * @param padding the horizontal and vertical padding to use when drawing |
| 2583 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2584 | private static void drawDragView(View v, Canvas destCanvas, int padding) { |
| 2585 | final Rect clipRect = sTempRect; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2586 | v.getDrawingRect(clipRect); |
| 2587 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 2588 | boolean textVisible = false; |
| 2589 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2590 | destCanvas.save(); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2591 | if (v instanceof TextView) { |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2592 | Drawable d = ((TextView) v).getCompoundDrawables()[1]; |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 2593 | Rect bounds = getDrawableBounds(d); |
| 2594 | clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2595 | destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2596 | d.draw(destCanvas); |
| 2597 | } else { |
| 2598 | if (v instanceof FolderIcon) { |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 2599 | // For FolderIcons the text can bleed into the icon area, and so we need to |
| 2600 | // hide the text completely (which can't be achieved by clipping). |
| 2601 | if (((FolderIcon) v).getTextVisible()) { |
| 2602 | ((FolderIcon) v).setTextVisible(false); |
| 2603 | textVisible = true; |
| 2604 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2605 | } |
| 2606 | destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); |
| 2607 | destCanvas.clipRect(clipRect, Op.REPLACE); |
| 2608 | v.draw(destCanvas); |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 2609 | |
| 2610 | // Restore text visibility of FolderIcon if necessary |
| 2611 | if (textVisible) { |
| 2612 | ((FolderIcon) v).setTextVisible(true); |
| 2613 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2614 | } |
| 2615 | destCanvas.restore(); |
| 2616 | } |
| 2617 | |
| 2618 | /** |
| 2619 | * Returns a new bitmap to show when the given View is being dragged around. |
| 2620 | * Responsibility for the bitmap is transferred to the caller. |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2621 | * @param expectedPadding padding to add to the drag view. If a different padding was used |
| 2622 | * its value will be changed |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2623 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2624 | public Bitmap createDragBitmap(View v, AtomicInteger expectedPadding) { |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2625 | Bitmap b; |
| 2626 | |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2627 | int padding = expectedPadding.get(); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2628 | if (v instanceof TextView) { |
| 2629 | Drawable d = ((TextView) v).getCompoundDrawables()[1]; |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 2630 | Rect bounds = getDrawableBounds(d); |
| 2631 | b = Bitmap.createBitmap(bounds.width() + padding, |
| 2632 | bounds.height() + padding, Bitmap.Config.ARGB_8888); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2633 | expectedPadding.set(padding - bounds.left - bounds.top); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2634 | } else { |
| 2635 | b = Bitmap.createBitmap( |
| 2636 | v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2639 | mCanvas.setBitmap(b); |
| 2640 | drawDragView(v, mCanvas, padding); |
| 2641 | mCanvas.setBitmap(null); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2642 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2643 | return b; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | /** |
| 2647 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 2648 | * Responsibility for the bitmap is transferred to the caller. |
| 2649 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2650 | private Bitmap createDragOutline(View v, int padding) { |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2651 | final int outlineColor = getResources().getColor(R.color.outline_color); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2652 | final Bitmap b = Bitmap.createBitmap( |
| 2653 | v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); |
| 2654 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2655 | mCanvas.setBitmap(b); |
| 2656 | drawDragView(v, mCanvas, padding); |
| 2657 | mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor); |
| 2658 | mCanvas.setBitmap(null); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2659 | return b; |
| 2660 | } |
| 2661 | |
| 2662 | /** |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2663 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 2664 | * Responsibility for the bitmap is transferred to the caller. |
| 2665 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2666 | private Bitmap createDragOutline(Bitmap orig, int padding, int w, int h, |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2667 | boolean clipAlpha) { |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2668 | final int outlineColor = getResources().getColor(R.color.outline_color); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2669 | final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2670 | mCanvas.setBitmap(b); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2671 | |
| 2672 | Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight()); |
| 2673 | float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(), |
| 2674 | (h - padding) / (float) orig.getHeight()); |
| 2675 | int scaledWidth = (int) (scaleFactor * orig.getWidth()); |
| 2676 | int scaledHeight = (int) (scaleFactor * orig.getHeight()); |
| 2677 | Rect dst = new Rect(0, 0, scaledWidth, scaledHeight); |
| 2678 | |
| 2679 | // center the image |
| 2680 | dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2); |
| 2681 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2682 | mCanvas.drawBitmap(orig, src, dst, null); |
| 2683 | mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor, |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2684 | clipAlpha); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2685 | mCanvas.setBitmap(null); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2686 | |
| 2687 | return b; |
| 2688 | } |
| 2689 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2690 | void startDrag(CellLayout.CellInfo cellInfo) { |
| 2691 | View child = cellInfo.cell; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2692 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2693 | // 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] | 2694 | if (!child.isInTouchMode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2695 | return; |
| 2696 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2697 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2698 | mDragInfo = cellInfo; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2699 | child.setVisibility(INVISIBLE); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2700 | CellLayout layout = (CellLayout) child.getParent().getParent(); |
| 2701 | layout.prepareChildForDrag(child); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2702 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2703 | beginDragShared(child, this); |
| 2704 | } |
| 2705 | |
| 2706 | public void beginDragShared(View child, DragSource source) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2707 | child.clearFocus(); |
| 2708 | child.setPressed(false); |
| 2709 | |
| 2710 | // The outline is used to visualize where the item will land if dropped |
| 2711 | mDragOutline = createDragOutline(child, DRAG_BITMAP_PADDING); |
| 2712 | |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2713 | mLauncher.onDragStarted(child); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2714 | // The drag bitmap follows the touch point around on the screen |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2715 | AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2716 | final Bitmap b = createDragBitmap(child, padding); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2717 | |
| 2718 | final int bmpWidth = b.getWidth(); |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 2719 | final int bmpHeight = b.getHeight(); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2720 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2721 | float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2722 | int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); |
| 2723 | int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2724 | - padding.get() / 2); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2725 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2726 | LauncherAppState app = LauncherAppState.getInstance(); |
| 2727 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 2728 | Point dragVisualizeOffset = null; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2729 | Rect dragRect = null; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2730 | if (child instanceof BubbleTextView) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2731 | int iconSize = grid.iconSizePx; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2732 | int top = child.getPaddingTop(); |
| 2733 | int left = (bmpWidth - iconSize) / 2; |
| 2734 | int right = left + iconSize; |
| 2735 | int bottom = top + iconSize; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2736 | dragLayerY += top; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 2737 | // Note: The drag region is used to calculate drag layer offsets, but the |
| 2738 | // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2739 | dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2740 | dragRect = new Rect(left, top, right, bottom); |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 2741 | } else if (child instanceof FolderIcon) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2742 | int previewSize = grid.folderIconSizePx; |
| 2743 | dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Winson Chung | 1e9cbfe | 2011-09-30 16:52:26 -0700 | [diff] [blame] | 2746 | // Clear the pressed state if necessary |
| 2747 | if (child instanceof BubbleTextView) { |
| 2748 | BubbleTextView icon = (BubbleTextView) child; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2749 | icon.clearPressedBackground(); |
Winson Chung | 1e9cbfe | 2011-09-30 16:52:26 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Adam Cohen | 2f32ad2 | 2013-11-13 11:29:49 +0000 | [diff] [blame] | 2752 | if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { |
| 2753 | String msg = "Drag started with a view that has no tag set. This " |
| 2754 | + "will cause a crash (issue 11627249) down the line. " |
| 2755 | + "View: " + child + " tag: " + child.getTag(); |
| 2756 | throw new IllegalStateException(msg); |
| 2757 | } |
| 2758 | |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 2759 | DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2760 | DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 2761 | dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 2762 | |
| 2763 | if (child.getParent() instanceof ShortcutAndWidgetContainer) { |
| 2764 | mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); |
| 2765 | } |
| 2766 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2767 | b.recycle(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2768 | } |
| 2769 | |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2770 | public void beginExternalDragShared(View child, DragSource source) { |
| 2771 | LauncherAppState app = LauncherAppState.getInstance(); |
| 2772 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 2773 | int iconSize = grid.iconSizePx; |
| 2774 | |
| 2775 | // Notify launcher of drag start |
| 2776 | mLauncher.onDragStarted(child); |
| 2777 | |
| 2778 | // Compose a new drag bitmap that is of the icon size |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2779 | AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2780 | final Bitmap tmpB = createDragBitmap(child, padding); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2781 | Bitmap b = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); |
| 2782 | Paint p = new Paint(); |
| 2783 | p.setFilterBitmap(true); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2784 | mCanvas.setBitmap(b); |
| 2785 | mCanvas.drawBitmap(tmpB, new Rect(0, 0, tmpB.getWidth(), tmpB.getHeight()), |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2786 | new Rect(0, 0, iconSize, iconSize), p); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2787 | mCanvas.setBitmap(null); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2788 | |
| 2789 | // Find the child's location on the screen |
| 2790 | int bmpWidth = tmpB.getWidth(); |
| 2791 | float iconScale = (float) bmpWidth / iconSize; |
| 2792 | float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY) * iconScale; |
| 2793 | int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); |
| 2794 | int dragLayerY = Math.round(mTempXY[1]); |
| 2795 | |
| 2796 | // Note: The drag region is used to calculate drag layer offsets, but the |
| 2797 | // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2798 | Point dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2799 | Rect dragRect = new Rect(0, 0, iconSize, iconSize); |
| 2800 | |
| 2801 | if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { |
| 2802 | String msg = "Drag started with a view that has no tag set. This " |
| 2803 | + "will cause a crash (issue 11627249) down the line. " |
| 2804 | + "View: " + child + " tag: " + child.getTag(); |
| 2805 | throw new IllegalStateException(msg); |
| 2806 | } |
| 2807 | |
| 2808 | // Start the drag |
| 2809 | DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), |
| 2810 | DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); |
| 2811 | dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); |
| 2812 | |
| 2813 | // Recycle temporary bitmaps |
| 2814 | tmpB.recycle(); |
| 2815 | } |
| 2816 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2817 | void addApplicationShortcut(ShortcutInfo info, CellLayout target, long container, long screenId, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2818 | int cellX, int cellY, boolean insertAtFirst, int intersectX, int intersectY) { |
| 2819 | View view = mLauncher.createShortcut(R.layout.application, target, (ShortcutInfo) info); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2820 | |
| 2821 | final int[] cellXY = new int[2]; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2822 | target.findCellForSpanThatIntersects(cellXY, 1, 1, intersectX, intersectY); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2823 | addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, insertAtFirst); |
Adam Cohen | 7c4c510 | 2013-06-14 17:42:35 -0700 | [diff] [blame] | 2824 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2825 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screenId, cellXY[0], |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2826 | cellXY[1]); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2827 | } |
| 2828 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2829 | public boolean transitionStateShouldAllowDrop() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2830 | return ((!isSwitchingState() || mTransitionProgress > 0.5f) && |
| 2831 | (mState == State.NORMAL || mState == State.SPRING_LOADED)); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2834 | /** |
| 2835 | * {@inheritDoc} |
| 2836 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2837 | public boolean acceptDrop(DragObject d) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2838 | // 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] | 2839 | CellLayout dropTargetLayout = mDropToLayout; |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2840 | if (d.dragSource != this) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2841 | // 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] | 2842 | if (dropTargetLayout == null) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2843 | return false; |
| 2844 | } |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2845 | if (!transitionStateShouldAllowDrop()) return false; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2846 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2847 | mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, |
| 2848 | d.dragView, mDragViewVisualCenter); |
| 2849 | |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 2850 | // We want the point to be mapped to the dragTarget. |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2851 | if (mLauncher.isHotseatLayout(dropTargetLayout)) { |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2852 | mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 2853 | } else { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2854 | mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2857 | int spanX = 1; |
| 2858 | int spanY = 1; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2859 | if (mDragInfo != null) { |
| 2860 | final CellLayout.CellInfo dragCellInfo = mDragInfo; |
| 2861 | spanX = dragCellInfo.spanX; |
| 2862 | spanY = dragCellInfo.spanY; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2863 | } else { |
| 2864 | final ItemInfo dragInfo = (ItemInfo) d.dragInfo; |
| 2865 | spanX = dragInfo.spanX; |
| 2866 | spanY = dragInfo.spanY; |
| 2867 | } |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2868 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2869 | int minSpanX = spanX; |
| 2870 | int minSpanY = spanY; |
| 2871 | if (d.dragInfo instanceof PendingAddWidgetInfo) { |
| 2872 | minSpanX = ((PendingAddWidgetInfo) d.dragInfo).minSpanX; |
| 2873 | minSpanY = ((PendingAddWidgetInfo) d.dragInfo).minSpanY; |
| 2874 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2875 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2876 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2877 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout, |
Adam Cohen | f0777b9 | 2012-02-28 14:02:45 -0800 | [diff] [blame] | 2878 | mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2879 | float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2880 | mDragViewVisualCenter[1], mTargetCell); |
Adam Cohen | ec0d61d | 2014-02-07 16:34:51 -0800 | [diff] [blame] | 2881 | if (mCreateUserFolderOnDrop && willCreateUserFolder((ItemInfo) d.dragInfo, |
| 2882 | dropTargetLayout, mTargetCell, distance, true)) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2883 | return true; |
| 2884 | } |
Adam Cohen | ec0d61d | 2014-02-07 16:34:51 -0800 | [diff] [blame] | 2885 | |
| 2886 | if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder((ItemInfo) d.dragInfo, |
| 2887 | dropTargetLayout, mTargetCell, distance)) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2888 | return true; |
| 2889 | } |
| 2890 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2891 | int[] resultSpan = new int[2]; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 2892 | mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2893 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, |
| 2894 | null, mTargetCell, resultSpan, CellLayout.MODE_ACCEPT_DROP); |
| 2895 | boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0; |
| 2896 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2897 | // 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] | 2898 | if (!foundCell) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2899 | // Don't show the message if we are dropping on the AllApps button and the hotseat |
| 2900 | // is full |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2901 | boolean isHotseat = mLauncher.isHotseatLayout(dropTargetLayout); |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 2902 | if (mTargetCell != null && isHotseat) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2903 | Hotseat hotseat = mLauncher.getHotseat(); |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 2904 | if (hotseat.isAllAppsButtonRank( |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2905 | hotseat.getOrderInHotseat(mTargetCell[0], mTargetCell[1]))) { |
| 2906 | return false; |
| 2907 | } |
| 2908 | } |
| 2909 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 2910 | mLauncher.showOutOfSpaceMessage(isHotseat); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2911 | return false; |
| 2912 | } |
| 2913 | } |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2914 | |
| 2915 | long screenId = getIdForScreen(dropTargetLayout); |
| 2916 | if (screenId == EXTRA_EMPTY_SCREEN_ID) { |
| 2917 | commitExtraEmptyScreen(); |
| 2918 | } |
| 2919 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2920 | return true; |
| 2921 | } |
| 2922 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2923 | boolean willCreateUserFolder(ItemInfo info, CellLayout target, int[] targetCell, float |
| 2924 | distance, boolean considerTimeout) { |
| 2925 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2926 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
| 2927 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2928 | if (dropOverView != null) { |
| 2929 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams(); |
| 2930 | if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) { |
| 2931 | return false; |
| 2932 | } |
| 2933 | } |
| 2934 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2935 | boolean hasntMoved = false; |
| 2936 | if (mDragInfo != null) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2937 | hasntMoved = dropOverView == mDragInfo.cell; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2938 | } |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2939 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2940 | if (dropOverView == null || hasntMoved || (considerTimeout && !mCreateUserFolderOnDrop)) { |
| 2941 | return false; |
| 2942 | } |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2943 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2944 | boolean aboveShortcut = (dropOverView.getTag() instanceof ShortcutInfo); |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2945 | boolean willBecomeShortcut = |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2946 | (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 2947 | info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT); |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2948 | |
| 2949 | return (aboveShortcut && willBecomeShortcut); |
| 2950 | } |
| 2951 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2952 | boolean willAddToExistingUserFolder(Object dragInfo, CellLayout target, int[] targetCell, |
| 2953 | float distance) { |
| 2954 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2955 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2956 | |
| 2957 | if (dropOverView != null) { |
| 2958 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams(); |
| 2959 | if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) { |
| 2960 | return false; |
| 2961 | } |
| 2962 | } |
| 2963 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2964 | if (dropOverView instanceof FolderIcon) { |
| 2965 | FolderIcon fi = (FolderIcon) dropOverView; |
| 2966 | if (fi.acceptDrop(dragInfo)) { |
| 2967 | return true; |
| 2968 | } |
| 2969 | } |
| 2970 | return false; |
| 2971 | } |
| 2972 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2973 | boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2974 | int[] targetCell, float distance, boolean external, DragView dragView, |
| 2975 | Runnable postAnimationRunnable) { |
| 2976 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2977 | View v = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2978 | |
Winson Chung | ec9a0a4 | 2011-07-20 20:42:13 -0700 | [diff] [blame] | 2979 | boolean hasntMoved = false; |
| 2980 | if (mDragInfo != null) { |
| 2981 | CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell); |
| 2982 | hasntMoved = (mDragInfo.cellX == targetCell[0] && |
| 2983 | mDragInfo.cellY == targetCell[1]) && (cellParent == target); |
| 2984 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2985 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2986 | if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false; |
| 2987 | mCreateUserFolderOnDrop = false; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2988 | final long screenId = (targetCell == null) ? mDragInfo.screenId : getIdForScreen(target); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2989 | |
| 2990 | boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo); |
| 2991 | boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo); |
| 2992 | |
| 2993 | if (aboveShortcut && willBecomeShortcut) { |
| 2994 | ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag(); |
| 2995 | ShortcutInfo destInfo = (ShortcutInfo) v.getTag(); |
| 2996 | // if the drag started here, we need to remove it from the workspace |
| 2997 | if (!external) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2998 | getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 3001 | Rect folderLocation = new Rect(); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 3002 | float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 3003 | target.removeView(v); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 3004 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3005 | FolderIcon fi = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3006 | mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 3007 | destInfo.cellX = -1; |
| 3008 | destInfo.cellY = -1; |
| 3009 | sourceInfo.cellX = -1; |
| 3010 | sourceInfo.cellY = -1; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 3011 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3012 | // If the dragView is null, we can't animate |
| 3013 | boolean animate = dragView != null; |
| 3014 | if (animate) { |
| 3015 | fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale, |
| 3016 | postAnimationRunnable); |
| 3017 | } else { |
| 3018 | fi.addItem(destInfo); |
| 3019 | fi.addItem(sourceInfo); |
| 3020 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 3021 | return true; |
| 3022 | } |
| 3023 | return false; |
| 3024 | } |
| 3025 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 3026 | boolean addToExistingFolderIfNecessary(View newView, CellLayout target, int[] targetCell, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3027 | float distance, DragObject d, boolean external) { |
| 3028 | if (distance > mMaxDistanceForFolderCreation) return false; |
| 3029 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 3030 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3031 | if (!mAddToExistingFolderOnDrop) return false; |
| 3032 | mAddToExistingFolderOnDrop = false; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3033 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3034 | if (dropOverView instanceof FolderIcon) { |
| 3035 | FolderIcon fi = (FolderIcon) dropOverView; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 3036 | if (fi.acceptDrop(d.dragInfo)) { |
| 3037 | fi.onDrop(d); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3038 | |
| 3039 | // if the drag started here, we need to remove it from the workspace |
| 3040 | if (!external) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3041 | getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3042 | } |
| 3043 | return true; |
| 3044 | } |
| 3045 | } |
| 3046 | return false; |
| 3047 | } |
| 3048 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3049 | public void onDrop(final DragObject d) { |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 3050 | mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3051 | mDragViewVisualCenter); |
| 3052 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3053 | CellLayout dropTargetLayout = mDropToLayout; |
| 3054 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3055 | // We want the point to be mapped to the dragTarget. |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3056 | if (dropTargetLayout != null) { |
| 3057 | if (mLauncher.isHotseatLayout(dropTargetLayout)) { |
Adam Cohen | bb00ff2 | 2012-07-12 15:43:01 -0700 | [diff] [blame] | 3058 | mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3059 | } else { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3060 | mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3061 | } |
Adam Cohen | ba78161 | 2011-05-09 14:37:39 -0700 | [diff] [blame] | 3062 | } |
Michael Jurka | c6ee42e | 2010-09-30 12:04:50 -0700 | [diff] [blame] | 3063 | |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 3064 | int snapScreen = -1; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3065 | boolean resizeOnDrop = false; |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 3066 | if (d.dragSource != this) { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3067 | final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], |
| 3068 | (int) mDragViewVisualCenter[1] }; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 3069 | onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d); |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 3070 | } else if (mDragInfo != null) { |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 3071 | final View cell = mDragInfo.cell; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3072 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3073 | Runnable resizeRunnable = null; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3074 | if (dropTargetLayout != null && !d.cancelled) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3075 | // Move internally |
Winson Chung | 40e882b | 2011-07-21 19:01:11 -0700 | [diff] [blame] | 3076 | boolean hasMovedLayouts = (getParentCellLayoutForView(cell) != dropTargetLayout); |
| 3077 | boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout); |
| 3078 | long container = hasMovedIntoHotseat ? |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3079 | LauncherSettings.Favorites.CONTAINER_HOTSEAT : |
| 3080 | LauncherSettings.Favorites.CONTAINER_DESKTOP; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3081 | long screenId = (mTargetCell[0] < 0) ? |
| 3082 | mDragInfo.screenId : getIdForScreen(dropTargetLayout); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3083 | int spanX = mDragInfo != null ? mDragInfo.spanX : 1; |
| 3084 | int spanY = mDragInfo != null ? mDragInfo.spanY : 1; |
| 3085 | // First we find the cell nearest to point at which the item is |
| 3086 | // dropped, without any consideration to whether there is an item there. |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3087 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3088 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) |
| 3089 | mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3090 | float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 3091 | mDragViewVisualCenter[1], mTargetCell); |
| 3092 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3093 | // If the item being dropped is a shortcut and the nearest drop |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 3094 | // 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] | 3095 | if (!mInScrollArea && createUserFolderIfNecessary(cell, container, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3096 | dropTargetLayout, mTargetCell, distance, false, d.dragView, null)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3097 | return; |
| 3098 | } |
| 3099 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3100 | if (addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, |
| 3101 | distance, d, false)) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3102 | return; |
| 3103 | } |
| 3104 | |
| 3105 | // Aside from the special case where we're dropping a shortcut onto a shortcut, |
| 3106 | // we need to find the nearest cell location that is vacant |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3107 | ItemInfo item = (ItemInfo) d.dragInfo; |
| 3108 | int minSpanX = item.spanX; |
| 3109 | int minSpanY = item.spanY; |
| 3110 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 3111 | minSpanX = item.minSpanX; |
| 3112 | minSpanY = item.minSpanY; |
| 3113 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3114 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3115 | int[] resultSpan = new int[2]; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3116 | mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3117 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, |
| 3118 | mTargetCell, resultSpan, CellLayout.MODE_ON_DROP); |
| 3119 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3120 | boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0; |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 3121 | |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 3122 | // if the widget resizes on drop |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 3123 | if (foundCell && (cell instanceof AppWidgetHostView) && |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 3124 | (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY)) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3125 | resizeOnDrop = true; |
| 3126 | item.spanX = resultSpan[0]; |
| 3127 | item.spanY = resultSpan[1]; |
Adam Cohen | 7bdfc97 | 2012-05-22 16:50:35 -0700 | [diff] [blame] | 3128 | AppWidgetHostView awhv = (AppWidgetHostView) cell; |
| 3129 | AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, resultSpan[0], |
| 3130 | resultSpan[1]); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3131 | } |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3132 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3133 | if (getScreenIdForPageIndex(mCurrentPage) != screenId && !hasMovedIntoHotseat) { |
| 3134 | snapScreen = getPageIndexForScreenId(screenId); |
| 3135 | snapToPage(snapScreen); |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3136 | } |
| 3137 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3138 | if (foundCell) { |
| 3139 | final ItemInfo info = (ItemInfo) cell.getTag(); |
Winson Chung | 40e882b | 2011-07-21 19:01:11 -0700 | [diff] [blame] | 3140 | if (hasMovedLayouts) { |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 3141 | // Reparent the view |
Sunny Goyal | 25611b1 | 2014-07-22 09:52:37 -0700 | [diff] [blame] | 3142 | CellLayout parentCell = getParentCellLayoutForView(cell); |
| 3143 | if (parentCell != null) { |
| 3144 | parentCell.removeView(cell); |
| 3145 | } else if (LauncherAppState.isDogfoodBuild()) { |
| 3146 | throw new NullPointerException("mDragInfo.cell has null parent"); |
| 3147 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3148 | addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1], |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3149 | info.spanX, info.spanY); |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | // update the item's position after drop |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 3153 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3154 | lp.cellX = lp.tmpCellX = mTargetCell[0]; |
| 3155 | lp.cellY = lp.tmpCellY = mTargetCell[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3156 | lp.cellHSpan = item.spanX; |
| 3157 | lp.cellVSpan = item.spanY; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3158 | lp.isLockedToGrid = true; |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 3159 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3160 | if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 3161 | cell instanceof LauncherAppWidgetHostView) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 3162 | final CellLayout cellLayout = dropTargetLayout; |
| 3163 | // We post this call so that the widget has a chance to be placed |
| 3164 | // in its final location |
| 3165 | |
| 3166 | final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3167 | LauncherAppWidgetProviderInfo pInfo = (LauncherAppWidgetProviderInfo) |
| 3168 | hostView.getAppWidgetInfo(); |
| 3169 | if (pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3170 | final Runnable addResizeFrame = new Runnable() { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 3171 | public void run() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 3172 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3173 | dragLayer.addResizeFrame(info, hostView, cellLayout); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 3174 | } |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 3175 | }; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3176 | resizeRunnable = (new Runnable() { |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 3177 | public void run() { |
| 3178 | if (!isPageMoving()) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3179 | addResizeFrame.run(); |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 3180 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3181 | mDelayedResizeRunnable = addResizeFrame; |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 3182 | } |
| 3183 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 3184 | }); |
| 3185 | } |
| 3186 | } |
| 3187 | |
Adam Cohen | 949debe | 2013-09-29 14:22:48 -0700 | [diff] [blame] | 3188 | LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, lp.cellX, |
| 3189 | lp.cellY, item.spanX, item.spanY); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3190 | } else { |
| 3191 | // If we can't find a drop location, we return the item to its original position |
| 3192 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); |
| 3193 | mTargetCell[0] = lp.cellX; |
| 3194 | mTargetCell[1] = lp.cellY; |
Adam Cohen | f1dcdf6 | 2012-05-10 16:51:52 -0700 | [diff] [blame] | 3195 | CellLayout layout = (CellLayout) cell.getParent().getParent(); |
| 3196 | layout.markCellsAsOccupiedForView(cell); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 3197 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3198 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 3199 | |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 3200 | final CellLayout parent = (CellLayout) cell.getParent().getParent(); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3201 | final Runnable finalResizeRunnable = resizeRunnable; |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 3202 | // Prepare it to be animated into its new position |
| 3203 | // This must be called after the view has been re-parented |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3204 | final Runnable onCompleteRunnable = new Runnable() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3205 | @Override |
| 3206 | public void run() { |
| 3207 | mAnimatingViewIntoPlace = false; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 3208 | updateChildrenLayersEnabled(false); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3209 | if (finalResizeRunnable != null) { |
| 3210 | finalResizeRunnable.run(); |
| 3211 | } |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3212 | } |
| 3213 | }; |
| 3214 | mAnimatingViewIntoPlace = true; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 3215 | if (d.dragView.hasDrawn()) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3216 | final ItemInfo info = (ItemInfo) cell.getTag(); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3217 | boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET |
| 3218 | || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
| 3219 | if (isWidget) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3220 | int animationType = resizeOnDrop ? ANIMATE_INTO_POSITION_AND_RESIZE : |
| 3221 | ANIMATE_INTO_POSITION_AND_DISAPPEAR; |
| 3222 | animateWidgetDrop(info, parent, d.dragView, |
| 3223 | onCompleteRunnable, animationType, cell, false); |
| 3224 | } else { |
Adam Cohen | 85b467b | 2012-02-29 15:38:46 -0800 | [diff] [blame] | 3225 | int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION; |
| 3226 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, |
| 3227 | onCompleteRunnable, this); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3228 | } |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 3229 | } else { |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 3230 | d.deferDragViewCleanupPostAnimation = false; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 3231 | cell.setVisibility(VISIBLE); |
| 3232 | } |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 3233 | parent.onDropChild(cell); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3234 | } |
| 3235 | } |
| 3236 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3237 | public void setFinalScrollForPageChange(int pageIndex) { |
| 3238 | CellLayout cl = (CellLayout) getChildAt(pageIndex); |
| 3239 | if (cl != null) { |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 3240 | mSavedScrollX = getScrollX(); |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 3241 | mSavedTranslationX = cl.getTranslationX(); |
| 3242 | mSavedRotationY = cl.getRotationY(); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 3243 | final int newX = getScrollForPage(pageIndex); |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 3244 | setScrollX(newX); |
| 3245 | cl.setTranslationX(0f); |
| 3246 | cl.setRotationY(0f); |
| 3247 | } |
| 3248 | } |
| 3249 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3250 | public void resetFinalScrollForPageChange(int pageIndex) { |
| 3251 | if (pageIndex >= 0) { |
| 3252 | CellLayout cl = (CellLayout) getChildAt(pageIndex); |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 3253 | setScrollX(mSavedScrollX); |
| 3254 | cl.setTranslationX(mSavedTranslationX); |
| 3255 | cl.setRotationY(mSavedRotationY); |
| 3256 | } |
| 3257 | } |
| 3258 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 3259 | public void getViewLocationRelativeToSelf(View v, int[] location) { |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 3260 | getLocationInWindow(location); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3261 | int x = location[0]; |
| 3262 | int y = location[1]; |
| 3263 | |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 3264 | v.getLocationInWindow(location); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3265 | int vX = location[0]; |
| 3266 | int vY = location[1]; |
| 3267 | |
| 3268 | location[0] = vX - x; |
| 3269 | location[1] = vY - y; |
| 3270 | } |
| 3271 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 3272 | public void onDragEnter(DragObject d) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3273 | mDragEnforcer.onDragEnter(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3274 | mCreateUserFolderOnDrop = false; |
| 3275 | mAddToExistingFolderOnDrop = false; |
| 3276 | |
| 3277 | mDropToLayout = null; |
| 3278 | CellLayout layout = getCurrentDropLayout(); |
| 3279 | setCurrentDropLayout(layout); |
| 3280 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 3281 | |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 3282 | if (!workspaceInModalState()) { |
| 3283 | mLauncher.getDragLayer().showPageHints(); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3284 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3285 | } |
| 3286 | |
Winson Chung | fe411c8 | 2013-09-26 16:07:17 -0700 | [diff] [blame] | 3287 | /** Return a rect that has the cellWidth/cellHeight (left, top), and |
| 3288 | * widthGap/heightGap (right, bottom) */ |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 3289 | static Rect getCellLayoutMetrics(Launcher launcher, int orientation) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 3290 | LauncherAppState app = LauncherAppState.getInstance(); |
| 3291 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 3292 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 3293 | Display display = launcher.getWindowManager().getDefaultDisplay(); |
| 3294 | Point smallestSize = new Point(); |
| 3295 | Point largestSize = new Point(); |
| 3296 | display.getCurrentSizeRange(smallestSize, largestSize); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 3297 | int countX = (int) grid.numColumns; |
| 3298 | int countY = (int) grid.numRows; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 3299 | if (orientation == CellLayout.LANDSCAPE) { |
| 3300 | if (mLandscapeCellLayoutMetrics == null) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 3301 | Rect padding = grid.getWorkspacePadding(CellLayout.LANDSCAPE); |
Winson Chung | dcd27ba | 2013-12-11 15:28:15 -0800 | [diff] [blame] | 3302 | int width = largestSize.x - padding.left - padding.right; |
| 3303 | int height = smallestSize.y - padding.top - padding.bottom; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 3304 | mLandscapeCellLayoutMetrics = new Rect(); |
Winson Chung | fe411c8 | 2013-09-26 16:07:17 -0700 | [diff] [blame] | 3305 | mLandscapeCellLayoutMetrics.set( |
| 3306 | grid.calculateCellWidth(width, countX), |
| 3307 | grid.calculateCellHeight(height, countY), 0, 0); |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 3308 | } |
| 3309 | return mLandscapeCellLayoutMetrics; |
| 3310 | } else if (orientation == CellLayout.PORTRAIT) { |
| 3311 | if (mPortraitCellLayoutMetrics == null) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 3312 | Rect padding = grid.getWorkspacePadding(CellLayout.PORTRAIT); |
Winson Chung | dcd27ba | 2013-12-11 15:28:15 -0800 | [diff] [blame] | 3313 | int width = smallestSize.x - padding.left - padding.right; |
| 3314 | int height = largestSize.y - padding.top - padding.bottom; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 3315 | mPortraitCellLayoutMetrics = new Rect(); |
Winson Chung | fe411c8 | 2013-09-26 16:07:17 -0700 | [diff] [blame] | 3316 | mPortraitCellLayoutMetrics.set( |
| 3317 | grid.calculateCellWidth(width, countX), |
| 3318 | grid.calculateCellHeight(height, countY), 0, 0); |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 3319 | } |
| 3320 | return mPortraitCellLayoutMetrics; |
| 3321 | } |
| 3322 | return null; |
| 3323 | } |
| 3324 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3325 | public void onDragExit(DragObject d) { |
| 3326 | mDragEnforcer.onDragExit(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3327 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3328 | // Here we store the final page that will be dropped to, if the workspace in fact |
| 3329 | // receives the drop |
| 3330 | if (mInScrollArea) { |
Winson Chung | cc1cfe4 | 2012-06-18 15:09:17 -0700 | [diff] [blame] | 3331 | if (isPageMoving()) { |
| 3332 | // If the user drops while the page is scrolling, we should use that page as the |
| 3333 | // destination instead of the page that is being hovered over. |
| 3334 | mDropToLayout = (CellLayout) getPageAt(getNextPage()); |
| 3335 | } else { |
| 3336 | mDropToLayout = mDragOverlappingLayout; |
| 3337 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3338 | } else { |
| 3339 | mDropToLayout = mDragTargetLayout; |
| 3340 | } |
| 3341 | |
| 3342 | if (mDragMode == DRAG_MODE_CREATE_FOLDER) { |
| 3343 | mCreateUserFolderOnDrop = true; |
| 3344 | } else if (mDragMode == DRAG_MODE_ADD_TO_FOLDER) { |
| 3345 | mAddToExistingFolderOnDrop = true; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3346 | } |
| 3347 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3348 | // Reset the scroll area and previous drag target |
| 3349 | onResetScrollArea(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3350 | setCurrentDropLayout(null); |
| 3351 | setCurrentDragOverlappingLayout(null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3352 | |
Adam Cohen | 74c28d1 | 2011-11-18 14:17:11 -0800 | [diff] [blame] | 3353 | mSpringLoadedDragController.cancel(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3354 | |
| 3355 | if (!mIsPageMoving) { |
| 3356 | hideOutlines(); |
| 3357 | } |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 3358 | mLauncher.getDragLayer().hidePageHints(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3361 | void setCurrentDropLayout(CellLayout layout) { |
| 3362 | if (mDragTargetLayout != null) { |
| 3363 | mDragTargetLayout.revertTempState(); |
| 3364 | mDragTargetLayout.onDragExit(); |
| 3365 | } |
| 3366 | mDragTargetLayout = layout; |
| 3367 | if (mDragTargetLayout != null) { |
| 3368 | mDragTargetLayout.onDragEnter(); |
| 3369 | } |
| 3370 | cleanupReorder(true); |
| 3371 | cleanupFolderCreation(); |
| 3372 | setCurrentDropOverCell(-1, -1); |
| 3373 | } |
| 3374 | |
| 3375 | void setCurrentDragOverlappingLayout(CellLayout layout) { |
| 3376 | if (mDragOverlappingLayout != null) { |
| 3377 | mDragOverlappingLayout.setIsDragOverlapping(false); |
| 3378 | } |
| 3379 | mDragOverlappingLayout = layout; |
| 3380 | if (mDragOverlappingLayout != null) { |
| 3381 | mDragOverlappingLayout.setIsDragOverlapping(true); |
| 3382 | } |
| 3383 | invalidate(); |
| 3384 | } |
| 3385 | |
| 3386 | void setCurrentDropOverCell(int x, int y) { |
| 3387 | if (x != mDragOverX || y != mDragOverY) { |
| 3388 | mDragOverX = x; |
| 3389 | mDragOverY = y; |
| 3390 | setDragMode(DRAG_MODE_NONE); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | void setDragMode(int dragMode) { |
| 3395 | if (dragMode != mDragMode) { |
| 3396 | if (dragMode == DRAG_MODE_NONE) { |
| 3397 | cleanupAddToFolder(); |
| 3398 | // We don't want to cancel the re-order alarm every time the target cell changes |
| 3399 | // as this feels to slow / unresponsive. |
| 3400 | cleanupReorder(false); |
| 3401 | cleanupFolderCreation(); |
| 3402 | } else if (dragMode == DRAG_MODE_ADD_TO_FOLDER) { |
| 3403 | cleanupReorder(true); |
| 3404 | cleanupFolderCreation(); |
| 3405 | } else if (dragMode == DRAG_MODE_CREATE_FOLDER) { |
| 3406 | cleanupAddToFolder(); |
| 3407 | cleanupReorder(true); |
| 3408 | } else if (dragMode == DRAG_MODE_REORDER) { |
| 3409 | cleanupAddToFolder(); |
| 3410 | cleanupFolderCreation(); |
| 3411 | } |
| 3412 | mDragMode = dragMode; |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | private void cleanupFolderCreation() { |
| 3417 | if (mDragFolderRingAnimator != null) { |
| 3418 | mDragFolderRingAnimator.animateToNaturalState(); |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 3419 | mDragFolderRingAnimator = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3420 | } |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 3421 | mFolderCreationAlarm.setOnAlarmListener(null); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3422 | mFolderCreationAlarm.cancelAlarm(); |
| 3423 | } |
| 3424 | |
| 3425 | private void cleanupAddToFolder() { |
| 3426 | if (mDragOverFolderIcon != null) { |
| 3427 | mDragOverFolderIcon.onDragExit(null); |
| 3428 | mDragOverFolderIcon = null; |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | private void cleanupReorder(boolean cancelAlarm) { |
| 3433 | // Any pending reorders are canceled |
| 3434 | if (cancelAlarm) { |
| 3435 | mReorderAlarm.cancelAlarm(); |
| 3436 | } |
| 3437 | mLastReorderX = -1; |
| 3438 | mLastReorderY = -1; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3441 | /* |
| 3442 | * |
| 3443 | * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's |
| 3444 | * coordinate space. The argument xy is modified with the return result. |
| 3445 | * |
| 3446 | * 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] | 3447 | * computing it itself; we use this to avoid redundant matrix inversions in |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3448 | * findMatchingPageForDragOver |
| 3449 | * |
| 3450 | */ |
| 3451 | void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3452 | xy[0] = xy[0] - v.getLeft(); |
| 3453 | xy[1] = xy[1] - v.getTop(); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3456 | boolean isPointInSelfOverHotseat(int x, int y, Rect r) { |
| 3457 | if (r == null) { |
| 3458 | r = new Rect(); |
| 3459 | } |
| 3460 | mTempPt[0] = x; |
| 3461 | mTempPt[1] = y; |
| 3462 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempPt, true); |
Winson Chung | abedd9f | 2013-09-24 15:41:09 -0700 | [diff] [blame] | 3463 | |
| 3464 | LauncherAppState app = LauncherAppState.getInstance(); |
| 3465 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 3466 | r = grid.getHotseatRect(); |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3467 | if (r.contains(mTempPt[0], mTempPt[1])) { |
| 3468 | return true; |
| 3469 | } |
| 3470 | return false; |
| 3471 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3472 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3473 | void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3474 | mTempPt[0] = (int) xy[0]; |
| 3475 | mTempPt[1] = (int) xy[1]; |
| 3476 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempPt, true); |
Winson Chung | 156ab5b | 2013-07-12 14:14:16 -0700 | [diff] [blame] | 3477 | mLauncher.getDragLayer().mapCoordInSelfToDescendent(hotseat.getLayout(), mTempPt); |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3478 | |
| 3479 | xy[0] = mTempPt[0]; |
| 3480 | xy[1] = mTempPt[1]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3481 | } |
| 3482 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3483 | /* |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3484 | * |
| 3485 | * Convert the 2D coordinate xy from this CellLayout's coordinate space to |
| 3486 | * the parent View's coordinate space. The argument xy is modified with the return result. |
| 3487 | * |
| 3488 | */ |
| 3489 | void mapPointFromChildToSelf(View v, float[] xy) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3490 | xy[0] += v.getLeft(); |
| 3491 | xy[1] += v.getTop(); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3494 | static private float squaredDistance(float[] point1, float[] point2) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3495 | float distanceX = point1[0] - point2[0]; |
| 3496 | float distanceY = point2[1] - point2[1]; |
| 3497 | return distanceX * distanceX + distanceY * distanceY; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3498 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3499 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3500 | /* |
| 3501 | * |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3502 | * This method returns the CellLayout that is currently being dragged to. In order to drag |
| 3503 | * to a CellLayout, either the touch point must be directly over the CellLayout, or as a second |
| 3504 | * strategy, we see if the dragView is overlapping any CellLayout and choose the closest one |
| 3505 | * |
| 3506 | * Return null if no CellLayout is currently being dragged over |
| 3507 | * |
| 3508 | */ |
| 3509 | private CellLayout findMatchingPageForDragOver( |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3510 | DragView dragView, float originX, float originY, boolean exact) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3511 | // We loop through all the screens (ie CellLayouts) and see which ones overlap |
| 3512 | // 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] | 3513 | final int screenCount = getChildCount(); |
| 3514 | CellLayout bestMatchingScreen = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3515 | float smallestDistSoFar = Float.MAX_VALUE; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3516 | |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3517 | for (int i = 0; i < screenCount; i++) { |
Adam Cohen | df041bc | 2013-09-22 12:32:22 -0700 | [diff] [blame] | 3518 | // The custom content screen is not a valid drag over option |
| 3519 | if (mScreenOrder.get(i) == CUSTOM_CONTENT_SCREEN_ID) { |
| 3520 | continue; |
| 3521 | } |
| 3522 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3523 | CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3524 | |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3525 | final float[] touchXy = {originX, originY}; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3526 | // Transform the touch coordinates to the CellLayout's local coordinates |
| 3527 | // 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] | 3528 | cl.getMatrix().invert(mTempInverseMatrix); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3529 | mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3530 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3531 | if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && |
| 3532 | touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) { |
| 3533 | return cl; |
| 3534 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3535 | |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 3536 | if (!exact) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3537 | // Get the center of the cell layout in screen coordinates |
| 3538 | final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates; |
| 3539 | cellLayoutCenter[0] = cl.getWidth()/2; |
| 3540 | cellLayoutCenter[1] = cl.getHeight()/2; |
| 3541 | mapPointFromChildToSelf(cl, cellLayoutCenter); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3542 | |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3543 | touchXy[0] = originX; |
| 3544 | touchXy[1] = originY; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3545 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3546 | // Calculate the distance between the center of the CellLayout |
| 3547 | // and the touch point |
| 3548 | float dist = squaredDistance(touchXy, cellLayoutCenter); |
| 3549 | |
| 3550 | if (dist < smallestDistSoFar) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3551 | smallestDistSoFar = dist; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3552 | bestMatchingScreen = cl; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3553 | } |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3554 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3555 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3556 | return bestMatchingScreen; |
| 3557 | } |
| 3558 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3559 | // This is used to compute the visual center of the dragView. This point is then |
| 3560 | // used to visualize drop locations and determine where to drop an item. The idea is that |
| 3561 | // the visual center represents the user's interpretation of where the item is, and hence |
| 3562 | // is the appropriate point to use when determining drop location. |
| 3563 | private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset, |
| 3564 | DragView dragView, float[] recycle) { |
| 3565 | float res[]; |
| 3566 | if (recycle == null) { |
| 3567 | res = new float[2]; |
| 3568 | } else { |
| 3569 | res = recycle; |
| 3570 | } |
| 3571 | |
| 3572 | // First off, the drag view has been shifted in a way that is not represented in the |
| 3573 | // x and y values or the x/yOffsets. Here we account for that shift. |
| 3574 | x += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetX); |
| 3575 | y += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY); |
| 3576 | |
| 3577 | // These represent the visual top and left of drag view if a dragRect was provided. |
| 3578 | // If a dragRect was not provided, then they correspond to the actual view left and |
| 3579 | // top, as the dragRect is in that case taken to be the entire dragView. |
| 3580 | // R.dimen.dragViewOffsetY. |
| 3581 | int left = x - xOffset; |
| 3582 | int top = y - yOffset; |
| 3583 | |
| 3584 | // In order to find the visual center, we shift by half the dragRect |
| 3585 | res[0] = left + dragView.getDragRegion().width() / 2; |
| 3586 | res[1] = top + dragView.getDragRegion().height() / 2; |
| 3587 | |
| 3588 | return res; |
| 3589 | } |
| 3590 | |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 3591 | private boolean isDragWidget(DragObject d) { |
| 3592 | return (d.dragInfo instanceof LauncherAppWidgetInfo || |
| 3593 | d.dragInfo instanceof PendingAddWidgetInfo); |
| 3594 | } |
| 3595 | private boolean isExternalDragWidget(DragObject d) { |
| 3596 | return d.dragSource != this && isDragWidget(d); |
| 3597 | } |
| 3598 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 3599 | public void onDragOver(DragObject d) { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3600 | // Skip drag over events while we are dragging over side pages |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3601 | if (mInScrollArea || !transitionStateShouldAllowDrop()) return; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3602 | |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3603 | Rect r = new Rect(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3604 | CellLayout layout = null; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3605 | ItemInfo item = (ItemInfo) d.dragInfo; |
Sunny Goyal | 25611b1 | 2014-07-22 09:52:37 -0700 | [diff] [blame] | 3606 | if (item == null) { |
| 3607 | if (LauncherAppState.isDogfoodBuild()) { |
| 3608 | throw new NullPointerException("DragObject has null info"); |
| 3609 | } |
| 3610 | return; |
| 3611 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3612 | |
| 3613 | // Ensure that we have proper spans for the item that we are dropping |
| 3614 | 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] | 3615 | mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3616 | d.dragView, mDragViewVisualCenter); |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3617 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3618 | final View child = (mDragInfo == null) ? null : mDragInfo.cell; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3619 | // Identify whether we have dragged over a side page |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3620 | if (workspaceInModalState()) { |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 3621 | if (mLauncher.getHotseat() != null && !isExternalDragWidget(d)) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3622 | if (isPointInSelfOverHotseat(d.x, d.y, r)) { |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3623 | layout = mLauncher.getHotseat().getLayout(); |
| 3624 | } |
| 3625 | } |
| 3626 | if (layout == null) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 3627 | layout = findMatchingPageForDragOver(d.dragView, d.x, d.y, false); |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3628 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3629 | if (layout != mDragTargetLayout) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3630 | setCurrentDropLayout(layout); |
| 3631 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3632 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3633 | boolean isInSpringLoadedMode = (mState == State.SPRING_LOADED); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3634 | if (isInSpringLoadedMode) { |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3635 | if (mLauncher.isHotseatLayout(layout)) { |
| 3636 | mSpringLoadedDragController.cancel(); |
| 3637 | } else { |
| 3638 | mSpringLoadedDragController.setAlarm(mDragTargetLayout); |
| 3639 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3640 | } |
| 3641 | } |
| 3642 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3643 | // 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] | 3644 | if (mLauncher.getHotseat() != null && !isDragWidget(d)) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3645 | if (isPointInSelfOverHotseat(d.x, d.y, r)) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3646 | layout = mLauncher.getHotseat().getLayout(); |
| 3647 | } |
| 3648 | } |
| 3649 | if (layout == null) { |
| 3650 | layout = getCurrentDropLayout(); |
| 3651 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3652 | if (layout != mDragTargetLayout) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3653 | setCurrentDropLayout(layout); |
| 3654 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | // Handle the drag over |
| 3659 | if (mDragTargetLayout != null) { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3660 | // We want the point to be mapped to the dragTarget. |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3661 | if (mLauncher.isHotseatLayout(mDragTargetLayout)) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3662 | mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3663 | } else { |
| 3664 | mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null); |
| 3665 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3666 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3667 | ItemInfo info = (ItemInfo) d.dragInfo; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3668 | |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3669 | int minSpanX = item.spanX; |
| 3670 | int minSpanY = item.spanY; |
| 3671 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 3672 | minSpanX = item.minSpanX; |
| 3673 | minSpanY = item.minSpanY; |
| 3674 | } |
| 3675 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3676 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3677 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, |
Adam Cohen | d024f98 | 2012-05-23 18:26:45 -0700 | [diff] [blame] | 3678 | mDragTargetLayout, mTargetCell); |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3679 | int reorderX = mTargetCell[0]; |
| 3680 | int reorderY = mTargetCell[1]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3681 | |
| 3682 | setCurrentDropOverCell(mTargetCell[0], mTargetCell[1]); |
| 3683 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3684 | float targetCellDistance = mDragTargetLayout.getDistanceFromCell( |
| 3685 | mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); |
| 3686 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3687 | final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], |
| 3688 | mTargetCell[1]); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3689 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3690 | manageFolderFeedback(info, mDragTargetLayout, mTargetCell, |
| 3691 | targetCellDistance, dragOverView); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3692 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3693 | boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied((int) |
| 3694 | mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], item.spanX, |
| 3695 | item.spanY, child, mTargetCell); |
| 3696 | |
| 3697 | if (!nearestDropOccupied) { |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3698 | mDragTargetLayout.visualizeDropLocation(child, mDragOutline, |
| 3699 | (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], |
| 3700 | mTargetCell[0], mTargetCell[1], item.spanX, item.spanY, false, |
| 3701 | d.dragView.getDragVisualizeOffset(), d.dragView.getDragRegion()); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3702 | } else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER) |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3703 | && !mReorderAlarm.alarmPending() && (mLastReorderX != reorderX || |
| 3704 | mLastReorderY != reorderY)) { |
Adam Cohen | d024f98 | 2012-05-23 18:26:45 -0700 | [diff] [blame] | 3705 | |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3706 | int[] resultSpan = new int[2]; |
| 3707 | mDragTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
| 3708 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, item.spanX, item.spanY, |
| 3709 | child, mTargetCell, resultSpan, CellLayout.MODE_SHOW_REORDER_HINT); |
| 3710 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3711 | // Otherwise, if we aren't adding to or creating a folder and there's no pending |
| 3712 | // reorder, then we schedule a reorder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3713 | ReorderAlarmListener listener = new ReorderAlarmListener(mDragViewVisualCenter, |
| 3714 | minSpanX, minSpanY, item.spanX, item.spanY, d.dragView, child); |
| 3715 | mReorderAlarm.setOnAlarmListener(listener); |
| 3716 | mReorderAlarm.setAlarm(REORDER_TIMEOUT); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | if (mDragMode == DRAG_MODE_CREATE_FOLDER || mDragMode == DRAG_MODE_ADD_TO_FOLDER || |
| 3720 | !nearestDropOccupied) { |
| 3721 | if (mDragTargetLayout != null) { |
| 3722 | mDragTargetLayout.revertTempState(); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3723 | } |
| 3724 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3728 | private void manageFolderFeedback(ItemInfo info, CellLayout targetLayout, |
| 3729 | int[] targetCell, float distance, View dragOverView) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3730 | boolean userFolderPending = willCreateUserFolder(info, targetLayout, targetCell, distance, |
| 3731 | false); |
| 3732 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3733 | if (mDragMode == DRAG_MODE_NONE && userFolderPending && |
| 3734 | !mFolderCreationAlarm.alarmPending()) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3735 | mFolderCreationAlarm.setOnAlarmListener(new |
| 3736 | FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1])); |
| 3737 | mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3738 | return; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | boolean willAddToFolder = |
| 3742 | willAddToExistingUserFolder(info, targetLayout, targetCell, distance); |
| 3743 | |
| 3744 | if (willAddToFolder && mDragMode == DRAG_MODE_NONE) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3745 | mDragOverFolderIcon = ((FolderIcon) dragOverView); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3746 | mDragOverFolderIcon.onDragEnter(info); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3747 | if (targetLayout != null) { |
| 3748 | targetLayout.clearDragOutlines(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3749 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3750 | setDragMode(DRAG_MODE_ADD_TO_FOLDER); |
| 3751 | return; |
Patrick Dubroy | 976ebec | 2010-08-04 20:03:37 -0700 | [diff] [blame] | 3752 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3753 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3754 | if (mDragMode == DRAG_MODE_ADD_TO_FOLDER && !willAddToFolder) { |
| 3755 | setDragMode(DRAG_MODE_NONE); |
| 3756 | } |
| 3757 | if (mDragMode == DRAG_MODE_CREATE_FOLDER && !userFolderPending) { |
| 3758 | setDragMode(DRAG_MODE_NONE); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3759 | } |
| 3760 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3761 | return; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3764 | class FolderCreationAlarmListener implements OnAlarmListener { |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3765 | CellLayout layout; |
| 3766 | int cellX; |
| 3767 | int cellY; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3768 | |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3769 | public FolderCreationAlarmListener(CellLayout layout, int cellX, int cellY) { |
| 3770 | this.layout = layout; |
| 3771 | this.cellX = cellX; |
| 3772 | this.cellY = cellY; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | public void onAlarm(Alarm alarm) { |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 3776 | if (mDragFolderRingAnimator != null) { |
| 3777 | // This shouldn't happen ever, but just in case, make sure we clean up the mess. |
| 3778 | mDragFolderRingAnimator.animateToNaturalState(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3779 | } |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 3780 | mDragFolderRingAnimator = new FolderRingAnimator(mLauncher, null); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3781 | mDragFolderRingAnimator.setCell(cellX, cellY); |
| 3782 | mDragFolderRingAnimator.setCellLayout(layout); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3783 | mDragFolderRingAnimator.animateToAcceptState(); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3784 | layout.showFolderAccept(mDragFolderRingAnimator); |
| 3785 | layout.clearDragOutlines(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3786 | setDragMode(DRAG_MODE_CREATE_FOLDER); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | class ReorderAlarmListener implements OnAlarmListener { |
| 3791 | float[] dragViewCenter; |
| 3792 | int minSpanX, minSpanY, spanX, spanY; |
| 3793 | DragView dragView; |
| 3794 | View child; |
| 3795 | |
| 3796 | public ReorderAlarmListener(float[] dragViewCenter, int minSpanX, int minSpanY, int spanX, |
| 3797 | int spanY, DragView dragView, View child) { |
| 3798 | this.dragViewCenter = dragViewCenter; |
| 3799 | this.minSpanX = minSpanX; |
| 3800 | this.minSpanY = minSpanY; |
| 3801 | this.spanX = spanX; |
| 3802 | this.spanY = spanY; |
| 3803 | this.child = child; |
| 3804 | this.dragView = dragView; |
| 3805 | } |
| 3806 | |
| 3807 | public void onAlarm(Alarm alarm) { |
| 3808 | int[] resultSpan = new int[2]; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3809 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3810 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, mDragTargetLayout, |
| 3811 | mTargetCell); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3812 | mLastReorderX = mTargetCell[0]; |
| 3813 | mLastReorderY = mTargetCell[1]; |
| 3814 | |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3815 | mTargetCell = mDragTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3816 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, |
| 3817 | child, mTargetCell, resultSpan, CellLayout.MODE_DRAG_OVER); |
| 3818 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3819 | if (mTargetCell[0] < 0 || mTargetCell[1] < 0) { |
| 3820 | mDragTargetLayout.revertTempState(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3821 | } else { |
| 3822 | setDragMode(DRAG_MODE_REORDER); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3823 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3824 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3825 | boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY; |
| 3826 | mDragTargetLayout.visualizeDropLocation(child, mDragOutline, |
| 3827 | (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], |
| 3828 | mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, |
| 3829 | dragView.getDragVisualizeOffset(), dragView.getDragRegion()); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 3833 | @Override |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3834 | public void getHitRectRelativeToDragLayer(Rect outRect) { |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 3835 | // We want the workspace to have the whole area of the display (it will find the correct |
| 3836 | // cell layout to drop to in the existing drag/drop logic. |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3837 | mLauncher.getDragLayer().getDescendantRectRelativeToSelf(this, outRect); |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 3838 | } |
| 3839 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3840 | /** |
| 3841 | * Add the item specified by dragInfo to the given layout. |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3842 | * @return true if successful |
| 3843 | */ |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 3844 | public boolean addExternalItemToScreen(ItemInfo dragInfo, CellLayout layout) { |
| 3845 | if (layout.findCellForSpan(mTempEstimate, dragInfo.spanX, dragInfo.spanY)) { |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 3846 | onDropExternal(dragInfo.dropPos, (ItemInfo) dragInfo, (CellLayout) layout, false); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3847 | return true; |
| 3848 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 3849 | mLauncher.showOutOfSpaceMessage(mLauncher.isHotseatLayout(layout)); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3850 | return false; |
| 3851 | } |
| 3852 | |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 3853 | private void onDropExternal(int[] touchXY, Object dragInfo, |
| 3854 | CellLayout cellLayout, boolean insertAtFirst) { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3855 | onDropExternal(touchXY, dragInfo, cellLayout, insertAtFirst, null); |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 3856 | } |
| 3857 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 3858 | /** |
| 3859 | * Drop an item that didn't originate on one of the workspace screens. |
| 3860 | * It may have come from Launcher (e.g. from all apps or customize), or it may have |
| 3861 | * come from another app altogether. |
| 3862 | * |
| 3863 | * NOTE: This can also be called when we are outside of a drag event, when we want |
| 3864 | * to add an item to one of the workspace screens. |
| 3865 | */ |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3866 | private void onDropExternal(final int[] touchXY, final Object dragInfo, |
| 3867 | final CellLayout cellLayout, boolean insertAtFirst, DragObject d) { |
| 3868 | final Runnable exitSpringLoadedRunnable = new Runnable() { |
| 3869 | @Override |
| 3870 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 3871 | mLauncher.exitSpringLoadedDragModeDelayed(true, |
| 3872 | Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3873 | } |
| 3874 | }; |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3875 | |
| 3876 | ItemInfo info = (ItemInfo) dragInfo; |
| 3877 | int spanX = info.spanX; |
| 3878 | int spanY = info.spanY; |
| 3879 | if (mDragInfo != null) { |
| 3880 | spanX = mDragInfo.spanX; |
| 3881 | spanY = mDragInfo.spanY; |
| 3882 | } |
| 3883 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3884 | final long container = mLauncher.isHotseatLayout(cellLayout) ? |
| 3885 | LauncherSettings.Favorites.CONTAINER_HOTSEAT : |
| 3886 | LauncherSettings.Favorites.CONTAINER_DESKTOP; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3887 | final long screenId = getIdForScreen(cellLayout); |
| 3888 | if (!mLauncher.isHotseatLayout(cellLayout) |
| 3889 | && screenId != getScreenIdForPageIndex(mCurrentPage) |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3890 | && mState != State.SPRING_LOADED) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3891 | snapToScreenId(screenId, null); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 3892 | } |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3893 | |
| 3894 | if (info instanceof PendingAddItemInfo) { |
| 3895 | final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) dragInfo; |
| 3896 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3897 | boolean findNearestVacantCell = true; |
| 3898 | if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { |
| 3899 | mTargetCell = findNearestArea((int) touchXY[0], (int) touchXY[1], spanX, spanY, |
| 3900 | cellLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3901 | float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 3902 | mDragViewVisualCenter[1], mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3903 | if (willCreateUserFolder((ItemInfo) d.dragInfo, cellLayout, mTargetCell, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3904 | distance, true) || willAddToExistingUserFolder((ItemInfo) d.dragInfo, |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3905 | cellLayout, mTargetCell, distance)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3906 | findNearestVacantCell = false; |
| 3907 | } |
| 3908 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3909 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3910 | final ItemInfo item = (ItemInfo) d.dragInfo; |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 3911 | boolean updateWidgetSize = false; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3912 | if (findNearestVacantCell) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3913 | int minSpanX = item.spanX; |
| 3914 | int minSpanY = item.spanY; |
| 3915 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 3916 | minSpanX = item.minSpanX; |
| 3917 | minSpanY = item.minSpanY; |
| 3918 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3919 | int[] resultSpan = new int[2]; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3920 | mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3921 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY, |
| 3922 | null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL); |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 3923 | |
| 3924 | if (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY) { |
| 3925 | updateWidgetSize = true; |
| 3926 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3927 | item.spanX = resultSpan[0]; |
| 3928 | item.spanY = resultSpan[1]; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3931 | Runnable onAnimationCompleteRunnable = new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3932 | @Override |
| 3933 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 3934 | // Normally removeExtraEmptyScreen is called in Workspace#onDragEnd, but when |
| 3935 | // adding an item that may not be dropped right away (due to a config activity) |
| 3936 | // we defer the removal until the activity returns. |
| 3937 | deferRemoveExtraEmptyScreen(); |
| 3938 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3939 | // When dragging and dropping from customization tray, we deal with creating |
| 3940 | // widgets/shortcuts/folders in a slightly different way |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3941 | mLauncher.addPendingItem(pendingInfo, container, screenId, mTargetCell, |
| 3942 | item.spanX, item.spanY); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3943 | } |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3944 | }; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3945 | boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET |
| 3946 | || pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
| 3947 | |
| 3948 | View finalView = isWidget ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null; |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 3949 | |
| 3950 | if (finalView instanceof AppWidgetHostView && updateWidgetSize) { |
| 3951 | AppWidgetHostView awhv = (AppWidgetHostView) finalView; |
| 3952 | AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, item.spanX, |
| 3953 | item.spanY); |
| 3954 | } |
| 3955 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3956 | int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3957 | if (isWidget && ((PendingAddWidgetInfo) pendingInfo).info != null && |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3958 | ((PendingAddWidgetInfo) pendingInfo).info.configure != null) { |
| 3959 | animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN; |
| 3960 | } |
| 3961 | animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable, |
| 3962 | animationStyle, finalView, true); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 3963 | } else { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3964 | // This is for other drag/drop cases, like dragging from All Apps |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3965 | View view = null; |
| 3966 | |
| 3967 | switch (info.itemType) { |
| 3968 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 3969 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3970 | if (info.container == NO_ID && info instanceof AppInfo) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3971 | // Came from all apps -- make a copy |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3972 | info = ((AppInfo) info).makeShortcut(); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3973 | } |
| 3974 | view = mLauncher.createShortcut(R.layout.application, cellLayout, |
| 3975 | (ShortcutInfo) info); |
| 3976 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3977 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3978 | view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout, |
| 3979 | (FolderInfo) info, mIconCache); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3980 | break; |
| 3981 | default: |
| 3982 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 3983 | } |
| 3984 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3985 | // First we find the cell nearest to point at which the item is |
| 3986 | // dropped, without any consideration to whether there is an item there. |
| 3987 | if (touchXY != null) { |
| 3988 | mTargetCell = findNearestArea((int) touchXY[0], (int) touchXY[1], spanX, spanY, |
| 3989 | cellLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3990 | float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 3991 | mDragViewVisualCenter[1], mTargetCell); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3992 | d.postAnimationRunnable = exitSpringLoadedRunnable; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3993 | if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, |
| 3994 | true, d.dragView, d.postAnimationRunnable)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3995 | return; |
| 3996 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3997 | if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, |
| 3998 | true)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3999 | return; |
| 4000 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 4001 | } |
| 4002 | |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 4003 | if (touchXY != null) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 4004 | // when dragging and dropping, just find the closest free spot |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 4005 | mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 4006 | (int) mDragViewVisualCenter[1], 1, 1, 1, 1, |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 4007 | null, mTargetCell, null, CellLayout.MODE_ON_DROP_EXTERNAL); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 4008 | } else { |
| 4009 | cellLayout.findCellForSpan(mTargetCell, 1, 1); |
| 4010 | } |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 4011 | // Add the item to DB before adding to screen ensures that the container and other |
| 4012 | // values of the info is properly updated. |
| 4013 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screenId, |
| 4014 | mTargetCell[0], mTargetCell[1]); |
| 4015 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4016 | addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4017 | info.spanY, insertAtFirst); |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 4018 | cellLayout.onDropChild(view); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4019 | cellLayout.getShortcutsAndWidgets().measureChild(view); |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 4020 | |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 4021 | if (d.dragView != null) { |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 4022 | // We wrap the animation call in the temporary set and reset of the current |
| 4023 | // cellLayout to its final transform -- this means we animate the drag view to |
| 4024 | // the correct final location. |
| 4025 | setFinalTransitionTransform(cellLayout); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 4026 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, |
Adam Cohen | 28f852a | 2013-10-15 14:34:05 -0700 | [diff] [blame] | 4027 | exitSpringLoadedRunnable, this); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 4028 | resetTransitionTransform(cellLayout); |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 4029 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 4030 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4031 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 4032 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4033 | public Bitmap createWidgetBitmap(ItemInfo widgetInfo, View layout) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4034 | int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(widgetInfo.spanX, |
| 4035 | widgetInfo.spanY, widgetInfo, false); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4036 | int visibility = layout.getVisibility(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4037 | layout.setVisibility(VISIBLE); |
| 4038 | |
| 4039 | int width = MeasureSpec.makeMeasureSpec(unScaledSize[0], MeasureSpec.EXACTLY); |
| 4040 | int height = MeasureSpec.makeMeasureSpec(unScaledSize[1], MeasureSpec.EXACTLY); |
| 4041 | Bitmap b = Bitmap.createBitmap(unScaledSize[0], unScaledSize[1], |
| 4042 | Bitmap.Config.ARGB_8888); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 4043 | mCanvas.setBitmap(b); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4044 | |
| 4045 | layout.measure(width, height); |
| 4046 | layout.layout(0, 0, unScaledSize[0], unScaledSize[1]); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 4047 | layout.draw(mCanvas); |
| 4048 | mCanvas.setBitmap(null); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4049 | layout.setVisibility(visibility); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4050 | return b; |
| 4051 | } |
| 4052 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4053 | private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 4054 | DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 4055 | boolean external, boolean scale) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4056 | // Now we animate the dragView, (ie. the widget or shortcut preview) into its final |
| 4057 | // location and size on the home screen. |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4058 | int spanX = info.spanX; |
| 4059 | int spanY = info.spanY; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4060 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4061 | Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY); |
| 4062 | loc[0] = r.left; |
| 4063 | loc[1] = r.top; |
| 4064 | |
| 4065 | setFinalTransitionTransform(layout); |
| 4066 | float cellLayoutScale = |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 4067 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4068 | resetTransitionTransform(layout); |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 4069 | |
| 4070 | float dragViewScaleX; |
| 4071 | float dragViewScaleY; |
| 4072 | if (scale) { |
| 4073 | dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth(); |
| 4074 | dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight(); |
| 4075 | } else { |
| 4076 | dragViewScaleX = 1f; |
| 4077 | dragViewScaleY = 1f; |
| 4078 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4079 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4080 | // The animation will scale the dragView about its center, so we need to center about |
| 4081 | // the final location. |
| 4082 | loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2; |
| 4083 | loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2; |
| 4084 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4085 | scaleXY[0] = dragViewScaleX * cellLayoutScale; |
| 4086 | scaleXY[1] = dragViewScaleY * cellLayoutScale; |
| 4087 | } |
| 4088 | |
| 4089 | public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView, |
| 4090 | final Runnable onCompleteRunnable, int animationType, final View finalView, |
| 4091 | boolean external) { |
| 4092 | Rect from = new Rect(); |
| 4093 | mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from); |
| 4094 | |
| 4095 | int[] finalPos = new int[2]; |
| 4096 | float scaleXY[] = new float[2]; |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 4097 | boolean scalePreview = !(info instanceof PendingAddShortcutInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4098 | getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 4099 | external, scalePreview); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4100 | |
| 4101 | Resources res = mLauncher.getResources(); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 4102 | final int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4103 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4104 | // In the case where we've prebound the widget, we remove it from the DragLayer |
| 4105 | if (finalView instanceof AppWidgetHostView && external) { |
Adam Cohen | 68f681b | 2012-05-28 15:01:16 -0700 | [diff] [blame] | 4106 | Log.d(TAG, "6557954 Animate widget drop, final view is appWidgetHostView"); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4107 | mLauncher.getDragLayer().removeView(finalView); |
| 4108 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4109 | |
| 4110 | boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || |
| 4111 | info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4112 | if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null) { |
| 4113 | Bitmap crossFadeBitmap = createWidgetBitmap(info, finalView); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4114 | dragView.setCrossFadeBitmap(crossFadeBitmap); |
| 4115 | dragView.crossFade((int) (duration * 0.8f)); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4116 | } else if (isWidget && external) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4117 | scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4118 | } |
| 4119 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4120 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 4121 | if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4122 | mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4123 | DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration); |
| 4124 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 4125 | int endStyle; |
| 4126 | if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) { |
| 4127 | endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE; |
| 4128 | } else { |
| 4129 | endStyle = DragLayer.ANIMATION_END_DISAPPEAR;; |
| 4130 | } |
| 4131 | |
| 4132 | Runnable onComplete = new Runnable() { |
| 4133 | @Override |
| 4134 | public void run() { |
| 4135 | if (finalView != null) { |
| 4136 | finalView.setVisibility(VISIBLE); |
| 4137 | } |
| 4138 | if (onCompleteRunnable != null) { |
| 4139 | onCompleteRunnable.run(); |
| 4140 | } |
| 4141 | } |
| 4142 | }; |
| 4143 | dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], |
| 4144 | finalPos[1], 1, 1, 1, scaleXY[0], scaleXY[1], onComplete, endStyle, |
| 4145 | duration, this); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 4146 | } |
| 4147 | } |
| 4148 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 4149 | public void setFinalTransitionTransform(CellLayout layout) { |
| 4150 | if (isSwitchingState()) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 4151 | mCurrentScale = getScaleX(); |
| 4152 | setScaleX(mNewScale); |
| 4153 | setScaleY(mNewScale); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 4154 | } |
| 4155 | } |
| 4156 | public void resetTransitionTransform(CellLayout layout) { |
| 4157 | if (isSwitchingState()) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 4158 | setScaleX(mCurrentScale); |
| 4159 | setScaleY(mCurrentScale); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 4160 | } |
| 4161 | } |
| 4162 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 4163 | /** |
| 4164 | * Return the current {@link CellLayout}, correctly picking the destination |
| 4165 | * screen while a scroll is in progress. |
| 4166 | */ |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 4167 | public CellLayout getCurrentDropLayout() { |
Winson Chung | 360e63f | 2012-04-27 13:48:05 -0700 | [diff] [blame] | 4168 | return (CellLayout) getChildAt(getNextPage()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4169 | } |
| 4170 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 4171 | /** |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 4172 | * Return the current CellInfo describing our current drag; this method exists |
| 4173 | * so that Launcher can sync this object with the correct info when the activity is created/ |
| 4174 | * destroyed |
| 4175 | * |
| 4176 | */ |
| 4177 | public CellLayout.CellInfo getDragInfo() { |
| 4178 | return mDragInfo; |
| 4179 | } |
| 4180 | |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 4181 | public int getCurrentPageOffsetFromCustomContent() { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 4182 | return getNextPage() - numCustomPages(); |
| 4183 | } |
| 4184 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 4185 | /** |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 4186 | * Calculate the nearest cell where the given object would be dropped. |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 4187 | * |
| 4188 | * pixelX and pixelY should be in the coordinate system of layout |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 4189 | */ |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4190 | private int[] findNearestArea(int pixelX, int pixelY, |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 4191 | int spanX, int spanY, CellLayout layout, int[] recycle) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4192 | return layout.findNearestArea( |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 4193 | pixelX, pixelY, spanX, spanY, recycle); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4194 | } |
| 4195 | |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 4196 | void setup(DragController dragController) { |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 4197 | mSpringLoadedDragController = new SpringLoadedDragController(mLauncher); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 4198 | mDragController = dragController; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 4199 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 4200 | // hardware layers on children are enabled on startup, but should be disabled until |
| 4201 | // needed |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 4202 | updateChildrenLayersEnabled(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4203 | } |
| 4204 | |
Patrick Dubroy | e3887cc | 2011-01-20 10:43:40 -0800 | [diff] [blame] | 4205 | /** |
| 4206 | * Called at the end of a drag which originated on the workspace. |
| 4207 | */ |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4208 | public void onDropCompleted(final View target, final DragObject d, |
| 4209 | final boolean isFlingToDelete, final boolean success) { |
| 4210 | if (mDeferDropAfterUninstall) { |
| 4211 | mDeferredAction = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 4212 | public void run() { |
| 4213 | onDropCompleted(target, d, isFlingToDelete, success); |
| 4214 | mDeferredAction = null; |
| 4215 | } |
| 4216 | }; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4217 | return; |
| 4218 | } |
| 4219 | |
| 4220 | boolean beingCalledAfterUninstall = mDeferredAction != null; |
| 4221 | |
| 4222 | if (success && !(beingCalledAfterUninstall && !mUninstallSuccessful)) { |
| 4223 | if (target != this && mDragInfo != null) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 4224 | removeWorkspaceItem(mDragInfo.cell); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4225 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 4226 | } else if (mDragInfo != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4227 | CellLayout cellLayout; |
| 4228 | if (mLauncher.isHotseatLayout(target)) { |
| 4229 | cellLayout = mLauncher.getHotseat().getLayout(); |
| 4230 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4231 | cellLayout = getScreenWithId(mDragInfo.screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4232 | } |
Jorim Jaggi | eedb00a | 2014-01-13 13:45:07 -0800 | [diff] [blame] | 4233 | if (cellLayout == null && LauncherAppState.isDogfoodBuild()) { |
| 4234 | throw new RuntimeException("Invalid state: cellLayout == null in " |
| 4235 | + "Workspace#onDropCompleted. Please file a bug. "); |
| 4236 | } |
| 4237 | if (cellLayout != null) { |
| 4238 | cellLayout.onDropChild(mDragInfo.cell); |
| 4239 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4240 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4241 | if ((d.cancelled || (beingCalledAfterUninstall && !mUninstallSuccessful)) |
| 4242 | && mDragInfo.cell != null) { |
| 4243 | mDragInfo.cell.setVisibility(VISIBLE); |
Adam Cohen | 36cc09b | 2011-09-29 17:33:15 -0700 | [diff] [blame] | 4244 | } |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 4245 | mDragOutline = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4246 | mDragInfo = null; |
| 4247 | } |
| 4248 | |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 4249 | public void removeWorkspaceItem(View v) { |
| 4250 | CellLayout parentCell = getParentCellLayoutForView(v); |
| 4251 | if (parentCell != null) { |
| 4252 | parentCell.removeView(v); |
| 4253 | } else if (LauncherAppState.isDogfoodBuild()) { |
| 4254 | throw new NullPointerException("mDragInfo.cell has null parent"); |
| 4255 | } |
| 4256 | if (v instanceof DropTarget) { |
| 4257 | mDragController.removeDropTarget((DropTarget) v); |
| 4258 | } |
| 4259 | } |
| 4260 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 4261 | public void deferCompleteDropAfterUninstallActivity() { |
| 4262 | mDeferDropAfterUninstall = true; |
| 4263 | } |
| 4264 | |
| 4265 | /// maybe move this into a smaller part |
| 4266 | public void onUninstallActivityReturned(boolean success) { |
| 4267 | mDeferDropAfterUninstall = false; |
| 4268 | mUninstallSuccessful = success; |
| 4269 | if (mDeferredAction != null) { |
| 4270 | mDeferredAction.run(); |
| 4271 | } |
| 4272 | } |
| 4273 | |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 4274 | void updateItemLocationsInDatabase(CellLayout cl) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4275 | int count = cl.getShortcutsAndWidgets().getChildCount(); |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 4276 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4277 | long screenId = getIdForScreen(cl); |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 4278 | int container = Favorites.CONTAINER_DESKTOP; |
| 4279 | |
| 4280 | if (mLauncher.isHotseatLayout(cl)) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4281 | screenId = -1; |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 4282 | container = Favorites.CONTAINER_HOTSEAT; |
| 4283 | } |
| 4284 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 4285 | for (int i = 0; i < count; i++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4286 | View v = cl.getShortcutsAndWidgets().getChildAt(i); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 4287 | ItemInfo info = (ItemInfo) v.getTag(); |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 4288 | // 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] | 4289 | if (info != null && info.requiresDbUpdate) { |
| 4290 | info.requiresDbUpdate = false; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4291 | LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, info.cellX, |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 4292 | info.cellY, info.spanX, info.spanY); |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 4293 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 4294 | } |
| 4295 | } |
| 4296 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4297 | void saveWorkspaceToDb() { |
| 4298 | saveWorkspaceScreenToDb((CellLayout) mLauncher.getHotseat().getLayout()); |
| 4299 | int count = getChildCount(); |
| 4300 | for (int i = 0; i < count; i++) { |
| 4301 | CellLayout cl = (CellLayout) getChildAt(i); |
| 4302 | saveWorkspaceScreenToDb(cl); |
| 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | void saveWorkspaceScreenToDb(CellLayout cl) { |
| 4307 | int count = cl.getShortcutsAndWidgets().getChildCount(); |
| 4308 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4309 | long screenId = getIdForScreen(cl); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4310 | int container = Favorites.CONTAINER_DESKTOP; |
| 4311 | |
Winson Chung | f70696d | 2013-06-25 16:19:53 -0700 | [diff] [blame] | 4312 | Hotseat hotseat = mLauncher.getHotseat(); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4313 | if (mLauncher.isHotseatLayout(cl)) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 4314 | screenId = -1; |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4315 | container = Favorites.CONTAINER_HOTSEAT; |
| 4316 | } |
| 4317 | |
| 4318 | for (int i = 0; i < count; i++) { |
| 4319 | View v = cl.getShortcutsAndWidgets().getChildAt(i); |
| 4320 | ItemInfo info = (ItemInfo) v.getTag(); |
| 4321 | // Null check required as the AllApps button doesn't have an item info |
| 4322 | if (info != null) { |
Winson Chung | f70696d | 2013-06-25 16:19:53 -0700 | [diff] [blame] | 4323 | int cellX = info.cellX; |
| 4324 | int cellY = info.cellY; |
| 4325 | if (container == Favorites.CONTAINER_HOTSEAT) { |
| 4326 | cellX = hotseat.getCellXFromOrder((int) info.screenId); |
| 4327 | cellY = hotseat.getCellYFromOrder((int) info.screenId); |
| 4328 | } |
| 4329 | LauncherModel.addItemToDatabase(mLauncher, info, container, screenId, cellX, |
| 4330 | cellY, false); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 4331 | } |
| 4332 | if (v instanceof FolderIcon) { |
| 4333 | FolderIcon fi = (FolderIcon) v; |
| 4334 | fi.getFolder().addItemLocationsInDatabase(); |
| 4335 | } |
| 4336 | } |
| 4337 | } |
| 4338 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 4339 | @Override |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 4340 | public float getIntrinsicIconScaleFactor() { |
| 4341 | return 1f; |
| 4342 | } |
| 4343 | |
| 4344 | @Override |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 4345 | public boolean supportsFlingToDelete() { |
| 4346 | return true; |
| 4347 | } |
| 4348 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 4349 | @Override |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 4350 | public boolean supportsAppInfoDropTarget() { |
| 4351 | return false; |
| 4352 | } |
| 4353 | |
| 4354 | @Override |
| 4355 | public boolean supportsDeleteDropTarget() { |
| 4356 | return true; |
| 4357 | } |
| 4358 | |
| 4359 | @Override |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 4360 | public void onFlingToDelete(DragObject d, int x, int y, PointF vec) { |
| 4361 | // Do nothing |
| 4362 | } |
| 4363 | |
| 4364 | @Override |
| 4365 | public void onFlingToDeleteCompleted() { |
| 4366 | // Do nothing |
| 4367 | } |
| 4368 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 4369 | public boolean isDropEnabled() { |
| 4370 | return true; |
| 4371 | } |
| 4372 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4373 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4374 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 4375 | // We don't dispatch restoreInstanceState to our children using this code path. |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 4376 | // Some pages will be restored immediately as their items are bound immediately, and |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4377 | // others we will need to wait until after their items are bound. |
| 4378 | mSavedStates = container; |
| 4379 | } |
| 4380 | |
| 4381 | public void restoreInstanceStateForChild(int child) { |
| 4382 | if (mSavedStates != null) { |
| 4383 | mRestoredPages.add(child); |
| 4384 | CellLayout cl = (CellLayout) getChildAt(child); |
Adam Cohen | b0ee081 | 2013-12-03 10:51:45 -0800 | [diff] [blame] | 4385 | if (cl != null) { |
| 4386 | cl.restoreInstanceState(mSavedStates); |
| 4387 | } |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4388 | } |
| 4389 | } |
| 4390 | |
| 4391 | public void restoreInstanceStateForRemainingPages() { |
| 4392 | int count = getChildCount(); |
| 4393 | for (int i = 0; i < count; i++) { |
| 4394 | if (!mRestoredPages.contains(i)) { |
| 4395 | restoreInstanceStateForChild(i); |
| 4396 | } |
| 4397 | } |
| 4398 | mRestoredPages.clear(); |
Winson Chung | d8e596d | 2013-10-21 17:14:12 -0700 | [diff] [blame] | 4399 | mSavedStates = null; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4403 | public void scrollLeft() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4404 | if (!workspaceInModalState() && !mIsSwitchingState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4405 | super.scrollLeft(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4406 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 4407 | Folder openFolder = getOpenFolder(); |
| 4408 | if (openFolder != null) { |
| 4409 | openFolder.completeDragExit(); |
| 4410 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4411 | } |
| 4412 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4413 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4414 | public void scrollRight() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4415 | if (!workspaceInModalState() && !mIsSwitchingState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4416 | super.scrollRight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4417 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 4418 | Folder openFolder = getOpenFolder(); |
| 4419 | if (openFolder != null) { |
| 4420 | openFolder.completeDragExit(); |
| 4421 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4422 | } |
| 4423 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 4424 | @Override |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 4425 | public boolean onEnterScrollArea(int x, int y, int direction) { |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 4426 | // Ignore the scroll area if we are dragging over the hot seat |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 4427 | boolean isPortrait = !LauncherAppState.isScreenLandscape(getContext()); |
Winson Chung | 10bfc6e | 2012-03-28 15:41:26 -0700 | [diff] [blame] | 4428 | if (mLauncher.getHotseat() != null && isPortrait) { |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 4429 | Rect r = new Rect(); |
| 4430 | mLauncher.getHotseat().getHitRect(r); |
| 4431 | if (r.contains(x, y)) { |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 4432 | return false; |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 4433 | } |
| 4434 | } |
| 4435 | |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 4436 | boolean result = false; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4437 | if (!workspaceInModalState() && !mIsSwitchingState && getOpenFolder() == null) { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 4438 | mInScrollArea = true; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 4439 | |
Winson Chung | 360e63f | 2012-04-27 13:48:05 -0700 | [diff] [blame] | 4440 | final int page = getNextPage() + |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 4441 | (direction == DragController.SCROLL_LEFT ? -1 : 1); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 4442 | // We always want to exit the current layout to ensure parity of enter / exit |
| 4443 | setCurrentDropLayout(null); |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 4444 | |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 4445 | if (0 <= page && page < getChildCount()) { |
Winson Chung | 482a5b6 | 2013-07-31 17:19:51 -0700 | [diff] [blame] | 4446 | // Ensure that we are not dragging over to the custom content screen |
| 4447 | if (getScreenIdForPageIndex(page) == CUSTOM_CONTENT_SCREEN_ID) { |
| 4448 | return false; |
| 4449 | } |
| 4450 | |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 4451 | CellLayout layout = (CellLayout) getChildAt(page); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 4452 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 4453 | |
| 4454 | // Workspace is responsible for drawing the edge glow on adjacent pages, |
| 4455 | // so we need to redraw the workspace when this may have changed. |
| 4456 | invalidate(); |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 4457 | result = true; |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 4458 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 4459 | } |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 4460 | return result; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | @Override |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 4464 | public boolean onExitScrollArea() { |
| 4465 | boolean result = false; |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 4466 | if (mInScrollArea) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 4467 | invalidate(); |
| 4468 | CellLayout layout = getCurrentDropLayout(); |
| 4469 | setCurrentDropLayout(layout); |
| 4470 | setCurrentDragOverlappingLayout(layout); |
| 4471 | |
Adam Cohen | 8a18afc | 2011-12-13 15:57:01 -0800 | [diff] [blame] | 4472 | result = true; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 4473 | mInScrollArea = false; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 4474 | } |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 4475 | return result; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 4476 | } |
| 4477 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 4478 | private void onResetScrollArea() { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 4479 | setCurrentDragOverlappingLayout(null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 4480 | mInScrollArea = false; |
| 4481 | } |
| 4482 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4483 | /** |
| 4484 | * Returns a specific CellLayout |
| 4485 | */ |
| 4486 | CellLayout getParentCellLayoutForView(View v) { |
| 4487 | ArrayList<CellLayout> layouts = getWorkspaceAndHotseatCellLayouts(); |
| 4488 | for (CellLayout layout : layouts) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4489 | if (layout.getShortcutsAndWidgets().indexOfChild(v) > -1) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4490 | return layout; |
| 4491 | } |
| 4492 | } |
| 4493 | return null; |
| 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * Returns a list of all the CellLayouts in the workspace. |
| 4498 | */ |
| 4499 | ArrayList<CellLayout> getWorkspaceAndHotseatCellLayouts() { |
| 4500 | ArrayList<CellLayout> layouts = new ArrayList<CellLayout>(); |
| 4501 | int screenCount = getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4502 | for (int screen = 0; screen < screenCount; screen++) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4503 | layouts.add(((CellLayout) getChildAt(screen))); |
| 4504 | } |
| 4505 | if (mLauncher.getHotseat() != null) { |
| 4506 | layouts.add(mLauncher.getHotseat().getLayout()); |
| 4507 | } |
| 4508 | return layouts; |
| 4509 | } |
| 4510 | |
| 4511 | /** |
| 4512 | * 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] | 4513 | * ShortcutsAndWidgetsContainer directly. Includes ShortcutAndWidgetContainers from |
| 4514 | * the hotseat and workspace pages |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4515 | */ |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4516 | ArrayList<ShortcutAndWidgetContainer> getAllShortcutAndWidgetContainers() { |
| 4517 | ArrayList<ShortcutAndWidgetContainer> childrenLayouts = |
| 4518 | new ArrayList<ShortcutAndWidgetContainer>(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4519 | int screenCount = getChildCount(); |
| 4520 | for (int screen = 0; screen < screenCount; screen++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4521 | childrenLayouts.add(((CellLayout) getChildAt(screen)).getShortcutsAndWidgets()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4522 | } |
| 4523 | if (mLauncher.getHotseat() != null) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4524 | childrenLayouts.add(mLauncher.getHotseat().getLayout().getShortcutsAndWidgets()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4525 | } |
| 4526 | return childrenLayouts; |
| 4527 | } |
| 4528 | |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4529 | public Folder getFolderForTag(final Object tag) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4530 | return (Folder) getFirstMatch(new ItemOperator() { |
| 4531 | |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4532 | @Override |
| 4533 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4534 | return (v instanceof Folder) && (((Folder) v).getInfo() == tag) |
| 4535 | && ((Folder) v).getInfo().opened; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4536 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4537 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4538 | } |
| 4539 | |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4540 | public View getViewForTag(final Object tag) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4541 | return getFirstMatch(new ItemOperator() { |
| 4542 | |
| 4543 | @Override |
| 4544 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4545 | return info == tag; |
| 4546 | } |
| 4547 | }); |
| 4548 | } |
| 4549 | |
| 4550 | public LauncherAppWidgetHostView getWidgetForAppWidgetId(final int appWidgetId) { |
| 4551 | return (LauncherAppWidgetHostView) getFirstMatch(new ItemOperator() { |
| 4552 | |
| 4553 | @Override |
| 4554 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4555 | return (info instanceof LauncherAppWidgetInfo) && |
| 4556 | ((LauncherAppWidgetInfo) info).appWidgetId == appWidgetId; |
| 4557 | } |
| 4558 | }); |
| 4559 | } |
| 4560 | |
| 4561 | private View getFirstMatch(final ItemOperator operator) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4562 | final View[] value = new View[1]; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4563 | mapOverItems(MAP_NO_RECURSE, new ItemOperator() { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4564 | @Override |
| 4565 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4566 | if (operator.evaluate(info, v, parent)) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4567 | value[0] = v; |
| 4568 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4569 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4570 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4571 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4572 | }); |
| 4573 | return value[0]; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4574 | } |
| 4575 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4576 | void clearDropTargets() { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4577 | mapOverItems(MAP_NO_RECURSE, new ItemOperator() { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4578 | @Override |
| 4579 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4580 | if (v instanceof DropTarget) { |
| 4581 | mDragController.removeDropTarget((DropTarget) v); |
| 4582 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4583 | // not done, process all the shortcuts |
| 4584 | return false; |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4585 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4586 | }); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4587 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4588 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4589 | public void disableShortcutsByPackageName(final ArrayList<String> packages, |
| 4590 | final UserHandleCompat user, final int reason) { |
| 4591 | final HashSet<String> packageNames = new HashSet<String>(); |
| 4592 | packageNames.addAll(packages); |
| 4593 | |
| 4594 | mapOverItems(MAP_RECURSE, new ItemOperator() { |
| 4595 | @Override |
| 4596 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4597 | if (info instanceof ShortcutInfo && v instanceof BubbleTextView) { |
| 4598 | ShortcutInfo shortcutInfo = (ShortcutInfo) info; |
| 4599 | ComponentName cn = shortcutInfo.getTargetComponent(); |
| 4600 | if (user.equals(shortcutInfo.user) && cn != null |
| 4601 | && packageNames.contains(cn.getPackageName())) { |
| 4602 | shortcutInfo.isDisabled |= reason; |
| 4603 | BubbleTextView shortcut = (BubbleTextView) v; |
| 4604 | shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, false); |
| 4605 | |
| 4606 | if (parent != null) { |
| 4607 | parent.invalidate(); |
| 4608 | } |
| 4609 | } |
| 4610 | } |
| 4611 | // process all the shortcuts |
| 4612 | return false; |
| 4613 | } |
| 4614 | }); |
| 4615 | } |
| 4616 | |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4617 | // Removes ALL items that match a given package name, this is usually called when a package |
| 4618 | // has been removed and we want to remove all components (widgets, shortcuts, apps) that |
| 4619 | // belong to that package. |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4620 | void removeItemsByPackageName(final ArrayList<String> packages, final UserHandleCompat user) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4621 | final HashSet<String> packageNames = new HashSet<String>(); |
Winson Chung | cd81073 | 2012-06-18 16:45:43 -0700 | [diff] [blame] | 4622 | packageNames.addAll(packages); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 4623 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4624 | // Filter out all the ItemInfos that this is going to affect |
| 4625 | final HashSet<ItemInfo> infos = new HashSet<ItemInfo>(); |
| 4626 | final HashSet<ComponentName> cns = new HashSet<ComponentName>(); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4627 | ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); |
| 4628 | for (CellLayout layoutParent : cellLayouts) { |
| 4629 | ViewGroup layout = layoutParent.getShortcutsAndWidgets(); |
| 4630 | int childCount = layout.getChildCount(); |
| 4631 | for (int i = 0; i < childCount; ++i) { |
| 4632 | View view = layout.getChildAt(i); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4633 | infos.add((ItemInfo) view.getTag()); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4634 | } |
| 4635 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4636 | LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { |
| 4637 | @Override |
| 4638 | public boolean filterItem(ItemInfo parent, ItemInfo info, |
| 4639 | ComponentName cn) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4640 | if (packageNames.contains(cn.getPackageName()) |
| 4641 | && info.user.equals(user)) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4642 | cns.add(cn); |
| 4643 | return true; |
| 4644 | } |
| 4645 | return false; |
| 4646 | } |
| 4647 | }; |
| 4648 | LauncherModel.filterItemInfos(infos, filter); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4649 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4650 | // Remove the affected components |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4651 | removeItemsByComponentName(cns, user); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4652 | } |
| 4653 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4654 | /** |
| 4655 | * Removes items that match the item info specified. When applications are removed |
| 4656 | * as a part of an update, this is called to ensure that other widgets and application |
| 4657 | * shortcuts are not removed. |
| 4658 | */ |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4659 | void removeItemsByComponentName(final HashSet<ComponentName> componentNames, |
| 4660 | final UserHandleCompat user) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4661 | ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); |
| 4662 | for (final CellLayout layoutParent: cellLayouts) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4663 | final ViewGroup layout = layoutParent.getShortcutsAndWidgets(); |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 4664 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4665 | final HashMap<ItemInfo, View> children = new HashMap<ItemInfo, View>(); |
| 4666 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 4667 | final View view = layout.getChildAt(j); |
| 4668 | children.put((ItemInfo) view.getTag(), view); |
| 4669 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 4670 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4671 | final ArrayList<View> childrenToRemove = new ArrayList<View>(); |
| 4672 | final HashMap<FolderInfo, ArrayList<ShortcutInfo>> folderAppsToRemove = |
| 4673 | new HashMap<FolderInfo, ArrayList<ShortcutInfo>>(); |
| 4674 | LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { |
| 4675 | @Override |
| 4676 | public boolean filterItem(ItemInfo parent, ItemInfo info, |
| 4677 | ComponentName cn) { |
| 4678 | if (parent instanceof FolderInfo) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4679 | if (componentNames.contains(cn) && info.user.equals(user)) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4680 | FolderInfo folder = (FolderInfo) parent; |
| 4681 | ArrayList<ShortcutInfo> appsToRemove; |
| 4682 | if (folderAppsToRemove.containsKey(folder)) { |
| 4683 | appsToRemove = folderAppsToRemove.get(folder); |
| 4684 | } else { |
| 4685 | appsToRemove = new ArrayList<ShortcutInfo>(); |
| 4686 | folderAppsToRemove.put(folder, appsToRemove); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 4687 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4688 | appsToRemove.add((ShortcutInfo) info); |
| 4689 | return true; |
| 4690 | } |
| 4691 | } else { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4692 | if (componentNames.contains(cn) && info.user.equals(user)) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4693 | childrenToRemove.add(children.get(info)); |
| 4694 | return true; |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 4695 | } |
| 4696 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4697 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4698 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4699 | }; |
| 4700 | LauncherModel.filterItemInfos(children.keySet(), filter); |
| 4701 | |
| 4702 | // Remove all the apps from their folders |
| 4703 | for (FolderInfo folder : folderAppsToRemove.keySet()) { |
| 4704 | ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder); |
| 4705 | for (ShortcutInfo info : appsToRemove) { |
| 4706 | folder.remove(info); |
| 4707 | } |
| 4708 | } |
| 4709 | |
| 4710 | // Remove all the other children |
| 4711 | for (View child : childrenToRemove) { |
| 4712 | // Note: We can not remove the view directly from CellLayoutChildren as this |
| 4713 | // does not re-mark the spaces as unoccupied. |
| 4714 | layoutParent.removeViewInLayout(child); |
| 4715 | if (child instanceof DropTarget) { |
| 4716 | mDragController.removeDropTarget((DropTarget) child); |
| 4717 | } |
| 4718 | } |
| 4719 | |
| 4720 | if (childrenToRemove.size() > 0) { |
| 4721 | layout.requestLayout(); |
| 4722 | layout.invalidate(); |
| 4723 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4724 | } |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 4725 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4726 | // Strip all the empty screens |
| 4727 | stripEmptyScreens(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4728 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4729 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4730 | interface ItemOperator { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4731 | /** |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4732 | * Process the next itemInfo, possibly with side-effect on {@link ItemOperator#value}. |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4733 | * |
| 4734 | * @param info info for the shortcut |
| 4735 | * @param view view for the shortcut |
| 4736 | * @param parent containing folder, or null |
| 4737 | * @return true if done, false to continue the map |
| 4738 | */ |
| 4739 | public boolean evaluate(ItemInfo info, View view, View parent); |
| 4740 | } |
| 4741 | |
| 4742 | /** |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4743 | * Map the operator over the shortcuts and widgets, return the first-non-null value. |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4744 | * |
| 4745 | * @param recurse true: iterate over folder children. false: op get the folders themselves. |
| 4746 | * @param op the operator to map over the shortcuts |
| 4747 | */ |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4748 | void mapOverItems(boolean recurse, ItemOperator op) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4749 | ArrayList<ShortcutAndWidgetContainer> containers = getAllShortcutAndWidgetContainers(); |
| 4750 | final int containerCount = containers.size(); |
| 4751 | for (int containerIdx = 0; containerIdx < containerCount; containerIdx++) { |
| 4752 | ShortcutAndWidgetContainer container = containers.get(containerIdx); |
| 4753 | // map over all the shortcuts on the workspace |
| 4754 | final int itemCount = container.getChildCount(); |
| 4755 | for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { |
| 4756 | View item = container.getChildAt(itemIdx); |
| 4757 | ItemInfo info = (ItemInfo) item.getTag(); |
| 4758 | if (recurse && info instanceof FolderInfo && item instanceof FolderIcon) { |
| 4759 | FolderIcon folder = (FolderIcon) item; |
| 4760 | ArrayList<View> folderChildren = folder.getFolder().getItemsInReadingOrder(); |
| 4761 | // map over all the children in the folder |
| 4762 | final int childCount = folderChildren.size(); |
| 4763 | for (int childIdx = 0; childIdx < childCount; childIdx++) { |
| 4764 | View child = folderChildren.get(childIdx); |
| 4765 | info = (ItemInfo) child.getTag(); |
| 4766 | if (op.evaluate(info, child, folder)) { |
| 4767 | return; |
| 4768 | } |
| 4769 | } |
| 4770 | } else { |
| 4771 | if (op.evaluate(info, item, null)) { |
| 4772 | return; |
| 4773 | } |
| 4774 | } |
| 4775 | } |
| 4776 | } |
| 4777 | } |
| 4778 | |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4779 | void updateShortcuts(ArrayList<ShortcutInfo> shortcuts) { |
| 4780 | final HashSet<ShortcutInfo> updates = new HashSet<ShortcutInfo>(shortcuts); |
| 4781 | mapOverItems(MAP_RECURSE, new ItemOperator() { |
| 4782 | @Override |
| 4783 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4784 | if (info instanceof ShortcutInfo && v instanceof BubbleTextView && |
| 4785 | updates.contains(info)) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4786 | ShortcutInfo si = (ShortcutInfo) info; |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4787 | BubbleTextView shortcut = (BubbleTextView) v; |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4788 | boolean oldPromiseState = shortcut.getCompoundDrawables()[1] |
| 4789 | instanceof PreloadIconDrawable; |
| 4790 | shortcut.applyFromShortcutInfo(si, mIconCache, true, |
| 4791 | si.isPromise() != oldPromiseState); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4792 | |
| 4793 | if (parent != null) { |
| 4794 | parent.invalidate(); |
| 4795 | } |
| 4796 | } |
| 4797 | // process all the shortcuts |
| 4798 | return false; |
| 4799 | } |
| 4800 | }); |
| 4801 | } |
| 4802 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 4803 | public void removeAbandonedPromise(String packageName, UserHandleCompat user) { |
| 4804 | ArrayList<String> packages = new ArrayList<String>(1); |
| 4805 | packages.add(packageName); |
| 4806 | LauncherModel.deletePackageFromDatabase(mLauncher, packageName, user); |
| 4807 | removeItemsByPackageName(packages, user); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 4808 | } |
| 4809 | |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 4810 | public void updatePackageBadge(final String packageName, final UserHandleCompat user) { |
| 4811 | mapOverItems(MAP_RECURSE, new ItemOperator() { |
| 4812 | @Override |
| 4813 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4814 | if (info instanceof ShortcutInfo && v instanceof BubbleTextView) { |
| 4815 | ShortcutInfo shortcutInfo = (ShortcutInfo) info; |
| 4816 | ComponentName cn = shortcutInfo.getTargetComponent(); |
| 4817 | if (user.equals(shortcutInfo.user) && cn != null |
| 4818 | && shortcutInfo.isPromise() |
| 4819 | && packageName.equals(cn.getPackageName())) { |
| 4820 | if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) { |
| 4821 | // For auto install apps update the icon as well as label. |
| 4822 | mIconCache.getTitleAndIcon(shortcutInfo, |
| 4823 | shortcutInfo.promisedIntent, user, true); |
| 4824 | } else { |
| 4825 | // Only update the icon for restored apps. |
| 4826 | shortcutInfo.updateIcon(mIconCache); |
| 4827 | } |
| 4828 | BubbleTextView shortcut = (BubbleTextView) v; |
| 4829 | shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, false); |
| 4830 | |
| 4831 | if (parent != null) { |
| 4832 | parent.invalidate(); |
| 4833 | } |
| 4834 | } |
| 4835 | } |
| 4836 | // process all the shortcuts |
| 4837 | return false; |
| 4838 | } |
| 4839 | }); |
| 4840 | } |
| 4841 | |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4842 | public void updatePackageState(ArrayList<PackageInstallInfo> installInfos) { |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4843 | for (final PackageInstallInfo installInfo : installInfos) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4844 | if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) { |
| 4845 | continue; |
| 4846 | } |
| 4847 | |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4848 | mapOverItems(MAP_RECURSE, new ItemOperator() { |
| 4849 | @Override |
| 4850 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Sunny Goyal | 3494262 | 2014-08-29 17:20:55 -0700 | [diff] [blame] | 4851 | if (info instanceof ShortcutInfo && v instanceof BubbleTextView) { |
| 4852 | ShortcutInfo si = (ShortcutInfo) info; |
| 4853 | ComponentName cn = si.getTargetComponent(); |
| 4854 | if (si.isPromise() && (cn != null) |
| 4855 | && installInfo.packageName.equals(cn.getPackageName())) { |
| 4856 | si.setInstallProgress(installInfo.progress); |
| 4857 | if (installInfo.state == PackageInstallerCompat.STATUS_FAILED) { |
| 4858 | // Mark this info as broken. |
| 4859 | si.status &= ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE; |
| 4860 | } |
| 4861 | ((BubbleTextView)v).applyState(false); |
| 4862 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4863 | } else if (v instanceof PendingAppWidgetHostView |
| 4864 | && info instanceof LauncherAppWidgetInfo |
| 4865 | && ((LauncherAppWidgetInfo) info).providerName.getPackageName() |
| 4866 | .equals(installInfo.packageName)) { |
| 4867 | ((LauncherAppWidgetInfo) info).installProgress = installInfo.progress; |
| 4868 | ((PendingAppWidgetHostView) v).applyState(); |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4869 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4870 | |
Sunny Goyal | e755d46 | 2014-07-22 13:48:29 -0700 | [diff] [blame] | 4871 | // process all the shortcuts |
| 4872 | return false; |
| 4873 | } |
| 4874 | }); |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4875 | } |
| 4876 | } |
| 4877 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4878 | void widgetsRestored(ArrayList<LauncherAppWidgetInfo> changedInfo) { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4879 | if (!changedInfo.isEmpty()) { |
| 4880 | DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, |
| 4881 | mLauncher.getAppWidgetHost()); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4882 | if (LauncherModel.getProviderInfo(getContext(), |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4883 | changedInfo.get(0).providerName) != null) { |
| 4884 | // Re-inflate the widgets which have changed status |
| 4885 | widgetRefresh.run(); |
| 4886 | } else { |
| 4887 | // widgetRefresh will automatically run when the packages are updated. |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4888 | // For now just update the progress bars |
| 4889 | for (LauncherAppWidgetInfo info : changedInfo) { |
| 4890 | if (info.hostView instanceof PendingAppWidgetHostView) { |
| 4891 | info.installProgress = 100; |
| 4892 | ((PendingAppWidgetHostView) info.hostView).applyState(); |
| 4893 | } |
| 4894 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4895 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4896 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4899 | private void moveToScreen(int page, boolean animate) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4900 | if (!workspaceInModalState()) { |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 4901 | if (animate) { |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4902 | snapToPage(page); |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 4903 | } else { |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4904 | setCurrentPage(page); |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 4905 | } |
Joe Onorato | c45b168 | 2010-01-11 18:48:40 -0500 | [diff] [blame] | 4906 | } |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4907 | View child = getChildAt(page); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4908 | if (child != null) { |
| 4909 | child.requestFocus(); |
| 4910 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4911 | } |
| 4912 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4913 | void moveToDefaultScreen(boolean animate) { |
| 4914 | moveToScreen(mDefaultPage, animate); |
| 4915 | } |
| 4916 | |
| 4917 | void moveToCustomContentScreen(boolean animate) { |
| 4918 | if (hasCustomContent()) { |
| 4919 | int ccIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID); |
| 4920 | if (animate) { |
| 4921 | snapToPage(ccIndex); |
| 4922 | } else { |
| 4923 | setCurrentPage(ccIndex); |
| 4924 | } |
| 4925 | View child = getChildAt(ccIndex); |
| 4926 | if (child != null) { |
| 4927 | child.requestFocus(); |
| 4928 | } |
| 4929 | } |
Adam Cohen | 76128b6 | 2013-11-14 16:43:59 +0000 | [diff] [blame] | 4930 | exitWidgetResizeMode(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4931 | } |
| 4932 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4933 | @Override |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4934 | protected PageIndicator.PageMarkerResources getPageIndicatorMarker(int pageIndex) { |
| 4935 | long screenId = getScreenIdForPageIndex(pageIndex); |
| 4936 | if (screenId == EXTRA_EMPTY_SCREEN_ID) { |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 4937 | int count = mScreenOrder.size() - numCustomPages(); |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4938 | if (count > 1) { |
Winson Chung | ba4e52f | 2013-10-01 17:22:13 -0700 | [diff] [blame] | 4939 | return new PageIndicator.PageMarkerResources(R.drawable.ic_pageindicator_current, |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4940 | R.drawable.ic_pageindicator_add); |
| 4941 | } |
Winson Chung | 82dfe58 | 2013-07-26 15:07:49 -0700 | [diff] [blame] | 4942 | } |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4943 | |
Winson Chung | 82dfe58 | 2013-07-26 15:07:49 -0700 | [diff] [blame] | 4944 | return super.getPageIndicatorMarker(pageIndex); |
| 4945 | } |
| 4946 | |
| 4947 | @Override |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4948 | public void syncPages() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4949 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4950 | |
| 4951 | @Override |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 4952 | public void syncPageItems(int page, boolean immediate) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4953 | } |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 4954 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 4955 | protected String getPageIndicatorDescription() { |
| 4956 | String settings = getResources().getString(R.string.settings_button_text); |
| 4957 | return getCurrentPageDescription() + ", " + settings; |
| 4958 | } |
| 4959 | |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 4960 | protected String getCurrentPageDescription() { |
| 4961 | int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 4962 | int delta = numCustomPages(); |
| 4963 | if (hasCustomContent() && getNextPage() == 0) { |
| 4964 | return mCustomContentDescription; |
| 4965 | } |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 4966 | return String.format(getContext().getString(R.string.workspace_scroll_format), |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 4967 | page + 1 - delta, getChildCount() - delta); |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 4968 | } |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 4969 | |
| 4970 | public void getLocationInDragLayer(int[] loc) { |
| 4971 | mLauncher.getDragLayer().getLocationInDragLayer(this, loc); |
| 4972 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4973 | |
| 4974 | /** |
| 4975 | * Used as a workaround to ensure that the AppWidgetService receives the |
| 4976 | * PACKAGE_ADDED broadcast before updating widgets. |
| 4977 | */ |
| 4978 | private class DeferredWidgetRefresh implements Runnable { |
| 4979 | private final ArrayList<LauncherAppWidgetInfo> mInfos; |
| 4980 | private final LauncherAppWidgetHost mHost; |
| 4981 | private final Handler mHandler; |
| 4982 | |
| 4983 | private boolean mRefreshPending; |
| 4984 | |
| 4985 | public DeferredWidgetRefresh(ArrayList<LauncherAppWidgetInfo> infos, |
| 4986 | LauncherAppWidgetHost host) { |
| 4987 | mInfos = infos; |
| 4988 | mHost = host; |
| 4989 | mHandler = new Handler(); |
| 4990 | mRefreshPending = true; |
| 4991 | |
| 4992 | mHost.addProviderChangeListener(this); |
| 4993 | // Force refresh after 10 seconds, if we don't get the provider changed event. |
| 4994 | // This could happen when the provider is no longer available in the app. |
| 4995 | mHandler.postDelayed(this, 10000); |
| 4996 | } |
| 4997 | |
| 4998 | @Override |
| 4999 | public void run() { |
| 5000 | mHost.removeProviderChangeListener(this); |
| 5001 | mHandler.removeCallbacks(this); |
| 5002 | |
| 5003 | if (!mRefreshPending) { |
| 5004 | return; |
| 5005 | } |
| 5006 | |
| 5007 | mRefreshPending = false; |
| 5008 | |
| 5009 | for (LauncherAppWidgetInfo info : mInfos) { |
| 5010 | if (info.hostView instanceof PendingAppWidgetHostView) { |
| 5011 | PendingAppWidgetHostView view = (PendingAppWidgetHostView) info.hostView; |
| 5012 | mLauncher.removeAppWidget(info); |
| 5013 | |
| 5014 | CellLayout cl = (CellLayout) view.getParent().getParent(); |
| 5015 | // Remove the current widget |
| 5016 | cl.removeView(view); |
| 5017 | mLauncher.bindAppWidget(info); |
| 5018 | } |
| 5019 | } |
| 5020 | } |
| 5021 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 5022 | } |