blob: bb3993efce200e619b26e7065d3e4729cbc7fee5 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Adam Cohendf2cc412011-04-27 16:56:57 -070019import android.animation.Animator;
20import android.animation.AnimatorListenerAdapter;
Adam Cohendf2cc412011-04-27 16:56:57 -070021import android.animation.ObjectAnimator;
22import android.animation.PropertyValuesHolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080023import android.content.Context;
Adam Cohen76fc0852011-06-17 13:26:23 -070024import android.content.res.Resources;
Winson Chung043f2af2012-03-01 16:09:54 -080025import android.graphics.PointF;
Romain Guyfb5411e2010-02-24 10:04:17 -080026import android.graphics.Rect;
Adam Cohenbadf71e2011-05-26 19:08:29 -070027import android.graphics.drawable.Drawable;
Adam Cohen7a14d0b2011-06-24 11:36:35 -070028import android.text.InputType;
Adam Cohene601a432011-07-26 21:51:30 -070029import android.text.Selection;
30import android.text.Spannable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.util.AttributeSet;
Adam Cohen3bf84d32012-05-07 20:17:14 -070032import android.util.Log;
Adam Cohen76fc0852011-06-17 13:26:23 -070033import android.view.ActionMode;
34import android.view.KeyEvent;
Adam Cohendf2cc412011-04-27 16:56:57 -070035import android.view.LayoutInflater;
Adam Cohen76fc0852011-06-17 13:26:23 -070036import android.view.Menu;
37import android.view.MenuItem;
Adam Cohen0c872ba2011-05-05 10:34:16 -070038import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039import android.view.View;
Adam Cohen3371da02011-10-25 21:38:29 -070040import android.view.accessibility.AccessibilityEvent;
41import android.view.accessibility.AccessibilityManager;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -070042import android.view.animation.AccelerateInterpolator;
43import android.view.animation.Interpolator;
Adam Cohen76fc0852011-06-17 13:26:23 -070044import android.view.inputmethod.EditorInfo;
45import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070047import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070048import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049
Daniel Sandler325dc232013-06-05 22:57:57 -040050import com.android.launcher3.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080051
Adam Cohenc0dcf592011-06-01 15:30:43 -070052import java.util.ArrayList;
Adam Cohen3bf84d32012-05-07 20:17:14 -070053import java.util.Collections;
54import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -070055
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056/**
57 * Represents a set of icons chosen by the user or generated by the system.
58 */
Adam Cohen8dfcba42011-07-07 16:38:18 -070059public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
Adam Cohenea0818d2011-09-30 20:06:58 -070060 View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
61 View.OnFocusChangeListener {
Adam Cohendf2cc412011-04-27 16:56:57 -070062 private static final String TAG = "Launcher.Folder";
63
Adam Cohen4eac29a2011-07-11 17:53:37 -070064 protected DragController mDragController;
65 protected Launcher mLauncher;
66 protected FolderInfo mInfo;
67
Adam Cohendf2cc412011-04-27 16:56:57 -070068 static final int STATE_NONE = -1;
69 static final int STATE_SMALL = 0;
70 static final int STATE_ANIMATING = 1;
71 static final int STATE_OPEN = 2;
72
73 private int mExpandDuration;
74 protected CellLayout mContent;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070075 private ScrollView mScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070076 private final LayoutInflater mInflater;
77 private final IconCache mIconCache;
78 private int mState = STATE_NONE;
Adam Cohenbfbfd262011-06-13 16:55:12 -070079 private static final int REORDER_ANIMATION_DURATION = 230;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070080 private static final int REORDER_DELAY = 250;
Adam Cohenbfbfd262011-06-13 16:55:12 -070081 private static final int ON_EXIT_CLOSE_DELAY = 800;
Adam Cohen2801caf2011-05-13 20:57:39 -070082 private boolean mRearrangeOnClose = false;
83 private FolderIcon mFolderIcon;
84 private int mMaxCountX;
85 private int mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070086 private int mMaxVisibleX;
87 private int mMaxVisibleY;
88 private int mMaxContentAreaHeight = 0;
Adam Cohen78dc83e2011-11-15 17:10:00 -080089 private int mMaxNumItems;
Adam Cohen7c693212011-05-18 15:26:57 -070090 private ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
Adam Cohenbadf71e2011-05-26 19:08:29 -070091 private Drawable mIconDrawable;
Adam Cohen7c693212011-05-18 15:26:57 -070092 boolean mItemsInvalidated = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -070093 private ShortcutInfo mCurrentDragInfo;
94 private View mCurrentDragView;
95 boolean mSuppressOnAdd = false;
96 private int[] mTargetCell = new int[2];
97 private int[] mPreviousTargetCell = new int[2];
98 private int[] mEmptyCell = new int[2];
99 private Alarm mReorderAlarm = new Alarm();
100 private Alarm mOnExitAlarm = new Alarm();
Adam Cohen76fc0852011-06-17 13:26:23 -0700101 private int mFolderNameHeight;
Adam Cohen8e776a62011-06-28 18:10:06 -0700102 private Rect mTempRect = new Rect();
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700103 private boolean mDragInProgress = false;
104 private boolean mDeleteFolderOnDropCompleted = false;
105 private boolean mSuppressFolderDeletion = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700106 private boolean mItemAddedBackToSelfViaIcon = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700107 FolderEditText mFolderName;
Adam Cohen268c4752012-06-06 17:47:33 -0700108 private float mFolderIconPivotX;
109 private float mFolderIconPivotY;
Adam Cohen228da5a2011-07-27 22:23:47 -0700110
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700111 private static final int SCROLL_CUT_OFF_AMOUNT = 60;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -0700112
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700113 private static final float MAX_SCROLL_VELOCITY = 1500f;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700114
Adam Cohen76fc0852011-06-17 13:26:23 -0700115 private boolean mIsEditingName = false;
116 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700117
Adam Cohena65beee2011-06-27 21:32:23 -0700118 private static String sDefaultFolderName;
119 private static String sHintText;
120
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700121 private int DRAG_MODE_NONE = 0;
122 private int DRAG_MODE_REORDER = 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700123 private int mDragMode = DRAG_MODE_NONE;
124
Adam Cohenfb91f302012-06-11 15:45:18 -0700125 private boolean mDestroyed;
126
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700127 private AutoScroller mAutoScroller;
128
Michael Jurka1e2f4652013-07-08 18:03:46 -0700129 private Runnable mDeferredAction;
130 private boolean mDeferDropAfterUninstall;
131 private boolean mUninstallSuccessful;
132
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 /**
134 * Used to inflate the Workspace from XML.
135 *
136 * @param context The application's context.
137 * @param attrs The attribtues set containing the Workspace's customization values.
138 */
139 public Folder(Context context, AttributeSet attrs) {
140 super(context, attrs);
141 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700142 mInflater = LayoutInflater.from(context);
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400143 mIconCache = (LauncherAppState.getInstance()).getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800144
145 Resources res = getResources();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700146 mMaxCountX = mMaxVisibleX = res.getInteger(R.integer.folder_max_count_x);
147 mMaxCountY = mMaxVisibleY = res.getInteger(R.integer.folder_max_count_y);
Adam Cohen78dc83e2011-11-15 17:10:00 -0800148 mMaxNumItems = res.getInteger(R.integer.folder_max_num_items);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700149
150 if (mMaxCountY == -1) {
151 // -2 indicates unlimited
152 mMaxCountY = Integer.MAX_VALUE;
153 mMaxVisibleX = LauncherModel.getCellCountX() + 1;
154 }
155 if (mMaxNumItems == -1) {
156 // -2 indicates unlimited
157 mMaxNumItems = Integer.MAX_VALUE;
158 mMaxVisibleY = LauncherModel.getCellCountY() + 1;
159 }
160 if (mMaxCountX == 0) {
161 mMaxCountX = mMaxVisibleX = LauncherModel.getCellCountX();
162 mMaxVisibleX++;
163 }
164 if (mMaxCountY == 0) {
165 mMaxCountY = mMaxVisibleY = LauncherModel.getCellCountY();
166 mMaxVisibleY++;
167 }
168 if (mMaxNumItems == 0) {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800169 mMaxNumItems = mMaxCountX * mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700170 if (mMaxNumItems < 0) {
171 mMaxNumItems = Integer.MAX_VALUE;
172 }
Adam Cohen78dc83e2011-11-15 17:10:00 -0800173 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700174
175 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700176 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700177
Adam Cohen76fc0852011-06-17 13:26:23 -0700178 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700179
180 if (sDefaultFolderName == null) {
181 sDefaultFolderName = res.getString(R.string.folder_name);
182 }
Adam Cohena65beee2011-06-27 21:32:23 -0700183 if (sHintText == null) {
184 sHintText = res.getString(R.string.folder_hint_text);
185 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700186 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700187 // We need this view to be focusable in touch mode so that when text editing of the folder
188 // name is complete, we have something to focus on, thus hiding the cursor and giving
189 // reliable behvior when clicking the text field (since it will always gain focus on click).
190 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 }
192
193 @Override
194 protected void onFinishInflate() {
195 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700196 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700197 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700198
199 // Beyond this height, the area scrolls
200 mContent.setGridSize(mMaxVisibleX, mMaxVisibleY);
201 mMaxContentAreaHeight = mContent.getDesiredHeight() - SCROLL_CUT_OFF_AMOUNT;
202
Adam Cohen2801caf2011-05-13 20:57:39 -0700203 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700204 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700205 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700206 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
207 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700208 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700209
210 // We find out how tall the text view wants to be (it is set to wrap_content), so that
211 // we can allocate the appropriate amount of space for it.
212 int measureSpec = MeasureSpec.UNSPECIFIED;
213 mFolderName.measure(measureSpec, measureSpec);
214 mFolderNameHeight = mFolderName.getMeasuredHeight();
215
216 // We disable action mode for now since it messes up the view on phones
217 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700218 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700219 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700220 mFolderName.setInputType(mFolderName.getInputType() |
221 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700222 mAutoScroller = new AutoScroller(mScrollView);
223 mAutoScroller.setMaximumVelocityAbsolute(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
224 mAutoScroller.setExtendsBeyondEdges(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700226
Adam Cohen76fc0852011-06-17 13:26:23 -0700227 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
228 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
229 return false;
230 }
231
232 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
233 return false;
234 }
235
236 public void onDestroyActionMode(ActionMode mode) {
237 }
238
239 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
240 return false;
241 }
242 };
243
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700245 Object tag = v.getTag();
246 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700247 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700248 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 }
250
251 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700252 // Return if global dragging is not enabled
253 if (!mLauncher.isDraggingEnabled()) return true;
254
Adam Cohendf2cc412011-04-27 16:56:57 -0700255 Object tag = v.getTag();
256 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700257 ShortcutInfo item = (ShortcutInfo) tag;
258 if (!v.isInTouchMode()) {
259 return false;
260 }
261
Winson Chung7d7541e2011-09-16 20:14:36 -0700262 mLauncher.dismissFolderCling(null);
263
Adam Cohendf2cc412011-04-27 16:56:57 -0700264 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700265 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700266 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700267
268 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700269 mEmptyCell[0] = item.cellX;
270 mEmptyCell[1] = item.cellY;
271 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700272
273 mContent.removeView(mCurrentDragView);
274 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700275 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700276 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700277 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800278 return true;
279 }
280
Adam Cohen76fc0852011-06-17 13:26:23 -0700281 public boolean isEditingName() {
282 return mIsEditingName;
283 }
284
285 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700286 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700287 mIsEditingName = true;
288 }
289
290 public void dismissEditingName() {
291 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
292 doneEditingFolderName(true);
293 }
294
295 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700296 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700297 // Convert to a string here to ensure that no other state associated with the text field
298 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700299 String newTitle = mFolderName.getText().toString();
300 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700301 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700302
Adam Cohen3371da02011-10-25 21:38:29 -0700303 if (commit) {
304 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700305 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700306 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700307 // In order to clear the focus from the text field, we set the focus on ourself. This
308 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
309 requestFocus();
310
Adam Cohene601a432011-07-26 21:51:30 -0700311 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700312 mIsEditingName = false;
313 }
314
315 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
316 if (actionId == EditorInfo.IME_ACTION_DONE) {
317 dismissEditingName();
318 return true;
319 }
320 return false;
321 }
322
323 public View getEditTextRegion() {
324 return mFolderName;
325 }
326
Adam Cohenbadf71e2011-05-26 19:08:29 -0700327 public Drawable getDragDrawable() {
328 return mIconDrawable;
329 }
330
Adam Cohen0c872ba2011-05-05 10:34:16 -0700331 /**
332 * We need to handle touch events to prevent them from falling through to the workspace below.
333 */
334 @Override
335 public boolean onTouchEvent(MotionEvent ev) {
336 return true;
337 }
338
Joe Onorato00acb122009-08-04 16:04:30 -0400339 public void setDragController(DragController dragController) {
340 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800341 }
342
Adam Cohen2801caf2011-05-13 20:57:39 -0700343 void setFolderIcon(FolderIcon icon) {
344 mFolderIcon = icon;
345 }
346
Adam Cohen3371da02011-10-25 21:38:29 -0700347 @Override
348 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
349 // When the folder gets focus, we don't want to announce the list of items.
350 return true;
351 }
352
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800353 /**
354 * @return the FolderInfo object associated with this folder
355 */
356 FolderInfo getInfo() {
357 return mInfo;
358 }
359
Adam Cohen3bf84d32012-05-07 20:17:14 -0700360 private class GridComparator implements Comparator<ShortcutInfo> {
361 int mNumCols;
362 public GridComparator(int numCols) {
363 mNumCols = numCols;
364 }
365
366 @Override
367 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
368 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
369 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
370 return (lhIndex - rhIndex);
371 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700372 }
373
374 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
375 int maxX = 0;
376 int count = items.size();
377 for (int i = 0; i < count; i++) {
378 ShortcutInfo item = items.get(i);
379 if (item.cellX > maxX) {
380 maxX = item.cellX;
381 }
382 }
Adam Cohen691a5792012-05-11 14:27:30 -0700383
384 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700385 Collections.sort(items, gridComparator);
386 final int countX = mContent.getCountX();
387 for (int i = 0; i < count; i++) {
388 int x = i % countX;
389 int y = i / countX;
390 ShortcutInfo item = items.get(i);
391 item.cellX = x;
392 item.cellY = y;
393 }
394 }
395
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800396 void bind(FolderInfo info) {
397 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700398 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700399 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700400 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700401 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700402 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700403 for (int i = 0; i < children.size(); i++) {
404 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700405 if (!createAndAddShortcut(child)) {
406 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700407 } else {
408 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700409 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700410 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700411
Adam Cohen0057bbc2011-08-12 18:30:51 -0700412 // We rearrange the items in case there are any empty gaps
413 setupContentForNumItems(count);
414
Adam Cohenc508b2d2011-06-28 14:41:44 -0700415 // If our folder has too many items we prune them from the list. This is an issue
416 // when upgrading from the old Folders implementation which could contain an unlimited
417 // number of items.
418 for (ShortcutInfo item: overflow) {
419 mInfo.remove(item);
420 LauncherModel.deleteItemFromDatabase(mLauncher, item);
421 }
422
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700423 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700424 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700425 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700426
Adam Cohenafb01ee2011-06-23 15:38:03 -0700427 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700428 mFolderName.setText(mInfo.title);
429 } else {
430 mFolderName.setText("");
431 }
Adam Cohen691a5792012-05-11 14:27:30 -0700432 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700433 }
434
435 /**
436 * Creates a new UserFolder, inflated from R.layout.user_folder.
437 *
438 * @param context The application's context.
439 *
440 * @return A new UserFolder.
441 */
442 static Folder fromXml(Context context) {
443 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
444 }
445
446 /**
447 * This method is intended to make the UserFolder to be visually identical in size and position
448 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
449 */
450 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700451 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800452 setScaleX(0.8f);
453 setScaleY(0.8f);
454 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700455 mState = STATE_SMALL;
456 }
457
458 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700459 positionAndSizeAsIcon();
460
Adam Cohen8e776a62011-06-28 18:10:06 -0700461 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700462 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800463 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
464 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
465 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200466 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700467 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800468
Adam Cohen2801caf2011-05-13 20:57:39 -0700469 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700470 @Override
471 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700472 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700473 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700474 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700475 mState = STATE_ANIMATING;
476 }
477 @Override
478 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700479 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700480 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700481 Cling cling = mLauncher.showFirstRunFoldersCling();
482 if (cling != null) {
483 cling.bringToFront();
484 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700485 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700486 }
487 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700488 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700489 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100490 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700491 }
492
Adam Cohen3371da02011-10-25 21:38:29 -0700493 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700494 AccessibilityManager accessibilityManager = (AccessibilityManager)
495 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
496 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700497 AccessibilityEvent event = AccessibilityEvent.obtain(type);
498 onInitializeAccessibilityEvent(event);
499 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700500 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700501 }
502 }
503
Adam Cohenac56cff2011-09-28 20:45:37 -0700504 private void setFocusOnFirstChild() {
505 View firstChild = mContent.getChildAt(0, 0);
506 if (firstChild != null) {
507 firstChild.requestFocus();
508 }
509 }
510
Adam Cohendf2cc412011-04-27 16:56:57 -0700511 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700512 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800513 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
514 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
515 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200516 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700517 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700518
Adam Cohen2801caf2011-05-13 20:57:39 -0700519 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700520 @Override
521 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700522 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700523 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700524 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700525 }
526 @Override
527 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700528 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700529 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700530 mState = STATE_ANIMATING;
531 }
532 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700533 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700534 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100535 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700536 }
537
538 void notifyDataSetChanged() {
539 // recreate all the children if the data set changes under us. We may want to do this more
540 // intelligently (ie just removing the views that should no longer exist)
541 mContent.removeAllViewsInLayout();
542 bind(mInfo);
543 }
544
Adam Cohencb3382b2011-05-24 14:07:08 -0700545 public boolean acceptDrop(DragObject d) {
546 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700547 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700548 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
549 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
550 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700551 }
552
Adam Cohendf2cc412011-04-27 16:56:57 -0700553 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
554 int[] emptyCell = new int[2];
555 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
556 item.cellX = emptyCell[0];
557 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700558 return true;
559 } else {
560 return false;
561 }
562 }
563
Adam Cohenc508b2d2011-06-28 14:41:44 -0700564 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700565 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700566 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700567 textView.setCompoundDrawablesWithIntrinsicBounds(null,
568 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
569 textView.setText(item.title);
570 textView.setTag(item);
571
572 textView.setOnClickListener(this);
573 textView.setOnLongClickListener(this);
574
Adam Cohenc508b2d2011-06-28 14:41:44 -0700575 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700576 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700577 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
578 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700579 // This shouldn't happen, log it.
580 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700581 if (!findAndSetEmptyCells(item)) {
582 return false;
583 }
584 }
585
Adam Cohendf2cc412011-04-27 16:56:57 -0700586 CellLayout.LayoutParams lp =
587 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
588 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700589 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700590 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700591 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700592 }
593
Adam Cohencb3382b2011-05-24 14:07:08 -0700594 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700595 mPreviousTargetCell[0] = -1;
596 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700597 mOnExitAlarm.cancelAlarm();
598 }
599
600 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
601 public void onAlarm(Alarm alarm) {
602 realTimeReorder(mEmptyCell, mTargetCell);
603 }
604 };
605
606 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
607 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
608 return true;
609 } else {
610 return false;
611 }
612 }
613
614 private void realTimeReorder(int[] empty, int[] target) {
615 boolean wrap;
616 int startX;
617 int endX;
618 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700619 int delay = 0;
620 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700621 if (readingOrderGreaterThan(target, empty)) {
622 wrap = empty[0] >= mContent.getCountX() - 1;
623 startY = wrap ? empty[1] + 1 : empty[1];
624 for (int y = startY; y <= target[1]; y++) {
625 startX = y == empty[1] ? empty[0] + 1 : 0;
626 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
627 for (int x = startX; x <= endX; x++) {
628 View v = mContent.getChildAt(x,y);
629 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800630 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700631 empty[0] = x;
632 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700633 delay += delayAmount;
634 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700635 }
636 }
637 }
638 } else {
639 wrap = empty[0] == 0;
640 startY = wrap ? empty[1] - 1 : empty[1];
641 for (int y = startY; y >= target[1]; y--) {
642 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
643 endX = y > target[1] ? 0 : target[0];
644 for (int x = startX; x >= endX; x--) {
645 View v = mContent.getChildAt(x,y);
646 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800647 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700648 empty[0] = x;
649 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700650 delay += delayAmount;
651 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700652 }
653 }
654 }
655 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700656 }
657
Adam Cohen2374abf2013-04-16 14:56:57 -0700658 public boolean isLayoutRtl() {
659 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
660 }
661
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700662 private Rect getDragObjectDrawingRect(View dragView, float[] r) {
663 final Rect drawingRect = mTempRect;
664 drawingRect.left = (int) r[0];
665 drawingRect.top = (int) r[1];
666 drawingRect.right = drawingRect.left + dragView.getMeasuredWidth();
667 drawingRect.bottom = drawingRect.top + dragView.getMeasuredHeight();
668 return drawingRect;
669 }
670
Adam Cohencb3382b2011-05-24 14:07:08 -0700671 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700672 int scrollOffset = mScrollView.getScrollY();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700673 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700674 r[0] -= getPaddingLeft();
675 r[1] -= getPaddingTop();
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700676 if (!mAutoScroller.onTouch(this, getDragObjectDrawingRect(d.dragView, r))) {
677 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1,
678 mTargetCell);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700679
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700680 if (isLayoutRtl()) {
681 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700682 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700683 if (mTargetCell[0] != mPreviousTargetCell[0]
684 || mTargetCell[1] != mPreviousTargetCell[1]) {
685 mReorderAlarm.cancelAlarm();
686 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
687 mReorderAlarm.setAlarm(REORDER_DELAY);
688 mPreviousTargetCell[0] = mTargetCell[0];
689 mPreviousTargetCell[1] = mTargetCell[1];
690 mDragMode = DRAG_MODE_REORDER;
691 } else {
692 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700693 }
Adam Cohenbfbfd262011-06-13 16:55:12 -0700694 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700695 }
696
Adam Cohenbfbfd262011-06-13 16:55:12 -0700697 // This is used to compute the visual center of the dragView. The idea is that
698 // the visual center represents the user's interpretation of where the item is, and hence
699 // is the appropriate point to use when determining drop location.
700 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
701 DragView dragView, float[] recycle) {
702 float res[];
703 if (recycle == null) {
704 res = new float[2];
705 } else {
706 res = recycle;
707 }
708
709 // These represent the visual top and left of drag view if a dragRect was provided.
710 // If a dragRect was not provided, then they correspond to the actual view left and
711 // top, as the dragRect is in that case taken to be the entire dragView.
712 // R.dimen.dragViewOffsetY.
713 int left = x - xOffset;
714 int top = y - yOffset;
715
716 // In order to find the visual center, we shift by half the dragRect
717 res[0] = left + dragView.getDragRegion().width() / 2;
718 res[1] = top + dragView.getDragRegion().height() / 2;
719
720 return res;
721 }
722
723 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
724 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700725 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700726 }
727 };
728
Adam Cohen95bb8002011-07-03 23:40:28 -0700729 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700730 mLauncher.closeFolder();
731 mCurrentDragInfo = null;
732 mCurrentDragView = null;
733 mSuppressOnAdd = false;
734 mRearrangeOnClose = true;
735 }
736
Adam Cohencb3382b2011-05-24 14:07:08 -0700737 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700738 // Exiting folder; stop the auto scroller.
739 mAutoScroller.stop();
740 // We only close the folder if this is a true drag exit, ie. not because
741 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700742 if (!d.dragComplete) {
743 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
744 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
745 }
746 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700747 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700748 }
749
Michael Jurka1e2f4652013-07-08 18:03:46 -0700750 public void onDropCompleted(final View target, final DragObject d,
751 final boolean isFlingToDelete, final boolean success) {
752 if (mDeferDropAfterUninstall) {
753 mDeferredAction = new Runnable() {
754 public void run() {
755 onDropCompleted(target, d, isFlingToDelete, success);
756 mDeferredAction = null;
757 }
758 };
759 return;
760 }
761
762 boolean beingCalledAfterUninstall = mDeferredAction != null;
763 boolean successfulDrop =
764 success && (!beingCalledAfterUninstall || mUninstallSuccessful);
765 if (successfulDrop) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700766 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700767 replaceFolderWithFinalItem();
768 }
769 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700770 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700771 // The drag failed, we need to return the item to the folder
772 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700773 }
774
775 if (target != this) {
776 if (mOnExitAlarm.alarmPending()) {
777 mOnExitAlarm.cancelAlarm();
Michael Jurka1e2f4652013-07-08 18:03:46 -0700778 if (successfulDrop) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700779 mSuppressFolderDeletion = true;
780 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700781 completeDragExit();
782 }
783 }
784 mDeleteFolderOnDropCompleted = false;
785 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700786 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700787 mCurrentDragInfo = null;
788 mCurrentDragView = null;
789 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700790
791 // Reordering may have occured, and we need to save the new item locations. We do this once
792 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700793 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700794 }
795
Michael Jurka1e2f4652013-07-08 18:03:46 -0700796 public void deferCompleteDropAfterUninstallActivity() {
797 mDeferDropAfterUninstall = true;
798 }
799
800 public void onUninstallActivityReturned(boolean success) {
801 mDeferDropAfterUninstall = false;
802 mUninstallSuccessful = success;
803 if (mDeferredAction != null) {
804 mDeferredAction.run();
805 }
806 }
807
Winson Chunga48487a2012-03-20 16:19:37 -0700808 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800809 public boolean supportsFlingToDelete() {
810 return true;
811 }
812
Winson Chunga48487a2012-03-20 16:19:37 -0700813 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
814 // Do nothing
815 }
816
817 @Override
818 public void onFlingToDeleteCompleted() {
819 // Do nothing
820 }
821
Adam Cohen4045eb72011-10-06 11:44:26 -0700822 private void updateItemLocationsInDatabase() {
823 ArrayList<View> list = getItemsInReadingOrder();
824 for (int i = 0; i < list.size(); i++) {
825 View v = list.get(i);
826 ItemInfo info = (ItemInfo) v.getTag();
827 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
828 info.cellX, info.cellY);
829 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700830 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700831
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700832 private void updateItemLocationsInDatabaseBatch() {
833 ArrayList<View> list = getItemsInReadingOrder();
834 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
835 for (int i = 0; i < list.size(); i++) {
836 View v = list.get(i);
837 ItemInfo info = (ItemInfo) v.getTag();
838 items.add(info);
839 }
840
841 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
842 }
843
Adam Cohene25af792013-06-06 23:08:25 -0700844 public void addItemLocationsInDatabase() {
845 ArrayList<View> list = getItemsInReadingOrder();
846 for (int i = 0; i < list.size(); i++) {
847 View v = list.get(i);
848 ItemInfo info = (ItemInfo) v.getTag();
849 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
850 info.cellX, info.cellY, false);
851 }
852 }
853
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700854 public void notifyDrop() {
855 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700856 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700857 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700858 }
859
860 public boolean isDropEnabled() {
861 return true;
862 }
863
Adam Cohen4045eb72011-10-06 11:44:26 -0700864 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700865 ArrayList<View> list = getItemsInReadingOrder();
866
867 int countX = mContent.getCountX();
868 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700869 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700870
Adam Cohen7c693212011-05-18 15:26:57 -0700871 while (!done) {
872 int oldCountX = countX;
873 int oldCountY = countY;
874 if (countX * countY < count) {
875 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800876 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700877 countX++;
878 } else if (countY < mMaxCountY) {
879 countY++;
880 }
881 if (countY == 0) countY++;
882 } else if ((countY - 1) * countX >= count && countY >= countX) {
883 countY = Math.max(0, countY - 1);
884 } else if ((countX - 1) * countY >= count) {
885 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700886 }
Adam Cohen7c693212011-05-18 15:26:57 -0700887 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700888 }
Adam Cohen7c693212011-05-18 15:26:57 -0700889 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700890 arrangeChildren(list);
891 }
892
893 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800894 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700895 }
896
897 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700898 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700899
900 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700901 int height = getFolderHeight();
Adam Cohen8e776a62011-06-28 18:10:06 -0700902 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700903
Adam Cohen307fe232012-08-16 17:55:58 -0700904 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700905
Adam Cohen307fe232012-08-16 17:55:58 -0700906 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
907 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700908 int centeredLeft = centerX - width / 2;
909 int centeredTop = centerY - height / 2;
910
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800911 int currentPage = mLauncher.getWorkspace().getCurrentPage();
912 // In case the workspace is scrolling, we need to use the final scroll to compute
913 // the folders bounds.
914 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700915 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800916 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700917 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700918 Rect bounds = new Rect();
919 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800920 // We reset the workspaces scroll
921 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700922
Adam Cohen35e7e642011-07-17 14:47:18 -0700923 // We need to bound the folder to the currently visible CellLayoutChildren
924 int left = Math.min(Math.max(bounds.left, centeredLeft),
925 bounds.left + bounds.width() - width);
926 int top = Math.min(Math.max(bounds.top, centeredTop),
927 bounds.top + bounds.height() - height);
928 // If the folder doesn't fit within the bounds, center it about the desired bounds
929 if (width >= bounds.width()) {
930 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700931 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700932 if (height >= bounds.height()) {
933 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700934 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700935
936 int folderPivotX = width / 2 + (centeredLeft - left);
937 int folderPivotY = height / 2 + (centeredTop - top);
938 setPivotX(folderPivotX);
939 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700940 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700941 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700942 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700943 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700944
Adam Cohen662b5982011-12-13 17:45:21 -0800945 lp.width = width;
946 lp.height = height;
947 lp.x = left;
948 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700949 }
950
Adam Cohen268c4752012-06-06 17:47:33 -0700951 float getPivotXForIconAnimation() {
952 return mFolderIconPivotX;
953 }
954 float getPivotYForIconAnimation() {
955 return mFolderIconPivotY;
956 }
957
Adam Cohen2801caf2011-05-13 20:57:39 -0700958 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700959 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700960
Adam Cohen8e776a62011-06-28 18:10:06 -0700961 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700962 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700963 lp = new DragLayer.LayoutParams(0, 0);
964 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700965 setLayoutParams(lp);
966 }
967 centerAboutIcon();
968 }
969
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700970 private int getFolderHeight() {
971 int contentAreaHeight = mContent.getDesiredHeight();
972 if (contentAreaHeight >= mMaxContentAreaHeight) {
973 // Subtract a bit so the user can see that it's scrollable.
974 contentAreaHeight = mMaxContentAreaHeight;
975 }
976 int height = getPaddingTop() + getPaddingBottom() + contentAreaHeight
Adam Cohenf4bb1cd2011-07-22 14:36:03 -0700977 + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700978 return height;
979 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700980
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700981 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohen234c4cd2011-07-17 21:03:04 -0700982
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700983 int contentAreaHeight = mContent.getDesiredHeight();
984 if (contentAreaHeight >= mMaxContentAreaHeight) {
985 // Subtract a bit so the user can see that it's scrollable.
986 contentAreaHeight = mMaxContentAreaHeight;
987 }
988
989 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
990 int height = getFolderHeight();
991 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
992 MeasureSpec.EXACTLY);
993 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentAreaHeight,
994 MeasureSpec.EXACTLY);
995
996 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
997 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
998 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -0700999 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
1000 setMeasuredDimension(width, height);
1001 }
1002
Adam Cohen2801caf2011-05-13 20:57:39 -07001003 private void arrangeChildren(ArrayList<View> list) {
1004 int[] vacant = new int[2];
1005 if (list == null) {
1006 list = getItemsInReadingOrder();
1007 }
1008 mContent.removeAllViews();
1009
1010 for (int i = 0; i < list.size(); i++) {
1011 View v = list.get(i);
1012 mContent.getVacantCell(vacant, 1, 1);
1013 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
1014 lp.cellX = vacant[0];
1015 lp.cellY = vacant[1];
1016 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -07001017 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
1018 info.cellX = vacant[0];
1019 info.cellY = vacant[1];
1020 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
1021 info.cellX, info.cellY);
1022 }
Adam Cohen2801caf2011-05-13 20:57:39 -07001023 boolean insert = false;
1024 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1025 }
Adam Cohen7c693212011-05-18 15:26:57 -07001026 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001027 }
1028
Adam Cohena9cf38f2011-05-02 15:36:58 -07001029 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001030 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001031 }
1032
1033 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001034 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001035 }
1036
Adam Cohen2801caf2011-05-13 20:57:39 -07001037 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001038 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001039 if (parent != null) {
1040 parent.removeView(this);
1041 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001042 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001043 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001044 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001045
Adam Cohen2801caf2011-05-13 20:57:39 -07001046 if (mRearrangeOnClose) {
1047 setupContentForNumItems(getItemCount());
1048 mRearrangeOnClose = false;
1049 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001050 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001051 if (!mDragInProgress && !mSuppressFolderDeletion) {
1052 replaceFolderWithFinalItem();
1053 } else if (mDragInProgress) {
1054 mDeleteFolderOnDropCompleted = true;
1055 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001056 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001057 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001058 }
1059
1060 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001061 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001062 Runnable onCompleteRunnable = new Runnable() {
1063 @Override
1064 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001065 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001066
Adam Cohenc5e63f32012-07-12 16:16:57 -07001067 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001068 // Move the item from the folder to the workspace, in the position of the folder
1069 if (getItemCount() == 1) {
1070 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001071 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001072 finalItem);
1073 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001074 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001075 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001076 if (getItemCount() <= 1) {
1077 // Remove the folder
1078 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1079 cellLayout.removeView(mFolderIcon);
1080 if (mFolderIcon instanceof DropTarget) {
1081 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1082 }
1083 mLauncher.removeFolder(mInfo);
1084 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001085 // We add the child after removing the folder to prevent both from existing at
1086 // the same time in the CellLayout.
1087 if (child != null) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001088 mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001089 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1090 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001091 }
1092 };
1093 View finalChild = getItemAt(0);
1094 if (finalChild != null) {
1095 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001096 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001097 mDestroyed = true;
1098 }
1099
1100 boolean isDestroyed() {
1101 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001102 }
1103
Adam Cohenac56cff2011-09-28 20:45:37 -07001104 // This method keeps track of the last item in the folder for the purposes
1105 // of keyboard focus
1106 private void updateTextViewFocus() {
1107 View lastChild = getItemAt(getItemCount() - 1);
1108 getItemAt(getItemCount() - 1);
1109 if (lastChild != null) {
1110 mFolderName.setNextFocusDownId(lastChild.getId());
1111 mFolderName.setNextFocusRightId(lastChild.getId());
1112 mFolderName.setNextFocusLeftId(lastChild.getId());
1113 mFolderName.setNextFocusUpId(lastChild.getId());
1114 }
1115 }
1116
Adam Cohenbfbfd262011-06-13 16:55:12 -07001117 public void onDrop(DragObject d) {
1118 ShortcutInfo item;
1119 if (d.dragInfo instanceof ApplicationInfo) {
1120 // Came from all apps -- make a copy
1121 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1122 item.spanX = 1;
1123 item.spanY = 1;
1124 } else {
1125 item = (ShortcutInfo) d.dragInfo;
1126 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001127 // Dragged from self onto self, currently this is the only path possible, however
1128 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001129 if (item == mCurrentDragInfo) {
1130 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1131 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1132 si.cellX = lp.cellX = mEmptyCell[0];
1133 si.cellX = lp.cellY = mEmptyCell[1];
1134 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001135 if (d.dragView.hasDrawn()) {
1136 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1137 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001138 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001139 mCurrentDragView.setVisibility(VISIBLE);
1140 }
Adam Cohene9166b22011-07-08 17:11:11 -07001141 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001142 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001143 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001144 }
1145 mInfo.add(item);
1146 }
1147
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001148 // This is used so the item doesn't immediately appear in the folder when added. In one case
1149 // we need to create the illusion that the item isn't added back to the folder yet, to
1150 // to correspond to the animation of the icon back into the folder. This is
1151 public void hideItem(ShortcutInfo info) {
1152 View v = getViewForInfo(info);
1153 v.setVisibility(INVISIBLE);
1154 }
1155 public void showItem(ShortcutInfo info) {
1156 View v = getViewForInfo(info);
1157 v.setVisibility(VISIBLE);
1158 }
1159
Adam Cohenbfbfd262011-06-13 16:55:12 -07001160 public void onAdd(ShortcutInfo item) {
1161 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001162 // If the item was dropped onto this open folder, we have done the work associated
1163 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001164 if (mSuppressOnAdd) return;
1165 if (!findAndSetEmptyCells(item)) {
1166 // The current layout is full, can we expand it?
1167 setupContentForNumItems(getItemCount() + 1);
1168 findAndSetEmptyCells(item);
1169 }
1170 createAndAddShortcut(item);
1171 LauncherModel.addOrMoveItemInDatabase(
1172 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1173 }
1174
Adam Cohena9cf38f2011-05-02 15:36:58 -07001175 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001176 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001177 // If this item is being dragged from this open folder, we have already handled
1178 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001179 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001180 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001181 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001182 if (mState == STATE_ANIMATING) {
1183 mRearrangeOnClose = true;
1184 } else {
1185 setupContentForNumItems(getItemCount());
1186 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001187 if (getItemCount() <= 1) {
1188 replaceFolderWithFinalItem();
1189 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001190 }
Adam Cohen7c693212011-05-18 15:26:57 -07001191
Adam Cohendf1e4e82011-06-24 15:57:39 -07001192 private View getViewForInfo(ShortcutInfo item) {
1193 for (int j = 0; j < mContent.getCountY(); j++) {
1194 for (int i = 0; i < mContent.getCountX(); i++) {
1195 View v = mContent.getChildAt(i, j);
1196 if (v.getTag() == item) {
1197 return v;
1198 }
1199 }
1200 }
1201 return null;
1202 }
1203
Adam Cohen76078c42011-06-09 15:06:52 -07001204 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001205 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001206 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001207
Adam Cohen76fc0852011-06-17 13:26:23 -07001208 public void onTitleChanged(CharSequence title) {
1209 }
Adam Cohen76078c42011-06-09 15:06:52 -07001210
Adam Cohen7c693212011-05-18 15:26:57 -07001211 public ArrayList<View> getItemsInReadingOrder() {
1212 if (mItemsInvalidated) {
1213 mItemsInReadingOrder.clear();
1214 for (int j = 0; j < mContent.getCountY(); j++) {
1215 for (int i = 0; i < mContent.getCountX(); i++) {
1216 View v = mContent.getChildAt(i, j);
1217 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001218 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001219 }
1220 }
1221 }
1222 mItemsInvalidated = false;
1223 }
1224 return mItemsInReadingOrder;
1225 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001226
1227 public void getLocationInDragLayer(int[] loc) {
1228 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1229 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001230
1231 public void onFocusChange(View v, boolean hasFocus) {
1232 if (v == mFolderName && hasFocus) {
1233 startEditingFolderName();
1234 }
1235 }
Adam Cohen7d30a372013-07-01 17:03:59 -07001236
1237 @Override
1238 public void getHitRectRelativeToDragLayer(Rect outRect) {
1239 getHitRect(outRect);
1240 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241}