blob: 808d85d66297e1d14de556008277be27d1a5ed0f [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Adam Cohendf2cc412011-04-27 16:56:57 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Adam Cohendf2cc412011-04-27 16:56:57 -070021import android.animation.ObjectAnimator;
22import android.animation.PropertyValuesHolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.content.Context;
Adam Cohen76fc0852011-06-17 13:26:23 -070024import android.content.res.Resources;
Winson Chung043f2af2012-03-01 16:09:54 -080025import android.graphics.PointF;
Romain Guyfb5411e2010-02-24 10:04:17 -080026import android.graphics.Rect;
Adam Cohenbadf71e2011-05-26 19:08:29 -070027import android.graphics.drawable.Drawable;
Alan Viverette4cda5b72013-08-28 17:53:41 -070028import android.os.SystemClock;
Adam Cohen7a14d0b2011-06-24 11:36:35 -070029import android.text.InputType;
Adam Cohene601a432011-07-26 21:51:30 -070030import android.text.Selection;
31import android.text.Spannable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.util.AttributeSet;
Winson Chung892c74d2013-08-22 16:15:50 -070033import android.util.DisplayMetrics;
Adam Cohen3bf84d32012-05-07 20:17:14 -070034import android.util.Log;
Winson Chung892c74d2013-08-22 16:15:50 -070035import android.util.TypedValue;
Adam Cohen76fc0852011-06-17 13:26:23 -070036import android.view.ActionMode;
37import android.view.KeyEvent;
Adam Cohendf2cc412011-04-27 16:56:57 -070038import android.view.LayoutInflater;
Adam Cohen76fc0852011-06-17 13:26:23 -070039import android.view.Menu;
40import android.view.MenuItem;
Adam Cohen0c872ba2011-05-05 10:34:16 -070041import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.view.View;
Adam Cohen3371da02011-10-25 21:38:29 -070043import android.view.accessibility.AccessibilityEvent;
44import android.view.accessibility.AccessibilityManager;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -070045import android.view.animation.AccelerateInterpolator;
46import android.view.animation.Interpolator;
Adam Cohen76fc0852011-06-17 13:26:23 -070047import android.view.inputmethod.EditorInfo;
48import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070050import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070051import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052
Daniel Sandler325dc232013-06-05 22:57:57 -040053import com.android.launcher3.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080054
Adam Cohenc0dcf592011-06-01 15:30:43 -070055import java.util.ArrayList;
Adam Cohen3bf84d32012-05-07 20:17:14 -070056import java.util.Collections;
57import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -070058
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059/**
60 * Represents a set of icons chosen by the user or generated by the system.
61 */
Adam Cohen8dfcba42011-07-07 16:38:18 -070062public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
Adam Cohenea0818d2011-09-30 20:06:58 -070063 View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
64 View.OnFocusChangeListener {
Adam Cohendf2cc412011-04-27 16:56:57 -070065 private static final String TAG = "Launcher.Folder";
66
Adam Cohen4eac29a2011-07-11 17:53:37 -070067 protected DragController mDragController;
68 protected Launcher mLauncher;
69 protected FolderInfo mInfo;
70
Adam Cohendf2cc412011-04-27 16:56:57 -070071 static final int STATE_NONE = -1;
72 static final int STATE_SMALL = 0;
73 static final int STATE_ANIMATING = 1;
74 static final int STATE_OPEN = 2;
75
76 private int mExpandDuration;
77 protected CellLayout mContent;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070078 private ScrollView mScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070079 private final LayoutInflater mInflater;
80 private final IconCache mIconCache;
81 private int mState = STATE_NONE;
Adam Cohenbfbfd262011-06-13 16:55:12 -070082 private static final int REORDER_ANIMATION_DURATION = 230;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070083 private static final int REORDER_DELAY = 250;
Adam Cohenbfbfd262011-06-13 16:55:12 -070084 private static final int ON_EXIT_CLOSE_DELAY = 800;
Adam Cohen2801caf2011-05-13 20:57:39 -070085 private boolean mRearrangeOnClose = false;
86 private FolderIcon mFolderIcon;
87 private int mMaxCountX;
88 private int mMaxCountY;
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 Cohen76fc0852011-06-17 13:26:23 -0700111 private boolean mIsEditingName = false;
112 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700113
Adam Cohena65beee2011-06-27 21:32:23 -0700114 private static String sDefaultFolderName;
115 private static String sHintText;
116
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700117 private int DRAG_MODE_NONE = 0;
118 private int DRAG_MODE_REORDER = 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700119 private int mDragMode = DRAG_MODE_NONE;
120
Adam Cohenfb91f302012-06-11 15:45:18 -0700121 private boolean mDestroyed;
122
Alan Viverette4cda5b72013-08-28 17:53:41 -0700123 private AutoScrollHelper mAutoScrollHelper;
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700124
Michael Jurka1e2f4652013-07-08 18:03:46 -0700125 private Runnable mDeferredAction;
126 private boolean mDeferDropAfterUninstall;
127 private boolean mUninstallSuccessful;
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);
Winson Chung5f8afe62013-08-12 16:19:28 -0700137
138 LauncherAppState app = LauncherAppState.getInstance();
139 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700141 mInflater = LayoutInflater.from(context);
Winson Chung5f8afe62013-08-12 16:19:28 -0700142 mIconCache = app.getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800143
144 Resources res = getResources();
Michael Jurka414300a2013-08-27 15:42:35 +0200145 mMaxCountX = (int) grid.numColumns;
Winson Chung5f8afe62013-08-12 16:19:28 -0700146 mMaxCountY = mMaxNumItems = Integer.MAX_VALUE;
Adam Cohen76fc0852011-06-17 13:26:23 -0700147
148 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700149 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700150
Adam Cohen76fc0852011-06-17 13:26:23 -0700151 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700152
153 if (sDefaultFolderName == null) {
154 sDefaultFolderName = res.getString(R.string.folder_name);
155 }
Adam Cohena65beee2011-06-27 21:32:23 -0700156 if (sHintText == null) {
157 sHintText = res.getString(R.string.folder_hint_text);
158 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700159 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700160 // We need this view to be focusable in touch mode so that when text editing of the folder
161 // name is complete, we have something to focus on, thus hiding the cursor and giving
162 // reliable behvior when clicking the text field (since it will always gain focus on click).
163 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 }
165
166 @Override
167 protected void onFinishInflate() {
168 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700169 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700170 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700171
Winson Chung5f8afe62013-08-12 16:19:28 -0700172 LauncherAppState app = LauncherAppState.getInstance();
173 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
174
Winson Chung5f8afe62013-08-12 16:19:28 -0700175 mContent.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
Adam Cohen2801caf2011-05-13 20:57:39 -0700176 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700177 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700178 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700179 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
180 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700181 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700182
183 // We find out how tall the text view wants to be (it is set to wrap_content), so that
184 // we can allocate the appropriate amount of space for it.
185 int measureSpec = MeasureSpec.UNSPECIFIED;
186 mFolderName.measure(measureSpec, measureSpec);
187 mFolderNameHeight = mFolderName.getMeasuredHeight();
188
189 // We disable action mode for now since it messes up the view on phones
190 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700191 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700192 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700193 mFolderName.setInputType(mFolderName.getInputType() |
194 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Alan Viverette4cda5b72013-08-28 17:53:41 -0700195 mAutoScrollHelper = new FolderAutoScrollHelper(mScrollView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700197
Adam Cohen76fc0852011-06-17 13:26:23 -0700198 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
199 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
200 return false;
201 }
202
203 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
204 return false;
205 }
206
207 public void onDestroyActionMode(ActionMode mode) {
208 }
209
210 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
211 return false;
212 }
213 };
214
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700216 Object tag = v.getTag();
217 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700218 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700219 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220 }
221
222 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700223 // Return if global dragging is not enabled
224 if (!mLauncher.isDraggingEnabled()) return true;
225
Adam Cohendf2cc412011-04-27 16:56:57 -0700226 Object tag = v.getTag();
227 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700228 ShortcutInfo item = (ShortcutInfo) tag;
229 if (!v.isInTouchMode()) {
230 return false;
231 }
232
Winson Chung7d7541e2011-09-16 20:14:36 -0700233 mLauncher.dismissFolderCling(null);
234
Adam Cohendf2cc412011-04-27 16:56:57 -0700235 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700236 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700237 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700238
239 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700240 mEmptyCell[0] = item.cellX;
241 mEmptyCell[1] = item.cellY;
242 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700243
244 mContent.removeView(mCurrentDragView);
245 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700246 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700247 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700248 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 return true;
250 }
251
Adam Cohen76fc0852011-06-17 13:26:23 -0700252 public boolean isEditingName() {
253 return mIsEditingName;
254 }
255
256 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700257 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700258 mIsEditingName = true;
259 }
260
261 public void dismissEditingName() {
262 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
263 doneEditingFolderName(true);
264 }
265
266 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700267 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700268 // Convert to a string here to ensure that no other state associated with the text field
269 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700270 String newTitle = mFolderName.getText().toString();
271 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700272 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700273
Adam Cohen3371da02011-10-25 21:38:29 -0700274 if (commit) {
275 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700276 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700277 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700278 // In order to clear the focus from the text field, we set the focus on ourself. This
279 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
280 requestFocus();
281
Adam Cohene601a432011-07-26 21:51:30 -0700282 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700283 mIsEditingName = false;
284 }
285
286 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
287 if (actionId == EditorInfo.IME_ACTION_DONE) {
288 dismissEditingName();
289 return true;
290 }
291 return false;
292 }
293
294 public View getEditTextRegion() {
295 return mFolderName;
296 }
297
Adam Cohenbadf71e2011-05-26 19:08:29 -0700298 public Drawable getDragDrawable() {
299 return mIconDrawable;
300 }
301
Adam Cohen0c872ba2011-05-05 10:34:16 -0700302 /**
303 * We need to handle touch events to prevent them from falling through to the workspace below.
304 */
305 @Override
306 public boolean onTouchEvent(MotionEvent ev) {
307 return true;
308 }
309
Joe Onorato00acb122009-08-04 16:04:30 -0400310 public void setDragController(DragController dragController) {
311 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800312 }
313
Adam Cohen2801caf2011-05-13 20:57:39 -0700314 void setFolderIcon(FolderIcon icon) {
315 mFolderIcon = icon;
316 }
317
Adam Cohen3371da02011-10-25 21:38:29 -0700318 @Override
319 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
320 // When the folder gets focus, we don't want to announce the list of items.
321 return true;
322 }
323
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800324 /**
325 * @return the FolderInfo object associated with this folder
326 */
327 FolderInfo getInfo() {
328 return mInfo;
329 }
330
Adam Cohen3bf84d32012-05-07 20:17:14 -0700331 private class GridComparator implements Comparator<ShortcutInfo> {
332 int mNumCols;
333 public GridComparator(int numCols) {
334 mNumCols = numCols;
335 }
336
337 @Override
338 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
339 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
340 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
341 return (lhIndex - rhIndex);
342 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700343 }
344
345 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
346 int maxX = 0;
347 int count = items.size();
348 for (int i = 0; i < count; i++) {
349 ShortcutInfo item = items.get(i);
350 if (item.cellX > maxX) {
351 maxX = item.cellX;
352 }
353 }
Adam Cohen691a5792012-05-11 14:27:30 -0700354
355 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700356 Collections.sort(items, gridComparator);
357 final int countX = mContent.getCountX();
358 for (int i = 0; i < count; i++) {
359 int x = i % countX;
360 int y = i / countX;
361 ShortcutInfo item = items.get(i);
362 item.cellX = x;
363 item.cellY = y;
364 }
365 }
366
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800367 void bind(FolderInfo info) {
368 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700369 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700370 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700371 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700372 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700373 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700374 for (int i = 0; i < children.size(); i++) {
375 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700376 if (!createAndAddShortcut(child)) {
377 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700378 } else {
379 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700380 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700381 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700382
Adam Cohen0057bbc2011-08-12 18:30:51 -0700383 // We rearrange the items in case there are any empty gaps
384 setupContentForNumItems(count);
385
Adam Cohenc508b2d2011-06-28 14:41:44 -0700386 // If our folder has too many items we prune them from the list. This is an issue
387 // when upgrading from the old Folders implementation which could contain an unlimited
388 // number of items.
389 for (ShortcutInfo item: overflow) {
390 mInfo.remove(item);
391 LauncherModel.deleteItemFromDatabase(mLauncher, item);
392 }
393
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700394 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700395 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700396 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700397
Adam Cohenafb01ee2011-06-23 15:38:03 -0700398 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700399 mFolderName.setText(mInfo.title);
400 } else {
401 mFolderName.setText("");
402 }
Adam Cohen691a5792012-05-11 14:27:30 -0700403 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700404 }
405
406 /**
407 * Creates a new UserFolder, inflated from R.layout.user_folder.
408 *
409 * @param context The application's context.
410 *
411 * @return A new UserFolder.
412 */
413 static Folder fromXml(Context context) {
414 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
415 }
416
417 /**
418 * This method is intended to make the UserFolder to be visually identical in size and position
419 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
420 */
421 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700422 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800423 setScaleX(0.8f);
424 setScaleY(0.8f);
425 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700426 mState = STATE_SMALL;
427 }
428
429 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700430 positionAndSizeAsIcon();
431
Adam Cohen8e776a62011-06-28 18:10:06 -0700432 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700433 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800434 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
435 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
436 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200437 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700438 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800439
Adam Cohen2801caf2011-05-13 20:57:39 -0700440 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700441 @Override
442 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700443 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700444 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700445 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700446 mState = STATE_ANIMATING;
447 }
448 @Override
449 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700450 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700451 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700452 Cling cling = mLauncher.showFirstRunFoldersCling();
453 if (cling != null) {
454 cling.bringToFront();
455 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700456 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700457 }
458 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700459 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700460 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100461 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700462 }
463
Adam Cohen3371da02011-10-25 21:38:29 -0700464 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700465 AccessibilityManager accessibilityManager = (AccessibilityManager)
466 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
467 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700468 AccessibilityEvent event = AccessibilityEvent.obtain(type);
469 onInitializeAccessibilityEvent(event);
470 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700471 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700472 }
473 }
474
Adam Cohenac56cff2011-09-28 20:45:37 -0700475 private void setFocusOnFirstChild() {
476 View firstChild = mContent.getChildAt(0, 0);
477 if (firstChild != null) {
478 firstChild.requestFocus();
479 }
480 }
481
Adam Cohendf2cc412011-04-27 16:56:57 -0700482 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700483 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800484 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
485 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
486 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200487 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700488 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700489
Adam Cohen2801caf2011-05-13 20:57:39 -0700490 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700491 @Override
492 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700493 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700494 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700495 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700496 }
497 @Override
498 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700499 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700500 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700501 mState = STATE_ANIMATING;
502 }
503 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700504 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700505 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100506 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700507 }
508
Adam Cohencb3382b2011-05-24 14:07:08 -0700509 public boolean acceptDrop(DragObject d) {
510 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700511 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700512 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
513 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
514 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700515 }
516
Adam Cohendf2cc412011-04-27 16:56:57 -0700517 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
518 int[] emptyCell = new int[2];
519 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
520 item.cellX = emptyCell[0];
521 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700522 return true;
523 } else {
524 return false;
525 }
526 }
527
Adam Cohenc508b2d2011-06-28 14:41:44 -0700528 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700529 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700530 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700531 textView.setCompoundDrawablesWithIntrinsicBounds(null,
532 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
533 textView.setText(item.title);
534 textView.setTag(item);
535
536 textView.setOnClickListener(this);
537 textView.setOnLongClickListener(this);
538
Adam Cohenc508b2d2011-06-28 14:41:44 -0700539 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700540 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700541 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
542 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700543 // This shouldn't happen, log it.
544 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700545 if (!findAndSetEmptyCells(item)) {
546 return false;
547 }
548 }
549
Adam Cohendf2cc412011-04-27 16:56:57 -0700550 CellLayout.LayoutParams lp =
551 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
552 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700553 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700554 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700555 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700556 }
557
Adam Cohencb3382b2011-05-24 14:07:08 -0700558 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700559 mPreviousTargetCell[0] = -1;
560 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700561 mOnExitAlarm.cancelAlarm();
562 }
563
564 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
565 public void onAlarm(Alarm alarm) {
566 realTimeReorder(mEmptyCell, mTargetCell);
567 }
568 };
569
570 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
571 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
572 return true;
573 } else {
574 return false;
575 }
576 }
577
578 private void realTimeReorder(int[] empty, int[] target) {
579 boolean wrap;
580 int startX;
581 int endX;
582 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700583 int delay = 0;
584 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700585 if (readingOrderGreaterThan(target, empty)) {
586 wrap = empty[0] >= mContent.getCountX() - 1;
587 startY = wrap ? empty[1] + 1 : empty[1];
588 for (int y = startY; y <= target[1]; y++) {
589 startX = y == empty[1] ? empty[0] + 1 : 0;
590 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
591 for (int x = startX; x <= endX; x++) {
592 View v = mContent.getChildAt(x,y);
593 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800594 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700595 empty[0] = x;
596 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700597 delay += delayAmount;
598 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700599 }
600 }
601 }
602 } else {
603 wrap = empty[0] == 0;
604 startY = wrap ? empty[1] - 1 : empty[1];
605 for (int y = startY; y >= target[1]; y--) {
606 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
607 endX = y > target[1] ? 0 : target[0];
608 for (int x = startX; x >= endX; x--) {
609 View v = mContent.getChildAt(x,y);
610 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800611 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700612 empty[0] = x;
613 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700614 delay += delayAmount;
615 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700616 }
617 }
618 }
619 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700620 }
621
Adam Cohen2374abf2013-04-16 14:56:57 -0700622 public boolean isLayoutRtl() {
623 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
624 }
625
Adam Cohencb3382b2011-05-24 14:07:08 -0700626 public void onDragOver(DragObject d) {
Alan Viverette4cda5b72013-08-28 17:53:41 -0700627 final DragView dragView = d.dragView;
628 final int scrollOffset = mScrollView.getScrollY();
629 final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700630 r[0] -= getPaddingLeft();
631 r[1] -= getPaddingTop();
632
Alan Viverette4cda5b72013-08-28 17:53:41 -0700633 final long downTime = SystemClock.uptimeMillis();
634 final MotionEvent translatedEv = MotionEvent.obtain(
635 downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);
636
637 if (!mAutoScrollHelper.isEnabled()) {
638 mAutoScrollHelper.setEnabled(true);
639 }
640
641 final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
642 translatedEv.recycle();
643
644 if (handled) {
645 mReorderAlarm.cancelAlarm();
646 } else {
647 mTargetCell = mContent.findNearestArea(
648 (int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700649 if (isLayoutRtl()) {
650 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700651 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700652 if (mTargetCell[0] != mPreviousTargetCell[0]
653 || mTargetCell[1] != mPreviousTargetCell[1]) {
654 mReorderAlarm.cancelAlarm();
655 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
656 mReorderAlarm.setAlarm(REORDER_DELAY);
657 mPreviousTargetCell[0] = mTargetCell[0];
658 mPreviousTargetCell[1] = mTargetCell[1];
659 mDragMode = DRAG_MODE_REORDER;
660 } else {
661 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700662 }
Adam Cohenbfbfd262011-06-13 16:55:12 -0700663 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700664 }
665
Adam Cohenbfbfd262011-06-13 16:55:12 -0700666 // This is used to compute the visual center of the dragView. The idea is that
667 // the visual center represents the user's interpretation of where the item is, and hence
668 // is the appropriate point to use when determining drop location.
669 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
670 DragView dragView, float[] recycle) {
671 float res[];
672 if (recycle == null) {
673 res = new float[2];
674 } else {
675 res = recycle;
676 }
677
678 // These represent the visual top and left of drag view if a dragRect was provided.
679 // If a dragRect was not provided, then they correspond to the actual view left and
680 // top, as the dragRect is in that case taken to be the entire dragView.
681 // R.dimen.dragViewOffsetY.
682 int left = x - xOffset;
683 int top = y - yOffset;
684
685 // In order to find the visual center, we shift by half the dragRect
686 res[0] = left + dragView.getDragRegion().width() / 2;
687 res[1] = top + dragView.getDragRegion().height() / 2;
688
689 return res;
690 }
691
692 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
693 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700694 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700695 }
696 };
697
Adam Cohen95bb8002011-07-03 23:40:28 -0700698 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700699 mLauncher.closeFolder();
700 mCurrentDragInfo = null;
701 mCurrentDragView = null;
702 mSuppressOnAdd = false;
703 mRearrangeOnClose = true;
704 }
705
Adam Cohencb3382b2011-05-24 14:07:08 -0700706 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700707 // Exiting folder; stop the auto scroller.
Alan Viverette4cda5b72013-08-28 17:53:41 -0700708 mAutoScrollHelper.setEnabled(false);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700709 // We only close the folder if this is a true drag exit, ie. not because
710 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700711 if (!d.dragComplete) {
712 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
713 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
714 }
715 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700716 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700717 }
718
Michael Jurka1e2f4652013-07-08 18:03:46 -0700719 public void onDropCompleted(final View target, final DragObject d,
720 final boolean isFlingToDelete, final boolean success) {
721 if (mDeferDropAfterUninstall) {
Michael Jurkaf3007582013-08-21 14:33:57 +0200722 Log.d(TAG, "Deferred handling drop because waiting for uninstall.");
Michael Jurka1e2f4652013-07-08 18:03:46 -0700723 mDeferredAction = new Runnable() {
724 public void run() {
725 onDropCompleted(target, d, isFlingToDelete, success);
726 mDeferredAction = null;
727 }
728 };
729 return;
730 }
731
732 boolean beingCalledAfterUninstall = mDeferredAction != null;
733 boolean successfulDrop =
734 success && (!beingCalledAfterUninstall || mUninstallSuccessful);
Winson Chung5f8afe62013-08-12 16:19:28 -0700735
Michael Jurka1e2f4652013-07-08 18:03:46 -0700736 if (successfulDrop) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700737 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700738 replaceFolderWithFinalItem();
739 }
740 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700741 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700742 // The drag failed, we need to return the item to the folder
743 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700744 }
745
746 if (target != this) {
747 if (mOnExitAlarm.alarmPending()) {
748 mOnExitAlarm.cancelAlarm();
Michael Jurka54554252013-08-01 12:52:23 +0200749 if (!successfulDrop) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700750 mSuppressFolderDeletion = true;
751 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700752 completeDragExit();
753 }
754 }
Winson Chung5f8afe62013-08-12 16:19:28 -0700755
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700756 mDeleteFolderOnDropCompleted = false;
757 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700758 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700759 mCurrentDragInfo = null;
760 mCurrentDragView = null;
761 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700762
763 // Reordering may have occured, and we need to save the new item locations. We do this once
764 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700765 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700766 }
767
Michael Jurka1e2f4652013-07-08 18:03:46 -0700768 public void deferCompleteDropAfterUninstallActivity() {
769 mDeferDropAfterUninstall = true;
770 }
771
772 public void onUninstallActivityReturned(boolean success) {
773 mDeferDropAfterUninstall = false;
774 mUninstallSuccessful = success;
775 if (mDeferredAction != null) {
776 mDeferredAction.run();
777 }
778 }
779
Winson Chunga48487a2012-03-20 16:19:37 -0700780 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800781 public boolean supportsFlingToDelete() {
782 return true;
783 }
784
Winson Chunga48487a2012-03-20 16:19:37 -0700785 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
786 // Do nothing
787 }
788
789 @Override
790 public void onFlingToDeleteCompleted() {
791 // Do nothing
792 }
793
Adam Cohen4045eb72011-10-06 11:44:26 -0700794 private void updateItemLocationsInDatabase() {
795 ArrayList<View> list = getItemsInReadingOrder();
796 for (int i = 0; i < list.size(); i++) {
797 View v = list.get(i);
798 ItemInfo info = (ItemInfo) v.getTag();
799 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
800 info.cellX, info.cellY);
801 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700802 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700803
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700804 private void updateItemLocationsInDatabaseBatch() {
805 ArrayList<View> list = getItemsInReadingOrder();
806 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
807 for (int i = 0; i < list.size(); i++) {
808 View v = list.get(i);
809 ItemInfo info = (ItemInfo) v.getTag();
810 items.add(info);
811 }
812
813 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
814 }
815
Adam Cohene25af792013-06-06 23:08:25 -0700816 public void addItemLocationsInDatabase() {
817 ArrayList<View> list = getItemsInReadingOrder();
818 for (int i = 0; i < list.size(); i++) {
819 View v = list.get(i);
820 ItemInfo info = (ItemInfo) v.getTag();
821 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
822 info.cellX, info.cellY, false);
823 }
824 }
825
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700826 public void notifyDrop() {
827 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700828 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700829 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700830 }
831
832 public boolean isDropEnabled() {
833 return true;
834 }
835
Adam Cohen4045eb72011-10-06 11:44:26 -0700836 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700837 ArrayList<View> list = getItemsInReadingOrder();
838
839 int countX = mContent.getCountX();
840 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700841 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700842
Adam Cohen7c693212011-05-18 15:26:57 -0700843 while (!done) {
844 int oldCountX = countX;
845 int oldCountY = countY;
846 if (countX * countY < count) {
847 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800848 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700849 countX++;
850 } else if (countY < mMaxCountY) {
851 countY++;
852 }
853 if (countY == 0) countY++;
854 } else if ((countY - 1) * countX >= count && countY >= countX) {
855 countY = Math.max(0, countY - 1);
856 } else if ((countX - 1) * countY >= count) {
857 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700858 }
Adam Cohen7c693212011-05-18 15:26:57 -0700859 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700860 }
Adam Cohen7c693212011-05-18 15:26:57 -0700861 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700862 arrangeChildren(list);
863 }
864
865 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800866 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700867 }
868
869 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700870 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700871
Winson Chung892c74d2013-08-22 16:15:50 -0700872 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700873 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700874 int height = getFolderHeight();
Adam Cohen2801caf2011-05-13 20:57:39 -0700875
Adam Cohen307fe232012-08-16 17:55:58 -0700876 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700877
Adam Cohen307fe232012-08-16 17:55:58 -0700878 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
879 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700880 int centeredLeft = centerX - width / 2;
881 int centeredTop = centerY - height / 2;
882
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800883 int currentPage = mLauncher.getWorkspace().getCurrentPage();
884 // In case the workspace is scrolling, we need to use the final scroll to compute
885 // the folders bounds.
886 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700887 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800888 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700889 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700890 Rect bounds = new Rect();
891 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800892 // We reset the workspaces scroll
893 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700894
Adam Cohen35e7e642011-07-17 14:47:18 -0700895 // We need to bound the folder to the currently visible CellLayoutChildren
896 int left = Math.min(Math.max(bounds.left, centeredLeft),
897 bounds.left + bounds.width() - width);
898 int top = Math.min(Math.max(bounds.top, centeredTop),
899 bounds.top + bounds.height() - height);
900 // If the folder doesn't fit within the bounds, center it about the desired bounds
901 if (width >= bounds.width()) {
902 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700903 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700904 if (height >= bounds.height()) {
905 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700906 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700907
908 int folderPivotX = width / 2 + (centeredLeft - left);
909 int folderPivotY = height / 2 + (centeredTop - top);
910 setPivotX(folderPivotX);
911 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700912 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700913 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700914 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700915 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700916
Adam Cohen662b5982011-12-13 17:45:21 -0800917 lp.width = width;
918 lp.height = height;
919 lp.x = left;
920 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700921 }
922
Adam Cohen268c4752012-06-06 17:47:33 -0700923 float getPivotXForIconAnimation() {
924 return mFolderIconPivotX;
925 }
926 float getPivotYForIconAnimation() {
927 return mFolderIconPivotY;
928 }
929
Adam Cohen2801caf2011-05-13 20:57:39 -0700930 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700931 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700932
Adam Cohen8e776a62011-06-28 18:10:06 -0700933 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700934 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700935 lp = new DragLayer.LayoutParams(0, 0);
936 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700937 setLayoutParams(lp);
938 }
939 centerAboutIcon();
940 }
941
Winson Chung892c74d2013-08-22 16:15:50 -0700942 private int getContentAreaHeight() {
943 LauncherAppState app = LauncherAppState.getInstance();
944 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
945 Rect workspacePadding = grid.getWorkspacePadding(grid.isLandscape ?
946 CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
947 int maxContentAreaHeight = grid.availableHeightPx -
948 4 * grid.edgeMarginPx -
949 workspacePadding.top - workspacePadding.bottom -
950 getPaddingTop() - getPaddingBottom() -
951 mFolderNameHeight;
952 return Math.min(maxContentAreaHeight,
953 mContent.getDesiredHeight());
954 }
955
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700956 private int getFolderHeight() {
Winson Chung892c74d2013-08-22 16:15:50 -0700957 int height = getPaddingTop() + getPaddingBottom()
958 + getContentAreaHeight() + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700959 return height;
960 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700961
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700962 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700963 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
964 int height = getFolderHeight();
965 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
966 MeasureSpec.EXACTLY);
Winson Chung892c74d2013-08-22 16:15:50 -0700967 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(getContentAreaHeight(),
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700968 MeasureSpec.EXACTLY);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700969 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
970 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
971 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -0700972 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
973 setMeasuredDimension(width, height);
974 }
975
Adam Cohen2801caf2011-05-13 20:57:39 -0700976 private void arrangeChildren(ArrayList<View> list) {
977 int[] vacant = new int[2];
978 if (list == null) {
979 list = getItemsInReadingOrder();
980 }
981 mContent.removeAllViews();
982
983 for (int i = 0; i < list.size(); i++) {
984 View v = list.get(i);
985 mContent.getVacantCell(vacant, 1, 1);
986 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
987 lp.cellX = vacant[0];
988 lp.cellY = vacant[1];
989 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -0700990 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
991 info.cellX = vacant[0];
992 info.cellY = vacant[1];
993 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
994 info.cellX, info.cellY);
995 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700996 boolean insert = false;
997 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
998 }
Adam Cohen7c693212011-05-18 15:26:57 -0700999 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001000 }
1001
Adam Cohena9cf38f2011-05-02 15:36:58 -07001002 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001003 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001004 }
1005
1006 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001007 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001008 }
1009
Adam Cohen2801caf2011-05-13 20:57:39 -07001010 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001011 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001012 if (parent != null) {
1013 parent.removeView(this);
1014 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001015 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001016 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001017 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001018
Adam Cohen2801caf2011-05-13 20:57:39 -07001019 if (mRearrangeOnClose) {
1020 setupContentForNumItems(getItemCount());
1021 mRearrangeOnClose = false;
1022 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001023 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001024 if (!mDragInProgress && !mSuppressFolderDeletion) {
1025 replaceFolderWithFinalItem();
1026 } else if (mDragInProgress) {
1027 mDeleteFolderOnDropCompleted = true;
1028 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001029 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001030 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001031 }
1032
1033 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001034 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001035 Runnable onCompleteRunnable = new Runnable() {
1036 @Override
1037 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001038 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001039
Adam Cohenc5e63f32012-07-12 16:16:57 -07001040 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001041 // Move the item from the folder to the workspace, in the position of the folder
1042 if (getItemCount() == 1) {
1043 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001044 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001045 finalItem);
1046 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001047 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001048 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001049 if (getItemCount() <= 1) {
1050 // Remove the folder
1051 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1052 cellLayout.removeView(mFolderIcon);
1053 if (mFolderIcon instanceof DropTarget) {
1054 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1055 }
1056 mLauncher.removeFolder(mInfo);
1057 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001058 // We add the child after removing the folder to prevent both from existing at
Winson Chung0e6a7132013-08-23 12:55:10 -07001059 // the same time in the CellLayout. We need to add the new item with addInScreenFromBind()
1060 // to ensure that hotseat items are placed correctly.
Adam Cohenc5e63f32012-07-12 16:16:57 -07001061 if (child != null) {
Winson Chung0e6a7132013-08-23 12:55:10 -07001062 mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001063 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1064 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001065 }
1066 };
1067 View finalChild = getItemAt(0);
1068 if (finalChild != null) {
1069 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001070 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001071 mDestroyed = true;
1072 }
1073
1074 boolean isDestroyed() {
1075 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001076 }
1077
Adam Cohenac56cff2011-09-28 20:45:37 -07001078 // This method keeps track of the last item in the folder for the purposes
1079 // of keyboard focus
1080 private void updateTextViewFocus() {
1081 View lastChild = getItemAt(getItemCount() - 1);
1082 getItemAt(getItemCount() - 1);
1083 if (lastChild != null) {
1084 mFolderName.setNextFocusDownId(lastChild.getId());
1085 mFolderName.setNextFocusRightId(lastChild.getId());
1086 mFolderName.setNextFocusLeftId(lastChild.getId());
1087 mFolderName.setNextFocusUpId(lastChild.getId());
1088 }
1089 }
1090
Adam Cohenbfbfd262011-06-13 16:55:12 -07001091 public void onDrop(DragObject d) {
1092 ShortcutInfo item;
Michael Jurkaeadbfc52013-09-04 00:45:37 +02001093 if (d.dragInfo instanceof AppInfo) {
Adam Cohenbfbfd262011-06-13 16:55:12 -07001094 // Came from all apps -- make a copy
Michael Jurkaeadbfc52013-09-04 00:45:37 +02001095 item = ((AppInfo) d.dragInfo).makeShortcut();
Adam Cohenbfbfd262011-06-13 16:55:12 -07001096 item.spanX = 1;
1097 item.spanY = 1;
1098 } else {
1099 item = (ShortcutInfo) d.dragInfo;
1100 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001101 // Dragged from self onto self, currently this is the only path possible, however
1102 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001103 if (item == mCurrentDragInfo) {
1104 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1105 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1106 si.cellX = lp.cellX = mEmptyCell[0];
1107 si.cellX = lp.cellY = mEmptyCell[1];
1108 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001109 if (d.dragView.hasDrawn()) {
1110 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1111 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001112 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001113 mCurrentDragView.setVisibility(VISIBLE);
1114 }
Adam Cohene9166b22011-07-08 17:11:11 -07001115 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001116 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001117 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001118 }
1119 mInfo.add(item);
1120 }
1121
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001122 // This is used so the item doesn't immediately appear in the folder when added. In one case
1123 // we need to create the illusion that the item isn't added back to the folder yet, to
1124 // to correspond to the animation of the icon back into the folder. This is
1125 public void hideItem(ShortcutInfo info) {
1126 View v = getViewForInfo(info);
1127 v.setVisibility(INVISIBLE);
1128 }
1129 public void showItem(ShortcutInfo info) {
1130 View v = getViewForInfo(info);
1131 v.setVisibility(VISIBLE);
1132 }
1133
Adam Cohenbfbfd262011-06-13 16:55:12 -07001134 public void onAdd(ShortcutInfo item) {
1135 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001136 // If the item was dropped onto this open folder, we have done the work associated
1137 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001138 if (mSuppressOnAdd) return;
1139 if (!findAndSetEmptyCells(item)) {
1140 // The current layout is full, can we expand it?
1141 setupContentForNumItems(getItemCount() + 1);
1142 findAndSetEmptyCells(item);
1143 }
1144 createAndAddShortcut(item);
1145 LauncherModel.addOrMoveItemInDatabase(
1146 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1147 }
1148
Adam Cohena9cf38f2011-05-02 15:36:58 -07001149 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001150 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001151 // If this item is being dragged from this open folder, we have already handled
1152 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001153 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001154 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001155 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001156 if (mState == STATE_ANIMATING) {
1157 mRearrangeOnClose = true;
1158 } else {
1159 setupContentForNumItems(getItemCount());
1160 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001161 if (getItemCount() <= 1) {
1162 replaceFolderWithFinalItem();
1163 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001164 }
Adam Cohen7c693212011-05-18 15:26:57 -07001165
Adam Cohendf1e4e82011-06-24 15:57:39 -07001166 private View getViewForInfo(ShortcutInfo item) {
1167 for (int j = 0; j < mContent.getCountY(); j++) {
1168 for (int i = 0; i < mContent.getCountX(); i++) {
1169 View v = mContent.getChildAt(i, j);
1170 if (v.getTag() == item) {
1171 return v;
1172 }
1173 }
1174 }
1175 return null;
1176 }
1177
Adam Cohen76078c42011-06-09 15:06:52 -07001178 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001179 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001180 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001181
Adam Cohen76fc0852011-06-17 13:26:23 -07001182 public void onTitleChanged(CharSequence title) {
1183 }
Adam Cohen76078c42011-06-09 15:06:52 -07001184
Adam Cohen7c693212011-05-18 15:26:57 -07001185 public ArrayList<View> getItemsInReadingOrder() {
1186 if (mItemsInvalidated) {
1187 mItemsInReadingOrder.clear();
1188 for (int j = 0; j < mContent.getCountY(); j++) {
1189 for (int i = 0; i < mContent.getCountX(); i++) {
1190 View v = mContent.getChildAt(i, j);
1191 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001192 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001193 }
1194 }
1195 }
1196 mItemsInvalidated = false;
1197 }
1198 return mItemsInReadingOrder;
1199 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001200
1201 public void getLocationInDragLayer(int[] loc) {
1202 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1203 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001204
1205 public void onFocusChange(View v, boolean hasFocus) {
1206 if (v == mFolderName && hasFocus) {
1207 startEditingFolderName();
1208 }
1209 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001210
1211 @Override
1212 public void getHitRectRelativeToDragLayer(Rect outRect) {
1213 getHitRect(outRect);
1214 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215}