The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 19 | import com.android.launcher.R; |
| 20 | import com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 21 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 22 | import android.animation.Animator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 23 | import android.animation.AnimatorListenerAdapter; |
Chet Haase | b1254a6 | 2010-09-07 13:35:00 -0700 | [diff] [blame] | 24 | import android.animation.AnimatorSet; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 25 | import android.animation.ObjectAnimator; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 26 | import android.animation.TimeInterpolator; |
| 27 | import android.animation.ValueAnimator; |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 28 | import android.animation.Animator.AnimatorListener; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 29 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 30 | import android.app.AlertDialog; |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 31 | import android.app.WallpaperManager; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 32 | import android.appwidget.AppWidgetManager; |
| 33 | import android.appwidget.AppWidgetProviderInfo; |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 34 | import android.content.ClipData; |
| 35 | import android.content.ClipDescription; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 36 | import android.content.ComponentName; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | import android.content.Context; |
| 38 | import android.content.Intent; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 40 | import android.content.pm.ProviderInfo; |
Patrick Dubroy | 7247f63 | 2010-08-04 16:02:59 -0700 | [diff] [blame] | 41 | import android.content.res.Resources; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.content.res.TypedArray; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 43 | import android.graphics.Bitmap; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 44 | import android.graphics.Camera; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 45 | import android.graphics.Canvas; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 46 | import android.graphics.Matrix; |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 47 | import android.graphics.Paint; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.graphics.Rect; |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 49 | import android.graphics.RectF; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 50 | import android.graphics.Region.Op; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 51 | import android.graphics.drawable.Drawable; |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 52 | import android.net.Uri; |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 53 | import android.os.IBinder; |
Adam Powell | 495f289 | 2010-04-16 16:40:55 -0700 | [diff] [blame] | 54 | import android.os.Parcelable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 55 | import android.util.AttributeSet; |
Daniel Sandler | 291ad12 | 2010-05-24 16:03:53 -0400 | [diff] [blame] | 56 | import android.util.Log; |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 57 | import android.util.Pair; |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 58 | import android.view.Display; |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 59 | import android.view.DragEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 60 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 61 | import android.view.View; |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 62 | import android.view.ViewGroup; |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 63 | import android.view.animation.DecelerateInterpolator; |
Michael Jurka | 3c38d56 | 2011-02-18 19:22:12 -0800 | [diff] [blame] | 64 | import android.widget.TabHost; |
| 65 | import android.widget.TabWidget; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 66 | import android.widget.TextView; |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 67 | import android.widget.Toast; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 68 | |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 69 | import java.util.ArrayList; |
| 70 | import java.util.HashSet; |
| 71 | import java.util.List; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 72 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 73 | /** |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 74 | * The workspace is a wide area with a wallpaper and a finite number of pages. |
| 75 | * 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] | 76 | * 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] | 77 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 78 | public class Workspace extends SmoothPagedView |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 79 | implements DropTarget, DragSource, DragScroller, View.OnTouchListener, |
| 80 | View.OnClickListener { |
Romain Guy | e47f55c | 2009-11-11 19:21:22 -0800 | [diff] [blame] | 81 | @SuppressWarnings({"UnusedDeclaration"}) |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 82 | private static final String TAG = "Launcher.Workspace"; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 83 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 84 | // This is how much the workspace shrinks when we enter all apps or |
| 85 | // customization mode |
| 86 | private static final float SHRINK_FACTOR = 0.16f; |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 87 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 88 | // How much the screens shrink when we enter spring loaded drag mode |
| 89 | private static final float SPRING_LOADED_DRAG_SHRINK_FACTOR = 0.7f; |
| 90 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 91 | // Y rotation to apply to the workspace screens |
| 92 | private static final float WORKSPACE_ROTATION = 12.5f; |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 93 | |
| 94 | // These are extra scale factors to apply to the mini home screens |
| 95 | // so as to achieve the desired transform |
Adam Cohen | 1b0aaac | 2010-10-28 11:11:18 -0700 | [diff] [blame] | 96 | private static final float EXTRA_SCALE_FACTOR_0 = 0.972f; |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 97 | private static final float EXTRA_SCALE_FACTOR_1 = 1.0f; |
Adam Cohen | 1b0aaac | 2010-10-28 11:11:18 -0700 | [diff] [blame] | 98 | private static final float EXTRA_SCALE_FACTOR_2 = 1.10f; |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 99 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 100 | private static final int CHILDREN_OUTLINE_FADE_OUT_DELAY = 0; |
| 101 | private static final int CHILDREN_OUTLINE_FADE_OUT_DURATION = 375; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 102 | private static final int CHILDREN_OUTLINE_FADE_IN_DURATION = 100; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 103 | |
Winson Chung | f135c6c | 2010-11-18 16:32:08 -0800 | [diff] [blame] | 104 | private static final int BACKGROUND_FADE_OUT_DURATION = 350; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 105 | private static final int BACKGROUND_FADE_IN_DURATION = 350; |
| 106 | |
| 107 | // These animators are used to fade the children's outlines |
| 108 | private ObjectAnimator mChildrenOutlineFadeInAnimation; |
| 109 | private ObjectAnimator mChildrenOutlineFadeOutAnimation; |
| 110 | private float mChildrenOutlineAlpha = 0; |
| 111 | |
| 112 | // 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] | 113 | private ValueAnimator mBackgroundFadeInAnimation; |
| 114 | private ValueAnimator mBackgroundFadeOutAnimation; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 115 | private Drawable mBackground; |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 116 | private Drawable mCustomizeTrayBackground; |
Michael Jurka | 25356e7 | 2011-03-03 14:53:11 -0800 | [diff] [blame] | 117 | boolean mDrawBackground = true; |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 118 | private boolean mDrawCustomizeTrayBackground; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 119 | private float mBackgroundAlpha = 0; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 120 | private float mOverScrollMaxBackgroundAlpha = 0.0f; |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 121 | private int mOverScrollPageIndex = -1; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 122 | |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 123 | private View mCustomizationDrawer; |
| 124 | private View mCustomizationDrawerContent; |
| 125 | private int[] mCustomizationDrawerPos = new int[2]; |
| 126 | private float[] mCustomizationDrawerTransformedPos = new float[2]; |
| 127 | |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 128 | private final WallpaperManager mWallpaperManager; |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 129 | private IBinder mWindowToken; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 130 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 131 | private int mDefaultPage; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 132 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 133 | private boolean mIsDragInProcess = false; |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 134 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 135 | /** |
| 136 | * CellInfo for the cell that is currently being dragged |
| 137 | */ |
| 138 | private CellLayout.CellInfo mDragInfo; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 139 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Target drop area calculated during last acceptDrop call. |
| 142 | */ |
| 143 | private int[] mTargetCell = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 144 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 145 | /** |
| 146 | * The CellLayout that is currently being dragged over |
| 147 | */ |
| 148 | private CellLayout mDragTargetLayout = null; |
| 149 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 150 | private Launcher mLauncher; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 151 | private IconCache mIconCache; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 152 | private DragController mDragController; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 153 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 154 | // These are temporary variables to prevent having to allocate a new object just to |
| 155 | // 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] | 156 | private int[] mTempCell = new int[2]; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 157 | private int[] mTempEstimate = new int[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 158 | private float[] mTempOriginXY = new float[2]; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 159 | private float[] mTempDragCoordinates = new float[2]; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 160 | private float[] mTempTouchCoordinates = new float[2]; |
| 161 | private float[] mTempCellLayoutCenterCoordinates = new float[2]; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 162 | private float[] mTempDragBottomRightCoordinates = new float[2]; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 163 | private Matrix mTempInverseMatrix = new Matrix(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 164 | |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 165 | private SpringLoadedDragController mSpringLoadedDragController; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 166 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 167 | private static final int DEFAULT_CELL_COUNT_X = 4; |
| 168 | private static final int DEFAULT_CELL_COUNT_Y = 4; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 169 | |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 170 | private Drawable mPreviousIndicator; |
| 171 | private Drawable mNextIndicator; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 172 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 173 | // 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] | 174 | // in all apps or customize mode) |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 175 | private boolean mIsSmall = false; |
| 176 | private boolean mIsInUnshrinkAnimation = false; |
Michael Jurka | bea1519 | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 177 | private AnimatorListener mShrinkAnimationListener; |
Michael Jurka | b8e1447 | 2010-12-20 16:06:10 -0800 | [diff] [blame] | 178 | private AnimatorListener mUnshrinkAnimationListener; |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 179 | enum ShrinkState { TOP, SPRING_LOADED, MIDDLE, BOTTOM_HIDDEN, BOTTOM_VISIBLE }; |
| 180 | private ShrinkState mShrinkState; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 181 | private boolean mWasSpringLoadedOnDragExit = false; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 182 | private boolean mWaitingToShrink = false; |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 183 | private ShrinkState mWaitingToShrinkState; |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 184 | private AnimatorSet mAnimator; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 185 | |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 186 | /** 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] | 187 | private boolean mInScrollArea = false; |
| 188 | |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 189 | /** If mInScrollArea is true, the direction of the scroll. */ |
| 190 | private int mPendingScrollDirection = DragController.SCROLL_NONE; |
| 191 | |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 192 | private final HolographicOutlineHelper mOutlineHelper = new HolographicOutlineHelper(); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 193 | private Bitmap mDragOutline = null; |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 194 | private final Rect mTempRect = new Rect(); |
| 195 | private final int[] mTempXY = new int[2]; |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 196 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 197 | private ValueAnimator mDropAnim = null; |
| 198 | private TimeInterpolator mQuintEaseOutInterpolator = new DecelerateInterpolator(2.5f); |
| 199 | private View mDropView = null; |
| 200 | private int[] mDropViewPos = new int[] { -1, -1 }; |
| 201 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 202 | // Paint used to draw external drop outline |
| 203 | private final Paint mExternalDragOutlinePaint = new Paint(); |
| 204 | |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 205 | // Camera and Matrix used to determine the final position of a neighboring CellLayout |
| 206 | private final Matrix mMatrix = new Matrix(); |
| 207 | private final Camera mCamera = new Camera(); |
| 208 | private final float mTempFloat2[] = new float[2]; |
| 209 | |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 210 | enum WallpaperVerticalOffset { TOP, MIDDLE, BOTTOM }; |
| 211 | int mWallpaperWidth; |
| 212 | int mWallpaperHeight; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 213 | WallpaperOffsetInterpolator mWallpaperOffset; |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 214 | boolean mUpdateWallpaperOffsetImmediately = false; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 215 | boolean mSyncWallpaperOffsetWithScroll = true; |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 216 | private Runnable mDelayedResizeRunnable; |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 217 | |
Michael Jurka | 0bb8563 | 2011-01-26 00:00:44 -0800 | [diff] [blame] | 218 | // info about the last drag |
| 219 | private DragView mLastDragView; |
| 220 | private int mLastDragOriginX; |
| 221 | private int mLastDragOriginY; |
| 222 | private int mLastDragXOffset; |
| 223 | private int mLastDragYOffset; |
| 224 | |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 225 | // Variables relating to touch disambiguation (scrolling workspace vs. scrolling a widget) |
| 226 | private float mXDown; |
| 227 | private float mYDown; |
| 228 | final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6; |
| 229 | final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3; |
| 230 | final static float TOUCH_SLOP_DAMPING_FACTOR = 4; |
| 231 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 232 | /** |
| 233 | * Used to inflate the Workspace from XML. |
| 234 | * |
| 235 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 236 | * @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] | 237 | */ |
| 238 | public Workspace(Context context, AttributeSet attrs) { |
| 239 | this(context, attrs, 0); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Used to inflate the Workspace from XML. |
| 244 | * |
| 245 | * @param context The application's context. |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 246 | * @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] | 247 | * @param defStyle Unused. |
| 248 | */ |
| 249 | public Workspace(Context context, AttributeSet attrs, int defStyle) { |
| 250 | super(context, attrs, defStyle); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 251 | mContentIsRefreshable = false; |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 252 | |
| 253 | if (!LauncherApplication.isScreenXLarge()) { |
| 254 | mFadeInAdjacentScreens = false; |
| 255 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 256 | |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 257 | mWallpaperManager = WallpaperManager.getInstance(context); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 258 | |
| 259 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 260 | R.styleable.Workspace, defStyle, 0); |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 261 | int cellCountX = a.getInt(R.styleable.Workspace_cellCountX, DEFAULT_CELL_COUNT_X); |
| 262 | int cellCountY = a.getInt(R.styleable.Workspace_cellCountY, DEFAULT_CELL_COUNT_Y); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 263 | mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 264 | a.recycle(); |
| 265 | |
Adam Cohen | d22015c | 2010-07-26 22:02:18 -0700 | [diff] [blame] | 266 | LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY); |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 267 | setHapticFeedbackEnabled(false); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 268 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 269 | initWorkspace(); |
Winson Chung | c35afb2 | 2011-02-23 13:01:49 -0800 | [diff] [blame] | 270 | |
| 271 | // Disable multitouch across the workspace/all apps/customize tray |
| 272 | setMotionEventSplittingEnabled(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Initializes various states for this workspace. |
| 277 | */ |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 278 | protected void initWorkspace() { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 279 | Context context = getContext(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 280 | mCurrentPage = mDefaultPage; |
| 281 | Launcher.setScreen(mCurrentPage); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 282 | LauncherApplication app = (LauncherApplication)context.getApplicationContext(); |
| 283 | mIconCache = app.getIconCache(); |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 284 | mExternalDragOutlinePaint.setAntiAlias(true); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 285 | setWillNotDraw(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 286 | |
Winson Chung | b4b7fa7 | 2010-11-18 14:38:53 -0800 | [diff] [blame] | 287 | try { |
| 288 | final Resources res = getResources(); |
| 289 | mBackground = res.getDrawable(R.drawable.all_apps_bg_gradient); |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 290 | mCustomizeTrayBackground = res.getDrawable(R.drawable.customize_bg_gradient); |
Winson Chung | b4b7fa7 | 2010-11-18 14:38:53 -0800 | [diff] [blame] | 291 | } catch (Resources.NotFoundException e) { |
| 292 | // In this case, we will skip drawing background protection |
| 293 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 294 | |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 295 | mUnshrinkAnimationListener = new AnimatorListenerAdapter() { |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 296 | @Override |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 297 | public void onAnimationStart(Animator animation) { |
| 298 | mIsInUnshrinkAnimation = true; |
| 299 | } |
Michael Jurka | 0bb8563 | 2011-01-26 00:00:44 -0800 | [diff] [blame] | 300 | |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 301 | @Override |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 302 | public void onAnimationEnd(Animator animation) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 303 | mIsInUnshrinkAnimation = false; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 304 | mSyncWallpaperOffsetWithScroll = true; |
Michael Jurka | 0bb8563 | 2011-01-26 00:00:44 -0800 | [diff] [blame] | 305 | if (mShrinkState == ShrinkState.SPRING_LOADED) { |
| 306 | View layout = null; |
| 307 | if (mLastDragView != null) { |
| 308 | layout = findMatchingPageForDragOver(mLastDragView, mLastDragOriginX, |
| 309 | mLastDragOriginY, mLastDragXOffset, mLastDragYOffset); |
| 310 | } |
| 311 | mSpringLoadedDragController.onEnterSpringLoadedMode(layout == null); |
| 312 | } else { |
Winson Chung | a58f8bb | 2010-12-14 18:18:05 -0800 | [diff] [blame] | 313 | mDrawCustomizeTrayBackground = false; |
| 314 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 315 | mWallpaperOffset.setOverrideHorizontalCatchupConstant(false); |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 316 | mAnimator = null; |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 317 | enableChildrenLayers(false); |
Michael Jurka | bea1519 | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 318 | } |
| 319 | }; |
| 320 | mShrinkAnimationListener = new AnimatorListenerAdapter() { |
| 321 | @Override |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 322 | public void onAnimationStart(Animator animation) { |
| 323 | enableChildrenLayers(true); |
| 324 | } |
| 325 | @Override |
Michael Jurka | bea1519 | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 326 | public void onAnimationEnd(Animator animation) { |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 327 | mWallpaperOffset.setOverrideHorizontalCatchupConstant(false); |
Patrick Dubroy | 60b7c53 | 2011-01-16 17:19:32 -0800 | [diff] [blame] | 328 | mAnimator = null; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 329 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 330 | }; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 331 | mSnapVelocity = 600; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 332 | mWallpaperOffset = new WallpaperOffsetInterpolator(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 333 | } |
| 334 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 335 | @Override |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 336 | protected int getScrollMode() { |
| 337 | if (LauncherApplication.isScreenXLarge()) { |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 338 | return SmoothPagedView.X_LARGE_MODE; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 339 | } else { |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 340 | return SmoothPagedView.DEFAULT_MODE; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 345 | public void addView(View child, int index, LayoutParams params) { |
| 346 | if (!(child instanceof CellLayout)) { |
| 347 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 348 | } |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 349 | ((CellLayout) child).setOnInterceptTouchListener(this); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 350 | child.setOnClickListener(this); |
| 351 | child.setClickable(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 352 | super.addView(child, index, params); |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public void addView(View child) { |
| 357 | if (!(child instanceof CellLayout)) { |
| 358 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 359 | } |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 360 | ((CellLayout) child).setOnInterceptTouchListener(this); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 361 | child.setOnClickListener(this); |
| 362 | child.setClickable(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 363 | super.addView(child); |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public void addView(View child, int index) { |
| 368 | if (!(child instanceof CellLayout)) { |
| 369 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 370 | } |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 371 | ((CellLayout) child).setOnInterceptTouchListener(this); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 372 | child.setOnClickListener(this); |
| 373 | child.setClickable(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 374 | super.addView(child, index); |
| 375 | } |
| 376 | |
| 377 | @Override |
| 378 | public void addView(View child, int width, int height) { |
| 379 | if (!(child instanceof CellLayout)) { |
| 380 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 381 | } |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 382 | ((CellLayout) child).setOnInterceptTouchListener(this); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 383 | child.setOnClickListener(this); |
| 384 | child.setClickable(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 385 | super.addView(child, width, height); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void addView(View child, LayoutParams params) { |
| 390 | if (!(child instanceof CellLayout)) { |
| 391 | throw new IllegalArgumentException("A Workspace can only have CellLayout children."); |
| 392 | } |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 393 | ((CellLayout) child).setOnInterceptTouchListener(this); |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 394 | child.setOnClickListener(this); |
| 395 | child.setClickable(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 396 | super.addView(child, params); |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * @return The open folder on the current screen, or null if there is none |
| 401 | */ |
| 402 | Folder getOpenFolder() { |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 403 | ViewGroup currentPage = ((CellLayout) getChildAt(mCurrentPage)).getChildrenLayout(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 404 | int count = currentPage.getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 405 | for (int i = 0; i < count; i++) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 406 | View child = currentPage.getChildAt(i); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 407 | if (child instanceof Folder) { |
| 408 | Folder folder = (Folder) child; |
| 409 | if (folder.getInfo().opened) |
| 410 | return folder; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | return null; |
| 414 | } |
| 415 | |
| 416 | ArrayList<Folder> getOpenFolders() { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 417 | final int screenCount = getChildCount(); |
| 418 | ArrayList<Folder> folders = new ArrayList<Folder>(screenCount); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 419 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 420 | for (int screen = 0; screen < screenCount; screen++) { |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 421 | ViewGroup currentPage = ((CellLayout) getChildAt(screen)).getChildrenLayout(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 422 | int count = currentPage.getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 423 | for (int i = 0; i < count; i++) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 424 | View child = currentPage.getChildAt(i); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 425 | if (child instanceof Folder) { |
| 426 | Folder folder = (Folder) child; |
| 427 | if (folder.getInfo().opened) |
| 428 | folders.add(folder); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 429 | break; |
| 430 | } |
| 431 | } |
| 432 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 433 | return folders; |
| 434 | } |
| 435 | |
Patrick Dubroy | a0aa012 | 2011-02-24 11:42:23 -0800 | [diff] [blame] | 436 | boolean isTouchActive() { |
| 437 | return mTouchState != TOUCH_STATE_REST; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 441 | * Adds the specified child in the specified screen. The position and dimension of |
| 442 | * the child are defined by x, y, spanX and spanY. |
| 443 | * |
| 444 | * @param child The child to add in one of the workspace's screens. |
| 445 | * @param screen The screen in which to add the child. |
| 446 | * @param x The X position of the child in the screen's grid. |
| 447 | * @param y The Y position of the child in the screen's grid. |
| 448 | * @param spanX The number of cells spanned horizontally by the child. |
| 449 | * @param spanY The number of cells spanned vertically by the child. |
| 450 | */ |
| 451 | void addInScreen(View child, int screen, int x, int y, int spanX, int spanY) { |
| 452 | addInScreen(child, screen, x, y, spanX, spanY, false); |
| 453 | } |
| 454 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 455 | void addInFullScreen(View child, int screen) { |
| 456 | addInScreen(child, screen, 0, 0, -1, -1); |
| 457 | } |
| 458 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 459 | /** |
| 460 | * Adds the specified child in the specified screen. The position and dimension of |
| 461 | * the child are defined by x, y, spanX and spanY. |
| 462 | * |
| 463 | * @param child The child to add in one of the workspace's screens. |
| 464 | * @param screen The screen in which to add the child. |
| 465 | * @param x The X position of the child in the screen's grid. |
| 466 | * @param y The Y position of the child in the screen's grid. |
| 467 | * @param spanX The number of cells spanned horizontally by the child. |
| 468 | * @param spanY The number of cells spanned vertically by the child. |
| 469 | * @param insert When true, the child is inserted at the beginning of the children list. |
| 470 | */ |
| 471 | void addInScreen(View child, int screen, int x, int y, int spanX, int spanY, boolean insert) { |
| 472 | if (screen < 0 || screen >= getChildCount()) { |
Daniel Sandler | 291ad12 | 2010-05-24 16:03:53 -0400 | [diff] [blame] | 473 | Log.e(TAG, "The screen must be >= 0 and < " + getChildCount() |
| 474 | + " (was " + screen + "); skipping child"); |
| 475 | return; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | final CellLayout group = (CellLayout) getChildAt(screen); |
| 479 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); |
| 480 | if (lp == null) { |
| 481 | lp = new CellLayout.LayoutParams(x, y, spanX, spanY); |
| 482 | } else { |
| 483 | lp.cellX = x; |
| 484 | lp.cellY = y; |
| 485 | lp.cellHSpan = spanX; |
| 486 | lp.cellVSpan = spanY; |
| 487 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 488 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 489 | // Get the canonical child id to uniquely represent this view in this screen |
Michael Jurka | 845ba3b | 2010-09-28 17:09:46 -0700 | [diff] [blame] | 490 | int childId = LauncherModel.getCellLayoutChildId(-1, screen, x, y, spanX, spanY); |
Michael Jurka | f3ca3ab | 2010-10-20 17:08:24 -0700 | [diff] [blame] | 491 | boolean markCellsAsOccupied = !(child instanceof Folder); |
| 492 | if (!group.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 493 | // TODO: This branch occurs when the workspace is adding views |
| 494 | // outside of the defined grid |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 495 | // maybe we should be deleting these items from the LauncherModel? |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 496 | Log.w(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout"); |
| 497 | } |
| 498 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 499 | if (!(child instanceof Folder)) { |
Joe Onorato | 0d44e94 | 2009-11-16 18:20:51 -0800 | [diff] [blame] | 500 | child.setHapticFeedbackEnabled(false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 501 | child.setOnLongClickListener(mLongClickListener); |
| 502 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 503 | if (child instanceof DropTarget) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 504 | mDragController.addDropTarget((DropTarget) child); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 505 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 506 | } |
| 507 | |
Patrick Dubroy | d0ce1ec | 2011-01-19 18:47:27 -0800 | [diff] [blame] | 508 | /** |
| 509 | * Check if the point (x, y) hits a given page. |
| 510 | */ |
| 511 | private boolean hitsPage(int index, float x, float y) { |
| 512 | final View page = getChildAt(index); |
| 513 | if (page != null) { |
| 514 | float[] localXY = { x, y }; |
| 515 | mapPointFromSelfToChild(page, localXY); |
| 516 | return (localXY[0] >= 0 && localXY[0] < page.getWidth() |
| 517 | && localXY[1] >= 0 && localXY[1] < page.getHeight()); |
| 518 | } |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | protected boolean hitsPreviousPage(float x, float y) { |
| 524 | // mNextPage is set to INVALID_PAGE whenever we are stationary. |
| 525 | // Calculating "next page" this way ensures that you scroll to whatever page you tap on |
| 526 | final int current = (mNextPage == INVALID_PAGE) ? mCurrentPage : mNextPage; |
| 527 | return hitsPage(current - 1, x, y); |
| 528 | } |
| 529 | |
| 530 | @Override |
| 531 | protected boolean hitsNextPage(float x, float y) { |
| 532 | // mNextPage is set to INVALID_PAGE whenever we are stationary. |
| 533 | // Calculating "next page" this way ensures that you scroll to whatever page you tap on |
| 534 | final int current = (mNextPage == INVALID_PAGE) ? mCurrentPage : mNextPage; |
| 535 | return hitsPage(current + 1, x, y); |
| 536 | } |
| 537 | |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 538 | /** |
| 539 | * Called directly from a CellLayout (not by the framework), after we've been added as a |
| 540 | * listener via setOnInterceptTouchEventListener(). This allows us to tell the CellLayout |
| 541 | * that it should intercept touch events, which is not something that is normally supported. |
| 542 | */ |
| 543 | @Override |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 544 | public boolean onTouch(View v, MotionEvent event) { |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 545 | return (mIsSmall || mIsInUnshrinkAnimation); |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Handle a click event on a CellLayout. |
| 550 | */ |
| 551 | @Override |
| 552 | public void onClick(View cellLayout) { |
| 553 | // Only allow clicks on a CellLayout if it is shrunken and visible. |
| 554 | if ((mIsSmall || mIsInUnshrinkAnimation) && mShrinkState != ShrinkState.BOTTOM_HIDDEN) { |
| 555 | mLauncher.onWorkspaceClick((CellLayout) cellLayout); |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 556 | } |
Michael Jurka | 0e26059 | 2010-06-30 17:07:39 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Adam Cohen | ded9f8d | 2010-11-03 13:25:16 -0700 | [diff] [blame] | 559 | protected void onWindowVisibilityChanged (int visibility) { |
| 560 | mLauncher.onWindowVisibilityChanged(visibility); |
| 561 | } |
| 562 | |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 563 | @Override |
| 564 | public boolean dispatchUnhandledMove(View focused, int direction) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 565 | if (mIsSmall || mIsInUnshrinkAnimation) { |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 566 | // when the home screens are shrunken, shouldn't allow side-scrolling |
| 567 | return false; |
| 568 | } |
| 569 | return super.dispatchUnhandledMove(focused, direction); |
| 570 | } |
| 571 | |
| 572 | @Override |
| 573 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 574 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 575 | mXDown = ev.getX(); |
| 576 | mYDown = ev.getY(); |
| 577 | } |
| 578 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 579 | if (mIsSmall || mIsInUnshrinkAnimation) { |
Patrick Dubroy | e708c52 | 2011-03-01 16:03:43 -0800 | [diff] [blame] | 580 | if (mLauncher.isAllAppsVisible() && mShrinkState == ShrinkState.BOTTOM_HIDDEN) { |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 581 | // Intercept this event so we can show the workspace in full view |
| 582 | // when it is clicked on and it is small |
Adam Cohen | be90934 | 2011-01-28 17:02:58 -0800 | [diff] [blame] | 583 | AllAppsPagedView allApps = (AllAppsPagedView) |
| 584 | mLauncher.findViewById(R.id.all_apps_paged_view); |
| 585 | if (allApps != null) { |
| 586 | allApps.onInterceptTouchEvent(ev); |
| 587 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 588 | return true; |
| 589 | } |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 590 | return false; |
| 591 | } |
| 592 | return super.onInterceptTouchEvent(ev); |
| 593 | } |
| 594 | |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 595 | @Override |
| 596 | protected void determineScrollingStart(MotionEvent ev) { |
Adam Cohen | 69c42da | 2011-02-03 16:38:07 -0800 | [diff] [blame] | 597 | if (!mIsSmall && !mIsInUnshrinkAnimation) { |
| 598 | float deltaX = Math.abs(ev.getX() - mXDown); |
| 599 | float deltaY = Math.abs(ev.getY() - mYDown); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 600 | |
Adam Cohen | 69c42da | 2011-02-03 16:38:07 -0800 | [diff] [blame] | 601 | if (Float.compare(deltaX, 0f) == 0) return; |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 602 | |
Adam Cohen | 69c42da | 2011-02-03 16:38:07 -0800 | [diff] [blame] | 603 | float slope = deltaY / deltaX; |
| 604 | float theta = (float) Math.atan(slope); |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 605 | |
Adam Cohen | 69c42da | 2011-02-03 16:38:07 -0800 | [diff] [blame] | 606 | if (deltaX > mTouchSlop || deltaY > mTouchSlop) { |
| 607 | cancelCurrentPageLongPress(); |
| 608 | } |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 609 | |
Adam Cohen | 69c42da | 2011-02-03 16:38:07 -0800 | [diff] [blame] | 610 | if (theta > MAX_SWIPE_ANGLE) { |
| 611 | // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace |
| 612 | return; |
| 613 | } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) { |
| 614 | // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to |
| 615 | // increase the touch slop to make it harder to begin scrolling the workspace. This |
| 616 | // results in vertically scrolling widgets to more easily. The higher the angle, the |
| 617 | // more we increase touch slop. |
| 618 | theta -= START_DAMPING_TOUCH_SLOP_ANGLE; |
| 619 | float extraRatio = (float) |
| 620 | Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE))); |
| 621 | super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio); |
| 622 | } else { |
| 623 | // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special |
| 624 | super.determineScrollingStart(ev); |
| 625 | } |
Adam Cohen | f8d2823 | 2011-02-01 21:47:00 -0800 | [diff] [blame] | 626 | } |
Michael Jurka | 1adf539 | 2010-10-18 18:10:22 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 629 | protected void onPageBeginMoving() { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 630 | if (mNextPage != INVALID_PAGE) { |
| 631 | // we're snapping to a particular screen |
Michael Jurka | 16fed41 | 2010-10-01 16:12:03 -0700 | [diff] [blame] | 632 | enableChildrenCache(mCurrentPage, mNextPage); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 633 | } else { |
| 634 | // this is when user is actively dragging a particular screen, they might |
| 635 | // swipe it either left or right (but we won't advance by more than one screen) |
Michael Jurka | 16fed41 | 2010-10-01 16:12:03 -0700 | [diff] [blame] | 636 | enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 637 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 638 | showOutlines(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 641 | protected void onPageEndMoving() { |
Michael Jurka | 16fed41 | 2010-10-01 16:12:03 -0700 | [diff] [blame] | 642 | clearChildrenCache(); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 643 | // Hide the outlines, as long as we're not dragging |
| 644 | if (!mDragController.dragging()) { |
| 645 | hideOutlines(); |
| 646 | } |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 647 | mOverScrollMaxBackgroundAlpha = 0.0f; |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 648 | mOverScrollPageIndex = -1; |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 649 | |
| 650 | if (mDelayedResizeRunnable != null) { |
| 651 | mDelayedResizeRunnable.run(); |
| 652 | mDelayedResizeRunnable = null; |
| 653 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | @Override |
| 657 | protected void notifyPageSwitchListener() { |
| 658 | super.notifyPageSwitchListener(); |
| 659 | |
| 660 | if (mPreviousIndicator != null) { |
| 661 | // if we know the next page, we show the indication for it right away; it looks |
| 662 | // weird if the indicators are lagging |
| 663 | int page = mNextPage; |
| 664 | if (page == INVALID_PAGE) { |
| 665 | page = mCurrentPage; |
| 666 | } |
| 667 | mPreviousIndicator.setLevel(page); |
| 668 | mNextIndicator.setLevel(page); |
| 669 | } |
| 670 | Launcher.setScreen(mCurrentPage); |
| 671 | }; |
| 672 | |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 673 | // As a ratio of screen height, the total distance we want the parallax effect to span |
| 674 | // vertically |
| 675 | private float wallpaperTravelToScreenHeightRatio(int width, int height) { |
| 676 | return 1.1f; |
| 677 | } |
| 678 | |
| 679 | // As a ratio of screen height, the total distance we want the parallax effect to span |
| 680 | // horizontally |
| 681 | private float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 682 | float aspectRatio = width / (float) height; |
| 683 | |
| 684 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 685 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 686 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 687 | // to span (ie travel) at any aspect ratio: |
| 688 | |
| 689 | final float ASPECT_RATIO_LANDSCAPE = 16/10f; |
| 690 | final float ASPECT_RATIO_PORTRAIT = 10/16f; |
| 691 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 692 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 693 | |
| 694 | // To find out the desired width at different aspect ratios, we use the following two |
| 695 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 696 | // (16/10)x + y = 1.5 |
| 697 | // (10/16)x + y = 1.2 |
| 698 | // We solve for x and y and end up with a final formula: |
| 699 | final float x = |
| 700 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
| 701 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 702 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 703 | return x * aspectRatio + y; |
| 704 | } |
| 705 | |
| 706 | // The range of scroll values for Workspace |
| 707 | private int getScrollRange() { |
| 708 | return getChildOffset(getChildCount() - 1) - getChildOffset(0); |
| 709 | } |
| 710 | |
| 711 | protected void setWallpaperDimension() { |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 712 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
| 713 | final int maxDim = Math.max(display.getWidth(), display.getHeight()); |
| 714 | final int minDim = Math.min(display.getWidth(), display.getHeight()); |
| 715 | |
| 716 | // We need to ensure that there is enough extra space in the wallpaper for the intended |
| 717 | // parallax effects |
| 718 | mWallpaperWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim)); |
| 719 | mWallpaperHeight = (int)(maxDim * wallpaperTravelToScreenHeightRatio(maxDim, minDim)); |
Winson Chung | f7640c8 | 2011-02-28 13:47:29 -0800 | [diff] [blame] | 720 | new Thread("setWallpaperDimension") { |
| 721 | public void run() { |
| 722 | mWallpaperManager.suggestDesiredDimensions(mWallpaperWidth, mWallpaperHeight); |
| 723 | } |
| 724 | }.start(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 727 | public void setVerticalWallpaperOffset(float offset) { |
| 728 | mWallpaperOffset.setFinalY(offset); |
| 729 | } |
| 730 | public float getVerticalWallpaperOffset() { |
| 731 | return mWallpaperOffset.getCurrY(); |
| 732 | } |
| 733 | public void setHorizontalWallpaperOffset(float offset) { |
| 734 | mWallpaperOffset.setFinalX(offset); |
| 735 | } |
| 736 | public float getHorizontalWallpaperOffset() { |
| 737 | return mWallpaperOffset.getCurrX(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 740 | private float wallpaperOffsetForCurrentScroll() { |
| 741 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
Michael Jurka | f70c781 | 2011-03-07 16:53:12 -0800 | [diff] [blame] | 742 | final boolean isStaticWallpaper = (mWallpaperManager.getWallpaperInfo() == null); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 743 | // The wallpaper travel width is how far, from left to right, the wallpaper will move |
| 744 | // at this orientation (for example, in portrait mode we don't move all the way to the |
| 745 | // edges of the wallpaper, or otherwise the parallax effect would be too strong) |
| 746 | int wallpaperTravelWidth = (int) (display.getWidth() * |
| 747 | wallpaperTravelToScreenWidthRatio(display.getWidth(), display.getHeight())); |
Michael Jurka | f70c781 | 2011-03-07 16:53:12 -0800 | [diff] [blame] | 748 | if (!isStaticWallpaper) { |
| 749 | wallpaperTravelWidth = mWallpaperWidth; |
| 750 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 751 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 752 | // Set wallpaper offset steps (1 / (number of screens - 1)) |
| 753 | // We have 3 vertical offset states (centered, and then top/bottom aligned |
| 754 | // for all apps/customize) |
| 755 | mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 1.0f / (3 - 1)); |
| 756 | |
Michael Jurka | 09d6eb0 | 2011-01-28 16:05:09 -0800 | [diff] [blame] | 757 | int scrollRange = getScrollRange(); |
| 758 | float scrollProgressOffset = 0; |
| 759 | |
| 760 | // Account for overscroll: you only see the absolute edge of the wallpaper if |
| 761 | // you overscroll as far as you can in landscape mode. Only do this for static wallpapers |
| 762 | // because live wallpapers (and probably 3rd party wallpaper providers) rely on the offset |
| 763 | // being even intervals from 0 to 1 (eg [0, 0.25, 0.5, 0.75, 1]) |
Michael Jurka | 09d6eb0 | 2011-01-28 16:05:09 -0800 | [diff] [blame] | 764 | if (isStaticWallpaper) { |
| 765 | int overscrollOffset = (int) (maxOverScroll() * display.getWidth()); |
| 766 | scrollProgressOffset += overscrollOffset / (float) getScrollRange(); |
| 767 | scrollRange += 2 * overscrollOffset; |
| 768 | } |
| 769 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 770 | float scrollProgress = |
Michael Jurka | 09d6eb0 | 2011-01-28 16:05:09 -0800 | [diff] [blame] | 771 | mScrollX / (float) scrollRange + scrollProgressOffset; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 772 | float offsetInDips = wallpaperTravelWidth * scrollProgress + |
Michael Jurka | f70c781 | 2011-03-07 16:53:12 -0800 | [diff] [blame] | 773 | (mWallpaperWidth - wallpaperTravelWidth) / 2; // center it |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 774 | float offset = offsetInDips / (float) mWallpaperWidth; |
| 775 | return offset; |
| 776 | } |
| 777 | private void syncWallpaperOffsetWithScroll() { |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 778 | if (LauncherApplication.isScreenXLarge()) { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 779 | mWallpaperOffset.setFinalX(wallpaperOffsetForCurrentScroll()); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
| 783 | public void updateWallpaperOffsetImmediately() { |
| 784 | mUpdateWallpaperOffsetImmediately = true; |
| 785 | } |
| 786 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 787 | private void updateWallpaperOffsets() { |
| 788 | boolean updateNow = false; |
| 789 | boolean keepUpdating = true; |
| 790 | if (mUpdateWallpaperOffsetImmediately) { |
| 791 | updateNow = true; |
| 792 | keepUpdating = false; |
| 793 | mWallpaperOffset.jumpToFinal(); |
| 794 | mUpdateWallpaperOffsetImmediately = false; |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 795 | } else { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 796 | updateNow = keepUpdating = mWallpaperOffset.computeScrollOffset(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 797 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 798 | if (updateNow) { |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 799 | if (mWindowToken != null) { |
| 800 | mWallpaperManager.setWallpaperOffsets(mWindowToken, |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 801 | mWallpaperOffset.getCurrX(), mWallpaperOffset.getCurrY()); |
| 802 | } |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 803 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 804 | if (keepUpdating) { |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 805 | fastInvalidate(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 806 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | class WallpaperOffsetInterpolator { |
| 810 | float mFinalHorizontalWallpaperOffset = 0.0f; |
| 811 | float mFinalVerticalWallpaperOffset = 0.5f; |
| 812 | float mHorizontalWallpaperOffset = 0.0f; |
| 813 | float mVerticalWallpaperOffset = 0.5f; |
| 814 | long mLastWallpaperOffsetUpdateTime; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 815 | boolean mIsMovingFast; |
| 816 | boolean mOverrideHorizontalCatchupConstant; |
| 817 | float mHorizontalCatchupConstant = 0.35f; |
| 818 | float mVerticalCatchupConstant = 0.35f; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 819 | |
| 820 | public WallpaperOffsetInterpolator() { |
| 821 | } |
| 822 | |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 823 | public void setOverrideHorizontalCatchupConstant(boolean override) { |
| 824 | mOverrideHorizontalCatchupConstant = override; |
| 825 | } |
| 826 | |
| 827 | public void setHorizontalCatchupConstant(float f) { |
| 828 | mHorizontalCatchupConstant = f; |
| 829 | } |
| 830 | |
| 831 | public void setVerticalCatchupConstant(float f) { |
| 832 | mVerticalCatchupConstant = f; |
| 833 | } |
| 834 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 835 | public boolean computeScrollOffset() { |
| 836 | if (Float.compare(mHorizontalWallpaperOffset, mFinalHorizontalWallpaperOffset) == 0 && |
| 837 | Float.compare(mVerticalWallpaperOffset, mFinalVerticalWallpaperOffset) == 0) { |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 838 | mIsMovingFast = false; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 839 | return false; |
| 840 | } |
| 841 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
| 842 | boolean isLandscape = display.getWidth() > display.getHeight(); |
| 843 | |
| 844 | long currentTime = System.currentTimeMillis(); |
| 845 | long timeSinceLastUpdate = currentTime - mLastWallpaperOffsetUpdateTime; |
| 846 | timeSinceLastUpdate = Math.min((long) (1000/30f), timeSinceLastUpdate); |
| 847 | timeSinceLastUpdate = Math.max(1L, timeSinceLastUpdate); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 848 | |
| 849 | float xdiff = Math.abs(mFinalHorizontalWallpaperOffset - mHorizontalWallpaperOffset); |
| 850 | if (!mIsMovingFast && xdiff > 0.07) { |
| 851 | mIsMovingFast = true; |
| 852 | } |
| 853 | |
| 854 | float fractionToCatchUpIn1MsHorizontal; |
| 855 | if (mOverrideHorizontalCatchupConstant) { |
| 856 | fractionToCatchUpIn1MsHorizontal = mHorizontalCatchupConstant; |
| 857 | } else if (mIsMovingFast) { |
| 858 | fractionToCatchUpIn1MsHorizontal = isLandscape ? 0.5f : 0.75f; |
| 859 | } else { |
| 860 | // slow |
| 861 | fractionToCatchUpIn1MsHorizontal = isLandscape ? 0.27f : 0.5f; |
| 862 | } |
| 863 | float fractionToCatchUpIn1MsVertical = mVerticalCatchupConstant; |
| 864 | |
| 865 | |
| 866 | fractionToCatchUpIn1MsHorizontal /= 33f; |
| 867 | fractionToCatchUpIn1MsVertical /= 33f; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 868 | |
| 869 | final float UPDATE_THRESHOLD = 0.00001f; |
| 870 | float hOffsetDelta = mFinalHorizontalWallpaperOffset - mHorizontalWallpaperOffset; |
| 871 | float vOffsetDelta = mFinalVerticalWallpaperOffset - mVerticalWallpaperOffset; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 872 | boolean jumpToFinalValue = Math.abs(hOffsetDelta) < UPDATE_THRESHOLD && |
| 873 | Math.abs(vOffsetDelta) < UPDATE_THRESHOLD; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 874 | if (jumpToFinalValue) { |
| 875 | mHorizontalWallpaperOffset = mFinalHorizontalWallpaperOffset; |
| 876 | mVerticalWallpaperOffset = mFinalVerticalWallpaperOffset; |
| 877 | } else { |
| 878 | float percentToCatchUpVertical = |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 879 | Math.min(1.0f, timeSinceLastUpdate * fractionToCatchUpIn1MsVertical); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 880 | float percentToCatchUpHorizontal = |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 881 | Math.min(1.0f, timeSinceLastUpdate * fractionToCatchUpIn1MsHorizontal); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 882 | mHorizontalWallpaperOffset += percentToCatchUpHorizontal * hOffsetDelta; |
| 883 | mVerticalWallpaperOffset += percentToCatchUpVertical * vOffsetDelta; |
| 884 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 885 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 886 | mLastWallpaperOffsetUpdateTime = System.currentTimeMillis(); |
| 887 | return true; |
| 888 | } |
| 889 | |
| 890 | public float getCurrX() { |
| 891 | return mHorizontalWallpaperOffset; |
| 892 | } |
| 893 | |
| 894 | public float getFinalX() { |
| 895 | return mFinalHorizontalWallpaperOffset; |
| 896 | } |
| 897 | |
| 898 | public float getCurrY() { |
| 899 | return mVerticalWallpaperOffset; |
| 900 | } |
| 901 | |
| 902 | public float getFinalY() { |
| 903 | return mFinalVerticalWallpaperOffset; |
| 904 | } |
| 905 | |
| 906 | public void setFinalX(float x) { |
| 907 | mFinalHorizontalWallpaperOffset = Math.max(0f, Math.min(x, 1.0f)); |
| 908 | } |
| 909 | |
| 910 | public void setFinalY(float y) { |
| 911 | mFinalVerticalWallpaperOffset = Math.max(0f, Math.min(y, 1.0f)); |
| 912 | } |
| 913 | |
| 914 | public void jumpToFinal() { |
| 915 | mHorizontalWallpaperOffset = mFinalHorizontalWallpaperOffset; |
| 916 | mVerticalWallpaperOffset = mFinalVerticalWallpaperOffset; |
| 917 | } |
Dianne Hackborn | 8f57395 | 2009-08-10 23:21:09 -0700 | [diff] [blame] | 918 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 919 | |
Michael Jurka | 340c5f3 | 2010-10-21 16:49:19 -0700 | [diff] [blame] | 920 | @Override |
| 921 | public void computeScroll() { |
| 922 | super.computeScroll(); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 923 | if (mSyncWallpaperOffsetWithScroll) { |
| 924 | syncWallpaperOffsetWithScroll(); |
| 925 | } |
Michael Jurka | 340c5f3 | 2010-10-21 16:49:19 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 928 | void showOutlines() { |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 929 | if (!mIsSmall && !mIsInUnshrinkAnimation) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 930 | if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel(); |
| 931 | if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel(); |
| 932 | mChildrenOutlineFadeInAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 1.0f); |
| 933 | mChildrenOutlineFadeInAnimation.setDuration(CHILDREN_OUTLINE_FADE_IN_DURATION); |
| 934 | mChildrenOutlineFadeInAnimation.start(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 935 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 938 | void hideOutlines() { |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 939 | if (!mIsSmall && !mIsInUnshrinkAnimation) { |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 940 | if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel(); |
| 941 | if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel(); |
| 942 | mChildrenOutlineFadeOutAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 0.0f); |
| 943 | mChildrenOutlineFadeOutAnimation.setDuration(CHILDREN_OUTLINE_FADE_OUT_DURATION); |
| 944 | mChildrenOutlineFadeOutAnimation.setStartDelay(CHILDREN_OUTLINE_FADE_OUT_DELAY); |
| 945 | mChildrenOutlineFadeOutAnimation.start(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 946 | } |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Patrick Dubroy | 94f78a5 | 2011-02-28 17:39:16 -0800 | [diff] [blame] | 949 | public void showOutlinesTemporarily() { |
| 950 | if (!mIsPageMoving && !isTouchActive()) { |
| 951 | snapToPage(mCurrentPage); |
| 952 | } |
| 953 | } |
| 954 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 955 | public void setChildrenOutlineAlpha(float alpha) { |
| 956 | mChildrenOutlineAlpha = alpha; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 957 | for (int i = 0; i < getChildCount(); i++) { |
| 958 | CellLayout cl = (CellLayout) getChildAt(i); |
| 959 | cl.setBackgroundAlpha(alpha); |
| 960 | } |
| 961 | } |
| 962 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 963 | public float getChildrenOutlineAlpha() { |
| 964 | return mChildrenOutlineAlpha; |
| 965 | } |
| 966 | |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 967 | void disableBackground() { |
| 968 | mDrawBackground = false; |
| 969 | } |
| 970 | void enableBackground() { |
| 971 | mDrawBackground = true; |
| 972 | } |
| 973 | |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 974 | private void showBackgroundGradientForAllApps() { |
| 975 | showBackgroundGradient(); |
| 976 | mDrawCustomizeTrayBackground = false; |
| 977 | } |
| 978 | |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 979 | private void showBackgroundGradientForCustomizeTray() { |
| 980 | showBackgroundGradient(); |
| 981 | mDrawCustomizeTrayBackground = true; |
| 982 | } |
| 983 | |
| 984 | private void showBackgroundGradient() { |
Winson Chung | b4b7fa7 | 2010-11-18 14:38:53 -0800 | [diff] [blame] | 985 | if (mBackground == null) return; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 986 | if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel(); |
| 987 | if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel(); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 988 | mBackgroundFadeInAnimation = ValueAnimator.ofFloat(getBackgroundAlpha(), 1f); |
| 989 | mBackgroundFadeInAnimation.addUpdateListener(new AnimatorUpdateListener() { |
| 990 | public void onAnimationUpdate(ValueAnimator animation) { |
| 991 | setBackgroundAlpha(((Float) animation.getAnimatedValue()).floatValue()); |
| 992 | } |
| 993 | }); |
Winson Chung | f135c6c | 2010-11-18 16:32:08 -0800 | [diff] [blame] | 994 | mBackgroundFadeInAnimation.setInterpolator(new DecelerateInterpolator(1.5f)); |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 995 | mBackgroundFadeInAnimation.setDuration(BACKGROUND_FADE_IN_DURATION); |
| 996 | mBackgroundFadeInAnimation.start(); |
| 997 | } |
| 998 | |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 999 | private void hideBackgroundGradient() { |
Winson Chung | b4b7fa7 | 2010-11-18 14:38:53 -0800 | [diff] [blame] | 1000 | if (mBackground == null) return; |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1001 | if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel(); |
| 1002 | if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel(); |
Michael Jurka | e0f5a61 | 2011-02-07 16:45:41 -0800 | [diff] [blame] | 1003 | mBackgroundFadeOutAnimation = ValueAnimator.ofFloat(getBackgroundAlpha(), 0f); |
| 1004 | mBackgroundFadeOutAnimation.addUpdateListener(new AnimatorUpdateListener() { |
| 1005 | public void onAnimationUpdate(ValueAnimator animation) { |
| 1006 | setBackgroundAlpha(((Float) animation.getAnimatedValue()).floatValue()); |
| 1007 | } |
| 1008 | }); |
Winson Chung | f135c6c | 2010-11-18 16:32:08 -0800 | [diff] [blame] | 1009 | mBackgroundFadeOutAnimation.setInterpolator(new DecelerateInterpolator(1.5f)); |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1010 | mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION); |
| 1011 | mBackgroundFadeOutAnimation.start(); |
| 1012 | } |
| 1013 | |
| 1014 | public void setBackgroundAlpha(float alpha) { |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1015 | if (alpha != mBackgroundAlpha) { |
| 1016 | mBackgroundAlpha = alpha; |
| 1017 | invalidate(); |
| 1018 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1019 | } |
| 1020 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1021 | public float getBackgroundAlpha() { |
| 1022 | return mBackgroundAlpha; |
| 1023 | } |
| 1024 | |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1025 | /** |
| 1026 | * Due to 3D transformations, if two CellLayouts are theoretically touching each other, |
| 1027 | * on the xy plane, when one is rotated along the y-axis, the gap between them is perceived |
| 1028 | * as being larger. This method computes what offset the rotated view should be translated |
| 1029 | * in order to minimize this perceived gap. |
| 1030 | * @param degrees Angle of the view |
| 1031 | * @param width Width of the view |
| 1032 | * @param height Height of the view |
| 1033 | * @return Offset to be used in a View.setTranslationX() call |
| 1034 | */ |
| 1035 | private float getOffsetXForRotation(float degrees, int width, int height) { |
| 1036 | mMatrix.reset(); |
| 1037 | mCamera.save(); |
| 1038 | mCamera.rotateY(Math.abs(degrees)); |
| 1039 | mCamera.getMatrix(mMatrix); |
| 1040 | mCamera.restore(); |
| 1041 | |
| 1042 | mMatrix.preTranslate(-width * 0.5f, -height * 0.5f); |
| 1043 | mMatrix.postTranslate(width * 0.5f, height * 0.5f); |
| 1044 | mTempFloat2[0] = width; |
| 1045 | mTempFloat2[1] = height; |
| 1046 | mMatrix.mapPoints(mTempFloat2); |
| 1047 | return (width - mTempFloat2[0]) * (degrees > 0.0f ? 1.0f : -1.0f); |
| 1048 | } |
| 1049 | |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1050 | float backgroundAlphaInterpolator(float r) { |
| 1051 | float pivotA = 0.1f; |
| 1052 | float pivotB = 0.4f; |
| 1053 | if (r < pivotA) { |
| 1054 | return 0; |
| 1055 | } else if (r > pivotB) { |
| 1056 | return 1.0f; |
| 1057 | } else { |
| 1058 | return (r - pivotA)/(pivotB - pivotA); |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | float overScrollBackgroundAlphaInterpolator(float r) { |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 1063 | float threshold = 0.08f; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1064 | |
| 1065 | if (r > mOverScrollMaxBackgroundAlpha) { |
| 1066 | mOverScrollMaxBackgroundAlpha = r; |
| 1067 | } else if (r < mOverScrollMaxBackgroundAlpha) { |
| 1068 | r = mOverScrollMaxBackgroundAlpha; |
| 1069 | } |
| 1070 | |
| 1071 | return Math.min(r / threshold, 1.0f); |
| 1072 | } |
| 1073 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1074 | @Override |
| 1075 | protected void screenScrolled(int screenCenter) { |
Adam Cohen | c3bc260 | 2011-03-30 11:49:12 -0700 | [diff] [blame^] | 1076 | // If the screen is not xlarge, then don't rotate the CellLayouts |
| 1077 | if (!LauncherApplication.isScreenXLarge()) return; |
| 1078 | |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 1079 | final int halfScreenSize = getMeasuredWidth() / 2; |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1080 | |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 1081 | for (int i = 0; i < getChildCount(); i++) { |
Adam Cohen | 1b0aaac | 2010-10-28 11:11:18 -0700 | [diff] [blame] | 1082 | CellLayout cl = (CellLayout) getChildAt(i); |
| 1083 | if (cl != null) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1084 | int totalDistance = getScaledMeasuredWidth(cl) + mPageSpacing; |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 1085 | int delta = screenCenter - (getChildOffset(i) - |
| 1086 | getRelativeChildOffset(i) + halfScreenSize); |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1087 | |
Adam Cohen | ddb8219 | 2010-11-10 16:32:54 -0800 | [diff] [blame] | 1088 | float scrollProgress = delta / (totalDistance * 1.0f); |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 1089 | scrollProgress = Math.min(scrollProgress, 1.0f); |
| 1090 | scrollProgress = Math.max(scrollProgress, -1.0f); |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1091 | |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 1092 | // If the current page (i) is being overscrolled, we use a different |
| 1093 | // set of rules for setting the background alpha multiplier. |
| 1094 | if ((mScrollX < 0 && i == 0) || (mScrollX > mMaxScrollX && |
| 1095 | i == getChildCount() -1 )) { |
| 1096 | cl.setBackgroundAlphaMultiplier( |
| 1097 | overScrollBackgroundAlphaInterpolator(Math.abs(scrollProgress))); |
| 1098 | mOverScrollPageIndex = i; |
| 1099 | } else if (mOverScrollPageIndex != i) { |
| 1100 | cl.setBackgroundAlphaMultiplier( |
| 1101 | backgroundAlphaInterpolator(Math.abs(scrollProgress))); |
Adam Cohen | e0f66b5 | 2010-11-23 15:06:07 -0800 | [diff] [blame] | 1102 | } |
Adam Cohen | 1b0aaac | 2010-10-28 11:11:18 -0700 | [diff] [blame] | 1103 | |
Adam Cohen | 21f12b5 | 2010-10-07 17:15:37 -0700 | [diff] [blame] | 1104 | float rotation = WORKSPACE_ROTATION * scrollProgress; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1105 | float translationX = getOffsetXForRotation(rotation, cl.getWidth(), cl.getHeight()); |
| 1106 | cl.setTranslationX(translationX); |
Adam Cohen | 68d7393 | 2010-11-15 10:50:58 -0800 | [diff] [blame] | 1107 | |
Adam Cohen | 1b0aaac | 2010-10-28 11:11:18 -0700 | [diff] [blame] | 1108 | cl.setRotationY(rotation); |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1113 | protected void onAttachedToWindow() { |
| 1114 | super.onAttachedToWindow(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1115 | mWindowToken = getWindowToken(); |
Joe Onorato | 956091b | 2010-02-19 12:47:40 -0800 | [diff] [blame] | 1116 | computeScroll(); |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1117 | mDragController.setWindowToken(mWindowToken); |
| 1118 | } |
| 1119 | |
| 1120 | protected void onDetachedFromWindow() { |
| 1121 | mWindowToken = null; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 1122 | } |
| 1123 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1124 | @Override |
Michael Jurka | 28750fb | 2010-09-24 17:43:49 -0700 | [diff] [blame] | 1125 | 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] | 1126 | if (mFirstLayout && mCurrentPage >= 0 && mCurrentPage < getChildCount()) { |
| 1127 | mUpdateWallpaperOffsetImmediately = true; |
| 1128 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1129 | super.onLayout(changed, left, top, right, bottom); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1130 | |
Michael Jurka | 79212d8 | 2010-07-30 16:36:20 -0700 | [diff] [blame] | 1131 | // if shrinkToBottom() is called on initialization, it has to be deferred |
| 1132 | // until after the first call to onLayout so that it has the correct width |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1133 | if (mWaitingToShrink) { |
Adam Cohen | 696a679 | 2010-12-09 11:46:38 -0800 | [diff] [blame] | 1134 | // shrink can trigger a synchronous onLayout call, so we |
| 1135 | // post this to avoid a stack overflow / tangled onLayout calls |
| 1136 | post(new Runnable() { |
| 1137 | public void run() { |
| 1138 | shrink(mWaitingToShrinkState, false); |
| 1139 | mWaitingToShrink = false; |
| 1140 | } |
| 1141 | }); |
Michael Jurka | 79212d8 | 2010-07-30 16:36:20 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1144 | if (LauncherApplication.isInPlaceRotationEnabled()) { |
| 1145 | // When the device is rotated, the scroll position of the current screen |
| 1146 | // needs to be refreshed |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1147 | setCurrentPage(getCurrentPage()); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1148 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | @Override |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1152 | protected void onDraw(Canvas canvas) { |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1153 | updateWallpaperOffsets(); |
Michael Jurka | c5b262c | 2011-01-12 20:24:50 -0800 | [diff] [blame] | 1154 | |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1155 | // Draw the background gradient if necessary |
Michael Jurka | 9c6fbed | 2011-03-02 17:41:34 -0800 | [diff] [blame] | 1156 | if (mBackground != null && mBackgroundAlpha > 0.0f && mDrawBackground) { |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1157 | int alpha = (int) (mBackgroundAlpha * 255); |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1158 | if (mDrawCustomizeTrayBackground) { |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 1159 | // Find out where to offset the gradient for the customization tray content |
| 1160 | mCustomizationDrawer.getLocationOnScreen(mCustomizationDrawerPos); |
| 1161 | final Matrix m = mCustomizationDrawer.getMatrix(); |
| 1162 | mCustomizationDrawerTransformedPos[0] = 0.0f; |
| 1163 | mCustomizationDrawerTransformedPos[1] = mCustomizationDrawerContent.getTop(); |
| 1164 | m.mapPoints(mCustomizationDrawerTransformedPos); |
| 1165 | |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 1166 | // Draw the bg glow behind the gradient |
| 1167 | mCustomizeTrayBackground.setAlpha(alpha); |
| 1168 | mCustomizeTrayBackground.setBounds(mScrollX, 0, mScrollX + getMeasuredWidth(), |
| 1169 | getMeasuredHeight()); |
| 1170 | mCustomizeTrayBackground.draw(canvas); |
| 1171 | |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 1172 | // Draw the bg gradient |
| 1173 | final int offset = (int) (mCustomizationDrawerPos[1] + |
| 1174 | mCustomizationDrawerTransformedPos[1]); |
Winson Chung | ce93f7e | 2011-01-11 09:53:27 -0800 | [diff] [blame] | 1175 | mBackground.setAlpha(alpha); |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 1176 | mBackground.setBounds(mScrollX, offset, mScrollX + getMeasuredWidth(), |
| 1177 | offset + getMeasuredHeight()); |
| 1178 | mBackground.draw(canvas); |
Winson Chung | ce93f7e | 2011-01-11 09:53:27 -0800 | [diff] [blame] | 1179 | } else { |
| 1180 | mBackground.setAlpha(alpha); |
| 1181 | mBackground.setBounds(mScrollX, 0, mScrollX + getMeasuredWidth(), |
| 1182 | getMeasuredHeight()); |
| 1183 | mBackground.draw(canvas); |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1184 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1185 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1186 | super.onDraw(canvas); |
| 1187 | } |
| 1188 | |
| 1189 | @Override |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1190 | protected void dispatchDraw(Canvas canvas) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 1191 | if (mIsSmall || mIsInUnshrinkAnimation) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1192 | // Draw all the workspaces if we're small |
| 1193 | final int pageCount = getChildCount(); |
| 1194 | final long drawingTime = getDrawingTime(); |
| 1195 | for (int i = 0; i < pageCount; i++) { |
Michael Jurka | a4b4016 | 2011-03-09 14:53:27 -0800 | [diff] [blame] | 1196 | final CellLayout page = (CellLayout) getChildAt(i); |
| 1197 | if (page.getVisibility() == VISIBLE |
| 1198 | && (page.getAlpha() != 0f || page.getBackgroundAlpha() != 0f)) { |
Michael Jurka | 2763be3 | 2011-02-24 11:19:57 -0800 | [diff] [blame] | 1199 | drawChild(canvas, page, drawingTime); |
| 1200 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1201 | } |
| 1202 | } else { |
| 1203 | super.dispatchDraw(canvas); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1204 | |
Patrick Dubroy | 0207c52 | 2010-11-03 22:12:02 -0700 | [diff] [blame] | 1205 | final int width = getWidth(); |
| 1206 | final int height = getHeight(); |
| 1207 | |
| 1208 | // In portrait orientation, draw the glowing edge when dragging to adjacent screens |
| 1209 | if (mInScrollArea && (height > width)) { |
| 1210 | final int pageHeight = getChildAt(0).getHeight(); |
| 1211 | |
| 1212 | // This determines the height of the glowing edge: 90% of the page height |
| 1213 | final int padding = (int) ((height - pageHeight) * 0.5f + pageHeight * 0.1f); |
| 1214 | |
| 1215 | final CellLayout leftPage = (CellLayout) getChildAt(mCurrentPage - 1); |
| 1216 | final CellLayout rightPage = (CellLayout) getChildAt(mCurrentPage + 1); |
| 1217 | |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 1218 | if (leftPage != null && leftPage.getIsDragOverlapping()) { |
Patrick Dubroy | 0207c52 | 2010-11-03 22:12:02 -0700 | [diff] [blame] | 1219 | final Drawable d = getResources().getDrawable(R.drawable.page_hover_left); |
| 1220 | d.setBounds(mScrollX, padding, mScrollX + d.getIntrinsicWidth(), height - padding); |
| 1221 | d.draw(canvas); |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 1222 | } else if (rightPage != null && rightPage.getIsDragOverlapping()) { |
Patrick Dubroy | 0207c52 | 2010-11-03 22:12:02 -0700 | [diff] [blame] | 1223 | final Drawable d = getResources().getDrawable(R.drawable.page_hover_right); |
| 1224 | d.setBounds(mScrollX + width - d.getIntrinsicWidth(), padding, mScrollX + width, height - padding); |
| 1225 | d.draw(canvas); |
| 1226 | } |
| 1227 | } |
| 1228 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1229 | if (mDropView != null) { |
Patrick Dubroy | 8ae3a62 | 2010-11-01 13:49:51 -0700 | [diff] [blame] | 1230 | // We are animating an item that was just dropped on the home screen. |
| 1231 | // Render its View in the current animation position. |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 1232 | canvas.save(Canvas.MATRIX_SAVE_FLAG); |
| 1233 | final int xPos = mDropViewPos[0] - mDropView.getScrollX(); |
| 1234 | final int yPos = mDropViewPos[1] - mDropView.getScrollY(); |
| 1235 | canvas.translate(xPos, yPos); |
| 1236 | mDropView.draw(canvas); |
| 1237 | canvas.restore(); |
| 1238 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1239 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | @Override |
| 1243 | protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 1244 | if (!mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1245 | final Folder openFolder = getOpenFolder(); |
| 1246 | if (openFolder != null) { |
| 1247 | return openFolder.requestFocus(direction, previouslyFocusedRect); |
| 1248 | } else { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1249 | return super.onRequestFocusInDescendants(direction, previouslyFocusedRect); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | return false; |
| 1253 | } |
| 1254 | |
| 1255 | @Override |
Romain Guy | c2e24c0 | 2009-06-01 16:11:41 -0700 | [diff] [blame] | 1256 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 1257 | if (!mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1258 | final Folder openFolder = getOpenFolder(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1259 | if (openFolder != null) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1260 | openFolder.addFocusables(views, direction); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1261 | } else { |
| 1262 | super.addFocusables(views, direction, focusableMode); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | @Override |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1268 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 1269 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
Michael Jurka | 54dd754 | 2010-07-30 14:47:52 -0700 | [diff] [blame] | 1270 | // (In XLarge mode, the workspace is shrunken below all apps, and responds to taps |
| 1271 | // ie when you click on a mini-screen, it zooms back to that screen) |
Joe Onorato | 6b4adbc | 2010-09-01 12:13:25 -0700 | [diff] [blame] | 1272 | if (!LauncherApplication.isScreenXLarge() && mLauncher.isAllAppsVisible()) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1273 | return false; |
| 1274 | } |
| 1275 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1276 | |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 1277 | return super.dispatchTouchEvent(ev); |
| 1278 | } |
| 1279 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1280 | void enableChildrenCache(int fromPage, int toPage) { |
| 1281 | if (fromPage > toPage) { |
| 1282 | final int temp = fromPage; |
| 1283 | fromPage = toPage; |
| 1284 | toPage = temp; |
Mike Cleron | 3a2b3f2 | 2009-11-05 17:17:42 -0800 | [diff] [blame] | 1285 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1286 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1287 | final int screenCount = getChildCount(); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1288 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1289 | fromPage = Math.max(fromPage, 0); |
| 1290 | toPage = Math.min(toPage, screenCount - 1); |
Adam Powell | fea5d02 | 2010-04-29 11:42:45 -0700 | [diff] [blame] | 1291 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1292 | for (int i = fromPage; i <= toPage; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1293 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1294 | layout.setChildrenDrawnWithCacheEnabled(true); |
| 1295 | layout.setChildrenDrawingCacheEnabled(true); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | void clearChildrenCache() { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1300 | final int screenCount = getChildCount(); |
| 1301 | for (int i = 0; i < screenCount; i++) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1302 | final CellLayout layout = (CellLayout) getChildAt(i); |
| 1303 | layout.setChildrenDrawnWithCacheEnabled(false); |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | @Override |
| 1308 | public boolean onTouchEvent(MotionEvent ev) { |
Adam Cohen | be90934 | 2011-01-28 17:02:58 -0800 | [diff] [blame] | 1309 | AllAppsPagedView allApps = (AllAppsPagedView) |
| 1310 | mLauncher.findViewById(R.id.all_apps_paged_view); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1311 | |
Adam Cohen | be90934 | 2011-01-28 17:02:58 -0800 | [diff] [blame] | 1312 | if (mLauncher.isAllAppsVisible() && mShrinkState == ShrinkState.BOTTOM_HIDDEN |
| 1313 | && allApps != null) { |
| 1314 | if (ev.getAction() == MotionEvent.ACTION_UP && |
| 1315 | allApps.getTouchState() == TOUCH_STATE_REST) { |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1316 | |
Adam Cohen | be90934 | 2011-01-28 17:02:58 -0800 | [diff] [blame] | 1317 | // Cancel any scrolling that is in progress. |
| 1318 | if (!mScroller.isFinished()) { |
| 1319 | mScroller.abortAnimation(); |
| 1320 | } |
| 1321 | setCurrentPage(mCurrentPage); |
| 1322 | |
| 1323 | if (mShrinkState == ShrinkState.BOTTOM_HIDDEN) { |
| 1324 | mLauncher.showWorkspace(true); |
| 1325 | } |
| 1326 | allApps.onTouchEvent(ev); |
| 1327 | return true; |
| 1328 | } else { |
| 1329 | return allApps.onTouchEvent(ev); |
| 1330 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1331 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1332 | return super.onTouchEvent(ev); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1333 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 1334 | |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1335 | protected void enableChildrenLayers(boolean enable) { |
| 1336 | for (int i = 0; i < getPageCount(); i++) { |
Michael Jurka | a7f801f | 2011-02-02 20:54:07 -0800 | [diff] [blame] | 1337 | ((ViewGroup)getChildAt(i)).setChildrenLayersEnabled(enable); |
Michael Jurka | ce7e05f | 2011-02-01 22:02:35 -0800 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | @Override |
| 1341 | protected void pageBeginMoving() { |
| 1342 | enableChildrenLayers(true); |
| 1343 | super.pageBeginMoving(); |
| 1344 | } |
| 1345 | |
| 1346 | @Override |
| 1347 | protected void pageEndMoving() { |
| 1348 | if (!mIsSmall && !mIsInUnshrinkAnimation) { |
| 1349 | enableChildrenLayers(false); |
| 1350 | } |
| 1351 | super.pageEndMoving(); |
| 1352 | } |
| 1353 | |
Jeff Brown | 1d0867c | 2010-12-02 18:27:39 -0800 | [diff] [blame] | 1354 | @Override |
| 1355 | protected void onWallpaperTap(MotionEvent ev) { |
| 1356 | final int[] position = mTempCell; |
| 1357 | getLocationOnScreen(position); |
| 1358 | |
| 1359 | int pointerIndex = ev.getActionIndex(); |
| 1360 | position[0] += (int) ev.getX(pointerIndex); |
| 1361 | position[1] += (int) ev.getY(pointerIndex); |
| 1362 | |
| 1363 | mWallpaperManager.sendWallpaperCommand(getWindowToken(), |
| 1364 | ev.getAction() == MotionEvent.ACTION_UP |
| 1365 | ? WallpaperManager.COMMAND_TAP : WallpaperManager.COMMAND_SECONDARY_TAP, |
| 1366 | position[0], position[1], 0, null); |
| 1367 | } |
| 1368 | |
Michael Jurka | 01f0ed4 | 2010-08-20 00:41:17 -0700 | [diff] [blame] | 1369 | public boolean isSmall() { |
| 1370 | return mIsSmall; |
| 1371 | } |
| 1372 | |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 1373 | private float getYScaleForScreen(int screen) { |
| 1374 | int x = Math.abs(screen - 2); |
| 1375 | |
| 1376 | // TODO: This should be generalized for use with arbitrary rotation angles. |
| 1377 | switch(x) { |
| 1378 | case 0: return EXTRA_SCALE_FACTOR_0; |
| 1379 | case 1: return EXTRA_SCALE_FACTOR_1; |
| 1380 | case 2: return EXTRA_SCALE_FACTOR_2; |
| 1381 | } |
| 1382 | return 1.0f; |
| 1383 | } |
| 1384 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1385 | public void shrink(ShrinkState shrinkState) { |
| 1386 | shrink(shrinkState, true); |
| 1387 | } |
Winson Chung | 9171e6d | 2010-11-17 17:39:27 -0800 | [diff] [blame] | 1388 | |
Michael Jurka | 3c38d56 | 2011-02-18 19:22:12 -0800 | [diff] [blame] | 1389 | private int getCustomizeDrawerHeight() { |
| 1390 | TabHost customizationDrawer = mLauncher.getCustomizationDrawer(); |
| 1391 | int height = customizationDrawer.getHeight(); |
| 1392 | TabWidget tabWidget = (TabWidget) |
| 1393 | customizationDrawer.findViewById(com.android.internal.R.id.tabs); |
| 1394 | if (tabWidget.getTabCount() > 0) { |
| 1395 | TextView tabText = (TextView) tabWidget.getChildTabViewAt(0); |
| 1396 | // subtract the empty space above the tab text |
| 1397 | height -= ((tabWidget.getHeight() - tabText.getLineHeight())) / 2; |
| 1398 | } |
| 1399 | return height; |
| 1400 | } |
| 1401 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1402 | // we use this to shrink the workspace for the all apps view and the customize view |
| 1403 | public void shrink(ShrinkState shrinkState, boolean animated) { |
Michael Jurka | 4c1085f | 2011-02-04 03:13:41 -0800 | [diff] [blame] | 1404 | // In the launcher interaction model, we're never in the state where we're shrunken and |
| 1405 | // visible in the bottom of the screen, and then want to fade to being invisible. |
| 1406 | // After spring loaded mode ends, this method was getting called twice, the first time |
| 1407 | // with BOTTOM_VISIBLE (what we want) and a second time with BOTTOM_INVISIBLE (not |
| 1408 | // what we want). As a temporary solution, we just change the second call to BOTTOM_VISIBLE |
| 1409 | if (mIsSmall && mShrinkState == ShrinkState.BOTTOM_VISIBLE) { |
| 1410 | shrinkState = ShrinkState.BOTTOM_VISIBLE; |
| 1411 | } |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1412 | if (mFirstLayout) { |
| 1413 | // (mFirstLayout == "first layout has not happened yet") |
| 1414 | // if we get a call to shrink() as part of our initialization (for example, if |
| 1415 | // Launcher is started in All Apps mode) then we need to wait for a layout call |
| 1416 | // to get our width so we can layout the mini-screen views correctly |
| 1417 | mWaitingToShrink = true; |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1418 | mWaitingToShrinkState = shrinkState; |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1419 | return; |
| 1420 | } |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1421 | // Stop any scrolling, move to the current page right away |
Michael Jurka | a997ac2 | 2010-10-27 18:10:55 -0700 | [diff] [blame] | 1422 | setCurrentPage((mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1423 | if (!mIsDragInProcess) { |
Patrick Dubroy | 0dfcf68 | 2011-01-18 17:08:11 -0800 | [diff] [blame] | 1424 | updateWhichPagesAcceptDrops(shrinkState); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1425 | } |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1426 | |
Adam Cohen | 1b0aaac | 2010-10-28 11:11:18 -0700 | [diff] [blame] | 1427 | CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage); |
Patrick Dubroy | 0dfcf68 | 2011-01-18 17:08:11 -0800 | [diff] [blame] | 1428 | if (currentPage == null) { |
| 1429 | Log.w(TAG, "currentPage is NULL! mCurrentPage " + mCurrentPage |
| 1430 | + " mNextPage " + mNextPage); |
| 1431 | return; |
| 1432 | } |
Adam Cohen | ddb8219 | 2010-11-10 16:32:54 -0800 | [diff] [blame] | 1433 | if (currentPage.getBackgroundAlphaMultiplier() < 1.0f) { |
| 1434 | currentPage.setBackgroundAlpha(0.0f); |
| 1435 | } |
Adam Cohen | 1b0aaac | 2010-10-28 11:11:18 -0700 | [diff] [blame] | 1436 | currentPage.setBackgroundAlphaMultiplier(1.0f); |
| 1437 | |
Patrick Dubroy | 0dfcf68 | 2011-01-18 17:08:11 -0800 | [diff] [blame] | 1438 | mIsSmall = true; |
| 1439 | mShrinkState = shrinkState; |
| 1440 | |
| 1441 | // we intercept and reject all touch events when we're small, so be sure to reset the state |
| 1442 | mTouchState = TOUCH_STATE_REST; |
| 1443 | mActivePointerId = INVALID_POINTER; |
| 1444 | |
Patrick Dubroy | 7247f63 | 2010-08-04 16:02:59 -0700 | [diff] [blame] | 1445 | final Resources res = getResources(); |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1446 | final int screenWidth = getWidth(); |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 1447 | final int screenHeight = getHeight(); |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 1448 | |
| 1449 | // Making the assumption that all pages have the same width as the 0th |
| 1450 | final int pageWidth = getChildAt(0).getMeasuredWidth(); |
| 1451 | final int pageHeight = getChildAt(0).getMeasuredHeight(); |
| 1452 | |
| 1453 | final int scaledPageWidth = (int) (SHRINK_FACTOR * pageWidth); |
| 1454 | final int scaledPageHeight = (int) (SHRINK_FACTOR * pageHeight); |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 1455 | final float extraScaledSpacing = res.getDimension(R.dimen.smallScreenExtraSpacing); |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1456 | |
| 1457 | final int screenCount = getChildCount(); |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 1458 | float totalWidth = screenCount * scaledPageWidth + (screenCount - 1) * extraScaledSpacing; |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 1459 | |
Winson Chung | df4b83d | 2010-10-20 17:49:27 -0700 | [diff] [blame] | 1460 | boolean isPortrait = getMeasuredHeight() > getMeasuredWidth(); |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1461 | float y = (isPortrait ? |
Winson Chung | ef0066b | 2010-10-21 11:55:00 -0700 | [diff] [blame] | 1462 | getResources().getDimension(R.dimen.allAppsSmallScreenVerticalMarginPortrait) : |
| 1463 | getResources().getDimension(R.dimen.allAppsSmallScreenVerticalMarginLandscape)); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1464 | float finalAlpha = 1.0f; |
| 1465 | float extraShrinkFactor = 1.0f; |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 1466 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1467 | if (shrinkState == ShrinkState.BOTTOM_VISIBLE) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1468 | y = screenHeight - y - scaledPageHeight; |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1469 | } else if (shrinkState == ShrinkState.BOTTOM_HIDDEN) { |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1470 | // We shrink and disappear to nothing in the case of all apps |
| 1471 | // (which is when we shrink to the bottom) |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1472 | y = screenHeight - y - scaledPageHeight; |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1473 | finalAlpha = 0.0f; |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1474 | } else if (shrinkState == ShrinkState.MIDDLE) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1475 | y = screenHeight / 2 - scaledPageHeight / 2; |
Winson Chung | b0b2e6f | 2010-10-12 17:49:56 -0700 | [diff] [blame] | 1476 | finalAlpha = 1.0f; |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1477 | } else if (shrinkState == ShrinkState.TOP) { |
Michael Jurka | 3c38d56 | 2011-02-18 19:22:12 -0800 | [diff] [blame] | 1478 | y = (screenHeight - getCustomizeDrawerHeight() - scaledPageHeight) / 2; |
Michael Jurka | 213d963 | 2010-07-28 11:29:25 -0700 | [diff] [blame] | 1479 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1480 | |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 1481 | int duration; |
| 1482 | if (shrinkState == ShrinkState.BOTTOM_HIDDEN || shrinkState == ShrinkState.BOTTOM_VISIBLE) { |
| 1483 | duration = res.getInteger(R.integer.config_allAppsWorkspaceShrinkTime); |
| 1484 | } else { |
| 1485 | duration = res.getInteger(R.integer.config_customizeWorkspaceShrinkTime); |
| 1486 | } |
| 1487 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1488 | // We animate all the screens to the centered position in workspace |
| 1489 | // At the same time, the screens become greyed/dimmed |
| 1490 | |
| 1491 | // newX is initialized to the left-most position of the centered screens |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1492 | float x = mScroller.getFinalX() + screenWidth / 2 - totalWidth / 2; |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 1493 | |
| 1494 | // We are going to scale about the center of the view, so we need to adjust the positions |
| 1495 | // of the views accordingly |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1496 | x -= (pageWidth - scaledPageWidth) / 2.0f; |
| 1497 | y -= (pageHeight - scaledPageHeight) / 2.0f; |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 1498 | |
| 1499 | if (mAnimator != null) { |
| 1500 | mAnimator.cancel(); |
| 1501 | } |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 1502 | |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 1503 | mAnimator = new AnimatorSet(); |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1504 | |
| 1505 | final float[] oldXs = new float[getChildCount()]; |
| 1506 | final float[] oldYs = new float[getChildCount()]; |
| 1507 | final float[] oldScaleXs = new float[getChildCount()]; |
| 1508 | final float[] oldScaleYs = new float[getChildCount()]; |
| 1509 | final float[] oldBackgroundAlphas = new float[getChildCount()]; |
| 1510 | final float[] oldAlphas = new float[getChildCount()]; |
| 1511 | final float[] oldRotationYs = new float[getChildCount()]; |
| 1512 | final float[] newXs = new float[getChildCount()]; |
| 1513 | final float[] newYs = new float[getChildCount()]; |
| 1514 | final float[] newScaleXs = new float[getChildCount()]; |
| 1515 | final float[] newScaleYs = new float[getChildCount()]; |
| 1516 | final float[] newBackgroundAlphas = new float[getChildCount()]; |
| 1517 | final float[] newAlphas = new float[getChildCount()]; |
| 1518 | final float[] newRotationYs = new float[getChildCount()]; |
| 1519 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1520 | for (int i = 0; i < screenCount; i++) { |
Adam Cohen | f16e571 | 2011-01-13 13:31:45 -0800 | [diff] [blame] | 1521 | final CellLayout cl = (CellLayout) getChildAt(i); |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 1522 | |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1523 | float rotation = (-i + 2) * WORKSPACE_ROTATION; |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 1524 | float rotationScaleX = (float) (1.0f / Math.cos(Math.PI * rotation / 180.0f)); |
| 1525 | float rotationScaleY = getYScaleForScreen(i); |
| 1526 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1527 | oldAlphas[i] = cl.getAlpha(); |
| 1528 | newAlphas[i] = finalAlpha; |
Michael Jurka | abded66 | 2011-03-04 12:06:57 -0800 | [diff] [blame] | 1529 | if (animated && (oldAlphas[i] != 0f || newAlphas[i] != 0f)) { |
| 1530 | // if the CellLayout will be visible during the animation, force building its |
| 1531 | // hardware layer immediately so we don't see a blip later in the animation |
| 1532 | cl.buildChildrenLayer(); |
| 1533 | } |
Michael Jurka | 3e5ad58 | 2011-02-03 22:46:34 -0800 | [diff] [blame] | 1534 | if (animated) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1535 | oldXs[i] = cl.getX(); |
| 1536 | oldYs[i] = cl.getY(); |
| 1537 | oldScaleXs[i] = cl.getScaleX(); |
| 1538 | oldScaleYs[i] = cl.getScaleY(); |
| 1539 | oldBackgroundAlphas[i] = cl.getBackgroundAlpha(); |
| 1540 | oldRotationYs[i] = cl.getRotationY(); |
| 1541 | newXs[i] = x; |
| 1542 | newYs[i] = y; |
| 1543 | newScaleXs[i] = SHRINK_FACTOR * rotationScaleX * extraShrinkFactor; |
| 1544 | newScaleYs[i] = SHRINK_FACTOR * rotationScaleY * extraShrinkFactor; |
| 1545 | newBackgroundAlphas[i] = finalAlpha; |
| 1546 | newRotationYs[i] = rotation; |
Michael Jurka | 79212d8 | 2010-07-30 16:36:20 -0700 | [diff] [blame] | 1547 | } else { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1548 | cl.setX((int)x); |
| 1549 | cl.setY((int)y); |
Michael Jurka | 883f55b | 2010-10-21 15:47:14 -0700 | [diff] [blame] | 1550 | cl.setScaleX(SHRINK_FACTOR * rotationScaleX * extraShrinkFactor); |
| 1551 | cl.setScaleY(SHRINK_FACTOR * rotationScaleY * extraShrinkFactor); |
| 1552 | cl.setBackgroundAlpha(finalAlpha); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1553 | cl.setAlpha(finalAlpha); |
Adam Cohen | a985e59 | 2010-09-09 11:23:48 -0700 | [diff] [blame] | 1554 | cl.setRotationY(rotation); |
Michael Jurka | 3e5ad58 | 2011-02-03 22:46:34 -0800 | [diff] [blame] | 1555 | mShrinkAnimationListener.onAnimationEnd(null); |
Michael Jurka | 79212d8 | 2010-07-30 16:36:20 -0700 | [diff] [blame] | 1556 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1557 | // increment newX for the next screen |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1558 | x += scaledPageWidth + extraScaledSpacing; |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1559 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1560 | |
| 1561 | float wallpaperOffset = 0.5f; |
| 1562 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
| 1563 | int wallpaperTravelHeight = (int) (display.getHeight() * |
| 1564 | wallpaperTravelToScreenHeightRatio(display.getWidth(), display.getHeight())); |
| 1565 | float offsetFromCenter = (wallpaperTravelHeight / (float) mWallpaperHeight) / 2f; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1566 | boolean isLandscape = display.getWidth() > display.getHeight(); |
| 1567 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1568 | switch (shrinkState) { |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1569 | // animating in |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1570 | case TOP: |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1571 | // customize |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1572 | wallpaperOffset = 0.5f + offsetFromCenter; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1573 | mWallpaperOffset.setVerticalCatchupConstant(isLandscape ? 0.46f : 0.44f); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1574 | break; |
| 1575 | case MIDDLE: |
| 1576 | case SPRING_LOADED: |
| 1577 | wallpaperOffset = 0.5f; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1578 | mWallpaperOffset.setVerticalCatchupConstant(isLandscape ? 0.34f : 0.32f); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1579 | break; |
| 1580 | case BOTTOM_HIDDEN: |
| 1581 | case BOTTOM_VISIBLE: |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1582 | // allapps |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1583 | wallpaperOffset = 0.5f - offsetFromCenter; |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1584 | mWallpaperOffset.setVerticalCatchupConstant(isLandscape ? 0.34f : 0.32f); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1585 | break; |
| 1586 | } |
| 1587 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1588 | setLayoutScale(1.0f); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1589 | if (animated) { |
| 1590 | mWallpaperOffset.setHorizontalCatchupConstant(0.46f); |
| 1591 | mWallpaperOffset.setOverrideHorizontalCatchupConstant(true); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1592 | |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1593 | mSyncWallpaperOffsetWithScroll = false; |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1594 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1595 | ValueAnimator animWithInterpolator = |
| 1596 | ValueAnimator.ofFloat(0f, 1f).setDuration(duration); |
| 1597 | animWithInterpolator.setInterpolator(mZoomOutInterpolator); |
| 1598 | |
| 1599 | final float oldHorizontalWallpaperOffset = getHorizontalWallpaperOffset(); |
| 1600 | final float oldVerticalWallpaperOffset = getVerticalWallpaperOffset(); |
| 1601 | final float newHorizontalWallpaperOffset = 0.5f; |
| 1602 | final float newVerticalWallpaperOffset = wallpaperOffset; |
Michael Jurka | c2e26a0 | 2011-03-24 15:20:26 -0700 | [diff] [blame] | 1603 | animWithInterpolator.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 1604 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 1605 | if (b == 0f) { |
| 1606 | // an optimization, and required for correct behavior. |
| 1607 | return; |
| 1608 | } |
| 1609 | fastInvalidate(); |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1610 | setHorizontalWallpaperOffset( |
| 1611 | a * oldHorizontalWallpaperOffset + b * newHorizontalWallpaperOffset); |
| 1612 | setVerticalWallpaperOffset( |
| 1613 | a * oldVerticalWallpaperOffset + b * newVerticalWallpaperOffset); |
| 1614 | for (int i = 0; i < screenCount; i++) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1615 | final CellLayout cl = (CellLayout) getChildAt(i); |
| 1616 | cl.fastInvalidate(); |
| 1617 | cl.setFastX(a * oldXs[i] + b * newXs[i]); |
| 1618 | cl.setFastY(a * oldYs[i] + b * newYs[i]); |
| 1619 | cl.setFastScaleX(a * oldScaleXs[i] + b * newScaleXs[i]); |
| 1620 | cl.setFastScaleY(a * oldScaleYs[i] + b * newScaleYs[i]); |
| 1621 | cl.setFastBackgroundAlpha( |
| 1622 | a * oldBackgroundAlphas[i] + b * newBackgroundAlphas[i]); |
| 1623 | cl.setFastAlpha(a * oldAlphas[i] + b * newAlphas[i]); |
| 1624 | cl.setFastRotationY(a * oldRotationYs[i] + b * newRotationYs[i]); |
| 1625 | } |
| 1626 | } |
| 1627 | }); |
| 1628 | mAnimator.playTogether(animWithInterpolator); |
Michael Jurka | bea1519 | 2010-11-17 12:33:46 -0800 | [diff] [blame] | 1629 | mAnimator.addListener(mShrinkAnimationListener); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 1630 | mAnimator.start(); |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1631 | } else { |
| 1632 | setVerticalWallpaperOffset(wallpaperOffset); |
| 1633 | setHorizontalWallpaperOffset(0.5f); |
| 1634 | updateWallpaperOffsetImmediately(); |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 1635 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1636 | setChildrenDrawnWithCacheEnabled(true); |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1637 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1638 | if (shrinkState == ShrinkState.TOP) { |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1639 | showBackgroundGradientForCustomizeTray(); |
| 1640 | } else { |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 1641 | showBackgroundGradientForAllApps(); |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 1642 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1645 | /* |
| 1646 | * This interpolator emulates the rate at which the perceived scale of an object changes |
| 1647 | * as its distance from a camera increases. When this interpolator is applied to a scale |
| 1648 | * animation on a view, it evokes the sense that the object is shrinking due to moving away |
| 1649 | * from the camera. |
| 1650 | */ |
| 1651 | static class ZInterpolator implements TimeInterpolator { |
| 1652 | private float focalLength; |
| 1653 | |
| 1654 | public ZInterpolator(float foc) { |
| 1655 | focalLength = foc; |
| 1656 | } |
| 1657 | |
Adam Cohen | eed565d | 2010-11-15 11:30:05 -0800 | [diff] [blame] | 1658 | public float getInterpolation(float input) { |
| 1659 | return (1.0f - focalLength / (focalLength + input)) / |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1660 | (1.0f - focalLength / (focalLength + 1.0f)); |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1661 | } |
| 1662 | } |
| 1663 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1664 | /* |
| 1665 | * The exact reverse of ZInterpolator. |
| 1666 | */ |
| 1667 | static class InverseZInterpolator implements TimeInterpolator { |
| 1668 | private ZInterpolator zInterpolator; |
| 1669 | public InverseZInterpolator(float foc) { |
| 1670 | zInterpolator = new ZInterpolator(foc); |
| 1671 | } |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1672 | public float getInterpolation(float input) { |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1673 | return 1 - zInterpolator.getInterpolation(1 - input); |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1674 | } |
| 1675 | } |
| 1676 | |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1677 | /* |
| 1678 | * ZInterpolator compounded with an ease-out. |
| 1679 | */ |
| 1680 | static class ZoomOutInterpolator implements TimeInterpolator { |
| 1681 | private final ZInterpolator zInterpolator = new ZInterpolator(0.2f); |
Michael Jurka | ea57348 | 2011-02-03 19:48:18 -0800 | [diff] [blame] | 1682 | private final DecelerateInterpolator decelerate = new DecelerateInterpolator(1.8f); |
Adam Cohen | 61033d3 | 2010-11-15 18:29:44 -0800 | [diff] [blame] | 1683 | |
| 1684 | public float getInterpolation(float input) { |
| 1685 | return decelerate.getInterpolation(zInterpolator.getInterpolation(input)); |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | /* |
| 1690 | * InvereZInterpolator compounded with an ease-out. |
| 1691 | */ |
| 1692 | static class ZoomInInterpolator implements TimeInterpolator { |
| 1693 | private final InverseZInterpolator inverseZInterpolator = new InverseZInterpolator(0.35f); |
| 1694 | private final DecelerateInterpolator decelerate = new DecelerateInterpolator(3.0f); |
| 1695 | |
| 1696 | public float getInterpolation(float input) { |
| 1697 | return decelerate.getInterpolation(inverseZInterpolator.getInterpolation(input)); |
| 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | private final ZoomOutInterpolator mZoomOutInterpolator = new ZoomOutInterpolator(); |
| 1702 | private final ZoomInInterpolator mZoomInInterpolator = new ZoomInInterpolator(); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1703 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1704 | private void updateWhichPagesAcceptDrops(ShrinkState state) { |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1705 | updateWhichPagesAcceptDropsHelper(state, false, 1, 1); |
| 1706 | } |
| 1707 | |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1708 | private void updateWhichPagesAcceptDropsDuringDrag(ShrinkState state, int spanX, int spanY) { |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1709 | updateWhichPagesAcceptDropsHelper(state, true, spanX, spanY); |
| 1710 | } |
| 1711 | |
| 1712 | private void updateWhichPagesAcceptDropsHelper( |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1713 | ShrinkState state, boolean isDragHappening, int spanX, int spanY) { |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1714 | final int screenCount = getChildCount(); |
| 1715 | for (int i = 0; i < screenCount; i++) { |
| 1716 | CellLayout cl = (CellLayout) getChildAt(i); |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 1717 | cl.setIsDragOccuring(isDragHappening); |
Winson Chung | 097eb0a | 2011-03-18 16:56:08 -0700 | [diff] [blame] | 1718 | if (state == null) { |
| 1719 | // If we are not in a shrunken state, mark all cell layouts as droppable (if they |
| 1720 | // have the space) |
| 1721 | cl.setAcceptsDrops(cl.findCellForSpan(null, spanX, spanY)); |
| 1722 | } else { |
| 1723 | switch (state) { |
| 1724 | case TOP: |
| 1725 | cl.setIsDefaultDropTarget(i == mCurrentPage); |
| 1726 | case BOTTOM_HIDDEN: |
| 1727 | case BOTTOM_VISIBLE: |
| 1728 | case SPRING_LOADED: |
| 1729 | if (state != ShrinkState.TOP) { |
| 1730 | cl.setIsDefaultDropTarget(false); |
| 1731 | } |
| 1732 | if (!isDragHappening) { |
| 1733 | // even if a drag isn't happening, we don't want to show a screen as |
| 1734 | // accepting drops if it doesn't have at least one free cell |
| 1735 | spanX = 1; |
| 1736 | spanY = 1; |
| 1737 | } |
| 1738 | // the page accepts drops if we can find at least one empty spot |
| 1739 | cl.setAcceptsDrops(cl.findCellForSpan(null, spanX, spanY)); |
| 1740 | break; |
| 1741 | default: |
| 1742 | throw new RuntimeException("Unhandled ShrinkState " + state); |
| 1743 | } |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | /* |
| 1749 | * |
| 1750 | * We call these methods (onDragStartedWithItemSpans/onDragStartedWithItemMinSize) whenever we |
| 1751 | * start a drag in Launcher, regardless of whether the drag has ever entered the Workspace |
| 1752 | * |
| 1753 | * These methods mark the appropriate pages as accepting drops (which alters their visual |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1754 | * appearance). |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1755 | * |
| 1756 | */ |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1757 | public void onDragStartedWithItemSpans(int spanX, int spanY, Bitmap b) { |
| 1758 | mIsDragInProcess = true; |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1759 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1760 | final Canvas canvas = new Canvas(); |
| 1761 | |
| 1762 | // We need to add extra padding to the bitmap to make room for the glow effect |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 1763 | final int bitmapPadding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1764 | |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 1765 | CellLayout cl = (CellLayout) getChildAt(0); |
| 1766 | int[] desiredSize = cl.cellSpansToSize(spanX, spanY); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1767 | // The outline is used to visualize where the item will land if dropped |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 1768 | mDragOutline = createDragOutline(b, canvas, bitmapPadding, desiredSize[0], desiredSize[1]); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1769 | |
| 1770 | updateWhichPagesAcceptDropsDuringDrag(mShrinkState, spanX, spanY); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | // we call this method whenever a drag and drop in Launcher finishes, even if Workspace was |
| 1774 | // never dragged over |
Patrick Dubroy | 7bccb42 | 2011-01-20 14:50:55 -0800 | [diff] [blame] | 1775 | public void onDragStopped(boolean success) { |
Michael Jurka | 0bb8563 | 2011-01-26 00:00:44 -0800 | [diff] [blame] | 1776 | mLastDragView = null; |
Patrick Dubroy | 7bccb42 | 2011-01-20 14:50:55 -0800 | [diff] [blame] | 1777 | // In the success case, DragController has already called onDragExit() |
| 1778 | if (!success) { |
| 1779 | doDragExit(); |
| 1780 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1781 | mIsDragInProcess = false; |
Michael Jurka | af91de0 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1782 | updateWhichPagesAcceptDrops(mShrinkState); |
Michael Jurka | 3e7c763 | 2010-10-02 16:01:03 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1785 | // We call this when we trigger an unshrink by clicking on the CellLayout cl |
| 1786 | public void unshrink(CellLayout clThatWasClicked) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1787 | unshrink(clThatWasClicked, false); |
| 1788 | } |
| 1789 | |
| 1790 | public void unshrink(CellLayout clThatWasClicked, boolean springLoaded) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1791 | int newCurrentPage = indexOfChild(clThatWasClicked); |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1792 | if (mIsSmall) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1793 | if (springLoaded) { |
| 1794 | setLayoutScale(SPRING_LOADED_DRAG_SHRINK_FACTOR); |
| 1795 | } |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 1796 | scrollToNewPageWithoutMovingPages(newCurrentPage); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1797 | unshrink(true, springLoaded); |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | public void enterSpringLoadedDragMode(CellLayout clThatWasClicked) { |
| 1803 | mShrinkState = ShrinkState.SPRING_LOADED; |
| 1804 | unshrink(clThatWasClicked, true); |
| 1805 | mDragTargetLayout.onDragEnter(); |
| 1806 | } |
| 1807 | |
| 1808 | public void exitSpringLoadedDragMode(ShrinkState shrinkState) { |
| 1809 | shrink(shrinkState); |
| 1810 | if (mDragTargetLayout != null) { |
| 1811 | mDragTargetLayout.onDragExit(); |
Michael Jurka | b0f28bd | 2010-07-30 11:58:59 -0700 | [diff] [blame] | 1812 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1815 | public void exitWidgetResizeMode() { |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 1816 | DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer); |
| 1817 | dragLayer.clearAllResizeFrames(); |
Patrick Dubroy | 758a923 | 2011-03-03 19:54:56 -0800 | [diff] [blame] | 1818 | } |
| 1819 | |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1820 | void unshrink(boolean animated) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1821 | unshrink(animated, false); |
| 1822 | } |
| 1823 | |
| 1824 | void unshrink(boolean animated, boolean springLoaded) { |
Michael Jurka | b7e0e88 | 2011-01-16 18:43:41 -0800 | [diff] [blame] | 1825 | mWaitingToShrink = false; |
Michael Jurka | b0f28bd | 2010-07-30 11:58:59 -0700 | [diff] [blame] | 1826 | if (mIsSmall) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1827 | float finalScaleFactor = 1.0f; |
| 1828 | float finalBackgroundAlpha = 0.0f; |
| 1829 | if (springLoaded) { |
| 1830 | finalScaleFactor = SPRING_LOADED_DRAG_SHRINK_FACTOR; |
| 1831 | finalBackgroundAlpha = 1.0f; |
| 1832 | } else { |
| 1833 | mIsSmall = false; |
| 1834 | } |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 1835 | if (mAnimator != null) { |
| 1836 | mAnimator.cancel(); |
| 1837 | } |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1838 | |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 1839 | mAnimator = new AnimatorSet(); |
Michael Jurka | b0f28bd | 2010-07-30 11:58:59 -0700 | [diff] [blame] | 1840 | final int screenCount = getChildCount(); |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1841 | |
| 1842 | final int duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1843 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1844 | final float[] oldTranslationXs = new float[getChildCount()]; |
| 1845 | final float[] oldTranslationYs = new float[getChildCount()]; |
| 1846 | final float[] oldScaleXs = new float[getChildCount()]; |
| 1847 | final float[] oldScaleYs = new float[getChildCount()]; |
| 1848 | final float[] oldBackgroundAlphas = new float[getChildCount()]; |
| 1849 | final float[] oldBackgroundAlphaMultipliers = new float[getChildCount()]; |
| 1850 | final float[] oldAlphas = new float[getChildCount()]; |
| 1851 | final float[] oldRotationYs = new float[getChildCount()]; |
| 1852 | final float[] newTranslationXs = new float[getChildCount()]; |
| 1853 | final float[] newTranslationYs = new float[getChildCount()]; |
| 1854 | final float[] newScaleXs = new float[getChildCount()]; |
| 1855 | final float[] newScaleYs = new float[getChildCount()]; |
| 1856 | final float[] newBackgroundAlphas = new float[getChildCount()]; |
| 1857 | final float[] newBackgroundAlphaMultipliers = new float[getChildCount()]; |
| 1858 | final float[] newAlphas = new float[getChildCount()]; |
| 1859 | final float[] newRotationYs = new float[getChildCount()]; |
| 1860 | |
Michael Jurka | b0f28bd | 2010-07-30 11:58:59 -0700 | [diff] [blame] | 1861 | for (int i = 0; i < screenCount; i++) { |
Patrick Dubroy | 7247f63 | 2010-08-04 16:02:59 -0700 | [diff] [blame] | 1862 | final CellLayout cl = (CellLayout)getChildAt(i); |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1863 | float finalAlphaValue = (i == mCurrentPage) ? 1.0f : 0.0f; |
Winson Chung | ae222ab | 2011-01-10 11:45:27 -0800 | [diff] [blame] | 1864 | float finalAlphaMultiplierValue = |
| 1865 | ((i == mCurrentPage) && (mShrinkState != ShrinkState.SPRING_LOADED)) ? |
| 1866 | 0.0f : 1.0f; |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1867 | float rotation = 0.0f; |
| 1868 | |
| 1869 | if (i < mCurrentPage) { |
| 1870 | rotation = WORKSPACE_ROTATION; |
| 1871 | } else if (i > mCurrentPage) { |
| 1872 | rotation = -WORKSPACE_ROTATION; |
| 1873 | } |
| 1874 | |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1875 | float translation = getOffsetXForRotation(rotation, cl.getWidth(), cl.getHeight()); |
Adam Cohen | cbbaf98 | 2010-11-12 14:50:33 -0800 | [diff] [blame] | 1876 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1877 | oldAlphas[i] = cl.getAlpha(); |
| 1878 | newAlphas[i] = finalAlphaValue; |
Michael Jurka | 3e5ad58 | 2011-02-03 22:46:34 -0800 | [diff] [blame] | 1879 | if (animated) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1880 | oldTranslationXs[i] = cl.getTranslationX(); |
| 1881 | oldTranslationYs[i] = cl.getTranslationY(); |
| 1882 | oldScaleXs[i] = cl.getScaleX(); |
| 1883 | oldScaleYs[i] = cl.getScaleY(); |
| 1884 | oldBackgroundAlphas[i] = cl.getBackgroundAlpha(); |
| 1885 | oldBackgroundAlphaMultipliers[i] = cl.getBackgroundAlphaMultiplier(); |
| 1886 | oldRotationYs[i] = cl.getRotationY(); |
Adam Cohen | 4904f66 | 2011-01-17 16:50:28 -0800 | [diff] [blame] | 1887 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1888 | newTranslationXs[i] = translation; |
| 1889 | newTranslationYs[i] = 0f; |
| 1890 | newScaleXs[i] = finalScaleFactor; |
| 1891 | newScaleYs[i] = finalScaleFactor; |
| 1892 | newBackgroundAlphas[i] = finalBackgroundAlpha; |
| 1893 | newBackgroundAlphaMultipliers[i] = finalAlphaMultiplierValue; |
| 1894 | newRotationYs[i] = rotation; |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1895 | } else { |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1896 | cl.setTranslationX(translation); |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1897 | cl.setTranslationY(0.0f); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 1898 | cl.setScaleX(finalScaleFactor); |
| 1899 | cl.setScaleY(finalScaleFactor); |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 1900 | cl.setBackgroundAlpha(0.0f); |
Winson Chung | ae222ab | 2011-01-10 11:45:27 -0800 | [diff] [blame] | 1901 | cl.setBackgroundAlphaMultiplier(finalAlphaMultiplierValue); |
Adam Cohen | f34bab5 | 2010-09-30 14:11:56 -0700 | [diff] [blame] | 1902 | cl.setAlpha(finalAlphaValue); |
| 1903 | cl.setRotationY(rotation); |
Michael Jurka | 3e5ad58 | 2011-02-03 22:46:34 -0800 | [diff] [blame] | 1904 | mUnshrinkAnimationListener.onAnimationEnd(null); |
Michael Jurka | 4cb3724 | 2010-08-09 21:05:32 -0700 | [diff] [blame] | 1905 | } |
Michael Jurka | b0f28bd | 2010-07-30 11:58:59 -0700 | [diff] [blame] | 1906 | } |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1907 | Display display = mLauncher.getWindowManager().getDefaultDisplay(); |
| 1908 | boolean isLandscape = display.getWidth() > display.getHeight(); |
| 1909 | switch (mShrinkState) { |
| 1910 | // animating out |
| 1911 | case TOP: |
| 1912 | // customize |
| 1913 | if (animated) { |
| 1914 | mWallpaperOffset.setHorizontalCatchupConstant(isLandscape ? 0.65f : 0.62f); |
| 1915 | mWallpaperOffset.setVerticalCatchupConstant(isLandscape ? 0.65f : 0.62f); |
| 1916 | mWallpaperOffset.setOverrideHorizontalCatchupConstant(true); |
| 1917 | } |
| 1918 | break; |
| 1919 | case MIDDLE: |
| 1920 | case SPRING_LOADED: |
| 1921 | if (animated) { |
| 1922 | mWallpaperOffset.setHorizontalCatchupConstant(isLandscape ? 0.49f : 0.46f); |
| 1923 | mWallpaperOffset.setVerticalCatchupConstant(isLandscape ? 0.49f : 0.46f); |
| 1924 | mWallpaperOffset.setOverrideHorizontalCatchupConstant(true); |
| 1925 | } |
| 1926 | break; |
| 1927 | case BOTTOM_HIDDEN: |
| 1928 | case BOTTOM_VISIBLE: |
| 1929 | // all apps |
| 1930 | if (animated) { |
Michael Jurka | ea57348 | 2011-02-03 19:48:18 -0800 | [diff] [blame] | 1931 | mWallpaperOffset.setHorizontalCatchupConstant(isLandscape ? 0.65f : 0.65f); |
| 1932 | mWallpaperOffset.setVerticalCatchupConstant(isLandscape ? 0.65f : 0.65f); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1933 | mWallpaperOffset.setOverrideHorizontalCatchupConstant(true); |
| 1934 | } |
| 1935 | break; |
| 1936 | } |
Michael Jurka | ab1983f | 2011-01-18 15:50:17 -0800 | [diff] [blame] | 1937 | if (animated) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1938 | ValueAnimator animWithInterpolator = |
| 1939 | ValueAnimator.ofFloat(0f, 1f).setDuration(duration); |
| 1940 | animWithInterpolator.setInterpolator(mZoomInInterpolator); |
Adam Lesinski | 6b879f0 | 2010-11-04 16:15:23 -0700 | [diff] [blame] | 1941 | |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1942 | final float oldHorizontalWallpaperOffset = getHorizontalWallpaperOffset(); |
| 1943 | final float oldVerticalWallpaperOffset = getVerticalWallpaperOffset(); |
| 1944 | final float newHorizontalWallpaperOffset = wallpaperOffsetForCurrentScroll(); |
| 1945 | final float newVerticalWallpaperOffset = 0.5f; |
Michael Jurka | c2e26a0 | 2011-03-24 15:20:26 -0700 | [diff] [blame] | 1946 | animWithInterpolator.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 1947 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 1948 | if (b == 0f) { |
| 1949 | // an optimization, but not required |
| 1950 | return; |
| 1951 | } |
| 1952 | fastInvalidate(); |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1953 | setHorizontalWallpaperOffset( |
| 1954 | a * oldHorizontalWallpaperOffset + b * newHorizontalWallpaperOffset); |
| 1955 | setVerticalWallpaperOffset( |
| 1956 | a * oldVerticalWallpaperOffset + b * newVerticalWallpaperOffset); |
| 1957 | for (int i = 0; i < screenCount; i++) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1958 | final CellLayout cl = (CellLayout) getChildAt(i); |
| 1959 | cl.fastInvalidate(); |
| 1960 | cl.setFastTranslationX( |
| 1961 | a * oldTranslationXs[i] + b * newTranslationXs[i]); |
| 1962 | cl.setFastTranslationY( |
| 1963 | a * oldTranslationYs[i] + b * newTranslationYs[i]); |
| 1964 | cl.setFastScaleX(a * oldScaleXs[i] + b * newScaleXs[i]); |
| 1965 | cl.setFastScaleY(a * oldScaleYs[i] + b * newScaleYs[i]); |
| 1966 | cl.setFastBackgroundAlpha( |
| 1967 | a * oldBackgroundAlphas[i] + b * newBackgroundAlphas[i]); |
| 1968 | cl.setBackgroundAlphaMultiplier(a * oldBackgroundAlphaMultipliers[i] + |
| 1969 | b * newBackgroundAlphaMultipliers[i]); |
| 1970 | cl.setFastAlpha(a * oldAlphas[i] + b * newAlphas[i]); |
| 1971 | } |
| 1972 | } |
| 1973 | }); |
| 1974 | |
| 1975 | ValueAnimator rotationAnim = |
| 1976 | ValueAnimator.ofFloat(0f, 1f).setDuration(duration); |
| 1977 | rotationAnim.setInterpolator(new DecelerateInterpolator(2.0f)); |
Michael Jurka | c2e26a0 | 2011-03-24 15:20:26 -0700 | [diff] [blame] | 1978 | rotationAnim.addUpdateListener(new LauncherAnimatorUpdateListener() { |
| 1979 | public void onAnimationUpdate(float a, float b) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1980 | // don't invalidate workspace because we did it above |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 1981 | if (b == 0f) { |
| 1982 | // an optimization, but not required |
| 1983 | return; |
| 1984 | } |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1985 | for (int i = 0; i < screenCount; i++) { |
Michael Jurka | 742574b | 2011-02-02 23:51:01 -0800 | [diff] [blame] | 1986 | final CellLayout cl = (CellLayout) getChildAt(i); |
| 1987 | cl.setFastRotationY(a * oldRotationYs[i] + b * newRotationYs[i]); |
| 1988 | } |
| 1989 | } |
| 1990 | }); |
| 1991 | |
| 1992 | mAnimator.playTogether(animWithInterpolator, rotationAnim); |
Michael Jurka | c86756c | 2010-10-10 15:15:47 -0700 | [diff] [blame] | 1993 | // If we call this when we're not animated, onAnimationEnd is never called on |
| 1994 | // the listener; make sure we only use the listener when we're actually animating |
Michael Jurka | 3c4c20f | 2010-10-28 15:36:06 -0700 | [diff] [blame] | 1995 | mAnimator.addListener(mUnshrinkAnimationListener); |
| 1996 | mAnimator.start(); |
Michael Jurka | ca5b836 | 2011-01-27 13:23:26 -0800 | [diff] [blame] | 1997 | } else { |
| 1998 | setHorizontalWallpaperOffset(wallpaperOffsetForCurrentScroll()); |
| 1999 | setVerticalWallpaperOffset(0.5f); |
| 2000 | updateWallpaperOffsetImmediately(); |
Michael Jurka | c86756c | 2010-10-10 15:15:47 -0700 | [diff] [blame] | 2001 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 2002 | } |
Winson Chung | 8d006d5 | 2010-11-29 15:55:29 -0800 | [diff] [blame] | 2003 | |
Winson Chung | a58f8bb | 2010-12-14 18:18:05 -0800 | [diff] [blame] | 2004 | if (!springLoaded) { |
| 2005 | hideBackgroundGradient(); |
| 2006 | } |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2009 | /** |
| 2010 | * Draw the View v into the given Canvas. |
| 2011 | * |
| 2012 | * @param v the view to draw |
| 2013 | * @param destCanvas the canvas to draw on |
| 2014 | * @param padding the horizontal and vertical padding to use when drawing |
| 2015 | */ |
| 2016 | private void drawDragView(View v, Canvas destCanvas, int padding) { |
| 2017 | final Rect clipRect = mTempRect; |
| 2018 | v.getDrawingRect(clipRect); |
| 2019 | |
| 2020 | // For a TextView, adjust the clip rect so that we don't include the text label |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 2021 | if (v instanceof BubbleTextView) { |
| 2022 | final BubbleTextView tv = (BubbleTextView) v; |
| 2023 | clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V + |
| 2024 | tv.getLayout().getLineTop(0); |
| 2025 | } else if (v instanceof TextView) { |
Winson Chung | bbc60d8 | 2010-11-11 16:34:41 -0800 | [diff] [blame] | 2026 | final TextView tv = (TextView) v; |
Winson Chung | 656d11c | 2010-11-29 17:15:47 -0800 | [diff] [blame] | 2027 | clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding() + |
| 2028 | tv.getLayout().getLineTop(0); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | // Draw the View into the bitmap. |
| 2032 | // The translate of scrollX and scrollY is necessary when drawing TextViews, because |
| 2033 | // they set scrollX and scrollY to large values to achieve centered text |
| 2034 | |
| 2035 | destCanvas.save(); |
| 2036 | destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); |
| 2037 | destCanvas.clipRect(clipRect, Op.REPLACE); |
| 2038 | v.draw(destCanvas); |
| 2039 | destCanvas.restore(); |
| 2040 | } |
| 2041 | |
| 2042 | /** |
| 2043 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 2044 | * Responsibility for the bitmap is transferred to the caller. |
| 2045 | */ |
| 2046 | private Bitmap createDragOutline(View v, Canvas canvas, int padding) { |
| 2047 | final int outlineColor = getResources().getColor(R.color.drag_outline_color); |
| 2048 | final Bitmap b = Bitmap.createBitmap( |
| 2049 | v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888); |
| 2050 | |
| 2051 | canvas.setBitmap(b); |
| 2052 | drawDragView(v, canvas, padding); |
Adam Cohen | 5bb50bd | 2010-12-03 11:39:55 -0800 | [diff] [blame] | 2053 | mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2054 | return b; |
| 2055 | } |
| 2056 | |
| 2057 | /** |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2058 | * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. |
| 2059 | * Responsibility for the bitmap is transferred to the caller. |
| 2060 | */ |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2061 | private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding, int w, int h) { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2062 | final int outlineColor = getResources().getColor(R.color.drag_outline_color); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2063 | final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2064 | canvas.setBitmap(b); |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2065 | |
| 2066 | Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight()); |
| 2067 | float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(), |
| 2068 | (h - padding) / (float) orig.getHeight()); |
| 2069 | int scaledWidth = (int) (scaleFactor * orig.getWidth()); |
| 2070 | int scaledHeight = (int) (scaleFactor * orig.getHeight()); |
| 2071 | Rect dst = new Rect(0, 0, scaledWidth, scaledHeight); |
| 2072 | |
| 2073 | // center the image |
| 2074 | dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2); |
| 2075 | |
| 2076 | Paint p = new Paint(); |
| 2077 | p.setFilterBitmap(true); |
| 2078 | canvas.drawBitmap(orig, src, dst, p); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2079 | mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor); |
| 2080 | |
| 2081 | return b; |
| 2082 | } |
| 2083 | |
| 2084 | /** |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2085 | * Creates a drag outline to represent a drop (that we don't have the actual information for |
| 2086 | * yet). May be changed in the future to alter the drop outline slightly depending on the |
| 2087 | * clip description mime data. |
| 2088 | */ |
| 2089 | private Bitmap createExternalDragOutline(Canvas canvas, int padding) { |
| 2090 | Resources r = getResources(); |
| 2091 | final int outlineColor = r.getColor(R.color.drag_outline_color); |
| 2092 | final int iconWidth = r.getDimensionPixelSize(R.dimen.workspace_cell_width); |
| 2093 | final int iconHeight = r.getDimensionPixelSize(R.dimen.workspace_cell_height); |
| 2094 | final int rectRadius = r.getDimensionPixelSize(R.dimen.external_drop_icon_rect_radius); |
| 2095 | final int inset = (int) (Math.min(iconWidth, iconHeight) * 0.2f); |
| 2096 | final Bitmap b = Bitmap.createBitmap( |
| 2097 | iconWidth + padding, iconHeight + padding, Bitmap.Config.ARGB_8888); |
| 2098 | |
| 2099 | canvas.setBitmap(b); |
| 2100 | canvas.drawRoundRect(new RectF(inset, inset, iconWidth - inset, iconHeight - inset), |
| 2101 | rectRadius, rectRadius, mExternalDragOutlinePaint); |
Adam Cohen | 5bb50bd | 2010-12-03 11:39:55 -0800 | [diff] [blame] | 2102 | mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor); |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2103 | return b; |
| 2104 | } |
| 2105 | |
| 2106 | /** |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2107 | * Returns a new bitmap to show when the given View is being dragged around. |
| 2108 | * Responsibility for the bitmap is transferred to the caller. |
| 2109 | */ |
| 2110 | private Bitmap createDragBitmap(View v, Canvas canvas, int padding) { |
| 2111 | final int outlineColor = getResources().getColor(R.color.drag_outline_color); |
| 2112 | final Bitmap b = Bitmap.createBitmap( |
| 2113 | mDragOutline.getWidth(), mDragOutline.getHeight(), Bitmap.Config.ARGB_8888); |
| 2114 | |
| 2115 | canvas.setBitmap(b); |
| 2116 | canvas.drawBitmap(mDragOutline, 0, 0, null); |
| 2117 | drawDragView(v, canvas, padding); |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 2118 | mOutlineHelper.applyOuterBlur(b, canvas, outlineColor); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2119 | |
| 2120 | return b; |
| 2121 | } |
| 2122 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2123 | void startDrag(CellLayout.CellInfo cellInfo) { |
| 2124 | View child = cellInfo.cell; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2125 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2126 | // 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] | 2127 | if (!child.isInTouchMode()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2128 | return; |
| 2129 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2130 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2131 | mDragInfo = cellInfo; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2132 | |
Patrick Dubroy | 0c10bb4 | 2011-01-14 18:20:08 -0800 | [diff] [blame] | 2133 | CellLayout current = (CellLayout) getChildAt(cellInfo.screen); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2134 | current.onDragChild(child); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2135 | |
| 2136 | child.clearFocus(); |
| 2137 | child.setPressed(false); |
| 2138 | |
| 2139 | final Canvas canvas = new Canvas(); |
| 2140 | |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 2141 | // We need to add extra padding to the bitmap to make room for the glow effect |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 2142 | final int bitmapPadding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS; |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 2143 | |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2144 | // The outline is used to visualize where the item will land if dropped |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 2145 | mDragOutline = createDragOutline(child, canvas, bitmapPadding); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2146 | |
| 2147 | // The drag bitmap follows the touch point around on the screen |
Patrick Dubroy | 8e58e91 | 2010-10-14 13:21:48 -0700 | [diff] [blame] | 2148 | final Bitmap b = createDragBitmap(child, canvas, bitmapPadding); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2149 | |
| 2150 | final int bmpWidth = b.getWidth(); |
| 2151 | final int bmpHeight = b.getHeight(); |
| 2152 | child.getLocationOnScreen(mTempXY); |
| 2153 | final int screenX = (int) mTempXY[0] + (child.getWidth() - bmpWidth) / 2; |
| 2154 | final int screenY = (int) mTempXY[1] + (child.getHeight() - bmpHeight) / 2; |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 2155 | mLauncher.lockScreenOrientation(); |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 2156 | mDragController.startDrag( |
| 2157 | b, screenX, screenY, this, child.getTag(), DragController.DRAG_ACTION_MOVE); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 2158 | b.recycle(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2159 | } |
| 2160 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2161 | void addApplicationShortcut(ShortcutInfo info, int screen, int cellX, int cellY, |
| 2162 | boolean insertAtFirst, int intersectX, int intersectY) { |
| 2163 | final CellLayout cellLayout = (CellLayout) getChildAt(screen); |
| 2164 | View view = mLauncher.createShortcut(R.layout.application, cellLayout, (ShortcutInfo) info); |
| 2165 | |
| 2166 | final int[] cellXY = new int[2]; |
| 2167 | cellLayout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectX, intersectY); |
| 2168 | addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, insertAtFirst); |
| 2169 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, |
| 2170 | LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, |
| 2171 | cellXY[0], cellXY[1]); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2172 | } |
| 2173 | |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2174 | private void setPositionForDropAnimation( |
| 2175 | View dragView, int dragViewX, int dragViewY, View parent, View child) { |
| 2176 | final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); |
| 2177 | |
| 2178 | // Based on the position of the drag view, find the top left of the original view |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 2179 | int viewX = dragViewX + (dragView.getWidth() - child.getMeasuredWidth()) / 2; |
| 2180 | int viewY = dragViewY + (dragView.getHeight() - child.getMeasuredHeight()) / 2; |
Adam Cohen | 8878a32 | 2011-03-28 13:18:42 -0700 | [diff] [blame] | 2181 | viewX += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetX); |
| 2182 | viewY += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY); |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2183 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2184 | // Set its old pos (in the new parent's coordinates); it will be animated |
| 2185 | // in animateViewIntoPosition after the next layout pass |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2186 | lp.oldX = viewX - (parent.getLeft() - mScrollX); |
| 2187 | lp.oldY = viewY - (parent.getTop() - mScrollY); |
| 2188 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2189 | |
Adam Cohen | df9de0b | 2011-01-10 11:01:49 -0800 | [diff] [blame] | 2190 | /* |
| 2191 | * We should be careful that this method cannot result in any synchronous requestLayout() |
| 2192 | * calls, as it is called from onLayout(). |
| 2193 | */ |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2194 | public void animateViewIntoPosition(final View view) { |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 2195 | final CellLayout parent = (CellLayout) view.getParent().getParent(); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2196 | final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams(); |
| 2197 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2198 | // Convert the animation params to be relative to the Workspace, not the CellLayout |
| 2199 | final int fromX = lp.oldX + parent.getLeft(); |
| 2200 | final int fromY = lp.oldY + parent.getTop(); |
| 2201 | |
| 2202 | final int dx = lp.x - lp.oldX; |
| 2203 | final int dy = lp.y - lp.oldY; |
| 2204 | |
| 2205 | // Calculate the duration of the animation based on the object's distance |
| 2206 | final float dist = (float) Math.sqrt(dx*dx + dy*dy); |
| 2207 | final Resources res = getResources(); |
| 2208 | final float maxDist = (float) res.getInteger(R.integer.config_dropAnimMaxDist); |
Patrick Dubroy | 8ae3a62 | 2010-11-01 13:49:51 -0700 | [diff] [blame] | 2209 | int duration = res.getInteger(R.integer.config_dropAnimMaxDuration); |
| 2210 | if (dist < maxDist) { |
| 2211 | duration *= mQuintEaseOutInterpolator.getInterpolation(dist / maxDist); |
| 2212 | } |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2213 | |
Patrick Dubroy | f243128 | 2010-11-02 14:46:20 -0700 | [diff] [blame] | 2214 | if (mDropAnim != null) { |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2215 | mDropAnim.end(); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2216 | } |
Patrick Dubroy | f243128 | 2010-11-02 14:46:20 -0700 | [diff] [blame] | 2217 | mDropAnim = new ValueAnimator(); |
| 2218 | mDropAnim.setInterpolator(mQuintEaseOutInterpolator); |
| 2219 | |
| 2220 | // The view is invisible during the animation; we render it manually. |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2221 | mDropAnim.addListener(new AnimatorListenerAdapter() { |
Patrick Dubroy | f243128 | 2010-11-02 14:46:20 -0700 | [diff] [blame] | 2222 | public void onAnimationStart(Animator animation) { |
| 2223 | // Set this here so that we don't render it until the animation begins |
| 2224 | mDropView = view; |
| 2225 | } |
| 2226 | |
Michael Jurka | 8edd75c | 2010-12-17 20:15:06 -0800 | [diff] [blame] | 2227 | public void onAnimationEnd(Animator animation) { |
Patrick Dubroy | f243128 | 2010-11-02 14:46:20 -0700 | [diff] [blame] | 2228 | if (mDropView != null) { |
| 2229 | mDropView.setVisibility(View.VISIBLE); |
| 2230 | mDropView = null; |
| 2231 | } |
| 2232 | } |
| 2233 | }); |
Patrick Dubroy | 8ae3a62 | 2010-11-01 13:49:51 -0700 | [diff] [blame] | 2234 | |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2235 | mDropAnim.setDuration(duration); |
| 2236 | mDropAnim.setFloatValues(0.0f, 1.0f); |
| 2237 | mDropAnim.removeAllUpdateListeners(); |
| 2238 | mDropAnim.addUpdateListener(new AnimatorUpdateListener() { |
| 2239 | public void onAnimationUpdate(ValueAnimator animation) { |
| 2240 | final float percent = (Float) animation.getAnimatedValue(); |
| 2241 | // Invalidate the old position |
| 2242 | invalidate(mDropViewPos[0], mDropViewPos[1], |
| 2243 | mDropViewPos[0] + view.getWidth(), mDropViewPos[1] + view.getHeight()); |
| 2244 | |
| 2245 | mDropViewPos[0] = fromX + (int) (percent * dx + 0.5f); |
| 2246 | mDropViewPos[1] = fromY + (int) (percent * dy + 0.5f); |
| 2247 | invalidate(mDropViewPos[0], mDropViewPos[1], |
| 2248 | mDropViewPos[0] + view.getWidth(), mDropViewPos[1] + view.getHeight()); |
| 2249 | } |
| 2250 | }); |
Patrick Dubroy | 8ae3a62 | 2010-11-01 13:49:51 -0700 | [diff] [blame] | 2251 | |
Patrick Dubroy | 6920c2c | 2010-12-19 20:24:40 -0800 | [diff] [blame] | 2252 | mDropAnim.start(); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | /** |
| 2256 | * {@inheritDoc} |
| 2257 | */ |
| 2258 | public boolean acceptDrop(DragSource source, int x, int y, |
| 2259 | int xOffset, int yOffset, DragView dragView, Object dragInfo) { |
| 2260 | |
| 2261 | // If it's an external drop (e.g. from All Apps), check if it should be accepted |
| 2262 | if (source != this) { |
| 2263 | // Don't accept the drop if we're not over a screen at time of drop |
Michael Jurka | 3d79192 | 2010-11-24 13:35:32 -0800 | [diff] [blame] | 2264 | if (mDragTargetLayout == null || !mDragTargetLayout.getAcceptsDrops()) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2265 | return false; |
| 2266 | } |
| 2267 | |
| 2268 | final CellLayout.CellInfo dragCellInfo = mDragInfo; |
| 2269 | final int spanX = dragCellInfo == null ? 1 : dragCellInfo.spanX; |
| 2270 | final int spanY = dragCellInfo == null ? 1 : dragCellInfo.spanY; |
| 2271 | |
| 2272 | final View ignoreView = dragCellInfo == null ? null : dragCellInfo.cell; |
| 2273 | |
| 2274 | // Don't accept the drop if there's no room for the item |
| 2275 | if (!mDragTargetLayout.findCellForSpanIgnoring(null, spanX, spanY, ignoreView)) { |
| 2276 | mLauncher.showOutOfSpaceMessage(); |
| 2277 | return false; |
| 2278 | } |
| 2279 | } |
| 2280 | return true; |
| 2281 | } |
| 2282 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2283 | public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, |
| 2284 | DragView dragView, Object dragInfo) { |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 2285 | boolean largeOrSpringLoaded = !mIsSmall || mWasSpringLoadedOnDragExit; |
| 2286 | int originX = largeOrSpringLoaded ? x - xOffset : x - xOffset + dragView.getWidth() / 2; |
| 2287 | int originY = largeOrSpringLoaded ? y - yOffset : y - yOffset + dragView.getHeight() / 2; |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2288 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2289 | if (mIsSmall || mIsInUnshrinkAnimation) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2290 | // get originX and originY in the local coordinate system of the screen |
| 2291 | mTempOriginXY[0] = originX; |
| 2292 | mTempOriginXY[1] = originY; |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2293 | mapPointFromSelfToChild(mDragTargetLayout, mTempOriginXY); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2294 | originX = (int)mTempOriginXY[0]; |
| 2295 | originY = (int)mTempOriginXY[1]; |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 2296 | if (!largeOrSpringLoaded) { |
| 2297 | originX -= mDragTargetLayout.getCellWidth() / 2; |
| 2298 | originY -= mDragTargetLayout.getCellHeight() / 2; |
| 2299 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2300 | } |
Michael Jurka | c6ee42e | 2010-09-30 12:04:50 -0700 | [diff] [blame] | 2301 | |
Michael Jurka | 3e5ad58 | 2011-02-03 22:46:34 -0800 | [diff] [blame] | 2302 | // When you are in customization mode and drag to a particular screen, make that the |
| 2303 | // new current/default screen, so any subsequent taps add items to that screen |
| 2304 | if (!mLauncher.isAllAppsVisible()) { |
| 2305 | int dragTargetIndex = indexOfChild(mDragTargetLayout); |
| 2306 | if (mCurrentPage != dragTargetIndex && (mIsSmall || mIsInUnshrinkAnimation)) { |
| 2307 | scrollToNewPageWithoutMovingPages(dragTargetIndex); |
| 2308 | } |
Michael Jurka | b09cac5 | 2011-01-05 20:23:39 -0800 | [diff] [blame] | 2309 | } |
| 2310 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2311 | if (source != this) { |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 2312 | final int[] touchXY = new int[] { originX, originY }; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 2313 | if ((mIsSmall || mIsInUnshrinkAnimation) && !mLauncher.isAllAppsVisible()) { |
| 2314 | // When the workspace is shrunk and the drop comes from customize, don't actually |
| 2315 | // add the item to the screen -- customize will do this itself |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 2316 | ((ItemInfo) dragInfo).dropPos = touchXY; |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 2317 | return; |
| 2318 | } |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 2319 | onDropExternal(touchXY, dragInfo, mDragTargetLayout, false, dragView, originX, originY); |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2320 | } else if (mDragInfo != null) { |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2321 | final View cell = mDragInfo.cell; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2322 | CellLayout dropTargetLayout = mDragTargetLayout; |
| 2323 | |
| 2324 | // Handle the case where the user drops when in the scroll area. |
| 2325 | // This is treated as a drop on the adjacent page. |
| 2326 | if (dropTargetLayout == null && mInScrollArea) { |
| 2327 | if (mPendingScrollDirection == DragController.SCROLL_LEFT) { |
| 2328 | dropTargetLayout = (CellLayout) getChildAt(mCurrentPage - 1); |
| 2329 | } else if (mPendingScrollDirection == DragController.SCROLL_RIGHT) { |
| 2330 | dropTargetLayout = (CellLayout) getChildAt(mCurrentPage + 1); |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | if (dropTargetLayout != null) { |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2335 | // Move internally |
| 2336 | mTargetCell = findNearestVacantArea(originX, originY, |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2337 | mDragInfo.spanX, mDragInfo.spanY, cell, dropTargetLayout, |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2338 | mTargetCell); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2339 | |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2340 | final int screen = (mTargetCell == null) ? |
| 2341 | mDragInfo.screen : indexOfChild(dropTargetLayout); |
| 2342 | |
| 2343 | if (screen != mCurrentPage) { |
| 2344 | snapToPage(screen); |
| 2345 | } |
| 2346 | |
| 2347 | if (mTargetCell != null) { |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2348 | if (screen != mDragInfo.screen) { |
| 2349 | // Reparent the view |
| 2350 | ((CellLayout) getChildAt(mDragInfo.screen)).removeView(cell); |
| 2351 | addInScreen(cell, screen, mTargetCell[0], mTargetCell[1], |
| 2352 | mDragInfo.spanX, mDragInfo.spanY); |
| 2353 | } |
| 2354 | |
| 2355 | // update the item's position after drop |
| 2356 | final ItemInfo info = (ItemInfo) cell.getTag(); |
| 2357 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 2358 | dropTargetLayout.onMove(cell, mTargetCell[0], mTargetCell[1]); |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2359 | lp.cellX = mTargetCell[0]; |
| 2360 | lp.cellY = mTargetCell[1]; |
| 2361 | cell.setId(LauncherModel.getCellLayoutChildId(-1, mDragInfo.screen, |
| 2362 | mTargetCell[0], mTargetCell[1], mDragInfo.spanX, mDragInfo.spanY)); |
| 2363 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2364 | if (cell instanceof LauncherAppWidgetHostView) { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2365 | final CellLayout cellLayout = dropTargetLayout; |
| 2366 | // We post this call so that the widget has a chance to be placed |
| 2367 | // in its final location |
| 2368 | |
| 2369 | final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell; |
| 2370 | AppWidgetProviderInfo pinfo = hostView.getAppWidgetInfo(); |
Adam Cohen | 27c09b0 | 2011-02-28 14:45:11 -0800 | [diff] [blame] | 2371 | if (pinfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE) { |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2372 | final Runnable resizeRunnable = new Runnable() { |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2373 | public void run() { |
Adam Cohen | 6788269 | 2011-03-11 15:29:03 -0800 | [diff] [blame] | 2374 | DragLayer dragLayer = (DragLayer) |
| 2375 | mLauncher.findViewById(R.id.drag_layer); |
| 2376 | dragLayer.addResizeFrame(info, hostView, |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2377 | cellLayout); |
| 2378 | } |
Adam Cohen | 26976d9 | 2011-03-22 15:33:33 -0700 | [diff] [blame] | 2379 | }; |
| 2380 | post(new Runnable() { |
| 2381 | public void run() { |
| 2382 | if (!isPageMoving()) { |
| 2383 | resizeRunnable.run(); |
| 2384 | } else { |
| 2385 | mDelayedResizeRunnable = resizeRunnable; |
| 2386 | } |
| 2387 | } |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2388 | }); |
| 2389 | } |
| 2390 | } |
| 2391 | |
Patrick Dubroy | 9438336 | 2010-10-29 15:03:24 -0700 | [diff] [blame] | 2392 | LauncherModel.moveItemInDatabase(mLauncher, info, |
| 2393 | LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, |
| 2394 | lp.cellX, lp.cellY); |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2395 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2396 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2397 | |
Michael Jurka | 8c920dd | 2011-01-20 14:16:56 -0800 | [diff] [blame] | 2398 | final CellLayout parent = (CellLayout) cell.getParent().getParent(); |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 2399 | |
| 2400 | // Prepare it to be animated into its new position |
| 2401 | // This must be called after the view has been re-parented |
Patrick Dubroy | cd68ff5 | 2010-10-28 17:57:05 -0700 | [diff] [blame] | 2402 | setPositionForDropAnimation(dragView, originX, originY, parent, cell); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2403 | boolean animateDrop = !mWasSpringLoadedOnDragExit; |
| 2404 | parent.onDropChild(cell, animateDrop); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2408 | public void onDragEnter(DragSource source, int x, int y, int xOffset, |
| 2409 | int yOffset, DragView dragView, Object dragInfo) { |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 2410 | mDragTargetLayout = null; // Reset the drag state |
| 2411 | |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2412 | if (!mIsSmall) { |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 2413 | mDragTargetLayout = getCurrentDropLayout(); |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2414 | mDragTargetLayout.onDragEnter(); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2415 | showOutlines(); |
| 2416 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2417 | } |
| 2418 | |
Michael Jurka | 1801479 | 2010-10-14 09:01:34 -0700 | [diff] [blame] | 2419 | public DropTarget getDropTargetDelegate(DragSource source, int x, int y, |
| 2420 | int xOffset, int yOffset, DragView dragView, Object dragInfo) { |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 2421 | |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 2422 | if (mIsSmall || mIsInUnshrinkAnimation) { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2423 | // If we're shrunken, don't let anyone drag on folders/etc that are on the mini-screens |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2424 | return null; |
| 2425 | } |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 2426 | // We may need to delegate the drag to a child view. If a 1x1 item |
| 2427 | // would land in a cell occupied by a DragTarget (e.g. a Folder), |
| 2428 | // then drag events should be handled by that child. |
| 2429 | |
Adam Cohen | d4844c3 | 2011-02-18 19:25:06 -0800 | [diff] [blame] | 2430 | ItemInfo item = (ItemInfo) dragInfo; |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 2431 | CellLayout currentLayout = getCurrentDropLayout(); |
| 2432 | |
| 2433 | int dragPointX, dragPointY; |
| 2434 | if (item.spanX == 1 && item.spanY == 1) { |
| 2435 | // For a 1x1, calculate the drop cell exactly as in onDragOver |
| 2436 | dragPointX = x - xOffset; |
| 2437 | dragPointY = y - yOffset; |
| 2438 | } else { |
| 2439 | // Otherwise, use the exact drag coordinates |
| 2440 | dragPointX = x; |
| 2441 | dragPointY = y; |
| 2442 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2443 | dragPointX += mScrollX - currentLayout.getLeft(); |
| 2444 | dragPointY += mScrollY - currentLayout.getTop(); |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 2445 | |
| 2446 | // If we are dragging over a cell that contains a DropTarget that will |
| 2447 | // accept the drop, delegate to that DropTarget. |
| 2448 | final int[] cellXY = mTempCell; |
| 2449 | currentLayout.estimateDropCell(dragPointX, dragPointY, item.spanX, item.spanY, cellXY); |
| 2450 | View child = currentLayout.getChildAt(cellXY[0], cellXY[1]); |
| 2451 | if (child instanceof DropTarget) { |
| 2452 | DropTarget target = (DropTarget)child; |
| 2453 | if (target.acceptDrop(source, x, y, xOffset, yOffset, dragView, dragInfo)) { |
| 2454 | return target; |
| 2455 | } |
| 2456 | } |
| 2457 | return null; |
| 2458 | } |
| 2459 | |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2460 | /** |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2461 | * Tests to see if the drop will be accepted by Launcher, and if so, includes additional data |
| 2462 | * in the returned structure related to the widgets that match the drop (or a null list if it is |
| 2463 | * a shortcut drop). If the drop is not accepted then a null structure is returned. |
| 2464 | */ |
| 2465 | private Pair<Integer, List<WidgetMimeTypeHandlerData>> validateDrag(DragEvent event) { |
| 2466 | final LauncherModel model = mLauncher.getModel(); |
| 2467 | final ClipDescription desc = event.getClipDescription(); |
| 2468 | final int mimeTypeCount = desc.getMimeTypeCount(); |
| 2469 | for (int i = 0; i < mimeTypeCount; ++i) { |
| 2470 | final String mimeType = desc.getMimeType(i); |
| 2471 | if (mimeType.equals(InstallShortcutReceiver.SHORTCUT_MIMETYPE)) { |
| 2472 | return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, null); |
| 2473 | } else { |
| 2474 | final List<WidgetMimeTypeHandlerData> widgets = |
| 2475 | model.resolveWidgetsForMimeType(mContext, mimeType); |
| 2476 | if (widgets.size() > 0) { |
| 2477 | return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, widgets); |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | return null; |
| 2482 | } |
| 2483 | |
| 2484 | /** |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2485 | * Global drag and drop handler |
| 2486 | */ |
| 2487 | @Override |
| 2488 | public boolean onDragEvent(DragEvent event) { |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2489 | final ClipDescription desc = event.getClipDescription(); |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2490 | final CellLayout layout = (CellLayout) getChildAt(mCurrentPage); |
| 2491 | final int[] pos = new int[2]; |
| 2492 | layout.getLocationOnScreen(pos); |
| 2493 | // We need to offset the drag coordinates to layout coordinate space |
| 2494 | final int x = (int) event.getX() - pos[0]; |
| 2495 | final int y = (int) event.getY() - pos[1]; |
| 2496 | |
| 2497 | switch (event.getAction()) { |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2498 | case DragEvent.ACTION_DRAG_STARTED: { |
| 2499 | // Validate this drag |
| 2500 | Pair<Integer, List<WidgetMimeTypeHandlerData>> test = validateDrag(event); |
| 2501 | if (test != null) { |
| 2502 | boolean isShortcut = (test.second == null); |
| 2503 | if (isShortcut) { |
| 2504 | // Check if we have enough space on this screen to add a new shortcut |
| 2505 | if (!layout.findCellForSpan(pos, 1, 1)) { |
| 2506 | Toast.makeText(mContext, mContext.getString(R.string.out_of_space), |
| 2507 | Toast.LENGTH_SHORT).show(); |
| 2508 | return false; |
| 2509 | } |
| 2510 | } |
| 2511 | } else { |
| 2512 | // Show error message if we couldn't accept any of the items |
| 2513 | Toast.makeText(mContext, mContext.getString(R.string.external_drop_widget_error), |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2514 | Toast.LENGTH_SHORT).show(); |
| 2515 | return false; |
| 2516 | } |
| 2517 | |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2518 | // Create the drag outline |
| 2519 | // We need to add extra padding to the bitmap to make room for the glow effect |
| 2520 | final Canvas canvas = new Canvas(); |
Michael Jurka | 38b4f7c | 2010-12-14 16:46:39 -0800 | [diff] [blame] | 2521 | final int bitmapPadding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS; |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2522 | mDragOutline = createExternalDragOutline(canvas, bitmapPadding); |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2523 | |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2524 | // Show the current page outlines to indicate that we can accept this drop |
| 2525 | showOutlines(); |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 2526 | layout.setIsDragOccuring(true); |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2527 | layout.onDragEnter(); |
| 2528 | layout.visualizeDropLocation(null, mDragOutline, x, y, 1, 1); |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2529 | |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2530 | return true; |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2531 | } |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2532 | case DragEvent.ACTION_DRAG_LOCATION: |
| 2533 | // Visualize the drop location |
| 2534 | layout.visualizeDropLocation(null, mDragOutline, x, y, 1, 1); |
| 2535 | return true; |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2536 | case DragEvent.ACTION_DROP: { |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2537 | // Try and add any shortcuts |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2538 | final LauncherModel model = mLauncher.getModel(); |
| 2539 | final ClipData data = event.getClipData(); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 2540 | |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2541 | // We assume that the mime types are ordered in descending importance of |
| 2542 | // representation. So we enumerate the list of mime types and alert the |
| 2543 | // user if any widgets can handle the drop. Only the most preferred |
| 2544 | // representation will be handled. |
| 2545 | pos[0] = x; |
| 2546 | pos[1] = y; |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2547 | Pair<Integer, List<WidgetMimeTypeHandlerData>> test = validateDrag(event); |
| 2548 | if (test != null) { |
| 2549 | final int index = test.first; |
| 2550 | final List<WidgetMimeTypeHandlerData> widgets = test.second; |
| 2551 | final boolean isShortcut = (widgets == null); |
| 2552 | final String mimeType = desc.getMimeType(index); |
| 2553 | if (isShortcut) { |
Dianne Hackborn | 0d5aad7 | 2011-01-17 15:28:58 -0800 | [diff] [blame] | 2554 | final Intent intent = data.getItemAt(index).getIntent(); |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2555 | Object info = model.infoFromShortcutIntent(mContext, intent, data.getIcon()); |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 2556 | onDropExternal(new int[] { x, y }, info, layout, false); |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2557 | } else { |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2558 | if (widgets.size() == 1) { |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2559 | // If there is only one item, then go ahead and add and configure |
| 2560 | // that widget |
| 2561 | final AppWidgetProviderInfo widgetInfo = widgets.get(0).widgetInfo; |
| 2562 | final PendingAddWidgetInfo createInfo = |
| 2563 | new PendingAddWidgetInfo(widgetInfo, mimeType, data); |
| 2564 | mLauncher.addAppWidgetFromDrop(createInfo, mCurrentPage, pos); |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2565 | } else { |
Winson Chung | 68846fd | 2010-10-29 11:00:27 -0700 | [diff] [blame] | 2566 | // Show the widget picker dialog if there is more than one widget |
| 2567 | // that can handle this data type |
| 2568 | final InstallWidgetReceiver.WidgetListAdapter adapter = |
| 2569 | new InstallWidgetReceiver.WidgetListAdapter(mLauncher, mimeType, |
| 2570 | data, widgets, layout, mCurrentPage, pos); |
| 2571 | final AlertDialog.Builder builder = |
| 2572 | new AlertDialog.Builder(mContext); |
| 2573 | builder.setAdapter(adapter, adapter); |
| 2574 | builder.setCancelable(true); |
| 2575 | builder.setTitle(mContext.getString( |
| 2576 | R.string.external_drop_widget_pick_title)); |
| 2577 | builder.setIcon(R.drawable.ic_no_applications); |
| 2578 | builder.show(); |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 2579 | } |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2580 | } |
| 2581 | } |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2582 | return true; |
Winson Chung | 580e277 | 2010-11-10 16:03:00 -0800 | [diff] [blame] | 2583 | } |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2584 | case DragEvent.ACTION_DRAG_ENDED: |
| 2585 | // Hide the page outlines after the drop |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 2586 | layout.setIsDragOccuring(false); |
Winson Chung | a9abd0e | 2010-10-27 17:18:37 -0700 | [diff] [blame] | 2587 | layout.onDragExit(); |
| 2588 | hideOutlines(); |
| 2589 | return true; |
| 2590 | } |
| 2591 | return super.onDragEvent(event); |
| 2592 | } |
| 2593 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2594 | /* |
| 2595 | * |
| 2596 | * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's |
| 2597 | * coordinate space. The argument xy is modified with the return result. |
| 2598 | * |
| 2599 | */ |
| 2600 | void mapPointFromSelfToChild(View v, float[] xy) { |
| 2601 | mapPointFromSelfToChild(v, xy, null); |
| 2602 | } |
| 2603 | |
| 2604 | /* |
| 2605 | * |
| 2606 | * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's |
| 2607 | * coordinate space. The argument xy is modified with the return result. |
| 2608 | * |
| 2609 | * 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] | 2610 | * computing it itself; we use this to avoid redundant matrix inversions in |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2611 | * findMatchingPageForDragOver |
| 2612 | * |
| 2613 | */ |
| 2614 | void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) { |
| 2615 | if (cachedInverseMatrix == null) { |
| 2616 | v.getMatrix().invert(mTempInverseMatrix); |
| 2617 | cachedInverseMatrix = mTempInverseMatrix; |
| 2618 | } |
| 2619 | xy[0] = xy[0] + mScrollX - v.getLeft(); |
| 2620 | xy[1] = xy[1] + mScrollY - v.getTop(); |
| 2621 | cachedInverseMatrix.mapPoints(xy); |
| 2622 | } |
| 2623 | |
| 2624 | /* |
| 2625 | * |
| 2626 | * Convert the 2D coordinate xy from this CellLayout's coordinate space to |
| 2627 | * the parent View's coordinate space. The argument xy is modified with the return result. |
| 2628 | * |
| 2629 | */ |
| 2630 | void mapPointFromChildToSelf(View v, float[] xy) { |
| 2631 | v.getMatrix().mapPoints(xy); |
| 2632 | xy[0] -= (mScrollX - v.getLeft()); |
| 2633 | xy[1] -= (mScrollY - v.getTop()); |
| 2634 | } |
| 2635 | |
| 2636 | static private float squaredDistance(float[] point1, float[] point2) { |
| 2637 | float distanceX = point1[0] - point2[0]; |
| 2638 | float distanceY = point2[1] - point2[1]; |
| 2639 | return distanceX * distanceX + distanceY * distanceY; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2642 | /* |
| 2643 | * |
| 2644 | * Returns true if the passed CellLayout cl overlaps with dragView |
| 2645 | * |
| 2646 | */ |
| 2647 | boolean overlaps(CellLayout cl, DragView dragView, |
| 2648 | int dragViewX, int dragViewY, Matrix cachedInverseMatrix) { |
| 2649 | // Transform the coordinates of the item being dragged to the CellLayout's coordinates |
| 2650 | final float[] draggedItemTopLeft = mTempDragCoordinates; |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2651 | draggedItemTopLeft[0] = dragViewX; |
| 2652 | draggedItemTopLeft[1] = dragViewY; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2653 | final float[] draggedItemBottomRight = mTempDragBottomRightCoordinates; |
Michael Jurka | f12c75c | 2011-01-25 22:41:40 -0800 | [diff] [blame] | 2654 | draggedItemBottomRight[0] = draggedItemTopLeft[0] + dragView.getDragRegionWidth(); |
| 2655 | draggedItemBottomRight[1] = draggedItemTopLeft[1] + dragView.getDragRegionHeight(); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2656 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2657 | // Transform the dragged item's top left coordinates |
| 2658 | // to the CellLayout's local coordinates |
| 2659 | mapPointFromSelfToChild(cl, draggedItemTopLeft, cachedInverseMatrix); |
| 2660 | float overlapRegionLeft = Math.max(0f, draggedItemTopLeft[0]); |
| 2661 | float overlapRegionTop = Math.max(0f, draggedItemTopLeft[1]); |
| 2662 | |
| 2663 | if (overlapRegionLeft <= cl.getWidth() && overlapRegionTop >= 0) { |
| 2664 | // Transform the dragged item's bottom right coordinates |
| 2665 | // to the CellLayout's local coordinates |
| 2666 | mapPointFromSelfToChild(cl, draggedItemBottomRight, cachedInverseMatrix); |
| 2667 | float overlapRegionRight = Math.min(cl.getWidth(), draggedItemBottomRight[0]); |
| 2668 | float overlapRegionBottom = Math.min(cl.getHeight(), draggedItemBottomRight[1]); |
| 2669 | |
| 2670 | if (overlapRegionRight >= 0 && overlapRegionBottom <= cl.getHeight()) { |
| 2671 | float overlap = (overlapRegionRight - overlapRegionLeft) * |
| 2672 | (overlapRegionBottom - overlapRegionTop); |
| 2673 | if (overlap > 0) { |
| 2674 | return true; |
| 2675 | } |
| 2676 | } |
| 2677 | } |
| 2678 | return false; |
| 2679 | } |
| 2680 | |
| 2681 | /* |
| 2682 | * |
| 2683 | * This method returns the CellLayout that is currently being dragged to. In order to drag |
| 2684 | * to a CellLayout, either the touch point must be directly over the CellLayout, or as a second |
| 2685 | * strategy, we see if the dragView is overlapping any CellLayout and choose the closest one |
| 2686 | * |
| 2687 | * Return null if no CellLayout is currently being dragged over |
| 2688 | * |
| 2689 | */ |
| 2690 | private CellLayout findMatchingPageForDragOver( |
| 2691 | DragView dragView, int originX, int originY, int offsetX, int offsetY) { |
| 2692 | // We loop through all the screens (ie CellLayouts) and see which ones overlap |
| 2693 | // 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] | 2694 | final int screenCount = getChildCount(); |
| 2695 | CellLayout bestMatchingScreen = null; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2696 | float smallestDistSoFar = Float.MAX_VALUE; |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2697 | |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2698 | for (int i = 0; i < screenCount; i++) { |
| 2699 | CellLayout cl = (CellLayout)getChildAt(i); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2700 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2701 | final float[] touchXy = mTempTouchCoordinates; |
| 2702 | touchXy[0] = originX + offsetX; |
| 2703 | touchXy[1] = originY + offsetY; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2704 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2705 | // Transform the touch coordinates to the CellLayout's local coordinates |
| 2706 | // 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] | 2707 | cl.getMatrix().invert(mTempInverseMatrix); |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2708 | mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2709 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2710 | if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && |
| 2711 | touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) { |
| 2712 | return cl; |
| 2713 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2714 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2715 | if (overlaps(cl, dragView, originX, originY, mTempInverseMatrix)) { |
| 2716 | // Get the center of the cell layout in screen coordinates |
| 2717 | final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates; |
| 2718 | cellLayoutCenter[0] = cl.getWidth()/2; |
| 2719 | cellLayoutCenter[1] = cl.getHeight()/2; |
| 2720 | mapPointFromChildToSelf(cl, cellLayoutCenter); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2721 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2722 | touchXy[0] = originX + offsetX; |
| 2723 | touchXy[1] = originY + offsetY; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2724 | |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2725 | // Calculate the distance between the center of the CellLayout |
| 2726 | // and the touch point |
| 2727 | float dist = squaredDistance(touchXy, cellLayoutCenter); |
| 2728 | |
| 2729 | if (dist < smallestDistSoFar) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2730 | smallestDistSoFar = dist; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2731 | bestMatchingScreen = cl; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2732 | } |
Michael Jurka | 4516c11 | 2010-10-07 15:13:47 -0700 | [diff] [blame] | 2733 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2734 | } |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 2735 | return bestMatchingScreen; |
| 2736 | } |
| 2737 | |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 2738 | public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, |
| 2739 | DragView dragView, Object dragInfo) { |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 2740 | // When touch is inside the scroll area, skip dragOver actions for the current screen |
| 2741 | if (!mInScrollArea) { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2742 | CellLayout layout; |
| 2743 | int originX = x - xOffset; |
| 2744 | int originY = y - yOffset; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2745 | boolean shrunken = mIsSmall || mIsInUnshrinkAnimation; |
| 2746 | if (shrunken) { |
Michael Jurka | 0bb8563 | 2011-01-26 00:00:44 -0800 | [diff] [blame] | 2747 | mLastDragView = dragView; |
| 2748 | mLastDragOriginX = originX; |
| 2749 | mLastDragOriginY = originY; |
| 2750 | mLastDragXOffset = xOffset; |
| 2751 | mLastDragYOffset = yOffset; |
| 2752 | layout = findMatchingPageForDragOver(dragView, originX, originY, xOffset, yOffset); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 2753 | |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2754 | if (layout != mDragTargetLayout) { |
| 2755 | if (mDragTargetLayout != null) { |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 2756 | mDragTargetLayout.setIsDragOverlapping(false); |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 2757 | mSpringLoadedDragController.onDragExit(); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2758 | } |
| 2759 | mDragTargetLayout = layout; |
Winson Chung | 707de28 | 2011-03-02 12:29:10 -0800 | [diff] [blame] | 2760 | // In spring-loaded mode, we still want the user to be able to hover over a |
| 2761 | // full screen (which is traditionally set to not accept drops) if they want to |
| 2762 | // get to pages beyond the screen that is full. |
| 2763 | boolean allowDragOver = (mDragTargetLayout != null) && |
| 2764 | (mDragTargetLayout.getAcceptsDrops() || |
| 2765 | (mShrinkState == ShrinkState.SPRING_LOADED)); |
| 2766 | if (allowDragOver) { |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 2767 | mDragTargetLayout.setIsDragOverlapping(true); |
Michael Jurka | 0bb8563 | 2011-01-26 00:00:44 -0800 | [diff] [blame] | 2768 | mSpringLoadedDragController.onDragEnter( |
| 2769 | mDragTargetLayout, mShrinkState == ShrinkState.SPRING_LOADED); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2770 | } |
| 2771 | } |
| 2772 | } else { |
| 2773 | layout = getCurrentDropLayout(); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2774 | if (layout != mDragTargetLayout) { |
| 2775 | if (mDragTargetLayout != null) { |
| 2776 | mDragTargetLayout.onDragExit(); |
| 2777 | } |
| 2778 | layout.onDragEnter(); |
| 2779 | mDragTargetLayout = layout; |
| 2780 | } |
| 2781 | } |
| 2782 | if (!shrunken || mShrinkState == ShrinkState.SPRING_LOADED) { |
| 2783 | layout = getCurrentDropLayout(); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2784 | |
| 2785 | final ItemInfo item = (ItemInfo)dragInfo; |
| 2786 | if (dragInfo instanceof LauncherAppWidgetInfo) { |
| 2787 | LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo)dragInfo; |
| 2788 | |
| 2789 | if (widgetInfo.spanX == -1) { |
| 2790 | // Calculate the grid spans needed to fit this widget |
| 2791 | int[] spans = layout.rectToCell( |
| 2792 | widgetInfo.minWidth, widgetInfo.minHeight, null); |
| 2793 | item.spanX = spans[0]; |
| 2794 | item.spanY = spans[1]; |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | if (source instanceof AllAppsPagedView) { |
| 2799 | // This is a hack to fix the point used to determine which cell an icon from |
| 2800 | // the all apps screen is over |
| 2801 | if (item != null && item.spanX == 1 && layout != null) { |
| 2802 | int dragRegionLeft = (dragView.getWidth() - layout.getCellWidth()) / 2; |
| 2803 | |
| 2804 | originX += dragRegionLeft - dragView.getDragRegionLeft(); |
| 2805 | if (dragView.getDragRegionWidth() != layout.getCellWidth()) { |
| 2806 | dragView.setDragRegion(dragView.getDragRegionLeft(), |
| 2807 | dragView.getDragRegionTop(), |
| 2808 | layout.getCellWidth(), |
| 2809 | dragView.getDragRegionHeight()); |
| 2810 | } |
| 2811 | } |
Patrick Dubroy | 62bbb3c | 2011-01-17 15:29:27 -0800 | [diff] [blame] | 2812 | } else if (source == this) { |
| 2813 | // When dragging from the workspace, the drag view is slightly bigger than |
| 2814 | // the original view, and offset vertically. Adjust to account for this. |
| 2815 | final View origView = mDragInfo.cell; |
| 2816 | originX += (dragView.getMeasuredWidth() - origView.getWidth()) / 2; |
| 2817 | originY += (dragView.getMeasuredHeight() - origView.getHeight()) / 2 |
| 2818 | + dragView.getOffsetY(); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2821 | if (mDragTargetLayout != null) { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2822 | final View child = (mDragInfo == null) ? null : mDragInfo.cell; |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2823 | float[] localOrigin = { originX, originY }; |
| 2824 | mapPointFromSelfToChild(mDragTargetLayout, localOrigin, null); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2825 | mDragTargetLayout.visualizeDropLocation(child, mDragOutline, |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2826 | (int) localOrigin[0], (int) localOrigin[1], item.spanX, item.spanY); |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 2827 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 2828 | } |
Patrick Dubroy | 976ebec | 2010-08-04 20:03:37 -0700 | [diff] [blame] | 2829 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2830 | } |
| 2831 | |
Patrick Dubroy | e3887cc | 2011-01-20 10:43:40 -0800 | [diff] [blame] | 2832 | private void doDragExit() { |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2833 | mWasSpringLoadedOnDragExit = mShrinkState == ShrinkState.SPRING_LOADED; |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 2834 | if (mDragTargetLayout != null) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2835 | mDragTargetLayout.onDragExit(); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 2836 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 2837 | if (!mIsPageMoving) { |
| 2838 | hideOutlines(); |
| 2839 | } |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2840 | if (mShrinkState == ShrinkState.SPRING_LOADED) { |
| 2841 | mLauncher.exitSpringLoadedDragMode(); |
| 2842 | } |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 2843 | clearAllHovers(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2844 | } |
| 2845 | |
Patrick Dubroy | e3887cc | 2011-01-20 10:43:40 -0800 | [diff] [blame] | 2846 | public void onDragExit(DragSource source, int x, int y, int xOffset, |
| 2847 | int yOffset, DragView dragView, Object dragInfo) { |
| 2848 | doDragExit(); |
| 2849 | } |
| 2850 | |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 2851 | @Override |
| 2852 | public void getHitRect(Rect outRect) { |
| 2853 | // We want the workspace to have the whole area of the display (it will find the correct |
| 2854 | // cell layout to drop to in the existing drag/drop logic. |
| 2855 | final Display d = mLauncher.getWindowManager().getDefaultDisplay(); |
| 2856 | outRect.set(0, 0, d.getWidth(), d.getHeight()); |
| 2857 | } |
| 2858 | |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2859 | /** |
| 2860 | * Add the item specified by dragInfo to the given layout. |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2861 | * @return true if successful |
| 2862 | */ |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 2863 | public boolean addExternalItemToScreen(ItemInfo dragInfo, CellLayout layout) { |
| 2864 | if (layout.findCellForSpan(mTempEstimate, dragInfo.spanX, dragInfo.spanY)) { |
Patrick Dubroy | bbaa75c | 2011-03-08 18:47:40 -0800 | [diff] [blame] | 2865 | onDropExternal(dragInfo.dropPos, (ItemInfo) dragInfo, (CellLayout) layout, false); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2866 | return true; |
| 2867 | } |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2868 | mLauncher.showOutOfSpaceMessage(); |
Patrick Dubroy | 2b9ff37 | 2010-09-07 17:49:27 -0700 | [diff] [blame] | 2869 | return false; |
| 2870 | } |
| 2871 | |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 2872 | private void onDropExternal(int[] touchXY, Object dragInfo, |
| 2873 | CellLayout cellLayout, boolean insertAtFirst) { |
| 2874 | onDropExternal(touchXY, dragInfo, cellLayout, insertAtFirst, null, 0, 0); |
| 2875 | } |
| 2876 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 2877 | /** |
| 2878 | * Drop an item that didn't originate on one of the workspace screens. |
| 2879 | * It may have come from Launcher (e.g. from all apps or customize), or it may have |
| 2880 | * come from another app altogether. |
| 2881 | * |
| 2882 | * NOTE: This can also be called when we are outside of a drag event, when we want |
| 2883 | * to add an item to one of the workspace screens. |
| 2884 | */ |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 2885 | private void onDropExternal(int[] touchXY, Object dragInfo, |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 2886 | CellLayout cellLayout, boolean insertAtFirst, DragView dragView, |
| 2887 | int dragViewX, int dragViewY) { |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2888 | int screen = indexOfChild(cellLayout); |
| 2889 | if (dragInfo instanceof PendingAddItemInfo) { |
| 2890 | PendingAddItemInfo info = (PendingAddItemInfo) dragInfo; |
| 2891 | // When dragging and dropping from customization tray, we deal with creating |
| 2892 | // widgets/shortcuts/folders in a slightly different way |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2893 | switch (info.itemType) { |
| 2894 | case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: |
Winson Chung | 55cef26 | 2010-10-28 14:14:18 -0700 | [diff] [blame] | 2895 | mLauncher.addAppWidgetFromDrop((PendingAddWidgetInfo) info, screen, touchXY); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2896 | break; |
| 2897 | case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: |
| 2898 | mLauncher.addLiveFolderFromDrop(info.componentName, screen, touchXY); |
| 2899 | break; |
| 2900 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 2901 | mLauncher.processShortcutFromDrop(info.componentName, screen, touchXY); |
| 2902 | break; |
| 2903 | default: |
| 2904 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 2905 | } |
| 2906 | cellLayout.onDragExit(); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 2907 | } else { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2908 | // This is for other drag/drop cases, like dragging from All Apps |
| 2909 | ItemInfo info = (ItemInfo) dragInfo; |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2910 | View view = null; |
| 2911 | |
| 2912 | switch (info.itemType) { |
| 2913 | case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: |
| 2914 | case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: |
| 2915 | if (info.container == NO_ID && info instanceof ApplicationInfo) { |
| 2916 | // Came from all apps -- make a copy |
| 2917 | info = new ShortcutInfo((ApplicationInfo) info); |
| 2918 | } |
| 2919 | view = mLauncher.createShortcut(R.layout.application, cellLayout, |
| 2920 | (ShortcutInfo) info); |
| 2921 | break; |
| 2922 | case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: |
| 2923 | view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, |
| 2924 | cellLayout, (UserFolderInfo) info, mIconCache); |
| 2925 | break; |
| 2926 | default: |
| 2927 | throw new IllegalStateException("Unknown item type: " + info.itemType); |
| 2928 | } |
| 2929 | |
| 2930 | mTargetCell = new int[2]; |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 2931 | if (touchXY != null) { |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2932 | // when dragging and dropping, just find the closest free spot |
Michael Jurka | c4e772e | 2011-02-10 13:32:01 -0800 | [diff] [blame] | 2933 | cellLayout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, mTargetCell); |
Michael Jurka | 9c6de3d | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2934 | } else { |
| 2935 | cellLayout.findCellForSpan(mTargetCell, 1, 1); |
| 2936 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2937 | addInScreen(view, indexOfChild(cellLayout), mTargetCell[0], |
| 2938 | mTargetCell[1], info.spanX, info.spanY, insertAtFirst); |
Michael Jurka | d3ef306 | 2010-11-23 16:23:58 -0800 | [diff] [blame] | 2939 | boolean animateDrop = !mWasSpringLoadedOnDragExit; |
| 2940 | cellLayout.onDropChild(view, animateDrop); |
| 2941 | cellLayout.animateDrop(); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 2942 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams(); |
Adam Cohen | d5e4273 | 2011-03-28 17:33:39 -0700 | [diff] [blame] | 2943 | cellLayout.getChildrenLayout().measureChild(view); |
| 2944 | |
| 2945 | if (dragView != null) { |
| 2946 | setPositionForDropAnimation(dragView, dragViewX, dragViewY, cellLayout, view); |
| 2947 | } |
Michael Jurka | af44209 | 2010-06-10 17:01:57 -0700 | [diff] [blame] | 2948 | |
| 2949 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2950 | LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2951 | lp.cellX, lp.cellY); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2952 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2953 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2954 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 2955 | /** |
| 2956 | * Return the current {@link CellLayout}, correctly picking the destination |
| 2957 | * screen while a scroll is in progress. |
| 2958 | */ |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 2959 | public CellLayout getCurrentDropLayout() { |
| 2960 | return (CellLayout) getChildAt(mNextPage == INVALID_PAGE ? mCurrentPage : mNextPage); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 2963 | /** |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2964 | * Return the current CellInfo describing our current drag; this method exists |
| 2965 | * so that Launcher can sync this object with the correct info when the activity is created/ |
| 2966 | * destroyed |
| 2967 | * |
| 2968 | */ |
| 2969 | public CellLayout.CellInfo getDragInfo() { |
| 2970 | return mDragInfo; |
| 2971 | } |
| 2972 | |
| 2973 | /** |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 2974 | * Calculate the nearest cell where the given object would be dropped. |
| 2975 | */ |
Michael Jurka | 6a1435d | 2010-09-27 17:35:12 -0700 | [diff] [blame] | 2976 | private int[] findNearestVacantArea(int pixelX, int pixelY, |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 2977 | int spanX, int spanY, View ignoreView, CellLayout layout, int[] recycle) { |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 2978 | |
Michael Jurka | 5f1c509 | 2010-09-03 14:15:02 -0700 | [diff] [blame] | 2979 | int localPixelX = pixelX - (layout.getLeft() - mScrollX); |
| 2980 | int localPixelY = pixelY - (layout.getTop() - mScrollY); |
Patrick Dubroy | 6569f2c | 2010-07-12 14:25:18 -0700 | [diff] [blame] | 2981 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 2982 | // Find the best target drop location |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 2983 | return layout.findNearestVacantArea( |
Michael Jurka | fc9f07d | 2010-09-30 13:22:31 -0700 | [diff] [blame] | 2984 | localPixelX, localPixelY, spanX, spanY, ignoreView, recycle); |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 2985 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 2986 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2987 | void setLauncher(Launcher launcher) { |
| 2988 | mLauncher = launcher; |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 2989 | mSpringLoadedDragController = new SpringLoadedDragController(mLauncher); |
Winson Chung | 8812703 | 2010-12-13 12:11:33 -0800 | [diff] [blame] | 2990 | |
| 2991 | mCustomizationDrawer = mLauncher.findViewById(R.id.customization_drawer); |
Winson Chung | 760e537 | 2010-12-15 13:14:23 -0800 | [diff] [blame] | 2992 | if (mCustomizationDrawer != null) { |
| 2993 | mCustomizationDrawerContent = |
| 2994 | mCustomizationDrawer.findViewById(com.android.internal.R.id.tabcontent); |
| 2995 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 2996 | } |
| 2997 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 2998 | public void setDragController(DragController dragController) { |
| 2999 | mDragController = dragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3000 | } |
| 3001 | |
Patrick Dubroy | e3887cc | 2011-01-20 10:43:40 -0800 | [diff] [blame] | 3002 | /** |
| 3003 | * Called at the end of a drag which originated on the workspace. |
| 3004 | */ |
Patrick Dubroy | 5f44542 | 2011-02-18 14:35:21 -0800 | [diff] [blame] | 3005 | public void onDropCompleted(View target, Object dragInfo, boolean success) { |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3006 | if (success) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3007 | if (target != this && mDragInfo != null) { |
| 3008 | final CellLayout cellLayout = (CellLayout) getChildAt(mDragInfo.screen); |
| 3009 | cellLayout.removeView(mDragInfo.cell); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 3010 | if (mDragInfo.cell instanceof DropTarget) { |
| 3011 | mDragController.removeDropTarget((DropTarget)mDragInfo.cell); |
| 3012 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3013 | // final Object tag = mDragInfo.cell.getTag(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3014 | } |
Patrick Dubroy | ce34a97 | 2010-10-19 10:34:32 -0700 | [diff] [blame] | 3015 | } else if (mDragInfo != null) { |
Patrick Dubroy | e3887cc | 2011-01-20 10:43:40 -0800 | [diff] [blame] | 3016 | // NOTE: When 'success' is true, onDragExit is called by the DragController before |
| 3017 | // calling onDropCompleted(). We call it ourselves here, but maybe this should be |
| 3018 | // moved into DragController.cancelDrag(). |
| 3019 | doDragExit(); |
| 3020 | ((CellLayout) getChildAt(mDragInfo.screen)).onDropChild(mDragInfo.cell, false); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3021 | } |
Winson Chung | 400438b | 2011-01-16 17:53:48 -0800 | [diff] [blame] | 3022 | mLauncher.unlockScreenOrientation(); |
Joe Onorato | 4be866d | 2010-10-10 11:26:02 -0700 | [diff] [blame] | 3023 | mDragOutline = null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3024 | mDragInfo = null; |
| 3025 | } |
| 3026 | |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 3027 | @Override |
| 3028 | public void onDragViewVisible() { |
| 3029 | ((View) mDragInfo.cell).setVisibility(View.GONE); |
| 3030 | } |
| 3031 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 3032 | public boolean isDropEnabled() { |
| 3033 | return true; |
| 3034 | } |
| 3035 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3036 | @Override |
| 3037 | protected void onRestoreInstanceState(Parcelable state) { |
| 3038 | super.onRestoreInstanceState(state); |
| 3039 | Launcher.setScreen(mCurrentPage); |
| 3040 | } |
| 3041 | |
| 3042 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3043 | public void scrollLeft() { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3044 | if (!mIsSmall && !mIsInUnshrinkAnimation) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3045 | super.scrollLeft(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3049 | @Override |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3050 | public void scrollRight() { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3051 | if (!mIsSmall && !mIsInUnshrinkAnimation) { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3052 | super.scrollRight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3053 | } |
| 3054 | } |
| 3055 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3056 | @Override |
| 3057 | public void onEnterScrollArea(int direction) { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3058 | if (!mIsSmall && !mIsInUnshrinkAnimation) { |
| 3059 | mInScrollArea = true; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3060 | mPendingScrollDirection = direction; |
| 3061 | |
| 3062 | final int page = mCurrentPage + (direction == DragController.SCROLL_LEFT ? -1 : 1); |
| 3063 | final CellLayout layout = (CellLayout) getChildAt(page); |
| 3064 | |
| 3065 | if (layout != null) { |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 3066 | layout.setIsDragOverlapping(true); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3067 | |
Patrick Dubroy | 0207c52 | 2010-11-03 22:12:02 -0700 | [diff] [blame] | 3068 | if (mDragTargetLayout != null) { |
| 3069 | mDragTargetLayout.onDragExit(); |
| 3070 | mDragTargetLayout = null; |
| 3071 | } |
Patrick Dubroy | 70b9530 | 2011-02-11 09:32:59 -0800 | [diff] [blame] | 3072 | // In portrait, need to redraw the edge glow when entering the scroll area |
| 3073 | if (getHeight() > getWidth()) { |
| 3074 | invalidate(); |
| 3075 | } |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3076 | } |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 3080 | private void clearAllHovers() { |
| 3081 | final int childCount = getChildCount(); |
| 3082 | for (int i = 0; i < childCount; i++) { |
Michael Jurka | 33945b2 | 2010-12-21 18:19:38 -0800 | [diff] [blame] | 3083 | ((CellLayout) getChildAt(i)).setIsDragOverlapping(false); |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 3084 | } |
Michael Jurka | c2f7f47 | 2010-12-14 15:34:42 -0800 | [diff] [blame] | 3085 | mSpringLoadedDragController.onDragExit(); |
Patrick Dubroy | 70b9530 | 2011-02-11 09:32:59 -0800 | [diff] [blame] | 3086 | |
| 3087 | // In portrait, workspace is responsible for drawing the edge glow on adjacent pages, |
| 3088 | // so we need to redraw the workspace when this may have changed. |
| 3089 | if (getHeight() > getWidth()) { |
| 3090 | invalidate(); |
| 3091 | } |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3094 | @Override |
| 3095 | public void onExitScrollArea() { |
Michael Jurka | d718d6a | 2010-10-14 15:35:17 -0700 | [diff] [blame] | 3096 | if (mInScrollArea) { |
| 3097 | mInScrollArea = false; |
Patrick Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 3098 | mPendingScrollDirection = DragController.SCROLL_NONE; |
Patrick Dubroy | 08ae2ec | 2010-10-14 23:54:22 -0700 | [diff] [blame] | 3099 | clearAllHovers(); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 3100 | } |
| 3101 | } |
| 3102 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3103 | public Folder getFolderForTag(Object tag) { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 3104 | final int screenCount = getChildCount(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3105 | for (int screen = 0; screen < screenCount; screen++) { |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 3106 | ViewGroup currentScreen = ((CellLayout) getChildAt(screen)).getChildrenLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3107 | int count = currentScreen.getChildCount(); |
| 3108 | for (int i = 0; i < count; i++) { |
| 3109 | View child = currentScreen.getChildAt(i); |
| 3110 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); |
| 3111 | if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) { |
| 3112 | Folder f = (Folder) child; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3113 | if (f.getInfo() == tag && f.getInfo().opened) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3114 | return f; |
| 3115 | } |
| 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | return null; |
| 3120 | } |
| 3121 | |
| 3122 | public View getViewForTag(Object tag) { |
| 3123 | int screenCount = getChildCount(); |
| 3124 | for (int screen = 0; screen < screenCount; screen++) { |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 3125 | ViewGroup currentScreen = ((CellLayout) getChildAt(screen)).getChildrenLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3126 | int count = currentScreen.getChildCount(); |
| 3127 | for (int i = 0; i < count; i++) { |
| 3128 | View child = currentScreen.getChildAt(i); |
| 3129 | if (child.getTag() == tag) { |
| 3130 | return child; |
| 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | return null; |
| 3135 | } |
| 3136 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3137 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3138 | void removeItems(final ArrayList<ApplicationInfo> apps) { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 3139 | final int screenCount = getChildCount(); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 3140 | final PackageManager manager = getContext().getPackageManager(); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3141 | final AppWidgetManager widgets = AppWidgetManager.getInstance(getContext()); |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3142 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3143 | final HashSet<String> packageNames = new HashSet<String>(); |
| 3144 | final int appCount = apps.size(); |
| 3145 | for (int i = 0; i < appCount; i++) { |
| 3146 | packageNames.add(apps.get(i).componentName.getPackageName()); |
| 3147 | } |
| 3148 | |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 3149 | for (int i = 0; i < screenCount; i++) { |
Winson Chung | 7a25a9e | 2011-01-30 13:33:56 -0800 | [diff] [blame] | 3150 | final CellLayout layoutParent = (CellLayout) getChildAt(i); |
| 3151 | final ViewGroup layout = layoutParent.getChildrenLayout(); |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3152 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3153 | // Avoid ANRs by treating each screen separately |
| 3154 | post(new Runnable() { |
| 3155 | public void run() { |
| 3156 | final ArrayList<View> childrenToRemove = new ArrayList<View>(); |
| 3157 | childrenToRemove.clear(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3158 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3159 | int childCount = layout.getChildCount(); |
| 3160 | for (int j = 0; j < childCount; j++) { |
| 3161 | final View view = layout.getChildAt(j); |
| 3162 | Object tag = view.getTag(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3163 | |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3164 | if (tag instanceof ShortcutInfo) { |
| 3165 | final ShortcutInfo info = (ShortcutInfo) tag; |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3166 | final Intent intent = info.intent; |
| 3167 | final ComponentName name = intent.getComponent(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3168 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3169 | if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { |
| 3170 | for (String packageName: packageNames) { |
| 3171 | if (packageName.equals(name.getPackageName())) { |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3172 | LauncherModel.deleteItemFromDatabase(mLauncher, info); |
| 3173 | childrenToRemove.add(view); |
| 3174 | } |
| 3175 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3176 | } |
| 3177 | } else if (tag instanceof UserFolderInfo) { |
| 3178 | final UserFolderInfo info = (UserFolderInfo) tag; |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3179 | final ArrayList<ShortcutInfo> contents = info.contents; |
| 3180 | final ArrayList<ShortcutInfo> toRemove = new ArrayList<ShortcutInfo>(1); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3181 | final int contentsCount = contents.size(); |
| 3182 | boolean removedFromFolder = false; |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3183 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3184 | for (int k = 0; k < contentsCount; k++) { |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3185 | final ShortcutInfo appInfo = contents.get(k); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3186 | final Intent intent = appInfo.intent; |
| 3187 | final ComponentName name = intent.getComponent(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3188 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3189 | if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { |
| 3190 | for (String packageName: packageNames) { |
| 3191 | if (packageName.equals(name.getPackageName())) { |
| 3192 | toRemove.add(appInfo); |
Brad Fitzpatrick | 73013bf | 2010-09-14 12:15:32 -0700 | [diff] [blame] | 3193 | LauncherModel.deleteItemFromDatabase(mLauncher, appInfo); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3194 | removedFromFolder = true; |
| 3195 | } |
| 3196 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3197 | } |
| 3198 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3199 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3200 | contents.removeAll(toRemove); |
| 3201 | if (removedFromFolder) { |
| 3202 | final Folder folder = getOpenFolder(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3203 | if (folder != null) |
| 3204 | folder.notifyDataSetChanged(); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3205 | } |
| 3206 | } else if (tag instanceof LiveFolderInfo) { |
| 3207 | final LiveFolderInfo info = (LiveFolderInfo) tag; |
| 3208 | final Uri uri = info.uri; |
| 3209 | final ProviderInfo providerInfo = manager.resolveContentProvider( |
| 3210 | uri.getAuthority(), 0); |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3211 | |
Joe Onorato | f11079b | 2010-04-15 11:47:28 -0700 | [diff] [blame] | 3212 | if (providerInfo != null) { |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3213 | for (String packageName: packageNames) { |
| 3214 | if (packageName.equals(providerInfo.packageName)) { |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3215 | LauncherModel.deleteItemFromDatabase(mLauncher, info); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3216 | childrenToRemove.add(view); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3217 | } |
| 3218 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3219 | } |
| 3220 | } else if (tag instanceof LauncherAppWidgetInfo) { |
| 3221 | final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag; |
| 3222 | final AppWidgetProviderInfo provider = |
| 3223 | widgets.getAppWidgetInfo(info.appWidgetId); |
Daniel Sandler | e1cc6c3 | 2010-05-07 11:49:29 -0400 | [diff] [blame] | 3224 | if (provider != null) { |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3225 | for (String packageName: packageNames) { |
| 3226 | if (packageName.equals(provider.provider.getPackageName())) { |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3227 | LauncherModel.deleteItemFromDatabase(mLauncher, info); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3228 | childrenToRemove.add(view); |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3229 | } |
| 3230 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3231 | } |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3232 | } |
| 3233 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3234 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3235 | childCount = childrenToRemove.size(); |
| 3236 | for (int j = 0; j < childCount; j++) { |
| 3237 | View child = childrenToRemove.get(j); |
Winson Chung | 7a25a9e | 2011-01-30 13:33:56 -0800 | [diff] [blame] | 3238 | // Note: We can not remove the view directly from CellLayoutChildren as this |
| 3239 | // does not re-mark the spaces as unoccupied. |
| 3240 | layoutParent.removeViewInLayout(child); |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3241 | if (child instanceof DropTarget) { |
| 3242 | mDragController.removeDropTarget((DropTarget)child); |
| 3243 | } |
Romain Guy | 574d20e | 2009-06-01 15:34:04 -0700 | [diff] [blame] | 3244 | } |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3245 | |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3246 | if (childCount > 0) { |
| 3247 | layout.requestLayout(); |
| 3248 | layout.invalidate(); |
Romain Guy | 5c16f3e | 2010-01-12 17:24:58 -0800 | [diff] [blame] | 3249 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3250 | } |
Romain Guy | 629de3e | 2010-01-13 12:20:59 -0800 | [diff] [blame] | 3251 | }); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3252 | } |
| 3253 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3254 | |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3255 | void updateShortcuts(ArrayList<ApplicationInfo> apps) { |
Michael Jurka | dee0589 | 2010-07-27 10:01:56 -0700 | [diff] [blame] | 3256 | final int screenCount = getChildCount(); |
| 3257 | for (int i = 0; i < screenCount; i++) { |
Winson Chung | 6e31408 | 2011-01-27 16:46:51 -0800 | [diff] [blame] | 3258 | final ViewGroup layout = ((CellLayout) getChildAt(i)).getChildrenLayout(); |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3259 | int childCount = layout.getChildCount(); |
| 3260 | for (int j = 0; j < childCount; j++) { |
| 3261 | final View view = layout.getChildAt(j); |
| 3262 | Object tag = view.getTag(); |
Joe Onorato | 0589f0f | 2010-02-08 13:44:00 -0800 | [diff] [blame] | 3263 | if (tag instanceof ShortcutInfo) { |
| 3264 | ShortcutInfo info = (ShortcutInfo)tag; |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3265 | // We need to check for ACTION_MAIN otherwise getComponent() might |
| 3266 | // return null for some shortcuts (for instance, for shortcuts to |
| 3267 | // web pages.) |
| 3268 | final Intent intent = info.intent; |
| 3269 | final ComponentName name = intent.getComponent(); |
| 3270 | if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION && |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3271 | Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { |
| 3272 | final int appCount = apps.size(); |
Winson Chung | aafa03c | 2010-06-11 17:34:16 -0700 | [diff] [blame] | 3273 | for (int k = 0; k < appCount; k++) { |
Joe Onorato | 64e6be7 | 2010-03-05 15:05:52 -0500 | [diff] [blame] | 3274 | ApplicationInfo app = apps.get(k); |
| 3275 | if (app.componentName.equals(name)) { |
| 3276 | info.setIcon(mIconCache.getIcon(info.intent)); |
| 3277 | ((TextView)view).setCompoundDrawablesWithIntrinsicBounds(null, |
| 3278 | new FastBitmapDrawable(info.getIcon(mIconCache)), |
| 3279 | null, null); |
| 3280 | } |
| 3281 | } |
The Android Open Source Project | f96811c | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 3282 | } |
| 3283 | } |
| 3284 | } |
| 3285 | } |
| 3286 | } |
| 3287 | |
Joe Onorato | 14f122b | 2009-11-19 14:06:36 -0800 | [diff] [blame] | 3288 | void moveToDefaultScreen(boolean animate) { |
Michael Jurka | c0e8fca | 2010-10-06 16:41:29 -0700 | [diff] [blame] | 3289 | if (mIsSmall || mIsInUnshrinkAnimation) { |
| 3290 | mLauncher.showWorkspace(animate, (CellLayout)getChildAt(mDefaultPage)); |
| 3291 | } else if (animate) { |
| 3292 | snapToPage(mDefaultPage); |
Joe Onorato | c45b168 | 2010-01-11 18:48:40 -0500 | [diff] [blame] | 3293 | } else { |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3294 | setCurrentPage(mDefaultPage); |
Joe Onorato | c45b168 | 2010-01-11 18:48:40 -0500 | [diff] [blame] | 3295 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3296 | getChildAt(mDefaultPage).requestFocus(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3297 | } |
| 3298 | |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 3299 | void setIndicators(Drawable previous, Drawable next) { |
| 3300 | mPreviousIndicator = previous; |
| 3301 | mNextIndicator = next; |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3302 | previous.setLevel(mCurrentPage); |
| 3303 | next.setLevel(mCurrentPage); |
Romain Guy | 8a73c51 | 2009-11-09 19:19:59 -0800 | [diff] [blame] | 3304 | } |
| 3305 | |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3306 | @Override |
| 3307 | public void syncPages() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3308 | } |
Michael Jurka | 0142d49 | 2010-08-25 17:46:15 -0700 | [diff] [blame] | 3309 | |
| 3310 | @Override |
| 3311 | public void syncPageItems(int page) { |
| 3312 | } |
| 3313 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 3314 | } |