blob: a71d9b2c05dc7249ef7ebfe19c7eb4298a833f83 [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;
Alan Viverette4cda5b72013-08-28 17:53:41 -070028import android.os.SystemClock;
Bjorn Bringertb66773c2013-09-25 16:12:24 +010029import android.support.v4.widget.AutoScrollHelper;
Adam Cohen7a14d0b2011-06-24 11:36:35 -070030import android.text.InputType;
Adam Cohene601a432011-07-26 21:51:30 -070031import android.text.Selection;
32import android.text.Spannable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080033import android.util.AttributeSet;
Winson Chung892c74d2013-08-22 16:15:50 -070034import android.util.DisplayMetrics;
Adam Cohen3bf84d32012-05-07 20:17:14 -070035import android.util.Log;
Winson Chung892c74d2013-08-22 16:15:50 -070036import android.util.TypedValue;
Adam Cohen76fc0852011-06-17 13:26:23 -070037import android.view.ActionMode;
38import android.view.KeyEvent;
Adam Cohendf2cc412011-04-27 16:56:57 -070039import android.view.LayoutInflater;
Adam Cohen76fc0852011-06-17 13:26:23 -070040import android.view.Menu;
41import android.view.MenuItem;
Adam Cohen0c872ba2011-05-05 10:34:16 -070042import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.view.View;
Adam Cohen3371da02011-10-25 21:38:29 -070044import android.view.accessibility.AccessibilityEvent;
45import android.view.accessibility.AccessibilityManager;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -070046import android.view.animation.AccelerateInterpolator;
47import android.view.animation.Interpolator;
Adam Cohen76fc0852011-06-17 13:26:23 -070048import android.view.inputmethod.EditorInfo;
49import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070051import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070052import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053
Daniel Sandler325dc232013-06-05 22:57:57 -040054import com.android.launcher3.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080055
Adam Cohenc0dcf592011-06-01 15:30:43 -070056import java.util.ArrayList;
Adam Cohen3bf84d32012-05-07 20:17:14 -070057import java.util.Collections;
58import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -070059
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060/**
61 * Represents a set of icons chosen by the user or generated by the system.
62 */
Adam Cohen8dfcba42011-07-07 16:38:18 -070063public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
Adam Cohenea0818d2011-09-30 20:06:58 -070064 View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
65 View.OnFocusChangeListener {
Adam Cohendf2cc412011-04-27 16:56:57 -070066 private static final String TAG = "Launcher.Folder";
67
Adam Cohen4eac29a2011-07-11 17:53:37 -070068 protected DragController mDragController;
69 protected Launcher mLauncher;
70 protected FolderInfo mInfo;
71
Adam Cohendf2cc412011-04-27 16:56:57 -070072 static final int STATE_NONE = -1;
73 static final int STATE_SMALL = 0;
74 static final int STATE_ANIMATING = 1;
75 static final int STATE_OPEN = 2;
76
77 private int mExpandDuration;
78 protected CellLayout mContent;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070079 private ScrollView mScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070080 private final LayoutInflater mInflater;
81 private final IconCache mIconCache;
82 private int mState = STATE_NONE;
Adam Cohenbfbfd262011-06-13 16:55:12 -070083 private static final int REORDER_ANIMATION_DURATION = 230;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070084 private static final int REORDER_DELAY = 250;
Adam Cohenbfbfd262011-06-13 16:55:12 -070085 private static final int ON_EXIT_CLOSE_DELAY = 800;
Adam Cohen2801caf2011-05-13 20:57:39 -070086 private boolean mRearrangeOnClose = false;
87 private FolderIcon mFolderIcon;
88 private int mMaxCountX;
89 private int mMaxCountY;
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
Adam Cohen76fc0852011-06-17 13:26:23 -0700112 private boolean mIsEditingName = false;
113 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700114
Adam Cohena65beee2011-06-27 21:32:23 -0700115 private static String sDefaultFolderName;
116 private static String sHintText;
117
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700118 private int DRAG_MODE_NONE = 0;
119 private int DRAG_MODE_REORDER = 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700120 private int mDragMode = DRAG_MODE_NONE;
121
Adam Cohenfb91f302012-06-11 15:45:18 -0700122 private boolean mDestroyed;
123
Alan Viverette4cda5b72013-08-28 17:53:41 -0700124 private AutoScrollHelper mAutoScrollHelper;
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700125
Michael Jurka1e2f4652013-07-08 18:03:46 -0700126 private Runnable mDeferredAction;
127 private boolean mDeferDropAfterUninstall;
128 private boolean mUninstallSuccessful;
129
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 /**
131 * Used to inflate the Workspace from XML.
132 *
133 * @param context The application's context.
134 * @param attrs The attribtues set containing the Workspace's customization values.
135 */
136 public Folder(Context context, AttributeSet attrs) {
137 super(context, attrs);
Winson Chung5f8afe62013-08-12 16:19:28 -0700138
139 LauncherAppState app = LauncherAppState.getInstance();
140 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700142 mInflater = LayoutInflater.from(context);
Winson Chung5f8afe62013-08-12 16:19:28 -0700143 mIconCache = app.getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800144
145 Resources res = getResources();
Michael Jurka414300a2013-08-27 15:42:35 +0200146 mMaxCountX = (int) grid.numColumns;
Adam Cohen477828c2013-09-20 12:05:49 -0700147 mMaxCountY = (int) grid.numRows;
148 mMaxNumItems = mMaxCountX * mMaxCountY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700149
150 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700151 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700152
Adam Cohen76fc0852011-06-17 13:26:23 -0700153 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700154
155 if (sDefaultFolderName == null) {
156 sDefaultFolderName = res.getString(R.string.folder_name);
157 }
Adam Cohena65beee2011-06-27 21:32:23 -0700158 if (sHintText == null) {
159 sHintText = res.getString(R.string.folder_hint_text);
160 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700161 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700162 // We need this view to be focusable in touch mode so that when text editing of the folder
163 // name is complete, we have something to focus on, thus hiding the cursor and giving
164 // reliable behvior when clicking the text field (since it will always gain focus on click).
165 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 }
167
168 @Override
169 protected void onFinishInflate() {
170 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700171 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700172 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700173
Winson Chung5f8afe62013-08-12 16:19:28 -0700174 LauncherAppState app = LauncherAppState.getInstance();
175 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
176
Winson Chung5f8afe62013-08-12 16:19:28 -0700177 mContent.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
Adam Cohen2801caf2011-05-13 20:57:39 -0700178 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700179 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700180 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700181 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
182 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700183 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700184
185 // We find out how tall the text view wants to be (it is set to wrap_content), so that
186 // we can allocate the appropriate amount of space for it.
187 int measureSpec = MeasureSpec.UNSPECIFIED;
188 mFolderName.measure(measureSpec, measureSpec);
189 mFolderNameHeight = mFolderName.getMeasuredHeight();
190
191 // We disable action mode for now since it messes up the view on phones
192 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700193 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700194 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700195 mFolderName.setInputType(mFolderName.getInputType() |
196 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Alan Viverette4cda5b72013-08-28 17:53:41 -0700197 mAutoScrollHelper = new FolderAutoScrollHelper(mScrollView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800198 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700199
Adam Cohen76fc0852011-06-17 13:26:23 -0700200 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
201 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
202 return false;
203 }
204
205 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
206 return false;
207 }
208
209 public void onDestroyActionMode(ActionMode mode) {
210 }
211
212 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
213 return false;
214 }
215 };
216
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700218 Object tag = v.getTag();
219 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700220 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700221 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 }
223
224 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700225 // Return if global dragging is not enabled
226 if (!mLauncher.isDraggingEnabled()) return true;
227
Adam Cohendf2cc412011-04-27 16:56:57 -0700228 Object tag = v.getTag();
229 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700230 ShortcutInfo item = (ShortcutInfo) tag;
231 if (!v.isInTouchMode()) {
232 return false;
233 }
234
Winson Chung7d7541e2011-09-16 20:14:36 -0700235 mLauncher.dismissFolderCling(null);
236
Adam Cohendf2cc412011-04-27 16:56:57 -0700237 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700238 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700239 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700240
241 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700242 mEmptyCell[0] = item.cellX;
243 mEmptyCell[1] = item.cellY;
244 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700245
246 mContent.removeView(mCurrentDragView);
247 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700248 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700249 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700250 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800251 return true;
252 }
253
Adam Cohen76fc0852011-06-17 13:26:23 -0700254 public boolean isEditingName() {
255 return mIsEditingName;
256 }
257
258 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700259 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700260 mIsEditingName = true;
261 }
262
263 public void dismissEditingName() {
264 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
265 doneEditingFolderName(true);
266 }
267
268 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700269 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700270 // Convert to a string here to ensure that no other state associated with the text field
271 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700272 String newTitle = mFolderName.getText().toString();
273 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700274 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700275
Adam Cohen3371da02011-10-25 21:38:29 -0700276 if (commit) {
277 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700278 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700279 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700280 // In order to clear the focus from the text field, we set the focus on ourself. This
281 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
282 requestFocus();
283
Adam Cohene601a432011-07-26 21:51:30 -0700284 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700285 mIsEditingName = false;
286 }
287
288 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
289 if (actionId == EditorInfo.IME_ACTION_DONE) {
290 dismissEditingName();
291 return true;
292 }
293 return false;
294 }
295
296 public View getEditTextRegion() {
297 return mFolderName;
298 }
299
Adam Cohenbadf71e2011-05-26 19:08:29 -0700300 public Drawable getDragDrawable() {
301 return mIconDrawable;
302 }
303
Adam Cohen0c872ba2011-05-05 10:34:16 -0700304 /**
305 * We need to handle touch events to prevent them from falling through to the workspace below.
306 */
307 @Override
308 public boolean onTouchEvent(MotionEvent ev) {
309 return true;
310 }
311
Joe Onorato00acb122009-08-04 16:04:30 -0400312 public void setDragController(DragController dragController) {
313 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800314 }
315
Adam Cohen2801caf2011-05-13 20:57:39 -0700316 void setFolderIcon(FolderIcon icon) {
317 mFolderIcon = icon;
318 }
319
Adam Cohen3371da02011-10-25 21:38:29 -0700320 @Override
321 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
322 // When the folder gets focus, we don't want to announce the list of items.
323 return true;
324 }
325
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800326 /**
327 * @return the FolderInfo object associated with this folder
328 */
329 FolderInfo getInfo() {
330 return mInfo;
331 }
332
Adam Cohen3bf84d32012-05-07 20:17:14 -0700333 private class GridComparator implements Comparator<ShortcutInfo> {
334 int mNumCols;
335 public GridComparator(int numCols) {
336 mNumCols = numCols;
337 }
338
339 @Override
340 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
341 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
342 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
343 return (lhIndex - rhIndex);
344 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700345 }
346
347 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
348 int maxX = 0;
349 int count = items.size();
350 for (int i = 0; i < count; i++) {
351 ShortcutInfo item = items.get(i);
352 if (item.cellX > maxX) {
353 maxX = item.cellX;
354 }
355 }
Adam Cohen691a5792012-05-11 14:27:30 -0700356
357 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700358 Collections.sort(items, gridComparator);
359 final int countX = mContent.getCountX();
360 for (int i = 0; i < count; i++) {
361 int x = i % countX;
362 int y = i / countX;
363 ShortcutInfo item = items.get(i);
364 item.cellX = x;
365 item.cellY = y;
366 }
367 }
368
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800369 void bind(FolderInfo info) {
370 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700371 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700372 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700373 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700374 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700375 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700376 for (int i = 0; i < children.size(); i++) {
377 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700378 if (!createAndAddShortcut(child)) {
379 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700380 } else {
381 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700382 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700383 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700384
Adam Cohen0057bbc2011-08-12 18:30:51 -0700385 // We rearrange the items in case there are any empty gaps
386 setupContentForNumItems(count);
387
Adam Cohenc508b2d2011-06-28 14:41:44 -0700388 // If our folder has too many items we prune them from the list. This is an issue
389 // when upgrading from the old Folders implementation which could contain an unlimited
390 // number of items.
391 for (ShortcutInfo item: overflow) {
392 mInfo.remove(item);
393 LauncherModel.deleteItemFromDatabase(mLauncher, item);
394 }
395
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700396 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700397 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700398 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700399
Adam Cohenafb01ee2011-06-23 15:38:03 -0700400 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700401 mFolderName.setText(mInfo.title);
402 } else {
403 mFolderName.setText("");
404 }
Adam Cohen691a5792012-05-11 14:27:30 -0700405 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700406 }
407
408 /**
409 * Creates a new UserFolder, inflated from R.layout.user_folder.
410 *
411 * @param context The application's context.
412 *
413 * @return A new UserFolder.
414 */
415 static Folder fromXml(Context context) {
416 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
417 }
418
419 /**
420 * This method is intended to make the UserFolder to be visually identical in size and position
421 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
422 */
423 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700424 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800425 setScaleX(0.8f);
426 setScaleY(0.8f);
427 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700428 mState = STATE_SMALL;
429 }
430
431 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700432 positionAndSizeAsIcon();
433
Adam Cohen8e776a62011-06-28 18:10:06 -0700434 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700435 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800436 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
437 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
438 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200439 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700440 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800441
Adam Cohen2801caf2011-05-13 20:57:39 -0700442 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700443 @Override
444 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700445 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700446 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700447 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700448 mState = STATE_ANIMATING;
449 }
450 @Override
451 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700452 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700453 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700454 Cling cling = mLauncher.showFirstRunFoldersCling();
455 if (cling != null) {
456 cling.bringToFront();
Winson Chungaf40f202013-09-18 18:26:31 -0700457 bringToFront();
Winson Chung7a74ac92011-09-20 17:43:51 -0700458 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700459 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700460 }
461 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700462 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700463 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100464 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700465 }
466
Adam Cohen3371da02011-10-25 21:38:29 -0700467 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700468 AccessibilityManager accessibilityManager = (AccessibilityManager)
469 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
470 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700471 AccessibilityEvent event = AccessibilityEvent.obtain(type);
472 onInitializeAccessibilityEvent(event);
473 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700474 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700475 }
476 }
477
Adam Cohenac56cff2011-09-28 20:45:37 -0700478 private void setFocusOnFirstChild() {
479 View firstChild = mContent.getChildAt(0, 0);
480 if (firstChild != null) {
481 firstChild.requestFocus();
482 }
483 }
484
Adam Cohendf2cc412011-04-27 16:56:57 -0700485 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700486 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800487 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
488 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
489 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200490 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700491 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700492
Adam Cohen2801caf2011-05-13 20:57:39 -0700493 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700494 @Override
495 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700496 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700497 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700498 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700499 }
500 @Override
501 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700502 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700503 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700504 mState = STATE_ANIMATING;
505 }
506 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700507 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700508 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100509 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700510 }
511
Adam Cohencb3382b2011-05-24 14:07:08 -0700512 public boolean acceptDrop(DragObject d) {
513 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700514 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700515 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
516 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
517 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700518 }
519
Adam Cohendf2cc412011-04-27 16:56:57 -0700520 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
521 int[] emptyCell = new int[2];
522 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
523 item.cellX = emptyCell[0];
524 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700525 return true;
526 } else {
527 return false;
528 }
529 }
530
Adam Cohenc508b2d2011-06-28 14:41:44 -0700531 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohen477828c2013-09-20 12:05:49 -0700532 final BubbleTextView textView =
533 (BubbleTextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700534 textView.setCompoundDrawablesWithIntrinsicBounds(null,
535 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
536 textView.setText(item.title);
537 textView.setTag(item);
Adam Cohen477828c2013-09-20 12:05:49 -0700538 textView.setTextColor(getResources().getColor(R.color.folder_items_text_color));
539 textView.setShadowsEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700540
541 textView.setOnClickListener(this);
542 textView.setOnLongClickListener(this);
543
Adam Cohenc508b2d2011-06-28 14:41:44 -0700544 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700545 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700546 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
547 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700548 // This shouldn't happen, log it.
549 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700550 if (!findAndSetEmptyCells(item)) {
551 return false;
552 }
553 }
554
Adam Cohendf2cc412011-04-27 16:56:57 -0700555 CellLayout.LayoutParams lp =
556 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
557 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700558 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700559 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700560 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700561 }
562
Adam Cohencb3382b2011-05-24 14:07:08 -0700563 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700564 mPreviousTargetCell[0] = -1;
565 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700566 mOnExitAlarm.cancelAlarm();
567 }
568
569 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
570 public void onAlarm(Alarm alarm) {
571 realTimeReorder(mEmptyCell, mTargetCell);
572 }
573 };
574
575 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
576 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
577 return true;
578 } else {
579 return false;
580 }
581 }
582
583 private void realTimeReorder(int[] empty, int[] target) {
584 boolean wrap;
585 int startX;
586 int endX;
587 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700588 int delay = 0;
589 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700590 if (readingOrderGreaterThan(target, empty)) {
591 wrap = empty[0] >= mContent.getCountX() - 1;
592 startY = wrap ? empty[1] + 1 : empty[1];
593 for (int y = startY; y <= target[1]; y++) {
594 startX = y == empty[1] ? empty[0] + 1 : 0;
595 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
596 for (int x = startX; x <= endX; x++) {
597 View v = mContent.getChildAt(x,y);
598 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800599 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700600 empty[0] = x;
601 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700602 delay += delayAmount;
603 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700604 }
605 }
606 }
607 } else {
608 wrap = empty[0] == 0;
609 startY = wrap ? empty[1] - 1 : empty[1];
610 for (int y = startY; y >= target[1]; y--) {
611 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
612 endX = y > target[1] ? 0 : target[0];
613 for (int x = startX; x >= endX; x--) {
614 View v = mContent.getChildAt(x,y);
615 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800616 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700617 empty[0] = x;
618 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700619 delay += delayAmount;
620 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700621 }
622 }
623 }
624 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700625 }
626
Adam Cohen2374abf2013-04-16 14:56:57 -0700627 public boolean isLayoutRtl() {
628 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
629 }
630
Adam Cohencb3382b2011-05-24 14:07:08 -0700631 public void onDragOver(DragObject d) {
Alan Viverette4cda5b72013-08-28 17:53:41 -0700632 final DragView dragView = d.dragView;
633 final int scrollOffset = mScrollView.getScrollY();
634 final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700635 r[0] -= getPaddingLeft();
636 r[1] -= getPaddingTop();
637
Alan Viverette4cda5b72013-08-28 17:53:41 -0700638 final long downTime = SystemClock.uptimeMillis();
639 final MotionEvent translatedEv = MotionEvent.obtain(
640 downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);
641
642 if (!mAutoScrollHelper.isEnabled()) {
643 mAutoScrollHelper.setEnabled(true);
644 }
645
646 final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
647 translatedEv.recycle();
648
649 if (handled) {
650 mReorderAlarm.cancelAlarm();
651 } else {
652 mTargetCell = mContent.findNearestArea(
653 (int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700654 if (isLayoutRtl()) {
655 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700656 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700657 if (mTargetCell[0] != mPreviousTargetCell[0]
658 || mTargetCell[1] != mPreviousTargetCell[1]) {
659 mReorderAlarm.cancelAlarm();
660 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
661 mReorderAlarm.setAlarm(REORDER_DELAY);
662 mPreviousTargetCell[0] = mTargetCell[0];
663 mPreviousTargetCell[1] = mTargetCell[1];
664 mDragMode = DRAG_MODE_REORDER;
665 } else {
666 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700667 }
Adam Cohenbfbfd262011-06-13 16:55:12 -0700668 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700669 }
670
Adam Cohenbfbfd262011-06-13 16:55:12 -0700671 // This is used to compute the visual center of the dragView. The idea is that
672 // the visual center represents the user's interpretation of where the item is, and hence
673 // is the appropriate point to use when determining drop location.
674 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
675 DragView dragView, float[] recycle) {
676 float res[];
677 if (recycle == null) {
678 res = new float[2];
679 } else {
680 res = recycle;
681 }
682
683 // These represent the visual top and left of drag view if a dragRect was provided.
684 // If a dragRect was not provided, then they correspond to the actual view left and
685 // top, as the dragRect is in that case taken to be the entire dragView.
686 // R.dimen.dragViewOffsetY.
687 int left = x - xOffset;
688 int top = y - yOffset;
689
690 // In order to find the visual center, we shift by half the dragRect
691 res[0] = left + dragView.getDragRegion().width() / 2;
692 res[1] = top + dragView.getDragRegion().height() / 2;
693
694 return res;
695 }
696
697 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
698 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700699 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700700 }
701 };
702
Adam Cohen95bb8002011-07-03 23:40:28 -0700703 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700704 mLauncher.closeFolder();
705 mCurrentDragInfo = null;
706 mCurrentDragView = null;
707 mSuppressOnAdd = false;
708 mRearrangeOnClose = true;
709 }
710
Adam Cohencb3382b2011-05-24 14:07:08 -0700711 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700712 // Exiting folder; stop the auto scroller.
Alan Viverette4cda5b72013-08-28 17:53:41 -0700713 mAutoScrollHelper.setEnabled(false);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700714 // We only close the folder if this is a true drag exit, ie. not because
715 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700716 if (!d.dragComplete) {
717 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
718 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
719 }
720 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700721 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700722 }
723
Michael Jurka1e2f4652013-07-08 18:03:46 -0700724 public void onDropCompleted(final View target, final DragObject d,
725 final boolean isFlingToDelete, final boolean success) {
726 if (mDeferDropAfterUninstall) {
Michael Jurkaf3007582013-08-21 14:33:57 +0200727 Log.d(TAG, "Deferred handling drop because waiting for uninstall.");
Michael Jurka1e2f4652013-07-08 18:03:46 -0700728 mDeferredAction = new Runnable() {
729 public void run() {
730 onDropCompleted(target, d, isFlingToDelete, success);
731 mDeferredAction = null;
732 }
733 };
734 return;
735 }
736
737 boolean beingCalledAfterUninstall = mDeferredAction != null;
738 boolean successfulDrop =
739 success && (!beingCalledAfterUninstall || mUninstallSuccessful);
Winson Chung5f8afe62013-08-12 16:19:28 -0700740
Michael Jurka1e2f4652013-07-08 18:03:46 -0700741 if (successfulDrop) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700742 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700743 replaceFolderWithFinalItem();
744 }
745 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700746 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700747 // The drag failed, we need to return the item to the folder
748 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700749 }
750
751 if (target != this) {
752 if (mOnExitAlarm.alarmPending()) {
753 mOnExitAlarm.cancelAlarm();
Michael Jurka54554252013-08-01 12:52:23 +0200754 if (!successfulDrop) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700755 mSuppressFolderDeletion = true;
756 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700757 completeDragExit();
758 }
759 }
Winson Chung5f8afe62013-08-12 16:19:28 -0700760
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700761 mDeleteFolderOnDropCompleted = false;
762 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700763 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700764 mCurrentDragInfo = null;
765 mCurrentDragView = null;
766 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700767
768 // Reordering may have occured, and we need to save the new item locations. We do this once
769 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700770 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700771 }
772
Michael Jurka1e2f4652013-07-08 18:03:46 -0700773 public void deferCompleteDropAfterUninstallActivity() {
774 mDeferDropAfterUninstall = true;
775 }
776
777 public void onUninstallActivityReturned(boolean success) {
778 mDeferDropAfterUninstall = false;
779 mUninstallSuccessful = success;
780 if (mDeferredAction != null) {
781 mDeferredAction.run();
782 }
783 }
784
Winson Chunga48487a2012-03-20 16:19:37 -0700785 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800786 public boolean supportsFlingToDelete() {
787 return true;
788 }
789
Winson Chunga48487a2012-03-20 16:19:37 -0700790 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
791 // Do nothing
792 }
793
794 @Override
795 public void onFlingToDeleteCompleted() {
796 // Do nothing
797 }
798
Adam Cohen4045eb72011-10-06 11:44:26 -0700799 private void updateItemLocationsInDatabase() {
800 ArrayList<View> list = getItemsInReadingOrder();
801 for (int i = 0; i < list.size(); i++) {
802 View v = list.get(i);
803 ItemInfo info = (ItemInfo) v.getTag();
804 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
805 info.cellX, info.cellY);
806 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700807 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700808
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700809 private void updateItemLocationsInDatabaseBatch() {
810 ArrayList<View> list = getItemsInReadingOrder();
811 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
812 for (int i = 0; i < list.size(); i++) {
813 View v = list.get(i);
814 ItemInfo info = (ItemInfo) v.getTag();
815 items.add(info);
816 }
817
818 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
819 }
820
Adam Cohene25af792013-06-06 23:08:25 -0700821 public void addItemLocationsInDatabase() {
822 ArrayList<View> list = getItemsInReadingOrder();
823 for (int i = 0; i < list.size(); i++) {
824 View v = list.get(i);
825 ItemInfo info = (ItemInfo) v.getTag();
826 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
827 info.cellX, info.cellY, false);
828 }
829 }
830
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700831 public void notifyDrop() {
832 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700833 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700834 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700835 }
836
837 public boolean isDropEnabled() {
838 return true;
839 }
840
Adam Cohen4045eb72011-10-06 11:44:26 -0700841 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700842 ArrayList<View> list = getItemsInReadingOrder();
843
844 int countX = mContent.getCountX();
845 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700846 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700847
Adam Cohen7c693212011-05-18 15:26:57 -0700848 while (!done) {
849 int oldCountX = countX;
850 int oldCountY = countY;
851 if (countX * countY < count) {
852 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800853 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700854 countX++;
855 } else if (countY < mMaxCountY) {
856 countY++;
857 }
858 if (countY == 0) countY++;
859 } else if ((countY - 1) * countX >= count && countY >= countX) {
860 countY = Math.max(0, countY - 1);
861 } else if ((countX - 1) * countY >= count) {
862 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700863 }
Adam Cohen7c693212011-05-18 15:26:57 -0700864 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700865 }
Adam Cohen7c693212011-05-18 15:26:57 -0700866 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700867 arrangeChildren(list);
868 }
869
870 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800871 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700872 }
873
874 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700875 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700876
Winson Chung892c74d2013-08-22 16:15:50 -0700877 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700878 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700879 int height = getFolderHeight();
Adam Cohen2801caf2011-05-13 20:57:39 -0700880
Adam Cohen307fe232012-08-16 17:55:58 -0700881 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700882
Winson Chungaf40f202013-09-18 18:26:31 -0700883 LauncherAppState app = LauncherAppState.getInstance();
884 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
885
Adam Cohen307fe232012-08-16 17:55:58 -0700886 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
887 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700888 int centeredLeft = centerX - width / 2;
889 int centeredTop = centerY - height / 2;
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800890 int currentPage = mLauncher.getWorkspace().getCurrentPage();
891 // In case the workspace is scrolling, we need to use the final scroll to compute
892 // the folders bounds.
893 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700894 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800895 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700896 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700897 Rect bounds = new Rect();
898 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800899 // We reset the workspaces scroll
900 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700901
Adam Cohen35e7e642011-07-17 14:47:18 -0700902 // We need to bound the folder to the currently visible CellLayoutChildren
903 int left = Math.min(Math.max(bounds.left, centeredLeft),
904 bounds.left + bounds.width() - width);
905 int top = Math.min(Math.max(bounds.top, centeredTop),
906 bounds.top + bounds.height() - height);
Winson Chungaf40f202013-09-18 18:26:31 -0700907 if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) {
908 // Center the folder if it is full (on phones only)
909 left = (grid.availableWidthPx - width) / 2;
910 } else if (width >= bounds.width()) {
911 // If the folder doesn't fit within the bounds, center it about the desired bounds
Adam Cohen35e7e642011-07-17 14:47:18 -0700912 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700913 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700914 if (height >= bounds.height()) {
915 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700916 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700917
918 int folderPivotX = width / 2 + (centeredLeft - left);
919 int folderPivotY = height / 2 + (centeredTop - top);
920 setPivotX(folderPivotX);
921 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700922 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700923 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700924 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700925 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700926
Adam Cohen662b5982011-12-13 17:45:21 -0800927 lp.width = width;
928 lp.height = height;
929 lp.x = left;
930 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700931 }
932
Adam Cohen268c4752012-06-06 17:47:33 -0700933 float getPivotXForIconAnimation() {
934 return mFolderIconPivotX;
935 }
936 float getPivotYForIconAnimation() {
937 return mFolderIconPivotY;
938 }
939
Adam Cohen2801caf2011-05-13 20:57:39 -0700940 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700941 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700942
Adam Cohen8e776a62011-06-28 18:10:06 -0700943 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700944 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700945 lp = new DragLayer.LayoutParams(0, 0);
946 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700947 setLayoutParams(lp);
948 }
949 centerAboutIcon();
950 }
951
Winson Chung892c74d2013-08-22 16:15:50 -0700952 private int getContentAreaHeight() {
953 LauncherAppState app = LauncherAppState.getInstance();
954 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
955 Rect workspacePadding = grid.getWorkspacePadding(grid.isLandscape ?
956 CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
957 int maxContentAreaHeight = grid.availableHeightPx -
958 4 * grid.edgeMarginPx -
959 workspacePadding.top - workspacePadding.bottom -
960 getPaddingTop() - getPaddingBottom() -
961 mFolderNameHeight;
962 return Math.min(maxContentAreaHeight,
963 mContent.getDesiredHeight());
964 }
965
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700966 private int getFolderHeight() {
Winson Chung892c74d2013-08-22 16:15:50 -0700967 int height = getPaddingTop() + getPaddingBottom()
968 + getContentAreaHeight() + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700969 return height;
970 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700971
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700972 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700973 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
974 int height = getFolderHeight();
975 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
976 MeasureSpec.EXACTLY);
Winson Chung892c74d2013-08-22 16:15:50 -0700977 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(getContentAreaHeight(),
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700978 MeasureSpec.EXACTLY);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700979 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
980 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
981 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -0700982 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
983 setMeasuredDimension(width, height);
984 }
985
Adam Cohen2801caf2011-05-13 20:57:39 -0700986 private void arrangeChildren(ArrayList<View> list) {
987 int[] vacant = new int[2];
988 if (list == null) {
989 list = getItemsInReadingOrder();
990 }
991 mContent.removeAllViews();
992
993 for (int i = 0; i < list.size(); i++) {
994 View v = list.get(i);
995 mContent.getVacantCell(vacant, 1, 1);
996 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
997 lp.cellX = vacant[0];
998 lp.cellY = vacant[1];
999 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -07001000 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
1001 info.cellX = vacant[0];
1002 info.cellY = vacant[1];
1003 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
1004 info.cellX, info.cellY);
1005 }
Adam Cohen2801caf2011-05-13 20:57:39 -07001006 boolean insert = false;
1007 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1008 }
Adam Cohen7c693212011-05-18 15:26:57 -07001009 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001010 }
1011
Adam Cohena9cf38f2011-05-02 15:36:58 -07001012 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001013 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001014 }
1015
1016 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001017 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001018 }
1019
Adam Cohen2801caf2011-05-13 20:57:39 -07001020 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001021 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001022 if (parent != null) {
1023 parent.removeView(this);
1024 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001025 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001026 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001027 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001028
Adam Cohen2801caf2011-05-13 20:57:39 -07001029 if (mRearrangeOnClose) {
1030 setupContentForNumItems(getItemCount());
1031 mRearrangeOnClose = false;
1032 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001033 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001034 if (!mDragInProgress && !mSuppressFolderDeletion) {
1035 replaceFolderWithFinalItem();
1036 } else if (mDragInProgress) {
1037 mDeleteFolderOnDropCompleted = true;
1038 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001039 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001040 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001041 }
1042
1043 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001044 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001045 Runnable onCompleteRunnable = new Runnable() {
1046 @Override
1047 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001048 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001049
Adam Cohenc5e63f32012-07-12 16:16:57 -07001050 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001051 // Move the item from the folder to the workspace, in the position of the folder
1052 if (getItemCount() == 1) {
1053 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001054 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001055 finalItem);
1056 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001057 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001058 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001059 if (getItemCount() <= 1) {
1060 // Remove the folder
1061 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1062 cellLayout.removeView(mFolderIcon);
1063 if (mFolderIcon instanceof DropTarget) {
1064 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1065 }
1066 mLauncher.removeFolder(mInfo);
1067 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001068 // We add the child after removing the folder to prevent both from existing at
Winson Chung0e6a7132013-08-23 12:55:10 -07001069 // the same time in the CellLayout. We need to add the new item with addInScreenFromBind()
1070 // to ensure that hotseat items are placed correctly.
Adam Cohenc5e63f32012-07-12 16:16:57 -07001071 if (child != null) {
Winson Chung0e6a7132013-08-23 12:55:10 -07001072 mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001073 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1074 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001075 }
1076 };
1077 View finalChild = getItemAt(0);
1078 if (finalChild != null) {
1079 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001080 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001081 mDestroyed = true;
1082 }
1083
1084 boolean isDestroyed() {
1085 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001086 }
1087
Adam Cohenac56cff2011-09-28 20:45:37 -07001088 // This method keeps track of the last item in the folder for the purposes
1089 // of keyboard focus
1090 private void updateTextViewFocus() {
1091 View lastChild = getItemAt(getItemCount() - 1);
1092 getItemAt(getItemCount() - 1);
1093 if (lastChild != null) {
1094 mFolderName.setNextFocusDownId(lastChild.getId());
1095 mFolderName.setNextFocusRightId(lastChild.getId());
1096 mFolderName.setNextFocusLeftId(lastChild.getId());
1097 mFolderName.setNextFocusUpId(lastChild.getId());
1098 }
1099 }
1100
Adam Cohenbfbfd262011-06-13 16:55:12 -07001101 public void onDrop(DragObject d) {
1102 ShortcutInfo item;
Michael Jurkaeadbfc52013-09-04 00:45:37 +02001103 if (d.dragInfo instanceof AppInfo) {
Adam Cohenbfbfd262011-06-13 16:55:12 -07001104 // Came from all apps -- make a copy
Michael Jurkaeadbfc52013-09-04 00:45:37 +02001105 item = ((AppInfo) d.dragInfo).makeShortcut();
Adam Cohenbfbfd262011-06-13 16:55:12 -07001106 item.spanX = 1;
1107 item.spanY = 1;
1108 } else {
1109 item = (ShortcutInfo) d.dragInfo;
1110 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001111 // Dragged from self onto self, currently this is the only path possible, however
1112 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001113 if (item == mCurrentDragInfo) {
1114 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1115 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1116 si.cellX = lp.cellX = mEmptyCell[0];
1117 si.cellX = lp.cellY = mEmptyCell[1];
1118 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001119 if (d.dragView.hasDrawn()) {
1120 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1121 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001122 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001123 mCurrentDragView.setVisibility(VISIBLE);
1124 }
Adam Cohene9166b22011-07-08 17:11:11 -07001125 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001126 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001127 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001128 }
1129 mInfo.add(item);
1130 }
1131
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001132 // This is used so the item doesn't immediately appear in the folder when added. In one case
1133 // we need to create the illusion that the item isn't added back to the folder yet, to
1134 // to correspond to the animation of the icon back into the folder. This is
1135 public void hideItem(ShortcutInfo info) {
1136 View v = getViewForInfo(info);
1137 v.setVisibility(INVISIBLE);
1138 }
1139 public void showItem(ShortcutInfo info) {
1140 View v = getViewForInfo(info);
1141 v.setVisibility(VISIBLE);
1142 }
1143
Adam Cohenbfbfd262011-06-13 16:55:12 -07001144 public void onAdd(ShortcutInfo item) {
1145 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001146 // If the item was dropped onto this open folder, we have done the work associated
1147 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001148 if (mSuppressOnAdd) return;
1149 if (!findAndSetEmptyCells(item)) {
1150 // The current layout is full, can we expand it?
1151 setupContentForNumItems(getItemCount() + 1);
1152 findAndSetEmptyCells(item);
1153 }
1154 createAndAddShortcut(item);
1155 LauncherModel.addOrMoveItemInDatabase(
1156 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1157 }
1158
Adam Cohena9cf38f2011-05-02 15:36:58 -07001159 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001160 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001161 // If this item is being dragged from this open folder, we have already handled
1162 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001163 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001164 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001165 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001166 if (mState == STATE_ANIMATING) {
1167 mRearrangeOnClose = true;
1168 } else {
1169 setupContentForNumItems(getItemCount());
1170 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001171 if (getItemCount() <= 1) {
1172 replaceFolderWithFinalItem();
1173 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001174 }
Adam Cohen7c693212011-05-18 15:26:57 -07001175
Adam Cohendf1e4e82011-06-24 15:57:39 -07001176 private View getViewForInfo(ShortcutInfo item) {
1177 for (int j = 0; j < mContent.getCountY(); j++) {
1178 for (int i = 0; i < mContent.getCountX(); i++) {
1179 View v = mContent.getChildAt(i, j);
1180 if (v.getTag() == item) {
1181 return v;
1182 }
1183 }
1184 }
1185 return null;
1186 }
1187
Adam Cohen76078c42011-06-09 15:06:52 -07001188 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001189 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001190 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001191
Adam Cohen76fc0852011-06-17 13:26:23 -07001192 public void onTitleChanged(CharSequence title) {
1193 }
Adam Cohen76078c42011-06-09 15:06:52 -07001194
Adam Cohen7c693212011-05-18 15:26:57 -07001195 public ArrayList<View> getItemsInReadingOrder() {
1196 if (mItemsInvalidated) {
1197 mItemsInReadingOrder.clear();
1198 for (int j = 0; j < mContent.getCountY(); j++) {
1199 for (int i = 0; i < mContent.getCountX(); i++) {
1200 View v = mContent.getChildAt(i, j);
1201 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001202 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001203 }
1204 }
1205 }
1206 mItemsInvalidated = false;
1207 }
1208 return mItemsInReadingOrder;
1209 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001210
1211 public void getLocationInDragLayer(int[] loc) {
1212 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1213 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001214
1215 public void onFocusChange(View v, boolean hasFocus) {
1216 if (v == mFolderName && hasFocus) {
1217 startEditingFolderName();
1218 }
1219 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001220
1221 @Override
1222 public void getHitRectRelativeToDragLayer(Rect outRect) {
1223 getHitRect(outRect);
1224 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001225}