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 | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 20 | import android.animation.AnimatorListenerAdapter; |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 21 | import android.animation.LayoutTransition; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 23 | import android.animation.PropertyValuesHolder; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 24 | import android.annotation.SuppressLint; |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 25 | import android.annotation.TargetApi; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 26 | import android.app.WallpaperManager; |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 27 | import android.appwidget.AppWidgetHostView; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 28 | import android.appwidget.AppWidgetProviderInfo; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.content.Context; |
Michael Jurka | adc574c | 2013-09-12 00:05:02 +0200 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
Patrick Dubroy | 7247f63 | 2010-08-04 16:02:59 -0700 | [diff] [blame] | 32 | import android.content.res.Resources; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | import android.content.res.TypedArray; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 34 | import android.graphics.Bitmap; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 35 | import android.graphics.Canvas; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 36 | import android.graphics.Matrix; |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 37 | import android.graphics.Paint; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 38 | import android.graphics.Point; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 39 | import android.graphics.PointF; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 40 | import android.graphics.Rect; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 41 | import android.graphics.Region.Op; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 42 | import android.graphics.drawable.Drawable; |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 43 | import android.os.AsyncTask; |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 44 | import android.os.Build; |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 45 | import android.os.Handler; |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 46 | import android.os.IBinder; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 47 | import android.os.Parcelable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.util.AttributeSet; |
Daniel Sandler | 291ad12 | 2010-05-24 16:03:53 -0400 | [diff] [blame] | 49 | import android.util.Log; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 50 | import android.util.SparseArray; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 51 | import android.view.Choreographer; |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 52 | import android.view.Display; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 54 | import android.view.View; |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 55 | import android.view.ViewGroup; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 56 | import android.view.accessibility.AccessibilityManager; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 57 | import android.view.animation.DecelerateInterpolator; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 58 | import android.view.animation.Interpolator; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 59 | import android.widget.TextView; |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 60 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 61 | import com.android.launcher3.FolderIcon.FolderRingAnimator; |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 62 | import com.android.launcher3.Launcher.CustomContentCallbacks; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 63 | import com.android.launcher3.Launcher.LauncherOverlay; |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 64 | import com.android.launcher3.LauncherSettings.Favorites; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 65 | import com.android.launcher3.UninstallDropTarget.UninstallSource; |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 66 | import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; |
Sunny Goyal | 1d08f70 | 2015-05-04 15:50:25 -0700 | [diff] [blame] | 67 | import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate; |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 68 | import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 69 | import com.android.launcher3.compat.UserHandleCompat; |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 70 | import com.android.launcher3.util.LongArrayMap; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 71 | import com.android.launcher3.util.Thunk; |
Sunny Goyal | 6a1e95a | 2015-03-20 17:26:30 -0700 | [diff] [blame] | 72 | import com.android.launcher3.util.WallpaperUtils; |
Hyunyoung Song | 3f47144 | 2015-04-08 19:01:34 -0700 | [diff] [blame] | 73 | import com.android.launcher3.widget.PendingAddShortcutInfo; |
| 74 | import com.android.launcher3.widget.PendingAddWidgetInfo; |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 75 | |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 76 | import java.util.ArrayList; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 77 | import java.util.HashMap; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 78 | import java.util.HashSet; |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 79 | import java.util.concurrent.atomic.AtomicInteger; |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 80 | |
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 | * The workspace is a wide area with a wallpaper and a finite number of pages. |
| 83 | * 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] | 84 | * 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] | 85 | */ |
Sunny Goyal | 5a1f53b | 2015-05-27 10:24:24 -0700 | [diff] [blame^] | 86 | public class Workspace extends PagedView |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 87 | implements DropTarget, DragSource, DragScroller, View.OnTouchListener, |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 88 | DragController.DragListener, LauncherTransitionable, ViewGroup.OnHierarchyChangeListener, |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 89 | Insettable, UninstallSource, AccessibilityDragSource { |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 90 | private static final String TAG = "Launcher.Workspace"; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -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 | |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 95 | private static final int ADJACENT_SCREEN_DROP_DURATION = 300; |
| 96 | |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 97 | static final boolean MAP_NO_RECURSE = false; |
| 98 | static final boolean MAP_RECURSE = true; |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 99 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 100 | private static final long CUSTOM_CONTENT_GESTURE_DELAY = 200; |
| 101 | private long mTouchDownTime = -1; |
| 102 | private long mCustomContentShowTime = -1; |
| 103 | |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 104 | private LayoutTransition mLayoutTransition; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 105 | @Thunk final WallpaperManager mWallpaperManager; |
| 106 | @Thunk IBinder mWindowToken; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 107 | |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 108 | private int mOriginalDefaultPage; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 109 | private int mDefaultPage; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 110 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 111 | private ShortcutAndWidgetContainer mDragSourceInternal; |
| 112 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 113 | // 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] | 114 | final static long EXTRA_EMPTY_SCREEN_ID = -201; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 115 | private final static long CUSTOM_CONTENT_SCREEN_ID = -301; |
| 116 | |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 117 | @Thunk LongArrayMap<CellLayout> mWorkspaceScreens = new LongArrayMap<>(); |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 118 | @Thunk ArrayList<Long> mScreenOrder = new ArrayList<Long>(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 119 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 120 | @Thunk Runnable mRemoveEmptyScreenRunnable; |
| 121 | @Thunk boolean mDeferRemoveExtraEmptyScreen = false; |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 122 | @Thunk boolean mAddNewPageOnDrag = true; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 123 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 124 | /** |
| 125 | * CellInfo for the cell that is currently being dragged |
| 126 | */ |
| 127 | private CellLayout.CellInfo mDragInfo; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 128 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 129 | /** |
| 130 | * Target drop area calculated during last acceptDrop call. |
| 131 | */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 132 | @Thunk int[] mTargetCell = new int[2]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 133 | private int mDragOverX = -1; |
| 134 | private int mDragOverY = -1; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 135 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 136 | static Rect mLandscapeCellLayoutMetrics = null; |
| 137 | static Rect mPortraitCellLayoutMetrics = null; |
| 138 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 139 | CustomContentCallbacks mCustomContentCallbacks; |
| 140 | boolean mCustomContentShowing; |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 141 | private float mLastCustomContentScrollProgress = -1f; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 142 | private String mCustomContentDescription = ""; |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 143 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 144 | /** |
| 145 | * The CellLayout that is currently being dragged over |
| 146 | */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 147 | @Thunk CellLayout mDragTargetLayout = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 148 | /** |
| 149 | * The CellLayout that we will show as glowing |
| 150 | */ |
| 151 | private CellLayout mDragOverlappingLayout = null; |
| 152 | |
| 153 | /** |
| 154 | * The CellLayout which will be dropped to |
| 155 | */ |
| 156 | private CellLayout mDropToLayout = null; |
| 157 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 158 | @Thunk Launcher mLauncher; |
| 159 | @Thunk IconCache mIconCache; |
| 160 | @Thunk DragController mDragController; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 161 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 162 | // These are temporary variables to prevent having to allocate a new object just to |
| 163 | // 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] | 164 | private int[] mTempCell = new int[2]; |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 165 | private int[] mTempPt = new int[2]; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 166 | private int[] mTempEstimate = new int[2]; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 167 | @Thunk float[] mDragViewVisualCenter = new float[2]; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 168 | private float[] mTempCellLayoutCenterCoordinates = new float[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 169 | private Matrix mTempInverseMatrix = new Matrix(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 170 | |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 171 | private SpringLoadedDragController mSpringLoadedDragController; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 172 | private float mSpringLoadedShrinkFactor; |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 173 | private float mOverviewModeShrinkFactor; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 174 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 175 | // 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] | 176 | // in all apps or customize mode) |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 177 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 178 | enum State { NORMAL, NORMAL_HIDDEN, SPRING_LOADED, OVERVIEW, OVERVIEW_HIDDEN}; |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 179 | private State mState = State.NORMAL; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 180 | private boolean mIsSwitchingState = false; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 181 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 182 | boolean mAnimatingViewIntoPlace = false; |
| 183 | boolean mIsDragOccuring = false; |
| 184 | boolean mChildrenLayersEnabled = true; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 185 | |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 186 | private boolean mStripScreensOnPageStopMoving = false; |
| 187 | |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 188 | /** 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] | 189 | private boolean mInScrollArea = false; |
| 190 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 191 | private HolographicOutlineHelper mOutlineHelper; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 192 | @Thunk Bitmap mDragOutline = null; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 193 | private static final Rect sTempRect = new Rect(); |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 194 | private final int[] mTempXY = new int[2]; |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 195 | private int[] mTempVisiblePagesRange = new int[2]; |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 196 | private boolean mOverscrollEffectSet; |
Michael Jurka | f8304f0 | 2012-04-26 13:33:26 -0700 | [diff] [blame] | 197 | public static final int DRAG_BITMAP_PADDING = 2; |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 198 | private boolean mWorkspaceFadeInAdjacentScreens; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 199 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 200 | WallpaperOffsetInterpolator mWallpaperOffset; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 201 | @Thunk boolean mWallpaperIsLiveWallpaper; |
| 202 | @Thunk int mNumPagesForWallpaperParallax; |
| 203 | @Thunk float mLastSetWallpaperOffsetSteps = 0; |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 204 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 205 | @Thunk Runnable mDelayedResizeRunnable; |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 206 | private Runnable mDelayedSnapToPageRunnable; |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 207 | private Point mDisplaySize = new Point(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 208 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 209 | // 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] | 210 | private static final int FOLDER_CREATION_TIMEOUT = 0; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 211 | public static final int REORDER_TIMEOUT = 350; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 212 | private final Alarm mFolderCreationAlarm = new Alarm(); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 213 | private final Alarm mReorderAlarm = new Alarm(); |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 214 | @Thunk FolderRingAnimator mDragFolderRingAnimator = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 215 | private FolderIcon mDragOverFolderIcon = null; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 216 | private boolean mCreateUserFolderOnDrop = false; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 217 | private boolean mAddToExistingFolderOnDrop = false; |
| 218 | private DropTarget.DragEnforcer mDragEnforcer; |
Adam Cohen | 3aff81c | 2012-05-16 21:01:01 -0700 | [diff] [blame] | 219 | private float mMaxDistanceForFolderCreation; |
Adam Cohen | 073a46f | 2011-05-17 16:28:09 -0700 | [diff] [blame] | 220 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 221 | private final Canvas mCanvas = new Canvas(); |
| 222 | |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 223 | // Variables relating to touch disambiguation (scrolling workspace vs. scrolling a widget) |
| 224 | private float mXDown; |
| 225 | private float mYDown; |
| 226 | final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6; |
| 227 | final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3; |
| 228 | final static float TOUCH_SLOP_DAMPING_FACTOR = 4; |
| 229 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 230 | // Relating to the animation of items being dropped externally |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 231 | public static final int ANIMATE_INTO_POSITION_AND_DISAPPEAR = 0; |
| 232 | public static final int ANIMATE_INTO_POSITION_AND_REMAIN = 1; |
| 233 | public static final int ANIMATE_INTO_POSITION_AND_RESIZE = 2; |
| 234 | public static final int COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION = 3; |
| 235 | public static final int CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION = 4; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 236 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 237 | // Related to dragging, folder creation and reordering |
| 238 | private static final int DRAG_MODE_NONE = 0; |
| 239 | private static final int DRAG_MODE_CREATE_FOLDER = 1; |
| 240 | private static final int DRAG_MODE_ADD_TO_FOLDER = 2; |
| 241 | private static final int DRAG_MODE_REORDER = 3; |
| 242 | private int mDragMode = DRAG_MODE_NONE; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 243 | @Thunk int mLastReorderX = -1; |
| 244 | @Thunk int mLastReorderY = -1; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 245 | |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 246 | private SparseArray<Parcelable> mSavedStates; |
| 247 | private final ArrayList<Integer> mRestoredPages = new ArrayList<Integer>(); |
| 248 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 249 | // 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] | 250 | private int mSavedScrollX; |
| 251 | private float mSavedRotationY; |
| 252 | private float mSavedTranslationX; |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 253 | |
| 254 | private float mCurrentScale; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 255 | private float mTransitionProgress; |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 256 | |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 257 | float mOverScrollEffect = 0f; |
| 258 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 259 | @Thunk Runnable mDeferredAction; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 260 | private boolean mDeferDropAfterUninstall; |
| 261 | private boolean mUninstallSuccessful; |
| 262 | |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 263 | // State related to Launcher Overlay |
| 264 | LauncherOverlay mLauncherOverlay; |
| 265 | boolean mScrollInteractionBegan; |
| 266 | boolean mStartedSendingScrollEvents; |
| 267 | boolean mShouldSendPageSettled; |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 268 | int mLastOverlaySroll = 0; |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 269 | |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 270 | // Handles workspace state transitions |
| 271 | private WorkspaceStateTransitionAnimation mStateTransitionAnimation; |
| 272 | |
Sunny Goyal | 1d08f70 | 2015-05-04 15:50:25 -0700 | [diff] [blame] | 273 | private AccessibilityDelegate mPagesAccessibilityDelegate; |
| 274 | |
Romain Guy | eeacd56 | 2012-10-10 18:47:33 -0700 | [diff] [blame] | 275 | private final Runnable mBindPages = new Runnable() { |
| 276 | @Override |
| 277 | public void run() { |
| 278 | mLauncher.getModel().bindRemainingSynchronousPages(); |
| 279 | } |
| 280 | }; |
| 281 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 282 | /** |
| 283 | * Used to inflate the Workspace from XML. |
| 284 | * |
| 285 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 286 | * @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] | 287 | */ |
| 288 | public Workspace(Context context, AttributeSet attrs) { |
| 289 | this(context, attrs, 0); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Used to inflate the Workspace from XML. |
| 294 | * |
| 295 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 296 | * @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] | 297 | * @param defStyle Unused. |
| 298 | */ |
| 299 | public Workspace(Context context, AttributeSet attrs, int defStyle) { |
| 300 | super(context, attrs, defStyle); |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 301 | |
Daniel Sandler | e4f9891 | 2013-06-25 15:13:26 -0400 | [diff] [blame] | 302 | mOutlineHelper = HolographicOutlineHelper.obtain(context); |
| 303 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 304 | mDragEnforcer = new DropTarget.DragEnforcer(context); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 305 | // With workspace, data is available straight from the get-go |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 306 | |
Michael Jurka | 8bc66c7 | 2012-06-21 08:36:45 -0700 | [diff] [blame] | 307 | mLauncher = (Launcher) context; |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 308 | mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this); |
Winson Chung | 867ca62 | 2012-02-21 15:48:35 -0800 | [diff] [blame] | 309 | final Resources res = getResources(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 310 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
| 311 | mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens(); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 312 | mFadeInAdjacentScreens = false; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 313 | mWallpaperManager = WallpaperManager.getInstance(context); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 314 | |
| 315 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 316 | R.styleable.Workspace, defStyle, 0); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 317 | mSpringLoadedShrinkFactor = |
| 318 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 319 | mOverviewModeShrinkFactor = grid.getOverviewModeScale(mIsRtl); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 320 | mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 321 | a.recycle(); |
| 322 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 323 | setOnHierarchyChangeListener(this); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 324 | setHapticFeedbackEnabled(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 326 | initWorkspace(); |
Winson Chung | c35afb2 | 2011-02-23 13:01:49 -0800 | [diff] [blame] | 327 | |
| 328 | // Disable multitouch across the workspace/all apps/customize tray |
| 329 | setMotionEventSplittingEnabled(true); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 330 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 331 | } |
| 332 | |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 333 | @Override |
| 334 | public void setInsets(Rect insets) { |
| 335 | mInsets.set(insets); |
Adam Cohen | 6400b84 | 2013-11-26 15:45:38 -0800 | [diff] [blame] | 336 | |
| 337 | CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); |
| 338 | if (customScreen != null) { |
| 339 | View customContent = customScreen.getShortcutsAndWidgets().getChildAt(0); |
| 340 | if (customContent instanceof Insettable) { |
| 341 | ((Insettable) customContent).setInsets(mInsets); |
| 342 | } |
| 343 | } |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 344 | } |
| 345 | |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 346 | // estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each |
| 347 | // dimension if unsuccessful |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 348 | public int[] estimateItemSize(ItemInfo itemInfo, boolean springLoaded) { |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 349 | int[] size = new int[2]; |
| 350 | if (getChildCount() > 0) { |
Winson Chung | ad7db6e | 2013-10-08 14:01:06 -0700 | [diff] [blame] | 351 | // Use the first non-custom page to estimate the child position |
| 352 | CellLayout cl = (CellLayout) getChildAt(numCustomPages()); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 353 | Rect r = estimateItemPosition(cl, itemInfo, 0, 0, itemInfo.spanX, itemInfo.spanY); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 354 | size[0] = r.width(); |
| 355 | size[1] = r.height(); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 356 | if (springLoaded) { |
| 357 | size[0] *= mSpringLoadedShrinkFactor; |
| 358 | size[1] *= mSpringLoadedShrinkFactor; |
| 359 | } |
| 360 | return size; |
| 361 | } else { |
| 362 | size[0] = Integer.MAX_VALUE; |
| 363 | size[1] = Integer.MAX_VALUE; |
| 364 | return size; |
| 365 | } |
| 366 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 367 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 368 | public Rect estimateItemPosition(CellLayout cl, ItemInfo pendingInfo, |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 369 | int hCell, int vCell, int hSpan, int vSpan) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 370 | Rect r = new Rect(); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 371 | cl.cellToRect(hCell, vCell, hSpan, vSpan, r); |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 372 | return r; |
| 373 | } |
| 374 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 375 | public void onDragStart(final DragSource source, Object info, int dragAction) { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 376 | mIsDragOccuring = true; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 377 | updateChildrenLayersEnabled(false); |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 378 | mLauncher.lockScreenOrientation(); |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 379 | mLauncher.onInteractionBegin(); |
Winson Chung | f561bdf | 2012-05-03 11:20:19 -0700 | [diff] [blame] | 380 | // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging |
| 381 | InstallShortcutReceiver.enableInstallQueue(); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 382 | post(new Runnable() { |
| 383 | @Override |
| 384 | public void run() { |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 385 | if (mIsDragOccuring && mAddNewPageOnDrag) { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 386 | mDeferRemoveExtraEmptyScreen = false; |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 387 | addExtraEmptyScreenOnDrag(); |
| 388 | } |
| 389 | } |
| 390 | }); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 393 | public void setAddNewPageOnDrag(boolean addPage) { |
| 394 | mAddNewPageOnDrag = addPage; |
| 395 | } |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 396 | |
| 397 | public void deferRemoveExtraEmptyScreen() { |
| 398 | mDeferRemoveExtraEmptyScreen = true; |
| 399 | } |
| 400 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 401 | public void onDragEnd() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 402 | if (!mDeferRemoveExtraEmptyScreen) { |
| 403 | removeExtraEmptyScreen(true, mDragSourceInternal != null); |
| 404 | } |
| 405 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 406 | mIsDragOccuring = false; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 407 | updateChildrenLayersEnabled(false); |
Winson Chung | 4b919f8 | 2012-05-01 10:44:08 -0700 | [diff] [blame] | 408 | mLauncher.unlockScreenOrientation(false); |
Winson Chung | f561bdf | 2012-05-03 11:20:19 -0700 | [diff] [blame] | 409 | |
| 410 | // Re-enable any Un/InstallShortcutReceiver and now process any queued items |
| 411 | InstallShortcutReceiver.disableAndFlushInstallQueue(getContext()); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 412 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 413 | mDragSourceInternal = null; |
Sandeep Siddhartha | ab2d9d7 | 2013-09-17 13:18:24 -0700 | [diff] [blame] | 414 | mLauncher.onInteractionEnd(); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 415 | } |
| 416 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 417 | /** |
| 418 | * Initializes various states for this workspace. |
| 419 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 420 | protected void initWorkspace() { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 421 | mCurrentPage = mDefaultPage; |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 422 | LauncherAppState app = LauncherAppState.getInstance(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 423 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 424 | mIconCache = app.getIconCache(); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 425 | setWillNotDraw(false); |
Romain Guy | ce3cbd1 | 2013-02-25 15:00:36 -0800 | [diff] [blame] | 426 | setClipChildren(false); |
| 427 | setClipToPadding(false); |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 428 | setChildrenDrawnWithCacheEnabled(true); |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 429 | |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 430 | setMinScale(mOverviewModeShrinkFactor); |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 431 | setupLayoutTransition(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 432 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 433 | mWallpaperOffset = new WallpaperOffsetInterpolator(); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 434 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
Michael Jurka | 84f2ce7 | 2012-04-13 15:08:01 -0700 | [diff] [blame] | 435 | display.getSize(mDisplaySize); |
Adam Cohen | 265b9a6 | 2011-12-07 14:37:18 -0800 | [diff] [blame] | 436 | |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 437 | mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx); |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 438 | |
| 439 | // Set the wallpaper dimensions when Launcher starts up |
Adam Cohen | 824fcb3 | 2014-05-21 23:01:25 +0000 | [diff] [blame] | 440 | setWallpaperDimension(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 443 | private void setupLayoutTransition() { |
| 444 | // We want to show layout transitions when pages are deleted, to close the gap. |
| 445 | mLayoutTransition = new LayoutTransition(); |
| 446 | mLayoutTransition.enableTransitionType(LayoutTransition.DISAPPEARING); |
| 447 | mLayoutTransition.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); |
| 448 | mLayoutTransition.disableTransitionType(LayoutTransition.APPEARING); |
| 449 | mLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING); |
| 450 | setLayoutTransition(mLayoutTransition); |
| 451 | } |
| 452 | |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 453 | void enableLayoutTransitions() { |
| 454 | setLayoutTransition(mLayoutTransition); |
| 455 | } |
| 456 | void disableLayoutTransitions() { |
| 457 | setLayoutTransition(null); |
| 458 | } |
| 459 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 460 | @Override |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 461 | public void onChildViewAdded(View parent, View child) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 462 | if (!(child instanceof CellLayout)) { |
| 463 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 464 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 465 | CellLayout cl = ((CellLayout) child); |
| 466 | cl.setOnInterceptTouchListener(this); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 467 | cl.setClickable(true); |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 468 | cl.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
Winson Chung | f70696d | 2013-06-25 16:19:53 -0700 | [diff] [blame] | 469 | super.onChildViewAdded(parent, child); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Michael Jurka | 920d7f4 | 2012-05-14 16:29:55 -0700 | [diff] [blame] | 472 | protected boolean shouldDrawChild(View child) { |
| 473 | final CellLayout cl = (CellLayout) child; |
| 474 | return super.shouldDrawChild(child) && |
Winson Chung | f4bd236 | 2013-10-07 17:11:27 -0700 | [diff] [blame] | 475 | (mIsSwitchingState || |
| 476 | cl.getShortcutsAndWidgets().getAlpha() > 0 || |
Michael Jurka | 920d7f4 | 2012-05-14 16:29:55 -0700 | [diff] [blame] | 477 | cl.getBackgroundAlpha() > 0); |
| 478 | } |
| 479 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 480 | /** |
| 481 | * @return The open folder on the current screen, or null if there is none |
| 482 | */ |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 483 | public Folder getOpenFolder() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 484 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 485 | int count = dragLayer.getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 486 | for (int i = 0; i < count; i++) { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 487 | View child = dragLayer.getChildAt(i); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 488 | if (child instanceof Folder) { |
| 489 | Folder folder = (Folder) child; |
| 490 | if (folder.getInfo().opened) |
| 491 | return folder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | return null; |
| 495 | } |
| 496 | |
Patrick Dubroy | a0aa012 | 2011-02-24 11:42:23 -0800 | [diff] [blame] | 497 | boolean isTouchActive() { |
| 498 | return mTouchState != TOUCH_STATE_REST; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 499 | } |
| 500 | |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 501 | public void removeAllWorkspaceScreens() { |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 502 | // Disable all layout transitions before removing all pages to ensure that we don't get the |
| 503 | // transition animations competing with us changing the scroll when we add pages or the |
| 504 | // custom content screen |
| 505 | disableLayoutTransitions(); |
| 506 | |
| 507 | // Since we increment the current page when we call addCustomContentPage via bindScreens |
| 508 | // (and other places), we need to adjust the current page back when we clear the pages |
| 509 | if (hasCustomContent()) { |
| 510 | removeCustomContentPage(); |
| 511 | } |
| 512 | |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 513 | // Remove the pages and clear the screen models |
| 514 | removeAllViews(); |
| 515 | mScreenOrder.clear(); |
| 516 | mWorkspaceScreens.clear(); |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 517 | |
| 518 | // Re-enable the layout transitions |
| 519 | enableLayoutTransitions(); |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 522 | public long insertNewWorkspaceScreenBeforeEmptyScreen(long screenId) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 523 | // Find the index to insert this view into. If the empty screen exists, then |
| 524 | // insert it before that. |
| 525 | int insertIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID); |
| 526 | if (insertIndex < 0) { |
| 527 | insertIndex = mScreenOrder.size(); |
| 528 | } |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 529 | return insertNewWorkspaceScreen(screenId, insertIndex); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 532 | public long insertNewWorkspaceScreen(long screenId) { |
| 533 | return insertNewWorkspaceScreen(screenId, getChildCount()); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Adam Cohen | 89bddfa | 2013-08-20 11:57:13 -0700 | [diff] [blame] | 536 | public long insertNewWorkspaceScreen(long screenId, int insertIndex) { |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 537 | if (mWorkspaceScreens.containsKey(screenId)) { |
| 538 | throw new RuntimeException("Screen id " + screenId + " already exists!"); |
| 539 | } |
| 540 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 541 | // Inflate the cell layout, but do not add it automatically so that we can get the newly |
| 542 | // created CellLayout. |
| 543 | CellLayout newScreen = (CellLayout) mLauncher.getLayoutInflater().inflate( |
| 544 | R.layout.workspace_screen, this, false /* attachToRoot */); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 545 | |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 546 | newScreen.setOnLongClickListener(mLongClickListener); |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 547 | newScreen.setOnClickListener(mLauncher); |
Winson Chung | 837b241 | 2013-09-09 14:43:51 -0700 | [diff] [blame] | 548 | newScreen.setSoundEffectsEnabled(false); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 549 | mWorkspaceScreens.put(screenId, newScreen); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 550 | mScreenOrder.add(insertIndex, screenId); |
| 551 | addView(newScreen, insertIndex); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 552 | |
Winson Chung | 3d9490a | 2015-03-24 17:38:42 -0700 | [diff] [blame] | 553 | LauncherAccessibilityDelegate delegate = |
| 554 | LauncherAppState.getInstance().getAccessibilityDelegate(); |
| 555 | if (delegate != null && delegate.isInAccessibleDrag()) { |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 556 | newScreen.enableAccessibleDrag(true, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 557 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 558 | return screenId; |
| 559 | } |
| 560 | |
Derek Prothro | dadd984 | 2014-01-17 13:43:50 -0500 | [diff] [blame] | 561 | public void createCustomContentContainer() { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 562 | CellLayout customScreen = (CellLayout) |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 563 | mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, this, false); |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 564 | customScreen.disableDragTarget(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 565 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 566 | mWorkspaceScreens.put(CUSTOM_CONTENT_SCREEN_ID, customScreen); |
| 567 | mScreenOrder.add(0, CUSTOM_CONTENT_SCREEN_ID); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 568 | |
Adam Cohen | 2702ea0 | 2013-08-15 16:17:42 -0700 | [diff] [blame] | 569 | // We want no padding on the custom content |
| 570 | customScreen.setPadding(0, 0, 0, 0); |
| 571 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 572 | addFullScreenPage(customScreen); |
Michael Jurka | ee0ce2b | 2013-07-02 17:24:35 -0700 | [diff] [blame] | 573 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 574 | // Ensure that the current page and default page are maintained. |
Winson Chung | 9e6a0a2 | 2013-08-27 11:58:12 -0700 | [diff] [blame] | 575 | mDefaultPage = mOriginalDefaultPage + 1; |
Winson Chung | 82e5c98 | 2013-10-09 12:04:50 -0700 | [diff] [blame] | 576 | |
| 577 | // Update the custom content hint |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 578 | if (mRestorePage != INVALID_RESTORE_PAGE) { |
| 579 | mRestorePage = mRestorePage + 1; |
| 580 | } else { |
| 581 | setCurrentPage(getCurrentPage() + 1); |
| 582 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 585 | public void removeCustomContentPage() { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 586 | CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); |
| 587 | if (customScreen == null) { |
| 588 | throw new RuntimeException("Expected custom content screen to exist"); |
| 589 | } |
| 590 | |
| 591 | mWorkspaceScreens.remove(CUSTOM_CONTENT_SCREEN_ID); |
| 592 | mScreenOrder.remove(CUSTOM_CONTENT_SCREEN_ID); |
| 593 | removeView(customScreen); |
Adam Cohen | bb6fda6 | 2013-10-10 12:48:52 -0700 | [diff] [blame] | 594 | |
| 595 | if (mCustomContentCallbacks != null) { |
| 596 | mCustomContentCallbacks.onScrollProgressChanged(0); |
| 597 | mCustomContentCallbacks.onHide(); |
| 598 | } |
| 599 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 600 | mCustomContentCallbacks = null; |
| 601 | |
| 602 | // Ensure that the current page and default page are maintained. |
| 603 | mDefaultPage = mOriginalDefaultPage - 1; |
Winson Chung | 82e5c98 | 2013-10-09 12:04:50 -0700 | [diff] [blame] | 604 | |
| 605 | // Update the custom content hint |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 606 | if (mRestorePage != INVALID_RESTORE_PAGE) { |
| 607 | mRestorePage = mRestorePage - 1; |
| 608 | } else { |
| 609 | setCurrentPage(getCurrentPage() - 1); |
| 610 | } |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 611 | } |
| 612 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 613 | public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks, |
| 614 | String description) { |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 615 | if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) { |
| 616 | throw new RuntimeException("Expected custom content screen to exist"); |
| 617 | } |
| 618 | |
| 619 | // Add the custom content to the full screen custom page |
| 620 | CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); |
| 621 | int spanX = customScreen.getCountX(); |
| 622 | int spanY = customScreen.getCountY(); |
| 623 | CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY); |
| 624 | lp.canReorder = false; |
| 625 | lp.isFullscreen = true; |
John Spurlock | 77e1f47 | 2013-09-11 10:09:51 -0400 | [diff] [blame] | 626 | if (customContent instanceof Insettable) { |
| 627 | ((Insettable)customContent).setInsets(mInsets); |
| 628 | } |
Adam Cohen | 166ebd4 | 2013-11-26 14:55:45 -0800 | [diff] [blame] | 629 | |
| 630 | // Verify that the child is removed from any existing parent. |
| 631 | if (customContent.getParent() instanceof ViewGroup) { |
| 632 | ViewGroup parent = (ViewGroup) customContent.getParent(); |
| 633 | parent.removeView(customContent); |
| 634 | } |
Adam Cohen | 225ad9b | 2013-10-07 13:03:00 -0700 | [diff] [blame] | 635 | customScreen.removeAllViews(); |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 636 | customScreen.addViewToCellLayout(customContent, 0, 0, lp, true); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 637 | mCustomContentDescription = description; |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 638 | |
| 639 | mCustomContentCallbacks = callbacks; |
| 640 | } |
| 641 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 642 | public void addExtraEmptyScreenOnDrag() { |
| 643 | boolean lastChildOnScreen = false; |
| 644 | boolean childOnFinalScreen = false; |
| 645 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 646 | // Cancel any pending removal of empty screen |
| 647 | mRemoveEmptyScreenRunnable = null; |
| 648 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 649 | if (mDragSourceInternal != null) { |
| 650 | if (mDragSourceInternal.getChildCount() == 1) { |
| 651 | lastChildOnScreen = true; |
| 652 | } |
| 653 | CellLayout cl = (CellLayout) mDragSourceInternal.getParent(); |
| 654 | if (indexOfChild(cl) == getChildCount() - 1) { |
| 655 | childOnFinalScreen = true; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | // If this is the last item on the final screen |
| 660 | if (lastChildOnScreen && childOnFinalScreen) { |
| 661 | return; |
| 662 | } |
| 663 | if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { |
| 664 | insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | public boolean addExtraEmptyScreen() { |
| 669 | if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { |
| 670 | insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); |
| 671 | return true; |
| 672 | } |
| 673 | return false; |
| 674 | } |
| 675 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 676 | private void convertFinalScreenToEmptyScreenIfNecessary() { |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 677 | if (mLauncher.isWorkspaceLoading()) { |
| 678 | // Invalid and dangerous operation if workspace is loading |
| 679 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 680 | return; |
| 681 | } |
| 682 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 683 | if (hasExtraEmptyScreen() || mScreenOrder.size() == 0) return; |
| 684 | long finalScreenId = mScreenOrder.get(mScreenOrder.size() - 1); |
| 685 | |
| 686 | if (finalScreenId == CUSTOM_CONTENT_SCREEN_ID) return; |
| 687 | CellLayout finalScreen = mWorkspaceScreens.get(finalScreenId); |
| 688 | |
| 689 | // 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] | 690 | if (finalScreen.getShortcutsAndWidgets().getChildCount() == 0 && |
| 691 | !finalScreen.isDropPending()) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 692 | mWorkspaceScreens.remove(finalScreenId); |
| 693 | mScreenOrder.remove(finalScreenId); |
| 694 | |
| 695 | // if this is the last non-custom content screen, convert it to the empty screen |
| 696 | mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, finalScreen); |
| 697 | mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID); |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 698 | |
Winson Chung | f0716b7 | 2013-11-18 16:09:54 -0800 | [diff] [blame] | 699 | // Update the model if we have changed any screens |
| 700 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 704 | public void removeExtraEmptyScreen(final boolean animate, boolean stripEmptyScreens) { |
| 705 | removeExtraEmptyScreenDelayed(animate, null, 0, stripEmptyScreens); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 708 | public void removeExtraEmptyScreenDelayed(final boolean animate, final Runnable onComplete, |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 709 | final int delay, final boolean stripEmptyScreens) { |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 710 | if (mLauncher.isWorkspaceLoading()) { |
| 711 | // Don't strip empty screens if the workspace is still loading |
| 712 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 713 | return; |
| 714 | } |
| 715 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 716 | if (delay > 0) { |
| 717 | postDelayed(new Runnable() { |
| 718 | @Override |
| 719 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 720 | removeExtraEmptyScreenDelayed(animate, onComplete, 0, stripEmptyScreens); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 721 | } |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 722 | }, delay); |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | convertFinalScreenToEmptyScreenIfNecessary(); |
| 727 | if (hasExtraEmptyScreen()) { |
| 728 | int emptyIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID); |
| 729 | if (getNextPage() == emptyIndex) { |
| 730 | snapToPage(getNextPage() - 1, SNAP_OFF_EMPTY_SCREEN_DURATION); |
| 731 | fadeAndRemoveEmptyScreen(SNAP_OFF_EMPTY_SCREEN_DURATION, FADE_EMPTY_SCREEN_DURATION, |
| 732 | onComplete, stripEmptyScreens); |
| 733 | } else { |
| 734 | fadeAndRemoveEmptyScreen(0, FADE_EMPTY_SCREEN_DURATION, |
| 735 | onComplete, stripEmptyScreens); |
| 736 | } |
| 737 | return; |
Adam Cohen | 3a14eeb | 2013-11-15 16:51:22 +0000 | [diff] [blame] | 738 | } else if (stripEmptyScreens) { |
| 739 | // If we're not going to strip the empty screens after removing |
| 740 | // the extra empty screen, do it right away. |
| 741 | stripEmptyScreens(); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 742 | } |
Adam Cohen | 3a14eeb | 2013-11-15 16:51:22 +0000 | [diff] [blame] | 743 | |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 744 | if (onComplete != null) { |
| 745 | onComplete.run(); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete, |
| 750 | final boolean stripEmptyScreens) { |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 751 | // XXX: Do we need to update LM workspace screens below? |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 752 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f); |
| 753 | PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f); |
| 754 | |
| 755 | final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); |
| 756 | |
| 757 | mRemoveEmptyScreenRunnable = new Runnable() { |
| 758 | @Override |
| 759 | public void run() { |
| 760 | if (hasExtraEmptyScreen()) { |
| 761 | mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); |
| 762 | mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); |
| 763 | removeView(cl); |
| 764 | if (stripEmptyScreens) { |
| 765 | stripEmptyScreens(); |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | }; |
| 770 | |
| 771 | ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(cl, alpha, bgAlpha); |
| 772 | oa.setDuration(duration); |
| 773 | oa.setStartDelay(delay); |
| 774 | oa.addListener(new AnimatorListenerAdapter() { |
| 775 | @Override |
| 776 | public void onAnimationEnd(Animator animation) { |
| 777 | if (mRemoveEmptyScreenRunnable != null) { |
| 778 | mRemoveEmptyScreenRunnable.run(); |
| 779 | } |
| 780 | if (onComplete != null) { |
| 781 | onComplete.run(); |
| 782 | } |
| 783 | } |
| 784 | }); |
| 785 | oa.start(); |
| 786 | } |
| 787 | |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 788 | public boolean hasExtraEmptyScreen() { |
| 789 | int nScreens = getChildCount(); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 790 | nScreens = nScreens - numCustomPages(); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 791 | return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1; |
| 792 | } |
| 793 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 794 | public long commitExtraEmptyScreen() { |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 795 | if (mLauncher.isWorkspaceLoading()) { |
| 796 | // Invalid and dangerous operation if workspace is loading |
| 797 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 798 | return -1; |
| 799 | } |
Winson Chung | a90303b | 2013-11-15 13:05:06 -0800 | [diff] [blame] | 800 | |
Winson Chung | 89f9705 | 2013-09-20 11:32:26 -0700 | [diff] [blame] | 801 | int index = getPageIndexForScreenId(EXTRA_EMPTY_SCREEN_ID); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 802 | CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 803 | mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 804 | mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); |
| 805 | |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 806 | long newId = LauncherAppState.getLauncherProvider().generateNewScreenId(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 807 | mWorkspaceScreens.put(newId, cl); |
| 808 | mScreenOrder.add(newId); |
| 809 | |
Winson Chung | 89f9705 | 2013-09-20 11:32:26 -0700 | [diff] [blame] | 810 | // Update the page indicator marker |
| 811 | if (getPageIndicator() != null) { |
| 812 | getPageIndicator().updateMarker(index, getPageIndicatorMarker(index)); |
| 813 | } |
| 814 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 815 | // Update the model for the new screen |
| 816 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
| 817 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 818 | return newId; |
| 819 | } |
| 820 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 821 | public CellLayout getScreenWithId(long screenId) { |
| 822 | CellLayout layout = mWorkspaceScreens.get(screenId); |
| 823 | return layout; |
| 824 | } |
| 825 | |
| 826 | public long getIdForScreen(CellLayout layout) { |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 827 | int index = mWorkspaceScreens.indexOfValue(layout); |
| 828 | if (index != -1) { |
| 829 | return mWorkspaceScreens.keyAt(index); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 830 | } |
| 831 | return -1; |
| 832 | } |
| 833 | |
| 834 | public int getPageIndexForScreenId(long screenId) { |
| 835 | return indexOfChild(mWorkspaceScreens.get(screenId)); |
| 836 | } |
| 837 | |
| 838 | public long getScreenIdForPageIndex(int index) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 839 | if (0 <= index && index < mScreenOrder.size()) { |
| 840 | return mScreenOrder.get(index); |
| 841 | } |
| 842 | return -1; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 845 | public ArrayList<Long> getScreenOrder() { |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 846 | return mScreenOrder; |
| 847 | } |
| 848 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 849 | public void stripEmptyScreens() { |
Adam Cohen | 65e4303 | 2014-03-03 11:37:21 -0800 | [diff] [blame] | 850 | if (mLauncher.isWorkspaceLoading()) { |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 851 | // Don't strip empty screens if the workspace is still loading. |
| 852 | // This is dangerous and can result in data loss. |
Adam Cohen | 517a7f5 | 2014-03-01 12:12:59 -0800 | [diff] [blame] | 853 | Launcher.addDumpLog(TAG, " - workspace loading, skip", true); |
| 854 | return; |
| 855 | } |
| 856 | |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 857 | if (isPageMoving()) { |
| 858 | mStripScreensOnPageStopMoving = true; |
| 859 | return; |
| 860 | } |
| 861 | |
| 862 | int currentPage = getNextPage(); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 863 | ArrayList<Long> removeScreens = new ArrayList<Long>(); |
Sunny Goyal | e2df062 | 2015-04-24 11:27:00 -0700 | [diff] [blame] | 864 | int total = mWorkspaceScreens.size(); |
| 865 | for (int i = 0; i < total; i++) { |
| 866 | long id = mWorkspaceScreens.keyAt(i); |
| 867 | CellLayout cl = mWorkspaceScreens.valueAt(i); |
Winson Chung | c916834 | 2013-06-26 14:54:55 -0700 | [diff] [blame] | 868 | if (id >= 0 && cl.getShortcutsAndWidgets().getChildCount() == 0) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 869 | removeScreens.add(id); |
| 870 | } |
| 871 | } |
| 872 | |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 873 | // We enforce at least one page to add new items to. In the case that we remove the last |
| 874 | // such screen, we convert the last screen to the empty screen |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 875 | int minScreens = 1 + numCustomPages(); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 876 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 877 | int pageShift = 0; |
| 878 | for (Long id: removeScreens) { |
| 879 | CellLayout cl = mWorkspaceScreens.get(id); |
| 880 | mWorkspaceScreens.remove(id); |
| 881 | mScreenOrder.remove(id); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 882 | |
| 883 | if (getChildCount() > minScreens) { |
| 884 | if (indexOfChild(cl) < currentPage) { |
| 885 | pageShift++; |
| 886 | } |
| 887 | removeView(cl); |
| 888 | } else { |
| 889 | // 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] | 890 | mRemoveEmptyScreenRunnable = null; |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 891 | mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, cl); |
| 892 | mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 893 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 894 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 895 | |
| 896 | if (!removeScreens.isEmpty()) { |
| 897 | // Update the model if we have changed any screens |
| 898 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
| 899 | } |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 900 | |
| 901 | if (pageShift >= 0) { |
| 902 | setCurrentPage(currentPage - pageShift); |
| 903 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | // See implementation for parameter definition. |
| 907 | void addInScreen(View child, long container, long screenId, |
| 908 | int x, int y, int spanX, int spanY) { |
| 909 | addInScreen(child, container, screenId, x, y, spanX, spanY, false, false); |
| 910 | } |
| 911 | |
| 912 | // At bind time, we use the rank (screenId) to compute x and y for hotseat items. |
| 913 | // See implementation for parameter definition. |
| 914 | void addInScreenFromBind(View child, long container, long screenId, int x, int y, |
| 915 | int spanX, int spanY) { |
| 916 | addInScreen(child, container, screenId, x, y, spanX, spanY, false, true); |
| 917 | } |
| 918 | |
| 919 | // See implementation for parameter definition. |
| 920 | void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, |
| 921 | boolean insert) { |
| 922 | addInScreen(child, container, screenId, x, y, spanX, spanY, insert, false); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 923 | } |
| 924 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 925 | /** |
| 926 | * Adds the specified child in the specified screen. The position and dimension of |
| 927 | * the child are defined by x, y, spanX and spanY. |
| 928 | * |
| 929 | * @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] | 930 | * @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] | 931 | * @param x The X position of the child in the screen's grid. |
| 932 | * @param y The Y position of the child in the screen's grid. |
| 933 | * @param spanX The number of cells spanned horizontally by the child. |
| 934 | * @param spanY The number of cells spanned vertically by the child. |
| 935 | * @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] | 936 | * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute |
| 937 | * the x and y position in which to place hotseat items. Otherwise |
| 938 | * 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] | 939 | */ |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 940 | void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, |
| 941 | boolean insert, boolean computeXYFromRank) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 942 | if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 943 | if (getScreenWithId(screenId) == null) { |
| 944 | Log.e(TAG, "Skipping child, screenId " + screenId + " not found"); |
Winson Chung | 8481e32 | 2013-08-09 16:06:38 -0700 | [diff] [blame] | 945 | // DEBUGGING - Print out the stack trace to see where we are adding from |
| 946 | new Throwable().printStackTrace(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 947 | return; |
| 948 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 949 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 950 | if (screenId == EXTRA_EMPTY_SCREEN_ID) { |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 951 | // This should never happen |
| 952 | throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID"); |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 955 | final CellLayout layout; |
| 956 | if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { |
| 957 | layout = mLauncher.getHotseat().getLayout(); |
Sunny Goyal | b3726d9 | 2014-08-20 16:58:17 -0700 | [diff] [blame] | 958 | child.setOnKeyListener(new HotseatIconKeyEventListener()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 959 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 960 | // Hide folder title in the hotseat |
| 961 | if (child instanceof FolderIcon) { |
| 962 | ((FolderIcon) child).setTextVisible(false); |
| 963 | } |
| 964 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 965 | if (computeXYFromRank) { |
| 966 | x = mLauncher.getHotseat().getCellXFromOrder((int) screenId); |
| 967 | y = mLauncher.getHotseat().getCellYFromOrder((int) screenId); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 968 | } else { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 969 | screenId = mLauncher.getHotseat().getOrderInHotseat(x, y); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 970 | } |
| 971 | } else { |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 972 | // Show folder title if not in the hotseat |
| 973 | if (child instanceof FolderIcon) { |
| 974 | ((FolderIcon) child).setTextVisible(true); |
| 975 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 976 | layout = getScreenWithId(screenId); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 977 | child.setOnKeyListener(new IconKeyEventListener()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Adam Cohen | 96d30a1 | 2013-07-16 18:13:21 -0700 | [diff] [blame] | 980 | ViewGroup.LayoutParams genericLp = child.getLayoutParams(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 981 | CellLayout.LayoutParams lp; |
| 982 | if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 983 | lp = new CellLayout.LayoutParams(x, y, spanX, spanY); |
| 984 | } else { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 985 | lp = (CellLayout.LayoutParams) genericLp; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 986 | lp.cellX = x; |
| 987 | lp.cellY = y; |
| 988 | lp.cellHSpan = spanX; |
| 989 | lp.cellVSpan = spanY; |
| 990 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 991 | |
Adam Cohen | 7f4eabe | 2011-04-21 16:19:16 -0700 | [diff] [blame] | 992 | if (spanX < 0 && spanY < 0) { |
| 993 | lp.isLockedToGrid = false; |
| 994 | } |
| 995 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 996 | // 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] | 997 | ItemInfo info = (ItemInfo) child.getTag(); |
| 998 | int childId = mLauncher.getViewIdForItem(info); |
| 999 | |
Michael Jurka | f3ca3ab | 2010-10-20 17:08:24 -0700 | [diff] [blame] | 1000 | boolean markCellsAsOccupied = !(child instanceof Folder); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1001 | if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1002 | // TODO: This branch occurs when the workspace is adding views |
| 1003 | // outside of the defined grid |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 1004 | // maybe we should be deleting these items from the LauncherModel? |
Adam Cohen | 4caf298 | 2013-08-20 18:54:31 -0700 | [diff] [blame] | 1005 | 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] | 1006 | } |
| 1007 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1008 | if (!(child instanceof Folder)) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 1009 | child.setHapticFeedbackEnabled(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1010 | child.setOnLongClickListener(mLongClickListener); |
| 1011 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1012 | if (child instanceof DropTarget) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1013 | mDragController.addDropTarget((DropTarget) child); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1014 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
Patrick Dubroy | d0ce1ec | 2011-01-19 18:47:27 -0800 | [diff] [blame] | 1017 | /** |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 1018 | * Called directly from a CellLayout (not by the framework), after we've been added as a |
| 1019 | * listener via setOnInterceptTouchEventListener(). This allows us to tell the CellLayout |
| 1020 | * that it should intercept touch events, which is not something that is normally supported. |
| 1021 | */ |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1022 | @SuppressLint("ClickableViewAccessibility") |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 1023 | @Override |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1024 | public boolean onTouch(View v, MotionEvent event) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1025 | return (workspaceInModalState() || !isFinishedSwitchingState()) |
| 1026 | || (!workspaceInModalState() && indexOfChild(v) != mCurrentPage); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 1027 | } |
| 1028 | |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 1029 | public boolean isSwitchingState() { |
| 1030 | return mIsSwitchingState; |
| 1031 | } |
| 1032 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1033 | /** This differs from isSwitchingState in that we take into account how far the transition |
| 1034 | * has completed. */ |
Winson Chung | 9b0b2fe | 2012-02-24 13:03:34 -0800 | [diff] [blame] | 1035 | public boolean isFinishedSwitchingState() { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1036 | return !mIsSwitchingState || (mTransitionProgress > 0.5f); |
| 1037 | } |
| 1038 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 1039 | protected void onWindowVisibilityChanged (int visibility) { |
| 1040 | mLauncher.onWindowVisibilityChanged(visibility); |
| 1041 | } |
| 1042 | |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1043 | @Override |
| 1044 | public boolean dispatchUnhandledMove(View focused, int direction) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1045 | if (workspaceInModalState() || !isFinishedSwitchingState()) { |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1046 | // when the home screens are shrunken, shouldn't allow side-scrolling |
| 1047 | return false; |
| 1048 | } |
| 1049 | return super.dispatchUnhandledMove(focused, direction); |
| 1050 | } |
| 1051 | |
| 1052 | @Override |
| 1053 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 1054 | switch (ev.getAction() & MotionEvent.ACTION_MASK) { |
| 1055 | case MotionEvent.ACTION_DOWN: |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1056 | mXDown = ev.getX(); |
| 1057 | mYDown = ev.getY(); |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1058 | mTouchDownTime = System.currentTimeMillis(); |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 1059 | break; |
| 1060 | case MotionEvent.ACTION_POINTER_UP: |
| 1061 | case MotionEvent.ACTION_UP: |
| 1062 | if (mTouchState == TOUCH_STATE_REST) { |
| 1063 | final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage); |
Sunny Goyal | 2805e63 | 2015-05-20 15:35:32 -0700 | [diff] [blame] | 1064 | if (currentPage != null) { |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 1065 | onWallpaperTap(ev); |
| 1066 | } |
| 1067 | } |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1068 | } |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1069 | return super.onInterceptTouchEvent(ev); |
| 1070 | } |
| 1071 | |
Jan-Willem Maarse | d3fbe68 | 2014-08-19 15:27:48 -0700 | [diff] [blame] | 1072 | @Override |
| 1073 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 1074 | // Ignore pointer scroll events if the custom content doesn't allow scrolling. |
| 1075 | if ((getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID) |
| 1076 | && (mCustomContentCallbacks != null) |
| 1077 | && !mCustomContentCallbacks.isScrollingAllowed()) { |
| 1078 | return false; |
| 1079 | } |
| 1080 | return super.onGenericMotionEvent(event); |
| 1081 | } |
| 1082 | |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1083 | protected void reinflateWidgetsIfNecessary() { |
| 1084 | final int clCount = getChildCount(); |
| 1085 | for (int i = 0; i < clCount; i++) { |
| 1086 | CellLayout cl = (CellLayout) getChildAt(i); |
| 1087 | ShortcutAndWidgetContainer swc = cl.getShortcutsAndWidgets(); |
| 1088 | final int itemCount = swc.getChildCount(); |
| 1089 | for (int j = 0; j < itemCount; j++) { |
| 1090 | View v = swc.getChildAt(j); |
| 1091 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1092 | if (v != null && v.getTag() instanceof LauncherAppWidgetInfo) { |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1093 | LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag(); |
| 1094 | LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) info.hostView; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 1095 | if (lahv != null && lahv.isReinflateRequired()) { |
Adam Cohen | 3d50932 | 2012-06-06 14:10:04 -0700 | [diff] [blame] | 1096 | mLauncher.removeAppWidget(info); |
| 1097 | // Remove the current widget which is inflated with the wrong orientation |
| 1098 | cl.removeView(lahv); |
| 1099 | mLauncher.bindAppWidget(info); |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 1106 | @Override |
| 1107 | protected void determineScrollingStart(MotionEvent ev) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1108 | if (!isFinishedSwitchingState()) return; |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1109 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1110 | float deltaX = ev.getX() - mXDown; |
| 1111 | float absDeltaX = Math.abs(deltaX); |
| 1112 | float absDeltaY = Math.abs(ev.getY() - mYDown); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1113 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1114 | if (Float.compare(absDeltaX, 0f) == 0) return; |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1115 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1116 | float slope = absDeltaY / absDeltaX; |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1117 | float theta = (float) Math.atan(slope); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1118 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1119 | if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) { |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1120 | cancelCurrentPageLongPress(); |
| 1121 | } |
| 1122 | |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1123 | boolean passRightSwipesToCustomContent = |
| 1124 | (mTouchDownTime - mCustomContentShowTime) > CUSTOM_CONTENT_GESTURE_DELAY; |
| 1125 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1126 | boolean swipeInIgnoreDirection = mIsRtl ? deltaX < 0 : deltaX > 0; |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1127 | boolean onCustomContentScreen = |
| 1128 | getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID; |
| 1129 | if (swipeInIgnoreDirection && onCustomContentScreen && passRightSwipesToCustomContent) { |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1130 | // Pass swipes to the right to the custom content page. |
| 1131 | return; |
| 1132 | } |
| 1133 | |
Jan-Willem Maarse | 2ff91c4 | 2014-07-10 15:58:12 -0700 | [diff] [blame] | 1134 | if (onCustomContentScreen && (mCustomContentCallbacks != null) |
| 1135 | && !mCustomContentCallbacks.isScrollingAllowed()) { |
| 1136 | // Don't allow workspace scrolling if the current custom content screen doesn't allow |
| 1137 | // scrolling. |
| 1138 | return; |
| 1139 | } |
| 1140 | |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 1141 | if (theta > MAX_SWIPE_ANGLE) { |
| 1142 | // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace |
| 1143 | return; |
| 1144 | } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) { |
| 1145 | // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to |
| 1146 | // increase the touch slop to make it harder to begin scrolling the workspace. This |
| 1147 | // results in vertically scrolling widgets to more easily. The higher the angle, the |
| 1148 | // more we increase touch slop. |
| 1149 | theta -= START_DAMPING_TOUCH_SLOP_ANGLE; |
| 1150 | float extraRatio = (float) |
| 1151 | Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE))); |
| 1152 | super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio); |
| 1153 | } else { |
| 1154 | // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special |
| 1155 | super.determineScrollingStart(ev); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 1156 | } |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 1159 | protected void onPageBeginMoving() { |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 1160 | super.onPageBeginMoving(); |
| 1161 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1162 | if (isHardwareAccelerated()) { |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1163 | updateChildrenLayersEnabled(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1164 | } else { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1165 | if (mNextPage != INVALID_PAGE) { |
| 1166 | // we're snapping to a particular screen |
| 1167 | enableChildrenCache(mCurrentPage, mNextPage); |
| 1168 | } else { |
| 1169 | // this is when user is actively dragging a particular screen, they might |
| 1170 | // swipe it either left or right (but we won't advance by more than one screen) |
| 1171 | enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1); |
| 1172 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 1176 | protected void onPageEndMoving() { |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 1177 | super.onPageEndMoving(); |
| 1178 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1179 | if (isHardwareAccelerated()) { |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1180 | updateChildrenLayersEnabled(false); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1181 | } else { |
| 1182 | clearChildrenCache(); |
| 1183 | } |
| 1184 | |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 1185 | if (mDragController.isDragging()) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1186 | if (workspaceInModalState()) { |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 1187 | // If we are in springloaded mode, then force an event to check if the current touch |
| 1188 | // is under a new page (to scroll to) |
Winson Chung | 25460a1 | 2013-04-01 18:21:28 -0700 | [diff] [blame] | 1189 | mDragController.forceTouchMove(); |
Winson Chung | 3bc21c3 | 2012-01-20 13:59:18 -0800 | [diff] [blame] | 1190 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 1191 | } |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 1192 | |
| 1193 | if (mDelayedResizeRunnable != null) { |
| 1194 | mDelayedResizeRunnable.run(); |
| 1195 | mDelayedResizeRunnable = null; |
| 1196 | } |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1197 | |
| 1198 | if (mDelayedSnapToPageRunnable != null) { |
| 1199 | mDelayedSnapToPageRunnable.run(); |
| 1200 | mDelayedSnapToPageRunnable = null; |
| 1201 | } |
Adam Cohen | accfd56 | 2013-07-12 14:40:40 -0700 | [diff] [blame] | 1202 | if (mStripScreensOnPageStopMoving) { |
| 1203 | stripEmptyScreens(); |
| 1204 | mStripScreensOnPageStopMoving = false; |
| 1205 | } |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1206 | |
| 1207 | if (mShouldSendPageSettled) { |
| 1208 | mLauncherOverlay.onScrollSettled(); |
| 1209 | mShouldSendPageSettled = false; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | protected void onScrollInteractionBegin() { |
| 1214 | super.onScrollInteractionEnd(); |
| 1215 | mScrollInteractionBegan = true; |
| 1216 | } |
| 1217 | |
| 1218 | protected void onScrollInteractionEnd() { |
| 1219 | super.onScrollInteractionEnd(); |
| 1220 | mScrollInteractionBegan = false; |
| 1221 | if (mStartedSendingScrollEvents) { |
| 1222 | mStartedSendingScrollEvents = false; |
| 1223 | mLauncherOverlay.onScrollInteractionEnd(); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | public void setLauncherOverlay(LauncherOverlay overlay) { |
| 1228 | mLauncherOverlay = overlay; |
| 1229 | } |
| 1230 | |
| 1231 | @Override |
| 1232 | protected void overScroll(float amount) { |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1233 | boolean shouldOverScroll = (amount <= 0 && (!hasCustomContent() || mIsRtl)) || |
| 1234 | (amount >= 0 && (!hasCustomContent() || !mIsRtl)); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1235 | |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1236 | boolean shouldScrollOverlay = mLauncherOverlay != null && |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1237 | ((amount <= 0 && !mIsRtl) || (amount >= 0 && mIsRtl)); |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1238 | |
| 1239 | boolean shouldZeroOverlay = mLauncherOverlay != null && mLastOverlaySroll != 0 && |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1240 | ((amount >= 0 && !mIsRtl) || (amount <= 0 && mIsRtl)); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1241 | |
| 1242 | if (shouldScrollOverlay) { |
| 1243 | if (!mStartedSendingScrollEvents && mScrollInteractionBegan) { |
| 1244 | mStartedSendingScrollEvents = true; |
| 1245 | mLauncherOverlay.onScrollInteractionBegin(); |
| 1246 | mShouldSendPageSettled = true; |
| 1247 | } |
| 1248 | int screenSize = getViewportWidth(); |
| 1249 | float f = (amount / screenSize); |
| 1250 | |
| 1251 | int progress = (int) Math.abs((f * 100)); |
| 1252 | |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1253 | mLastOverlaySroll = progress; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1254 | mLauncherOverlay.onScrollChange(progress, mIsRtl); |
Adam Cohen | c2d6e89 | 2014-10-16 09:49:24 -0700 | [diff] [blame] | 1255 | } else if (shouldOverScroll) { |
| 1256 | dampedOverScroll(amount); |
| 1257 | mOverScrollEffect = acceleratedOverFactor(amount); |
| 1258 | } else { |
| 1259 | mOverScrollEffect = 0; |
| 1260 | } |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1261 | |
| 1262 | if (shouldZeroOverlay) { |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1263 | mLauncherOverlay.onScrollChange(0, mIsRtl); |
Adam Cohen | 8c4ca92 | 2014-10-24 17:40:34 -0700 | [diff] [blame] | 1264 | } |
Adam Cohen | 89cbbb9 | 2013-09-25 16:52:48 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | @Override |
| 1268 | protected void notifyPageSwitchListener() { |
| 1269 | super.notifyPageSwitchListener(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1270 | |
Adam Cohen | 6ad0e7d | 2013-07-24 13:55:41 -0700 | [diff] [blame] | 1271 | if (hasCustomContent() && getNextPage() == 0 && !mCustomContentShowing) { |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1272 | mCustomContentShowing = true; |
| 1273 | if (mCustomContentCallbacks != null) { |
Selim Cinek | 3a8a8f7 | 2014-01-16 10:38:38 -0800 | [diff] [blame] | 1274 | mCustomContentCallbacks.onShow(false); |
Adam Cohen | 3d1b2b4 | 2013-08-14 15:57:58 -0700 | [diff] [blame] | 1275 | mCustomContentShowTime = System.currentTimeMillis(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1276 | } |
Adam Cohen | 6ad0e7d | 2013-07-24 13:55:41 -0700 | [diff] [blame] | 1277 | } else if (hasCustomContent() && getNextPage() != 0 && mCustomContentShowing) { |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1278 | mCustomContentShowing = false; |
| 1279 | if (mCustomContentCallbacks != null) { |
| 1280 | mCustomContentCallbacks.onHide(); |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1281 | } |
| 1282 | } |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1283 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1284 | |
Adam Cohen | 6fecd41 | 2013-10-02 17:41:50 -0700 | [diff] [blame] | 1285 | protected CustomContentCallbacks getCustomContentCallbacks() { |
| 1286 | return mCustomContentCallbacks; |
| 1287 | } |
| 1288 | |
Adam Cohen | 824fcb3 | 2014-05-21 23:01:25 +0000 | [diff] [blame] | 1289 | protected void setWallpaperDimension() { |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1290 | new AsyncTask<Void, Void, Void>() { |
| 1291 | public Void doInBackground(Void ... args) { |
Sunny Goyal | 6a1e95a | 2015-03-20 17:26:30 -0700 | [diff] [blame] | 1292 | String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY; |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1293 | SharedPreferences sp = |
| 1294 | mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS); |
Sunny Goyal | 6a1e95a | 2015-03-20 17:26:30 -0700 | [diff] [blame] | 1295 | WallpaperUtils.suggestWallpaperDimension(mLauncher.getResources(), |
Adam Cohen | ea90f83 | 2014-05-21 15:03:34 -0700 | [diff] [blame] | 1296 | sp, mLauncher.getWindowManager(), mWallpaperManager, |
| 1297 | mLauncher.overrideWallpaperDimensions()); |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1298 | return null; |
| 1299 | } |
| 1300 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 1301 | } |
| 1302 | |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1303 | protected void snapToPage(int whichPage, Runnable r) { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1304 | snapToPage(whichPage, SLOW_PAGE_SNAP_ANIMATION_DURATION, r); |
| 1305 | } |
| 1306 | |
| 1307 | protected void snapToPage(int whichPage, int duration, Runnable r) { |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1308 | if (mDelayedSnapToPageRunnable != null) { |
| 1309 | mDelayedSnapToPageRunnable.run(); |
| 1310 | } |
| 1311 | mDelayedSnapToPageRunnable = r; |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 1312 | snapToPage(whichPage, duration); |
Winson Chung | f0c6ae0 | 2012-03-21 16:10:31 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Adam Cohen | db364c3 | 2014-05-20 14:23:40 -0700 | [diff] [blame] | 1315 | public void snapToScreenId(long screenId) { |
| 1316 | snapToScreenId(screenId, null); |
| 1317 | } |
| 1318 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1319 | protected void snapToScreenId(long screenId, Runnable r) { |
| 1320 | snapToPage(getPageIndexForScreenId(screenId), r); |
| 1321 | } |
| 1322 | |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1323 | class WallpaperOffsetInterpolator implements Choreographer.FrameCallback { |
| 1324 | float mFinalOffset = 0.0f; |
Michael Jurka | 046cf34 | 2013-09-14 16:40:34 +0200 | [diff] [blame] | 1325 | float mCurrentOffset = 0.5f; // to force an initial update |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1326 | boolean mWaitingForUpdate; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1327 | Choreographer mChoreographer; |
| 1328 | Interpolator mInterpolator; |
| 1329 | boolean mAnimating; |
| 1330 | long mAnimationStartTime; |
| 1331 | float mAnimationStartOffset; |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1332 | private final int ANIMATION_DURATION = 250; |
| 1333 | // 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] | 1334 | private final int MIN_PARALLAX_PAGE_SPAN = 3; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1335 | int mNumScreens; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1336 | |
| 1337 | public WallpaperOffsetInterpolator() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1338 | mChoreographer = Choreographer.getInstance(); |
| 1339 | mInterpolator = new DecelerateInterpolator(1.5f); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1340 | } |
| 1341 | |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1342 | @Override |
| 1343 | public void doFrame(long frameTimeNanos) { |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1344 | updateOffset(false); |
| 1345 | } |
| 1346 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1347 | private void updateOffset(boolean force) { |
| 1348 | if (mWaitingForUpdate || force) { |
| 1349 | mWaitingForUpdate = false; |
Michael Jurka | 1bd90b0 | 2013-09-05 23:10:14 +0200 | [diff] [blame] | 1350 | if (computeScrollOffset() && mWindowToken != null) { |
| 1351 | try { |
| 1352 | mWallpaperManager.setWallpaperOffsets(mWindowToken, |
| 1353 | mWallpaperOffset.getCurrX(), 0.5f); |
| 1354 | setWallpaperOffsetSteps(); |
| 1355 | } catch (IllegalArgumentException e) { |
| 1356 | Log.e(TAG, "Error updating wallpaper offset: " + e); |
| 1357 | } |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1358 | } |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1359 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1360 | } |
| 1361 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1362 | public boolean computeScrollOffset() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1363 | final float oldOffset = mCurrentOffset; |
| 1364 | if (mAnimating) { |
| 1365 | long durationSinceAnimation = System.currentTimeMillis() - mAnimationStartTime; |
| 1366 | float t0 = durationSinceAnimation / (float) ANIMATION_DURATION; |
| 1367 | float t1 = mInterpolator.getInterpolation(t0); |
| 1368 | mCurrentOffset = mAnimationStartOffset + |
| 1369 | (mFinalOffset - mAnimationStartOffset) * t1; |
| 1370 | mAnimating = durationSinceAnimation < ANIMATION_DURATION; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1371 | } else { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1372 | mCurrentOffset = mFinalOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1373 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1374 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1375 | if (Math.abs(mCurrentOffset - mFinalOffset) > 0.0000001f) { |
| 1376 | scheduleUpdate(); |
| 1377 | } |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1378 | if (Math.abs(oldOffset - mCurrentOffset) > 0.0000001f) { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1379 | return true; |
| 1380 | } |
| 1381 | return false; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1384 | private float wallpaperOffsetForCurrentScroll() { |
Sunny Goyal | 3fa3c12 | 2015-04-15 13:15:06 -0700 | [diff] [blame] | 1385 | // TODO: do different behavior if it's a live wallpaper? |
| 1386 | // Don't use up all the wallpaper parallax until you have at least |
| 1387 | // MIN_PARALLAX_PAGE_SPAN pages |
| 1388 | int numScrollingPages = getNumScreensExcludingEmptyAndCustom(); |
| 1389 | int parallaxPageSpan; |
| 1390 | if (mWallpaperIsLiveWallpaper) { |
| 1391 | parallaxPageSpan = numScrollingPages - 1; |
| 1392 | } else { |
| 1393 | parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages - 1); |
| 1394 | } |
| 1395 | mNumPagesForWallpaperParallax = parallaxPageSpan; |
| 1396 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1397 | if (getChildCount() <= 1) { |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1398 | if (mIsRtl) { |
Sunny Goyal | 3fa3c12 | 2015-04-15 13:15:06 -0700 | [diff] [blame] | 1399 | return 1 - 1.0f/mNumPagesForWallpaperParallax; |
| 1400 | } |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1401 | return 0; |
| 1402 | } |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1403 | |
| 1404 | // Exclude the leftmost page |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1405 | int emptyExtraPages = numEmptyScreensToIgnore(); |
| 1406 | int firstIndex = numCustomPages(); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1407 | // 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] | 1408 | int lastIndex = getChildCount() - 1 - emptyExtraPages; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1409 | if (mIsRtl) { |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1410 | int temp = firstIndex; |
| 1411 | firstIndex = lastIndex; |
| 1412 | lastIndex = temp; |
| 1413 | } |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1414 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1415 | int firstPageScrollX = getScrollForPage(firstIndex); |
| 1416 | int scrollRange = getScrollForPage(lastIndex) - firstPageScrollX; |
| 1417 | if (scrollRange == 0) { |
| 1418 | return 0; |
| 1419 | } else { |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1420 | // Sometimes the left parameter of the pages is animated during a layout transition; |
| 1421 | // this parameter offsets it to keep the wallpaper from animating as well |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1422 | int adjustedScroll = |
Michael Jurka | 8fd3adc | 2013-10-16 13:50:24 -0700 | [diff] [blame] | 1423 | getScrollX() - firstPageScrollX - getLayoutTransitionOffsetForPage(0); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1424 | float offset = Math.min(1, adjustedScroll / (float) scrollRange); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1425 | offset = Math.max(0, offset); |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 1426 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1427 | // On RTL devices, push the wallpaper offset to the right if we don't have enough |
| 1428 | // pages (ie if numScrollingPages < MIN_PARALLAX_PAGE_SPAN) |
Sunny Goyal | 3fa3c12 | 2015-04-15 13:15:06 -0700 | [diff] [blame] | 1429 | if (!mWallpaperIsLiveWallpaper && numScrollingPages < MIN_PARALLAX_PAGE_SPAN |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1430 | && mIsRtl) { |
Sunny Goyal | 3fa3c12 | 2015-04-15 13:15:06 -0700 | [diff] [blame] | 1431 | return offset * (parallaxPageSpan - numScrollingPages + 1) / parallaxPageSpan; |
| 1432 | } |
| 1433 | return offset * (numScrollingPages - 1) / parallaxPageSpan; |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1437 | private int numEmptyScreensToIgnore() { |
| 1438 | int numScrollingPages = getChildCount() - numCustomPages(); |
| 1439 | if (numScrollingPages >= MIN_PARALLAX_PAGE_SPAN && hasExtraEmptyScreen()) { |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1440 | return 1; |
| 1441 | } else { |
| 1442 | return 0; |
| 1443 | } |
| 1444 | } |
| 1445 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1446 | private int getNumScreensExcludingEmptyAndCustom() { |
| 1447 | int numScrollingPages = getChildCount() - numEmptyScreensToIgnore() - numCustomPages(); |
Michael Jurka | 2f81731 | 2013-09-20 03:03:42 +0200 | [diff] [blame] | 1448 | return numScrollingPages; |
| 1449 | } |
| 1450 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1451 | public void syncWithScroll() { |
| 1452 | float offset = wallpaperOffsetForCurrentScroll(); |
| 1453 | mWallpaperOffset.setFinalX(offset); |
| 1454 | updateOffset(true); |
| 1455 | } |
| 1456 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1457 | public float getCurrX() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1458 | return mCurrentOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | public float getFinalX() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1462 | return mFinalOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1463 | } |
| 1464 | |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1465 | private void animateToFinal() { |
| 1466 | mAnimating = true; |
| 1467 | mAnimationStartOffset = mCurrentOffset; |
| 1468 | mAnimationStartTime = System.currentTimeMillis(); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1469 | } |
| 1470 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1471 | private void setWallpaperOffsetSteps() { |
| 1472 | // Set wallpaper offset steps (1 / (number of screens - 1)) |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 1473 | float xOffset = 1.0f / mNumPagesForWallpaperParallax; |
| 1474 | if (xOffset != mLastSetWallpaperOffsetSteps) { |
| 1475 | mWallpaperManager.setWallpaperOffsetSteps(xOffset, 1.0f); |
| 1476 | mLastSetWallpaperOffsetSteps = xOffset; |
| 1477 | } |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1478 | } |
| 1479 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1480 | public void setFinalX(float x) { |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1481 | scheduleUpdate(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1482 | mFinalOffset = Math.max(0f, Math.min(x, 1.0f)); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1483 | if (getNumScreensExcludingEmptyAndCustom() != mNumScreens) { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1484 | if (mNumScreens > 0) { |
| 1485 | // Don't animate if we're going from 0 screens |
| 1486 | animateToFinal(); |
| 1487 | } |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1488 | mNumScreens = getNumScreensExcludingEmptyAndCustom(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1489 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1490 | } |
| 1491 | |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1492 | private void scheduleUpdate() { |
| 1493 | if (!mWaitingForUpdate) { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1494 | mChoreographer.postFrameCallback(this); |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1495 | mWaitingForUpdate = true; |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1496 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | public void jumpToFinal() { |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1500 | mCurrentOffset = mFinalOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1501 | } |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 1502 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1503 | |
Michael Jurka | 340c5f3 | 2010-10-21 16:49:19 -0700 | [diff] [blame] | 1504 | @Override |
| 1505 | public void computeScroll() { |
| 1506 | super.computeScroll(); |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1507 | mWallpaperOffset.syncWithScroll(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1508 | } |
| 1509 | |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 1510 | @Override |
| 1511 | public void announceForAccessibility(CharSequence text) { |
| 1512 | // Don't announce if apps is on top of us. |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1513 | if (!mLauncher.isAppsViewVisible()) { |
Jason Monk | ed05f09 | 2014-04-24 10:13:05 -0400 | [diff] [blame] | 1514 | super.announceForAccessibility(text); |
| 1515 | } |
| 1516 | } |
| 1517 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 1518 | public void showOutlinesTemporarily() { |
| 1519 | if (!mIsPageMoving && !isTouchActive()) { |
| 1520 | snapToPage(mCurrentPage); |
| 1521 | } |
| 1522 | } |
| 1523 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1524 | float backgroundAlphaInterpolator(float r) { |
| 1525 | float pivotA = 0.1f; |
| 1526 | float pivotB = 0.4f; |
| 1527 | if (r < pivotA) { |
| 1528 | return 0; |
| 1529 | } else if (r > pivotB) { |
| 1530 | return 1.0f; |
| 1531 | } else { |
| 1532 | return (r - pivotA)/(pivotB - pivotA); |
| 1533 | } |
| 1534 | } |
| 1535 | |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1536 | private void updatePageAlphaValues(int screenCenter) { |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1537 | boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX; |
| 1538 | if (mWorkspaceFadeInAdjacentScreens && |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 1539 | !workspaceInModalState() && |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1540 | !mIsSwitchingState && |
| 1541 | !isInOverscroll) { |
Adam Cohen | 84a465a | 2013-11-11 18:49:56 +0000 | [diff] [blame] | 1542 | for (int i = numCustomPages(); i < getChildCount(); i++) { |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1543 | CellLayout child = (CellLayout) getChildAt(i); |
| 1544 | if (child != null) { |
| 1545 | float scrollProgress = getScrollProgress(screenCenter, child, i); |
Adam Cohen | 7389496 | 2011-10-31 13:17:17 -0700 | [diff] [blame] | 1546 | float alpha = 1 - Math.abs(scrollProgress); |
Michael Jurka | 869390b | 2012-05-06 15:55:19 -0700 | [diff] [blame] | 1547 | child.getShortcutsAndWidgets().setAlpha(alpha); |
Adam Cohen | 7389496 | 2011-10-31 13:17:17 -0700 | [diff] [blame] | 1548 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1549 | } |
| 1550 | } |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 1553 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 1554 | @Override |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 1555 | public void enableAccessibleDrag(boolean enable) { |
| 1556 | for (int i = 0; i < getChildCount(); i++) { |
| 1557 | CellLayout child = (CellLayout) getChildAt(i); |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 1558 | child.enableAccessibleDrag(enable, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | if (enable) { |
| 1562 | // We need to allow our individual children to become click handlers in this case |
| 1563 | setOnClickListener(null); |
| 1564 | } else { |
| 1565 | // Reset our click listener |
| 1566 | setOnClickListener(mLauncher); |
| 1567 | } |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 1568 | mLauncher.getSearchBar().enableAccessibleDrag(enable); |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 1569 | mLauncher.getHotseat().getLayout() |
| 1570 | .enableAccessibleDrag(enable, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 1571 | } |
| 1572 | |
Winson Chung | 98ca0f7 | 2013-07-29 12:58:51 -0700 | [diff] [blame] | 1573 | public boolean hasCustomContent() { |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1574 | return (mScreenOrder.size() > 0 && mScreenOrder.get(0) == CUSTOM_CONTENT_SCREEN_ID); |
| 1575 | } |
| 1576 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1577 | public int numCustomPages() { |
| 1578 | return hasCustomContent() ? 1 : 0; |
| 1579 | } |
| 1580 | |
Adam Cohen | bffe745 | 2013-07-22 18:21:45 -0700 | [diff] [blame] | 1581 | public boolean isOnOrMovingToCustomContent() { |
| 1582 | return hasCustomContent() && getNextPage() == 0; |
| 1583 | } |
| 1584 | |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1585 | private void updateStateForCustomContent(int screenCenter) { |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1586 | float translationX = 0; |
| 1587 | float progress = 0; |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 1588 | if (hasCustomContent()) { |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1589 | int index = mScreenOrder.indexOf(CUSTOM_CONTENT_SCREEN_ID); |
Adam Cohen | 564a2e7 | 2013-10-09 14:47:32 -0700 | [diff] [blame] | 1590 | |
Adam Cohen | a45de07 | 2013-10-11 16:07:47 -0700 | [diff] [blame] | 1591 | int scrollDelta = getScrollX() - getScrollForPage(index) - |
| 1592 | getLayoutTransitionOffsetForPage(index); |
| 1593 | float scrollRange = getScrollForPage(index + 1) - getScrollForPage(index); |
| 1594 | translationX = scrollRange - scrollDelta; |
| 1595 | progress = (scrollRange - scrollDelta) / scrollRange; |
Adam Cohen | af9b0e5 | 2013-09-23 19:27:38 -0700 | [diff] [blame] | 1596 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1597 | if (mIsRtl) { |
Adam Cohen | af9b0e5 | 2013-09-23 19:27:38 -0700 | [diff] [blame] | 1598 | translationX = Math.min(0, translationX); |
| 1599 | } else { |
| 1600 | translationX = Math.max(0, translationX); |
| 1601 | } |
Adam Cohen | 955806d | 2013-07-19 16:36:43 -0700 | [diff] [blame] | 1602 | progress = Math.max(0, progress); |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1603 | } |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1604 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1605 | if (Float.compare(progress, mLastCustomContentScrollProgress) == 0) return; |
Adam Cohen | 84add1d | 2013-10-14 16:29:02 -0700 | [diff] [blame] | 1606 | |
| 1607 | CellLayout cc = mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID); |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1608 | if (progress > 0 && cc.getVisibility() != VISIBLE && !workspaceInModalState()) { |
Adam Cohen | 84add1d | 2013-10-14 16:29:02 -0700 | [diff] [blame] | 1609 | cc.setVisibility(VISIBLE); |
| 1610 | } |
| 1611 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1612 | mLastCustomContentScrollProgress = progress; |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1613 | |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 1614 | // We should only update the drag layer background alpha if we are not in all apps or the |
| 1615 | // widgets tray |
| 1616 | if (mState == State.NORMAL) { |
| 1617 | mLauncher.getDragLayer().setBackgroundAlpha(progress * 0.8f); |
| 1618 | } |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 1619 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1620 | if (mLauncher.getHotseat() != null) { |
| 1621 | mLauncher.getHotseat().setTranslationX(translationX); |
| 1622 | } |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1623 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1624 | if (getPageIndicator() != null) { |
| 1625 | getPageIndicator().setTranslationX(translationX); |
| 1626 | } |
Adam Cohen | c36fa5c | 2013-08-29 11:54:42 -0700 | [diff] [blame] | 1627 | |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 1628 | if (mCustomContentCallbacks != null) { |
| 1629 | mCustomContentCallbacks.onScrollProgressChanged(progress); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1633 | @Override |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1634 | protected OnClickListener getPageIndicatorClickListener() { |
| 1635 | AccessibilityManager am = (AccessibilityManager) |
| 1636 | getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 1637 | if (!am.isTouchExplorationEnabled()) { |
| 1638 | return null; |
| 1639 | } |
| 1640 | OnClickListener listener = new OnClickListener() { |
| 1641 | @Override |
| 1642 | public void onClick(View arg0) { |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 1643 | mLauncher.showOverviewMode(true); |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1644 | } |
| 1645 | }; |
| 1646 | return listener; |
| 1647 | } |
| 1648 | |
| 1649 | @Override |
Michael Jurka | a3d30ad | 2012-05-08 13:43:43 -0700 | [diff] [blame] | 1650 | protected void screenScrolled(int screenCenter) { |
| 1651 | super.screenScrolled(screenCenter); |
| 1652 | |
| 1653 | updatePageAlphaValues(screenCenter); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 1654 | updateStateForCustomContent(screenCenter); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1655 | enableHwLayersOnVisiblePages(); |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1656 | |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 1657 | boolean shouldOverScroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX; |
Adam Cohen | af9b0e5 | 2013-09-23 19:27:38 -0700 | [diff] [blame] | 1658 | |
| 1659 | if (shouldOverScroll) { |
Winson Chung | 52aee60 | 2013-01-30 12:01:02 -0800 | [diff] [blame] | 1660 | int index = 0; |
Winson Chung | 52aee60 | 2013-01-30 12:01:02 -0800 | [diff] [blame] | 1661 | final int lowerIndex = 0; |
| 1662 | final int upperIndex = getChildCount() - 1; |
Adam Cohen | a29f504 | 2013-09-26 14:29:35 -0700 | [diff] [blame] | 1663 | |
| 1664 | final boolean isLeftPage = mOverScrollX < 0; |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 1665 | index = (!mIsRtl && isLeftPage) || (mIsRtl && !isLeftPage) ? lowerIndex : upperIndex; |
Winson Chung | 52aee60 | 2013-01-30 12:01:02 -0800 | [diff] [blame] | 1666 | |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1667 | CellLayout cl = (CellLayout) getChildAt(index); |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 1668 | float effect = Math.abs(mOverScrollEffect); |
| 1669 | cl.setOverScrollAmount(Math.abs(effect), isLeftPage); |
Adam Cohen | a29f504 | 2013-09-26 14:29:35 -0700 | [diff] [blame] | 1670 | |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 1671 | mOverscrollEffectSet = true; |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1672 | } else { |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 1673 | if (mOverscrollEffectSet && getChildCount() > 0) { |
| 1674 | mOverscrollEffectSet = false; |
| 1675 | ((CellLayout) getChildAt(0)).setOverScrollAmount(0, false); |
| 1676 | ((CellLayout) getChildAt(getChildCount() - 1)).setOverScrollAmount(0, false); |
Adam Cohen | 7842d7f | 2011-09-12 15:28:15 -0700 | [diff] [blame] | 1677 | } |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1678 | } |
| 1679 | } |
| 1680 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1681 | protected void onAttachedToWindow() { |
| 1682 | super.onAttachedToWindow(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1683 | mWindowToken = getWindowToken(); |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 1684 | computeScroll(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1685 | mDragController.setWindowToken(mWindowToken); |
| 1686 | } |
| 1687 | |
| 1688 | protected void onDetachedFromWindow() { |
Romain Guy | e666195 | 2013-08-08 19:13:22 -0700 | [diff] [blame] | 1689 | super.onDetachedFromWindow(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1690 | mWindowToken = null; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1691 | } |
| 1692 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1693 | protected void onResume() { |
| 1694 | if (getPageIndicator() != null) { |
| 1695 | // In case accessibility state has changed, we need to perform this on every |
| 1696 | // attach to window |
Adam Cohen | d36d947 | 2013-10-10 15:32:41 -0700 | [diff] [blame] | 1697 | OnClickListener listener = getPageIndicatorClickListener(); |
| 1698 | if (listener != null) { |
| 1699 | getPageIndicator().setOnClickListener(listener); |
| 1700 | } |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1701 | } |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1702 | |
| 1703 | // Update wallpaper dimensions if they were changed since last onResume |
| 1704 | // (we also always set the wallpaper dimensions in the constructor) |
| 1705 | if (LauncherAppState.getInstance().hasWallpaperChangedSinceLastCheck()) { |
Adam Cohen | 824fcb3 | 2014-05-21 23:01:25 +0000 | [diff] [blame] | 1706 | setWallpaperDimension(); |
Michael Jurka | a6a0547 | 2013-11-13 17:59:46 +0100 | [diff] [blame] | 1707 | } |
Michael Jurka | 2a4f492 | 2014-01-29 16:32:39 +0100 | [diff] [blame] | 1708 | mWallpaperIsLiveWallpaper = mWallpaperManager.getWallpaperInfo() != null; |
| 1709 | // Force the wallpaper offset steps to be set again, because another app might have changed |
| 1710 | // them |
| 1711 | mLastSetWallpaperOffsetSteps = 0f; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1714 | @Override |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 1715 | 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] | 1716 | if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) { |
Michael Jurka | fe09cb7 | 2013-08-27 15:48:58 +0200 | [diff] [blame] | 1717 | mWallpaperOffset.syncWithScroll(); |
Michael Jurka | cc07e7a | 2013-08-26 20:56:35 +0200 | [diff] [blame] | 1718 | mWallpaperOffset.jumpToFinal(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 1719 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1720 | super.onLayout(changed, left, top, right, bottom); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | @Override |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1724 | protected void onDraw(Canvas canvas) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1725 | super.onDraw(canvas); |
Winson Chung | b8b2a5a | 2012-07-12 17:55:31 -0700 | [diff] [blame] | 1726 | |
| 1727 | // Call back to LauncherModel to finish binding after the first draw |
Romain Guy | eeacd56 | 2012-10-10 18:47:33 -0700 | [diff] [blame] | 1728 | post(mBindPages); |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1729 | } |
| 1730 | |
Michael Jurka | dfab7f0 | 2011-11-18 13:01:04 -0800 | [diff] [blame] | 1731 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1732 | protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1733 | if (!mLauncher.isAppsViewVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1734 | final Folder openFolder = getOpenFolder(); |
| 1735 | if (openFolder != null) { |
| 1736 | return openFolder.requestFocus(direction, previouslyFocusedRect); |
| 1737 | } else { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1738 | return super.onRequestFocusInDescendants(direction, previouslyFocusedRect); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | return false; |
| 1742 | } |
| 1743 | |
| 1744 | @Override |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1745 | public int getDescendantFocusability() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1746 | if (workspaceInModalState()) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1747 | return ViewGroup.FOCUS_BLOCK_DESCENDANTS; |
| 1748 | } |
| 1749 | return super.getDescendantFocusability(); |
| 1750 | } |
| 1751 | |
| 1752 | @Override |
Romain Guy | c2e24c0 | 2009-06-01 16:11:41 -0700 | [diff] [blame] | 1753 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1754 | if (!mLauncher.isAppsViewVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1755 | final Folder openFolder = getOpenFolder(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1756 | if (openFolder != null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1757 | openFolder.addFocusables(views, direction); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1758 | } else { |
| 1759 | super.addFocusables(views, direction, focusableMode); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1764 | public boolean workspaceInModalState() { |
| 1765 | return mState != State.NORMAL; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1768 | void enableChildrenCache(int fromPage, int toPage) { |
| 1769 | if (fromPage > toPage) { |
| 1770 | final int temp = fromPage; |
| 1771 | fromPage = toPage; |
| 1772 | toPage = temp; |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 1773 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1774 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1775 | final int screenCount = getChildCount(); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1776 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1777 | fromPage = Math.max(fromPage, 0); |
| 1778 | toPage = Math.min(toPage, screenCount - 1); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1779 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1780 | for (int i = fromPage; i <= toPage; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1781 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1782 | layout.setChildrenDrawnWithCacheEnabled(true); |
| 1783 | layout.setChildrenDrawingCacheEnabled(true); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | void clearChildrenCache() { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1788 | final int screenCount = getChildCount(); |
| 1789 | for (int i = 0; i < screenCount; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1790 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1791 | layout.setChildrenDrawnWithCacheEnabled(false); |
Adam Cohen | 8182e5b | 2011-08-01 15:43:31 -0700 | [diff] [blame] | 1792 | // In software mode, we don't want the items to continue to be drawn into bitmaps |
| 1793 | if (!isHardwareAccelerated()) { |
| 1794 | layout.setChildrenDrawingCacheEnabled(false); |
| 1795 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 1799 | @Thunk void updateChildrenLayersEnabled(boolean force) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1800 | boolean small = mState == State.OVERVIEW || mIsSwitchingState; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1801 | boolean enableChildrenLayers = force || small || mAnimatingViewIntoPlace || isPageMoving(); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1802 | |
| 1803 | if (enableChildrenLayers != mChildrenLayersEnabled) { |
| 1804 | mChildrenLayersEnabled = enableChildrenLayers; |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1805 | if (mChildrenLayersEnabled) { |
| 1806 | enableHwLayersOnVisiblePages(); |
| 1807 | } else { |
| 1808 | for (int i = 0; i < getPageCount(); i++) { |
| 1809 | final CellLayout cl = (CellLayout) getChildAt(i); |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1810 | cl.enableHardwareLayer(false); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | private void enableHwLayersOnVisiblePages() { |
| 1817 | if (mChildrenLayersEnabled) { |
| 1818 | final int screenCount = getChildCount(); |
| 1819 | getVisiblePages(mTempVisiblePagesRange); |
| 1820 | int leftScreen = mTempVisiblePagesRange[0]; |
| 1821 | int rightScreen = mTempVisiblePagesRange[1]; |
| 1822 | if (leftScreen == rightScreen) { |
| 1823 | // make sure we're caching at least two pages always |
| 1824 | if (rightScreen < screenCount - 1) { |
| 1825 | rightScreen++; |
| 1826 | } else if (leftScreen > 0) { |
| 1827 | leftScreen--; |
| 1828 | } |
| 1829 | } |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1830 | |
| 1831 | final CellLayout customScreen = mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1832 | for (int i = 0; i < screenCount; i++) { |
Michael Jurka | 47639b9 | 2013-01-14 12:42:27 +0100 | [diff] [blame] | 1833 | final CellLayout layout = (CellLayout) getPageAt(i); |
Chris Craik | 01f2d7f | 2013-10-01 14:41:56 -0700 | [diff] [blame] | 1834 | |
| 1835 | // enable layers between left and right screen inclusive, except for the |
| 1836 | // customScreen, which may animate its content during transitions. |
| 1837 | boolean enableLayer = layout != customScreen && |
| 1838 | leftScreen <= i && i <= rightScreen && shouldDrawChild(layout); |
| 1839 | layout.enableHardwareLayer(enableLayer); |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 1840 | } |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1841 | } |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1842 | } |
| 1843 | |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1844 | public void buildPageHardwareLayers() { |
| 1845 | // force layers to be enabled just for the call to buildLayer |
| 1846 | updateChildrenLayersEnabled(true); |
| 1847 | if (getWindowToken() != null) { |
| 1848 | final int childCount = getChildCount(); |
| 1849 | for (int i = 0; i < childCount; i++) { |
| 1850 | CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | d51f33a | 2012-06-28 15:35:26 -0700 | [diff] [blame] | 1851 | cl.buildHardwareLayer(); |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | updateChildrenLayersEnabled(false); |
| 1855 | } |
| 1856 | |
Jeff Brown | 1d0867c | 2010-12-02 18:27:39 -0800 | [diff] [blame] | 1857 | protected void onWallpaperTap(MotionEvent ev) { |
| 1858 | final int[] position = mTempCell; |
| 1859 | getLocationOnScreen(position); |
| 1860 | |
| 1861 | int pointerIndex = ev.getActionIndex(); |
| 1862 | position[0] += (int) ev.getX(pointerIndex); |
| 1863 | position[1] += (int) ev.getY(pointerIndex); |
| 1864 | |
| 1865 | mWallpaperManager.sendWallpaperCommand(getWindowToken(), |
| 1866 | ev.getAction() == MotionEvent.ACTION_UP |
| 1867 | ? WallpaperManager.COMMAND_TAP : WallpaperManager.COMMAND_SECONDARY_TAP, |
| 1868 | position[0], position[1], 0, null); |
| 1869 | } |
| 1870 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1871 | /* |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 1872 | * |
| 1873 | * We call these methods (onDragStartedWithItemSpans/onDragStartedWithSize) whenever we |
| 1874 | * start a drag in Launcher, regardless of whether the drag has ever entered the Workspace |
| 1875 | * |
| 1876 | * These methods mark the appropriate pages as accepting drops (which alters their visual |
| 1877 | * appearance). |
| 1878 | * |
| 1879 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 1880 | private static Rect getDrawableBounds(Drawable d) { |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 1881 | Rect bounds = new Rect(); |
| 1882 | d.copyBounds(bounds); |
| 1883 | if (bounds.width() == 0 || bounds.height() == 0) { |
| 1884 | bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 1885 | } else { |
| 1886 | bounds.offsetTo(0, 0); |
| 1887 | } |
| 1888 | if (d instanceof PreloadIconDrawable) { |
| 1889 | int inset = -((PreloadIconDrawable) d).getOutset(); |
| 1890 | bounds.inset(inset, inset); |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 1891 | } |
| 1892 | return bounds; |
| 1893 | } |
| 1894 | |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 1895 | public void onExternalDragStartedWithItem(View v) { |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 1896 | // Compose a drag bitmap with the view scaled to the icon size |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 1897 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 1898 | int iconSize = grid.iconSizePx; |
| 1899 | int bmpWidth = v.getMeasuredWidth(); |
| 1900 | int bmpHeight = v.getMeasuredHeight(); |
| 1901 | |
| 1902 | // If this is a text view, use its drawable instead |
| 1903 | if (v instanceof TextView) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1904 | Drawable d = getTextViewIcon((TextView) v); |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 1905 | Rect bounds = getDrawableBounds(d); |
| 1906 | bmpWidth = bounds.width(); |
| 1907 | bmpHeight = bounds.height(); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | // Compose the bitmap to create the icon from |
| 1911 | Bitmap b = Bitmap.createBitmap(bmpWidth, bmpHeight, |
| 1912 | Bitmap.Config.ARGB_8888); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 1913 | mCanvas.setBitmap(b); |
| 1914 | drawDragView(v, mCanvas, 0); |
| 1915 | mCanvas.setBitmap(null); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 1916 | |
| 1917 | // 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] | 1918 | mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, iconSize, iconSize, true); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 1921 | public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) { |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 1922 | int[] size = estimateItemSize(info, false); |
Adam Cohen | 6639687 | 2011-04-15 17:50:36 -0700 | [diff] [blame] | 1923 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1924 | // 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] | 1925 | mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, size[0], size[1], clipAlpha); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1928 | public void exitWidgetResizeMode() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 1929 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 1930 | dragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1931 | } |
| 1932 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1933 | @Override |
Adam Cohen | 6f127a6 | 2014-06-12 14:54:41 -0700 | [diff] [blame] | 1934 | protected void getFreeScrollPageRange(int[] range) { |
| 1935 | getOverviewModePages(range); |
| 1936 | } |
| 1937 | |
| 1938 | private void getOverviewModePages(int[] range) { |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 1939 | int start = numCustomPages(); |
Adam Cohen | 1003be9 | 2013-09-16 14:09:28 -0700 | [diff] [blame] | 1940 | int end = getChildCount() - 1; |
| 1941 | |
| 1942 | range[0] = Math.max(0, Math.min(start, getChildCount() - 1)); |
| 1943 | range[1] = Math.max(0, end); |
Adam Cohen | 6f127a6 | 2014-06-12 14:54:41 -0700 | [diff] [blame] | 1944 | } |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1945 | |
Sunny Goyal | 1d08f70 | 2015-05-04 15:50:25 -0700 | [diff] [blame] | 1946 | public void onStartReordering() { |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1947 | super.onStartReordering(); |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 1948 | // Reordering handles its own animations, disable the automatic ones. |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 1949 | disableLayoutTransitions(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
Sunny Goyal | 1d08f70 | 2015-05-04 15:50:25 -0700 | [diff] [blame] | 1952 | public void onEndReordering() { |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1953 | super.onEndReordering(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1954 | |
Adam Cohen | dcb173d | 2014-04-01 13:33:58 -0700 | [diff] [blame] | 1955 | if (mLauncher.isWorkspaceLoading()) { |
| 1956 | // Invalid and dangerous operation if workspace is loading |
| 1957 | return; |
| 1958 | } |
| 1959 | |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1960 | mScreenOrder.clear(); |
Adam Cohen | 2bf63d5 | 2013-09-29 17:46:49 -0700 | [diff] [blame] | 1961 | int count = getChildCount(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1962 | for (int i = 0; i < count; i++) { |
| 1963 | CellLayout cl = ((CellLayout) getChildAt(i)); |
| 1964 | mScreenOrder.add(getIdForScreen(cl)); |
| 1965 | } |
Winson Chung | d64d176 | 2013-08-20 14:37:16 -0700 | [diff] [blame] | 1966 | |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1967 | mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); |
Adam Cohen | 22cba7f | 2013-07-19 16:14:00 -0700 | [diff] [blame] | 1968 | |
| 1969 | // Re-enable auto layout transitions for page deletion. |
Winson Chung | 964df6b | 2013-10-11 15:55:37 -0700 | [diff] [blame] | 1970 | enableLayoutTransitions(); |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Adam Cohen | f358a4b | 2013-07-23 16:47:31 -0700 | [diff] [blame] | 1973 | public boolean isInOverviewMode() { |
| 1974 | return mState == State.OVERVIEW; |
| 1975 | } |
| 1976 | |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 1977 | int getOverviewModeTranslationY() { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 1978 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 1979 | Rect overviewBar = grid.getOverviewModeButtonBarRect(); |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 1980 | |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 1981 | int availableHeight = getViewportHeight(); |
| 1982 | int scaledHeight = (int) (mOverviewModeShrinkFactor * getNormalChildHeight()); |
| 1983 | int offsetFromTopEdge = (availableHeight - scaledHeight) / 2; |
| 1984 | int offsetToCenterInOverview = (availableHeight - mInsets.top - overviewBar.height() |
| 1985 | - scaledHeight) / 2; |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 1986 | |
Winson Chung | c82d262 | 2013-11-06 13:23:29 -0800 | [diff] [blame] | 1987 | return -offsetFromTopEdge + mInsets.top + offsetToCenterInOverview; |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 1990 | /** |
| 1991 | * Sets the current workspace {@link State}, returning an animation transitioning the workspace |
| 1992 | * to that new state. |
| 1993 | */ |
| 1994 | public Animator setStateWithAnimation(State toState, int toPage, boolean animated, |
| 1995 | HashMap<View, Integer> layerViews) { |
| 1996 | // Create the animation to the new state |
| 1997 | Animator workspaceAnim = mStateTransitionAnimation.getAnimationToState(getState(), |
| 1998 | toState, toPage, animated, layerViews); |
| 1999 | |
| 2000 | // Update the current state |
| 2001 | mState = toState; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 2002 | updateAccessibilityFlags(); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2003 | |
| 2004 | return workspaceAnim; |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
Adam Cohen | e25c5d1 | 2014-06-18 10:34:58 -0700 | [diff] [blame] | 2007 | State getState() { |
| 2008 | return mState; |
| 2009 | } |
| 2010 | |
Sunny Goyal | 1d08f70 | 2015-05-04 15:50:25 -0700 | [diff] [blame] | 2011 | public void updateAccessibilityFlags() { |
| 2012 | if (Utilities.isLmpOrAbove()) { |
| 2013 | int total = getPageCount(); |
| 2014 | for (int i = numCustomPages(); i < total; i++) { |
| 2015 | updateAccessibilityFlags((CellLayout) getPageAt(i), i); |
| 2016 | } |
| 2017 | if (mState == State.NORMAL) { |
| 2018 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
| 2019 | } else { |
| 2020 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 2021 | } |
| 2022 | } else { |
| 2023 | int accessible = mState == State.NORMAL ? |
| 2024 | IMPORTANT_FOR_ACCESSIBILITY_NO : |
| 2025 | IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS; |
| 2026 | setImportantForAccessibility(accessible); |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | private void updateAccessibilityFlags(CellLayout page, int pageNo) { |
| 2031 | if (mState == State.OVERVIEW) { |
| 2032 | page.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 2033 | page.getShortcutsAndWidgets().setImportantForAccessibility( |
| 2034 | IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); |
| 2035 | page.setContentDescription(getPageDescription(pageNo)); |
| 2036 | |
| 2037 | if (mPagesAccessibilityDelegate == null) { |
| 2038 | mPagesAccessibilityDelegate = new OverviewScreenAccessibilityDelegate(this); |
| 2039 | } |
| 2040 | page.setAccessibilityDelegate(mPagesAccessibilityDelegate); |
| 2041 | } else { |
| 2042 | int accessible = mState == State.NORMAL ? |
| 2043 | IMPORTANT_FOR_ACCESSIBILITY_NO : |
| 2044 | IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS; |
| 2045 | page.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
| 2046 | page.getShortcutsAndWidgets().setImportantForAccessibility(accessible); |
| 2047 | page.setContentDescription(null); |
| 2048 | page.setAccessibilityDelegate(null); |
| 2049 | } |
Adam Cohen | edaaa30 | 2013-10-01 17:33:27 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2052 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 2053 | public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) { |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2054 | mIsSwitchingState = true; |
| 2055 | |
| 2056 | // Invalidate here to ensure that the pages are rendered during the state change transition. |
| 2057 | invalidate(); |
| 2058 | |
| 2059 | updateChildrenLayersEnabled(false); |
| 2060 | hideCustomContentIfNecessary(); |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 2064 | public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { |
| 2065 | } |
| 2066 | |
| 2067 | @Override |
Winson Chung | 7044272 | 2012-02-10 15:43:22 -0800 | [diff] [blame] | 2068 | public void onLauncherTransitionStep(Launcher l, float t) { |
| 2069 | mTransitionProgress = t; |
| 2070 | } |
| 2071 | |
| 2072 | @Override |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2073 | public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2074 | mIsSwitchingState = false; |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2075 | updateChildrenLayersEnabled(false); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2076 | showCustomContentIfNecessary(); |
Adam Cohen | 3f452c8 | 2013-09-19 11:57:17 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | void updateCustomContentVisibility() { |
| 2080 | int visibility = mState == Workspace.State.NORMAL ? VISIBLE : INVISIBLE; |
| 2081 | if (hasCustomContent()) { |
| 2082 | mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(visibility); |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | void showCustomContentIfNecessary() { |
| 2087 | boolean show = mState == Workspace.State.NORMAL; |
| 2088 | if (show && hasCustomContent()) { |
| 2089 | mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(VISIBLE); |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | void hideCustomContentIfNecessary() { |
| 2094 | boolean hide = mState != Workspace.State.NORMAL; |
| 2095 | if (hide && hasCustomContent()) { |
Adam Cohen | 1774a8a | 2013-11-15 10:56:16 +0000 | [diff] [blame] | 2096 | disableLayoutTransitions(); |
Adam Cohen | 3f452c8 | 2013-09-19 11:57:17 -0700 | [diff] [blame] | 2097 | mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(INVISIBLE); |
Adam Cohen | 1774a8a | 2013-11-15 10:56:16 +0000 | [diff] [blame] | 2098 | enableLayoutTransitions(); |
Adam Cohen | f343499 | 2013-09-16 16:52:59 -0700 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | |
Michael Jurka | bed61d2 | 2012-02-14 22:51:29 -0800 | [diff] [blame] | 2102 | @Override |
| 2103 | public View getContent() { |
| 2104 | return this; |
| 2105 | } |
| 2106 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2107 | /** |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2108 | * Returns the drawable for the given text view. |
| 2109 | */ |
| 2110 | public static Drawable getTextViewIcon(TextView tv) { |
| 2111 | final Drawable[] drawables = tv.getCompoundDrawables(); |
| 2112 | for (int i = 0; i < drawables.length; i++) { |
| 2113 | if (drawables[i] != null) { |
| 2114 | return drawables[i]; |
| 2115 | } |
| 2116 | } |
| 2117 | return null; |
| 2118 | } |
| 2119 | |
| 2120 | /** |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2121 | * Draw the View v into the given Canvas. |
| 2122 | * |
| 2123 | * @param v the view to draw |
| 2124 | * @param destCanvas the canvas to draw on |
| 2125 | * @param padding the horizontal and vertical padding to use when drawing |
| 2126 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2127 | private static void drawDragView(View v, Canvas destCanvas, int padding) { |
| 2128 | final Rect clipRect = sTempRect; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2129 | v.getDrawingRect(clipRect); |
| 2130 | |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 2131 | boolean textVisible = false; |
| 2132 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2133 | destCanvas.save(); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2134 | if (v instanceof TextView) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2135 | Drawable d = getTextViewIcon((TextView) v); |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 2136 | Rect bounds = getDrawableBounds(d); |
| 2137 | clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2138 | destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2139 | d.draw(destCanvas); |
| 2140 | } else { |
| 2141 | if (v instanceof FolderIcon) { |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 2142 | // For FolderIcons the text can bleed into the icon area, and so we need to |
| 2143 | // hide the text completely (which can't be achieved by clipping). |
| 2144 | if (((FolderIcon) v).getTextVisible()) { |
| 2145 | ((FolderIcon) v).setTextVisible(false); |
| 2146 | textVisible = true; |
| 2147 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2148 | } |
| 2149 | destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); |
| 2150 | destCanvas.clipRect(clipRect, Op.REPLACE); |
| 2151 | v.draw(destCanvas); |
Adam Cohen | 099f60d | 2011-08-23 21:07:26 -0700 | [diff] [blame] | 2152 | |
| 2153 | // Restore text visibility of FolderIcon if necessary |
| 2154 | if (textVisible) { |
| 2155 | ((FolderIcon) v).setTextVisible(true); |
| 2156 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2157 | } |
| 2158 | destCanvas.restore(); |
| 2159 | } |
| 2160 | |
| 2161 | /** |
| 2162 | * Returns a new bitmap to show when the given View is being dragged around. |
| 2163 | * Responsibility for the bitmap is transferred to the caller. |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2164 | * @param expectedPadding padding to add to the drag view. If a different padding was used |
| 2165 | * its value will be changed |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2166 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2167 | public Bitmap createDragBitmap(View v, AtomicInteger expectedPadding) { |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2168 | Bitmap b; |
| 2169 | |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2170 | int padding = expectedPadding.get(); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2171 | if (v instanceof TextView) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2172 | Drawable d = getTextViewIcon((TextView) v); |
Mathew Inwood | 8590029 | 2014-04-16 14:17:39 +0100 | [diff] [blame] | 2173 | Rect bounds = getDrawableBounds(d); |
| 2174 | b = Bitmap.createBitmap(bounds.width() + padding, |
| 2175 | bounds.height() + padding, Bitmap.Config.ARGB_8888); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2176 | expectedPadding.set(padding - bounds.left - bounds.top); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2177 | } else { |
| 2178 | b = Bitmap.createBitmap( |
| 2179 | v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2182 | mCanvas.setBitmap(b); |
| 2183 | drawDragView(v, mCanvas, padding); |
| 2184 | mCanvas.setBitmap(null); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2185 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2186 | return b; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | /** |
| 2190 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 2191 | * Responsibility for the bitmap is transferred to the caller. |
| 2192 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2193 | private Bitmap createDragOutline(View v, int padding) { |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2194 | final int outlineColor = getResources().getColor(R.color.outline_color); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2195 | final Bitmap b = Bitmap.createBitmap( |
| 2196 | v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); |
| 2197 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2198 | mCanvas.setBitmap(b); |
| 2199 | drawDragView(v, mCanvas, padding); |
| 2200 | mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor); |
| 2201 | mCanvas.setBitmap(null); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2202 | return b; |
| 2203 | } |
| 2204 | |
| 2205 | /** |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2206 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 2207 | * Responsibility for the bitmap is transferred to the caller. |
| 2208 | */ |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2209 | private Bitmap createDragOutline(Bitmap orig, int padding, int w, int h, |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2210 | boolean clipAlpha) { |
Adam Cohen | 410f3cd | 2013-09-22 12:09:32 -0700 | [diff] [blame] | 2211 | final int outlineColor = getResources().getColor(R.color.outline_color); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2212 | final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2213 | mCanvas.setBitmap(b); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2214 | |
| 2215 | Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight()); |
| 2216 | float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(), |
| 2217 | (h - padding) / (float) orig.getHeight()); |
| 2218 | int scaledWidth = (int) (scaleFactor * orig.getWidth()); |
| 2219 | int scaledHeight = (int) (scaleFactor * orig.getHeight()); |
| 2220 | Rect dst = new Rect(0, 0, scaledWidth, scaledHeight); |
| 2221 | |
| 2222 | // center the image |
| 2223 | dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2); |
| 2224 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2225 | mCanvas.drawBitmap(orig, src, dst, null); |
| 2226 | mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor, |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 2227 | clipAlpha); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2228 | mCanvas.setBitmap(null); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2229 | |
| 2230 | return b; |
| 2231 | } |
| 2232 | |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2233 | public void startDrag(CellLayout.CellInfo cellInfo) { |
| 2234 | startDrag(cellInfo, false); |
| 2235 | } |
| 2236 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 2237 | @Override |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2238 | public void startDrag(CellLayout.CellInfo cellInfo, boolean accessible) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2239 | View child = cellInfo.cell; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2240 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2241 | // 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] | 2242 | if (!child.isInTouchMode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2243 | return; |
| 2244 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2245 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2246 | mDragInfo = cellInfo; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2247 | child.setVisibility(INVISIBLE); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2248 | CellLayout layout = (CellLayout) child.getParent().getParent(); |
| 2249 | layout.prepareChildForDrag(child); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2250 | |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2251 | beginDragShared(child, this, accessible); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2254 | public void beginDragShared(View child, DragSource source, boolean accessible) { |
| 2255 | beginDragShared(child, new Point(), source, accessible); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2256 | } |
| 2257 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2258 | public void beginDragShared(View child, Point relativeTouchPos, DragSource source, |
| 2259 | boolean accessible) { |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2260 | child.clearFocus(); |
| 2261 | child.setPressed(false); |
| 2262 | |
| 2263 | // The outline is used to visualize where the item will land if dropped |
| 2264 | mDragOutline = createDragOutline(child, DRAG_BITMAP_PADDING); |
| 2265 | |
Anjali Koppal | 62d18ed | 2014-03-10 17:04:03 -0700 | [diff] [blame] | 2266 | mLauncher.onDragStarted(child); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2267 | // The drag bitmap follows the touch point around on the screen |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2268 | AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2269 | final Bitmap b = createDragBitmap(child, padding); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2270 | |
| 2271 | final int bmpWidth = b.getWidth(); |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 2272 | final int bmpHeight = b.getHeight(); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2273 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2274 | float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2275 | int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); |
| 2276 | int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2277 | - padding.get() / 2); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2278 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 2279 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 2280 | Point dragVisualizeOffset = null; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2281 | Rect dragRect = null; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2282 | if (child instanceof BubbleTextView) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2283 | BubbleTextView icon = (BubbleTextView) child; |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2284 | int iconSize = grid.iconSizePx; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2285 | int top = child.getPaddingTop(); |
| 2286 | int left = (bmpWidth - iconSize) / 2; |
| 2287 | int right = left + iconSize; |
| 2288 | int bottom = top + iconSize; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 2289 | if (icon.isLayoutHorizontal()) { |
| 2290 | // If the layout is horizontal, then if we are just picking up the icon, then just |
| 2291 | // use the child position since the icon is top-left aligned. Otherwise, offset |
| 2292 | // the drag layer position horizontally so that the icon is under the current |
| 2293 | // touch position. |
| 2294 | if (icon.getIcon().getBounds().contains(relativeTouchPos.x, relativeTouchPos.y)) { |
| 2295 | dragLayerX = Math.round(mTempXY[0]); |
| 2296 | } else { |
| 2297 | dragLayerX = Math.round(mTempXY[0] + relativeTouchPos.x - (bmpWidth / 2)); |
| 2298 | } |
| 2299 | } |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2300 | dragLayerY += top; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 2301 | // Note: The drag region is used to calculate drag layer offsets, but the |
| 2302 | // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2303 | dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2304 | dragRect = new Rect(left, top, right, bottom); |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 2305 | } else if (child instanceof FolderIcon) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2306 | int previewSize = grid.folderIconSizePx; |
| 2307 | dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
Winson Chung | 1e9cbfe | 2011-09-30 16:52:26 -0700 | [diff] [blame] | 2310 | // Clear the pressed state if necessary |
| 2311 | if (child instanceof BubbleTextView) { |
| 2312 | BubbleTextView icon = (BubbleTextView) child; |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2313 | icon.clearPressedBackground(); |
Winson Chung | 1e9cbfe | 2011-09-30 16:52:26 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Adam Cohen | 2f32ad2 | 2013-11-13 11:29:49 +0000 | [diff] [blame] | 2316 | if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { |
| 2317 | String msg = "Drag started with a view that has no tag set. This " |
| 2318 | + "will cause a crash (issue 11627249) down the line. " |
| 2319 | + "View: " + child + " tag: " + child.getTag(); |
| 2320 | throw new IllegalStateException(msg); |
| 2321 | } |
| 2322 | |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 2323 | DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2324 | DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, accessible); |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 2325 | dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); |
Adam Cohen | 5084cba | 2013-09-03 12:01:16 -0700 | [diff] [blame] | 2326 | |
| 2327 | if (child.getParent() instanceof ShortcutAndWidgetContainer) { |
| 2328 | mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); |
| 2329 | } |
| 2330 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2331 | b.recycle(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2332 | } |
| 2333 | |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2334 | public void beginExternalDragShared(View child, DragSource source) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 2335 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2336 | int iconSize = grid.iconSizePx; |
| 2337 | |
| 2338 | // Notify launcher of drag start |
| 2339 | mLauncher.onDragStarted(child); |
| 2340 | |
| 2341 | // Compose a new drag bitmap that is of the icon size |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2342 | AtomicInteger padding = new AtomicInteger(DRAG_BITMAP_PADDING); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2343 | final Bitmap tmpB = createDragBitmap(child, padding); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2344 | Bitmap b = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); |
| 2345 | Paint p = new Paint(); |
| 2346 | p.setFilterBitmap(true); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2347 | mCanvas.setBitmap(b); |
| 2348 | mCanvas.drawBitmap(tmpB, new Rect(0, 0, tmpB.getWidth(), tmpB.getHeight()), |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2349 | new Rect(0, 0, iconSize, iconSize), p); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 2350 | mCanvas.setBitmap(null); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2351 | |
| 2352 | // Find the child's location on the screen |
| 2353 | int bmpWidth = tmpB.getWidth(); |
| 2354 | float iconScale = (float) bmpWidth / iconSize; |
| 2355 | float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY) * iconScale; |
| 2356 | int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); |
| 2357 | int dragLayerY = Math.round(mTempXY[1]); |
| 2358 | |
| 2359 | // Note: The drag region is used to calculate drag layer offsets, but the |
| 2360 | // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 2361 | Point dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2362 | Rect dragRect = new Rect(0, 0, iconSize, iconSize); |
| 2363 | |
| 2364 | if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { |
| 2365 | String msg = "Drag started with a view that has no tag set. This " |
| 2366 | + "will cause a crash (issue 11627249) down the line. " |
| 2367 | + "View: " + child + " tag: " + child.getTag(); |
| 2368 | throw new IllegalStateException(msg); |
| 2369 | } |
| 2370 | |
| 2371 | // Start the drag |
| 2372 | DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2373 | DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, false); |
Winson Chung | babb53e | 2014-04-14 17:12:49 -0700 | [diff] [blame] | 2374 | dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); |
| 2375 | |
| 2376 | // Recycle temporary bitmaps |
| 2377 | tmpB.recycle(); |
| 2378 | } |
| 2379 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2380 | public boolean transitionStateShouldAllowDrop() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 2381 | return ((!isSwitchingState() || mTransitionProgress > 0.5f) && |
| 2382 | (mState == State.NORMAL || mState == State.SPRING_LOADED)); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2385 | /** |
| 2386 | * {@inheritDoc} |
| 2387 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2388 | public boolean acceptDrop(DragObject d) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2389 | // 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] | 2390 | CellLayout dropTargetLayout = mDropToLayout; |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2391 | if (d.dragSource != this) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2392 | // 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] | 2393 | if (dropTargetLayout == null) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2394 | return false; |
| 2395 | } |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 2396 | if (!transitionStateShouldAllowDrop()) return false; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2397 | |
Sunny Goyal | 1587d53 | 2015-01-29 09:57:16 -0800 | [diff] [blame] | 2398 | mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter); |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2399 | |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 2400 | // We want the point to be mapped to the dragTarget. |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2401 | if (mLauncher.isHotseatLayout(dropTargetLayout)) { |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 2402 | mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 2403 | } else { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2404 | mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); |
Adam Cohen | 2e9f4fb | 2011-08-30 22:46:55 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2407 | int spanX = 1; |
| 2408 | int spanY = 1; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2409 | if (mDragInfo != null) { |
| 2410 | final CellLayout.CellInfo dragCellInfo = mDragInfo; |
| 2411 | spanX = dragCellInfo.spanX; |
| 2412 | spanY = dragCellInfo.spanY; |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 2413 | } else { |
| 2414 | final ItemInfo dragInfo = (ItemInfo) d.dragInfo; |
| 2415 | spanX = dragInfo.spanX; |
| 2416 | spanY = dragInfo.spanY; |
| 2417 | } |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2418 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2419 | int minSpanX = spanX; |
| 2420 | int minSpanY = spanY; |
| 2421 | if (d.dragInfo instanceof PendingAddWidgetInfo) { |
| 2422 | minSpanX = ((PendingAddWidgetInfo) d.dragInfo).minSpanX; |
| 2423 | minSpanY = ((PendingAddWidgetInfo) d.dragInfo).minSpanY; |
| 2424 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2425 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2426 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2427 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout, |
Adam Cohen | f0777b9 | 2012-02-28 14:02:45 -0800 | [diff] [blame] | 2428 | mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2429 | float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2430 | mDragViewVisualCenter[1], mTargetCell); |
Adam Cohen | ec0d61d | 2014-02-07 16:34:51 -0800 | [diff] [blame] | 2431 | if (mCreateUserFolderOnDrop && willCreateUserFolder((ItemInfo) d.dragInfo, |
| 2432 | dropTargetLayout, mTargetCell, distance, true)) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2433 | return true; |
| 2434 | } |
Adam Cohen | ec0d61d | 2014-02-07 16:34:51 -0800 | [diff] [blame] | 2435 | |
| 2436 | if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder((ItemInfo) d.dragInfo, |
| 2437 | dropTargetLayout, mTargetCell, distance)) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2438 | return true; |
| 2439 | } |
| 2440 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2441 | int[] resultSpan = new int[2]; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 2442 | mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2443 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, |
| 2444 | null, mTargetCell, resultSpan, CellLayout.MODE_ACCEPT_DROP); |
| 2445 | boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0; |
| 2446 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2447 | // 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] | 2448 | if (!foundCell) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2449 | // Don't show the message if we are dropping on the AllApps button and the hotseat |
| 2450 | // is full |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2451 | boolean isHotseat = mLauncher.isHotseatLayout(dropTargetLayout); |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 2452 | if (mTargetCell != null && isHotseat) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2453 | Hotseat hotseat = mLauncher.getHotseat(); |
Andrew Flynn | 0dca1ec | 2012-02-29 13:33:22 -0800 | [diff] [blame] | 2454 | if (hotseat.isAllAppsButtonRank( |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 2455 | hotseat.getOrderInHotseat(mTargetCell[0], mTargetCell[1]))) { |
| 2456 | return false; |
| 2457 | } |
| 2458 | } |
| 2459 | |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 2460 | mLauncher.showOutOfSpaceMessage(isHotseat); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2461 | return false; |
| 2462 | } |
| 2463 | } |
Adam Cohen | dedbd96 | 2013-07-11 14:21:49 -0700 | [diff] [blame] | 2464 | |
| 2465 | long screenId = getIdForScreen(dropTargetLayout); |
| 2466 | if (screenId == EXTRA_EMPTY_SCREEN_ID) { |
| 2467 | commitExtraEmptyScreen(); |
| 2468 | } |
| 2469 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2470 | return true; |
| 2471 | } |
| 2472 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2473 | boolean willCreateUserFolder(ItemInfo info, CellLayout target, int[] targetCell, float |
| 2474 | distance, boolean considerTimeout) { |
| 2475 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2476 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
| 2477 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2478 | if (dropOverView != null) { |
| 2479 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams(); |
| 2480 | if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) { |
| 2481 | return false; |
| 2482 | } |
| 2483 | } |
| 2484 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2485 | boolean hasntMoved = false; |
| 2486 | if (mDragInfo != null) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2487 | hasntMoved = dropOverView == mDragInfo.cell; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2488 | } |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2489 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2490 | if (dropOverView == null || hasntMoved || (considerTimeout && !mCreateUserFolderOnDrop)) { |
| 2491 | return false; |
| 2492 | } |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2493 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2494 | boolean aboveShortcut = (dropOverView.getTag() instanceof ShortcutInfo); |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2495 | boolean willBecomeShortcut = |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2496 | (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 2497 | info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT); |
Adam Cohen | e031096 | 2011-04-18 16:15:31 -0700 | [diff] [blame] | 2498 | |
| 2499 | return (aboveShortcut && willBecomeShortcut); |
| 2500 | } |
| 2501 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2502 | boolean willAddToExistingUserFolder(Object dragInfo, CellLayout target, int[] targetCell, |
| 2503 | float distance) { |
| 2504 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2505 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2506 | |
| 2507 | if (dropOverView != null) { |
| 2508 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams(); |
| 2509 | if (lp.useTmpCoords && (lp.tmpCellX != lp.cellX || lp.tmpCellY != lp.tmpCellY)) { |
| 2510 | return false; |
| 2511 | } |
| 2512 | } |
| 2513 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2514 | if (dropOverView instanceof FolderIcon) { |
| 2515 | FolderIcon fi = (FolderIcon) dropOverView; |
| 2516 | if (fi.acceptDrop(dragInfo)) { |
| 2517 | return true; |
| 2518 | } |
| 2519 | } |
| 2520 | return false; |
| 2521 | } |
| 2522 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2523 | boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2524 | int[] targetCell, float distance, boolean external, DragView dragView, |
| 2525 | Runnable postAnimationRunnable) { |
| 2526 | if (distance > mMaxDistanceForFolderCreation) return false; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2527 | View v = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2528 | |
Winson Chung | ec9a0a4 | 2011-07-20 20:42:13 -0700 | [diff] [blame] | 2529 | boolean hasntMoved = false; |
| 2530 | if (mDragInfo != null) { |
| 2531 | CellLayout cellParent = getParentCellLayoutForView(mDragInfo.cell); |
| 2532 | hasntMoved = (mDragInfo.cellX == targetCell[0] && |
| 2533 | mDragInfo.cellY == targetCell[1]) && (cellParent == target); |
| 2534 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2535 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 2536 | if (v == null || hasntMoved || !mCreateUserFolderOnDrop) return false; |
| 2537 | mCreateUserFolderOnDrop = false; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2538 | final long screenId = (targetCell == null) ? mDragInfo.screenId : getIdForScreen(target); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2539 | |
| 2540 | boolean aboveShortcut = (v.getTag() instanceof ShortcutInfo); |
| 2541 | boolean willBecomeShortcut = (newView.getTag() instanceof ShortcutInfo); |
| 2542 | |
| 2543 | if (aboveShortcut && willBecomeShortcut) { |
| 2544 | ShortcutInfo sourceInfo = (ShortcutInfo) newView.getTag(); |
| 2545 | ShortcutInfo destInfo = (ShortcutInfo) v.getTag(); |
| 2546 | // if the drag started here, we need to remove it from the workspace |
| 2547 | if (!external) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2548 | getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 2551 | Rect folderLocation = new Rect(); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 2552 | float scale = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(v, folderLocation); |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2553 | target.removeView(v); |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 2554 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2555 | FolderIcon fi = |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2556 | mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 2557 | destInfo.cellX = -1; |
| 2558 | destInfo.cellY = -1; |
| 2559 | sourceInfo.cellX = -1; |
| 2560 | sourceInfo.cellY = -1; |
Adam Cohen | d044526 | 2011-07-04 23:53:22 -0700 | [diff] [blame] | 2561 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 2562 | // If the dragView is null, we can't animate |
| 2563 | boolean animate = dragView != null; |
| 2564 | if (animate) { |
| 2565 | fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale, |
| 2566 | postAnimationRunnable); |
| 2567 | } else { |
| 2568 | fi.addItem(destInfo); |
| 2569 | fi.addItem(sourceInfo); |
| 2570 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 2571 | return true; |
| 2572 | } |
| 2573 | return false; |
| 2574 | } |
| 2575 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2576 | boolean addToExistingFolderIfNecessary(View newView, CellLayout target, int[] targetCell, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2577 | float distance, DragObject d, boolean external) { |
| 2578 | if (distance > mMaxDistanceForFolderCreation) return false; |
| 2579 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 2580 | View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2581 | if (!mAddToExistingFolderOnDrop) return false; |
| 2582 | mAddToExistingFolderOnDrop = false; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2583 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2584 | if (dropOverView instanceof FolderIcon) { |
| 2585 | FolderIcon fi = (FolderIcon) dropOverView; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 2586 | if (fi.acceptDrop(d.dragInfo)) { |
| 2587 | fi.onDrop(d); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2588 | |
| 2589 | // if the drag started here, we need to remove it from the workspace |
| 2590 | if (!external) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2591 | getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2592 | } |
| 2593 | return true; |
| 2594 | } |
| 2595 | } |
| 2596 | return false; |
| 2597 | } |
| 2598 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 2599 | @Override |
| 2600 | public void prepareAccessibilityDrop() { } |
| 2601 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2602 | public void onDrop(final DragObject d) { |
Sunny Goyal | 1587d53 | 2015-01-29 09:57:16 -0800 | [diff] [blame] | 2603 | mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2604 | CellLayout dropTargetLayout = mDropToLayout; |
| 2605 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2606 | // We want the point to be mapped to the dragTarget. |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2607 | if (dropTargetLayout != null) { |
| 2608 | if (mLauncher.isHotseatLayout(dropTargetLayout)) { |
Adam Cohen | bb00ff2 | 2012-07-12 15:43:01 -0700 | [diff] [blame] | 2609 | mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2610 | } else { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2611 | mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2612 | } |
Adam Cohen | ba78161 | 2011-05-09 14:37:39 -0700 | [diff] [blame] | 2613 | } |
Michael Jurka | c6ee42e | 2010-09-30 12:04:50 -0700 | [diff] [blame] | 2614 | |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2615 | int snapScreen = WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2616 | boolean resizeOnDrop = false; |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2617 | if (d.dragSource != this) { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2618 | final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], |
| 2619 | (int) mDragViewVisualCenter[1] }; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 2620 | onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d); |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2621 | } else if (mDragInfo != null) { |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2622 | final View cell = mDragInfo.cell; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2623 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2624 | Runnable resizeRunnable = null; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 2625 | if (dropTargetLayout != null && !d.cancelled) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2626 | // Move internally |
Winson Chung | 40e882b | 2011-07-21 19:01:11 -0700 | [diff] [blame] | 2627 | boolean hasMovedLayouts = (getParentCellLayoutForView(cell) != dropTargetLayout); |
| 2628 | boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout); |
| 2629 | long container = hasMovedIntoHotseat ? |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2630 | LauncherSettings.Favorites.CONTAINER_HOTSEAT : |
| 2631 | LauncherSettings.Favorites.CONTAINER_DESKTOP; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2632 | long screenId = (mTargetCell[0] < 0) ? |
| 2633 | mDragInfo.screenId : getIdForScreen(dropTargetLayout); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2634 | int spanX = mDragInfo != null ? mDragInfo.spanX : 1; |
| 2635 | int spanY = mDragInfo != null ? mDragInfo.spanY : 1; |
| 2636 | // First we find the cell nearest to point at which the item is |
| 2637 | // dropped, without any consideration to whether there is an item there. |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2638 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2639 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) |
| 2640 | mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2641 | float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 2642 | mDragViewVisualCenter[1], mTargetCell); |
| 2643 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2644 | // If the item being dropped is a shortcut and the nearest drop |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 2645 | // 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] | 2646 | if (!mInScrollArea && createUserFolderIfNecessary(cell, container, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2647 | dropTargetLayout, mTargetCell, distance, false, d.dragView, null)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2648 | return; |
| 2649 | } |
| 2650 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2651 | if (addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, |
| 2652 | distance, d, false)) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2653 | return; |
| 2654 | } |
| 2655 | |
| 2656 | // Aside from the special case where we're dropping a shortcut onto a shortcut, |
| 2657 | // we need to find the nearest cell location that is vacant |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2658 | ItemInfo item = (ItemInfo) d.dragInfo; |
| 2659 | int minSpanX = item.spanX; |
| 2660 | int minSpanY = item.spanY; |
| 2661 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 2662 | minSpanX = item.minSpanX; |
| 2663 | minSpanY = item.minSpanY; |
| 2664 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2665 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2666 | int[] resultSpan = new int[2]; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 2667 | mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2668 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, |
| 2669 | mTargetCell, resultSpan, CellLayout.MODE_ON_DROP); |
| 2670 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2671 | boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0; |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 2672 | |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 2673 | // if the widget resizes on drop |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 2674 | if (foundCell && (cell instanceof AppWidgetHostView) && |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 2675 | (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY)) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2676 | resizeOnDrop = true; |
| 2677 | item.spanX = resultSpan[0]; |
| 2678 | item.spanY = resultSpan[1]; |
Adam Cohen | 7bdfc97 | 2012-05-22 16:50:35 -0700 | [diff] [blame] | 2679 | AppWidgetHostView awhv = (AppWidgetHostView) cell; |
| 2680 | AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, resultSpan[0], |
| 2681 | resultSpan[1]); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2682 | } |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 2683 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2684 | if (getScreenIdForPageIndex(mCurrentPage) != screenId && !hasMovedIntoHotseat) { |
| 2685 | snapScreen = getPageIndexForScreenId(screenId); |
| 2686 | snapToPage(snapScreen); |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2687 | } |
| 2688 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2689 | if (foundCell) { |
| 2690 | final ItemInfo info = (ItemInfo) cell.getTag(); |
Winson Chung | 40e882b | 2011-07-21 19:01:11 -0700 | [diff] [blame] | 2691 | if (hasMovedLayouts) { |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2692 | // Reparent the view |
Sunny Goyal | 25611b1 | 2014-07-22 09:52:37 -0700 | [diff] [blame] | 2693 | CellLayout parentCell = getParentCellLayoutForView(cell); |
| 2694 | if (parentCell != null) { |
| 2695 | parentCell.removeView(cell); |
| 2696 | } else if (LauncherAppState.isDogfoodBuild()) { |
| 2697 | throw new NullPointerException("mDragInfo.cell has null parent"); |
| 2698 | } |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2699 | addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1], |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2700 | info.spanX, info.spanY); |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | // update the item's position after drop |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2704 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2705 | lp.cellX = lp.tmpCellX = mTargetCell[0]; |
| 2706 | lp.cellY = lp.tmpCellY = mTargetCell[1]; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2707 | lp.cellHSpan = item.spanX; |
| 2708 | lp.cellVSpan = item.spanY; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 2709 | lp.isLockedToGrid = true; |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2710 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 2711 | if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && |
| 2712 | cell instanceof LauncherAppWidgetHostView) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2713 | final CellLayout cellLayout = dropTargetLayout; |
| 2714 | // We post this call so that the widget has a chance to be placed |
| 2715 | // in its final location |
| 2716 | |
| 2717 | final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell; |
Sunny Goyal | 2434d40 | 2015-02-17 11:44:15 -0800 | [diff] [blame] | 2718 | AppWidgetProviderInfo pInfo = hostView.getAppWidgetInfo(); |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 2719 | if (pInfo != null && pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE |
| 2720 | && !d.accessibleDrag) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2721 | final Runnable addResizeFrame = new Runnable() { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2722 | public void run() { |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 2723 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 2724 | dragLayer.addResizeFrame(info, hostView, cellLayout); |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2725 | } |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2726 | }; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2727 | resizeRunnable = (new Runnable() { |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2728 | public void run() { |
| 2729 | if (!isPageMoving()) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2730 | addResizeFrame.run(); |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2731 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2732 | mDelayedResizeRunnable = addResizeFrame; |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2733 | } |
| 2734 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2735 | }); |
| 2736 | } |
| 2737 | } |
| 2738 | |
Adam Cohen | 949debe | 2013-09-29 14:22:48 -0700 | [diff] [blame] | 2739 | LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, lp.cellX, |
| 2740 | lp.cellY, item.spanX, item.spanY); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2741 | } else { |
| 2742 | // If we can't find a drop location, we return the item to its original position |
| 2743 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); |
| 2744 | mTargetCell[0] = lp.cellX; |
| 2745 | mTargetCell[1] = lp.cellY; |
Adam Cohen | f1dcdf6 | 2012-05-10 16:51:52 -0700 | [diff] [blame] | 2746 | CellLayout layout = (CellLayout) cell.getParent().getParent(); |
| 2747 | layout.markCellsAsOccupiedForView(cell); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2748 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2749 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2750 | |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 2751 | final CellLayout parent = (CellLayout) cell.getParent().getParent(); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2752 | final Runnable finalResizeRunnable = resizeRunnable; |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2753 | // Prepare it to be animated into its new position |
| 2754 | // This must be called after the view has been re-parented |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2755 | final Runnable onCompleteRunnable = new Runnable() { |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 2756 | @Override |
| 2757 | public void run() { |
| 2758 | mAnimatingViewIntoPlace = false; |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 2759 | updateChildrenLayersEnabled(false); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2760 | if (finalResizeRunnable != null) { |
| 2761 | finalResizeRunnable.run(); |
| 2762 | } |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 2763 | } |
| 2764 | }; |
| 2765 | mAnimatingViewIntoPlace = true; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2766 | if (d.dragView.hasDrawn()) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2767 | final ItemInfo info = (ItemInfo) cell.getTag(); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 2768 | boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET |
| 2769 | || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
| 2770 | if (isWidget) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2771 | int animationType = resizeOnDrop ? ANIMATE_INTO_POSITION_AND_RESIZE : |
| 2772 | ANIMATE_INTO_POSITION_AND_DISAPPEAR; |
| 2773 | animateWidgetDrop(info, parent, d.dragView, |
| 2774 | onCompleteRunnable, animationType, cell, false); |
| 2775 | } else { |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 2776 | int duration = snapScreen < 0 ? |
| 2777 | WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE : |
| 2778 | ADJACENT_SCREEN_DROP_DURATION; |
Adam Cohen | 85b467b | 2012-02-29 15:38:46 -0800 | [diff] [blame] | 2779 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, |
| 2780 | onCompleteRunnable, this); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 2781 | } |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2782 | } else { |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 2783 | d.deferDragViewCleanupPostAnimation = false; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 2784 | cell.setVisibility(VISIBLE); |
| 2785 | } |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 2786 | parent.onDropChild(cell); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2787 | } |
| 2788 | } |
| 2789 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2790 | public void setFinalScrollForPageChange(int pageIndex) { |
| 2791 | CellLayout cl = (CellLayout) getChildAt(pageIndex); |
| 2792 | if (cl != null) { |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 2793 | mSavedScrollX = getScrollX(); |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 2794 | mSavedTranslationX = cl.getTranslationX(); |
| 2795 | mSavedRotationY = cl.getRotationY(); |
Adam Cohen | edb4076 | 2013-07-18 16:45:45 -0700 | [diff] [blame] | 2796 | final int newX = getScrollForPage(pageIndex); |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 2797 | setScrollX(newX); |
| 2798 | cl.setTranslationX(0f); |
| 2799 | cl.setRotationY(0f); |
| 2800 | } |
| 2801 | } |
| 2802 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 2803 | public void resetFinalScrollForPageChange(int pageIndex) { |
| 2804 | if (pageIndex >= 0) { |
| 2805 | CellLayout cl = (CellLayout) getChildAt(pageIndex); |
Adam Cohen | ed51cc9 | 2011-08-01 20:28:08 -0700 | [diff] [blame] | 2806 | setScrollX(mSavedScrollX); |
| 2807 | cl.setTranslationX(mSavedTranslationX); |
| 2808 | cl.setRotationY(mSavedRotationY); |
| 2809 | } |
| 2810 | } |
| 2811 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 2812 | public void getViewLocationRelativeToSelf(View v, int[] location) { |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 2813 | getLocationInWindow(location); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2814 | int x = location[0]; |
| 2815 | int y = location[1]; |
| 2816 | |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 2817 | v.getLocationInWindow(location); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 2818 | int vX = location[0]; |
| 2819 | int vY = location[1]; |
| 2820 | |
| 2821 | location[0] = vX - x; |
| 2822 | location[1] = vY - y; |
| 2823 | } |
| 2824 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 2825 | public void onDragEnter(DragObject d) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2826 | mDragEnforcer.onDragEnter(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2827 | mCreateUserFolderOnDrop = false; |
| 2828 | mAddToExistingFolderOnDrop = false; |
| 2829 | |
| 2830 | mDropToLayout = null; |
| 2831 | CellLayout layout = getCurrentDropLayout(); |
| 2832 | setCurrentDropLayout(layout); |
| 2833 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 2834 | |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 2835 | if (!workspaceInModalState()) { |
| 2836 | mLauncher.getDragLayer().showPageHints(); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2837 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2838 | } |
| 2839 | |
Winson Chung | fe411c8 | 2013-09-26 16:07:17 -0700 | [diff] [blame] | 2840 | /** Return a rect that has the cellWidth/cellHeight (left, top), and |
| 2841 | * widthGap/heightGap (right, bottom) */ |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2842 | static Rect getCellLayoutMetrics(Launcher launcher, int orientation) { |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2843 | LauncherAppState app = LauncherAppState.getInstance(); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 2844 | InvariantDeviceProfile inv = app.getInvariantDeviceProfile(); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 2845 | |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2846 | Display display = launcher.getWindowManager().getDefaultDisplay(); |
| 2847 | Point smallestSize = new Point(); |
| 2848 | Point largestSize = new Point(); |
| 2849 | display.getCurrentSizeRange(smallestSize, largestSize); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 2850 | int countX = (int) inv.numColumns; |
| 2851 | int countY = (int) inv.numRows; |
| 2852 | boolean isLayoutRtl = Utilities.isRtl(launcher.getResources()); |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2853 | if (orientation == CellLayout.LANDSCAPE) { |
| 2854 | if (mLandscapeCellLayoutMetrics == null) { |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 2855 | Rect padding = inv.landscapeProfile.getWorkspacePadding(isLayoutRtl); |
Winson Chung | dcd27ba | 2013-12-11 15:28:15 -0800 | [diff] [blame] | 2856 | int width = largestSize.x - padding.left - padding.right; |
| 2857 | int height = smallestSize.y - padding.top - padding.bottom; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2858 | mLandscapeCellLayoutMetrics = new Rect(); |
Winson Chung | fe411c8 | 2013-09-26 16:07:17 -0700 | [diff] [blame] | 2859 | mLandscapeCellLayoutMetrics.set( |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 2860 | DeviceProfile.calculateCellWidth(width, countX), |
| 2861 | DeviceProfile.calculateCellHeight(height, countY), 0, 0); |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2862 | } |
| 2863 | return mLandscapeCellLayoutMetrics; |
| 2864 | } else if (orientation == CellLayout.PORTRAIT) { |
| 2865 | if (mPortraitCellLayoutMetrics == null) { |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 2866 | Rect padding = inv.portraitProfile.getWorkspacePadding(isLayoutRtl); |
Winson Chung | dcd27ba | 2013-12-11 15:28:15 -0800 | [diff] [blame] | 2867 | int width = smallestSize.x - padding.left - padding.right; |
| 2868 | int height = largestSize.y - padding.top - padding.bottom; |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2869 | mPortraitCellLayoutMetrics = new Rect(); |
Winson Chung | fe411c8 | 2013-09-26 16:07:17 -0700 | [diff] [blame] | 2870 | mPortraitCellLayoutMetrics.set( |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 2871 | DeviceProfile.calculateCellWidth(width, countX), |
| 2872 | DeviceProfile.calculateCellHeight(height, countY), 0, 0); |
Adam Cohen | a897f39 | 2012-04-27 18:12:05 -0700 | [diff] [blame] | 2873 | } |
| 2874 | return mPortraitCellLayoutMetrics; |
| 2875 | } |
| 2876 | return null; |
| 2877 | } |
| 2878 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2879 | public void onDragExit(DragObject d) { |
| 2880 | mDragEnforcer.onDragExit(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2881 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2882 | // Here we store the final page that will be dropped to, if the workspace in fact |
| 2883 | // receives the drop |
| 2884 | if (mInScrollArea) { |
Winson Chung | cc1cfe4 | 2012-06-18 15:09:17 -0700 | [diff] [blame] | 2885 | if (isPageMoving()) { |
| 2886 | // If the user drops while the page is scrolling, we should use that page as the |
| 2887 | // destination instead of the page that is being hovered over. |
| 2888 | mDropToLayout = (CellLayout) getPageAt(getNextPage()); |
| 2889 | } else { |
| 2890 | mDropToLayout = mDragOverlappingLayout; |
| 2891 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2892 | } else { |
| 2893 | mDropToLayout = mDragTargetLayout; |
| 2894 | } |
| 2895 | |
| 2896 | if (mDragMode == DRAG_MODE_CREATE_FOLDER) { |
| 2897 | mCreateUserFolderOnDrop = true; |
| 2898 | } else if (mDragMode == DRAG_MODE_ADD_TO_FOLDER) { |
| 2899 | mAddToExistingFolderOnDrop = true; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 2900 | } |
| 2901 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2902 | // Reset the scroll area and previous drag target |
| 2903 | onResetScrollArea(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2904 | setCurrentDropLayout(null); |
| 2905 | setCurrentDragOverlappingLayout(null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2906 | |
Adam Cohen | 74c28d1 | 2011-11-18 14:17:11 -0800 | [diff] [blame] | 2907 | mSpringLoadedDragController.cancel(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2908 | |
Adam Cohen | c50438c | 2014-08-19 17:43:05 -0700 | [diff] [blame] | 2909 | mLauncher.getDragLayer().hidePageHints(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2912 | void setCurrentDropLayout(CellLayout layout) { |
| 2913 | if (mDragTargetLayout != null) { |
| 2914 | mDragTargetLayout.revertTempState(); |
| 2915 | mDragTargetLayout.onDragExit(); |
| 2916 | } |
| 2917 | mDragTargetLayout = layout; |
| 2918 | if (mDragTargetLayout != null) { |
| 2919 | mDragTargetLayout.onDragEnter(); |
| 2920 | } |
| 2921 | cleanupReorder(true); |
| 2922 | cleanupFolderCreation(); |
| 2923 | setCurrentDropOverCell(-1, -1); |
| 2924 | } |
| 2925 | |
| 2926 | void setCurrentDragOverlappingLayout(CellLayout layout) { |
| 2927 | if (mDragOverlappingLayout != null) { |
| 2928 | mDragOverlappingLayout.setIsDragOverlapping(false); |
| 2929 | } |
| 2930 | mDragOverlappingLayout = layout; |
| 2931 | if (mDragOverlappingLayout != null) { |
| 2932 | mDragOverlappingLayout.setIsDragOverlapping(true); |
| 2933 | } |
| 2934 | invalidate(); |
| 2935 | } |
| 2936 | |
| 2937 | void setCurrentDropOverCell(int x, int y) { |
| 2938 | if (x != mDragOverX || y != mDragOverY) { |
| 2939 | mDragOverX = x; |
| 2940 | mDragOverY = y; |
| 2941 | setDragMode(DRAG_MODE_NONE); |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | void setDragMode(int dragMode) { |
| 2946 | if (dragMode != mDragMode) { |
| 2947 | if (dragMode == DRAG_MODE_NONE) { |
| 2948 | cleanupAddToFolder(); |
| 2949 | // We don't want to cancel the re-order alarm every time the target cell changes |
| 2950 | // as this feels to slow / unresponsive. |
| 2951 | cleanupReorder(false); |
| 2952 | cleanupFolderCreation(); |
| 2953 | } else if (dragMode == DRAG_MODE_ADD_TO_FOLDER) { |
| 2954 | cleanupReorder(true); |
| 2955 | cleanupFolderCreation(); |
| 2956 | } else if (dragMode == DRAG_MODE_CREATE_FOLDER) { |
| 2957 | cleanupAddToFolder(); |
| 2958 | cleanupReorder(true); |
| 2959 | } else if (dragMode == DRAG_MODE_REORDER) { |
| 2960 | cleanupAddToFolder(); |
| 2961 | cleanupFolderCreation(); |
| 2962 | } |
| 2963 | mDragMode = dragMode; |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | private void cleanupFolderCreation() { |
| 2968 | if (mDragFolderRingAnimator != null) { |
| 2969 | mDragFolderRingAnimator.animateToNaturalState(); |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 2970 | mDragFolderRingAnimator = null; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2971 | } |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 2972 | mFolderCreationAlarm.setOnAlarmListener(null); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 2973 | mFolderCreationAlarm.cancelAlarm(); |
| 2974 | } |
| 2975 | |
| 2976 | private void cleanupAddToFolder() { |
| 2977 | if (mDragOverFolderIcon != null) { |
| 2978 | mDragOverFolderIcon.onDragExit(null); |
| 2979 | mDragOverFolderIcon = null; |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | private void cleanupReorder(boolean cancelAlarm) { |
| 2984 | // Any pending reorders are canceled |
| 2985 | if (cancelAlarm) { |
| 2986 | mReorderAlarm.cancelAlarm(); |
| 2987 | } |
| 2988 | mLastReorderX = -1; |
| 2989 | mLastReorderY = -1; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2992 | /* |
| 2993 | * |
| 2994 | * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's |
| 2995 | * coordinate space. The argument xy is modified with the return result. |
| 2996 | * |
| 2997 | * 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] | 2998 | * computing it itself; we use this to avoid redundant matrix inversions in |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2999 | * findMatchingPageForDragOver |
| 3000 | * |
| 3001 | */ |
| 3002 | void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3003 | xy[0] = xy[0] - v.getLeft(); |
| 3004 | xy[1] = xy[1] - v.getTop(); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3007 | boolean isPointInSelfOverHotseat(int x, int y, Rect r) { |
| 3008 | if (r == null) { |
| 3009 | r = new Rect(); |
| 3010 | } |
| 3011 | mTempPt[0] = x; |
| 3012 | mTempPt[1] = y; |
| 3013 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempPt, true); |
Winson Chung | abedd9f | 2013-09-24 15:41:09 -0700 | [diff] [blame] | 3014 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 3015 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Winson Chung | abedd9f | 2013-09-24 15:41:09 -0700 | [diff] [blame] | 3016 | r = grid.getHotseatRect(); |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3017 | if (r.contains(mTempPt[0], mTempPt[1])) { |
| 3018 | return true; |
| 3019 | } |
| 3020 | return false; |
| 3021 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3022 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3023 | void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3024 | mTempPt[0] = (int) xy[0]; |
| 3025 | mTempPt[1] = (int) xy[1]; |
| 3026 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempPt, true); |
Winson Chung | 156ab5b | 2013-07-12 14:14:16 -0700 | [diff] [blame] | 3027 | mLauncher.getDragLayer().mapCoordInSelfToDescendent(hotseat.getLayout(), mTempPt); |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3028 | |
| 3029 | xy[0] = mTempPt[0]; |
| 3030 | xy[1] = mTempPt[1]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3033 | /* |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3034 | * |
| 3035 | * Convert the 2D coordinate xy from this CellLayout's coordinate space to |
| 3036 | * the parent View's coordinate space. The argument xy is modified with the return result. |
| 3037 | * |
| 3038 | */ |
| 3039 | void mapPointFromChildToSelf(View v, float[] xy) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3040 | xy[0] += v.getLeft(); |
| 3041 | xy[1] += v.getTop(); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3042 | } |
| 3043 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3044 | static private float squaredDistance(float[] point1, float[] point2) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3045 | float distanceX = point1[0] - point2[0]; |
| 3046 | float distanceY = point2[1] - point2[1]; |
| 3047 | return distanceX * distanceX + distanceY * distanceY; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3048 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3049 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3050 | /* |
| 3051 | * |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3052 | * This method returns the CellLayout that is currently being dragged to. In order to drag |
| 3053 | * to a CellLayout, either the touch point must be directly over the CellLayout, or as a second |
| 3054 | * strategy, we see if the dragView is overlapping any CellLayout and choose the closest one |
| 3055 | * |
| 3056 | * Return null if no CellLayout is currently being dragged over |
| 3057 | * |
| 3058 | */ |
| 3059 | private CellLayout findMatchingPageForDragOver( |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3060 | DragView dragView, float originX, float originY, boolean exact) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3061 | // We loop through all the screens (ie CellLayouts) and see which ones overlap |
| 3062 | // 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] | 3063 | final int screenCount = getChildCount(); |
| 3064 | CellLayout bestMatchingScreen = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3065 | float smallestDistSoFar = Float.MAX_VALUE; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3066 | |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3067 | for (int i = 0; i < screenCount; i++) { |
Adam Cohen | df041bc | 2013-09-22 12:32:22 -0700 | [diff] [blame] | 3068 | // The custom content screen is not a valid drag over option |
| 3069 | if (mScreenOrder.get(i) == CUSTOM_CONTENT_SCREEN_ID) { |
| 3070 | continue; |
| 3071 | } |
| 3072 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3073 | CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3074 | |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3075 | final float[] touchXy = {originX, originY}; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3076 | // Transform the touch coordinates to the CellLayout's local coordinates |
| 3077 | // 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] | 3078 | cl.getMatrix().invert(mTempInverseMatrix); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3079 | mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3080 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3081 | if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && |
| 3082 | touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) { |
| 3083 | return cl; |
| 3084 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3085 | |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 3086 | if (!exact) { |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3087 | // Get the center of the cell layout in screen coordinates |
| 3088 | final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates; |
| 3089 | cellLayoutCenter[0] = cl.getWidth()/2; |
| 3090 | cellLayoutCenter[1] = cl.getHeight()/2; |
| 3091 | mapPointFromChildToSelf(cl, cellLayoutCenter); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3092 | |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3093 | touchXy[0] = originX; |
| 3094 | touchXy[1] = originY; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3095 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3096 | // Calculate the distance between the center of the CellLayout |
| 3097 | // and the touch point |
| 3098 | float dist = squaredDistance(touchXy, cellLayoutCenter); |
| 3099 | |
| 3100 | if (dist < smallestDistSoFar) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3101 | smallestDistSoFar = dist; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3102 | bestMatchingScreen = cl; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3103 | } |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 3104 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3105 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 3106 | return bestMatchingScreen; |
| 3107 | } |
| 3108 | |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 3109 | private boolean isDragWidget(DragObject d) { |
| 3110 | return (d.dragInfo instanceof LauncherAppWidgetInfo || |
| 3111 | d.dragInfo instanceof PendingAddWidgetInfo); |
| 3112 | } |
| 3113 | private boolean isExternalDragWidget(DragObject d) { |
| 3114 | return d.dragSource != this && isDragWidget(d); |
| 3115 | } |
| 3116 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 3117 | public void onDragOver(DragObject d) { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3118 | // Skip drag over events while we are dragging over side pages |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3119 | if (mInScrollArea || !transitionStateShouldAllowDrop()) return; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3120 | |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3121 | Rect r = new Rect(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3122 | CellLayout layout = null; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3123 | ItemInfo item = (ItemInfo) d.dragInfo; |
Sunny Goyal | 25611b1 | 2014-07-22 09:52:37 -0700 | [diff] [blame] | 3124 | if (item == null) { |
| 3125 | if (LauncherAppState.isDogfoodBuild()) { |
| 3126 | throw new NullPointerException("DragObject has null info"); |
| 3127 | } |
| 3128 | return; |
| 3129 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3130 | |
| 3131 | // Ensure that we have proper spans for the item that we are dropping |
| 3132 | if (item.spanX < 0 || item.spanY < 0) throw new RuntimeException("Improper spans found"); |
Sunny Goyal | 1587d53 | 2015-01-29 09:57:16 -0800 | [diff] [blame] | 3133 | mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter); |
Adam Cohen | 0061875 | 2011-07-20 12:06:04 -0700 | [diff] [blame] | 3134 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3135 | final View child = (mDragInfo == null) ? null : mDragInfo.cell; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3136 | // Identify whether we have dragged over a side page |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3137 | if (workspaceInModalState()) { |
Winson Chung | ea359c6 | 2011-08-03 17:06:35 -0700 | [diff] [blame] | 3138 | if (mLauncher.getHotseat() != null && !isExternalDragWidget(d)) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3139 | if (isPointInSelfOverHotseat(d.x, d.y, r)) { |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3140 | layout = mLauncher.getHotseat().getLayout(); |
| 3141 | } |
| 3142 | } |
| 3143 | if (layout == null) { |
Winson Chung | 96ef409 | 2011-11-22 12:25:14 -0800 | [diff] [blame] | 3144 | layout = findMatchingPageForDragOver(d.dragView, d.x, d.y, false); |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3145 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3146 | if (layout != mDragTargetLayout) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3147 | setCurrentDropLayout(layout); |
| 3148 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3149 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3150 | boolean isInSpringLoadedMode = (mState == State.SPRING_LOADED); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3151 | if (isInSpringLoadedMode) { |
Winson Chung | 4afe9b3 | 2011-07-27 17:46:20 -0700 | [diff] [blame] | 3152 | if (mLauncher.isHotseatLayout(layout)) { |
| 3153 | mSpringLoadedDragController.cancel(); |
| 3154 | } else { |
| 3155 | mSpringLoadedDragController.setAlarm(mDragTargetLayout); |
| 3156 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3157 | } |
| 3158 | } |
| 3159 | } else { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3160 | // 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] | 3161 | if (mLauncher.getHotseat() != null && !isDragWidget(d)) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3162 | if (isPointInSelfOverHotseat(d.x, d.y, r)) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3163 | layout = mLauncher.getHotseat().getLayout(); |
| 3164 | } |
| 3165 | } |
| 3166 | if (layout == null) { |
| 3167 | layout = getCurrentDropLayout(); |
| 3168 | } |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3169 | if (layout != mDragTargetLayout) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3170 | setCurrentDropLayout(layout); |
| 3171 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3172 | } |
| 3173 | } |
| 3174 | |
| 3175 | // Handle the drag over |
| 3176 | if (mDragTargetLayout != null) { |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3177 | // We want the point to be mapped to the dragTarget. |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3178 | if (mLauncher.isHotseatLayout(mDragTargetLayout)) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3179 | mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3180 | } else { |
| 3181 | mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null); |
| 3182 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3183 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3184 | ItemInfo info = (ItemInfo) d.dragInfo; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3185 | |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3186 | int minSpanX = item.spanX; |
| 3187 | int minSpanY = item.spanY; |
| 3188 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 3189 | minSpanX = item.minSpanX; |
| 3190 | minSpanY = item.minSpanY; |
| 3191 | } |
| 3192 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3193 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3194 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, |
Adam Cohen | d024f98 | 2012-05-23 18:26:45 -0700 | [diff] [blame] | 3195 | mDragTargetLayout, mTargetCell); |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3196 | int reorderX = mTargetCell[0]; |
| 3197 | int reorderY = mTargetCell[1]; |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3198 | |
| 3199 | setCurrentDropOverCell(mTargetCell[0], mTargetCell[1]); |
| 3200 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3201 | float targetCellDistance = mDragTargetLayout.getDistanceFromCell( |
| 3202 | mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); |
| 3203 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3204 | final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], |
| 3205 | mTargetCell[1]); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 3206 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3207 | manageFolderFeedback(info, mDragTargetLayout, mTargetCell, |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 3208 | targetCellDistance, dragOverView, d.accessibleDrag); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3209 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3210 | boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied((int) |
| 3211 | mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], item.spanX, |
| 3212 | item.spanY, child, mTargetCell); |
| 3213 | |
| 3214 | if (!nearestDropOccupied) { |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3215 | mDragTargetLayout.visualizeDropLocation(child, mDragOutline, |
| 3216 | (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], |
| 3217 | mTargetCell[0], mTargetCell[1], item.spanX, item.spanY, false, |
| 3218 | d.dragView.getDragVisualizeOffset(), d.dragView.getDragRegion()); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3219 | } else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER) |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3220 | && !mReorderAlarm.alarmPending() && (mLastReorderX != reorderX || |
| 3221 | mLastReorderY != reorderY)) { |
Adam Cohen | d024f98 | 2012-05-23 18:26:45 -0700 | [diff] [blame] | 3222 | |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3223 | int[] resultSpan = new int[2]; |
| 3224 | mDragTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
| 3225 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, item.spanX, item.spanY, |
| 3226 | child, mTargetCell, resultSpan, CellLayout.MODE_SHOW_REORDER_HINT); |
| 3227 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3228 | // Otherwise, if we aren't adding to or creating a folder and there's no pending |
| 3229 | // reorder, then we schedule a reorder |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3230 | ReorderAlarmListener listener = new ReorderAlarmListener(mDragViewVisualCenter, |
| 3231 | minSpanX, minSpanY, item.spanX, item.spanY, d.dragView, child); |
| 3232 | mReorderAlarm.setOnAlarmListener(listener); |
| 3233 | mReorderAlarm.setAlarm(REORDER_TIMEOUT); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | if (mDragMode == DRAG_MODE_CREATE_FOLDER || mDragMode == DRAG_MODE_ADD_TO_FOLDER || |
| 3237 | !nearestDropOccupied) { |
| 3238 | if (mDragTargetLayout != null) { |
| 3239 | mDragTargetLayout.revertTempState(); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3240 | } |
| 3241 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3242 | } |
| 3243 | } |
| 3244 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3245 | private void manageFolderFeedback(ItemInfo info, CellLayout targetLayout, |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 3246 | int[] targetCell, float distance, View dragOverView, boolean accessibleDrag) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3247 | boolean userFolderPending = willCreateUserFolder(info, targetLayout, targetCell, distance, |
| 3248 | false); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3249 | if (mDragMode == DRAG_MODE_NONE && userFolderPending && |
| 3250 | !mFolderCreationAlarm.alarmPending()) { |
Adam Cohen | c9735cf | 2015-01-23 16:11:55 -0800 | [diff] [blame] | 3251 | |
| 3252 | FolderCreationAlarmListener listener = new |
| 3253 | FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1]); |
| 3254 | |
| 3255 | if (!accessibleDrag) { |
| 3256 | mFolderCreationAlarm.setOnAlarmListener(listener); |
| 3257 | mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT); |
| 3258 | } else { |
| 3259 | listener.onAlarm(mFolderCreationAlarm); |
| 3260 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3261 | return; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | boolean willAddToFolder = |
| 3265 | willAddToExistingUserFolder(info, targetLayout, targetCell, distance); |
| 3266 | |
| 3267 | if (willAddToFolder && mDragMode == DRAG_MODE_NONE) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3268 | mDragOverFolderIcon = ((FolderIcon) dragOverView); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3269 | mDragOverFolderIcon.onDragEnter(info); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3270 | if (targetLayout != null) { |
| 3271 | targetLayout.clearDragOutlines(); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3272 | } |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3273 | setDragMode(DRAG_MODE_ADD_TO_FOLDER); |
| 3274 | return; |
Patrick Dubroy | 976ebec | 2010-08-04 20:03:37 -0700 | [diff] [blame] | 3275 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3276 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3277 | if (mDragMode == DRAG_MODE_ADD_TO_FOLDER && !willAddToFolder) { |
| 3278 | setDragMode(DRAG_MODE_NONE); |
| 3279 | } |
| 3280 | if (mDragMode == DRAG_MODE_CREATE_FOLDER && !userFolderPending) { |
| 3281 | setDragMode(DRAG_MODE_NONE); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3282 | } |
| 3283 | |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3284 | return; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3287 | class FolderCreationAlarmListener implements OnAlarmListener { |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3288 | CellLayout layout; |
| 3289 | int cellX; |
| 3290 | int cellY; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3291 | |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3292 | public FolderCreationAlarmListener(CellLayout layout, int cellX, int cellY) { |
| 3293 | this.layout = layout; |
| 3294 | this.cellX = cellX; |
| 3295 | this.cellY = cellY; |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | public void onAlarm(Alarm alarm) { |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 3299 | if (mDragFolderRingAnimator != null) { |
| 3300 | // This shouldn't happen ever, but just in case, make sure we clean up the mess. |
| 3301 | mDragFolderRingAnimator.animateToNaturalState(); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3302 | } |
Adam Cohen | 8ec05f9 | 2013-10-13 12:29:03 -0700 | [diff] [blame] | 3303 | mDragFolderRingAnimator = new FolderRingAnimator(mLauncher, null); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3304 | mDragFolderRingAnimator.setCell(cellX, cellY); |
| 3305 | mDragFolderRingAnimator.setCellLayout(layout); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3306 | mDragFolderRingAnimator.animateToAcceptState(); |
Adam Cohen | 69ce2e5 | 2011-07-03 19:25:21 -0700 | [diff] [blame] | 3307 | layout.showFolderAccept(mDragFolderRingAnimator); |
| 3308 | layout.clearDragOutlines(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3309 | setDragMode(DRAG_MODE_CREATE_FOLDER); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | class ReorderAlarmListener implements OnAlarmListener { |
| 3314 | float[] dragViewCenter; |
| 3315 | int minSpanX, minSpanY, spanX, spanY; |
| 3316 | DragView dragView; |
| 3317 | View child; |
| 3318 | |
| 3319 | public ReorderAlarmListener(float[] dragViewCenter, int minSpanX, int minSpanY, int spanX, |
| 3320 | int spanY, DragView dragView, View child) { |
| 3321 | this.dragViewCenter = dragViewCenter; |
| 3322 | this.minSpanX = minSpanX; |
| 3323 | this.minSpanY = minSpanY; |
| 3324 | this.spanX = spanX; |
| 3325 | this.spanY = spanY; |
| 3326 | this.child = child; |
| 3327 | this.dragView = dragView; |
| 3328 | } |
| 3329 | |
| 3330 | public void onAlarm(Alarm alarm) { |
| 3331 | int[] resultSpan = new int[2]; |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3332 | mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], |
Adam Cohen | 74c5491 | 2013-09-29 14:48:04 -0700 | [diff] [blame] | 3333 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, mDragTargetLayout, |
| 3334 | mTargetCell); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3335 | mLastReorderX = mTargetCell[0]; |
| 3336 | mLastReorderY = mTargetCell[1]; |
| 3337 | |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3338 | mTargetCell = mDragTargetLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3339 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, |
| 3340 | child, mTargetCell, resultSpan, CellLayout.MODE_DRAG_OVER); |
| 3341 | |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3342 | if (mTargetCell[0] < 0 || mTargetCell[1] < 0) { |
| 3343 | mDragTargetLayout.revertTempState(); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3344 | } else { |
| 3345 | setDragMode(DRAG_MODE_REORDER); |
Adam Cohen | 19f3792 | 2012-03-21 11:59:11 -0700 | [diff] [blame] | 3346 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3347 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3348 | boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY; |
| 3349 | mDragTargetLayout.visualizeDropLocation(child, mDragOutline, |
| 3350 | (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], |
| 3351 | mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, |
| 3352 | dragView.getDragVisualizeOffset(), dragView.getDragRegion()); |
Adam Cohen | 19072da | 2011-05-31 14:30:45 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 3356 | @Override |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3357 | public void getHitRectRelativeToDragLayer(Rect outRect) { |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 3358 | // We want the workspace to have the whole area of the display (it will find the correct |
| 3359 | // cell layout to drop to in the existing drag/drop logic. |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3360 | mLauncher.getDragLayer().getDescendantRectRelativeToSelf(this, outRect); |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 3361 | } |
| 3362 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3363 | /** |
| 3364 | * Add the item specified by dragInfo to the given layout. |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3365 | * @return true if successful |
| 3366 | */ |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 3367 | public boolean addExternalItemToScreen(ItemInfo dragInfo, CellLayout layout) { |
| 3368 | if (layout.findCellForSpan(mTempEstimate, dragInfo.spanX, dragInfo.spanY)) { |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 3369 | onDropExternal(dragInfo.dropPos, (ItemInfo) dragInfo, (CellLayout) layout, false); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3370 | return true; |
| 3371 | } |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 3372 | mLauncher.showOutOfSpaceMessage(mLauncher.isHotseatLayout(layout)); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 3373 | return false; |
| 3374 | } |
| 3375 | |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 3376 | private void onDropExternal(int[] touchXY, Object dragInfo, |
| 3377 | CellLayout cellLayout, boolean insertAtFirst) { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3378 | onDropExternal(touchXY, dragInfo, cellLayout, insertAtFirst, null); |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 3381 | /** |
| 3382 | * Drop an item that didn't originate on one of the workspace screens. |
| 3383 | * It may have come from Launcher (e.g. from all apps or customize), or it may have |
| 3384 | * come from another app altogether. |
| 3385 | * |
| 3386 | * NOTE: This can also be called when we are outside of a drag event, when we want |
| 3387 | * to add an item to one of the workspace screens. |
| 3388 | */ |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3389 | private void onDropExternal(final int[] touchXY, final Object dragInfo, |
| 3390 | final CellLayout cellLayout, boolean insertAtFirst, DragObject d) { |
| 3391 | final Runnable exitSpringLoadedRunnable = new Runnable() { |
| 3392 | @Override |
| 3393 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 3394 | mLauncher.exitSpringLoadedDragModeDelayed(true, |
| 3395 | Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3396 | } |
| 3397 | }; |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3398 | |
| 3399 | ItemInfo info = (ItemInfo) dragInfo; |
| 3400 | int spanX = info.spanX; |
| 3401 | int spanY = info.spanY; |
| 3402 | if (mDragInfo != null) { |
| 3403 | spanX = mDragInfo.spanX; |
| 3404 | spanY = mDragInfo.spanY; |
| 3405 | } |
| 3406 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3407 | final long container = mLauncher.isHotseatLayout(cellLayout) ? |
| 3408 | LauncherSettings.Favorites.CONTAINER_HOTSEAT : |
| 3409 | LauncherSettings.Favorites.CONTAINER_DESKTOP; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3410 | final long screenId = getIdForScreen(cellLayout); |
| 3411 | if (!mLauncher.isHotseatLayout(cellLayout) |
| 3412 | && screenId != getScreenIdForPageIndex(mCurrentPage) |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3413 | && mState != State.SPRING_LOADED) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3414 | snapToScreenId(screenId, null); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 3415 | } |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3416 | |
| 3417 | if (info instanceof PendingAddItemInfo) { |
| 3418 | final PendingAddItemInfo pendingInfo = (PendingAddItemInfo) dragInfo; |
| 3419 | |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3420 | boolean findNearestVacantCell = true; |
| 3421 | if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { |
| 3422 | mTargetCell = findNearestArea((int) touchXY[0], (int) touchXY[1], spanX, spanY, |
| 3423 | cellLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3424 | float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 3425 | mDragViewVisualCenter[1], mTargetCell); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3426 | if (willCreateUserFolder((ItemInfo) d.dragInfo, cellLayout, mTargetCell, |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3427 | distance, true) || willAddToExistingUserFolder((ItemInfo) d.dragInfo, |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3428 | cellLayout, mTargetCell, distance)) { |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3429 | findNearestVacantCell = false; |
| 3430 | } |
| 3431 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3432 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3433 | final ItemInfo item = (ItemInfo) d.dragInfo; |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 3434 | boolean updateWidgetSize = false; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3435 | if (findNearestVacantCell) { |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3436 | int minSpanX = item.spanX; |
| 3437 | int minSpanY = item.spanY; |
| 3438 | if (item.minSpanX > 0 && item.minSpanY > 0) { |
| 3439 | minSpanX = item.minSpanX; |
| 3440 | minSpanY = item.minSpanY; |
| 3441 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3442 | int[] resultSpan = new int[2]; |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3443 | mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3444 | (int) mDragViewVisualCenter[1], minSpanX, minSpanY, info.spanX, info.spanY, |
| 3445 | null, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP_EXTERNAL); |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 3446 | |
| 3447 | if (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY) { |
| 3448 | updateWidgetSize = true; |
| 3449 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3450 | item.spanX = resultSpan[0]; |
| 3451 | item.spanY = resultSpan[1]; |
Adam Cohen | 558baaf | 2011-08-15 15:22:57 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3454 | Runnable onAnimationCompleteRunnable = new Runnable() { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3455 | @Override |
| 3456 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 3457 | // Normally removeExtraEmptyScreen is called in Workspace#onDragEnd, but when |
| 3458 | // adding an item that may not be dropped right away (due to a config activity) |
| 3459 | // we defer the removal until the activity returns. |
| 3460 | deferRemoveExtraEmptyScreen(); |
| 3461 | |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3462 | // When dragging and dropping from customization tray, we deal with creating |
| 3463 | // widgets/shortcuts/folders in a slightly different way |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3464 | mLauncher.addPendingItem(pendingInfo, container, screenId, mTargetCell, |
| 3465 | item.spanX, item.spanY); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3466 | } |
Adam Cohen | b7e1618 | 2011-07-15 17:55:02 -0700 | [diff] [blame] | 3467 | }; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3468 | boolean isWidget = pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET |
| 3469 | || pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
| 3470 | |
| 3471 | View finalView = isWidget ? ((PendingAddWidgetInfo) pendingInfo).boundWidget : null; |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 3472 | |
| 3473 | if (finalView instanceof AppWidgetHostView && updateWidgetSize) { |
| 3474 | AppWidgetHostView awhv = (AppWidgetHostView) finalView; |
| 3475 | AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, item.spanX, |
| 3476 | item.spanY); |
| 3477 | } |
| 3478 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3479 | int animationStyle = ANIMATE_INTO_POSITION_AND_DISAPPEAR; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3480 | if (isWidget && ((PendingAddWidgetInfo) pendingInfo).info != null && |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3481 | ((PendingAddWidgetInfo) pendingInfo).info.configure != null) { |
| 3482 | animationStyle = ANIMATE_INTO_POSITION_AND_REMAIN; |
| 3483 | } |
| 3484 | animateWidgetDrop(info, cellLayout, d.dragView, onAnimationCompleteRunnable, |
| 3485 | animationStyle, finalView, true); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 3486 | } else { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3487 | // This is for other drag/drop cases, like dragging from All Apps |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3488 | View view = null; |
| 3489 | |
| 3490 | switch (info.itemType) { |
| 3491 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 3492 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 3493 | if (info.container == NO_ID && info instanceof AppInfo) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3494 | // Came from all apps -- make a copy |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3495 | info = ((AppInfo) info).makeShortcut(); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3496 | } |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 3497 | view = mLauncher.createShortcut(cellLayout, (ShortcutInfo) info); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3498 | break; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 3499 | case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3500 | view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout, |
| 3501 | (FolderInfo) info, mIconCache); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3502 | break; |
| 3503 | default: |
| 3504 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 3505 | } |
| 3506 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3507 | // First we find the cell nearest to point at which the item is |
| 3508 | // dropped, without any consideration to whether there is an item there. |
| 3509 | if (touchXY != null) { |
| 3510 | mTargetCell = findNearestArea((int) touchXY[0], (int) touchXY[1], spanX, spanY, |
| 3511 | cellLayout, mTargetCell); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3512 | float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], |
| 3513 | mDragViewVisualCenter[1], mTargetCell); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3514 | d.postAnimationRunnable = exitSpringLoadedRunnable; |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3515 | if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, |
| 3516 | true, d.dragView, d.postAnimationRunnable)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3517 | return; |
| 3518 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3519 | if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, |
| 3520 | true)) { |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 3521 | return; |
| 3522 | } |
Adam Cohen | 10b1737 | 2011-04-15 14:21:25 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 3525 | if (touchXY != null) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3526 | // when dragging and dropping, just find the closest free spot |
Adam Cohen | fa3c58f | 2013-12-06 16:10:55 -0800 | [diff] [blame] | 3527 | mTargetCell = cellLayout.performReorder((int) mDragViewVisualCenter[0], |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3528 | (int) mDragViewVisualCenter[1], 1, 1, 1, 1, |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 3529 | null, mTargetCell, null, CellLayout.MODE_ON_DROP_EXTERNAL); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 3530 | } else { |
| 3531 | cellLayout.findCellForSpan(mTargetCell, 1, 1); |
| 3532 | } |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 3533 | // Add the item to DB before adding to screen ensures that the container and other |
| 3534 | // values of the info is properly updated. |
| 3535 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screenId, |
| 3536 | mTargetCell[0], mTargetCell[1]); |
| 3537 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3538 | addInScreen(view, container, screenId, mTargetCell[0], mTargetCell[1], info.spanX, |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 3539 | info.spanY, insertAtFirst); |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 3540 | cellLayout.onDropChild(view); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3541 | cellLayout.getShortcutsAndWidgets().measureChild(view); |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 3542 | |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 3543 | if (d.dragView != null) { |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3544 | // We wrap the animation call in the temporary set and reset of the current |
| 3545 | // cellLayout to its final transform -- this means we animate the drag view to |
| 3546 | // the correct final location. |
| 3547 | setFinalTransitionTransform(cellLayout); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 3548 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, |
Adam Cohen | 28f852a | 2013-10-15 14:34:05 -0700 | [diff] [blame] | 3549 | exitSpringLoadedRunnable, this); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3550 | resetTransitionTransform(cellLayout); |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 3551 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3552 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3553 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3554 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3555 | public Bitmap createWidgetBitmap(ItemInfo widgetInfo, View layout) { |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 3556 | int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(widgetInfo, false); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3557 | int visibility = layout.getVisibility(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3558 | layout.setVisibility(VISIBLE); |
| 3559 | |
| 3560 | int width = MeasureSpec.makeMeasureSpec(unScaledSize[0], MeasureSpec.EXACTLY); |
| 3561 | int height = MeasureSpec.makeMeasureSpec(unScaledSize[1], MeasureSpec.EXACTLY); |
| 3562 | Bitmap b = Bitmap.createBitmap(unScaledSize[0], unScaledSize[1], |
| 3563 | Bitmap.Config.ARGB_8888); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 3564 | mCanvas.setBitmap(b); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3565 | |
| 3566 | layout.measure(width, height); |
| 3567 | layout.layout(0, 0, unScaledSize[0], unScaledSize[1]); |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 3568 | layout.draw(mCanvas); |
| 3569 | mCanvas.setBitmap(null); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3570 | layout.setVisibility(visibility); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3571 | return b; |
| 3572 | } |
| 3573 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3574 | private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, |
Adam Cohen | 9d5b7d8 | 2012-05-09 18:00:44 -0700 | [diff] [blame] | 3575 | DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 3576 | boolean external, boolean scale) { |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3577 | // Now we animate the dragView, (ie. the widget or shortcut preview) into its final |
| 3578 | // location and size on the home screen. |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3579 | int spanX = info.spanX; |
| 3580 | int spanY = info.spanY; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3581 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3582 | Rect r = estimateItemPosition(layout, info, targetCell[0], targetCell[1], spanX, spanY); |
| 3583 | loc[0] = r.left; |
| 3584 | loc[1] = r.top; |
| 3585 | |
| 3586 | setFinalTransitionTransform(layout); |
| 3587 | float cellLayoutScale = |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3588 | mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(layout, loc, true); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3589 | resetTransitionTransform(layout); |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 3590 | |
| 3591 | float dragViewScaleX; |
| 3592 | float dragViewScaleY; |
| 3593 | if (scale) { |
| 3594 | dragViewScaleX = (1.0f * r.width()) / dragView.getMeasuredWidth(); |
| 3595 | dragViewScaleY = (1.0f * r.height()) / dragView.getMeasuredHeight(); |
| 3596 | } else { |
| 3597 | dragViewScaleX = 1f; |
| 3598 | dragViewScaleY = 1f; |
| 3599 | } |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3600 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3601 | // The animation will scale the dragView about its center, so we need to center about |
| 3602 | // the final location. |
| 3603 | loc[0] -= (dragView.getMeasuredWidth() - cellLayoutScale * r.width()) / 2; |
| 3604 | loc[1] -= (dragView.getMeasuredHeight() - cellLayoutScale * r.height()) / 2; |
| 3605 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3606 | scaleXY[0] = dragViewScaleX * cellLayoutScale; |
| 3607 | scaleXY[1] = dragViewScaleY * cellLayoutScale; |
| 3608 | } |
| 3609 | |
| 3610 | public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, DragView dragView, |
| 3611 | final Runnable onCompleteRunnable, int animationType, final View finalView, |
| 3612 | boolean external) { |
| 3613 | Rect from = new Rect(); |
| 3614 | mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from); |
| 3615 | |
| 3616 | int[] finalPos = new int[2]; |
| 3617 | float scaleXY[] = new float[2]; |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 3618 | boolean scalePreview = !(info instanceof PendingAddShortcutInfo); |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3619 | getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, |
Michael Jurka | a2fe786 | 2012-05-29 05:58:17 -0700 | [diff] [blame] | 3620 | external, scalePreview); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3621 | |
| 3622 | Resources res = mLauncher.getResources(); |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3623 | final int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3624 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3625 | // In the case where we've prebound the widget, we remove it from the DragLayer |
| 3626 | if (finalView instanceof AppWidgetHostView && external) { |
| 3627 | mLauncher.getDragLayer().removeView(finalView); |
| 3628 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3629 | |
| 3630 | boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || |
| 3631 | info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3632 | if ((animationType == ANIMATE_INTO_POSITION_AND_RESIZE || external) && finalView != null) { |
| 3633 | Bitmap crossFadeBitmap = createWidgetBitmap(info, finalView); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3634 | dragView.setCrossFadeBitmap(crossFadeBitmap); |
| 3635 | dragView.crossFade((int) (duration * 0.8f)); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 3636 | } else if (isWidget && external) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3637 | scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3638 | } |
| 3639 | |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3640 | DragLayer dragLayer = mLauncher.getDragLayer(); |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 3641 | if (animationType == CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION) { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3642 | mLauncher.getDragLayer().animateViewIntoPosition(dragView, finalPos, 0f, 0.1f, 0.1f, |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3643 | DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration); |
| 3644 | } else { |
Adam Cohen | d41fbf5 | 2012-02-16 23:53:59 -0800 | [diff] [blame] | 3645 | int endStyle; |
| 3646 | if (animationType == ANIMATE_INTO_POSITION_AND_REMAIN) { |
| 3647 | endStyle = DragLayer.ANIMATION_END_REMAIN_VISIBLE; |
| 3648 | } else { |
| 3649 | endStyle = DragLayer.ANIMATION_END_DISAPPEAR;; |
| 3650 | } |
| 3651 | |
| 3652 | Runnable onComplete = new Runnable() { |
| 3653 | @Override |
| 3654 | public void run() { |
| 3655 | if (finalView != null) { |
| 3656 | finalView.setVisibility(VISIBLE); |
| 3657 | } |
| 3658 | if (onCompleteRunnable != null) { |
| 3659 | onCompleteRunnable.run(); |
| 3660 | } |
| 3661 | } |
| 3662 | }; |
| 3663 | dragLayer.animateViewIntoPosition(dragView, from.left, from.top, finalPos[0], |
| 3664 | finalPos[1], 1, 1, 1, scaleXY[0], scaleXY[1], onComplete, endStyle, |
| 3665 | duration, this); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 3666 | } |
| 3667 | } |
| 3668 | |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3669 | public void setFinalTransitionTransform(CellLayout layout) { |
| 3670 | if (isSwitchingState()) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3671 | mCurrentScale = getScaleX(); |
Winson Chung | dc61c4d | 2015-04-20 18:26:57 -0700 | [diff] [blame] | 3672 | setScaleX(mStateTransitionAnimation.getFinalScale()); |
| 3673 | setScaleY(mStateTransitionAnimation.getFinalScale()); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | public void resetTransitionTransform(CellLayout layout) { |
| 3677 | if (isSwitchingState()) { |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 3678 | setScaleX(mCurrentScale); |
| 3679 | setScaleY(mCurrentScale); |
Adam Cohen | 4b285c5 | 2011-07-21 14:24:06 -0700 | [diff] [blame] | 3680 | } |
| 3681 | } |
| 3682 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3683 | /** |
| 3684 | * Return the current {@link CellLayout}, correctly picking the destination |
| 3685 | * screen while a scroll is in progress. |
| 3686 | */ |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3687 | public CellLayout getCurrentDropLayout() { |
Winson Chung | 360e63f | 2012-04-27 13:48:05 -0700 | [diff] [blame] | 3688 | return (CellLayout) getChildAt(getNextPage()); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3689 | } |
| 3690 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3691 | /** |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3692 | * Return the current CellInfo describing our current drag; this method exists |
| 3693 | * so that Launcher can sync this object with the correct info when the activity is created/ |
| 3694 | * destroyed |
| 3695 | * |
| 3696 | */ |
| 3697 | public CellLayout.CellInfo getDragInfo() { |
| 3698 | return mDragInfo; |
| 3699 | } |
| 3700 | |
Winson Chung | 9b9fb96 | 2013-11-15 15:39:34 -0800 | [diff] [blame] | 3701 | public int getCurrentPageOffsetFromCustomContent() { |
Adam Cohen | 21cd002 | 2013-10-09 18:57:02 -0700 | [diff] [blame] | 3702 | return getNextPage() - numCustomPages(); |
| 3703 | } |
| 3704 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3705 | /** |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3706 | * Calculate the nearest cell where the given object would be dropped. |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3707 | * |
| 3708 | * pixelX and pixelY should be in the coordinate system of layout |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 3709 | */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 3710 | @Thunk int[] findNearestArea(int pixelX, int pixelY, |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3711 | int spanX, int spanY, CellLayout layout, int[] recycle) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3712 | return layout.findNearestArea( |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 3713 | pixelX, pixelY, spanX, spanY, recycle); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 3716 | void setup(DragController dragController) { |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 3717 | mSpringLoadedDragController = new SpringLoadedDragController(mLauncher); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3718 | mDragController = dragController; |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3719 | |
Michael Jurka | d74c984 | 2011-07-10 12:44:21 -0700 | [diff] [blame] | 3720 | // hardware layers on children are enabled on startup, but should be disabled until |
| 3721 | // needed |
Michael Jurka | 3a0469d | 2012-06-21 09:38:41 -0700 | [diff] [blame] | 3722 | updateChildrenLayersEnabled(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3723 | } |
| 3724 | |
Patrick Dubroy | e3887cc | 2011-01-20 10:43:40 -0800 | [diff] [blame] | 3725 | /** |
| 3726 | * Called at the end of a drag which originated on the workspace. |
| 3727 | */ |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3728 | public void onDropCompleted(final View target, final DragObject d, |
| 3729 | final boolean isFlingToDelete, final boolean success) { |
| 3730 | if (mDeferDropAfterUninstall) { |
| 3731 | mDeferredAction = new Runnable() { |
Adam Cohen | ad4e15c | 2013-10-17 16:21:35 -0700 | [diff] [blame] | 3732 | public void run() { |
| 3733 | onDropCompleted(target, d, isFlingToDelete, success); |
| 3734 | mDeferredAction = null; |
| 3735 | } |
| 3736 | }; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3737 | return; |
| 3738 | } |
| 3739 | |
| 3740 | boolean beingCalledAfterUninstall = mDeferredAction != null; |
| 3741 | |
| 3742 | if (success && !(beingCalledAfterUninstall && !mUninstallSuccessful)) { |
Sunny Goyal | 95deb3a | 2015-03-05 10:27:01 -0800 | [diff] [blame] | 3743 | if (target != this && mDragInfo != null) { |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3744 | removeWorkspaceItem(mDragInfo.cell); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3745 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 3746 | } else if (mDragInfo != null) { |
Sunny Goyal | 9282059 | 2015-03-02 11:31:35 -0800 | [diff] [blame] | 3747 | final CellLayout cellLayout = mLauncher.getCellLayout( |
| 3748 | mDragInfo.container, mDragInfo.screenId); |
Jorim Jaggi | eedb00a | 2014-01-13 13:45:07 -0800 | [diff] [blame] | 3749 | if (cellLayout != null) { |
| 3750 | cellLayout.onDropChild(mDragInfo.cell); |
Sunny Goyal | 9282059 | 2015-03-02 11:31:35 -0800 | [diff] [blame] | 3751 | } else if (LauncherAppState.isDogfoodBuild()) { |
| 3752 | throw new RuntimeException("Invalid state: cellLayout == null in " |
| 3753 | + "Workspace#onDropCompleted. Please file a bug. "); |
| 3754 | }; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3755 | } |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3756 | if ((d.cancelled || (beingCalledAfterUninstall && !mUninstallSuccessful)) |
| 3757 | && mDragInfo.cell != null) { |
| 3758 | mDragInfo.cell.setVisibility(VISIBLE); |
Adam Cohen | 36cc09b | 2011-09-29 17:33:15 -0700 | [diff] [blame] | 3759 | } |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 3760 | mDragOutline = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3761 | mDragInfo = null; |
| 3762 | } |
| 3763 | |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 3764 | /** |
| 3765 | * For opposite operation. See {@link #addInScreen}. |
| 3766 | */ |
Sunny Goyal | 71b5c0b | 2015-01-08 16:59:04 -0800 | [diff] [blame] | 3767 | public void removeWorkspaceItem(View v) { |
| 3768 | CellLayout parentCell = getParentCellLayoutForView(v); |
| 3769 | if (parentCell != null) { |
| 3770 | parentCell.removeView(v); |
| 3771 | } else if (LauncherAppState.isDogfoodBuild()) { |
| 3772 | throw new NullPointerException("mDragInfo.cell has null parent"); |
| 3773 | } |
| 3774 | if (v instanceof DropTarget) { |
| 3775 | mDragController.removeDropTarget((DropTarget) v); |
| 3776 | } |
| 3777 | } |
| 3778 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 3779 | @Override |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3780 | public void deferCompleteDropAfterUninstallActivity() { |
| 3781 | mDeferDropAfterUninstall = true; |
| 3782 | } |
| 3783 | |
| 3784 | /// maybe move this into a smaller part |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 3785 | @Override |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 3786 | public void onUninstallActivityReturned(boolean success) { |
| 3787 | mDeferDropAfterUninstall = false; |
| 3788 | mUninstallSuccessful = success; |
| 3789 | if (mDeferredAction != null) { |
| 3790 | mDeferredAction.run(); |
| 3791 | } |
| 3792 | } |
| 3793 | |
Adam Cohen | ea889a2 | 2012-03-27 16:45:39 -0700 | [diff] [blame] | 3794 | void updateItemLocationsInDatabase(CellLayout cl) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3795 | int count = cl.getShortcutsAndWidgets().getChildCount(); |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 3796 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3797 | long screenId = getIdForScreen(cl); |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 3798 | int container = Favorites.CONTAINER_DESKTOP; |
| 3799 | |
| 3800 | if (mLauncher.isHotseatLayout(cl)) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3801 | screenId = -1; |
Adam Cohen | d346171 | 2012-03-29 17:25:17 -0700 | [diff] [blame] | 3802 | container = Favorites.CONTAINER_HOTSEAT; |
| 3803 | } |
| 3804 | |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3805 | for (int i = 0; i < count; i++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 3806 | View v = cl.getShortcutsAndWidgets().getChildAt(i); |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3807 | ItemInfo info = (ItemInfo) v.getTag(); |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 3808 | // 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] | 3809 | if (info != null && info.requiresDbUpdate) { |
| 3810 | info.requiresDbUpdate = false; |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3811 | LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, info.cellX, |
Adam Cohen | bebf042 | 2012-04-11 18:06:28 -0700 | [diff] [blame] | 3812 | info.cellY, info.spanX, info.spanY); |
Adam Cohen | 2acce88 | 2012-03-28 19:03:19 -0700 | [diff] [blame] | 3813 | } |
Adam Cohen | 482ed82 | 2012-03-02 14:15:13 -0800 | [diff] [blame] | 3814 | } |
| 3815 | } |
| 3816 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 3817 | void saveWorkspaceToDb() { |
| 3818 | saveWorkspaceScreenToDb((CellLayout) mLauncher.getHotseat().getLayout()); |
| 3819 | int count = getChildCount(); |
| 3820 | for (int i = 0; i < count; i++) { |
| 3821 | CellLayout cl = (CellLayout) getChildAt(i); |
| 3822 | saveWorkspaceScreenToDb(cl); |
| 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | void saveWorkspaceScreenToDb(CellLayout cl) { |
| 3827 | int count = cl.getShortcutsAndWidgets().getChildCount(); |
| 3828 | |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3829 | long screenId = getIdForScreen(cl); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 3830 | int container = Favorites.CONTAINER_DESKTOP; |
| 3831 | |
Winson Chung | f70696d | 2013-06-25 16:19:53 -0700 | [diff] [blame] | 3832 | Hotseat hotseat = mLauncher.getHotseat(); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 3833 | if (mLauncher.isHotseatLayout(cl)) { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 3834 | screenId = -1; |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 3835 | container = Favorites.CONTAINER_HOTSEAT; |
| 3836 | } |
| 3837 | |
| 3838 | for (int i = 0; i < count; i++) { |
| 3839 | View v = cl.getShortcutsAndWidgets().getChildAt(i); |
| 3840 | ItemInfo info = (ItemInfo) v.getTag(); |
| 3841 | // Null check required as the AllApps button doesn't have an item info |
| 3842 | if (info != null) { |
Winson Chung | f70696d | 2013-06-25 16:19:53 -0700 | [diff] [blame] | 3843 | int cellX = info.cellX; |
| 3844 | int cellY = info.cellY; |
| 3845 | if (container == Favorites.CONTAINER_HOTSEAT) { |
| 3846 | cellX = hotseat.getCellXFromOrder((int) info.screenId); |
| 3847 | cellY = hotseat.getCellYFromOrder((int) info.screenId); |
| 3848 | } |
Sunny Goyal | 1d4a2df | 2015-03-30 11:11:46 -0700 | [diff] [blame] | 3849 | LauncherModel.addItemToDatabase(mLauncher, info, container, screenId, cellX, cellY); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 3850 | } |
| 3851 | if (v instanceof FolderIcon) { |
| 3852 | FolderIcon fi = (FolderIcon) v; |
| 3853 | fi.getFolder().addItemLocationsInDatabase(); |
| 3854 | } |
| 3855 | } |
| 3856 | } |
| 3857 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 3858 | @Override |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 3859 | public float getIntrinsicIconScaleFactor() { |
| 3860 | return 1f; |
| 3861 | } |
| 3862 | |
| 3863 | @Override |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 3864 | public boolean supportsFlingToDelete() { |
| 3865 | return true; |
| 3866 | } |
| 3867 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 3868 | @Override |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 3869 | public boolean supportsAppInfoDropTarget() { |
| 3870 | return false; |
| 3871 | } |
| 3872 | |
| 3873 | @Override |
| 3874 | public boolean supportsDeleteDropTarget() { |
| 3875 | return true; |
| 3876 | } |
| 3877 | |
| 3878 | @Override |
Sunny Goyal | ddec734 | 2015-04-29 18:12:37 -0700 | [diff] [blame] | 3879 | public void onFlingToDelete(DragObject d, PointF vec) { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 3880 | // Do nothing |
| 3881 | } |
| 3882 | |
| 3883 | @Override |
| 3884 | public void onFlingToDeleteCompleted() { |
| 3885 | // Do nothing |
| 3886 | } |
| 3887 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3888 | public boolean isDropEnabled() { |
| 3889 | return true; |
| 3890 | } |
| 3891 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3892 | @Override |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 3893 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 3894 | // We don't dispatch restoreInstanceState to our children using this code path. |
Dave Hawkey | a888158 | 2013-09-17 15:55:33 -0600 | [diff] [blame] | 3895 | // 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] | 3896 | // others we will need to wait until after their items are bound. |
| 3897 | mSavedStates = container; |
| 3898 | } |
| 3899 | |
| 3900 | public void restoreInstanceStateForChild(int child) { |
| 3901 | if (mSavedStates != null) { |
| 3902 | mRestoredPages.add(child); |
| 3903 | CellLayout cl = (CellLayout) getChildAt(child); |
Adam Cohen | b0ee081 | 2013-12-03 10:51:45 -0800 | [diff] [blame] | 3904 | if (cl != null) { |
| 3905 | cl.restoreInstanceState(mSavedStates); |
| 3906 | } |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | public void restoreInstanceStateForRemainingPages() { |
| 3911 | int count = getChildCount(); |
| 3912 | for (int i = 0; i < count; i++) { |
| 3913 | if (!mRestoredPages.contains(i)) { |
| 3914 | restoreInstanceStateForChild(i); |
| 3915 | } |
| 3916 | } |
| 3917 | mRestoredPages.clear(); |
Winson Chung | d8e596d | 2013-10-21 17:14:12 -0700 | [diff] [blame] | 3918 | mSavedStates = null; |
Adam Cohen | 1462de3 | 2012-07-24 22:34:36 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3922 | public void scrollLeft() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3923 | if (!workspaceInModalState() && !mIsSwitchingState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3924 | super.scrollLeft(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3925 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 3926 | Folder openFolder = getOpenFolder(); |
| 3927 | if (openFolder != null) { |
| 3928 | openFolder.completeDragExit(); |
| 3929 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3930 | } |
| 3931 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3932 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3933 | public void scrollRight() { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3934 | if (!workspaceInModalState() && !mIsSwitchingState) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3935 | super.scrollRight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3936 | } |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 3937 | Folder openFolder = getOpenFolder(); |
| 3938 | if (openFolder != null) { |
| 3939 | openFolder.completeDragExit(); |
| 3940 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3941 | } |
| 3942 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3943 | @Override |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3944 | public boolean onEnterScrollArea(int x, int y, int direction) { |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 3945 | // Ignore the scroll area if we are dragging over the hot seat |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 3946 | boolean isPortrait = !LauncherAppState.isScreenLandscape(getContext()); |
Winson Chung | 10bfc6e | 2012-03-28 15:41:26 -0700 | [diff] [blame] | 3947 | if (mLauncher.getHotseat() != null && isPortrait) { |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 3948 | Rect r = new Rect(); |
| 3949 | mLauncher.getHotseat().getHitRect(r); |
| 3950 | if (r.contains(x, y)) { |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3951 | return false; |
Winson Chung | 1c4cf4a | 2011-07-29 14:49:10 -0700 | [diff] [blame] | 3952 | } |
| 3953 | } |
| 3954 | |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3955 | boolean result = false; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 3956 | if (!workspaceInModalState() && !mIsSwitchingState && getOpenFolder() == null) { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3957 | mInScrollArea = true; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3958 | |
Winson Chung | 360e63f | 2012-04-27 13:48:05 -0700 | [diff] [blame] | 3959 | final int page = getNextPage() + |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 3960 | (direction == DragController.SCROLL_LEFT ? -1 : 1); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3961 | // We always want to exit the current layout to ensure parity of enter / exit |
| 3962 | setCurrentDropLayout(null); |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3963 | |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 3964 | if (0 <= page && page < getChildCount()) { |
Winson Chung | 482a5b6 | 2013-07-31 17:19:51 -0700 | [diff] [blame] | 3965 | // Ensure that we are not dragging over to the custom content screen |
| 3966 | if (getScreenIdForPageIndex(page) == CUSTOM_CONTENT_SCREEN_ID) { |
| 3967 | return false; |
| 3968 | } |
| 3969 | |
Winson Chung | aa15ffe | 2012-01-18 15:45:28 -0800 | [diff] [blame] | 3970 | CellLayout layout = (CellLayout) getChildAt(page); |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3971 | setCurrentDragOverlappingLayout(layout); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3972 | |
| 3973 | // Workspace is responsible for drawing the edge glow on adjacent pages, |
| 3974 | // so we need to redraw the workspace when this may have changed. |
| 3975 | invalidate(); |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3976 | result = true; |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3977 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3978 | } |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3979 | return result; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | @Override |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3983 | public boolean onExitScrollArea() { |
| 3984 | boolean result = false; |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3985 | if (mInScrollArea) { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3986 | invalidate(); |
| 3987 | CellLayout layout = getCurrentDropLayout(); |
| 3988 | setCurrentDropLayout(layout); |
| 3989 | setCurrentDragOverlappingLayout(layout); |
| 3990 | |
Adam Cohen | 8a18afc | 2011-12-13 15:57:01 -0800 | [diff] [blame] | 3991 | result = true; |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3992 | mInScrollArea = false; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3993 | } |
Winson Chung | 3e0839e | 2011-10-03 15:15:18 -0700 | [diff] [blame] | 3994 | return result; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3995 | } |
| 3996 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3997 | private void onResetScrollArea() { |
Adam Cohen | c6cc61d | 2012-04-04 12:47:08 -0700 | [diff] [blame] | 3998 | setCurrentDragOverlappingLayout(null); |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 3999 | mInScrollArea = false; |
| 4000 | } |
| 4001 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4002 | /** |
| 4003 | * Returns a specific CellLayout |
| 4004 | */ |
| 4005 | CellLayout getParentCellLayoutForView(View v) { |
| 4006 | ArrayList<CellLayout> layouts = getWorkspaceAndHotseatCellLayouts(); |
| 4007 | for (CellLayout layout : layouts) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4008 | if (layout.getShortcutsAndWidgets().indexOfChild(v) > -1) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4009 | return layout; |
| 4010 | } |
| 4011 | } |
| 4012 | return null; |
| 4013 | } |
| 4014 | |
| 4015 | /** |
| 4016 | * Returns a list of all the CellLayouts in the workspace. |
| 4017 | */ |
| 4018 | ArrayList<CellLayout> getWorkspaceAndHotseatCellLayouts() { |
| 4019 | ArrayList<CellLayout> layouts = new ArrayList<CellLayout>(); |
| 4020 | int screenCount = getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4021 | for (int screen = 0; screen < screenCount; screen++) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4022 | layouts.add(((CellLayout) getChildAt(screen))); |
| 4023 | } |
| 4024 | if (mLauncher.getHotseat() != null) { |
| 4025 | layouts.add(mLauncher.getHotseat().getLayout()); |
| 4026 | } |
| 4027 | return layouts; |
| 4028 | } |
| 4029 | |
| 4030 | /** |
| 4031 | * 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] | 4032 | * ShortcutsAndWidgetsContainer directly. Includes ShortcutAndWidgetContainers from |
| 4033 | * the hotseat and workspace pages |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4034 | */ |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4035 | ArrayList<ShortcutAndWidgetContainer> getAllShortcutAndWidgetContainers() { |
| 4036 | ArrayList<ShortcutAndWidgetContainer> childrenLayouts = |
| 4037 | new ArrayList<ShortcutAndWidgetContainer>(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4038 | int screenCount = getChildCount(); |
| 4039 | for (int screen = 0; screen < screenCount; screen++) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4040 | childrenLayouts.add(((CellLayout) getChildAt(screen)).getShortcutsAndWidgets()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4041 | } |
| 4042 | if (mLauncher.getHotseat() != null) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4043 | childrenLayouts.add(mLauncher.getHotseat().getLayout().getShortcutsAndWidgets()); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4044 | } |
| 4045 | return childrenLayouts; |
| 4046 | } |
| 4047 | |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4048 | public Folder getFolderForTag(final Object tag) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4049 | return (Folder) getFirstMatch(new ItemOperator() { |
| 4050 | |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4051 | @Override |
| 4052 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4053 | return (v instanceof Folder) && (((Folder) v).getInfo() == tag) |
| 4054 | && ((Folder) v).getInfo().opened; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4055 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4056 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4057 | } |
| 4058 | |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4059 | public View getViewForTag(final Object tag) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4060 | return getFirstMatch(new ItemOperator() { |
| 4061 | |
| 4062 | @Override |
| 4063 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4064 | return info == tag; |
| 4065 | } |
| 4066 | }); |
| 4067 | } |
| 4068 | |
| 4069 | public LauncherAppWidgetHostView getWidgetForAppWidgetId(final int appWidgetId) { |
| 4070 | return (LauncherAppWidgetHostView) getFirstMatch(new ItemOperator() { |
| 4071 | |
| 4072 | @Override |
| 4073 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4074 | return (info instanceof LauncherAppWidgetInfo) && |
| 4075 | ((LauncherAppWidgetInfo) info).appWidgetId == appWidgetId; |
| 4076 | } |
| 4077 | }); |
| 4078 | } |
| 4079 | |
| 4080 | private View getFirstMatch(final ItemOperator operator) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4081 | final View[] value = new View[1]; |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4082 | mapOverItems(MAP_NO_RECURSE, new ItemOperator() { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4083 | @Override |
| 4084 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4085 | if (operator.evaluate(info, v, parent)) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4086 | value[0] = v; |
| 4087 | return true; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4088 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4089 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4090 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4091 | }); |
| 4092 | return value[0]; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4093 | } |
| 4094 | |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4095 | void clearDropTargets() { |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4096 | mapOverItems(MAP_NO_RECURSE, new ItemOperator() { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4097 | @Override |
| 4098 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4099 | if (v instanceof DropTarget) { |
| 4100 | mDragController.removeDropTarget((DropTarget) v); |
| 4101 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4102 | // not done, process all the shortcuts |
| 4103 | return false; |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4104 | } |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4105 | }); |
Adam Cohen | df03538 | 2011-04-11 17:22:04 -0700 | [diff] [blame] | 4106 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4107 | |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4108 | public void disableShortcutsByPackageName(final ArrayList<String> packages, |
| 4109 | final UserHandleCompat user, final int reason) { |
| 4110 | final HashSet<String> packageNames = new HashSet<String>(); |
| 4111 | packageNames.addAll(packages); |
| 4112 | |
| 4113 | mapOverItems(MAP_RECURSE, new ItemOperator() { |
| 4114 | @Override |
| 4115 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4116 | if (info instanceof ShortcutInfo && v instanceof BubbleTextView) { |
| 4117 | ShortcutInfo shortcutInfo = (ShortcutInfo) info; |
| 4118 | ComponentName cn = shortcutInfo.getTargetComponent(); |
| 4119 | if (user.equals(shortcutInfo.user) && cn != null |
| 4120 | && packageNames.contains(cn.getPackageName())) { |
| 4121 | shortcutInfo.isDisabled |= reason; |
| 4122 | BubbleTextView shortcut = (BubbleTextView) v; |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 4123 | shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache); |
Sunny Goyal | 1a745e8 | 2014-10-02 15:58:31 -0700 | [diff] [blame] | 4124 | |
| 4125 | if (parent != null) { |
| 4126 | parent.invalidate(); |
| 4127 | } |
| 4128 | } |
| 4129 | } |
| 4130 | // process all the shortcuts |
| 4131 | return false; |
| 4132 | } |
| 4133 | }); |
| 4134 | } |
| 4135 | |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4136 | // Removes ALL items that match a given package name, this is usually called when a package |
| 4137 | // has been removed and we want to remove all components (widgets, shortcuts, apps) that |
| 4138 | // belong to that package. |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4139 | void removeItemsByPackageName(final ArrayList<String> packages, final UserHandleCompat user) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4140 | final HashSet<String> packageNames = new HashSet<String>(); |
Winson Chung | cd81073 | 2012-06-18 16:45:43 -0700 | [diff] [blame] | 4141 | packageNames.addAll(packages); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 4142 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4143 | // Filter out all the ItemInfos that this is going to affect |
| 4144 | final HashSet<ItemInfo> infos = new HashSet<ItemInfo>(); |
| 4145 | final HashSet<ComponentName> cns = new HashSet<ComponentName>(); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4146 | ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); |
| 4147 | for (CellLayout layoutParent : cellLayouts) { |
| 4148 | ViewGroup layout = layoutParent.getShortcutsAndWidgets(); |
| 4149 | int childCount = layout.getChildCount(); |
| 4150 | for (int i = 0; i < childCount; ++i) { |
| 4151 | View view = layout.getChildAt(i); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4152 | infos.add((ItemInfo) view.getTag()); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4153 | } |
| 4154 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4155 | LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { |
| 4156 | @Override |
| 4157 | public boolean filterItem(ItemInfo parent, ItemInfo info, |
| 4158 | ComponentName cn) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4159 | if (packageNames.contains(cn.getPackageName()) |
| 4160 | && info.user.equals(user)) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4161 | cns.add(cn); |
| 4162 | return true; |
| 4163 | } |
| 4164 | return false; |
| 4165 | } |
| 4166 | }; |
| 4167 | LauncherModel.filterItemInfos(infos, filter); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4168 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4169 | // Remove the affected components |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4170 | removeItemsByComponentName(cns, user); |
Winson Chung | 83892cc | 2013-05-01 16:53:33 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4173 | /** |
| 4174 | * Removes items that match the item info specified. When applications are removed |
| 4175 | * as a part of an update, this is called to ensure that other widgets and application |
| 4176 | * shortcuts are not removed. |
| 4177 | */ |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4178 | void removeItemsByComponentName(final HashSet<ComponentName> componentNames, |
| 4179 | final UserHandleCompat user) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 4180 | ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); |
| 4181 | for (final CellLayout layoutParent: cellLayouts) { |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 4182 | final ViewGroup layout = layoutParent.getShortcutsAndWidgets(); |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 4183 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4184 | final HashMap<ItemInfo, View> children = new HashMap<ItemInfo, View>(); |
| 4185 | for (int j = 0; j < layout.getChildCount(); j++) { |
| 4186 | final View view = layout.getChildAt(j); |
| 4187 | children.put((ItemInfo) view.getTag(), view); |
| 4188 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 4189 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4190 | final ArrayList<View> childrenToRemove = new ArrayList<View>(); |
| 4191 | final HashMap<FolderInfo, ArrayList<ShortcutInfo>> folderAppsToRemove = |
| 4192 | new HashMap<FolderInfo, ArrayList<ShortcutInfo>>(); |
| 4193 | LauncherModel.ItemInfoFilter filter = new LauncherModel.ItemInfoFilter() { |
| 4194 | @Override |
| 4195 | public boolean filterItem(ItemInfo parent, ItemInfo info, |
| 4196 | ComponentName cn) { |
| 4197 | if (parent instanceof FolderInfo) { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4198 | if (componentNames.contains(cn) && info.user.equals(user)) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4199 | FolderInfo folder = (FolderInfo) parent; |
| 4200 | ArrayList<ShortcutInfo> appsToRemove; |
| 4201 | if (folderAppsToRemove.containsKey(folder)) { |
| 4202 | appsToRemove = folderAppsToRemove.get(folder); |
| 4203 | } else { |
| 4204 | appsToRemove = new ArrayList<ShortcutInfo>(); |
| 4205 | folderAppsToRemove.put(folder, appsToRemove); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 4206 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4207 | appsToRemove.add((ShortcutInfo) info); |
| 4208 | return true; |
| 4209 | } |
| 4210 | } else { |
Kenny Guy | ed13187 | 2014-04-30 03:02:21 +0100 | [diff] [blame] | 4211 | if (componentNames.contains(cn) && info.user.equals(user)) { |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4212 | childrenToRemove.add(children.get(info)); |
| 4213 | return true; |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 4214 | } |
| 4215 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4216 | return false; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4217 | } |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4218 | }; |
| 4219 | LauncherModel.filterItemInfos(children.keySet(), filter); |
| 4220 | |
| 4221 | // Remove all the apps from their folders |
| 4222 | for (FolderInfo folder : folderAppsToRemove.keySet()) { |
| 4223 | ArrayList<ShortcutInfo> appsToRemove = folderAppsToRemove.get(folder); |
| 4224 | for (ShortcutInfo info : appsToRemove) { |
| 4225 | folder.remove(info); |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | // Remove all the other children |
| 4230 | for (View child : childrenToRemove) { |
| 4231 | // Note: We can not remove the view directly from CellLayoutChildren as this |
| 4232 | // does not re-mark the spaces as unoccupied. |
| 4233 | layoutParent.removeViewInLayout(child); |
| 4234 | if (child instanceof DropTarget) { |
| 4235 | mDragController.removeDropTarget((DropTarget) child); |
| 4236 | } |
| 4237 | } |
| 4238 | |
| 4239 | if (childrenToRemove.size() > 0) { |
| 4240 | layout.requestLayout(); |
| 4241 | layout.invalidate(); |
| 4242 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4243 | } |
Winson Chung | 2efec4e | 2012-05-03 12:31:48 -0700 | [diff] [blame] | 4244 | |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4245 | // Strip all the empty screens |
| 4246 | stripEmptyScreens(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4247 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4248 | |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4249 | interface ItemOperator { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4250 | /** |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4251 | * Process the next itemInfo, possibly with side-effect on {@link ItemOperator#value}. |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4252 | * |
| 4253 | * @param info info for the shortcut |
| 4254 | * @param view view for the shortcut |
| 4255 | * @param parent containing folder, or null |
| 4256 | * @return true if done, false to continue the map |
| 4257 | */ |
| 4258 | public boolean evaluate(ItemInfo info, View view, View parent); |
| 4259 | } |
| 4260 | |
| 4261 | /** |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4262 | * 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] | 4263 | * |
| 4264 | * @param recurse true: iterate over folder children. false: op get the folders themselves. |
| 4265 | * @param op the operator to map over the shortcuts |
| 4266 | */ |
Sunny Goyal | 651077b | 2014-06-30 14:15:31 -0700 | [diff] [blame] | 4267 | void mapOverItems(boolean recurse, ItemOperator op) { |
Chris Wren | aeff7ea | 2014-02-14 16:59:24 -0500 | [diff] [blame] | 4268 | ArrayList<ShortcutAndWidgetContainer> containers = getAllShortcutAndWidgetContainers(); |
| 4269 | final int containerCount = containers.size(); |
| 4270 | for (int containerIdx = 0; containerIdx < containerCount; containerIdx++) { |
| 4271 | ShortcutAndWidgetContainer container = containers.get(containerIdx); |
| 4272 | // map over all the shortcuts on the workspace |
| 4273 | final int itemCount = container.getChildCount(); |
| 4274 | for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { |
| 4275 | View item = container.getChildAt(itemIdx); |
| 4276 | ItemInfo info = (ItemInfo) item.getTag(); |
| 4277 | if (recurse && info instanceof FolderInfo && item instanceof FolderIcon) { |
| 4278 | FolderIcon folder = (FolderIcon) item; |
| 4279 | ArrayList<View> folderChildren = folder.getFolder().getItemsInReadingOrder(); |
| 4280 | // map over all the children in the folder |
| 4281 | final int childCount = folderChildren.size(); |
| 4282 | for (int childIdx = 0; childIdx < childCount; childIdx++) { |
| 4283 | View child = folderChildren.get(childIdx); |
| 4284 | info = (ItemInfo) child.getTag(); |
| 4285 | if (op.evaluate(info, child, folder)) { |
| 4286 | return; |
| 4287 | } |
| 4288 | } |
| 4289 | } else { |
| 4290 | if (op.evaluate(info, item, null)) { |
| 4291 | return; |
| 4292 | } |
| 4293 | } |
| 4294 | } |
| 4295 | } |
| 4296 | } |
| 4297 | |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4298 | void updateShortcuts(ArrayList<ShortcutInfo> shortcuts) { |
| 4299 | final HashSet<ShortcutInfo> updates = new HashSet<ShortcutInfo>(shortcuts); |
| 4300 | mapOverItems(MAP_RECURSE, new ItemOperator() { |
| 4301 | @Override |
| 4302 | public boolean evaluate(ItemInfo info, View v, View parent) { |
| 4303 | if (info instanceof ShortcutInfo && v instanceof BubbleTextView && |
| 4304 | updates.contains(info)) { |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4305 | ShortcutInfo si = (ShortcutInfo) info; |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4306 | BubbleTextView shortcut = (BubbleTextView) v; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 4307 | boolean oldPromiseState = getTextViewIcon(shortcut) |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4308 | instanceof PreloadIconDrawable; |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 4309 | shortcut.applyFromShortcutInfo(si, mIconCache, |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4310 | si.isPromise() != oldPromiseState); |
Sunny Goyal | b50cc8c | 2014-10-06 16:23:56 -0700 | [diff] [blame] | 4311 | |
| 4312 | if (parent != null) { |
| 4313 | parent.invalidate(); |
| 4314 | } |
| 4315 | } |
| 4316 | // process all the shortcuts |
| 4317 | return false; |
| 4318 | } |
| 4319 | }); |
| 4320 | } |
| 4321 | |
Sunny Goyal | e7b8cd9 | 2014-08-27 14:04:33 -0700 | [diff] [blame] | 4322 | public void removeAbandonedPromise(String packageName, UserHandleCompat user) { |
| 4323 | ArrayList<String> packages = new ArrayList<String>(1); |
| 4324 | packages.add(packageName); |
| 4325 | LauncherModel.deletePackageFromDatabase(mLauncher, packageName, user); |
| 4326 | removeItemsByPackageName(packages, user); |
Chris Wren | 40c5ed3 | 2014-06-24 18:24:23 -0400 | [diff] [blame] | 4327 | } |
| 4328 | |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 4329 | public void updateRestoreItems(final HashSet<ItemInfo> updates) { |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 4330 | mapOverItems(MAP_RECURSE, new ItemOperator() { |
| 4331 | @Override |
| 4332 | public boolean evaluate(ItemInfo info, View v, View parent) { |
Sunny Goyal | 756adbc | 2015-04-16 15:20:51 -0700 | [diff] [blame] | 4333 | if (info instanceof ShortcutInfo && v instanceof BubbleTextView |
| 4334 | && updates.contains(info)) { |
| 4335 | ((BubbleTextView) v).applyState(false); |
| 4336 | } else if (v instanceof PendingAppWidgetHostView |
| 4337 | && info instanceof LauncherAppWidgetInfo |
| 4338 | && updates.contains(info)) { |
| 4339 | ((PendingAppWidgetHostView) v).applyState(); |
Sunny Goyal | a22666f | 2014-09-18 13:25:15 -0700 | [diff] [blame] | 4340 | } |
| 4341 | // process all the shortcuts |
| 4342 | return false; |
| 4343 | } |
| 4344 | }); |
| 4345 | } |
| 4346 | |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4347 | void widgetsRestored(ArrayList<LauncherAppWidgetInfo> changedInfo) { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4348 | if (!changedInfo.isEmpty()) { |
| 4349 | DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, |
| 4350 | mLauncher.getAppWidgetHost()); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 4351 | if (LauncherModel.getProviderInfo(getContext(), |
Robin Lee | 26ace12 | 2015-03-16 19:41:43 +0000 | [diff] [blame] | 4352 | changedInfo.get(0).providerName, |
| 4353 | changedInfo.get(0).user) != null) { |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4354 | // Re-inflate the widgets which have changed status |
| 4355 | widgetRefresh.run(); |
| 4356 | } else { |
| 4357 | // widgetRefresh will automatically run when the packages are updated. |
Sunny Goyal | 4390ace | 2014-10-13 11:33:11 -0700 | [diff] [blame] | 4358 | // For now just update the progress bars |
| 4359 | for (LauncherAppWidgetInfo info : changedInfo) { |
| 4360 | if (info.hostView instanceof PendingAppWidgetHostView) { |
| 4361 | info.installProgress = 100; |
| 4362 | ((PendingAppWidgetHostView) info.hostView).applyState(); |
| 4363 | } |
| 4364 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4365 | } |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 4366 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 4367 | } |
| 4368 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4369 | private void moveToScreen(int page, boolean animate) { |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 4370 | if (!workspaceInModalState()) { |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 4371 | if (animate) { |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4372 | snapToPage(page); |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 4373 | } else { |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4374 | setCurrentPage(page); |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 4375 | } |
Joe Onorato | c45b168 | 2010-01-11 18:48:40 -0500 | [diff] [blame] | 4376 | } |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4377 | View child = getChildAt(page); |
Winson Chung | 64359a5 | 2013-07-08 17:17:08 -0700 | [diff] [blame] | 4378 | if (child != null) { |
| 4379 | child.requestFocus(); |
| 4380 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4381 | } |
| 4382 | |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4383 | void moveToDefaultScreen(boolean animate) { |
| 4384 | moveToScreen(mDefaultPage, animate); |
| 4385 | } |
| 4386 | |
| 4387 | void moveToCustomContentScreen(boolean animate) { |
| 4388 | if (hasCustomContent()) { |
| 4389 | int ccIndex = getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID); |
| 4390 | if (animate) { |
| 4391 | snapToPage(ccIndex); |
| 4392 | } else { |
| 4393 | setCurrentPage(ccIndex); |
| 4394 | } |
| 4395 | View child = getChildAt(ccIndex); |
| 4396 | if (child != null) { |
| 4397 | child.requestFocus(); |
| 4398 | } |
| 4399 | } |
Adam Cohen | 76128b6 | 2013-11-14 16:43:59 +0000 | [diff] [blame] | 4400 | exitWidgetResizeMode(); |
Allan Wojciechowski | af110e8 | 2013-09-12 10:48:23 +0100 | [diff] [blame] | 4401 | } |
| 4402 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 4403 | @Override |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4404 | protected PageIndicator.PageMarkerResources getPageIndicatorMarker(int pageIndex) { |
| 4405 | long screenId = getScreenIdForPageIndex(pageIndex); |
| 4406 | if (screenId == EXTRA_EMPTY_SCREEN_ID) { |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 4407 | int count = mScreenOrder.size() - numCustomPages(); |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4408 | if (count > 1) { |
Winson Chung | ba4e52f | 2013-10-01 17:22:13 -0700 | [diff] [blame] | 4409 | return new PageIndicator.PageMarkerResources(R.drawable.ic_pageindicator_current, |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4410 | R.drawable.ic_pageindicator_add); |
| 4411 | } |
Winson Chung | 82dfe58 | 2013-07-26 15:07:49 -0700 | [diff] [blame] | 4412 | } |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 4413 | |
Winson Chung | 82dfe58 | 2013-07-26 15:07:49 -0700 | [diff] [blame] | 4414 | return super.getPageIndicatorMarker(pageIndex); |
| 4415 | } |
| 4416 | |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 4417 | protected String getPageIndicatorDescription() { |
| 4418 | String settings = getResources().getString(R.string.settings_button_text); |
| 4419 | return getCurrentPageDescription() + ", " + settings; |
| 4420 | } |
| 4421 | |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 4422 | protected String getCurrentPageDescription() { |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 4423 | if (hasCustomContent() && getNextPage() == 0) { |
| 4424 | return mCustomContentDescription; |
| 4425 | } |
Sunny Goyal | 1d08f70 | 2015-05-04 15:50:25 -0700 | [diff] [blame] | 4426 | int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage; |
| 4427 | return getPageDescription(page); |
| 4428 | } |
| 4429 | |
| 4430 | private String getPageDescription(int page) { |
| 4431 | int delta = numCustomPages(); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 4432 | return String.format(getContext().getString(R.string.workspace_scroll_format), |
Adam Cohen | 5380521 | 2013-10-01 10:39:23 -0700 | [diff] [blame] | 4433 | page + 1 - delta, getChildCount() - delta); |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 4434 | } |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 4435 | |
| 4436 | public void getLocationInDragLayer(int[] loc) { |
| 4437 | mLauncher.getDragLayer().getLocationInDragLayer(this, loc); |
| 4438 | } |
Sunny Goyal | 0fc1be1 | 2014-08-11 17:05:23 -0700 | [diff] [blame] | 4439 | |
| 4440 | /** |
| 4441 | * Used as a workaround to ensure that the AppWidgetService receives the |
| 4442 | * PACKAGE_ADDED broadcast before updating widgets. |
| 4443 | */ |
| 4444 | private class DeferredWidgetRefresh implements Runnable { |
| 4445 | private final ArrayList<LauncherAppWidgetInfo> mInfos; |
| 4446 | private final LauncherAppWidgetHost mHost; |
| 4447 | private final Handler mHandler; |
| 4448 | |
| 4449 | private boolean mRefreshPending; |
| 4450 | |
| 4451 | public DeferredWidgetRefresh(ArrayList<LauncherAppWidgetInfo> infos, |
| 4452 | LauncherAppWidgetHost host) { |
| 4453 | mInfos = infos; |
| 4454 | mHost = host; |
| 4455 | mHandler = new Handler(); |
| 4456 | mRefreshPending = true; |
| 4457 | |
| 4458 | mHost.addProviderChangeListener(this); |
| 4459 | // Force refresh after 10 seconds, if we don't get the provider changed event. |
| 4460 | // This could happen when the provider is no longer available in the app. |
| 4461 | mHandler.postDelayed(this, 10000); |
| 4462 | } |
| 4463 | |
| 4464 | @Override |
| 4465 | public void run() { |
| 4466 | mHost.removeProviderChangeListener(this); |
| 4467 | mHandler.removeCallbacks(this); |
| 4468 | |
| 4469 | if (!mRefreshPending) { |
| 4470 | return; |
| 4471 | } |
| 4472 | |
| 4473 | mRefreshPending = false; |
| 4474 | |
| 4475 | for (LauncherAppWidgetInfo info : mInfos) { |
| 4476 | if (info.hostView instanceof PendingAppWidgetHostView) { |
| 4477 | PendingAppWidgetHostView view = (PendingAppWidgetHostView) info.hostView; |
| 4478 | mLauncher.removeAppWidget(info); |
| 4479 | |
| 4480 | CellLayout cl = (CellLayout) view.getParent().getParent(); |
| 4481 | // Remove the current widget |
| 4482 | cl.removeView(view); |
| 4483 | mLauncher.bindAppWidget(info); |
| 4484 | } |
| 4485 | } |
| 4486 | } |
| 4487 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 4488 | } |