blob: 9eafc223162f742d76cd1861c7db117433b7b218 [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;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070023import android.content.ComponentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024import android.content.Context;
Adam Cohen76fc0852011-06-17 13:26:23 -070025import android.content.res.Resources;
Winson Chung043f2af2012-03-01 16:09:54 -080026import android.graphics.PointF;
Romain Guyfb5411e2010-02-24 10:04:17 -080027import android.graphics.Rect;
Adam Cohenbadf71e2011-05-26 19:08:29 -070028import android.graphics.drawable.Drawable;
Adam Cohen7a14d0b2011-06-24 11:36:35 -070029import android.text.InputType;
Adam Cohene601a432011-07-26 21:51:30 -070030import android.text.Selection;
31import android.text.Spannable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032import android.util.AttributeSet;
Adam Cohen3bf84d32012-05-07 20:17:14 -070033import android.util.Log;
Adam Cohen76fc0852011-06-17 13:26:23 -070034import android.view.ActionMode;
35import android.view.KeyEvent;
Adam Cohendf2cc412011-04-27 16:56:57 -070036import android.view.LayoutInflater;
Adam Cohen76fc0852011-06-17 13:26:23 -070037import android.view.Menu;
38import android.view.MenuItem;
Adam Cohen0c872ba2011-05-05 10:34:16 -070039import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.view.View;
Adam Cohen3371da02011-10-25 21:38:29 -070041import android.view.accessibility.AccessibilityEvent;
42import android.view.accessibility.AccessibilityManager;
Adam Cohen76fc0852011-06-17 13:26:23 -070043import android.view.inputmethod.EditorInfo;
44import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070046import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070047import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048
Daniel Sandler325dc232013-06-05 22:57:57 -040049import com.android.launcher3.R;
50import 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;
112 private static final int SCROLL_BAND_HEIGHT = 110;
113
Adam Cohen76fc0852011-06-17 13:26:23 -0700114 private boolean mIsEditingName = false;
115 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700116
Adam Cohena65beee2011-06-27 21:32:23 -0700117 private static String sDefaultFolderName;
118 private static String sHintText;
119
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700120 private int DRAG_MODE_NONE = 0;
121 private int DRAG_MODE_REORDER = 1;
122 private int DRAG_MODE_SCROLL_UP = 2;
123 private int DRAG_MODE_SCROLL_DOWN = 3;
124 private int mDragMode = DRAG_MODE_NONE;
125
Adam Cohenfb91f302012-06-11 15:45:18 -0700126 private boolean mDestroyed;
127
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 /**
129 * Used to inflate the Workspace from XML.
130 *
131 * @param context The application's context.
132 * @param attrs The attribtues set containing the Workspace's customization values.
133 */
134 public Folder(Context context, AttributeSet attrs) {
135 super(context, attrs);
136 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700137 mInflater = LayoutInflater.from(context);
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400138 mIconCache = (LauncherAppState.getInstance()).getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800139
140 Resources res = getResources();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700141 mMaxCountX = mMaxVisibleX = res.getInteger(R.integer.folder_max_count_x);
142 mMaxCountY = mMaxVisibleY = res.getInteger(R.integer.folder_max_count_y);
Adam Cohen78dc83e2011-11-15 17:10:00 -0800143 mMaxNumItems = res.getInteger(R.integer.folder_max_num_items);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700144
145 if (mMaxCountY == -1) {
146 // -2 indicates unlimited
147 mMaxCountY = Integer.MAX_VALUE;
148 mMaxVisibleX = LauncherModel.getCellCountX() + 1;
149 }
150 if (mMaxNumItems == -1) {
151 // -2 indicates unlimited
152 mMaxNumItems = Integer.MAX_VALUE;
153 mMaxVisibleY = LauncherModel.getCellCountY() + 1;
154 }
155 if (mMaxCountX == 0) {
156 mMaxCountX = mMaxVisibleX = LauncherModel.getCellCountX();
157 mMaxVisibleX++;
158 }
159 if (mMaxCountY == 0) {
160 mMaxCountY = mMaxVisibleY = LauncherModel.getCellCountY();
161 mMaxVisibleY++;
162 }
163 if (mMaxNumItems == 0) {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800164 mMaxNumItems = mMaxCountX * mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700165 if (mMaxNumItems < 0) {
166 mMaxNumItems = Integer.MAX_VALUE;
167 }
Adam Cohen78dc83e2011-11-15 17:10:00 -0800168 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700169
170 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700171 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700172
Adam Cohen76fc0852011-06-17 13:26:23 -0700173 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700174
175 if (sDefaultFolderName == null) {
176 sDefaultFolderName = res.getString(R.string.folder_name);
177 }
Adam Cohena65beee2011-06-27 21:32:23 -0700178 if (sHintText == null) {
179 sHintText = res.getString(R.string.folder_hint_text);
180 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700181 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700182 // We need this view to be focusable in touch mode so that when text editing of the folder
183 // name is complete, we have something to focus on, thus hiding the cursor and giving
184 // reliable behvior when clicking the text field (since it will always gain focus on click).
185 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186 }
187
188 @Override
189 protected void onFinishInflate() {
190 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700191 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700192 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700193
194 // Beyond this height, the area scrolls
195 mContent.setGridSize(mMaxVisibleX, mMaxVisibleY);
196 mMaxContentAreaHeight = mContent.getDesiredHeight() - SCROLL_CUT_OFF_AMOUNT;
197
Adam Cohen2801caf2011-05-13 20:57:39 -0700198 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700199 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700200 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700201 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
202 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700203 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700204
205 // We find out how tall the text view wants to be (it is set to wrap_content), so that
206 // we can allocate the appropriate amount of space for it.
207 int measureSpec = MeasureSpec.UNSPECIFIED;
208 mFolderName.measure(measureSpec, measureSpec);
209 mFolderNameHeight = mFolderName.getMeasuredHeight();
210
211 // We disable action mode for now since it messes up the view on phones
212 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700213 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700214 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700215 mFolderName.setInputType(mFolderName.getInputType() |
216 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700218
Adam Cohen76fc0852011-06-17 13:26:23 -0700219 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
220 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
221 return false;
222 }
223
224 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
225 return false;
226 }
227
228 public void onDestroyActionMode(ActionMode mode) {
229 }
230
231 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
232 return false;
233 }
234 };
235
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800236 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700237 Object tag = v.getTag();
238 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700239 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700240 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800241 }
242
243 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700244 // Return if global dragging is not enabled
245 if (!mLauncher.isDraggingEnabled()) return true;
246
Adam Cohendf2cc412011-04-27 16:56:57 -0700247 Object tag = v.getTag();
248 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700249 ShortcutInfo item = (ShortcutInfo) tag;
250 if (!v.isInTouchMode()) {
251 return false;
252 }
253
Winson Chung7d7541e2011-09-16 20:14:36 -0700254 mLauncher.dismissFolderCling(null);
255
Adam Cohendf2cc412011-04-27 16:56:57 -0700256 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700257 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700258 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700259
260 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700261 mEmptyCell[0] = item.cellX;
262 mEmptyCell[1] = item.cellY;
263 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700264
265 mContent.removeView(mCurrentDragView);
266 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700267 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700268 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700269 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 return true;
271 }
272
Adam Cohen76fc0852011-06-17 13:26:23 -0700273 public boolean isEditingName() {
274 return mIsEditingName;
275 }
276
277 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700278 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700279 mIsEditingName = true;
280 }
281
282 public void dismissEditingName() {
283 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
284 doneEditingFolderName(true);
285 }
286
287 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700288 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700289 // Convert to a string here to ensure that no other state associated with the text field
290 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700291 String newTitle = mFolderName.getText().toString();
292 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700293 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700294
Adam Cohen3371da02011-10-25 21:38:29 -0700295 if (commit) {
296 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700297 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700298 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700299 // In order to clear the focus from the text field, we set the focus on ourself. This
300 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
301 requestFocus();
302
Adam Cohene601a432011-07-26 21:51:30 -0700303 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700304 mIsEditingName = false;
305 }
306
307 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
308 if (actionId == EditorInfo.IME_ACTION_DONE) {
309 dismissEditingName();
310 return true;
311 }
312 return false;
313 }
314
315 public View getEditTextRegion() {
316 return mFolderName;
317 }
318
Adam Cohenbadf71e2011-05-26 19:08:29 -0700319 public Drawable getDragDrawable() {
320 return mIconDrawable;
321 }
322
Adam Cohen0c872ba2011-05-05 10:34:16 -0700323 /**
324 * We need to handle touch events to prevent them from falling through to the workspace below.
325 */
326 @Override
327 public boolean onTouchEvent(MotionEvent ev) {
328 return true;
329 }
330
Joe Onorato00acb122009-08-04 16:04:30 -0400331 public void setDragController(DragController dragController) {
332 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800333 }
334
Adam Cohen2801caf2011-05-13 20:57:39 -0700335 void setFolderIcon(FolderIcon icon) {
336 mFolderIcon = icon;
337 }
338
Adam Cohen3371da02011-10-25 21:38:29 -0700339 @Override
340 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
341 // When the folder gets focus, we don't want to announce the list of items.
342 return true;
343 }
344
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800345 /**
346 * @return the FolderInfo object associated with this folder
347 */
348 FolderInfo getInfo() {
349 return mInfo;
350 }
351
Adam Cohen3bf84d32012-05-07 20:17:14 -0700352 private class GridComparator implements Comparator<ShortcutInfo> {
353 int mNumCols;
354 public GridComparator(int numCols) {
355 mNumCols = numCols;
356 }
357
358 @Override
359 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
360 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
361 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
362 return (lhIndex - rhIndex);
363 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700364 }
365
366 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
367 int maxX = 0;
368 int count = items.size();
369 for (int i = 0; i < count; i++) {
370 ShortcutInfo item = items.get(i);
371 if (item.cellX > maxX) {
372 maxX = item.cellX;
373 }
374 }
Adam Cohen691a5792012-05-11 14:27:30 -0700375
376 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700377 Collections.sort(items, gridComparator);
378 final int countX = mContent.getCountX();
379 for (int i = 0; i < count; i++) {
380 int x = i % countX;
381 int y = i / countX;
382 ShortcutInfo item = items.get(i);
383 item.cellX = x;
384 item.cellY = y;
385 }
386 }
387
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 void bind(FolderInfo info) {
389 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700390 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700391 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700392 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700393 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700394 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700395 for (int i = 0; i < children.size(); i++) {
396 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700397 if (!createAndAddShortcut(child)) {
398 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700399 } else {
400 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700401 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700402 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700403
Adam Cohen0057bbc2011-08-12 18:30:51 -0700404 // We rearrange the items in case there are any empty gaps
405 setupContentForNumItems(count);
406
Adam Cohenc508b2d2011-06-28 14:41:44 -0700407 // If our folder has too many items we prune them from the list. This is an issue
408 // when upgrading from the old Folders implementation which could contain an unlimited
409 // number of items.
410 for (ShortcutInfo item: overflow) {
411 mInfo.remove(item);
412 LauncherModel.deleteItemFromDatabase(mLauncher, item);
413 }
414
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700415 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700416 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700417 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700418
Adam Cohenafb01ee2011-06-23 15:38:03 -0700419 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700420 mFolderName.setText(mInfo.title);
421 } else {
422 mFolderName.setText("");
423 }
Adam Cohen691a5792012-05-11 14:27:30 -0700424 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700425 }
426
427 /**
428 * Creates a new UserFolder, inflated from R.layout.user_folder.
429 *
430 * @param context The application's context.
431 *
432 * @return A new UserFolder.
433 */
434 static Folder fromXml(Context context) {
435 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
436 }
437
438 /**
439 * This method is intended to make the UserFolder to be visually identical in size and position
440 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
441 */
442 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700443 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800444 setScaleX(0.8f);
445 setScaleY(0.8f);
446 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700447 mState = STATE_SMALL;
448 }
449
450 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700451 positionAndSizeAsIcon();
452
Adam Cohen8e776a62011-06-28 18:10:06 -0700453 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700454 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800455 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
456 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
457 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200458 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700459 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800460
Adam Cohen2801caf2011-05-13 20:57:39 -0700461 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700462 @Override
463 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700464 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700465 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700466 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700467 mState = STATE_ANIMATING;
468 }
469 @Override
470 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700471 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700472 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700473 Cling cling = mLauncher.showFirstRunFoldersCling();
474 if (cling != null) {
475 cling.bringToFront();
476 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700477 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700478 }
479 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700480 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700481 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100482 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700483 }
484
Adam Cohen3371da02011-10-25 21:38:29 -0700485 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700486 AccessibilityManager accessibilityManager = (AccessibilityManager)
487 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
488 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700489 AccessibilityEvent event = AccessibilityEvent.obtain(type);
490 onInitializeAccessibilityEvent(event);
491 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700492 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700493 }
494 }
495
Adam Cohenac56cff2011-09-28 20:45:37 -0700496 private void setFocusOnFirstChild() {
497 View firstChild = mContent.getChildAt(0, 0);
498 if (firstChild != null) {
499 firstChild.requestFocus();
500 }
501 }
502
Adam Cohendf2cc412011-04-27 16:56:57 -0700503 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700504 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800505 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
506 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
507 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200508 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700509 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700510
Adam Cohen2801caf2011-05-13 20:57:39 -0700511 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700512 @Override
513 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700514 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700515 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700516 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700517 }
518 @Override
519 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700520 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700521 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700522 mState = STATE_ANIMATING;
523 }
524 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700525 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700526 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100527 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700528 }
529
530 void notifyDataSetChanged() {
531 // recreate all the children if the data set changes under us. We may want to do this more
532 // intelligently (ie just removing the views that should no longer exist)
533 mContent.removeAllViewsInLayout();
534 bind(mInfo);
535 }
536
Adam Cohencb3382b2011-05-24 14:07:08 -0700537 public boolean acceptDrop(DragObject d) {
538 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700539 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700540 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
541 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
542 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700543 }
544
Adam Cohendf2cc412011-04-27 16:56:57 -0700545 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
546 int[] emptyCell = new int[2];
547 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
548 item.cellX = emptyCell[0];
549 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700550 return true;
551 } else {
552 return false;
553 }
554 }
555
Adam Cohenc508b2d2011-06-28 14:41:44 -0700556 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700557 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700558 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700559 textView.setCompoundDrawablesWithIntrinsicBounds(null,
560 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
561 textView.setText(item.title);
562 textView.setTag(item);
563
564 textView.setOnClickListener(this);
565 textView.setOnLongClickListener(this);
566
Adam Cohenc508b2d2011-06-28 14:41:44 -0700567 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700568 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700569 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
570 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700571 // This shouldn't happen, log it.
572 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700573 if (!findAndSetEmptyCells(item)) {
574 return false;
575 }
576 }
577
Adam Cohendf2cc412011-04-27 16:56:57 -0700578 CellLayout.LayoutParams lp =
579 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
580 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700581 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700582 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700583 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700584 }
585
Adam Cohencb3382b2011-05-24 14:07:08 -0700586 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700587 mPreviousTargetCell[0] = -1;
588 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700589 mOnExitAlarm.cancelAlarm();
590 }
591
592 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
593 public void onAlarm(Alarm alarm) {
594 realTimeReorder(mEmptyCell, mTargetCell);
595 }
596 };
597
598 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
599 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
600 return true;
601 } else {
602 return false;
603 }
604 }
605
606 private void realTimeReorder(int[] empty, int[] target) {
607 boolean wrap;
608 int startX;
609 int endX;
610 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700611 int delay = 0;
612 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700613 if (readingOrderGreaterThan(target, empty)) {
614 wrap = empty[0] >= mContent.getCountX() - 1;
615 startY = wrap ? empty[1] + 1 : empty[1];
616 for (int y = startY; y <= target[1]; y++) {
617 startX = y == empty[1] ? empty[0] + 1 : 0;
618 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
619 for (int x = startX; x <= endX; x++) {
620 View v = mContent.getChildAt(x,y);
621 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800622 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700623 empty[0] = x;
624 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700625 delay += delayAmount;
626 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700627 }
628 }
629 }
630 } else {
631 wrap = empty[0] == 0;
632 startY = wrap ? empty[1] - 1 : empty[1];
633 for (int y = startY; y >= target[1]; y--) {
634 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
635 endX = y > target[1] ? 0 : target[0];
636 for (int x = startX; x >= endX; x--) {
637 View v = mContent.getChildAt(x,y);
638 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800639 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700640 empty[0] = x;
641 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700642 delay += delayAmount;
643 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700644 }
645 }
646 }
647 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700648 }
649
Adam Cohen2374abf2013-04-16 14:56:57 -0700650 public boolean isLayoutRtl() {
651 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
652 }
653
Adam Cohencb3382b2011-05-24 14:07:08 -0700654 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700655 int scrollOffset = mScrollView.getScrollY();
656
Adam Cohenbfbfd262011-06-13 16:55:12 -0700657 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700658 r[0] -= getPaddingLeft();
659 r[1] -= getPaddingTop();
660
661 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset,
662 1, 1, mTargetCell);
Adam Cohenbfbfd262011-06-13 16:55:12 -0700663
Adam Cohen2374abf2013-04-16 14:56:57 -0700664 if (isLayoutRtl()) {
665 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
666 }
667
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700668 if (r[1] < SCROLL_BAND_HEIGHT && mScrollView.getScrollY() > 0) {
669 // Scroll up
670 if (mDragMode != DRAG_MODE_SCROLL_UP) {
671 mDragMode = DRAG_MODE_SCROLL_UP;
672 scrollUp();
673 }
674 mReorderAlarm.cancelAlarm();
675 } else if (r[1] > (getFolderHeight() - SCROLL_BAND_HEIGHT) && mScrollView.getScrollY() <
676 (mContent.getMeasuredHeight() - mScrollView.getMeasuredHeight())) {
677 if (mDragMode != DRAG_MODE_SCROLL_DOWN) {
678 mDragMode = DRAG_MODE_SCROLL_DOWN;
679 scrollDown();
680 }
681 mReorderAlarm.cancelAlarm();
682 } else if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700683 mReorderAlarm.cancelAlarm();
684 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700685 mReorderAlarm.setAlarm(REORDER_DELAY);
Adam Cohenbfbfd262011-06-13 16:55:12 -0700686 mPreviousTargetCell[0] = mTargetCell[0];
687 mPreviousTargetCell[1] = mTargetCell[1];
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700688 mDragMode = DRAG_MODE_REORDER;
689 } else {
690 mDragMode = DRAG_MODE_NONE;
691 }
692 }
693
694 Runnable mScrollUpRunnable = new Runnable() {
695 @Override
696 public void run() {
697 scrollUp();
698 }
699 };
700
701 Runnable mScrollDownRunnable = new Runnable() {
702 @Override
703 public void run() {
704 scrollDown();
705 }
706 };
707
708 private void scrollUp() {
709 if (mDragMode == DRAG_MODE_SCROLL_UP) {
710 mScrollView.setScrollY(mScrollView.getScrollY() - 7);
711 invalidate();
712 post(mScrollUpRunnable);
713 }
714 }
715
716 private void scrollDown() {
717 if (mDragMode == DRAG_MODE_SCROLL_DOWN) {
718 mScrollView.setScrollY(mScrollView.getScrollY() + 7);
719 invalidate();
720 post(mScrollDownRunnable);
Adam Cohenbfbfd262011-06-13 16:55:12 -0700721 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700722 }
723
Adam Cohenbfbfd262011-06-13 16:55:12 -0700724 // This is used to compute the visual center of the dragView. The idea is that
725 // the visual center represents the user's interpretation of where the item is, and hence
726 // is the appropriate point to use when determining drop location.
727 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
728 DragView dragView, float[] recycle) {
729 float res[];
730 if (recycle == null) {
731 res = new float[2];
732 } else {
733 res = recycle;
734 }
735
736 // These represent the visual top and left of drag view if a dragRect was provided.
737 // If a dragRect was not provided, then they correspond to the actual view left and
738 // top, as the dragRect is in that case taken to be the entire dragView.
739 // R.dimen.dragViewOffsetY.
740 int left = x - xOffset;
741 int top = y - yOffset;
742
743 // In order to find the visual center, we shift by half the dragRect
744 res[0] = left + dragView.getDragRegion().width() / 2;
745 res[1] = top + dragView.getDragRegion().height() / 2;
746
747 return res;
748 }
749
750 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
751 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700752 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700753 }
754 };
755
Adam Cohen95bb8002011-07-03 23:40:28 -0700756 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700757 mLauncher.closeFolder();
758 mCurrentDragInfo = null;
759 mCurrentDragView = null;
760 mSuppressOnAdd = false;
761 mRearrangeOnClose = true;
762 }
763
Adam Cohencb3382b2011-05-24 14:07:08 -0700764 public void onDragExit(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700765 // We only close the folder if this is a true drag exit, ie. not because a drop
766 // has occurred above the folder.
767 if (!d.dragComplete) {
768 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
769 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
770 }
771 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700772 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700773 }
774
Winson Chunga48487a2012-03-20 16:19:37 -0700775 public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete,
776 boolean success) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700777 if (success) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700778 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700779 replaceFolderWithFinalItem();
780 }
781 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700782 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700783 // The drag failed, we need to return the item to the folder
784 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700785 }
786
787 if (target != this) {
788 if (mOnExitAlarm.alarmPending()) {
789 mOnExitAlarm.cancelAlarm();
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700790 if (!success) {
791 mSuppressFolderDeletion = true;
792 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700793 completeDragExit();
794 }
795 }
796 mDeleteFolderOnDropCompleted = false;
797 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700798 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700799 mCurrentDragInfo = null;
800 mCurrentDragView = null;
801 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700802
803 // Reordering may have occured, and we need to save the new item locations. We do this once
804 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700805 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700806 }
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 Cohencb3382b2011-05-24 14:07:08 -0700864 public DropTarget getDropTargetDelegate(DragObject d) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700865 return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800866 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700867
Adam Cohen4045eb72011-10-06 11:44:26 -0700868 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700869 ArrayList<View> list = getItemsInReadingOrder();
870
871 int countX = mContent.getCountX();
872 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700873 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700874
Adam Cohen7c693212011-05-18 15:26:57 -0700875 while (!done) {
876 int oldCountX = countX;
877 int oldCountY = countY;
878 if (countX * countY < count) {
879 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800880 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700881 countX++;
882 } else if (countY < mMaxCountY) {
883 countY++;
884 }
885 if (countY == 0) countY++;
886 } else if ((countY - 1) * countX >= count && countY >= countX) {
887 countY = Math.max(0, countY - 1);
888 } else if ((countX - 1) * countY >= count) {
889 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700890 }
Adam Cohen7c693212011-05-18 15:26:57 -0700891 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700892 }
Adam Cohen7c693212011-05-18 15:26:57 -0700893 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700894 arrangeChildren(list);
895 }
896
897 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800898 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700899 }
900
901 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700902 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700903
904 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700905 int height = getFolderHeight();
Adam Cohen8e776a62011-06-28 18:10:06 -0700906 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700907
Adam Cohen307fe232012-08-16 17:55:58 -0700908 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700909
Adam Cohen307fe232012-08-16 17:55:58 -0700910 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
911 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700912 int centeredLeft = centerX - width / 2;
913 int centeredTop = centerY - height / 2;
914
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800915 int currentPage = mLauncher.getWorkspace().getCurrentPage();
916 // In case the workspace is scrolling, we need to use the final scroll to compute
917 // the folders bounds.
918 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700919 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800920 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700921 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700922 Rect bounds = new Rect();
923 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800924 // We reset the workspaces scroll
925 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700926
Adam Cohen35e7e642011-07-17 14:47:18 -0700927 // We need to bound the folder to the currently visible CellLayoutChildren
928 int left = Math.min(Math.max(bounds.left, centeredLeft),
929 bounds.left + bounds.width() - width);
930 int top = Math.min(Math.max(bounds.top, centeredTop),
931 bounds.top + bounds.height() - height);
932 // If the folder doesn't fit within the bounds, center it about the desired bounds
933 if (width >= bounds.width()) {
934 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700935 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700936 if (height >= bounds.height()) {
937 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700938 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700939
940 int folderPivotX = width / 2 + (centeredLeft - left);
941 int folderPivotY = height / 2 + (centeredTop - top);
942 setPivotX(folderPivotX);
943 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700944 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700945 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700946 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700947 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700948
Adam Cohen662b5982011-12-13 17:45:21 -0800949 lp.width = width;
950 lp.height = height;
951 lp.x = left;
952 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700953 }
954
Adam Cohen268c4752012-06-06 17:47:33 -0700955 float getPivotXForIconAnimation() {
956 return mFolderIconPivotX;
957 }
958 float getPivotYForIconAnimation() {
959 return mFolderIconPivotY;
960 }
961
Adam Cohen2801caf2011-05-13 20:57:39 -0700962 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700963 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700964
Adam Cohen8e776a62011-06-28 18:10:06 -0700965 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700966 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700967 lp = new DragLayer.LayoutParams(0, 0);
968 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700969 setLayoutParams(lp);
970 }
971 centerAboutIcon();
972 }
973
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700974 private int getFolderHeight() {
975 int contentAreaHeight = mContent.getDesiredHeight();
976 if (contentAreaHeight >= mMaxContentAreaHeight) {
977 // Subtract a bit so the user can see that it's scrollable.
978 contentAreaHeight = mMaxContentAreaHeight;
979 }
980 int height = getPaddingTop() + getPaddingBottom() + contentAreaHeight
Adam Cohenf4bb1cd2011-07-22 14:36:03 -0700981 + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700982 return height;
983 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700984
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700985 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohen234c4cd2011-07-17 21:03:04 -0700986
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700987 int contentAreaHeight = mContent.getDesiredHeight();
988 if (contentAreaHeight >= mMaxContentAreaHeight) {
989 // Subtract a bit so the user can see that it's scrollable.
990 contentAreaHeight = mMaxContentAreaHeight;
991 }
992
993 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
994 int height = getFolderHeight();
995 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
996 MeasureSpec.EXACTLY);
997 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentAreaHeight,
998 MeasureSpec.EXACTLY);
999
1000 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
1001 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
1002 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -07001003 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
1004 setMeasuredDimension(width, height);
1005 }
1006
Adam Cohen2801caf2011-05-13 20:57:39 -07001007 private void arrangeChildren(ArrayList<View> list) {
1008 int[] vacant = new int[2];
1009 if (list == null) {
1010 list = getItemsInReadingOrder();
1011 }
1012 mContent.removeAllViews();
1013
1014 for (int i = 0; i < list.size(); i++) {
1015 View v = list.get(i);
1016 mContent.getVacantCell(vacant, 1, 1);
1017 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
1018 lp.cellX = vacant[0];
1019 lp.cellY = vacant[1];
1020 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -07001021 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
1022 info.cellX = vacant[0];
1023 info.cellY = vacant[1];
1024 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
1025 info.cellX, info.cellY);
1026 }
Adam Cohen2801caf2011-05-13 20:57:39 -07001027 boolean insert = false;
1028 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1029 }
Adam Cohen7c693212011-05-18 15:26:57 -07001030 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001031 }
1032
Adam Cohena9cf38f2011-05-02 15:36:58 -07001033 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001034 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001035 }
1036
1037 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001038 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001039 }
1040
Adam Cohen2801caf2011-05-13 20:57:39 -07001041 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001042 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001043 if (parent != null) {
1044 parent.removeView(this);
1045 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001046 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001047 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001048 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001049
Adam Cohen2801caf2011-05-13 20:57:39 -07001050 if (mRearrangeOnClose) {
1051 setupContentForNumItems(getItemCount());
1052 mRearrangeOnClose = false;
1053 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001054 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001055 if (!mDragInProgress && !mSuppressFolderDeletion) {
1056 replaceFolderWithFinalItem();
1057 } else if (mDragInProgress) {
1058 mDeleteFolderOnDropCompleted = true;
1059 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001060 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001061 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001062 }
1063
1064 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001065 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001066 Runnable onCompleteRunnable = new Runnable() {
1067 @Override
1068 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001069 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001070
Adam Cohenc5e63f32012-07-12 16:16:57 -07001071 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001072 // Move the item from the folder to the workspace, in the position of the folder
1073 if (getItemCount() == 1) {
1074 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001075 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001076 finalItem);
1077 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001078 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001079 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001080 if (getItemCount() <= 1) {
1081 // Remove the folder
1082 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1083 cellLayout.removeView(mFolderIcon);
1084 if (mFolderIcon instanceof DropTarget) {
1085 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1086 }
1087 mLauncher.removeFolder(mInfo);
1088 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001089 // We add the child after removing the folder to prevent both from existing at
1090 // the same time in the CellLayout.
1091 if (child != null) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001092 mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001093 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1094 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001095 }
1096 };
1097 View finalChild = getItemAt(0);
1098 if (finalChild != null) {
1099 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001100 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001101 mDestroyed = true;
1102 }
1103
1104 boolean isDestroyed() {
1105 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001106 }
1107
Adam Cohenac56cff2011-09-28 20:45:37 -07001108 // This method keeps track of the last item in the folder for the purposes
1109 // of keyboard focus
1110 private void updateTextViewFocus() {
1111 View lastChild = getItemAt(getItemCount() - 1);
1112 getItemAt(getItemCount() - 1);
1113 if (lastChild != null) {
1114 mFolderName.setNextFocusDownId(lastChild.getId());
1115 mFolderName.setNextFocusRightId(lastChild.getId());
1116 mFolderName.setNextFocusLeftId(lastChild.getId());
1117 mFolderName.setNextFocusUpId(lastChild.getId());
1118 }
1119 }
1120
Adam Cohenbfbfd262011-06-13 16:55:12 -07001121 public void onDrop(DragObject d) {
1122 ShortcutInfo item;
1123 if (d.dragInfo instanceof ApplicationInfo) {
1124 // Came from all apps -- make a copy
1125 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1126 item.spanX = 1;
1127 item.spanY = 1;
1128 } else {
1129 item = (ShortcutInfo) d.dragInfo;
1130 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001131 // Dragged from self onto self, currently this is the only path possible, however
1132 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001133 if (item == mCurrentDragInfo) {
1134 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1135 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1136 si.cellX = lp.cellX = mEmptyCell[0];
1137 si.cellX = lp.cellY = mEmptyCell[1];
1138 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001139 if (d.dragView.hasDrawn()) {
1140 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1141 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001142 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001143 mCurrentDragView.setVisibility(VISIBLE);
1144 }
Adam Cohene9166b22011-07-08 17:11:11 -07001145 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001146 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001147 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001148 }
1149 mInfo.add(item);
1150 }
1151
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001152 // This is used so the item doesn't immediately appear in the folder when added. In one case
1153 // we need to create the illusion that the item isn't added back to the folder yet, to
1154 // to correspond to the animation of the icon back into the folder. This is
1155 public void hideItem(ShortcutInfo info) {
1156 View v = getViewForInfo(info);
1157 v.setVisibility(INVISIBLE);
1158 }
1159 public void showItem(ShortcutInfo info) {
1160 View v = getViewForInfo(info);
1161 v.setVisibility(VISIBLE);
1162 }
1163
Adam Cohenbfbfd262011-06-13 16:55:12 -07001164 public void onAdd(ShortcutInfo item) {
1165 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001166 // If the item was dropped onto this open folder, we have done the work associated
1167 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001168 if (mSuppressOnAdd) return;
1169 if (!findAndSetEmptyCells(item)) {
1170 // The current layout is full, can we expand it?
1171 setupContentForNumItems(getItemCount() + 1);
1172 findAndSetEmptyCells(item);
1173 }
1174 createAndAddShortcut(item);
1175 LauncherModel.addOrMoveItemInDatabase(
1176 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1177 }
1178
Adam Cohena9cf38f2011-05-02 15:36:58 -07001179 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001180 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001181 // If this item is being dragged from this open folder, we have already handled
1182 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001183 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001184 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001185 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001186 if (mState == STATE_ANIMATING) {
1187 mRearrangeOnClose = true;
1188 } else {
1189 setupContentForNumItems(getItemCount());
1190 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001191 if (getItemCount() <= 1) {
1192 replaceFolderWithFinalItem();
1193 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001194 }
Adam Cohen7c693212011-05-18 15:26:57 -07001195
Adam Cohendf1e4e82011-06-24 15:57:39 -07001196 private View getViewForInfo(ShortcutInfo item) {
1197 for (int j = 0; j < mContent.getCountY(); j++) {
1198 for (int i = 0; i < mContent.getCountX(); i++) {
1199 View v = mContent.getChildAt(i, j);
1200 if (v.getTag() == item) {
1201 return v;
1202 }
1203 }
1204 }
1205 return null;
1206 }
1207
Adam Cohen76078c42011-06-09 15:06:52 -07001208 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001209 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001210 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001211
Adam Cohen76fc0852011-06-17 13:26:23 -07001212 public void onTitleChanged(CharSequence title) {
1213 }
Adam Cohen76078c42011-06-09 15:06:52 -07001214
Adam Cohen7c693212011-05-18 15:26:57 -07001215 public ArrayList<View> getItemsInReadingOrder() {
1216 if (mItemsInvalidated) {
1217 mItemsInReadingOrder.clear();
1218 for (int j = 0; j < mContent.getCountY(); j++) {
1219 for (int i = 0; i < mContent.getCountX(); i++) {
1220 View v = mContent.getChildAt(i, j);
1221 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001222 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001223 }
1224 }
1225 }
1226 mItemsInvalidated = false;
1227 }
1228 return mItemsInReadingOrder;
1229 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001230
1231 public void getLocationInDragLayer(int[] loc) {
1232 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1233 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001234
1235 public void onFocusChange(View v, boolean hasFocus) {
1236 if (v == mFolderName && hasFocus) {
1237 startEditingFolderName();
1238 }
1239 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001240}