blob: 47fc6c3f462cb335d4a6026c9bc808198dc716e5 [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;
Adam Cohen477828c2013-09-20 12:05:49 -0700146 mMaxCountY = (int) grid.numRows;
147 mMaxNumItems = mMaxCountX * mMaxCountY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700148
149 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700150 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700151
Adam Cohen76fc0852011-06-17 13:26:23 -0700152 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700153
154 if (sDefaultFolderName == null) {
155 sDefaultFolderName = res.getString(R.string.folder_name);
156 }
Adam Cohena65beee2011-06-27 21:32:23 -0700157 if (sHintText == null) {
158 sHintText = res.getString(R.string.folder_hint_text);
159 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700160 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700161 // We need this view to be focusable in touch mode so that when text editing of the folder
162 // name is complete, we have something to focus on, thus hiding the cursor and giving
163 // reliable behvior when clicking the text field (since it will always gain focus on click).
164 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 }
166
167 @Override
168 protected void onFinishInflate() {
169 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700170 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700171 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700172
Winson Chung5f8afe62013-08-12 16:19:28 -0700173 LauncherAppState app = LauncherAppState.getInstance();
174 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
175
Winson Chung5f8afe62013-08-12 16:19:28 -0700176 mContent.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
Adam Cohen2801caf2011-05-13 20:57:39 -0700177 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700178 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700179 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700180 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
181 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700182 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700183
184 // We find out how tall the text view wants to be (it is set to wrap_content), so that
185 // we can allocate the appropriate amount of space for it.
186 int measureSpec = MeasureSpec.UNSPECIFIED;
187 mFolderName.measure(measureSpec, measureSpec);
188 mFolderNameHeight = mFolderName.getMeasuredHeight();
189
190 // We disable action mode for now since it messes up the view on phones
191 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700192 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700193 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700194 mFolderName.setInputType(mFolderName.getInputType() |
195 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Alan Viverette4cda5b72013-08-28 17:53:41 -0700196 mAutoScrollHelper = new FolderAutoScrollHelper(mScrollView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800197 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700198
Adam Cohen76fc0852011-06-17 13:26:23 -0700199 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
200 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
201 return false;
202 }
203
204 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
205 return false;
206 }
207
208 public void onDestroyActionMode(ActionMode mode) {
209 }
210
211 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
212 return false;
213 }
214 };
215
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700217 Object tag = v.getTag();
218 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700219 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700220 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 }
222
223 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700224 // Return if global dragging is not enabled
225 if (!mLauncher.isDraggingEnabled()) return true;
226
Adam Cohendf2cc412011-04-27 16:56:57 -0700227 Object tag = v.getTag();
228 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700229 ShortcutInfo item = (ShortcutInfo) tag;
230 if (!v.isInTouchMode()) {
231 return false;
232 }
233
Winson Chung7d7541e2011-09-16 20:14:36 -0700234 mLauncher.dismissFolderCling(null);
235
Adam Cohendf2cc412011-04-27 16:56:57 -0700236 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700237 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700238 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700239
240 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700241 mEmptyCell[0] = item.cellX;
242 mEmptyCell[1] = item.cellY;
243 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700244
245 mContent.removeView(mCurrentDragView);
246 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700247 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700248 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700249 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800250 return true;
251 }
252
Adam Cohen76fc0852011-06-17 13:26:23 -0700253 public boolean isEditingName() {
254 return mIsEditingName;
255 }
256
257 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700258 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700259 mIsEditingName = true;
260 }
261
262 public void dismissEditingName() {
263 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
264 doneEditingFolderName(true);
265 }
266
267 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700268 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700269 // Convert to a string here to ensure that no other state associated with the text field
270 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700271 String newTitle = mFolderName.getText().toString();
272 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700273 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700274
Adam Cohen3371da02011-10-25 21:38:29 -0700275 if (commit) {
276 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700277 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700278 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700279 // In order to clear the focus from the text field, we set the focus on ourself. This
280 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
281 requestFocus();
282
Adam Cohene601a432011-07-26 21:51:30 -0700283 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700284 mIsEditingName = false;
285 }
286
287 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
288 if (actionId == EditorInfo.IME_ACTION_DONE) {
289 dismissEditingName();
290 return true;
291 }
292 return false;
293 }
294
295 public View getEditTextRegion() {
296 return mFolderName;
297 }
298
Adam Cohenbadf71e2011-05-26 19:08:29 -0700299 public Drawable getDragDrawable() {
300 return mIconDrawable;
301 }
302
Adam Cohen0c872ba2011-05-05 10:34:16 -0700303 /**
304 * We need to handle touch events to prevent them from falling through to the workspace below.
305 */
306 @Override
307 public boolean onTouchEvent(MotionEvent ev) {
308 return true;
309 }
310
Joe Onorato00acb122009-08-04 16:04:30 -0400311 public void setDragController(DragController dragController) {
312 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800313 }
314
Adam Cohen2801caf2011-05-13 20:57:39 -0700315 void setFolderIcon(FolderIcon icon) {
316 mFolderIcon = icon;
317 }
318
Adam Cohen3371da02011-10-25 21:38:29 -0700319 @Override
320 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
321 // When the folder gets focus, we don't want to announce the list of items.
322 return true;
323 }
324
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800325 /**
326 * @return the FolderInfo object associated with this folder
327 */
328 FolderInfo getInfo() {
329 return mInfo;
330 }
331
Adam Cohen3bf84d32012-05-07 20:17:14 -0700332 private class GridComparator implements Comparator<ShortcutInfo> {
333 int mNumCols;
334 public GridComparator(int numCols) {
335 mNumCols = numCols;
336 }
337
338 @Override
339 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
340 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
341 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
342 return (lhIndex - rhIndex);
343 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700344 }
345
346 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
347 int maxX = 0;
348 int count = items.size();
349 for (int i = 0; i < count; i++) {
350 ShortcutInfo item = items.get(i);
351 if (item.cellX > maxX) {
352 maxX = item.cellX;
353 }
354 }
Adam Cohen691a5792012-05-11 14:27:30 -0700355
356 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700357 Collections.sort(items, gridComparator);
358 final int countX = mContent.getCountX();
359 for (int i = 0; i < count; i++) {
360 int x = i % countX;
361 int y = i / countX;
362 ShortcutInfo item = items.get(i);
363 item.cellX = x;
364 item.cellY = y;
365 }
366 }
367
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800368 void bind(FolderInfo info) {
369 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700370 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700371 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700372 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700373 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700374 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700375 for (int i = 0; i < children.size(); i++) {
376 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700377 if (!createAndAddShortcut(child)) {
378 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700379 } else {
380 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700381 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700382 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700383
Adam Cohen0057bbc2011-08-12 18:30:51 -0700384 // We rearrange the items in case there are any empty gaps
385 setupContentForNumItems(count);
386
Adam Cohenc508b2d2011-06-28 14:41:44 -0700387 // If our folder has too many items we prune them from the list. This is an issue
388 // when upgrading from the old Folders implementation which could contain an unlimited
389 // number of items.
390 for (ShortcutInfo item: overflow) {
391 mInfo.remove(item);
392 LauncherModel.deleteItemFromDatabase(mLauncher, item);
393 }
394
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700395 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700396 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700397 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700398
Adam Cohenafb01ee2011-06-23 15:38:03 -0700399 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700400 mFolderName.setText(mInfo.title);
401 } else {
402 mFolderName.setText("");
403 }
Adam Cohen691a5792012-05-11 14:27:30 -0700404 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700405 }
406
407 /**
408 * Creates a new UserFolder, inflated from R.layout.user_folder.
409 *
410 * @param context The application's context.
411 *
412 * @return A new UserFolder.
413 */
414 static Folder fromXml(Context context) {
415 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
416 }
417
418 /**
419 * This method is intended to make the UserFolder to be visually identical in size and position
420 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
421 */
422 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700423 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800424 setScaleX(0.8f);
425 setScaleY(0.8f);
426 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700427 mState = STATE_SMALL;
428 }
429
430 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700431 positionAndSizeAsIcon();
432
Adam Cohen8e776a62011-06-28 18:10:06 -0700433 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700434 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800435 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
436 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
437 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200438 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700439 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800440
Adam Cohen2801caf2011-05-13 20:57:39 -0700441 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700442 @Override
443 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700444 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700445 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700446 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700447 mState = STATE_ANIMATING;
448 }
449 @Override
450 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700451 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700452 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700453 Cling cling = mLauncher.showFirstRunFoldersCling();
454 if (cling != null) {
455 cling.bringToFront();
456 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700457 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700458 }
459 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700460 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700461 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100462 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700463 }
464
Adam Cohen3371da02011-10-25 21:38:29 -0700465 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700466 AccessibilityManager accessibilityManager = (AccessibilityManager)
467 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
468 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700469 AccessibilityEvent event = AccessibilityEvent.obtain(type);
470 onInitializeAccessibilityEvent(event);
471 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700472 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700473 }
474 }
475
Adam Cohenac56cff2011-09-28 20:45:37 -0700476 private void setFocusOnFirstChild() {
477 View firstChild = mContent.getChildAt(0, 0);
478 if (firstChild != null) {
479 firstChild.requestFocus();
480 }
481 }
482
Adam Cohendf2cc412011-04-27 16:56:57 -0700483 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700484 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800485 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
486 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
487 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200488 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700489 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700490
Adam Cohen2801caf2011-05-13 20:57:39 -0700491 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700492 @Override
493 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700494 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700495 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700496 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700497 }
498 @Override
499 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700500 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700501 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700502 mState = STATE_ANIMATING;
503 }
504 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700505 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700506 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100507 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700508 }
509
Adam Cohencb3382b2011-05-24 14:07:08 -0700510 public boolean acceptDrop(DragObject d) {
511 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700512 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700513 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
514 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
515 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700516 }
517
Adam Cohendf2cc412011-04-27 16:56:57 -0700518 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
519 int[] emptyCell = new int[2];
520 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
521 item.cellX = emptyCell[0];
522 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700523 return true;
524 } else {
525 return false;
526 }
527 }
528
Adam Cohenc508b2d2011-06-28 14:41:44 -0700529 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohen477828c2013-09-20 12:05:49 -0700530 final BubbleTextView textView =
531 (BubbleTextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700532 textView.setCompoundDrawablesWithIntrinsicBounds(null,
533 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
534 textView.setText(item.title);
535 textView.setTag(item);
Adam Cohen477828c2013-09-20 12:05:49 -0700536 textView.setTextColor(getResources().getColor(R.color.folder_items_text_color));
537 textView.setShadowsEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700538
539 textView.setOnClickListener(this);
540 textView.setOnLongClickListener(this);
541
Adam Cohenc508b2d2011-06-28 14:41:44 -0700542 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700543 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700544 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
545 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700546 // This shouldn't happen, log it.
547 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700548 if (!findAndSetEmptyCells(item)) {
549 return false;
550 }
551 }
552
Adam Cohendf2cc412011-04-27 16:56:57 -0700553 CellLayout.LayoutParams lp =
554 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
555 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700556 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700557 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700558 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700559 }
560
Adam Cohencb3382b2011-05-24 14:07:08 -0700561 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700562 mPreviousTargetCell[0] = -1;
563 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700564 mOnExitAlarm.cancelAlarm();
565 }
566
567 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
568 public void onAlarm(Alarm alarm) {
569 realTimeReorder(mEmptyCell, mTargetCell);
570 }
571 };
572
573 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
574 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
575 return true;
576 } else {
577 return false;
578 }
579 }
580
581 private void realTimeReorder(int[] empty, int[] target) {
582 boolean wrap;
583 int startX;
584 int endX;
585 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700586 int delay = 0;
587 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700588 if (readingOrderGreaterThan(target, empty)) {
589 wrap = empty[0] >= mContent.getCountX() - 1;
590 startY = wrap ? empty[1] + 1 : empty[1];
591 for (int y = startY; y <= target[1]; y++) {
592 startX = y == empty[1] ? empty[0] + 1 : 0;
593 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
594 for (int x = startX; x <= endX; x++) {
595 View v = mContent.getChildAt(x,y);
596 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800597 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700598 empty[0] = x;
599 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700600 delay += delayAmount;
601 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700602 }
603 }
604 }
605 } else {
606 wrap = empty[0] == 0;
607 startY = wrap ? empty[1] - 1 : empty[1];
608 for (int y = startY; y >= target[1]; y--) {
609 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
610 endX = y > target[1] ? 0 : target[0];
611 for (int x = startX; x >= endX; x--) {
612 View v = mContent.getChildAt(x,y);
613 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800614 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700615 empty[0] = x;
616 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700617 delay += delayAmount;
618 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700619 }
620 }
621 }
622 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700623 }
624
Adam Cohen2374abf2013-04-16 14:56:57 -0700625 public boolean isLayoutRtl() {
626 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
627 }
628
Adam Cohencb3382b2011-05-24 14:07:08 -0700629 public void onDragOver(DragObject d) {
Alan Viverette4cda5b72013-08-28 17:53:41 -0700630 final DragView dragView = d.dragView;
631 final int scrollOffset = mScrollView.getScrollY();
632 final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700633 r[0] -= getPaddingLeft();
634 r[1] -= getPaddingTop();
635
Alan Viverette4cda5b72013-08-28 17:53:41 -0700636 final long downTime = SystemClock.uptimeMillis();
637 final MotionEvent translatedEv = MotionEvent.obtain(
638 downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);
639
640 if (!mAutoScrollHelper.isEnabled()) {
641 mAutoScrollHelper.setEnabled(true);
642 }
643
644 final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
645 translatedEv.recycle();
646
647 if (handled) {
648 mReorderAlarm.cancelAlarm();
649 } else {
650 mTargetCell = mContent.findNearestArea(
651 (int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700652 if (isLayoutRtl()) {
653 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700654 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700655 if (mTargetCell[0] != mPreviousTargetCell[0]
656 || mTargetCell[1] != mPreviousTargetCell[1]) {
657 mReorderAlarm.cancelAlarm();
658 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
659 mReorderAlarm.setAlarm(REORDER_DELAY);
660 mPreviousTargetCell[0] = mTargetCell[0];
661 mPreviousTargetCell[1] = mTargetCell[1];
662 mDragMode = DRAG_MODE_REORDER;
663 } else {
664 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700665 }
Adam Cohenbfbfd262011-06-13 16:55:12 -0700666 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700667 }
668
Adam Cohenbfbfd262011-06-13 16:55:12 -0700669 // This is used to compute the visual center of the dragView. The idea is that
670 // the visual center represents the user's interpretation of where the item is, and hence
671 // is the appropriate point to use when determining drop location.
672 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
673 DragView dragView, float[] recycle) {
674 float res[];
675 if (recycle == null) {
676 res = new float[2];
677 } else {
678 res = recycle;
679 }
680
681 // These represent the visual top and left of drag view if a dragRect was provided.
682 // If a dragRect was not provided, then they correspond to the actual view left and
683 // top, as the dragRect is in that case taken to be the entire dragView.
684 // R.dimen.dragViewOffsetY.
685 int left = x - xOffset;
686 int top = y - yOffset;
687
688 // In order to find the visual center, we shift by half the dragRect
689 res[0] = left + dragView.getDragRegion().width() / 2;
690 res[1] = top + dragView.getDragRegion().height() / 2;
691
692 return res;
693 }
694
695 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
696 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700697 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700698 }
699 };
700
Adam Cohen95bb8002011-07-03 23:40:28 -0700701 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700702 mLauncher.closeFolder();
703 mCurrentDragInfo = null;
704 mCurrentDragView = null;
705 mSuppressOnAdd = false;
706 mRearrangeOnClose = true;
707 }
708
Adam Cohencb3382b2011-05-24 14:07:08 -0700709 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700710 // Exiting folder; stop the auto scroller.
Alan Viverette4cda5b72013-08-28 17:53:41 -0700711 mAutoScrollHelper.setEnabled(false);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700712 // We only close the folder if this is a true drag exit, ie. not because
713 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700714 if (!d.dragComplete) {
715 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
716 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
717 }
718 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700719 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700720 }
721
Michael Jurka1e2f4652013-07-08 18:03:46 -0700722 public void onDropCompleted(final View target, final DragObject d,
723 final boolean isFlingToDelete, final boolean success) {
724 if (mDeferDropAfterUninstall) {
Michael Jurkaf3007582013-08-21 14:33:57 +0200725 Log.d(TAG, "Deferred handling drop because waiting for uninstall.");
Michael Jurka1e2f4652013-07-08 18:03:46 -0700726 mDeferredAction = new Runnable() {
727 public void run() {
728 onDropCompleted(target, d, isFlingToDelete, success);
729 mDeferredAction = null;
730 }
731 };
732 return;
733 }
734
735 boolean beingCalledAfterUninstall = mDeferredAction != null;
736 boolean successfulDrop =
737 success && (!beingCalledAfterUninstall || mUninstallSuccessful);
Winson Chung5f8afe62013-08-12 16:19:28 -0700738
Michael Jurka1e2f4652013-07-08 18:03:46 -0700739 if (successfulDrop) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700740 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700741 replaceFolderWithFinalItem();
742 }
743 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700744 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700745 // The drag failed, we need to return the item to the folder
746 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700747 }
748
749 if (target != this) {
750 if (mOnExitAlarm.alarmPending()) {
751 mOnExitAlarm.cancelAlarm();
Michael Jurka54554252013-08-01 12:52:23 +0200752 if (!successfulDrop) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700753 mSuppressFolderDeletion = true;
754 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700755 completeDragExit();
756 }
757 }
Winson Chung5f8afe62013-08-12 16:19:28 -0700758
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700759 mDeleteFolderOnDropCompleted = false;
760 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700761 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700762 mCurrentDragInfo = null;
763 mCurrentDragView = null;
764 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700765
766 // Reordering may have occured, and we need to save the new item locations. We do this once
767 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700768 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700769 }
770
Michael Jurka1e2f4652013-07-08 18:03:46 -0700771 public void deferCompleteDropAfterUninstallActivity() {
772 mDeferDropAfterUninstall = true;
773 }
774
775 public void onUninstallActivityReturned(boolean success) {
776 mDeferDropAfterUninstall = false;
777 mUninstallSuccessful = success;
778 if (mDeferredAction != null) {
779 mDeferredAction.run();
780 }
781 }
782
Winson Chunga48487a2012-03-20 16:19:37 -0700783 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800784 public boolean supportsFlingToDelete() {
785 return true;
786 }
787
Winson Chunga48487a2012-03-20 16:19:37 -0700788 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
789 // Do nothing
790 }
791
792 @Override
793 public void onFlingToDeleteCompleted() {
794 // Do nothing
795 }
796
Adam Cohen4045eb72011-10-06 11:44:26 -0700797 private void updateItemLocationsInDatabase() {
798 ArrayList<View> list = getItemsInReadingOrder();
799 for (int i = 0; i < list.size(); i++) {
800 View v = list.get(i);
801 ItemInfo info = (ItemInfo) v.getTag();
802 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
803 info.cellX, info.cellY);
804 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700805 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700806
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700807 private void updateItemLocationsInDatabaseBatch() {
808 ArrayList<View> list = getItemsInReadingOrder();
809 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
810 for (int i = 0; i < list.size(); i++) {
811 View v = list.get(i);
812 ItemInfo info = (ItemInfo) v.getTag();
813 items.add(info);
814 }
815
816 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
817 }
818
Adam Cohene25af792013-06-06 23:08:25 -0700819 public void addItemLocationsInDatabase() {
820 ArrayList<View> list = getItemsInReadingOrder();
821 for (int i = 0; i < list.size(); i++) {
822 View v = list.get(i);
823 ItemInfo info = (ItemInfo) v.getTag();
824 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
825 info.cellX, info.cellY, false);
826 }
827 }
828
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700829 public void notifyDrop() {
830 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700831 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700832 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700833 }
834
835 public boolean isDropEnabled() {
836 return true;
837 }
838
Adam Cohen4045eb72011-10-06 11:44:26 -0700839 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700840 ArrayList<View> list = getItemsInReadingOrder();
841
842 int countX = mContent.getCountX();
843 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700844 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700845
Adam Cohen7c693212011-05-18 15:26:57 -0700846 while (!done) {
847 int oldCountX = countX;
848 int oldCountY = countY;
849 if (countX * countY < count) {
850 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800851 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700852 countX++;
853 } else if (countY < mMaxCountY) {
854 countY++;
855 }
856 if (countY == 0) countY++;
857 } else if ((countY - 1) * countX >= count && countY >= countX) {
858 countY = Math.max(0, countY - 1);
859 } else if ((countX - 1) * countY >= count) {
860 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700861 }
Adam Cohen7c693212011-05-18 15:26:57 -0700862 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700863 }
Adam Cohen7c693212011-05-18 15:26:57 -0700864 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700865 arrangeChildren(list);
866 }
867
868 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800869 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700870 }
871
872 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700873 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700874
Winson Chung892c74d2013-08-22 16:15:50 -0700875 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700876 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700877 int height = getFolderHeight();
Adam Cohen2801caf2011-05-13 20:57:39 -0700878
Adam Cohen307fe232012-08-16 17:55:58 -0700879 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700880
Adam Cohen307fe232012-08-16 17:55:58 -0700881 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
882 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700883 int centeredLeft = centerX - width / 2;
884 int centeredTop = centerY - height / 2;
885
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800886 int currentPage = mLauncher.getWorkspace().getCurrentPage();
887 // In case the workspace is scrolling, we need to use the final scroll to compute
888 // the folders bounds.
889 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700890 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800891 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700892 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700893 Rect bounds = new Rect();
894 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800895 // We reset the workspaces scroll
896 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700897
Adam Cohen35e7e642011-07-17 14:47:18 -0700898 // We need to bound the folder to the currently visible CellLayoutChildren
899 int left = Math.min(Math.max(bounds.left, centeredLeft),
900 bounds.left + bounds.width() - width);
901 int top = Math.min(Math.max(bounds.top, centeredTop),
902 bounds.top + bounds.height() - height);
903 // If the folder doesn't fit within the bounds, center it about the desired bounds
904 if (width >= bounds.width()) {
905 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700906 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700907 if (height >= bounds.height()) {
908 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700909 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700910
911 int folderPivotX = width / 2 + (centeredLeft - left);
912 int folderPivotY = height / 2 + (centeredTop - top);
913 setPivotX(folderPivotX);
914 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700915 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700916 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700917 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700918 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700919
Adam Cohen662b5982011-12-13 17:45:21 -0800920 lp.width = width;
921 lp.height = height;
922 lp.x = left;
923 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700924 }
925
Adam Cohen268c4752012-06-06 17:47:33 -0700926 float getPivotXForIconAnimation() {
927 return mFolderIconPivotX;
928 }
929 float getPivotYForIconAnimation() {
930 return mFolderIconPivotY;
931 }
932
Adam Cohen2801caf2011-05-13 20:57:39 -0700933 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700934 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700935
Adam Cohen8e776a62011-06-28 18:10:06 -0700936 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700937 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700938 lp = new DragLayer.LayoutParams(0, 0);
939 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700940 setLayoutParams(lp);
941 }
942 centerAboutIcon();
943 }
944
Winson Chung892c74d2013-08-22 16:15:50 -0700945 private int getContentAreaHeight() {
946 LauncherAppState app = LauncherAppState.getInstance();
947 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
948 Rect workspacePadding = grid.getWorkspacePadding(grid.isLandscape ?
949 CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
950 int maxContentAreaHeight = grid.availableHeightPx -
951 4 * grid.edgeMarginPx -
952 workspacePadding.top - workspacePadding.bottom -
953 getPaddingTop() - getPaddingBottom() -
954 mFolderNameHeight;
955 return Math.min(maxContentAreaHeight,
956 mContent.getDesiredHeight());
957 }
958
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700959 private int getFolderHeight() {
Winson Chung892c74d2013-08-22 16:15:50 -0700960 int height = getPaddingTop() + getPaddingBottom()
961 + getContentAreaHeight() + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700962 return height;
963 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700964
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700965 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700966 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
967 int height = getFolderHeight();
968 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
969 MeasureSpec.EXACTLY);
Winson Chung892c74d2013-08-22 16:15:50 -0700970 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(getContentAreaHeight(),
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700971 MeasureSpec.EXACTLY);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700972 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
Winson Chung0e6a7132013-08-23 12:55:10 -07001062 // the same time in the CellLayout. We need to add the new item with addInScreenFromBind()
1063 // to ensure that hotseat items are placed correctly.
Adam Cohenc5e63f32012-07-12 16:16:57 -07001064 if (child != null) {
Winson Chung0e6a7132013-08-23 12:55:10 -07001065 mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001066 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1067 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001068 }
1069 };
1070 View finalChild = getItemAt(0);
1071 if (finalChild != null) {
1072 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001073 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001074 mDestroyed = true;
1075 }
1076
1077 boolean isDestroyed() {
1078 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001079 }
1080
Adam Cohenac56cff2011-09-28 20:45:37 -07001081 // This method keeps track of the last item in the folder for the purposes
1082 // of keyboard focus
1083 private void updateTextViewFocus() {
1084 View lastChild = getItemAt(getItemCount() - 1);
1085 getItemAt(getItemCount() - 1);
1086 if (lastChild != null) {
1087 mFolderName.setNextFocusDownId(lastChild.getId());
1088 mFolderName.setNextFocusRightId(lastChild.getId());
1089 mFolderName.setNextFocusLeftId(lastChild.getId());
1090 mFolderName.setNextFocusUpId(lastChild.getId());
1091 }
1092 }
1093
Adam Cohenbfbfd262011-06-13 16:55:12 -07001094 public void onDrop(DragObject d) {
1095 ShortcutInfo item;
Michael Jurkaeadbfc52013-09-04 00:45:37 +02001096 if (d.dragInfo instanceof AppInfo) {
Adam Cohenbfbfd262011-06-13 16:55:12 -07001097 // Came from all apps -- make a copy
Michael Jurkaeadbfc52013-09-04 00:45:37 +02001098 item = ((AppInfo) d.dragInfo).makeShortcut();
Adam Cohenbfbfd262011-06-13 16:55:12 -07001099 item.spanX = 1;
1100 item.spanY = 1;
1101 } else {
1102 item = (ShortcutInfo) d.dragInfo;
1103 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001104 // Dragged from self onto self, currently this is the only path possible, however
1105 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001106 if (item == mCurrentDragInfo) {
1107 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1108 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1109 si.cellX = lp.cellX = mEmptyCell[0];
1110 si.cellX = lp.cellY = mEmptyCell[1];
1111 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001112 if (d.dragView.hasDrawn()) {
1113 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1114 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001115 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001116 mCurrentDragView.setVisibility(VISIBLE);
1117 }
Adam Cohene9166b22011-07-08 17:11:11 -07001118 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001119 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001120 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001121 }
1122 mInfo.add(item);
1123 }
1124
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001125 // This is used so the item doesn't immediately appear in the folder when added. In one case
1126 // we need to create the illusion that the item isn't added back to the folder yet, to
1127 // to correspond to the animation of the icon back into the folder. This is
1128 public void hideItem(ShortcutInfo info) {
1129 View v = getViewForInfo(info);
1130 v.setVisibility(INVISIBLE);
1131 }
1132 public void showItem(ShortcutInfo info) {
1133 View v = getViewForInfo(info);
1134 v.setVisibility(VISIBLE);
1135 }
1136
Adam Cohenbfbfd262011-06-13 16:55:12 -07001137 public void onAdd(ShortcutInfo item) {
1138 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001139 // If the item was dropped onto this open folder, we have done the work associated
1140 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001141 if (mSuppressOnAdd) return;
1142 if (!findAndSetEmptyCells(item)) {
1143 // The current layout is full, can we expand it?
1144 setupContentForNumItems(getItemCount() + 1);
1145 findAndSetEmptyCells(item);
1146 }
1147 createAndAddShortcut(item);
1148 LauncherModel.addOrMoveItemInDatabase(
1149 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1150 }
1151
Adam Cohena9cf38f2011-05-02 15:36:58 -07001152 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001153 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001154 // If this item is being dragged from this open folder, we have already handled
1155 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001156 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001157 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001158 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001159 if (mState == STATE_ANIMATING) {
1160 mRearrangeOnClose = true;
1161 } else {
1162 setupContentForNumItems(getItemCount());
1163 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001164 if (getItemCount() <= 1) {
1165 replaceFolderWithFinalItem();
1166 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001167 }
Adam Cohen7c693212011-05-18 15:26:57 -07001168
Adam Cohendf1e4e82011-06-24 15:57:39 -07001169 private View getViewForInfo(ShortcutInfo item) {
1170 for (int j = 0; j < mContent.getCountY(); j++) {
1171 for (int i = 0; i < mContent.getCountX(); i++) {
1172 View v = mContent.getChildAt(i, j);
1173 if (v.getTag() == item) {
1174 return v;
1175 }
1176 }
1177 }
1178 return null;
1179 }
1180
Adam Cohen76078c42011-06-09 15:06:52 -07001181 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001182 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001183 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001184
Adam Cohen76fc0852011-06-17 13:26:23 -07001185 public void onTitleChanged(CharSequence title) {
1186 }
Adam Cohen76078c42011-06-09 15:06:52 -07001187
Adam Cohen7c693212011-05-18 15:26:57 -07001188 public ArrayList<View> getItemsInReadingOrder() {
1189 if (mItemsInvalidated) {
1190 mItemsInReadingOrder.clear();
1191 for (int j = 0; j < mContent.getCountY(); j++) {
1192 for (int i = 0; i < mContent.getCountX(); i++) {
1193 View v = mContent.getChildAt(i, j);
1194 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001195 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001196 }
1197 }
1198 }
1199 mItemsInvalidated = false;
1200 }
1201 return mItemsInReadingOrder;
1202 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001203
1204 public void getLocationInDragLayer(int[] loc) {
1205 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1206 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001207
1208 public void onFocusChange(View v, boolean hasFocus) {
1209 if (v == mFolderName && hasFocus) {
1210 startEditingFolderName();
1211 }
1212 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001213
1214 @Override
1215 public void getHitRectRelativeToDragLayer(Rect outRect) {
1216 getHitRect(outRect);
1217 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218}