blob: 3aa91333c1e0a1f2c9fb16010c5892eb6f0edce7 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Adam Cohendf2cc412011-04-27 16:56:57 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Adam Cohendf2cc412011-04-27 16:56:57 -070021import android.animation.ObjectAnimator;
22import android.animation.PropertyValuesHolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.content.Context;
Adam Cohen76fc0852011-06-17 13:26:23 -070024import android.content.res.Resources;
Winson Chung043f2af2012-03-01 16:09:54 -080025import android.graphics.PointF;
Romain Guyfb5411e2010-02-24 10:04:17 -080026import android.graphics.Rect;
Adam Cohenbadf71e2011-05-26 19:08:29 -070027import android.graphics.drawable.Drawable;
Adam Cohen7a14d0b2011-06-24 11:36:35 -070028import android.text.InputType;
Adam Cohene601a432011-07-26 21:51:30 -070029import android.text.Selection;
30import android.text.Spannable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.util.AttributeSet;
Winson Chung892c74d2013-08-22 16:15:50 -070032import android.util.DisplayMetrics;
Adam Cohen3bf84d32012-05-07 20:17:14 -070033import android.util.Log;
Winson Chung892c74d2013-08-22 16:15:50 -070034import android.util.TypedValue;
Adam Cohen76fc0852011-06-17 13:26:23 -070035import android.view.ActionMode;
36import android.view.KeyEvent;
Adam Cohendf2cc412011-04-27 16:56:57 -070037import android.view.LayoutInflater;
Adam Cohen76fc0852011-06-17 13:26:23 -070038import android.view.Menu;
39import android.view.MenuItem;
Adam Cohen0c872ba2011-05-05 10:34:16 -070040import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.view.View;
Adam Cohen3371da02011-10-25 21:38:29 -070042import android.view.accessibility.AccessibilityEvent;
43import android.view.accessibility.AccessibilityManager;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -070044import android.view.animation.AccelerateInterpolator;
45import android.view.animation.Interpolator;
Adam Cohen76fc0852011-06-17 13:26:23 -070046import android.view.inputmethod.EditorInfo;
47import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070049import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070050import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051
Daniel Sandler325dc232013-06-05 22:57:57 -040052import com.android.launcher3.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080053
Adam Cohenc0dcf592011-06-01 15:30:43 -070054import java.util.ArrayList;
Adam Cohen3bf84d32012-05-07 20:17:14 -070055import java.util.Collections;
56import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -070057
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058/**
59 * Represents a set of icons chosen by the user or generated by the system.
60 */
Adam Cohen8dfcba42011-07-07 16:38:18 -070061public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
Adam Cohenea0818d2011-09-30 20:06:58 -070062 View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
63 View.OnFocusChangeListener {
Adam Cohendf2cc412011-04-27 16:56:57 -070064 private static final String TAG = "Launcher.Folder";
65
Adam Cohen4eac29a2011-07-11 17:53:37 -070066 protected DragController mDragController;
67 protected Launcher mLauncher;
68 protected FolderInfo mInfo;
69
Adam Cohendf2cc412011-04-27 16:56:57 -070070 static final int STATE_NONE = -1;
71 static final int STATE_SMALL = 0;
72 static final int STATE_ANIMATING = 1;
73 static final int STATE_OPEN = 2;
74
75 private int mExpandDuration;
76 protected CellLayout mContent;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070077 private ScrollView mScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070078 private final LayoutInflater mInflater;
79 private final IconCache mIconCache;
80 private int mState = STATE_NONE;
Adam Cohenbfbfd262011-06-13 16:55:12 -070081 private static final int REORDER_ANIMATION_DURATION = 230;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070082 private static final int REORDER_DELAY = 250;
Adam Cohenbfbfd262011-06-13 16:55:12 -070083 private static final int ON_EXIT_CLOSE_DELAY = 800;
Adam Cohen2801caf2011-05-13 20:57:39 -070084 private boolean mRearrangeOnClose = false;
85 private FolderIcon mFolderIcon;
86 private int mMaxCountX;
87 private int mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070088 private int mMaxVisibleX;
89 private int mMaxVisibleY;
Adam Cohen78dc83e2011-11-15 17:10:00 -080090 private int mMaxNumItems;
Adam Cohen7c693212011-05-18 15:26:57 -070091 private ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
Adam Cohenbadf71e2011-05-26 19:08:29 -070092 private Drawable mIconDrawable;
Adam Cohen7c693212011-05-18 15:26:57 -070093 boolean mItemsInvalidated = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -070094 private ShortcutInfo mCurrentDragInfo;
95 private View mCurrentDragView;
96 boolean mSuppressOnAdd = false;
97 private int[] mTargetCell = new int[2];
98 private int[] mPreviousTargetCell = new int[2];
99 private int[] mEmptyCell = new int[2];
100 private Alarm mReorderAlarm = new Alarm();
101 private Alarm mOnExitAlarm = new Alarm();
Adam Cohen76fc0852011-06-17 13:26:23 -0700102 private int mFolderNameHeight;
Adam Cohen8e776a62011-06-28 18:10:06 -0700103 private Rect mTempRect = new Rect();
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700104 private boolean mDragInProgress = false;
105 private boolean mDeleteFolderOnDropCompleted = false;
106 private boolean mSuppressFolderDeletion = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700107 private boolean mItemAddedBackToSelfViaIcon = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700108 FolderEditText mFolderName;
Adam Cohen268c4752012-06-06 17:47:33 -0700109 private float mFolderIconPivotX;
110 private float mFolderIconPivotY;
Adam Cohen228da5a2011-07-27 22:23:47 -0700111
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700112 private static final float MAX_SCROLL_VELOCITY = 1500f;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700113
Adam Cohen76fc0852011-06-17 13:26:23 -0700114 private boolean mIsEditingName = false;
115 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700116
Adam Cohena65beee2011-06-27 21:32:23 -0700117 private static String sDefaultFolderName;
118 private static String sHintText;
119
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700120 private int DRAG_MODE_NONE = 0;
121 private int DRAG_MODE_REORDER = 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700122 private int mDragMode = DRAG_MODE_NONE;
123
Adam Cohenfb91f302012-06-11 15:45:18 -0700124 private boolean mDestroyed;
125
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700126 private AutoScroller mAutoScroller;
127
Michael Jurka1e2f4652013-07-08 18:03:46 -0700128 private Runnable mDeferredAction;
129 private boolean mDeferDropAfterUninstall;
130 private boolean mUninstallSuccessful;
131
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 /**
133 * Used to inflate the Workspace from XML.
134 *
135 * @param context The application's context.
136 * @param attrs The attribtues set containing the Workspace's customization values.
137 */
138 public Folder(Context context, AttributeSet attrs) {
139 super(context, attrs);
Winson Chung5f8afe62013-08-12 16:19:28 -0700140
141 LauncherAppState app = LauncherAppState.getInstance();
142 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700144 mInflater = LayoutInflater.from(context);
Winson Chung5f8afe62013-08-12 16:19:28 -0700145 mIconCache = app.getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800146
147 Resources res = getResources();
Winson Chung892c74d2013-08-22 16:15:50 -0700148 mMaxCountX = mMaxVisibleX = (int) grid.numColumns;
149 mMaxVisibleY = (int) grid.numRows;
Winson Chung5f8afe62013-08-12 16:19:28 -0700150 mMaxCountY = mMaxNumItems = Integer.MAX_VALUE;
Adam Cohen76fc0852011-06-17 13:26:23 -0700151
152 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700153 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700154
Adam Cohen76fc0852011-06-17 13:26:23 -0700155 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700156
157 if (sDefaultFolderName == null) {
158 sDefaultFolderName = res.getString(R.string.folder_name);
159 }
Adam Cohena65beee2011-06-27 21:32:23 -0700160 if (sHintText == null) {
161 sHintText = res.getString(R.string.folder_hint_text);
162 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700163 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700164 // We need this view to be focusable in touch mode so that when text editing of the folder
165 // name is complete, we have something to focus on, thus hiding the cursor and giving
166 // reliable behvior when clicking the text field (since it will always gain focus on click).
167 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 }
169
170 @Override
171 protected void onFinishInflate() {
172 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700173 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700174 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700175
Winson Chung5f8afe62013-08-12 16:19:28 -0700176 LauncherAppState app = LauncherAppState.getInstance();
177 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
Winson Chung892c74d2013-08-22 16:15:50 -0700178 Rect padding = grid.getWorkspacePadding(grid.isLandscape ?
179 CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
180 DisplayMetrics dm = getResources().getDisplayMetrics();
Winson Chung5f8afe62013-08-12 16:19:28 -0700181
Winson Chung5f8afe62013-08-12 16:19:28 -0700182 mContent.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
Adam Cohen2801caf2011-05-13 20:57:39 -0700183 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700184 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700185 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700186 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
187 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700188 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700189
190 // We find out how tall the text view wants to be (it is set to wrap_content), so that
191 // we can allocate the appropriate amount of space for it.
192 int measureSpec = MeasureSpec.UNSPECIFIED;
193 mFolderName.measure(measureSpec, measureSpec);
194 mFolderNameHeight = mFolderName.getMeasuredHeight();
195
196 // We disable action mode for now since it messes up the view on phones
197 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700198 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700199 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700200 mFolderName.setInputType(mFolderName.getInputType() |
201 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700202 mAutoScroller = new AutoScroller(mScrollView);
203 mAutoScroller.setMaximumVelocityAbsolute(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
204 mAutoScroller.setExtendsBeyondEdges(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700206
Adam Cohen76fc0852011-06-17 13:26:23 -0700207 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
208 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
209 return false;
210 }
211
212 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
213 return false;
214 }
215
216 public void onDestroyActionMode(ActionMode mode) {
217 }
218
219 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
220 return false;
221 }
222 };
223
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700225 Object tag = v.getTag();
226 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700227 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700228 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 }
230
231 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700232 // Return if global dragging is not enabled
233 if (!mLauncher.isDraggingEnabled()) return true;
234
Adam Cohendf2cc412011-04-27 16:56:57 -0700235 Object tag = v.getTag();
236 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700237 ShortcutInfo item = (ShortcutInfo) tag;
238 if (!v.isInTouchMode()) {
239 return false;
240 }
241
Winson Chung7d7541e2011-09-16 20:14:36 -0700242 mLauncher.dismissFolderCling(null);
243
Adam Cohendf2cc412011-04-27 16:56:57 -0700244 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700245 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700246 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700247
248 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700249 mEmptyCell[0] = item.cellX;
250 mEmptyCell[1] = item.cellY;
251 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700252
253 mContent.removeView(mCurrentDragView);
254 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700255 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700256 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700257 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 return true;
259 }
260
Adam Cohen76fc0852011-06-17 13:26:23 -0700261 public boolean isEditingName() {
262 return mIsEditingName;
263 }
264
265 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700266 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700267 mIsEditingName = true;
268 }
269
270 public void dismissEditingName() {
271 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
272 doneEditingFolderName(true);
273 }
274
275 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700276 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700277 // Convert to a string here to ensure that no other state associated with the text field
278 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700279 String newTitle = mFolderName.getText().toString();
280 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700281 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700282
Adam Cohen3371da02011-10-25 21:38:29 -0700283 if (commit) {
284 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700285 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700286 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700287 // In order to clear the focus from the text field, we set the focus on ourself. This
288 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
289 requestFocus();
290
Adam Cohene601a432011-07-26 21:51:30 -0700291 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700292 mIsEditingName = false;
293 }
294
295 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
296 if (actionId == EditorInfo.IME_ACTION_DONE) {
297 dismissEditingName();
298 return true;
299 }
300 return false;
301 }
302
303 public View getEditTextRegion() {
304 return mFolderName;
305 }
306
Adam Cohenbadf71e2011-05-26 19:08:29 -0700307 public Drawable getDragDrawable() {
308 return mIconDrawable;
309 }
310
Adam Cohen0c872ba2011-05-05 10:34:16 -0700311 /**
312 * We need to handle touch events to prevent them from falling through to the workspace below.
313 */
314 @Override
315 public boolean onTouchEvent(MotionEvent ev) {
316 return true;
317 }
318
Joe Onorato00acb122009-08-04 16:04:30 -0400319 public void setDragController(DragController dragController) {
320 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 }
322
Adam Cohen2801caf2011-05-13 20:57:39 -0700323 void setFolderIcon(FolderIcon icon) {
324 mFolderIcon = icon;
325 }
326
Adam Cohen3371da02011-10-25 21:38:29 -0700327 @Override
328 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
329 // When the folder gets focus, we don't want to announce the list of items.
330 return true;
331 }
332
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800333 /**
334 * @return the FolderInfo object associated with this folder
335 */
336 FolderInfo getInfo() {
337 return mInfo;
338 }
339
Adam Cohen3bf84d32012-05-07 20:17:14 -0700340 private class GridComparator implements Comparator<ShortcutInfo> {
341 int mNumCols;
342 public GridComparator(int numCols) {
343 mNumCols = numCols;
344 }
345
346 @Override
347 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
348 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
349 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
350 return (lhIndex - rhIndex);
351 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700352 }
353
354 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
355 int maxX = 0;
356 int count = items.size();
357 for (int i = 0; i < count; i++) {
358 ShortcutInfo item = items.get(i);
359 if (item.cellX > maxX) {
360 maxX = item.cellX;
361 }
362 }
Adam Cohen691a5792012-05-11 14:27:30 -0700363
364 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700365 Collections.sort(items, gridComparator);
366 final int countX = mContent.getCountX();
367 for (int i = 0; i < count; i++) {
368 int x = i % countX;
369 int y = i / countX;
370 ShortcutInfo item = items.get(i);
371 item.cellX = x;
372 item.cellY = y;
373 }
374 }
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 void bind(FolderInfo info) {
377 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700378 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700379 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700380 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700381 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700382 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700383 for (int i = 0; i < children.size(); i++) {
384 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700385 if (!createAndAddShortcut(child)) {
386 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700387 } else {
388 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700389 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700390 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700391
Adam Cohen0057bbc2011-08-12 18:30:51 -0700392 // We rearrange the items in case there are any empty gaps
393 setupContentForNumItems(count);
394
Adam Cohenc508b2d2011-06-28 14:41:44 -0700395 // If our folder has too many items we prune them from the list. This is an issue
396 // when upgrading from the old Folders implementation which could contain an unlimited
397 // number of items.
398 for (ShortcutInfo item: overflow) {
399 mInfo.remove(item);
400 LauncherModel.deleteItemFromDatabase(mLauncher, item);
401 }
402
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700403 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700404 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700405 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700406
Adam Cohenafb01ee2011-06-23 15:38:03 -0700407 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700408 mFolderName.setText(mInfo.title);
409 } else {
410 mFolderName.setText("");
411 }
Adam Cohen691a5792012-05-11 14:27:30 -0700412 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700413 }
414
415 /**
416 * Creates a new UserFolder, inflated from R.layout.user_folder.
417 *
418 * @param context The application's context.
419 *
420 * @return A new UserFolder.
421 */
422 static Folder fromXml(Context context) {
423 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
424 }
425
426 /**
427 * This method is intended to make the UserFolder to be visually identical in size and position
428 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
429 */
430 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700431 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800432 setScaleX(0.8f);
433 setScaleY(0.8f);
434 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700435 mState = STATE_SMALL;
436 }
437
438 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700439 positionAndSizeAsIcon();
440
Adam Cohen8e776a62011-06-28 18:10:06 -0700441 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700442 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800443 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
444 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
445 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200446 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700447 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800448
Adam Cohen2801caf2011-05-13 20:57:39 -0700449 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700450 @Override
451 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700452 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700453 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700454 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700455 mState = STATE_ANIMATING;
456 }
457 @Override
458 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700459 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700460 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700461 Cling cling = mLauncher.showFirstRunFoldersCling();
462 if (cling != null) {
463 cling.bringToFront();
464 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700465 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700466 }
467 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700468 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700469 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100470 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700471 }
472
Adam Cohen3371da02011-10-25 21:38:29 -0700473 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700474 AccessibilityManager accessibilityManager = (AccessibilityManager)
475 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
476 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700477 AccessibilityEvent event = AccessibilityEvent.obtain(type);
478 onInitializeAccessibilityEvent(event);
479 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700480 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700481 }
482 }
483
Adam Cohenac56cff2011-09-28 20:45:37 -0700484 private void setFocusOnFirstChild() {
485 View firstChild = mContent.getChildAt(0, 0);
486 if (firstChild != null) {
487 firstChild.requestFocus();
488 }
489 }
490
Adam Cohendf2cc412011-04-27 16:56:57 -0700491 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700492 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800493 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
494 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
495 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200496 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700497 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700498
Adam Cohen2801caf2011-05-13 20:57:39 -0700499 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700500 @Override
501 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700502 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700503 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700504 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700505 }
506 @Override
507 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700508 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700509 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700510 mState = STATE_ANIMATING;
511 }
512 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700513 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700514 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100515 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700516 }
517
Adam Cohencb3382b2011-05-24 14:07:08 -0700518 public boolean acceptDrop(DragObject d) {
519 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700520 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700521 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
522 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
523 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700524 }
525
Adam Cohendf2cc412011-04-27 16:56:57 -0700526 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
527 int[] emptyCell = new int[2];
528 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
529 item.cellX = emptyCell[0];
530 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700531 return true;
532 } else {
533 return false;
534 }
535 }
536
Adam Cohenc508b2d2011-06-28 14:41:44 -0700537 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700538 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700539 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700540 textView.setCompoundDrawablesWithIntrinsicBounds(null,
541 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
542 textView.setText(item.title);
543 textView.setTag(item);
544
545 textView.setOnClickListener(this);
546 textView.setOnLongClickListener(this);
547
Adam Cohenc508b2d2011-06-28 14:41:44 -0700548 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700549 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700550 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
551 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700552 // This shouldn't happen, log it.
553 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700554 if (!findAndSetEmptyCells(item)) {
555 return false;
556 }
557 }
558
Adam Cohendf2cc412011-04-27 16:56:57 -0700559 CellLayout.LayoutParams lp =
560 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
561 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700562 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700563 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700564 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700565 }
566
Adam Cohencb3382b2011-05-24 14:07:08 -0700567 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700568 mPreviousTargetCell[0] = -1;
569 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700570 mOnExitAlarm.cancelAlarm();
571 }
572
573 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
574 public void onAlarm(Alarm alarm) {
575 realTimeReorder(mEmptyCell, mTargetCell);
576 }
577 };
578
579 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
580 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
581 return true;
582 } else {
583 return false;
584 }
585 }
586
587 private void realTimeReorder(int[] empty, int[] target) {
588 boolean wrap;
589 int startX;
590 int endX;
591 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700592 int delay = 0;
593 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700594 if (readingOrderGreaterThan(target, empty)) {
595 wrap = empty[0] >= mContent.getCountX() - 1;
596 startY = wrap ? empty[1] + 1 : empty[1];
597 for (int y = startY; y <= target[1]; y++) {
598 startX = y == empty[1] ? empty[0] + 1 : 0;
599 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
600 for (int x = startX; x <= endX; x++) {
601 View v = mContent.getChildAt(x,y);
602 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800603 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700604 empty[0] = x;
605 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700606 delay += delayAmount;
607 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700608 }
609 }
610 }
611 } else {
612 wrap = empty[0] == 0;
613 startY = wrap ? empty[1] - 1 : empty[1];
614 for (int y = startY; y >= target[1]; y--) {
615 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
616 endX = y > target[1] ? 0 : target[0];
617 for (int x = startX; x >= endX; x--) {
618 View v = mContent.getChildAt(x,y);
619 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800620 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700621 empty[0] = x;
622 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700623 delay += delayAmount;
624 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700625 }
626 }
627 }
628 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700629 }
630
Adam Cohen2374abf2013-04-16 14:56:57 -0700631 public boolean isLayoutRtl() {
632 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
633 }
634
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700635 private Rect getDragObjectDrawingRect(View dragView, float[] r) {
636 final Rect drawingRect = mTempRect;
637 drawingRect.left = (int) r[0];
638 drawingRect.top = (int) r[1];
639 drawingRect.right = drawingRect.left + dragView.getMeasuredWidth();
640 drawingRect.bottom = drawingRect.top + dragView.getMeasuredHeight();
641 return drawingRect;
642 }
643
Adam Cohencb3382b2011-05-24 14:07:08 -0700644 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700645 int scrollOffset = mScrollView.getScrollY();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700646 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700647 r[0] -= getPaddingLeft();
648 r[1] -= getPaddingTop();
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700649 if (!mAutoScroller.onTouch(this, getDragObjectDrawingRect(d.dragView, r))) {
650 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1,
651 mTargetCell);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700652
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700653 if (isLayoutRtl()) {
654 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700655 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700656 if (mTargetCell[0] != mPreviousTargetCell[0]
657 || mTargetCell[1] != mPreviousTargetCell[1]) {
658 mReorderAlarm.cancelAlarm();
659 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
660 mReorderAlarm.setAlarm(REORDER_DELAY);
661 mPreviousTargetCell[0] = mTargetCell[0];
662 mPreviousTargetCell[1] = mTargetCell[1];
663 mDragMode = DRAG_MODE_REORDER;
664 } else {
665 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700666 }
Adam Cohen61a9a5c2013-08-14 13:32:04 -0700667 } else {
668 mReorderAlarm.cancelAlarm();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700669 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700670 }
671
Adam Cohenbfbfd262011-06-13 16:55:12 -0700672 // This is used to compute the visual center of the dragView. The idea is that
673 // the visual center represents the user's interpretation of where the item is, and hence
674 // is the appropriate point to use when determining drop location.
675 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
676 DragView dragView, float[] recycle) {
677 float res[];
678 if (recycle == null) {
679 res = new float[2];
680 } else {
681 res = recycle;
682 }
683
684 // These represent the visual top and left of drag view if a dragRect was provided.
685 // If a dragRect was not provided, then they correspond to the actual view left and
686 // top, as the dragRect is in that case taken to be the entire dragView.
687 // R.dimen.dragViewOffsetY.
688 int left = x - xOffset;
689 int top = y - yOffset;
690
691 // In order to find the visual center, we shift by half the dragRect
692 res[0] = left + dragView.getDragRegion().width() / 2;
693 res[1] = top + dragView.getDragRegion().height() / 2;
694
695 return res;
696 }
697
698 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
699 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700700 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700701 }
702 };
703
Adam Cohen95bb8002011-07-03 23:40:28 -0700704 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700705 mLauncher.closeFolder();
706 mCurrentDragInfo = null;
707 mCurrentDragView = null;
708 mSuppressOnAdd = false;
709 mRearrangeOnClose = true;
710 }
711
Adam Cohencb3382b2011-05-24 14:07:08 -0700712 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700713 // Exiting folder; stop the auto scroller.
714 mAutoScroller.stop();
715 // We only close the folder if this is a true drag exit, ie. not because
716 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700717 if (!d.dragComplete) {
718 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
719 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
720 }
721 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700722 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700723 }
724
Michael Jurka1e2f4652013-07-08 18:03:46 -0700725 public void onDropCompleted(final View target, final DragObject d,
726 final boolean isFlingToDelete, final boolean success) {
727 if (mDeferDropAfterUninstall) {
Michael Jurkaf3007582013-08-21 14:33:57 +0200728 Log.d(TAG, "Deferred handling drop because waiting for uninstall.");
Michael Jurka1e2f4652013-07-08 18:03:46 -0700729 mDeferredAction = new Runnable() {
730 public void run() {
731 onDropCompleted(target, d, isFlingToDelete, success);
732 mDeferredAction = null;
733 }
734 };
735 return;
736 }
737
738 boolean beingCalledAfterUninstall = mDeferredAction != null;
739 boolean successfulDrop =
740 success && (!beingCalledAfterUninstall || mUninstallSuccessful);
Winson Chung5f8afe62013-08-12 16:19:28 -0700741
Michael Jurka1e2f4652013-07-08 18:03:46 -0700742 if (successfulDrop) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700743 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700744 replaceFolderWithFinalItem();
745 }
746 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700747 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700748 // The drag failed, we need to return the item to the folder
749 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700750 }
751
752 if (target != this) {
753 if (mOnExitAlarm.alarmPending()) {
754 mOnExitAlarm.cancelAlarm();
Michael Jurka54554252013-08-01 12:52:23 +0200755 if (!successfulDrop) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700756 mSuppressFolderDeletion = true;
757 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700758 completeDragExit();
759 }
760 }
Winson Chung5f8afe62013-08-12 16:19:28 -0700761
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700762 mDeleteFolderOnDropCompleted = false;
763 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700764 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700765 mCurrentDragInfo = null;
766 mCurrentDragView = null;
767 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700768
769 // Reordering may have occured, and we need to save the new item locations. We do this once
770 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700771 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700772 }
773
Michael Jurka1e2f4652013-07-08 18:03:46 -0700774 public void deferCompleteDropAfterUninstallActivity() {
775 mDeferDropAfterUninstall = true;
776 }
777
778 public void onUninstallActivityReturned(boolean success) {
779 mDeferDropAfterUninstall = false;
780 mUninstallSuccessful = success;
781 if (mDeferredAction != null) {
782 mDeferredAction.run();
783 }
784 }
785
Winson Chunga48487a2012-03-20 16:19:37 -0700786 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800787 public boolean supportsFlingToDelete() {
788 return true;
789 }
790
Winson Chunga48487a2012-03-20 16:19:37 -0700791 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
792 // Do nothing
793 }
794
795 @Override
796 public void onFlingToDeleteCompleted() {
797 // Do nothing
798 }
799
Adam Cohen4045eb72011-10-06 11:44:26 -0700800 private void updateItemLocationsInDatabase() {
801 ArrayList<View> list = getItemsInReadingOrder();
802 for (int i = 0; i < list.size(); i++) {
803 View v = list.get(i);
804 ItemInfo info = (ItemInfo) v.getTag();
805 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
806 info.cellX, info.cellY);
807 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700808 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700809
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700810 private void updateItemLocationsInDatabaseBatch() {
811 ArrayList<View> list = getItemsInReadingOrder();
812 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
813 for (int i = 0; i < list.size(); i++) {
814 View v = list.get(i);
815 ItemInfo info = (ItemInfo) v.getTag();
816 items.add(info);
817 }
818
819 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
820 }
821
Adam Cohene25af792013-06-06 23:08:25 -0700822 public void addItemLocationsInDatabase() {
823 ArrayList<View> list = getItemsInReadingOrder();
824 for (int i = 0; i < list.size(); i++) {
825 View v = list.get(i);
826 ItemInfo info = (ItemInfo) v.getTag();
827 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
828 info.cellX, info.cellY, false);
829 }
830 }
831
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700832 public void notifyDrop() {
833 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700834 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700835 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700836 }
837
838 public boolean isDropEnabled() {
839 return true;
840 }
841
Adam Cohen4045eb72011-10-06 11:44:26 -0700842 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700843 ArrayList<View> list = getItemsInReadingOrder();
844
845 int countX = mContent.getCountX();
846 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700847 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700848
Adam Cohen7c693212011-05-18 15:26:57 -0700849 while (!done) {
850 int oldCountX = countX;
851 int oldCountY = countY;
852 if (countX * countY < count) {
853 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800854 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700855 countX++;
856 } else if (countY < mMaxCountY) {
857 countY++;
858 }
859 if (countY == 0) countY++;
860 } else if ((countY - 1) * countX >= count && countY >= countX) {
861 countY = Math.max(0, countY - 1);
862 } else if ((countX - 1) * countY >= count) {
863 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700864 }
Adam Cohen7c693212011-05-18 15:26:57 -0700865 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700866 }
Adam Cohen7c693212011-05-18 15:26:57 -0700867 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700868 arrangeChildren(list);
869 }
870
871 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800872 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700873 }
874
875 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700876 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700877
Winson Chung892c74d2013-08-22 16:15:50 -0700878 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700879 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700880 int height = getFolderHeight();
Adam Cohen2801caf2011-05-13 20:57:39 -0700881
Adam Cohen307fe232012-08-16 17:55:58 -0700882 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700883
Adam Cohen307fe232012-08-16 17:55:58 -0700884 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
885 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700886 int centeredLeft = centerX - width / 2;
887 int centeredTop = centerY - height / 2;
888
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800889 int currentPage = mLauncher.getWorkspace().getCurrentPage();
890 // In case the workspace is scrolling, we need to use the final scroll to compute
891 // the folders bounds.
892 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700893 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800894 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700895 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700896 Rect bounds = new Rect();
897 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800898 // We reset the workspaces scroll
899 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700900
Adam Cohen35e7e642011-07-17 14:47:18 -0700901 // We need to bound the folder to the currently visible CellLayoutChildren
902 int left = Math.min(Math.max(bounds.left, centeredLeft),
903 bounds.left + bounds.width() - width);
904 int top = Math.min(Math.max(bounds.top, centeredTop),
905 bounds.top + bounds.height() - height);
906 // If the folder doesn't fit within the bounds, center it about the desired bounds
907 if (width >= bounds.width()) {
908 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700909 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700910 if (height >= bounds.height()) {
911 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700912 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700913
914 int folderPivotX = width / 2 + (centeredLeft - left);
915 int folderPivotY = height / 2 + (centeredTop - top);
916 setPivotX(folderPivotX);
917 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700918 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700919 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700920 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700921 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700922
Adam Cohen662b5982011-12-13 17:45:21 -0800923 lp.width = width;
924 lp.height = height;
925 lp.x = left;
926 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700927 }
928
Adam Cohen268c4752012-06-06 17:47:33 -0700929 float getPivotXForIconAnimation() {
930 return mFolderIconPivotX;
931 }
932 float getPivotYForIconAnimation() {
933 return mFolderIconPivotY;
934 }
935
Adam Cohen2801caf2011-05-13 20:57:39 -0700936 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700937 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700938
Adam Cohen8e776a62011-06-28 18:10:06 -0700939 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700940 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700941 lp = new DragLayer.LayoutParams(0, 0);
942 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700943 setLayoutParams(lp);
944 }
945 centerAboutIcon();
946 }
947
Winson Chung892c74d2013-08-22 16:15:50 -0700948 private int getContentAreaHeight() {
949 LauncherAppState app = LauncherAppState.getInstance();
950 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
951 Rect workspacePadding = grid.getWorkspacePadding(grid.isLandscape ?
952 CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
953 int maxContentAreaHeight = grid.availableHeightPx -
954 4 * grid.edgeMarginPx -
955 workspacePadding.top - workspacePadding.bottom -
956 getPaddingTop() - getPaddingBottom() -
957 mFolderNameHeight;
958 return Math.min(maxContentAreaHeight,
959 mContent.getDesiredHeight());
960 }
961
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700962 private int getFolderHeight() {
Winson Chung892c74d2013-08-22 16:15:50 -0700963 int height = getPaddingTop() + getPaddingBottom()
964 + getContentAreaHeight() + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700965 return height;
966 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700967
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700968 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700969 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
970 int height = getFolderHeight();
971 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
972 MeasureSpec.EXACTLY);
Winson Chung892c74d2013-08-22 16:15:50 -0700973 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(getContentAreaHeight(),
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700974 MeasureSpec.EXACTLY);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700975 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
976 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
977 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -0700978 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
979 setMeasuredDimension(width, height);
980 }
981
Adam Cohen2801caf2011-05-13 20:57:39 -0700982 private void arrangeChildren(ArrayList<View> list) {
983 int[] vacant = new int[2];
984 if (list == null) {
985 list = getItemsInReadingOrder();
986 }
987 mContent.removeAllViews();
988
989 for (int i = 0; i < list.size(); i++) {
990 View v = list.get(i);
991 mContent.getVacantCell(vacant, 1, 1);
992 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
993 lp.cellX = vacant[0];
994 lp.cellY = vacant[1];
995 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -0700996 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
997 info.cellX = vacant[0];
998 info.cellY = vacant[1];
999 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
1000 info.cellX, info.cellY);
1001 }
Adam Cohen2801caf2011-05-13 20:57:39 -07001002 boolean insert = false;
1003 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1004 }
Adam Cohen7c693212011-05-18 15:26:57 -07001005 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001006 }
1007
Adam Cohena9cf38f2011-05-02 15:36:58 -07001008 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001009 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001010 }
1011
1012 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001013 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001014 }
1015
Adam Cohen2801caf2011-05-13 20:57:39 -07001016 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001017 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001018 if (parent != null) {
1019 parent.removeView(this);
1020 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001021 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001022 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001023 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001024
Adam Cohen2801caf2011-05-13 20:57:39 -07001025 if (mRearrangeOnClose) {
1026 setupContentForNumItems(getItemCount());
1027 mRearrangeOnClose = false;
1028 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001029 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001030 if (!mDragInProgress && !mSuppressFolderDeletion) {
1031 replaceFolderWithFinalItem();
1032 } else if (mDragInProgress) {
1033 mDeleteFolderOnDropCompleted = true;
1034 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001035 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001036 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001037 }
1038
1039 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001040 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001041 Runnable onCompleteRunnable = new Runnable() {
1042 @Override
1043 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001044 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001045
Adam Cohenc5e63f32012-07-12 16:16:57 -07001046 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001047 // Move the item from the folder to the workspace, in the position of the folder
1048 if (getItemCount() == 1) {
1049 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001050 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001051 finalItem);
1052 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001053 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001054 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001055 if (getItemCount() <= 1) {
1056 // Remove the folder
1057 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1058 cellLayout.removeView(mFolderIcon);
1059 if (mFolderIcon instanceof DropTarget) {
1060 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1061 }
1062 mLauncher.removeFolder(mInfo);
1063 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001064 // We add the child after removing the folder to prevent both from existing at
Winson Chung0e6a7132013-08-23 12:55:10 -07001065 // the same time in the CellLayout. We need to add the new item with addInScreenFromBind()
1066 // to ensure that hotseat items are placed correctly.
Adam Cohenc5e63f32012-07-12 16:16:57 -07001067 if (child != null) {
Winson Chung0e6a7132013-08-23 12:55:10 -07001068 mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001069 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1070 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001071 }
1072 };
1073 View finalChild = getItemAt(0);
1074 if (finalChild != null) {
1075 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001076 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001077 mDestroyed = true;
1078 }
1079
1080 boolean isDestroyed() {
1081 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001082 }
1083
Adam Cohenac56cff2011-09-28 20:45:37 -07001084 // This method keeps track of the last item in the folder for the purposes
1085 // of keyboard focus
1086 private void updateTextViewFocus() {
1087 View lastChild = getItemAt(getItemCount() - 1);
1088 getItemAt(getItemCount() - 1);
1089 if (lastChild != null) {
1090 mFolderName.setNextFocusDownId(lastChild.getId());
1091 mFolderName.setNextFocusRightId(lastChild.getId());
1092 mFolderName.setNextFocusLeftId(lastChild.getId());
1093 mFolderName.setNextFocusUpId(lastChild.getId());
1094 }
1095 }
1096
Adam Cohenbfbfd262011-06-13 16:55:12 -07001097 public void onDrop(DragObject d) {
1098 ShortcutInfo item;
1099 if (d.dragInfo instanceof ApplicationInfo) {
1100 // Came from all apps -- make a copy
1101 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1102 item.spanX = 1;
1103 item.spanY = 1;
1104 } else {
1105 item = (ShortcutInfo) d.dragInfo;
1106 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001107 // Dragged from self onto self, currently this is the only path possible, however
1108 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001109 if (item == mCurrentDragInfo) {
1110 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1111 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1112 si.cellX = lp.cellX = mEmptyCell[0];
1113 si.cellX = lp.cellY = mEmptyCell[1];
1114 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001115 if (d.dragView.hasDrawn()) {
1116 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1117 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001118 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001119 mCurrentDragView.setVisibility(VISIBLE);
1120 }
Adam Cohene9166b22011-07-08 17:11:11 -07001121 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001122 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001123 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001124 }
1125 mInfo.add(item);
1126 }
1127
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001128 // This is used so the item doesn't immediately appear in the folder when added. In one case
1129 // we need to create the illusion that the item isn't added back to the folder yet, to
1130 // to correspond to the animation of the icon back into the folder. This is
1131 public void hideItem(ShortcutInfo info) {
1132 View v = getViewForInfo(info);
1133 v.setVisibility(INVISIBLE);
1134 }
1135 public void showItem(ShortcutInfo info) {
1136 View v = getViewForInfo(info);
1137 v.setVisibility(VISIBLE);
1138 }
1139
Adam Cohenbfbfd262011-06-13 16:55:12 -07001140 public void onAdd(ShortcutInfo item) {
1141 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001142 // If the item was dropped onto this open folder, we have done the work associated
1143 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001144 if (mSuppressOnAdd) return;
1145 if (!findAndSetEmptyCells(item)) {
1146 // The current layout is full, can we expand it?
1147 setupContentForNumItems(getItemCount() + 1);
1148 findAndSetEmptyCells(item);
1149 }
1150 createAndAddShortcut(item);
1151 LauncherModel.addOrMoveItemInDatabase(
1152 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1153 }
1154
Adam Cohena9cf38f2011-05-02 15:36:58 -07001155 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001156 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001157 // If this item is being dragged from this open folder, we have already handled
1158 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001159 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001160 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001161 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001162 if (mState == STATE_ANIMATING) {
1163 mRearrangeOnClose = true;
1164 } else {
1165 setupContentForNumItems(getItemCount());
1166 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001167 if (getItemCount() <= 1) {
1168 replaceFolderWithFinalItem();
1169 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001170 }
Adam Cohen7c693212011-05-18 15:26:57 -07001171
Adam Cohendf1e4e82011-06-24 15:57:39 -07001172 private View getViewForInfo(ShortcutInfo item) {
1173 for (int j = 0; j < mContent.getCountY(); j++) {
1174 for (int i = 0; i < mContent.getCountX(); i++) {
1175 View v = mContent.getChildAt(i, j);
1176 if (v.getTag() == item) {
1177 return v;
1178 }
1179 }
1180 }
1181 return null;
1182 }
1183
Adam Cohen76078c42011-06-09 15:06:52 -07001184 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001185 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001186 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001187
Adam Cohen76fc0852011-06-17 13:26:23 -07001188 public void onTitleChanged(CharSequence title) {
1189 }
Adam Cohen76078c42011-06-09 15:06:52 -07001190
Adam Cohen7c693212011-05-18 15:26:57 -07001191 public ArrayList<View> getItemsInReadingOrder() {
1192 if (mItemsInvalidated) {
1193 mItemsInReadingOrder.clear();
1194 for (int j = 0; j < mContent.getCountY(); j++) {
1195 for (int i = 0; i < mContent.getCountX(); i++) {
1196 View v = mContent.getChildAt(i, j);
1197 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001198 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001199 }
1200 }
1201 }
1202 mItemsInvalidated = false;
1203 }
1204 return mItemsInReadingOrder;
1205 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001206
1207 public void getLocationInDragLayer(int[] loc) {
1208 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1209 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001210
1211 public void onFocusChange(View v, boolean hasFocus) {
1212 if (v == mFolderName && hasFocus) {
1213 startEditingFolderName();
1214 }
1215 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001216
1217 @Override
1218 public void getHitRectRelativeToDragLayer(Rect outRect) {
1219 getHitRect(outRect);
1220 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221}