blob: 3ff4fa323c8148c7ec3315f2993123b0eda3295c [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;
Adam Cohen3bf84d32012-05-07 20:17:14 -070032import android.util.Log;
Adam Cohen76fc0852011-06-17 13:26:23 -070033import android.view.ActionMode;
34import android.view.KeyEvent;
Adam Cohendf2cc412011-04-27 16:56:57 -070035import android.view.LayoutInflater;
Adam Cohen76fc0852011-06-17 13:26:23 -070036import android.view.Menu;
37import android.view.MenuItem;
Adam Cohen0c872ba2011-05-05 10:34:16 -070038import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.view.View;
Adam Cohen3371da02011-10-25 21:38:29 -070040import android.view.accessibility.AccessibilityEvent;
41import android.view.accessibility.AccessibilityManager;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -070042import android.view.animation.AccelerateInterpolator;
43import android.view.animation.Interpolator;
Adam Cohen76fc0852011-06-17 13:26:23 -070044import android.view.inputmethod.EditorInfo;
45import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070047import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070048import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049
Daniel Sandler325dc232013-06-05 22:57:57 -040050import com.android.launcher3.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080051
Adam Cohenc0dcf592011-06-01 15:30:43 -070052import java.util.ArrayList;
Adam Cohen3bf84d32012-05-07 20:17:14 -070053import java.util.Collections;
54import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -070055
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056/**
57 * Represents a set of icons chosen by the user or generated by the system.
58 */
Adam Cohen8dfcba42011-07-07 16:38:18 -070059public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
Adam Cohenea0818d2011-09-30 20:06:58 -070060 View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
61 View.OnFocusChangeListener {
Adam Cohendf2cc412011-04-27 16:56:57 -070062 private static final String TAG = "Launcher.Folder";
63
Adam Cohen4eac29a2011-07-11 17:53:37 -070064 protected DragController mDragController;
65 protected Launcher mLauncher;
66 protected FolderInfo mInfo;
67
Adam Cohendf2cc412011-04-27 16:56:57 -070068 static final int STATE_NONE = -1;
69 static final int STATE_SMALL = 0;
70 static final int STATE_ANIMATING = 1;
71 static final int STATE_OPEN = 2;
72
73 private int mExpandDuration;
74 protected CellLayout mContent;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070075 private ScrollView mScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070076 private final LayoutInflater mInflater;
77 private final IconCache mIconCache;
78 private int mState = STATE_NONE;
Adam Cohenbfbfd262011-06-13 16:55:12 -070079 private static final int REORDER_ANIMATION_DURATION = 230;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070080 private static final int REORDER_DELAY = 250;
Adam Cohenbfbfd262011-06-13 16:55:12 -070081 private static final int ON_EXIT_CLOSE_DELAY = 800;
Adam Cohen2801caf2011-05-13 20:57:39 -070082 private boolean mRearrangeOnClose = false;
83 private FolderIcon mFolderIcon;
84 private int mMaxCountX;
85 private int mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070086 private int mMaxVisibleX;
87 private int mMaxVisibleY;
88 private int mMaxContentAreaHeight = 0;
Adam Cohen78dc83e2011-11-15 17:10:00 -080089 private int mMaxNumItems;
Adam Cohen7c693212011-05-18 15:26:57 -070090 private ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
Adam Cohenbadf71e2011-05-26 19:08:29 -070091 private Drawable mIconDrawable;
Adam Cohen7c693212011-05-18 15:26:57 -070092 boolean mItemsInvalidated = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -070093 private ShortcutInfo mCurrentDragInfo;
94 private View mCurrentDragView;
95 boolean mSuppressOnAdd = false;
96 private int[] mTargetCell = new int[2];
97 private int[] mPreviousTargetCell = new int[2];
98 private int[] mEmptyCell = new int[2];
99 private Alarm mReorderAlarm = new Alarm();
100 private Alarm mOnExitAlarm = new Alarm();
Adam Cohen76fc0852011-06-17 13:26:23 -0700101 private int mFolderNameHeight;
Adam Cohen8e776a62011-06-28 18:10:06 -0700102 private Rect mTempRect = new Rect();
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700103 private boolean mDragInProgress = false;
104 private boolean mDeleteFolderOnDropCompleted = false;
105 private boolean mSuppressFolderDeletion = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700106 private boolean mItemAddedBackToSelfViaIcon = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700107 FolderEditText mFolderName;
Adam Cohen268c4752012-06-06 17:47:33 -0700108 private float mFolderIconPivotX;
109 private float mFolderIconPivotY;
Adam Cohen228da5a2011-07-27 22:23:47 -0700110
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700111 private static final int SCROLL_CUT_OFF_AMOUNT = 60;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -0700112
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700113 private static final float MAX_SCROLL_VELOCITY = 1500f;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700114
Adam Cohen76fc0852011-06-17 13:26:23 -0700115 private boolean mIsEditingName = false;
116 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700117
Adam Cohena65beee2011-06-27 21:32:23 -0700118 private static String sDefaultFolderName;
119 private static String sHintText;
120
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700121 private int DRAG_MODE_NONE = 0;
122 private int DRAG_MODE_REORDER = 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700123 private int mDragMode = DRAG_MODE_NONE;
124
Adam Cohenfb91f302012-06-11 15:45:18 -0700125 private boolean mDestroyed;
126
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700127 private AutoScroller mAutoScroller;
128
Michael Jurka1e2f4652013-07-08 18:03:46 -0700129 private Runnable mDeferredAction;
130 private boolean mDeferDropAfterUninstall;
131 private boolean mUninstallSuccessful;
132
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 /**
134 * Used to inflate the Workspace from XML.
135 *
136 * @param context The application's context.
137 * @param attrs The attribtues set containing the Workspace's customization values.
138 */
139 public Folder(Context context, AttributeSet attrs) {
140 super(context, attrs);
141 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700142 mInflater = LayoutInflater.from(context);
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400143 mIconCache = (LauncherAppState.getInstance()).getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800144
145 Resources res = getResources();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700146 mMaxCountX = mMaxVisibleX = res.getInteger(R.integer.folder_max_count_x);
147 mMaxCountY = mMaxVisibleY = res.getInteger(R.integer.folder_max_count_y);
Adam Cohen78dc83e2011-11-15 17:10:00 -0800148 mMaxNumItems = res.getInteger(R.integer.folder_max_num_items);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700149
150 if (mMaxCountY == -1) {
151 // -2 indicates unlimited
152 mMaxCountY = Integer.MAX_VALUE;
153 mMaxVisibleX = LauncherModel.getCellCountX() + 1;
154 }
155 if (mMaxNumItems == -1) {
156 // -2 indicates unlimited
157 mMaxNumItems = Integer.MAX_VALUE;
158 mMaxVisibleY = LauncherModel.getCellCountY() + 1;
159 }
160 if (mMaxCountX == 0) {
161 mMaxCountX = mMaxVisibleX = LauncherModel.getCellCountX();
162 mMaxVisibleX++;
163 }
164 if (mMaxCountY == 0) {
165 mMaxCountY = mMaxVisibleY = LauncherModel.getCellCountY();
166 mMaxVisibleY++;
167 }
168 if (mMaxNumItems == 0) {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800169 mMaxNumItems = mMaxCountX * mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700170 if (mMaxNumItems < 0) {
171 mMaxNumItems = Integer.MAX_VALUE;
172 }
Adam Cohen78dc83e2011-11-15 17:10:00 -0800173 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700174
175 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700176 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700177
Adam Cohen76fc0852011-06-17 13:26:23 -0700178 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700179
180 if (sDefaultFolderName == null) {
181 sDefaultFolderName = res.getString(R.string.folder_name);
182 }
Adam Cohena65beee2011-06-27 21:32:23 -0700183 if (sHintText == null) {
184 sHintText = res.getString(R.string.folder_hint_text);
185 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700186 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700187 // We need this view to be focusable in touch mode so that when text editing of the folder
188 // name is complete, we have something to focus on, thus hiding the cursor and giving
189 // reliable behvior when clicking the text field (since it will always gain focus on click).
190 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 }
192
193 @Override
194 protected void onFinishInflate() {
195 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700196 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700197 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700198
199 // Beyond this height, the area scrolls
200 mContent.setGridSize(mMaxVisibleX, mMaxVisibleY);
201 mMaxContentAreaHeight = mContent.getDesiredHeight() - SCROLL_CUT_OFF_AMOUNT;
202
Adam Cohen2801caf2011-05-13 20:57:39 -0700203 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700204 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700205 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700206 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
207 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700208 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700209
210 // We find out how tall the text view wants to be (it is set to wrap_content), so that
211 // we can allocate the appropriate amount of space for it.
212 int measureSpec = MeasureSpec.UNSPECIFIED;
213 mFolderName.measure(measureSpec, measureSpec);
214 mFolderNameHeight = mFolderName.getMeasuredHeight();
215
216 // We disable action mode for now since it messes up the view on phones
217 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700218 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700219 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700220 mFolderName.setInputType(mFolderName.getInputType() |
221 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700222 mAutoScroller = new AutoScroller(mScrollView);
223 mAutoScroller.setMaximumVelocityAbsolute(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
224 mAutoScroller.setExtendsBeyondEdges(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700226
Adam Cohen76fc0852011-06-17 13:26:23 -0700227 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
228 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
229 return false;
230 }
231
232 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
233 return false;
234 }
235
236 public void onDestroyActionMode(ActionMode mode) {
237 }
238
239 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
240 return false;
241 }
242 };
243
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700245 Object tag = v.getTag();
246 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700247 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700248 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 }
250
251 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700252 // Return if global dragging is not enabled
253 if (!mLauncher.isDraggingEnabled()) return true;
254
Adam Cohendf2cc412011-04-27 16:56:57 -0700255 Object tag = v.getTag();
256 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700257 ShortcutInfo item = (ShortcutInfo) tag;
258 if (!v.isInTouchMode()) {
259 return false;
260 }
261
Winson Chung7d7541e2011-09-16 20:14:36 -0700262 mLauncher.dismissFolderCling(null);
263
Adam Cohendf2cc412011-04-27 16:56:57 -0700264 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700265 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700266 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700267
268 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700269 mEmptyCell[0] = item.cellX;
270 mEmptyCell[1] = item.cellY;
271 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700272
273 mContent.removeView(mCurrentDragView);
274 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700275 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700276 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700277 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278 return true;
279 }
280
Adam Cohen76fc0852011-06-17 13:26:23 -0700281 public boolean isEditingName() {
282 return mIsEditingName;
283 }
284
285 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700286 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700287 mIsEditingName = true;
288 }
289
290 public void dismissEditingName() {
291 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
292 doneEditingFolderName(true);
293 }
294
295 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700296 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700297 // Convert to a string here to ensure that no other state associated with the text field
298 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700299 String newTitle = mFolderName.getText().toString();
300 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700301 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700302
Adam Cohen3371da02011-10-25 21:38:29 -0700303 if (commit) {
304 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700305 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700306 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700307 // In order to clear the focus from the text field, we set the focus on ourself. This
308 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
309 requestFocus();
310
Adam Cohene601a432011-07-26 21:51:30 -0700311 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700312 mIsEditingName = false;
313 }
314
315 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
316 if (actionId == EditorInfo.IME_ACTION_DONE) {
317 dismissEditingName();
318 return true;
319 }
320 return false;
321 }
322
323 public View getEditTextRegion() {
324 return mFolderName;
325 }
326
Adam Cohenbadf71e2011-05-26 19:08:29 -0700327 public Drawable getDragDrawable() {
328 return mIconDrawable;
329 }
330
Adam Cohen0c872ba2011-05-05 10:34:16 -0700331 /**
332 * We need to handle touch events to prevent them from falling through to the workspace below.
333 */
334 @Override
335 public boolean onTouchEvent(MotionEvent ev) {
336 return true;
337 }
338
Joe Onorato00acb122009-08-04 16:04:30 -0400339 public void setDragController(DragController dragController) {
340 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 }
342
Adam Cohen2801caf2011-05-13 20:57:39 -0700343 void setFolderIcon(FolderIcon icon) {
344 mFolderIcon = icon;
345 }
346
Adam Cohen3371da02011-10-25 21:38:29 -0700347 @Override
348 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
349 // When the folder gets focus, we don't want to announce the list of items.
350 return true;
351 }
352
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800353 /**
354 * @return the FolderInfo object associated with this folder
355 */
356 FolderInfo getInfo() {
357 return mInfo;
358 }
359
Adam Cohen3bf84d32012-05-07 20:17:14 -0700360 private class GridComparator implements Comparator<ShortcutInfo> {
361 int mNumCols;
362 public GridComparator(int numCols) {
363 mNumCols = numCols;
364 }
365
366 @Override
367 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
368 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
369 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
370 return (lhIndex - rhIndex);
371 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700372 }
373
374 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
375 int maxX = 0;
376 int count = items.size();
377 for (int i = 0; i < count; i++) {
378 ShortcutInfo item = items.get(i);
379 if (item.cellX > maxX) {
380 maxX = item.cellX;
381 }
382 }
Adam Cohen691a5792012-05-11 14:27:30 -0700383
384 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700385 Collections.sort(items, gridComparator);
386 final int countX = mContent.getCountX();
387 for (int i = 0; i < count; i++) {
388 int x = i % countX;
389 int y = i / countX;
390 ShortcutInfo item = items.get(i);
391 item.cellX = x;
392 item.cellY = y;
393 }
394 }
395
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800396 void bind(FolderInfo info) {
397 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700398 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700399 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700400 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700401 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700402 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700403 for (int i = 0; i < children.size(); i++) {
404 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700405 if (!createAndAddShortcut(child)) {
406 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700407 } else {
408 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700409 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700410 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700411
Adam Cohen0057bbc2011-08-12 18:30:51 -0700412 // We rearrange the items in case there are any empty gaps
413 setupContentForNumItems(count);
414
Adam Cohenc508b2d2011-06-28 14:41:44 -0700415 // If our folder has too many items we prune them from the list. This is an issue
416 // when upgrading from the old Folders implementation which could contain an unlimited
417 // number of items.
418 for (ShortcutInfo item: overflow) {
419 mInfo.remove(item);
420 LauncherModel.deleteItemFromDatabase(mLauncher, item);
421 }
422
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700423 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700424 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700425 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700426
Adam Cohenafb01ee2011-06-23 15:38:03 -0700427 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700428 mFolderName.setText(mInfo.title);
429 } else {
430 mFolderName.setText("");
431 }
Adam Cohen691a5792012-05-11 14:27:30 -0700432 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700433 }
434
435 /**
436 * Creates a new UserFolder, inflated from R.layout.user_folder.
437 *
438 * @param context The application's context.
439 *
440 * @return A new UserFolder.
441 */
442 static Folder fromXml(Context context) {
443 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
444 }
445
446 /**
447 * This method is intended to make the UserFolder to be visually identical in size and position
448 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
449 */
450 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700451 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800452 setScaleX(0.8f);
453 setScaleY(0.8f);
454 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700455 mState = STATE_SMALL;
456 }
457
458 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700459 positionAndSizeAsIcon();
460
Adam Cohen8e776a62011-06-28 18:10:06 -0700461 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700462 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800463 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
464 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
465 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200466 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700467 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800468
Adam Cohen2801caf2011-05-13 20:57:39 -0700469 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700470 @Override
471 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700472 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700473 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700474 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700475 mState = STATE_ANIMATING;
476 }
477 @Override
478 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700479 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700480 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700481 Cling cling = mLauncher.showFirstRunFoldersCling();
482 if (cling != null) {
483 cling.bringToFront();
484 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700485 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700486 }
487 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700488 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700489 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100490 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700491 }
492
Adam Cohen3371da02011-10-25 21:38:29 -0700493 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700494 AccessibilityManager accessibilityManager = (AccessibilityManager)
495 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
496 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700497 AccessibilityEvent event = AccessibilityEvent.obtain(type);
498 onInitializeAccessibilityEvent(event);
499 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700500 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700501 }
502 }
503
Adam Cohenac56cff2011-09-28 20:45:37 -0700504 private void setFocusOnFirstChild() {
505 View firstChild = mContent.getChildAt(0, 0);
506 if (firstChild != null) {
507 firstChild.requestFocus();
508 }
509 }
510
Adam Cohendf2cc412011-04-27 16:56:57 -0700511 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700512 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800513 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
514 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
515 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200516 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700517 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700518
Adam Cohen2801caf2011-05-13 20:57:39 -0700519 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700520 @Override
521 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700522 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700523 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700524 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700525 }
526 @Override
527 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700528 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700529 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700530 mState = STATE_ANIMATING;
531 }
532 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700533 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700534 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100535 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700536 }
537
538 void notifyDataSetChanged() {
539 // recreate all the children if the data set changes under us. We may want to do this more
540 // intelligently (ie just removing the views that should no longer exist)
541 mContent.removeAllViewsInLayout();
542 bind(mInfo);
543 }
544
Adam Cohencb3382b2011-05-24 14:07:08 -0700545 public boolean acceptDrop(DragObject d) {
546 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700547 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700548 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
549 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
550 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700551 }
552
Adam Cohendf2cc412011-04-27 16:56:57 -0700553 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
554 int[] emptyCell = new int[2];
555 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
556 item.cellX = emptyCell[0];
557 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700558 return true;
559 } else {
560 return false;
561 }
562 }
563
Adam Cohenc508b2d2011-06-28 14:41:44 -0700564 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700565 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700566 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700567 textView.setCompoundDrawablesWithIntrinsicBounds(null,
568 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
569 textView.setText(item.title);
570 textView.setTag(item);
571
572 textView.setOnClickListener(this);
573 textView.setOnLongClickListener(this);
574
Adam Cohenc508b2d2011-06-28 14:41:44 -0700575 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700576 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700577 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
578 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700579 // This shouldn't happen, log it.
580 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700581 if (!findAndSetEmptyCells(item)) {
582 return false;
583 }
584 }
585
Adam Cohendf2cc412011-04-27 16:56:57 -0700586 CellLayout.LayoutParams lp =
587 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
588 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700589 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700590 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700591 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700592 }
593
Adam Cohencb3382b2011-05-24 14:07:08 -0700594 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700595 mPreviousTargetCell[0] = -1;
596 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700597 mOnExitAlarm.cancelAlarm();
598 }
599
600 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
601 public void onAlarm(Alarm alarm) {
602 realTimeReorder(mEmptyCell, mTargetCell);
603 }
604 };
605
606 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
607 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
608 return true;
609 } else {
610 return false;
611 }
612 }
613
614 private void realTimeReorder(int[] empty, int[] target) {
615 boolean wrap;
616 int startX;
617 int endX;
618 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700619 int delay = 0;
620 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700621 if (readingOrderGreaterThan(target, empty)) {
622 wrap = empty[0] >= mContent.getCountX() - 1;
623 startY = wrap ? empty[1] + 1 : empty[1];
624 for (int y = startY; y <= target[1]; y++) {
625 startX = y == empty[1] ? empty[0] + 1 : 0;
626 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
627 for (int x = startX; x <= endX; x++) {
628 View v = mContent.getChildAt(x,y);
629 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800630 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700631 empty[0] = x;
632 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700633 delay += delayAmount;
634 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700635 }
636 }
637 }
638 } else {
639 wrap = empty[0] == 0;
640 startY = wrap ? empty[1] - 1 : empty[1];
641 for (int y = startY; y >= target[1]; y--) {
642 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
643 endX = y > target[1] ? 0 : target[0];
644 for (int x = startX; x >= endX; x--) {
645 View v = mContent.getChildAt(x,y);
646 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800647 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700648 empty[0] = x;
649 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700650 delay += delayAmount;
651 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700652 }
653 }
654 }
655 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700656 }
657
Adam Cohen2374abf2013-04-16 14:56:57 -0700658 public boolean isLayoutRtl() {
659 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
660 }
661
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700662 private Rect getDragObjectDrawingRect(View dragView, float[] r) {
663 final Rect drawingRect = mTempRect;
664 drawingRect.left = (int) r[0];
665 drawingRect.top = (int) r[1];
666 drawingRect.right = drawingRect.left + dragView.getMeasuredWidth();
667 drawingRect.bottom = drawingRect.top + dragView.getMeasuredHeight();
668 return drawingRect;
669 }
670
Adam Cohencb3382b2011-05-24 14:07:08 -0700671 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700672 int scrollOffset = mScrollView.getScrollY();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700673 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700674 r[0] -= getPaddingLeft();
675 r[1] -= getPaddingTop();
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700676 if (!mAutoScroller.onTouch(this, getDragObjectDrawingRect(d.dragView, r))) {
677 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1,
678 mTargetCell);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700679
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700680 if (isLayoutRtl()) {
681 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700682 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700683 if (mTargetCell[0] != mPreviousTargetCell[0]
684 || mTargetCell[1] != mPreviousTargetCell[1]) {
685 mReorderAlarm.cancelAlarm();
686 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
687 mReorderAlarm.setAlarm(REORDER_DELAY);
688 mPreviousTargetCell[0] = mTargetCell[0];
689 mPreviousTargetCell[1] = mTargetCell[1];
690 mDragMode = DRAG_MODE_REORDER;
691 } else {
692 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700693 }
Adam Cohen61a9a5c2013-08-14 13:32:04 -0700694 } else {
695 mReorderAlarm.cancelAlarm();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700696 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700697 }
698
Adam Cohenbfbfd262011-06-13 16:55:12 -0700699 // This is used to compute the visual center of the dragView. The idea is that
700 // the visual center represents the user's interpretation of where the item is, and hence
701 // is the appropriate point to use when determining drop location.
702 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
703 DragView dragView, float[] recycle) {
704 float res[];
705 if (recycle == null) {
706 res = new float[2];
707 } else {
708 res = recycle;
709 }
710
711 // These represent the visual top and left of drag view if a dragRect was provided.
712 // If a dragRect was not provided, then they correspond to the actual view left and
713 // top, as the dragRect is in that case taken to be the entire dragView.
714 // R.dimen.dragViewOffsetY.
715 int left = x - xOffset;
716 int top = y - yOffset;
717
718 // In order to find the visual center, we shift by half the dragRect
719 res[0] = left + dragView.getDragRegion().width() / 2;
720 res[1] = top + dragView.getDragRegion().height() / 2;
721
722 return res;
723 }
724
725 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
726 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700727 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700728 }
729 };
730
Adam Cohen95bb8002011-07-03 23:40:28 -0700731 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700732 mLauncher.closeFolder();
733 mCurrentDragInfo = null;
734 mCurrentDragView = null;
735 mSuppressOnAdd = false;
736 mRearrangeOnClose = true;
737 }
738
Adam Cohencb3382b2011-05-24 14:07:08 -0700739 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700740 // Exiting folder; stop the auto scroller.
741 mAutoScroller.stop();
742 // We only close the folder if this is a true drag exit, ie. not because
743 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700744 if (!d.dragComplete) {
745 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
746 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
747 }
748 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700749 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700750 }
751
Michael Jurka1e2f4652013-07-08 18:03:46 -0700752 public void onDropCompleted(final View target, final DragObject d,
753 final boolean isFlingToDelete, final boolean success) {
754 if (mDeferDropAfterUninstall) {
755 mDeferredAction = new Runnable() {
756 public void run() {
757 onDropCompleted(target, d, isFlingToDelete, success);
758 mDeferredAction = null;
759 }
760 };
761 return;
762 }
763
764 boolean beingCalledAfterUninstall = mDeferredAction != null;
765 boolean successfulDrop =
766 success && (!beingCalledAfterUninstall || mUninstallSuccessful);
767 if (successfulDrop) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700768 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700769 replaceFolderWithFinalItem();
770 }
771 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700772 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700773 // The drag failed, we need to return the item to the folder
774 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700775 }
776
777 if (target != this) {
778 if (mOnExitAlarm.alarmPending()) {
779 mOnExitAlarm.cancelAlarm();
Michael Jurka54554252013-08-01 12:52:23 +0200780 if (!successfulDrop) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700781 mSuppressFolderDeletion = true;
782 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700783 completeDragExit();
784 }
785 }
786 mDeleteFolderOnDropCompleted = false;
787 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700788 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700789 mCurrentDragInfo = null;
790 mCurrentDragView = null;
791 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700792
793 // Reordering may have occured, and we need to save the new item locations. We do this once
794 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700795 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700796 }
797
Michael Jurka1e2f4652013-07-08 18:03:46 -0700798 public void deferCompleteDropAfterUninstallActivity() {
799 mDeferDropAfterUninstall = true;
800 }
801
802 public void onUninstallActivityReturned(boolean success) {
803 mDeferDropAfterUninstall = false;
804 mUninstallSuccessful = success;
805 if (mDeferredAction != null) {
806 mDeferredAction.run();
807 }
808 }
809
Winson Chunga48487a2012-03-20 16:19:37 -0700810 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800811 public boolean supportsFlingToDelete() {
812 return true;
813 }
814
Winson Chunga48487a2012-03-20 16:19:37 -0700815 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
816 // Do nothing
817 }
818
819 @Override
820 public void onFlingToDeleteCompleted() {
821 // Do nothing
822 }
823
Adam Cohen4045eb72011-10-06 11:44:26 -0700824 private void updateItemLocationsInDatabase() {
825 ArrayList<View> list = getItemsInReadingOrder();
826 for (int i = 0; i < list.size(); i++) {
827 View v = list.get(i);
828 ItemInfo info = (ItemInfo) v.getTag();
829 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
830 info.cellX, info.cellY);
831 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700832 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700833
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700834 private void updateItemLocationsInDatabaseBatch() {
835 ArrayList<View> list = getItemsInReadingOrder();
836 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
837 for (int i = 0; i < list.size(); i++) {
838 View v = list.get(i);
839 ItemInfo info = (ItemInfo) v.getTag();
840 items.add(info);
841 }
842
843 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
844 }
845
Adam Cohene25af792013-06-06 23:08:25 -0700846 public void addItemLocationsInDatabase() {
847 ArrayList<View> list = getItemsInReadingOrder();
848 for (int i = 0; i < list.size(); i++) {
849 View v = list.get(i);
850 ItemInfo info = (ItemInfo) v.getTag();
851 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
852 info.cellX, info.cellY, false);
853 }
854 }
855
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700856 public void notifyDrop() {
857 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700858 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700859 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700860 }
861
862 public boolean isDropEnabled() {
863 return true;
864 }
865
Adam Cohen4045eb72011-10-06 11:44:26 -0700866 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700867 ArrayList<View> list = getItemsInReadingOrder();
868
869 int countX = mContent.getCountX();
870 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700871 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700872
Adam Cohen7c693212011-05-18 15:26:57 -0700873 while (!done) {
874 int oldCountX = countX;
875 int oldCountY = countY;
876 if (countX * countY < count) {
877 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800878 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700879 countX++;
880 } else if (countY < mMaxCountY) {
881 countY++;
882 }
883 if (countY == 0) countY++;
884 } else if ((countY - 1) * countX >= count && countY >= countX) {
885 countY = Math.max(0, countY - 1);
886 } else if ((countX - 1) * countY >= count) {
887 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700888 }
Adam Cohen7c693212011-05-18 15:26:57 -0700889 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700890 }
Adam Cohen7c693212011-05-18 15:26:57 -0700891 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700892 arrangeChildren(list);
893 }
894
895 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800896 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700897 }
898
899 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700900 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700901
902 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700903 int height = getFolderHeight();
Adam Cohen8e776a62011-06-28 18:10:06 -0700904 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700905
Adam Cohen307fe232012-08-16 17:55:58 -0700906 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700907
Adam Cohen307fe232012-08-16 17:55:58 -0700908 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
909 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700910 int centeredLeft = centerX - width / 2;
911 int centeredTop = centerY - height / 2;
912
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800913 int currentPage = mLauncher.getWorkspace().getCurrentPage();
914 // In case the workspace is scrolling, we need to use the final scroll to compute
915 // the folders bounds.
916 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700917 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800918 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700919 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700920 Rect bounds = new Rect();
921 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800922 // We reset the workspaces scroll
923 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700924
Adam Cohen35e7e642011-07-17 14:47:18 -0700925 // We need to bound the folder to the currently visible CellLayoutChildren
926 int left = Math.min(Math.max(bounds.left, centeredLeft),
927 bounds.left + bounds.width() - width);
928 int top = Math.min(Math.max(bounds.top, centeredTop),
929 bounds.top + bounds.height() - height);
930 // If the folder doesn't fit within the bounds, center it about the desired bounds
931 if (width >= bounds.width()) {
932 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700933 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700934 if (height >= bounds.height()) {
935 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700936 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700937
938 int folderPivotX = width / 2 + (centeredLeft - left);
939 int folderPivotY = height / 2 + (centeredTop - top);
940 setPivotX(folderPivotX);
941 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700942 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700943 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700944 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700945 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700946
Adam Cohen662b5982011-12-13 17:45:21 -0800947 lp.width = width;
948 lp.height = height;
949 lp.x = left;
950 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700951 }
952
Adam Cohen268c4752012-06-06 17:47:33 -0700953 float getPivotXForIconAnimation() {
954 return mFolderIconPivotX;
955 }
956 float getPivotYForIconAnimation() {
957 return mFolderIconPivotY;
958 }
959
Adam Cohen2801caf2011-05-13 20:57:39 -0700960 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700961 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700962
Adam Cohen8e776a62011-06-28 18:10:06 -0700963 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700964 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700965 lp = new DragLayer.LayoutParams(0, 0);
966 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700967 setLayoutParams(lp);
968 }
969 centerAboutIcon();
970 }
971
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700972 private int getFolderHeight() {
973 int contentAreaHeight = mContent.getDesiredHeight();
974 if (contentAreaHeight >= mMaxContentAreaHeight) {
975 // Subtract a bit so the user can see that it's scrollable.
976 contentAreaHeight = mMaxContentAreaHeight;
977 }
978 int height = getPaddingTop() + getPaddingBottom() + contentAreaHeight
Adam Cohenf4bb1cd2011-07-22 14:36:03 -0700979 + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700980 return height;
981 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700982
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700983 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohen234c4cd2011-07-17 21:03:04 -0700984
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700985 int contentAreaHeight = mContent.getDesiredHeight();
986 if (contentAreaHeight >= mMaxContentAreaHeight) {
987 // Subtract a bit so the user can see that it's scrollable.
988 contentAreaHeight = mMaxContentAreaHeight;
989 }
990
991 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
992 int height = getFolderHeight();
993 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
994 MeasureSpec.EXACTLY);
995 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentAreaHeight,
996 MeasureSpec.EXACTLY);
997
998 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
999 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
1000 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -07001001 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
1002 setMeasuredDimension(width, height);
1003 }
1004
Adam Cohen2801caf2011-05-13 20:57:39 -07001005 private void arrangeChildren(ArrayList<View> list) {
1006 int[] vacant = new int[2];
1007 if (list == null) {
1008 list = getItemsInReadingOrder();
1009 }
1010 mContent.removeAllViews();
1011
1012 for (int i = 0; i < list.size(); i++) {
1013 View v = list.get(i);
1014 mContent.getVacantCell(vacant, 1, 1);
1015 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
1016 lp.cellX = vacant[0];
1017 lp.cellY = vacant[1];
1018 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -07001019 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
1020 info.cellX = vacant[0];
1021 info.cellY = vacant[1];
1022 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
1023 info.cellX, info.cellY);
1024 }
Adam Cohen2801caf2011-05-13 20:57:39 -07001025 boolean insert = false;
1026 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1027 }
Adam Cohen7c693212011-05-18 15:26:57 -07001028 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001029 }
1030
Adam Cohena9cf38f2011-05-02 15:36:58 -07001031 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001032 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001033 }
1034
1035 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001036 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001037 }
1038
Adam Cohen2801caf2011-05-13 20:57:39 -07001039 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001040 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001041 if (parent != null) {
1042 parent.removeView(this);
1043 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001044 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001045 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001046 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001047
Adam Cohen2801caf2011-05-13 20:57:39 -07001048 if (mRearrangeOnClose) {
1049 setupContentForNumItems(getItemCount());
1050 mRearrangeOnClose = false;
1051 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001052 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001053 if (!mDragInProgress && !mSuppressFolderDeletion) {
1054 replaceFolderWithFinalItem();
1055 } else if (mDragInProgress) {
1056 mDeleteFolderOnDropCompleted = true;
1057 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001058 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001059 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001060 }
1061
1062 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001063 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001064 Runnable onCompleteRunnable = new Runnable() {
1065 @Override
1066 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001067 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001068
Adam Cohenc5e63f32012-07-12 16:16:57 -07001069 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001070 // Move the item from the folder to the workspace, in the position of the folder
1071 if (getItemCount() == 1) {
1072 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001073 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001074 finalItem);
1075 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001076 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001077 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001078 if (getItemCount() <= 1) {
1079 // Remove the folder
1080 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1081 cellLayout.removeView(mFolderIcon);
1082 if (mFolderIcon instanceof DropTarget) {
1083 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1084 }
1085 mLauncher.removeFolder(mInfo);
1086 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001087 // We add the child after removing the folder to prevent both from existing at
1088 // the same time in the CellLayout.
1089 if (child != null) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001090 mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001091 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1092 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001093 }
1094 };
1095 View finalChild = getItemAt(0);
1096 if (finalChild != null) {
1097 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001098 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001099 mDestroyed = true;
1100 }
1101
1102 boolean isDestroyed() {
1103 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001104 }
1105
Adam Cohenac56cff2011-09-28 20:45:37 -07001106 // This method keeps track of the last item in the folder for the purposes
1107 // of keyboard focus
1108 private void updateTextViewFocus() {
1109 View lastChild = getItemAt(getItemCount() - 1);
1110 getItemAt(getItemCount() - 1);
1111 if (lastChild != null) {
1112 mFolderName.setNextFocusDownId(lastChild.getId());
1113 mFolderName.setNextFocusRightId(lastChild.getId());
1114 mFolderName.setNextFocusLeftId(lastChild.getId());
1115 mFolderName.setNextFocusUpId(lastChild.getId());
1116 }
1117 }
1118
Adam Cohenbfbfd262011-06-13 16:55:12 -07001119 public void onDrop(DragObject d) {
1120 ShortcutInfo item;
1121 if (d.dragInfo instanceof ApplicationInfo) {
1122 // Came from all apps -- make a copy
1123 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1124 item.spanX = 1;
1125 item.spanY = 1;
1126 } else {
1127 item = (ShortcutInfo) d.dragInfo;
1128 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001129 // Dragged from self onto self, currently this is the only path possible, however
1130 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001131 if (item == mCurrentDragInfo) {
1132 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1133 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1134 si.cellX = lp.cellX = mEmptyCell[0];
1135 si.cellX = lp.cellY = mEmptyCell[1];
1136 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001137 if (d.dragView.hasDrawn()) {
1138 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1139 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001140 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001141 mCurrentDragView.setVisibility(VISIBLE);
1142 }
Adam Cohene9166b22011-07-08 17:11:11 -07001143 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001144 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001145 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001146 }
1147 mInfo.add(item);
1148 }
1149
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001150 // This is used so the item doesn't immediately appear in the folder when added. In one case
1151 // we need to create the illusion that the item isn't added back to the folder yet, to
1152 // to correspond to the animation of the icon back into the folder. This is
1153 public void hideItem(ShortcutInfo info) {
1154 View v = getViewForInfo(info);
1155 v.setVisibility(INVISIBLE);
1156 }
1157 public void showItem(ShortcutInfo info) {
1158 View v = getViewForInfo(info);
1159 v.setVisibility(VISIBLE);
1160 }
1161
Adam Cohenbfbfd262011-06-13 16:55:12 -07001162 public void onAdd(ShortcutInfo item) {
1163 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001164 // If the item was dropped onto this open folder, we have done the work associated
1165 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001166 if (mSuppressOnAdd) return;
1167 if (!findAndSetEmptyCells(item)) {
1168 // The current layout is full, can we expand it?
1169 setupContentForNumItems(getItemCount() + 1);
1170 findAndSetEmptyCells(item);
1171 }
1172 createAndAddShortcut(item);
1173 LauncherModel.addOrMoveItemInDatabase(
1174 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1175 }
1176
Adam Cohena9cf38f2011-05-02 15:36:58 -07001177 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001178 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001179 // If this item is being dragged from this open folder, we have already handled
1180 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001181 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001182 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001183 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001184 if (mState == STATE_ANIMATING) {
1185 mRearrangeOnClose = true;
1186 } else {
1187 setupContentForNumItems(getItemCount());
1188 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001189 if (getItemCount() <= 1) {
1190 replaceFolderWithFinalItem();
1191 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001192 }
Adam Cohen7c693212011-05-18 15:26:57 -07001193
Adam Cohendf1e4e82011-06-24 15:57:39 -07001194 private View getViewForInfo(ShortcutInfo item) {
1195 for (int j = 0; j < mContent.getCountY(); j++) {
1196 for (int i = 0; i < mContent.getCountX(); i++) {
1197 View v = mContent.getChildAt(i, j);
1198 if (v.getTag() == item) {
1199 return v;
1200 }
1201 }
1202 }
1203 return null;
1204 }
1205
Adam Cohen76078c42011-06-09 15:06:52 -07001206 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001207 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001208 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001209
Adam Cohen76fc0852011-06-17 13:26:23 -07001210 public void onTitleChanged(CharSequence title) {
1211 }
Adam Cohen76078c42011-06-09 15:06:52 -07001212
Adam Cohen7c693212011-05-18 15:26:57 -07001213 public ArrayList<View> getItemsInReadingOrder() {
1214 if (mItemsInvalidated) {
1215 mItemsInReadingOrder.clear();
1216 for (int j = 0; j < mContent.getCountY(); j++) {
1217 for (int i = 0; i < mContent.getCountX(); i++) {
1218 View v = mContent.getChildAt(i, j);
1219 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001220 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001221 }
1222 }
1223 }
1224 mItemsInvalidated = false;
1225 }
1226 return mItemsInReadingOrder;
1227 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001228
1229 public void getLocationInDragLayer(int[] loc) {
1230 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1231 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001232
1233 public void onFocusChange(View v, boolean hasFocus) {
1234 if (v == mFolderName && hasFocus) {
1235 startEditingFolderName();
1236 }
1237 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001238
1239 @Override
1240 public void getHitRectRelativeToDragLayer(Rect outRect) {
1241 getHitRect(outRect);
1242 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001243}