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