blob: f23e1bb39c2d973b6fc8442fea5c9e6c75b93a93 [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);
Winson Chung5f8afe62013-08-12 16:19:28 -0700141
142 LauncherAppState app = LauncherAppState.getInstance();
143 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700145 mInflater = LayoutInflater.from(context);
Winson Chung5f8afe62013-08-12 16:19:28 -0700146 mIconCache = app.getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800147
148 Resources res = getResources();
Winson Chung5f8afe62013-08-12 16:19:28 -0700149 mMaxCountX = mMaxVisibleX = mMaxVisibleY = (int) (grid.numColumns);
150 mMaxCountY = mMaxNumItems = Integer.MAX_VALUE;
Adam Cohen76fc0852011-06-17 13:26:23 -0700151
152 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700153 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700154
Adam Cohen76fc0852011-06-17 13:26:23 -0700155 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700156
157 if (sDefaultFolderName == null) {
158 sDefaultFolderName = res.getString(R.string.folder_name);
159 }
Adam Cohena65beee2011-06-27 21:32:23 -0700160 if (sHintText == null) {
161 sHintText = res.getString(R.string.folder_hint_text);
162 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700163 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700164 // We need this view to be focusable in touch mode so that when text editing of the folder
165 // name is complete, we have something to focus on, thus hiding the cursor and giving
166 // reliable behvior when clicking the text field (since it will always gain focus on click).
167 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 }
169
170 @Override
171 protected void onFinishInflate() {
172 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700173 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700174 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700175
Winson Chung5f8afe62013-08-12 16:19:28 -0700176 LauncherAppState app = LauncherAppState.getInstance();
177 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
178
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700179 // Beyond this height, the area scrolls
Winson Chung5f8afe62013-08-12 16:19:28 -0700180 mContent.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700181 mContent.setGridSize(mMaxVisibleX, mMaxVisibleY);
182 mMaxContentAreaHeight = mContent.getDesiredHeight() - SCROLL_CUT_OFF_AMOUNT;
Adam Cohen2801caf2011-05-13 20:57:39 -0700183 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700184 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700185 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700186 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
187 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700188 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700189
190 // We find out how tall the text view wants to be (it is set to wrap_content), so that
191 // we can allocate the appropriate amount of space for it.
192 int measureSpec = MeasureSpec.UNSPECIFIED;
193 mFolderName.measure(measureSpec, measureSpec);
194 mFolderNameHeight = mFolderName.getMeasuredHeight();
195
196 // We disable action mode for now since it messes up the view on phones
197 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700198 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700199 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700200 mFolderName.setInputType(mFolderName.getInputType() |
201 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700202 mAutoScroller = new AutoScroller(mScrollView);
203 mAutoScroller.setMaximumVelocityAbsolute(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
204 mAutoScroller.setExtendsBeyondEdges(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700206
Adam Cohen76fc0852011-06-17 13:26:23 -0700207 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
208 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
209 return false;
210 }
211
212 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
213 return false;
214 }
215
216 public void onDestroyActionMode(ActionMode mode) {
217 }
218
219 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
220 return false;
221 }
222 };
223
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700225 Object tag = v.getTag();
226 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700227 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700228 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800229 }
230
231 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700232 // Return if global dragging is not enabled
233 if (!mLauncher.isDraggingEnabled()) return true;
234
Adam Cohendf2cc412011-04-27 16:56:57 -0700235 Object tag = v.getTag();
236 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700237 ShortcutInfo item = (ShortcutInfo) tag;
238 if (!v.isInTouchMode()) {
239 return false;
240 }
241
Winson Chung7d7541e2011-09-16 20:14:36 -0700242 mLauncher.dismissFolderCling(null);
243
Adam Cohendf2cc412011-04-27 16:56:57 -0700244 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700245 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700246 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700247
248 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700249 mEmptyCell[0] = item.cellX;
250 mEmptyCell[1] = item.cellY;
251 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700252
253 mContent.removeView(mCurrentDragView);
254 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700255 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700256 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700257 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 return true;
259 }
260
Adam Cohen76fc0852011-06-17 13:26:23 -0700261 public boolean isEditingName() {
262 return mIsEditingName;
263 }
264
265 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700266 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700267 mIsEditingName = true;
268 }
269
270 public void dismissEditingName() {
271 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
272 doneEditingFolderName(true);
273 }
274
275 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700276 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700277 // Convert to a string here to ensure that no other state associated with the text field
278 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700279 String newTitle = mFolderName.getText().toString();
280 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700281 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700282
Adam Cohen3371da02011-10-25 21:38:29 -0700283 if (commit) {
284 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700285 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700286 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700287 // In order to clear the focus from the text field, we set the focus on ourself. This
288 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
289 requestFocus();
290
Adam Cohene601a432011-07-26 21:51:30 -0700291 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700292 mIsEditingName = false;
293 }
294
295 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
296 if (actionId == EditorInfo.IME_ACTION_DONE) {
297 dismissEditingName();
298 return true;
299 }
300 return false;
301 }
302
303 public View getEditTextRegion() {
304 return mFolderName;
305 }
306
Adam Cohenbadf71e2011-05-26 19:08:29 -0700307 public Drawable getDragDrawable() {
308 return mIconDrawable;
309 }
310
Adam Cohen0c872ba2011-05-05 10:34:16 -0700311 /**
312 * We need to handle touch events to prevent them from falling through to the workspace below.
313 */
314 @Override
315 public boolean onTouchEvent(MotionEvent ev) {
316 return true;
317 }
318
Joe Onorato00acb122009-08-04 16:04:30 -0400319 public void setDragController(DragController dragController) {
320 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 }
322
Adam Cohen2801caf2011-05-13 20:57:39 -0700323 void setFolderIcon(FolderIcon icon) {
324 mFolderIcon = icon;
325 }
326
Adam Cohen3371da02011-10-25 21:38:29 -0700327 @Override
328 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
329 // When the folder gets focus, we don't want to announce the list of items.
330 return true;
331 }
332
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800333 /**
334 * @return the FolderInfo object associated with this folder
335 */
336 FolderInfo getInfo() {
337 return mInfo;
338 }
339
Adam Cohen3bf84d32012-05-07 20:17:14 -0700340 private class GridComparator implements Comparator<ShortcutInfo> {
341 int mNumCols;
342 public GridComparator(int numCols) {
343 mNumCols = numCols;
344 }
345
346 @Override
347 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
348 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
349 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
350 return (lhIndex - rhIndex);
351 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700352 }
353
354 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
355 int maxX = 0;
356 int count = items.size();
357 for (int i = 0; i < count; i++) {
358 ShortcutInfo item = items.get(i);
359 if (item.cellX > maxX) {
360 maxX = item.cellX;
361 }
362 }
Adam Cohen691a5792012-05-11 14:27:30 -0700363
364 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700365 Collections.sort(items, gridComparator);
366 final int countX = mContent.getCountX();
367 for (int i = 0; i < count; i++) {
368 int x = i % countX;
369 int y = i / countX;
370 ShortcutInfo item = items.get(i);
371 item.cellX = x;
372 item.cellY = y;
373 }
374 }
375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 void bind(FolderInfo info) {
377 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700378 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700379 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700380 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700381 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700382 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700383 for (int i = 0; i < children.size(); i++) {
384 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700385 if (!createAndAddShortcut(child)) {
386 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700387 } else {
388 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700389 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700390 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700391
Adam Cohen0057bbc2011-08-12 18:30:51 -0700392 // We rearrange the items in case there are any empty gaps
393 setupContentForNumItems(count);
394
Adam Cohenc508b2d2011-06-28 14:41:44 -0700395 // If our folder has too many items we prune them from the list. This is an issue
396 // when upgrading from the old Folders implementation which could contain an unlimited
397 // number of items.
398 for (ShortcutInfo item: overflow) {
399 mInfo.remove(item);
400 LauncherModel.deleteItemFromDatabase(mLauncher, item);
401 }
402
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700403 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700404 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700405 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700406
Adam Cohenafb01ee2011-06-23 15:38:03 -0700407 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700408 mFolderName.setText(mInfo.title);
409 } else {
410 mFolderName.setText("");
411 }
Adam Cohen691a5792012-05-11 14:27:30 -0700412 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700413 }
414
415 /**
416 * Creates a new UserFolder, inflated from R.layout.user_folder.
417 *
418 * @param context The application's context.
419 *
420 * @return A new UserFolder.
421 */
422 static Folder fromXml(Context context) {
423 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
424 }
425
426 /**
427 * This method is intended to make the UserFolder to be visually identical in size and position
428 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
429 */
430 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700431 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800432 setScaleX(0.8f);
433 setScaleY(0.8f);
434 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700435 mState = STATE_SMALL;
436 }
437
438 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700439 positionAndSizeAsIcon();
440
Adam Cohen8e776a62011-06-28 18:10:06 -0700441 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700442 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800443 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
444 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
445 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200446 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700447 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800448
Adam Cohen2801caf2011-05-13 20:57:39 -0700449 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700450 @Override
451 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700452 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700453 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700454 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700455 mState = STATE_ANIMATING;
456 }
457 @Override
458 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700459 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700460 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700461 Cling cling = mLauncher.showFirstRunFoldersCling();
462 if (cling != null) {
463 cling.bringToFront();
464 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700465 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700466 }
467 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700468 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700469 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100470 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700471 }
472
Adam Cohen3371da02011-10-25 21:38:29 -0700473 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700474 AccessibilityManager accessibilityManager = (AccessibilityManager)
475 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
476 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700477 AccessibilityEvent event = AccessibilityEvent.obtain(type);
478 onInitializeAccessibilityEvent(event);
479 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700480 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700481 }
482 }
483
Adam Cohenac56cff2011-09-28 20:45:37 -0700484 private void setFocusOnFirstChild() {
485 View firstChild = mContent.getChildAt(0, 0);
486 if (firstChild != null) {
487 firstChild.requestFocus();
488 }
489 }
490
Adam Cohendf2cc412011-04-27 16:56:57 -0700491 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700492 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800493 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
494 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
495 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200496 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700497 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700498
Adam Cohen2801caf2011-05-13 20:57:39 -0700499 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700500 @Override
501 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700502 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700503 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700504 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700505 }
506 @Override
507 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700508 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700509 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700510 mState = STATE_ANIMATING;
511 }
512 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700513 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700514 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100515 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700516 }
517
Adam Cohencb3382b2011-05-24 14:07:08 -0700518 public boolean acceptDrop(DragObject d) {
519 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700520 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700521 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
522 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
523 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700524 }
525
Adam Cohendf2cc412011-04-27 16:56:57 -0700526 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
527 int[] emptyCell = new int[2];
528 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
529 item.cellX = emptyCell[0];
530 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700531 return true;
532 } else {
533 return false;
534 }
535 }
536
Adam Cohenc508b2d2011-06-28 14:41:44 -0700537 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700538 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700539 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700540 textView.setCompoundDrawablesWithIntrinsicBounds(null,
541 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
542 textView.setText(item.title);
543 textView.setTag(item);
544
545 textView.setOnClickListener(this);
546 textView.setOnLongClickListener(this);
547
Adam Cohenc508b2d2011-06-28 14:41:44 -0700548 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700549 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700550 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
551 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700552 // This shouldn't happen, log it.
553 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700554 if (!findAndSetEmptyCells(item)) {
555 return false;
556 }
557 }
558
Adam Cohendf2cc412011-04-27 16:56:57 -0700559 CellLayout.LayoutParams lp =
560 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
561 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700562 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700563 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700564 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700565 }
566
Adam Cohencb3382b2011-05-24 14:07:08 -0700567 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700568 mPreviousTargetCell[0] = -1;
569 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700570 mOnExitAlarm.cancelAlarm();
571 }
572
573 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
574 public void onAlarm(Alarm alarm) {
575 realTimeReorder(mEmptyCell, mTargetCell);
576 }
577 };
578
579 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
580 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
581 return true;
582 } else {
583 return false;
584 }
585 }
586
587 private void realTimeReorder(int[] empty, int[] target) {
588 boolean wrap;
589 int startX;
590 int endX;
591 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700592 int delay = 0;
593 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700594 if (readingOrderGreaterThan(target, empty)) {
595 wrap = empty[0] >= mContent.getCountX() - 1;
596 startY = wrap ? empty[1] + 1 : empty[1];
597 for (int y = startY; y <= target[1]; y++) {
598 startX = y == empty[1] ? empty[0] + 1 : 0;
599 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
600 for (int x = startX; x <= endX; x++) {
601 View v = mContent.getChildAt(x,y);
602 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800603 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700604 empty[0] = x;
605 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700606 delay += delayAmount;
607 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700608 }
609 }
610 }
611 } else {
612 wrap = empty[0] == 0;
613 startY = wrap ? empty[1] - 1 : empty[1];
614 for (int y = startY; y >= target[1]; y--) {
615 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
616 endX = y > target[1] ? 0 : target[0];
617 for (int x = startX; x >= endX; x--) {
618 View v = mContent.getChildAt(x,y);
619 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800620 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700621 empty[0] = x;
622 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700623 delay += delayAmount;
624 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700625 }
626 }
627 }
628 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700629 }
630
Adam Cohen2374abf2013-04-16 14:56:57 -0700631 public boolean isLayoutRtl() {
632 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
633 }
634
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700635 private Rect getDragObjectDrawingRect(View dragView, float[] r) {
636 final Rect drawingRect = mTempRect;
637 drawingRect.left = (int) r[0];
638 drawingRect.top = (int) r[1];
639 drawingRect.right = drawingRect.left + dragView.getMeasuredWidth();
640 drawingRect.bottom = drawingRect.top + dragView.getMeasuredHeight();
641 return drawingRect;
642 }
643
Adam Cohencb3382b2011-05-24 14:07:08 -0700644 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700645 int scrollOffset = mScrollView.getScrollY();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700646 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700647 r[0] -= getPaddingLeft();
648 r[1] -= getPaddingTop();
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700649 if (!mAutoScroller.onTouch(this, getDragObjectDrawingRect(d.dragView, r))) {
650 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1,
651 mTargetCell);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700652
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700653 if (isLayoutRtl()) {
654 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700655 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700656 if (mTargetCell[0] != mPreviousTargetCell[0]
657 || mTargetCell[1] != mPreviousTargetCell[1]) {
658 mReorderAlarm.cancelAlarm();
659 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
660 mReorderAlarm.setAlarm(REORDER_DELAY);
661 mPreviousTargetCell[0] = mTargetCell[0];
662 mPreviousTargetCell[1] = mTargetCell[1];
663 mDragMode = DRAG_MODE_REORDER;
664 } else {
665 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700666 }
Adam Cohen61a9a5c2013-08-14 13:32:04 -0700667 } else {
668 mReorderAlarm.cancelAlarm();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700669 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700670 }
671
Adam Cohenbfbfd262011-06-13 16:55:12 -0700672 // This is used to compute the visual center of the dragView. The idea is that
673 // the visual center represents the user's interpretation of where the item is, and hence
674 // is the appropriate point to use when determining drop location.
675 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
676 DragView dragView, float[] recycle) {
677 float res[];
678 if (recycle == null) {
679 res = new float[2];
680 } else {
681 res = recycle;
682 }
683
684 // These represent the visual top and left of drag view if a dragRect was provided.
685 // If a dragRect was not provided, then they correspond to the actual view left and
686 // top, as the dragRect is in that case taken to be the entire dragView.
687 // R.dimen.dragViewOffsetY.
688 int left = x - xOffset;
689 int top = y - yOffset;
690
691 // In order to find the visual center, we shift by half the dragRect
692 res[0] = left + dragView.getDragRegion().width() / 2;
693 res[1] = top + dragView.getDragRegion().height() / 2;
694
695 return res;
696 }
697
698 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
699 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700700 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700701 }
702 };
703
Adam Cohen95bb8002011-07-03 23:40:28 -0700704 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700705 mLauncher.closeFolder();
706 mCurrentDragInfo = null;
707 mCurrentDragView = null;
708 mSuppressOnAdd = false;
709 mRearrangeOnClose = true;
710 }
711
Adam Cohencb3382b2011-05-24 14:07:08 -0700712 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700713 // Exiting folder; stop the auto scroller.
714 mAutoScroller.stop();
715 // We only close the folder if this is a true drag exit, ie. not because
716 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700717 if (!d.dragComplete) {
718 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
719 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
720 }
721 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700722 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700723 }
724
Michael Jurka1e2f4652013-07-08 18:03:46 -0700725 public void onDropCompleted(final View target, final DragObject d,
726 final boolean isFlingToDelete, final boolean success) {
727 if (mDeferDropAfterUninstall) {
728 mDeferredAction = new Runnable() {
729 public void run() {
730 onDropCompleted(target, d, isFlingToDelete, success);
731 mDeferredAction = null;
732 }
733 };
734 return;
735 }
736
737 boolean beingCalledAfterUninstall = mDeferredAction != null;
738 boolean successfulDrop =
739 success && (!beingCalledAfterUninstall || mUninstallSuccessful);
Winson Chung5f8afe62013-08-12 16:19:28 -0700740
Michael Jurka1e2f4652013-07-08 18:03:46 -0700741 if (successfulDrop) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700742 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700743 replaceFolderWithFinalItem();
744 }
745 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700746 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700747 // The drag failed, we need to return the item to the folder
748 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700749 }
750
751 if (target != this) {
752 if (mOnExitAlarm.alarmPending()) {
753 mOnExitAlarm.cancelAlarm();
Michael Jurka54554252013-08-01 12:52:23 +0200754 if (!successfulDrop) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700755 mSuppressFolderDeletion = true;
756 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700757 completeDragExit();
758 }
759 }
Winson Chung5f8afe62013-08-12 16:19:28 -0700760
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700761 mDeleteFolderOnDropCompleted = false;
762 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700763 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700764 mCurrentDragInfo = null;
765 mCurrentDragView = null;
766 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700767
768 // Reordering may have occured, and we need to save the new item locations. We do this once
769 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700770 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700771 }
772
Michael Jurka1e2f4652013-07-08 18:03:46 -0700773 public void deferCompleteDropAfterUninstallActivity() {
774 mDeferDropAfterUninstall = true;
775 }
776
777 public void onUninstallActivityReturned(boolean success) {
778 mDeferDropAfterUninstall = false;
779 mUninstallSuccessful = success;
780 if (mDeferredAction != null) {
781 mDeferredAction.run();
782 }
783 }
784
Winson Chunga48487a2012-03-20 16:19:37 -0700785 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800786 public boolean supportsFlingToDelete() {
787 return true;
788 }
789
Winson Chunga48487a2012-03-20 16:19:37 -0700790 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
791 // Do nothing
792 }
793
794 @Override
795 public void onFlingToDeleteCompleted() {
796 // Do nothing
797 }
798
Adam Cohen4045eb72011-10-06 11:44:26 -0700799 private void updateItemLocationsInDatabase() {
800 ArrayList<View> list = getItemsInReadingOrder();
801 for (int i = 0; i < list.size(); i++) {
802 View v = list.get(i);
803 ItemInfo info = (ItemInfo) v.getTag();
804 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
805 info.cellX, info.cellY);
806 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700807 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700808
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700809 private void updateItemLocationsInDatabaseBatch() {
810 ArrayList<View> list = getItemsInReadingOrder();
811 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
812 for (int i = 0; i < list.size(); i++) {
813 View v = list.get(i);
814 ItemInfo info = (ItemInfo) v.getTag();
815 items.add(info);
816 }
817
818 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
819 }
820
Adam Cohene25af792013-06-06 23:08:25 -0700821 public void addItemLocationsInDatabase() {
822 ArrayList<View> list = getItemsInReadingOrder();
823 for (int i = 0; i < list.size(); i++) {
824 View v = list.get(i);
825 ItemInfo info = (ItemInfo) v.getTag();
826 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
827 info.cellX, info.cellY, false);
828 }
829 }
830
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700831 public void notifyDrop() {
832 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700833 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700834 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700835 }
836
837 public boolean isDropEnabled() {
838 return true;
839 }
840
Adam Cohen4045eb72011-10-06 11:44:26 -0700841 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700842 ArrayList<View> list = getItemsInReadingOrder();
843
844 int countX = mContent.getCountX();
845 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700846 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700847
Adam Cohen7c693212011-05-18 15:26:57 -0700848 while (!done) {
849 int oldCountX = countX;
850 int oldCountY = countY;
851 if (countX * countY < count) {
852 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800853 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700854 countX++;
855 } else if (countY < mMaxCountY) {
856 countY++;
857 }
858 if (countY == 0) countY++;
859 } else if ((countY - 1) * countX >= count && countY >= countX) {
860 countY = Math.max(0, countY - 1);
861 } else if ((countX - 1) * countY >= count) {
862 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700863 }
Adam Cohen7c693212011-05-18 15:26:57 -0700864 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700865 }
Adam Cohen7c693212011-05-18 15:26:57 -0700866 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700867 arrangeChildren(list);
868 }
869
870 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800871 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700872 }
873
874 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700875 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700876
877 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700878 int height = getFolderHeight();
Adam Cohen8e776a62011-06-28 18:10:06 -0700879 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700880
Adam Cohen307fe232012-08-16 17:55:58 -0700881 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700882
Adam Cohen307fe232012-08-16 17:55:58 -0700883 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
884 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700885 int centeredLeft = centerX - width / 2;
886 int centeredTop = centerY - height / 2;
887
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800888 int currentPage = mLauncher.getWorkspace().getCurrentPage();
889 // In case the workspace is scrolling, we need to use the final scroll to compute
890 // the folders bounds.
891 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700892 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800893 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700894 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700895 Rect bounds = new Rect();
896 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800897 // We reset the workspaces scroll
898 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700899
Adam Cohen35e7e642011-07-17 14:47:18 -0700900 // We need to bound the folder to the currently visible CellLayoutChildren
901 int left = Math.min(Math.max(bounds.left, centeredLeft),
902 bounds.left + bounds.width() - width);
903 int top = Math.min(Math.max(bounds.top, centeredTop),
904 bounds.top + bounds.height() - height);
905 // If the folder doesn't fit within the bounds, center it about the desired bounds
906 if (width >= bounds.width()) {
907 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700908 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700909 if (height >= bounds.height()) {
910 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700911 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700912
913 int folderPivotX = width / 2 + (centeredLeft - left);
914 int folderPivotY = height / 2 + (centeredTop - top);
915 setPivotX(folderPivotX);
916 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700917 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700918 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700919 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700920 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700921
Adam Cohen662b5982011-12-13 17:45:21 -0800922 lp.width = width;
923 lp.height = height;
924 lp.x = left;
925 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700926 }
927
Adam Cohen268c4752012-06-06 17:47:33 -0700928 float getPivotXForIconAnimation() {
929 return mFolderIconPivotX;
930 }
931 float getPivotYForIconAnimation() {
932 return mFolderIconPivotY;
933 }
934
Adam Cohen2801caf2011-05-13 20:57:39 -0700935 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700936 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700937
Adam Cohen8e776a62011-06-28 18:10:06 -0700938 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700939 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700940 lp = new DragLayer.LayoutParams(0, 0);
941 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700942 setLayoutParams(lp);
943 }
944 centerAboutIcon();
945 }
946
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700947 private int getFolderHeight() {
948 int contentAreaHeight = mContent.getDesiredHeight();
949 if (contentAreaHeight >= mMaxContentAreaHeight) {
950 // Subtract a bit so the user can see that it's scrollable.
951 contentAreaHeight = mMaxContentAreaHeight;
952 }
953 int height = getPaddingTop() + getPaddingBottom() + contentAreaHeight
Adam Cohenf4bb1cd2011-07-22 14:36:03 -0700954 + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700955 return height;
956 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700957
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700958 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700959 int contentAreaHeight = mContent.getDesiredHeight();
960 if (contentAreaHeight >= mMaxContentAreaHeight) {
961 // Subtract a bit so the user can see that it's scrollable.
962 contentAreaHeight = mMaxContentAreaHeight;
963 }
964
965 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
966 int height = getFolderHeight();
967 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
968 MeasureSpec.EXACTLY);
969 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentAreaHeight,
970 MeasureSpec.EXACTLY);
971
972 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
973 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
974 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -0700975 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
976 setMeasuredDimension(width, height);
977 }
978
Adam Cohen2801caf2011-05-13 20:57:39 -0700979 private void arrangeChildren(ArrayList<View> list) {
980 int[] vacant = new int[2];
981 if (list == null) {
982 list = getItemsInReadingOrder();
983 }
984 mContent.removeAllViews();
985
986 for (int i = 0; i < list.size(); i++) {
987 View v = list.get(i);
988 mContent.getVacantCell(vacant, 1, 1);
989 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
990 lp.cellX = vacant[0];
991 lp.cellY = vacant[1];
992 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -0700993 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
994 info.cellX = vacant[0];
995 info.cellY = vacant[1];
996 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
997 info.cellX, info.cellY);
998 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700999 boolean insert = false;
1000 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1001 }
Adam Cohen7c693212011-05-18 15:26:57 -07001002 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001003 }
1004
Adam Cohena9cf38f2011-05-02 15:36:58 -07001005 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001006 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001007 }
1008
1009 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001010 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001011 }
1012
Adam Cohen2801caf2011-05-13 20:57:39 -07001013 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001014 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001015 if (parent != null) {
1016 parent.removeView(this);
1017 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001018 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001019 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001020 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001021
Adam Cohen2801caf2011-05-13 20:57:39 -07001022 if (mRearrangeOnClose) {
1023 setupContentForNumItems(getItemCount());
1024 mRearrangeOnClose = false;
1025 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001026 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001027 if (!mDragInProgress && !mSuppressFolderDeletion) {
1028 replaceFolderWithFinalItem();
1029 } else if (mDragInProgress) {
1030 mDeleteFolderOnDropCompleted = true;
1031 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001032 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001033 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001034 }
1035
1036 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001037 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001038 Runnable onCompleteRunnable = new Runnable() {
1039 @Override
1040 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001041 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001042
Adam Cohenc5e63f32012-07-12 16:16:57 -07001043 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001044 // Move the item from the folder to the workspace, in the position of the folder
1045 if (getItemCount() == 1) {
1046 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001047 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001048 finalItem);
1049 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001050 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001051 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001052 if (getItemCount() <= 1) {
1053 // Remove the folder
1054 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1055 cellLayout.removeView(mFolderIcon);
1056 if (mFolderIcon instanceof DropTarget) {
1057 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1058 }
1059 mLauncher.removeFolder(mInfo);
1060 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001061 // We add the child after removing the folder to prevent both from existing at
1062 // the same time in the CellLayout.
1063 if (child != null) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001064 mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001065 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1066 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001067 }
1068 };
1069 View finalChild = getItemAt(0);
1070 if (finalChild != null) {
1071 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001072 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001073 mDestroyed = true;
1074 }
1075
1076 boolean isDestroyed() {
1077 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001078 }
1079
Adam Cohenac56cff2011-09-28 20:45:37 -07001080 // This method keeps track of the last item in the folder for the purposes
1081 // of keyboard focus
1082 private void updateTextViewFocus() {
1083 View lastChild = getItemAt(getItemCount() - 1);
1084 getItemAt(getItemCount() - 1);
1085 if (lastChild != null) {
1086 mFolderName.setNextFocusDownId(lastChild.getId());
1087 mFolderName.setNextFocusRightId(lastChild.getId());
1088 mFolderName.setNextFocusLeftId(lastChild.getId());
1089 mFolderName.setNextFocusUpId(lastChild.getId());
1090 }
1091 }
1092
Adam Cohenbfbfd262011-06-13 16:55:12 -07001093 public void onDrop(DragObject d) {
1094 ShortcutInfo item;
1095 if (d.dragInfo instanceof ApplicationInfo) {
1096 // Came from all apps -- make a copy
1097 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1098 item.spanX = 1;
1099 item.spanY = 1;
1100 } else {
1101 item = (ShortcutInfo) d.dragInfo;
1102 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001103 // Dragged from self onto self, currently this is the only path possible, however
1104 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001105 if (item == mCurrentDragInfo) {
1106 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1107 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1108 si.cellX = lp.cellX = mEmptyCell[0];
1109 si.cellX = lp.cellY = mEmptyCell[1];
1110 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001111 if (d.dragView.hasDrawn()) {
1112 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1113 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001114 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001115 mCurrentDragView.setVisibility(VISIBLE);
1116 }
Adam Cohene9166b22011-07-08 17:11:11 -07001117 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001118 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001119 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001120 }
1121 mInfo.add(item);
1122 }
1123
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001124 // This is used so the item doesn't immediately appear in the folder when added. In one case
1125 // we need to create the illusion that the item isn't added back to the folder yet, to
1126 // to correspond to the animation of the icon back into the folder. This is
1127 public void hideItem(ShortcutInfo info) {
1128 View v = getViewForInfo(info);
1129 v.setVisibility(INVISIBLE);
1130 }
1131 public void showItem(ShortcutInfo info) {
1132 View v = getViewForInfo(info);
1133 v.setVisibility(VISIBLE);
1134 }
1135
Adam Cohenbfbfd262011-06-13 16:55:12 -07001136 public void onAdd(ShortcutInfo item) {
1137 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001138 // If the item was dropped onto this open folder, we have done the work associated
1139 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001140 if (mSuppressOnAdd) return;
1141 if (!findAndSetEmptyCells(item)) {
1142 // The current layout is full, can we expand it?
1143 setupContentForNumItems(getItemCount() + 1);
1144 findAndSetEmptyCells(item);
1145 }
1146 createAndAddShortcut(item);
1147 LauncherModel.addOrMoveItemInDatabase(
1148 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1149 }
1150
Adam Cohena9cf38f2011-05-02 15:36:58 -07001151 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001152 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001153 // If this item is being dragged from this open folder, we have already handled
1154 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001155 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001156 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001157 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001158 if (mState == STATE_ANIMATING) {
1159 mRearrangeOnClose = true;
1160 } else {
1161 setupContentForNumItems(getItemCount());
1162 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001163 if (getItemCount() <= 1) {
1164 replaceFolderWithFinalItem();
1165 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001166 }
Adam Cohen7c693212011-05-18 15:26:57 -07001167
Adam Cohendf1e4e82011-06-24 15:57:39 -07001168 private View getViewForInfo(ShortcutInfo item) {
1169 for (int j = 0; j < mContent.getCountY(); j++) {
1170 for (int i = 0; i < mContent.getCountX(); i++) {
1171 View v = mContent.getChildAt(i, j);
1172 if (v.getTag() == item) {
1173 return v;
1174 }
1175 }
1176 }
1177 return null;
1178 }
1179
Adam Cohen76078c42011-06-09 15:06:52 -07001180 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001181 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001182 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001183
Adam Cohen76fc0852011-06-17 13:26:23 -07001184 public void onTitleChanged(CharSequence title) {
1185 }
Adam Cohen76078c42011-06-09 15:06:52 -07001186
Adam Cohen7c693212011-05-18 15:26:57 -07001187 public ArrayList<View> getItemsInReadingOrder() {
1188 if (mItemsInvalidated) {
1189 mItemsInReadingOrder.clear();
1190 for (int j = 0; j < mContent.getCountY(); j++) {
1191 for (int i = 0; i < mContent.getCountX(); i++) {
1192 View v = mContent.getChildAt(i, j);
1193 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001194 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001195 }
1196 }
1197 }
1198 mItemsInvalidated = false;
1199 }
1200 return mItemsInReadingOrder;
1201 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001202
1203 public void getLocationInDragLayer(int[] loc) {
1204 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1205 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001206
1207 public void onFocusChange(View v, boolean hasFocus) {
1208 if (v == mFolderName && hasFocus) {
1209 startEditingFolderName();
1210 }
1211 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001212
1213 @Override
1214 public void getHitRectRelativeToDragLayer(Rect outRect) {
1215 getHitRect(outRect);
1216 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217}