blob: 4de929725ef5ab67e8f199f32be8d1a378644e3c [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
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129 /**
130 * Used to inflate the Workspace from XML.
131 *
132 * @param context The application's context.
133 * @param attrs The attribtues set containing the Workspace's customization values.
134 */
135 public Folder(Context context, AttributeSet attrs) {
136 super(context, attrs);
137 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700138 mInflater = LayoutInflater.from(context);
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400139 mIconCache = (LauncherAppState.getInstance()).getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800140
141 Resources res = getResources();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700142 mMaxCountX = mMaxVisibleX = res.getInteger(R.integer.folder_max_count_x);
143 mMaxCountY = mMaxVisibleY = res.getInteger(R.integer.folder_max_count_y);
Adam Cohen78dc83e2011-11-15 17:10:00 -0800144 mMaxNumItems = res.getInteger(R.integer.folder_max_num_items);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700145
146 if (mMaxCountY == -1) {
147 // -2 indicates unlimited
148 mMaxCountY = Integer.MAX_VALUE;
149 mMaxVisibleX = LauncherModel.getCellCountX() + 1;
150 }
151 if (mMaxNumItems == -1) {
152 // -2 indicates unlimited
153 mMaxNumItems = Integer.MAX_VALUE;
154 mMaxVisibleY = LauncherModel.getCellCountY() + 1;
155 }
156 if (mMaxCountX == 0) {
157 mMaxCountX = mMaxVisibleX = LauncherModel.getCellCountX();
158 mMaxVisibleX++;
159 }
160 if (mMaxCountY == 0) {
161 mMaxCountY = mMaxVisibleY = LauncherModel.getCellCountY();
162 mMaxVisibleY++;
163 }
164 if (mMaxNumItems == 0) {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800165 mMaxNumItems = mMaxCountX * mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700166 if (mMaxNumItems < 0) {
167 mMaxNumItems = Integer.MAX_VALUE;
168 }
Adam Cohen78dc83e2011-11-15 17:10:00 -0800169 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700170
171 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700172 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700173
Adam Cohen76fc0852011-06-17 13:26:23 -0700174 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700175
176 if (sDefaultFolderName == null) {
177 sDefaultFolderName = res.getString(R.string.folder_name);
178 }
Adam Cohena65beee2011-06-27 21:32:23 -0700179 if (sHintText == null) {
180 sHintText = res.getString(R.string.folder_hint_text);
181 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700182 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700183 // We need this view to be focusable in touch mode so that when text editing of the folder
184 // name is complete, we have something to focus on, thus hiding the cursor and giving
185 // reliable behvior when clicking the text field (since it will always gain focus on click).
186 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 }
188
189 @Override
190 protected void onFinishInflate() {
191 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700192 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700193 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700194
195 // Beyond this height, the area scrolls
196 mContent.setGridSize(mMaxVisibleX, mMaxVisibleY);
197 mMaxContentAreaHeight = mContent.getDesiredHeight() - SCROLL_CUT_OFF_AMOUNT;
198
Adam Cohen2801caf2011-05-13 20:57:39 -0700199 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700200 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700201 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700202 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
203 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700204 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700205
206 // We find out how tall the text view wants to be (it is set to wrap_content), so that
207 // we can allocate the appropriate amount of space for it.
208 int measureSpec = MeasureSpec.UNSPECIFIED;
209 mFolderName.measure(measureSpec, measureSpec);
210 mFolderNameHeight = mFolderName.getMeasuredHeight();
211
212 // We disable action mode for now since it messes up the view on phones
213 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700214 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700215 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700216 mFolderName.setInputType(mFolderName.getInputType() |
217 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700218 mAutoScroller = new AutoScroller(mScrollView);
219 mAutoScroller.setMaximumVelocityAbsolute(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
220 mAutoScroller.setExtendsBeyondEdges(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700222
Adam Cohen76fc0852011-06-17 13:26:23 -0700223 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
224 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
225 return false;
226 }
227
228 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
229 return false;
230 }
231
232 public void onDestroyActionMode(ActionMode mode) {
233 }
234
235 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
236 return false;
237 }
238 };
239
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800240 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700241 Object tag = v.getTag();
242 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700243 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700244 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245 }
246
247 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700248 // Return if global dragging is not enabled
249 if (!mLauncher.isDraggingEnabled()) return true;
250
Adam Cohendf2cc412011-04-27 16:56:57 -0700251 Object tag = v.getTag();
252 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700253 ShortcutInfo item = (ShortcutInfo) tag;
254 if (!v.isInTouchMode()) {
255 return false;
256 }
257
Winson Chung7d7541e2011-09-16 20:14:36 -0700258 mLauncher.dismissFolderCling(null);
259
Adam Cohendf2cc412011-04-27 16:56:57 -0700260 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700261 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700262 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700263
264 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700265 mEmptyCell[0] = item.cellX;
266 mEmptyCell[1] = item.cellY;
267 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700268
269 mContent.removeView(mCurrentDragView);
270 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700271 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700272 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700273 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800274 return true;
275 }
276
Adam Cohen76fc0852011-06-17 13:26:23 -0700277 public boolean isEditingName() {
278 return mIsEditingName;
279 }
280
281 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700282 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700283 mIsEditingName = true;
284 }
285
286 public void dismissEditingName() {
287 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
288 doneEditingFolderName(true);
289 }
290
291 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700292 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700293 // Convert to a string here to ensure that no other state associated with the text field
294 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700295 String newTitle = mFolderName.getText().toString();
296 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700297 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700298
Adam Cohen3371da02011-10-25 21:38:29 -0700299 if (commit) {
300 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700301 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700302 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700303 // In order to clear the focus from the text field, we set the focus on ourself. This
304 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
305 requestFocus();
306
Adam Cohene601a432011-07-26 21:51:30 -0700307 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700308 mIsEditingName = false;
309 }
310
311 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
312 if (actionId == EditorInfo.IME_ACTION_DONE) {
313 dismissEditingName();
314 return true;
315 }
316 return false;
317 }
318
319 public View getEditTextRegion() {
320 return mFolderName;
321 }
322
Adam Cohenbadf71e2011-05-26 19:08:29 -0700323 public Drawable getDragDrawable() {
324 return mIconDrawable;
325 }
326
Adam Cohen0c872ba2011-05-05 10:34:16 -0700327 /**
328 * We need to handle touch events to prevent them from falling through to the workspace below.
329 */
330 @Override
331 public boolean onTouchEvent(MotionEvent ev) {
332 return true;
333 }
334
Joe Onorato00acb122009-08-04 16:04:30 -0400335 public void setDragController(DragController dragController) {
336 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800337 }
338
Adam Cohen2801caf2011-05-13 20:57:39 -0700339 void setFolderIcon(FolderIcon icon) {
340 mFolderIcon = icon;
341 }
342
Adam Cohen3371da02011-10-25 21:38:29 -0700343 @Override
344 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
345 // When the folder gets focus, we don't want to announce the list of items.
346 return true;
347 }
348
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800349 /**
350 * @return the FolderInfo object associated with this folder
351 */
352 FolderInfo getInfo() {
353 return mInfo;
354 }
355
Adam Cohen3bf84d32012-05-07 20:17:14 -0700356 private class GridComparator implements Comparator<ShortcutInfo> {
357 int mNumCols;
358 public GridComparator(int numCols) {
359 mNumCols = numCols;
360 }
361
362 @Override
363 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
364 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
365 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
366 return (lhIndex - rhIndex);
367 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700368 }
369
370 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
371 int maxX = 0;
372 int count = items.size();
373 for (int i = 0; i < count; i++) {
374 ShortcutInfo item = items.get(i);
375 if (item.cellX > maxX) {
376 maxX = item.cellX;
377 }
378 }
Adam Cohen691a5792012-05-11 14:27:30 -0700379
380 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700381 Collections.sort(items, gridComparator);
382 final int countX = mContent.getCountX();
383 for (int i = 0; i < count; i++) {
384 int x = i % countX;
385 int y = i / countX;
386 ShortcutInfo item = items.get(i);
387 item.cellX = x;
388 item.cellY = y;
389 }
390 }
391
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800392 void bind(FolderInfo info) {
393 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700394 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700395 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700396 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700397 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700398 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700399 for (int i = 0; i < children.size(); i++) {
400 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700401 if (!createAndAddShortcut(child)) {
402 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700403 } else {
404 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700405 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700406 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700407
Adam Cohen0057bbc2011-08-12 18:30:51 -0700408 // We rearrange the items in case there are any empty gaps
409 setupContentForNumItems(count);
410
Adam Cohenc508b2d2011-06-28 14:41:44 -0700411 // If our folder has too many items we prune them from the list. This is an issue
412 // when upgrading from the old Folders implementation which could contain an unlimited
413 // number of items.
414 for (ShortcutInfo item: overflow) {
415 mInfo.remove(item);
416 LauncherModel.deleteItemFromDatabase(mLauncher, item);
417 }
418
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700419 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700420 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700421 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700422
Adam Cohenafb01ee2011-06-23 15:38:03 -0700423 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700424 mFolderName.setText(mInfo.title);
425 } else {
426 mFolderName.setText("");
427 }
Adam Cohen691a5792012-05-11 14:27:30 -0700428 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700429 }
430
431 /**
432 * Creates a new UserFolder, inflated from R.layout.user_folder.
433 *
434 * @param context The application's context.
435 *
436 * @return A new UserFolder.
437 */
438 static Folder fromXml(Context context) {
439 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
440 }
441
442 /**
443 * This method is intended to make the UserFolder to be visually identical in size and position
444 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
445 */
446 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700447 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800448 setScaleX(0.8f);
449 setScaleY(0.8f);
450 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700451 mState = STATE_SMALL;
452 }
453
454 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700455 positionAndSizeAsIcon();
456
Adam Cohen8e776a62011-06-28 18:10:06 -0700457 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700458 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800459 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
460 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
461 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200462 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700463 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800464
Adam Cohen2801caf2011-05-13 20:57:39 -0700465 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700466 @Override
467 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700468 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700469 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700470 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700471 mState = STATE_ANIMATING;
472 }
473 @Override
474 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700475 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700476 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700477 Cling cling = mLauncher.showFirstRunFoldersCling();
478 if (cling != null) {
479 cling.bringToFront();
480 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700481 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700482 }
483 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700484 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700485 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100486 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700487 }
488
Adam Cohen3371da02011-10-25 21:38:29 -0700489 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700490 AccessibilityManager accessibilityManager = (AccessibilityManager)
491 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
492 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700493 AccessibilityEvent event = AccessibilityEvent.obtain(type);
494 onInitializeAccessibilityEvent(event);
495 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700496 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700497 }
498 }
499
Adam Cohenac56cff2011-09-28 20:45:37 -0700500 private void setFocusOnFirstChild() {
501 View firstChild = mContent.getChildAt(0, 0);
502 if (firstChild != null) {
503 firstChild.requestFocus();
504 }
505 }
506
Adam Cohendf2cc412011-04-27 16:56:57 -0700507 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700508 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800509 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
510 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
511 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200512 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700513 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700514
Adam Cohen2801caf2011-05-13 20:57:39 -0700515 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700516 @Override
517 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700518 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700519 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700520 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700521 }
522 @Override
523 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700524 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700525 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700526 mState = STATE_ANIMATING;
527 }
528 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700529 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700530 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100531 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700532 }
533
534 void notifyDataSetChanged() {
535 // recreate all the children if the data set changes under us. We may want to do this more
536 // intelligently (ie just removing the views that should no longer exist)
537 mContent.removeAllViewsInLayout();
538 bind(mInfo);
539 }
540
Adam Cohencb3382b2011-05-24 14:07:08 -0700541 public boolean acceptDrop(DragObject d) {
542 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700543 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700544 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
545 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
546 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700547 }
548
Adam Cohendf2cc412011-04-27 16:56:57 -0700549 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
550 int[] emptyCell = new int[2];
551 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
552 item.cellX = emptyCell[0];
553 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700554 return true;
555 } else {
556 return false;
557 }
558 }
559
Adam Cohenc508b2d2011-06-28 14:41:44 -0700560 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700561 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700562 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700563 textView.setCompoundDrawablesWithIntrinsicBounds(null,
564 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
565 textView.setText(item.title);
566 textView.setTag(item);
567
568 textView.setOnClickListener(this);
569 textView.setOnLongClickListener(this);
570
Adam Cohenc508b2d2011-06-28 14:41:44 -0700571 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700572 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700573 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
574 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700575 // This shouldn't happen, log it.
576 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700577 if (!findAndSetEmptyCells(item)) {
578 return false;
579 }
580 }
581
Adam Cohendf2cc412011-04-27 16:56:57 -0700582 CellLayout.LayoutParams lp =
583 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
584 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700585 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700586 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700587 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700588 }
589
Adam Cohencb3382b2011-05-24 14:07:08 -0700590 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700591 mPreviousTargetCell[0] = -1;
592 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700593 mOnExitAlarm.cancelAlarm();
594 }
595
596 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
597 public void onAlarm(Alarm alarm) {
598 realTimeReorder(mEmptyCell, mTargetCell);
599 }
600 };
601
602 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
603 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
604 return true;
605 } else {
606 return false;
607 }
608 }
609
610 private void realTimeReorder(int[] empty, int[] target) {
611 boolean wrap;
612 int startX;
613 int endX;
614 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700615 int delay = 0;
616 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700617 if (readingOrderGreaterThan(target, empty)) {
618 wrap = empty[0] >= mContent.getCountX() - 1;
619 startY = wrap ? empty[1] + 1 : empty[1];
620 for (int y = startY; y <= target[1]; y++) {
621 startX = y == empty[1] ? empty[0] + 1 : 0;
622 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
623 for (int x = startX; x <= endX; x++) {
624 View v = mContent.getChildAt(x,y);
625 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800626 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700627 empty[0] = x;
628 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700629 delay += delayAmount;
630 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700631 }
632 }
633 }
634 } else {
635 wrap = empty[0] == 0;
636 startY = wrap ? empty[1] - 1 : empty[1];
637 for (int y = startY; y >= target[1]; y--) {
638 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
639 endX = y > target[1] ? 0 : target[0];
640 for (int x = startX; x >= endX; x--) {
641 View v = mContent.getChildAt(x,y);
642 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800643 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700644 empty[0] = x;
645 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700646 delay += delayAmount;
647 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700648 }
649 }
650 }
651 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700652 }
653
Adam Cohen2374abf2013-04-16 14:56:57 -0700654 public boolean isLayoutRtl() {
655 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
656 }
657
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700658 private Rect getDragObjectDrawingRect(View dragView, float[] r) {
659 final Rect drawingRect = mTempRect;
660 drawingRect.left = (int) r[0];
661 drawingRect.top = (int) r[1];
662 drawingRect.right = drawingRect.left + dragView.getMeasuredWidth();
663 drawingRect.bottom = drawingRect.top + dragView.getMeasuredHeight();
664 return drawingRect;
665 }
666
Adam Cohencb3382b2011-05-24 14:07:08 -0700667 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700668 int scrollOffset = mScrollView.getScrollY();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700669 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700670 r[0] -= getPaddingLeft();
671 r[1] -= getPaddingTop();
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700672 if (!mAutoScroller.onTouch(this, getDragObjectDrawingRect(d.dragView, r))) {
673 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1,
674 mTargetCell);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700675
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700676 if (isLayoutRtl()) {
677 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700678 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700679 if (mTargetCell[0] != mPreviousTargetCell[0]
680 || mTargetCell[1] != mPreviousTargetCell[1]) {
681 mReorderAlarm.cancelAlarm();
682 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
683 mReorderAlarm.setAlarm(REORDER_DELAY);
684 mPreviousTargetCell[0] = mTargetCell[0];
685 mPreviousTargetCell[1] = mTargetCell[1];
686 mDragMode = DRAG_MODE_REORDER;
687 } else {
688 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700689 }
Adam Cohenbfbfd262011-06-13 16:55:12 -0700690 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700691 }
692
Adam Cohenbfbfd262011-06-13 16:55:12 -0700693 // This is used to compute the visual center of the dragView. The idea is that
694 // the visual center represents the user's interpretation of where the item is, and hence
695 // is the appropriate point to use when determining drop location.
696 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
697 DragView dragView, float[] recycle) {
698 float res[];
699 if (recycle == null) {
700 res = new float[2];
701 } else {
702 res = recycle;
703 }
704
705 // These represent the visual top and left of drag view if a dragRect was provided.
706 // If a dragRect was not provided, then they correspond to the actual view left and
707 // top, as the dragRect is in that case taken to be the entire dragView.
708 // R.dimen.dragViewOffsetY.
709 int left = x - xOffset;
710 int top = y - yOffset;
711
712 // In order to find the visual center, we shift by half the dragRect
713 res[0] = left + dragView.getDragRegion().width() / 2;
714 res[1] = top + dragView.getDragRegion().height() / 2;
715
716 return res;
717 }
718
719 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
720 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700721 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700722 }
723 };
724
Adam Cohen95bb8002011-07-03 23:40:28 -0700725 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700726 mLauncher.closeFolder();
727 mCurrentDragInfo = null;
728 mCurrentDragView = null;
729 mSuppressOnAdd = false;
730 mRearrangeOnClose = true;
731 }
732
Adam Cohencb3382b2011-05-24 14:07:08 -0700733 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700734 // Exiting folder; stop the auto scroller.
735 mAutoScroller.stop();
736 // We only close the folder if this is a true drag exit, ie. not because
737 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700738 if (!d.dragComplete) {
739 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
740 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
741 }
742 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700743 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700744 }
745
Winson Chunga48487a2012-03-20 16:19:37 -0700746 public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete,
747 boolean success) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700748 if (success) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700749 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700750 replaceFolderWithFinalItem();
751 }
752 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700753 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700754 // The drag failed, we need to return the item to the folder
755 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700756 }
757
758 if (target != this) {
759 if (mOnExitAlarm.alarmPending()) {
760 mOnExitAlarm.cancelAlarm();
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700761 if (!success) {
762 mSuppressFolderDeletion = true;
763 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700764 completeDragExit();
765 }
766 }
767 mDeleteFolderOnDropCompleted = false;
768 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700769 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700770 mCurrentDragInfo = null;
771 mCurrentDragView = null;
772 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700773
774 // Reordering may have occured, and we need to save the new item locations. We do this once
775 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700776 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700777 }
778
Winson Chunga48487a2012-03-20 16:19:37 -0700779 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800780 public boolean supportsFlingToDelete() {
781 return true;
782 }
783
Winson Chunga48487a2012-03-20 16:19:37 -0700784 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
785 // Do nothing
786 }
787
788 @Override
789 public void onFlingToDeleteCompleted() {
790 // Do nothing
791 }
792
Adam Cohen4045eb72011-10-06 11:44:26 -0700793 private void updateItemLocationsInDatabase() {
794 ArrayList<View> list = getItemsInReadingOrder();
795 for (int i = 0; i < list.size(); i++) {
796 View v = list.get(i);
797 ItemInfo info = (ItemInfo) v.getTag();
798 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
799 info.cellX, info.cellY);
800 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700801 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700802
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700803 private void updateItemLocationsInDatabaseBatch() {
804 ArrayList<View> list = getItemsInReadingOrder();
805 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
806 for (int i = 0; i < list.size(); i++) {
807 View v = list.get(i);
808 ItemInfo info = (ItemInfo) v.getTag();
809 items.add(info);
810 }
811
812 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
813 }
814
Adam Cohene25af792013-06-06 23:08:25 -0700815 public void addItemLocationsInDatabase() {
816 ArrayList<View> list = getItemsInReadingOrder();
817 for (int i = 0; i < list.size(); i++) {
818 View v = list.get(i);
819 ItemInfo info = (ItemInfo) v.getTag();
820 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
821 info.cellX, info.cellY, false);
822 }
823 }
824
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700825 public void notifyDrop() {
826 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700827 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700828 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700829 }
830
831 public boolean isDropEnabled() {
832 return true;
833 }
834
Adam Cohen4045eb72011-10-06 11:44:26 -0700835 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700836 ArrayList<View> list = getItemsInReadingOrder();
837
838 int countX = mContent.getCountX();
839 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700840 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700841
Adam Cohen7c693212011-05-18 15:26:57 -0700842 while (!done) {
843 int oldCountX = countX;
844 int oldCountY = countY;
845 if (countX * countY < count) {
846 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800847 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700848 countX++;
849 } else if (countY < mMaxCountY) {
850 countY++;
851 }
852 if (countY == 0) countY++;
853 } else if ((countY - 1) * countX >= count && countY >= countX) {
854 countY = Math.max(0, countY - 1);
855 } else if ((countX - 1) * countY >= count) {
856 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700857 }
Adam Cohen7c693212011-05-18 15:26:57 -0700858 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700859 }
Adam Cohen7c693212011-05-18 15:26:57 -0700860 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700861 arrangeChildren(list);
862 }
863
864 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800865 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700866 }
867
868 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700869 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700870
871 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700872 int height = getFolderHeight();
Adam Cohen8e776a62011-06-28 18:10:06 -0700873 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700874
Adam Cohen307fe232012-08-16 17:55:58 -0700875 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700876
Adam Cohen307fe232012-08-16 17:55:58 -0700877 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
878 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700879 int centeredLeft = centerX - width / 2;
880 int centeredTop = centerY - height / 2;
881
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800882 int currentPage = mLauncher.getWorkspace().getCurrentPage();
883 // In case the workspace is scrolling, we need to use the final scroll to compute
884 // the folders bounds.
885 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700886 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800887 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700888 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700889 Rect bounds = new Rect();
890 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800891 // We reset the workspaces scroll
892 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700893
Adam Cohen35e7e642011-07-17 14:47:18 -0700894 // We need to bound the folder to the currently visible CellLayoutChildren
895 int left = Math.min(Math.max(bounds.left, centeredLeft),
896 bounds.left + bounds.width() - width);
897 int top = Math.min(Math.max(bounds.top, centeredTop),
898 bounds.top + bounds.height() - height);
899 // If the folder doesn't fit within the bounds, center it about the desired bounds
900 if (width >= bounds.width()) {
901 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700902 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700903 if (height >= bounds.height()) {
904 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700905 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700906
907 int folderPivotX = width / 2 + (centeredLeft - left);
908 int folderPivotY = height / 2 + (centeredTop - top);
909 setPivotX(folderPivotX);
910 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700911 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700912 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700913 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700914 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700915
Adam Cohen662b5982011-12-13 17:45:21 -0800916 lp.width = width;
917 lp.height = height;
918 lp.x = left;
919 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700920 }
921
Adam Cohen268c4752012-06-06 17:47:33 -0700922 float getPivotXForIconAnimation() {
923 return mFolderIconPivotX;
924 }
925 float getPivotYForIconAnimation() {
926 return mFolderIconPivotY;
927 }
928
Adam Cohen2801caf2011-05-13 20:57:39 -0700929 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700930 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700931
Adam Cohen8e776a62011-06-28 18:10:06 -0700932 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700933 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700934 lp = new DragLayer.LayoutParams(0, 0);
935 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700936 setLayoutParams(lp);
937 }
938 centerAboutIcon();
939 }
940
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700941 private int getFolderHeight() {
942 int contentAreaHeight = mContent.getDesiredHeight();
943 if (contentAreaHeight >= mMaxContentAreaHeight) {
944 // Subtract a bit so the user can see that it's scrollable.
945 contentAreaHeight = mMaxContentAreaHeight;
946 }
947 int height = getPaddingTop() + getPaddingBottom() + contentAreaHeight
Adam Cohenf4bb1cd2011-07-22 14:36:03 -0700948 + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700949 return height;
950 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700951
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700952 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohen234c4cd2011-07-17 21:03:04 -0700953
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700954 int contentAreaHeight = mContent.getDesiredHeight();
955 if (contentAreaHeight >= mMaxContentAreaHeight) {
956 // Subtract a bit so the user can see that it's scrollable.
957 contentAreaHeight = mMaxContentAreaHeight;
958 }
959
960 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
961 int height = getFolderHeight();
962 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
963 MeasureSpec.EXACTLY);
964 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentAreaHeight,
965 MeasureSpec.EXACTLY);
966
967 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
968 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
969 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -0700970 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
971 setMeasuredDimension(width, height);
972 }
973
Adam Cohen2801caf2011-05-13 20:57:39 -0700974 private void arrangeChildren(ArrayList<View> list) {
975 int[] vacant = new int[2];
976 if (list == null) {
977 list = getItemsInReadingOrder();
978 }
979 mContent.removeAllViews();
980
981 for (int i = 0; i < list.size(); i++) {
982 View v = list.get(i);
983 mContent.getVacantCell(vacant, 1, 1);
984 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
985 lp.cellX = vacant[0];
986 lp.cellY = vacant[1];
987 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -0700988 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
989 info.cellX = vacant[0];
990 info.cellY = vacant[1];
991 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
992 info.cellX, info.cellY);
993 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700994 boolean insert = false;
995 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
996 }
Adam Cohen7c693212011-05-18 15:26:57 -0700997 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700998 }
999
Adam Cohena9cf38f2011-05-02 15:36:58 -07001000 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001001 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001002 }
1003
1004 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001005 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001006 }
1007
Adam Cohen2801caf2011-05-13 20:57:39 -07001008 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001009 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001010 if (parent != null) {
1011 parent.removeView(this);
1012 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001013 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001014 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001015 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001016
Adam Cohen2801caf2011-05-13 20:57:39 -07001017 if (mRearrangeOnClose) {
1018 setupContentForNumItems(getItemCount());
1019 mRearrangeOnClose = false;
1020 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001021 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001022 if (!mDragInProgress && !mSuppressFolderDeletion) {
1023 replaceFolderWithFinalItem();
1024 } else if (mDragInProgress) {
1025 mDeleteFolderOnDropCompleted = true;
1026 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001027 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001028 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001029 }
1030
1031 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001032 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001033 Runnable onCompleteRunnable = new Runnable() {
1034 @Override
1035 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001036 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001037
Adam Cohenc5e63f32012-07-12 16:16:57 -07001038 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001039 // Move the item from the folder to the workspace, in the position of the folder
1040 if (getItemCount() == 1) {
1041 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001042 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001043 finalItem);
1044 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001045 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001046 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001047 if (getItemCount() <= 1) {
1048 // Remove the folder
1049 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1050 cellLayout.removeView(mFolderIcon);
1051 if (mFolderIcon instanceof DropTarget) {
1052 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1053 }
1054 mLauncher.removeFolder(mInfo);
1055 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001056 // We add the child after removing the folder to prevent both from existing at
1057 // the same time in the CellLayout.
1058 if (child != null) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001059 mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001060 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1061 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001062 }
1063 };
1064 View finalChild = getItemAt(0);
1065 if (finalChild != null) {
1066 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001067 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001068 mDestroyed = true;
1069 }
1070
1071 boolean isDestroyed() {
1072 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001073 }
1074
Adam Cohenac56cff2011-09-28 20:45:37 -07001075 // This method keeps track of the last item in the folder for the purposes
1076 // of keyboard focus
1077 private void updateTextViewFocus() {
1078 View lastChild = getItemAt(getItemCount() - 1);
1079 getItemAt(getItemCount() - 1);
1080 if (lastChild != null) {
1081 mFolderName.setNextFocusDownId(lastChild.getId());
1082 mFolderName.setNextFocusRightId(lastChild.getId());
1083 mFolderName.setNextFocusLeftId(lastChild.getId());
1084 mFolderName.setNextFocusUpId(lastChild.getId());
1085 }
1086 }
1087
Adam Cohenbfbfd262011-06-13 16:55:12 -07001088 public void onDrop(DragObject d) {
1089 ShortcutInfo item;
1090 if (d.dragInfo instanceof ApplicationInfo) {
1091 // Came from all apps -- make a copy
1092 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1093 item.spanX = 1;
1094 item.spanY = 1;
1095 } else {
1096 item = (ShortcutInfo) d.dragInfo;
1097 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001098 // Dragged from self onto self, currently this is the only path possible, however
1099 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001100 if (item == mCurrentDragInfo) {
1101 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1102 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1103 si.cellX = lp.cellX = mEmptyCell[0];
1104 si.cellX = lp.cellY = mEmptyCell[1];
1105 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001106 if (d.dragView.hasDrawn()) {
1107 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1108 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001109 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001110 mCurrentDragView.setVisibility(VISIBLE);
1111 }
Adam Cohene9166b22011-07-08 17:11:11 -07001112 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001113 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001114 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001115 }
1116 mInfo.add(item);
1117 }
1118
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001119 // This is used so the item doesn't immediately appear in the folder when added. In one case
1120 // we need to create the illusion that the item isn't added back to the folder yet, to
1121 // to correspond to the animation of the icon back into the folder. This is
1122 public void hideItem(ShortcutInfo info) {
1123 View v = getViewForInfo(info);
1124 v.setVisibility(INVISIBLE);
1125 }
1126 public void showItem(ShortcutInfo info) {
1127 View v = getViewForInfo(info);
1128 v.setVisibility(VISIBLE);
1129 }
1130
Adam Cohenbfbfd262011-06-13 16:55:12 -07001131 public void onAdd(ShortcutInfo item) {
1132 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001133 // If the item was dropped onto this open folder, we have done the work associated
1134 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001135 if (mSuppressOnAdd) return;
1136 if (!findAndSetEmptyCells(item)) {
1137 // The current layout is full, can we expand it?
1138 setupContentForNumItems(getItemCount() + 1);
1139 findAndSetEmptyCells(item);
1140 }
1141 createAndAddShortcut(item);
1142 LauncherModel.addOrMoveItemInDatabase(
1143 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1144 }
1145
Adam Cohena9cf38f2011-05-02 15:36:58 -07001146 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001147 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001148 // If this item is being dragged from this open folder, we have already handled
1149 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001150 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001151 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001152 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001153 if (mState == STATE_ANIMATING) {
1154 mRearrangeOnClose = true;
1155 } else {
1156 setupContentForNumItems(getItemCount());
1157 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001158 if (getItemCount() <= 1) {
1159 replaceFolderWithFinalItem();
1160 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001161 }
Adam Cohen7c693212011-05-18 15:26:57 -07001162
Adam Cohendf1e4e82011-06-24 15:57:39 -07001163 private View getViewForInfo(ShortcutInfo item) {
1164 for (int j = 0; j < mContent.getCountY(); j++) {
1165 for (int i = 0; i < mContent.getCountX(); i++) {
1166 View v = mContent.getChildAt(i, j);
1167 if (v.getTag() == item) {
1168 return v;
1169 }
1170 }
1171 }
1172 return null;
1173 }
1174
Adam Cohen76078c42011-06-09 15:06:52 -07001175 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001176 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001177 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001178
Adam Cohen76fc0852011-06-17 13:26:23 -07001179 public void onTitleChanged(CharSequence title) {
1180 }
Adam Cohen76078c42011-06-09 15:06:52 -07001181
Adam Cohen7c693212011-05-18 15:26:57 -07001182 public ArrayList<View> getItemsInReadingOrder() {
1183 if (mItemsInvalidated) {
1184 mItemsInReadingOrder.clear();
1185 for (int j = 0; j < mContent.getCountY(); j++) {
1186 for (int i = 0; i < mContent.getCountX(); i++) {
1187 View v = mContent.getChildAt(i, j);
1188 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001189 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001190 }
1191 }
1192 }
1193 mItemsInvalidated = false;
1194 }
1195 return mItemsInReadingOrder;
1196 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001197
1198 public void getLocationInDragLayer(int[] loc) {
1199 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1200 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001201
1202 public void onFocusChange(View v, boolean hasFocus) {
1203 if (v == mFolderName && hasFocus) {
1204 startEditingFolderName();
1205 }
1206 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001207
1208 @Override
1209 public void getHitRectRelativeToDragLayer(Rect outRect) {
1210 getHitRect(outRect);
1211 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001212}