blob: f57ff07a912af41e9ddeea228d0afdcbdc06e95f [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Adam Cohendf2cc412011-04-27 16:56:57 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Adam Cohendf2cc412011-04-27 16:56:57 -070021import android.animation.ObjectAnimator;
22import android.animation.PropertyValuesHolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.content.Context;
Adam Cohen76fc0852011-06-17 13:26:23 -070024import android.content.res.Resources;
Winson Chung043f2af2012-03-01 16:09:54 -080025import android.graphics.PointF;
Romain Guyfb5411e2010-02-24 10:04:17 -080026import android.graphics.Rect;
Adam Cohenbadf71e2011-05-26 19:08:29 -070027import android.graphics.drawable.Drawable;
Adam Cohen7a14d0b2011-06-24 11:36:35 -070028import android.text.InputType;
Adam Cohene601a432011-07-26 21:51:30 -070029import android.text.Selection;
30import android.text.Spannable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.util.AttributeSet;
Winson Chung892c74d2013-08-22 16:15:50 -070032import android.util.DisplayMetrics;
Adam Cohen3bf84d32012-05-07 20:17:14 -070033import android.util.Log;
Winson Chung892c74d2013-08-22 16:15:50 -070034import android.util.TypedValue;
Adam Cohen76fc0852011-06-17 13:26:23 -070035import android.view.ActionMode;
36import android.view.KeyEvent;
Adam Cohendf2cc412011-04-27 16:56:57 -070037import android.view.LayoutInflater;
Adam Cohen76fc0852011-06-17 13:26:23 -070038import android.view.Menu;
39import android.view.MenuItem;
Adam Cohen0c872ba2011-05-05 10:34:16 -070040import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.view.View;
Adam Cohen3371da02011-10-25 21:38:29 -070042import android.view.accessibility.AccessibilityEvent;
43import android.view.accessibility.AccessibilityManager;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -070044import android.view.animation.AccelerateInterpolator;
45import android.view.animation.Interpolator;
Adam Cohen76fc0852011-06-17 13:26:23 -070046import android.view.inputmethod.EditorInfo;
47import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070049import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070050import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051
Daniel Sandler325dc232013-06-05 22:57:57 -040052import com.android.launcher3.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080053
Adam Cohenc0dcf592011-06-01 15:30:43 -070054import java.util.ArrayList;
Adam Cohen3bf84d32012-05-07 20:17:14 -070055import java.util.Collections;
56import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -070057
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058/**
59 * Represents a set of icons chosen by the user or generated by the system.
60 */
Adam Cohen8dfcba42011-07-07 16:38:18 -070061public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
Adam Cohenea0818d2011-09-30 20:06:58 -070062 View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
63 View.OnFocusChangeListener {
Adam Cohendf2cc412011-04-27 16:56:57 -070064 private static final String TAG = "Launcher.Folder";
65
Adam Cohen4eac29a2011-07-11 17:53:37 -070066 protected DragController mDragController;
67 protected Launcher mLauncher;
68 protected FolderInfo mInfo;
69
Adam Cohendf2cc412011-04-27 16:56:57 -070070 static final int STATE_NONE = -1;
71 static final int STATE_SMALL = 0;
72 static final int STATE_ANIMATING = 1;
73 static final int STATE_OPEN = 2;
74
75 private int mExpandDuration;
76 protected CellLayout mContent;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070077 private ScrollView mScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070078 private final LayoutInflater mInflater;
79 private final IconCache mIconCache;
80 private int mState = STATE_NONE;
Adam Cohenbfbfd262011-06-13 16:55:12 -070081 private static final int REORDER_ANIMATION_DURATION = 230;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070082 private static final int REORDER_DELAY = 250;
Adam Cohenbfbfd262011-06-13 16:55:12 -070083 private static final int ON_EXIT_CLOSE_DELAY = 800;
Adam Cohen2801caf2011-05-13 20:57:39 -070084 private boolean mRearrangeOnClose = false;
85 private FolderIcon mFolderIcon;
86 private int mMaxCountX;
87 private int mMaxCountY;
Adam Cohen78dc83e2011-11-15 17:10:00 -080088 private int mMaxNumItems;
Adam Cohen7c693212011-05-18 15:26:57 -070089 private ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
Adam Cohenbadf71e2011-05-26 19:08:29 -070090 private Drawable mIconDrawable;
Adam Cohen7c693212011-05-18 15:26:57 -070091 boolean mItemsInvalidated = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -070092 private ShortcutInfo mCurrentDragInfo;
93 private View mCurrentDragView;
94 boolean mSuppressOnAdd = false;
95 private int[] mTargetCell = new int[2];
96 private int[] mPreviousTargetCell = new int[2];
97 private int[] mEmptyCell = new int[2];
98 private Alarm mReorderAlarm = new Alarm();
99 private Alarm mOnExitAlarm = new Alarm();
Adam Cohen76fc0852011-06-17 13:26:23 -0700100 private int mFolderNameHeight;
Adam Cohen8e776a62011-06-28 18:10:06 -0700101 private Rect mTempRect = new Rect();
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700102 private boolean mDragInProgress = false;
103 private boolean mDeleteFolderOnDropCompleted = false;
104 private boolean mSuppressFolderDeletion = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700105 private boolean mItemAddedBackToSelfViaIcon = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700106 FolderEditText mFolderName;
Adam Cohen268c4752012-06-06 17:47:33 -0700107 private float mFolderIconPivotX;
108 private float mFolderIconPivotY;
Adam Cohen228da5a2011-07-27 22:23:47 -0700109
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700110 private static final float MAX_SCROLL_VELOCITY = 1500f;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700111
Adam Cohen76fc0852011-06-17 13:26:23 -0700112 private boolean mIsEditingName = false;
113 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700114
Adam Cohena65beee2011-06-27 21:32:23 -0700115 private static String sDefaultFolderName;
116 private static String sHintText;
117
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700118 private int DRAG_MODE_NONE = 0;
119 private int DRAG_MODE_REORDER = 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700120 private int mDragMode = DRAG_MODE_NONE;
121
Adam Cohenfb91f302012-06-11 15:45:18 -0700122 private boolean mDestroyed;
123
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700124 private AutoScroller mAutoScroller;
125
Michael Jurka1e2f4652013-07-08 18:03:46 -0700126 private Runnable mDeferredAction;
127 private boolean mDeferDropAfterUninstall;
128 private boolean mUninstallSuccessful;
129
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 /**
131 * Used to inflate the Workspace from XML.
132 *
133 * @param context The application's context.
134 * @param attrs The attribtues set containing the Workspace's customization values.
135 */
136 public Folder(Context context, AttributeSet attrs) {
137 super(context, attrs);
Winson Chung5f8afe62013-08-12 16:19:28 -0700138
139 LauncherAppState app = LauncherAppState.getInstance();
140 DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700142 mInflater = LayoutInflater.from(context);
Winson Chung5f8afe62013-08-12 16:19:28 -0700143 mIconCache = app.getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800144
145 Resources res = getResources();
Michael Jurka414300a2013-08-27 15:42:35 +0200146 mMaxCountX = (int) grid.numColumns;
Winson Chung5f8afe62013-08-12 16:19:28 -0700147 mMaxCountY = mMaxNumItems = Integer.MAX_VALUE;
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);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700196 mAutoScroller = new AutoScroller(mScrollView);
197 mAutoScroller.setMaximumVelocityAbsolute(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
198 mAutoScroller.setExtendsBeyondEdges(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700200
Adam Cohen76fc0852011-06-17 13:26:23 -0700201 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
202 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
203 return false;
204 }
205
206 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
207 return false;
208 }
209
210 public void onDestroyActionMode(ActionMode mode) {
211 }
212
213 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
214 return false;
215 }
216 };
217
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700219 Object tag = v.getTag();
220 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700221 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223 }
224
225 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700226 // Return if global dragging is not enabled
227 if (!mLauncher.isDraggingEnabled()) return true;
228
Adam Cohendf2cc412011-04-27 16:56:57 -0700229 Object tag = v.getTag();
230 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700231 ShortcutInfo item = (ShortcutInfo) tag;
232 if (!v.isInTouchMode()) {
233 return false;
234 }
235
Winson Chung7d7541e2011-09-16 20:14:36 -0700236 mLauncher.dismissFolderCling(null);
237
Adam Cohendf2cc412011-04-27 16:56:57 -0700238 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700239 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700240 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700241
242 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700243 mEmptyCell[0] = item.cellX;
244 mEmptyCell[1] = item.cellY;
245 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700246
247 mContent.removeView(mCurrentDragView);
248 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700249 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700250 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700251 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 return true;
253 }
254
Adam Cohen76fc0852011-06-17 13:26:23 -0700255 public boolean isEditingName() {
256 return mIsEditingName;
257 }
258
259 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700260 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700261 mIsEditingName = true;
262 }
263
264 public void dismissEditingName() {
265 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
266 doneEditingFolderName(true);
267 }
268
269 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700270 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700271 // Convert to a string here to ensure that no other state associated with the text field
272 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700273 String newTitle = mFolderName.getText().toString();
274 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700275 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700276
Adam Cohen3371da02011-10-25 21:38:29 -0700277 if (commit) {
278 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700279 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700280 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700281 // In order to clear the focus from the text field, we set the focus on ourself. This
282 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
283 requestFocus();
284
Adam Cohene601a432011-07-26 21:51:30 -0700285 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700286 mIsEditingName = false;
287 }
288
289 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
290 if (actionId == EditorInfo.IME_ACTION_DONE) {
291 dismissEditingName();
292 return true;
293 }
294 return false;
295 }
296
297 public View getEditTextRegion() {
298 return mFolderName;
299 }
300
Adam Cohenbadf71e2011-05-26 19:08:29 -0700301 public Drawable getDragDrawable() {
302 return mIconDrawable;
303 }
304
Adam Cohen0c872ba2011-05-05 10:34:16 -0700305 /**
306 * We need to handle touch events to prevent them from falling through to the workspace below.
307 */
308 @Override
309 public boolean onTouchEvent(MotionEvent ev) {
310 return true;
311 }
312
Joe Onorato00acb122009-08-04 16:04:30 -0400313 public void setDragController(DragController dragController) {
314 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800315 }
316
Adam Cohen2801caf2011-05-13 20:57:39 -0700317 void setFolderIcon(FolderIcon icon) {
318 mFolderIcon = icon;
319 }
320
Adam Cohen3371da02011-10-25 21:38:29 -0700321 @Override
322 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
323 // When the folder gets focus, we don't want to announce the list of items.
324 return true;
325 }
326
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800327 /**
328 * @return the FolderInfo object associated with this folder
329 */
330 FolderInfo getInfo() {
331 return mInfo;
332 }
333
Adam Cohen3bf84d32012-05-07 20:17:14 -0700334 private class GridComparator implements Comparator<ShortcutInfo> {
335 int mNumCols;
336 public GridComparator(int numCols) {
337 mNumCols = numCols;
338 }
339
340 @Override
341 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
342 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
343 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
344 return (lhIndex - rhIndex);
345 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700346 }
347
348 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
349 int maxX = 0;
350 int count = items.size();
351 for (int i = 0; i < count; i++) {
352 ShortcutInfo item = items.get(i);
353 if (item.cellX > maxX) {
354 maxX = item.cellX;
355 }
356 }
Adam Cohen691a5792012-05-11 14:27:30 -0700357
358 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700359 Collections.sort(items, gridComparator);
360 final int countX = mContent.getCountX();
361 for (int i = 0; i < count; i++) {
362 int x = i % countX;
363 int y = i / countX;
364 ShortcutInfo item = items.get(i);
365 item.cellX = x;
366 item.cellY = y;
367 }
368 }
369
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 void bind(FolderInfo info) {
371 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700372 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700373 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700374 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700375 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700376 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700377 for (int i = 0; i < children.size(); i++) {
378 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700379 if (!createAndAddShortcut(child)) {
380 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700381 } else {
382 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700383 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700384 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700385
Adam Cohen0057bbc2011-08-12 18:30:51 -0700386 // We rearrange the items in case there are any empty gaps
387 setupContentForNumItems(count);
388
Adam Cohenc508b2d2011-06-28 14:41:44 -0700389 // If our folder has too many items we prune them from the list. This is an issue
390 // when upgrading from the old Folders implementation which could contain an unlimited
391 // number of items.
392 for (ShortcutInfo item: overflow) {
393 mInfo.remove(item);
394 LauncherModel.deleteItemFromDatabase(mLauncher, item);
395 }
396
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700397 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700398 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700399 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700400
Adam Cohenafb01ee2011-06-23 15:38:03 -0700401 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700402 mFolderName.setText(mInfo.title);
403 } else {
404 mFolderName.setText("");
405 }
Adam Cohen691a5792012-05-11 14:27:30 -0700406 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700407 }
408
409 /**
410 * Creates a new UserFolder, inflated from R.layout.user_folder.
411 *
412 * @param context The application's context.
413 *
414 * @return A new UserFolder.
415 */
416 static Folder fromXml(Context context) {
417 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
418 }
419
420 /**
421 * This method is intended to make the UserFolder to be visually identical in size and position
422 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
423 */
424 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700425 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800426 setScaleX(0.8f);
427 setScaleY(0.8f);
428 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700429 mState = STATE_SMALL;
430 }
431
432 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700433 positionAndSizeAsIcon();
434
Adam Cohen8e776a62011-06-28 18:10:06 -0700435 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700436 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800437 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
438 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
439 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200440 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700441 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800442
Adam Cohen2801caf2011-05-13 20:57:39 -0700443 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700444 @Override
445 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700446 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700447 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700448 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700449 mState = STATE_ANIMATING;
450 }
451 @Override
452 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700453 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700454 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700455 Cling cling = mLauncher.showFirstRunFoldersCling();
456 if (cling != null) {
457 cling.bringToFront();
458 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700459 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700460 }
461 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700462 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700463 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100464 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700465 }
466
Adam Cohen3371da02011-10-25 21:38:29 -0700467 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700468 AccessibilityManager accessibilityManager = (AccessibilityManager)
469 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
470 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700471 AccessibilityEvent event = AccessibilityEvent.obtain(type);
472 onInitializeAccessibilityEvent(event);
473 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700474 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700475 }
476 }
477
Adam Cohenac56cff2011-09-28 20:45:37 -0700478 private void setFocusOnFirstChild() {
479 View firstChild = mContent.getChildAt(0, 0);
480 if (firstChild != null) {
481 firstChild.requestFocus();
482 }
483 }
484
Adam Cohendf2cc412011-04-27 16:56:57 -0700485 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700486 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800487 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
488 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
489 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200490 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700491 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700492
Adam Cohen2801caf2011-05-13 20:57:39 -0700493 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700494 @Override
495 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700496 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700497 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700498 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700499 }
500 @Override
501 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700502 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700503 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700504 mState = STATE_ANIMATING;
505 }
506 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700507 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700508 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100509 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700510 }
511
Adam Cohencb3382b2011-05-24 14:07:08 -0700512 public boolean acceptDrop(DragObject d) {
513 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700514 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700515 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
516 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
517 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700518 }
519
Adam Cohendf2cc412011-04-27 16:56:57 -0700520 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
521 int[] emptyCell = new int[2];
522 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
523 item.cellX = emptyCell[0];
524 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700525 return true;
526 } else {
527 return false;
528 }
529 }
530
Adam Cohenc508b2d2011-06-28 14:41:44 -0700531 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700532 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700533 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700534 textView.setCompoundDrawablesWithIntrinsicBounds(null,
535 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
536 textView.setText(item.title);
537 textView.setTag(item);
538
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
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700629 private Rect getDragObjectDrawingRect(View dragView, float[] r) {
630 final Rect drawingRect = mTempRect;
631 drawingRect.left = (int) r[0];
632 drawingRect.top = (int) r[1];
633 drawingRect.right = drawingRect.left + dragView.getMeasuredWidth();
634 drawingRect.bottom = drawingRect.top + dragView.getMeasuredHeight();
635 return drawingRect;
636 }
637
Adam Cohencb3382b2011-05-24 14:07:08 -0700638 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700639 int scrollOffset = mScrollView.getScrollY();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700640 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700641 r[0] -= getPaddingLeft();
642 r[1] -= getPaddingTop();
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700643 if (!mAutoScroller.onTouch(this, getDragObjectDrawingRect(d.dragView, r))) {
644 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1,
645 mTargetCell);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700646
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700647 if (isLayoutRtl()) {
648 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700649 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700650 if (mTargetCell[0] != mPreviousTargetCell[0]
651 || mTargetCell[1] != mPreviousTargetCell[1]) {
652 mReorderAlarm.cancelAlarm();
653 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
654 mReorderAlarm.setAlarm(REORDER_DELAY);
655 mPreviousTargetCell[0] = mTargetCell[0];
656 mPreviousTargetCell[1] = mTargetCell[1];
657 mDragMode = DRAG_MODE_REORDER;
658 } else {
659 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700660 }
Adam Cohen61a9a5c2013-08-14 13:32:04 -0700661 } else {
662 mReorderAlarm.cancelAlarm();
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.
708 mAutoScroller.stop();
709 // 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;
1093 if (d.dragInfo instanceof ApplicationInfo) {
1094 // Came from all apps -- make a copy
1095 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1096 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}