blob: 347a1d428a72ce4272cf0988584c029d89321db6 [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);
138 mIconCache = ((LauncherApplication)context.getApplicationContext()).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) {
239 // refactor this code from Folder
240 ShortcutInfo item = (ShortcutInfo) tag;
241 int[] pos = new int[2];
242 v.getLocationOnScreen(pos);
243 item.intent.setSourceBounds(new Rect(pos[0], pos[1],
244 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Winson Chungc7450e32012-04-17 17:34:08 -0700245
246 mLauncher.startActivitySafely(v, item.intent, item);
Adam Cohendf2cc412011-04-27 16:56:57 -0700247 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800248 }
249
250 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700251 // Return if global dragging is not enabled
252 if (!mLauncher.isDraggingEnabled()) return true;
253
Adam Cohendf2cc412011-04-27 16:56:57 -0700254 Object tag = v.getTag();
255 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700256 ShortcutInfo item = (ShortcutInfo) tag;
257 if (!v.isInTouchMode()) {
258 return false;
259 }
260
Winson Chung7d7541e2011-09-16 20:14:36 -0700261 mLauncher.dismissFolderCling(null);
262
Adam Cohendf2cc412011-04-27 16:56:57 -0700263 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700264 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700265 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700266
267 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700268 mEmptyCell[0] = item.cellX;
269 mEmptyCell[1] = item.cellY;
270 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700271
272 mContent.removeView(mCurrentDragView);
273 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700274 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700275 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700276 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 return true;
278 }
279
Adam Cohen76fc0852011-06-17 13:26:23 -0700280 public boolean isEditingName() {
281 return mIsEditingName;
282 }
283
284 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700285 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700286 mIsEditingName = true;
287 }
288
289 public void dismissEditingName() {
290 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
291 doneEditingFolderName(true);
292 }
293
294 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700295 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700296 // Convert to a string here to ensure that no other state associated with the text field
297 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700298 String newTitle = mFolderName.getText().toString();
299 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700300 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700301
Adam Cohen3371da02011-10-25 21:38:29 -0700302 if (commit) {
303 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700304 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700305 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700306 // In order to clear the focus from the text field, we set the focus on ourself. This
307 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
308 requestFocus();
309
Adam Cohene601a432011-07-26 21:51:30 -0700310 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700311 mIsEditingName = false;
312 }
313
314 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
315 if (actionId == EditorInfo.IME_ACTION_DONE) {
316 dismissEditingName();
317 return true;
318 }
319 return false;
320 }
321
322 public View getEditTextRegion() {
323 return mFolderName;
324 }
325
Adam Cohenbadf71e2011-05-26 19:08:29 -0700326 public Drawable getDragDrawable() {
327 return mIconDrawable;
328 }
329
Adam Cohen0c872ba2011-05-05 10:34:16 -0700330 /**
331 * We need to handle touch events to prevent them from falling through to the workspace below.
332 */
333 @Override
334 public boolean onTouchEvent(MotionEvent ev) {
335 return true;
336 }
337
Joe Onorato00acb122009-08-04 16:04:30 -0400338 public void setDragController(DragController dragController) {
339 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800340 }
341
Adam Cohen2801caf2011-05-13 20:57:39 -0700342 void setFolderIcon(FolderIcon icon) {
343 mFolderIcon = icon;
344 }
345
Adam Cohen3371da02011-10-25 21:38:29 -0700346 @Override
347 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
348 // When the folder gets focus, we don't want to announce the list of items.
349 return true;
350 }
351
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800352 /**
353 * @return the FolderInfo object associated with this folder
354 */
355 FolderInfo getInfo() {
356 return mInfo;
357 }
358
Adam Cohen3bf84d32012-05-07 20:17:14 -0700359 private class GridComparator implements Comparator<ShortcutInfo> {
360 int mNumCols;
361 public GridComparator(int numCols) {
362 mNumCols = numCols;
363 }
364
365 @Override
366 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
367 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
368 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
369 return (lhIndex - rhIndex);
370 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700371 }
372
373 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
374 int maxX = 0;
375 int count = items.size();
376 for (int i = 0; i < count; i++) {
377 ShortcutInfo item = items.get(i);
378 if (item.cellX > maxX) {
379 maxX = item.cellX;
380 }
381 }
Adam Cohen691a5792012-05-11 14:27:30 -0700382
383 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700384 Collections.sort(items, gridComparator);
385 final int countX = mContent.getCountX();
386 for (int i = 0; i < count; i++) {
387 int x = i % countX;
388 int y = i / countX;
389 ShortcutInfo item = items.get(i);
390 item.cellX = x;
391 item.cellY = y;
392 }
393 }
394
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800395 void bind(FolderInfo info) {
396 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700397 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700398 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700399 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700400 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700401 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700402 for (int i = 0; i < children.size(); i++) {
403 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700404 if (!createAndAddShortcut(child)) {
405 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700406 } else {
407 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700408 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700409 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700410
Adam Cohen0057bbc2011-08-12 18:30:51 -0700411 // We rearrange the items in case there are any empty gaps
412 setupContentForNumItems(count);
413
Adam Cohenc508b2d2011-06-28 14:41:44 -0700414 // If our folder has too many items we prune them from the list. This is an issue
415 // when upgrading from the old Folders implementation which could contain an unlimited
416 // number of items.
417 for (ShortcutInfo item: overflow) {
418 mInfo.remove(item);
419 LauncherModel.deleteItemFromDatabase(mLauncher, item);
420 }
421
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700422 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700423 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700424 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700425
Adam Cohenafb01ee2011-06-23 15:38:03 -0700426 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700427 mFolderName.setText(mInfo.title);
428 } else {
429 mFolderName.setText("");
430 }
Adam Cohen691a5792012-05-11 14:27:30 -0700431 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700432 }
433
434 /**
435 * Creates a new UserFolder, inflated from R.layout.user_folder.
436 *
437 * @param context The application's context.
438 *
439 * @return A new UserFolder.
440 */
441 static Folder fromXml(Context context) {
442 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
443 }
444
445 /**
446 * This method is intended to make the UserFolder to be visually identical in size and position
447 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
448 */
449 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700450 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800451 setScaleX(0.8f);
452 setScaleY(0.8f);
453 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700454 mState = STATE_SMALL;
455 }
456
457 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700458 positionAndSizeAsIcon();
459
Adam Cohen8e776a62011-06-28 18:10:06 -0700460 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700461 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800462 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
463 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
464 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200465 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700466 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800467
Adam Cohen2801caf2011-05-13 20:57:39 -0700468 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700469 @Override
470 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700471 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700472 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700473 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700474 mState = STATE_ANIMATING;
475 }
476 @Override
477 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700478 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700479 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700480 Cling cling = mLauncher.showFirstRunFoldersCling();
481 if (cling != null) {
482 cling.bringToFront();
483 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700484 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700485 }
486 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700487 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700488 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100489 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700490 }
491
Adam Cohen3371da02011-10-25 21:38:29 -0700492 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700493 AccessibilityManager accessibilityManager = (AccessibilityManager)
494 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
495 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700496 AccessibilityEvent event = AccessibilityEvent.obtain(type);
497 onInitializeAccessibilityEvent(event);
498 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700499 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700500 }
501 }
502
Adam Cohenac56cff2011-09-28 20:45:37 -0700503 private void setFocusOnFirstChild() {
504 View firstChild = mContent.getChildAt(0, 0);
505 if (firstChild != null) {
506 firstChild.requestFocus();
507 }
508 }
509
Adam Cohendf2cc412011-04-27 16:56:57 -0700510 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700511 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800512 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
513 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
514 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200515 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700516 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700517
Adam Cohen2801caf2011-05-13 20:57:39 -0700518 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700519 @Override
520 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700521 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700522 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700523 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700524 }
525 @Override
526 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700527 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700528 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700529 mState = STATE_ANIMATING;
530 }
531 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700532 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700533 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100534 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700535 }
536
537 void notifyDataSetChanged() {
538 // recreate all the children if the data set changes under us. We may want to do this more
539 // intelligently (ie just removing the views that should no longer exist)
540 mContent.removeAllViewsInLayout();
541 bind(mInfo);
542 }
543
Adam Cohencb3382b2011-05-24 14:07:08 -0700544 public boolean acceptDrop(DragObject d) {
545 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700546 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700547 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
548 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
549 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700550 }
551
Adam Cohendf2cc412011-04-27 16:56:57 -0700552 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
553 int[] emptyCell = new int[2];
554 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
555 item.cellX = emptyCell[0];
556 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700557 return true;
558 } else {
559 return false;
560 }
561 }
562
Adam Cohenc508b2d2011-06-28 14:41:44 -0700563 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700564 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700565 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700566 textView.setCompoundDrawablesWithIntrinsicBounds(null,
567 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
568 textView.setText(item.title);
569 textView.setTag(item);
570
571 textView.setOnClickListener(this);
572 textView.setOnLongClickListener(this);
573
Adam Cohenc508b2d2011-06-28 14:41:44 -0700574 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700575 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700576 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
577 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700578 // This shouldn't happen, log it.
579 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700580 if (!findAndSetEmptyCells(item)) {
581 return false;
582 }
583 }
584
Adam Cohendf2cc412011-04-27 16:56:57 -0700585 CellLayout.LayoutParams lp =
586 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
587 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700588 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700589 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700590 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700591 }
592
Adam Cohencb3382b2011-05-24 14:07:08 -0700593 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700594 mPreviousTargetCell[0] = -1;
595 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700596 mOnExitAlarm.cancelAlarm();
597 }
598
599 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
600 public void onAlarm(Alarm alarm) {
601 realTimeReorder(mEmptyCell, mTargetCell);
602 }
603 };
604
605 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
606 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
607 return true;
608 } else {
609 return false;
610 }
611 }
612
613 private void realTimeReorder(int[] empty, int[] target) {
614 boolean wrap;
615 int startX;
616 int endX;
617 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700618 int delay = 0;
619 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700620 if (readingOrderGreaterThan(target, empty)) {
621 wrap = empty[0] >= mContent.getCountX() - 1;
622 startY = wrap ? empty[1] + 1 : empty[1];
623 for (int y = startY; y <= target[1]; y++) {
624 startX = y == empty[1] ? empty[0] + 1 : 0;
625 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
626 for (int x = startX; x <= endX; x++) {
627 View v = mContent.getChildAt(x,y);
628 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800629 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700630 empty[0] = x;
631 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700632 delay += delayAmount;
633 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700634 }
635 }
636 }
637 } else {
638 wrap = empty[0] == 0;
639 startY = wrap ? empty[1] - 1 : empty[1];
640 for (int y = startY; y >= target[1]; y--) {
641 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
642 endX = y > target[1] ? 0 : target[0];
643 for (int x = startX; x >= endX; x--) {
644 View v = mContent.getChildAt(x,y);
645 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800646 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700647 empty[0] = x;
648 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700649 delay += delayAmount;
650 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700651 }
652 }
653 }
654 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700655 }
656
Adam Cohen2374abf2013-04-16 14:56:57 -0700657 public boolean isLayoutRtl() {
658 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
659 }
660
Adam Cohencb3382b2011-05-24 14:07:08 -0700661 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700662 int scrollOffset = mScrollView.getScrollY();
663
Adam Cohenbfbfd262011-06-13 16:55:12 -0700664 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700665 r[0] -= getPaddingLeft();
666 r[1] -= getPaddingTop();
667
668 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset,
669 1, 1, mTargetCell);
Adam Cohenbfbfd262011-06-13 16:55:12 -0700670
Adam Cohen2374abf2013-04-16 14:56:57 -0700671 if (isLayoutRtl()) {
672 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
673 }
674
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700675 if (r[1] < SCROLL_BAND_HEIGHT && mScrollView.getScrollY() > 0) {
676 // Scroll up
677 if (mDragMode != DRAG_MODE_SCROLL_UP) {
678 mDragMode = DRAG_MODE_SCROLL_UP;
679 scrollUp();
680 }
681 mReorderAlarm.cancelAlarm();
682 } else if (r[1] > (getFolderHeight() - SCROLL_BAND_HEIGHT) && mScrollView.getScrollY() <
683 (mContent.getMeasuredHeight() - mScrollView.getMeasuredHeight())) {
684 if (mDragMode != DRAG_MODE_SCROLL_DOWN) {
685 mDragMode = DRAG_MODE_SCROLL_DOWN;
686 scrollDown();
687 }
688 mReorderAlarm.cancelAlarm();
689 } else if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700690 mReorderAlarm.cancelAlarm();
691 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700692 mReorderAlarm.setAlarm(REORDER_DELAY);
Adam Cohenbfbfd262011-06-13 16:55:12 -0700693 mPreviousTargetCell[0] = mTargetCell[0];
694 mPreviousTargetCell[1] = mTargetCell[1];
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700695 mDragMode = DRAG_MODE_REORDER;
696 } else {
697 mDragMode = DRAG_MODE_NONE;
698 }
699 }
700
701 Runnable mScrollUpRunnable = new Runnable() {
702 @Override
703 public void run() {
704 scrollUp();
705 }
706 };
707
708 Runnable mScrollDownRunnable = new Runnable() {
709 @Override
710 public void run() {
711 scrollDown();
712 }
713 };
714
715 private void scrollUp() {
716 if (mDragMode == DRAG_MODE_SCROLL_UP) {
717 mScrollView.setScrollY(mScrollView.getScrollY() - 7);
718 invalidate();
719 post(mScrollUpRunnable);
720 }
721 }
722
723 private void scrollDown() {
724 if (mDragMode == DRAG_MODE_SCROLL_DOWN) {
725 mScrollView.setScrollY(mScrollView.getScrollY() + 7);
726 invalidate();
727 post(mScrollDownRunnable);
Adam Cohenbfbfd262011-06-13 16:55:12 -0700728 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700729 }
730
Adam Cohenbfbfd262011-06-13 16:55:12 -0700731 // This is used to compute the visual center of the dragView. The idea is that
732 // the visual center represents the user's interpretation of where the item is, and hence
733 // is the appropriate point to use when determining drop location.
734 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
735 DragView dragView, float[] recycle) {
736 float res[];
737 if (recycle == null) {
738 res = new float[2];
739 } else {
740 res = recycle;
741 }
742
743 // These represent the visual top and left of drag view if a dragRect was provided.
744 // If a dragRect was not provided, then they correspond to the actual view left and
745 // top, as the dragRect is in that case taken to be the entire dragView.
746 // R.dimen.dragViewOffsetY.
747 int left = x - xOffset;
748 int top = y - yOffset;
749
750 // In order to find the visual center, we shift by half the dragRect
751 res[0] = left + dragView.getDragRegion().width() / 2;
752 res[1] = top + dragView.getDragRegion().height() / 2;
753
754 return res;
755 }
756
757 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
758 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700759 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700760 }
761 };
762
Adam Cohen95bb8002011-07-03 23:40:28 -0700763 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700764 mLauncher.closeFolder();
765 mCurrentDragInfo = null;
766 mCurrentDragView = null;
767 mSuppressOnAdd = false;
768 mRearrangeOnClose = true;
769 }
770
Adam Cohencb3382b2011-05-24 14:07:08 -0700771 public void onDragExit(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700772 // We only close the folder if this is a true drag exit, ie. not because a drop
773 // has occurred above the folder.
774 if (!d.dragComplete) {
775 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
776 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
777 }
778 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700779 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700780 }
781
Winson Chunga48487a2012-03-20 16:19:37 -0700782 public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete,
783 boolean success) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700784 if (success) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700785 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700786 replaceFolderWithFinalItem();
787 }
788 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700789 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700790 // The drag failed, we need to return the item to the folder
791 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700792 }
793
794 if (target != this) {
795 if (mOnExitAlarm.alarmPending()) {
796 mOnExitAlarm.cancelAlarm();
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700797 if (!success) {
798 mSuppressFolderDeletion = true;
799 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700800 completeDragExit();
801 }
802 }
803 mDeleteFolderOnDropCompleted = false;
804 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700805 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700806 mCurrentDragInfo = null;
807 mCurrentDragView = null;
808 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700809
810 // Reordering may have occured, and we need to save the new item locations. We do this once
811 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700812 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700813 }
814
Winson Chunga48487a2012-03-20 16:19:37 -0700815 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800816 public boolean supportsFlingToDelete() {
817 return true;
818 }
819
Winson Chunga48487a2012-03-20 16:19:37 -0700820 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
821 // Do nothing
822 }
823
824 @Override
825 public void onFlingToDeleteCompleted() {
826 // Do nothing
827 }
828
Adam Cohen4045eb72011-10-06 11:44:26 -0700829 private void updateItemLocationsInDatabase() {
830 ArrayList<View> list = getItemsInReadingOrder();
831 for (int i = 0; i < list.size(); i++) {
832 View v = list.get(i);
833 ItemInfo info = (ItemInfo) v.getTag();
834 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
835 info.cellX, info.cellY);
836 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700837 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700838
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700839 private void updateItemLocationsInDatabaseBatch() {
840 ArrayList<View> list = getItemsInReadingOrder();
841 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
842 for (int i = 0; i < list.size(); i++) {
843 View v = list.get(i);
844 ItemInfo info = (ItemInfo) v.getTag();
845 items.add(info);
846 }
847
848 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
849 }
850
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700851 public void notifyDrop() {
852 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700853 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700854 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700855 }
856
857 public boolean isDropEnabled() {
858 return true;
859 }
860
Adam Cohencb3382b2011-05-24 14:07:08 -0700861 public DropTarget getDropTargetDelegate(DragObject d) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700862 return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800863 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700864
Adam Cohen4045eb72011-10-06 11:44:26 -0700865 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700866 ArrayList<View> list = getItemsInReadingOrder();
867
868 int countX = mContent.getCountX();
869 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700870 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700871
Adam Cohen7c693212011-05-18 15:26:57 -0700872 while (!done) {
873 int oldCountX = countX;
874 int oldCountY = countY;
875 if (countX * countY < count) {
876 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800877 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700878 countX++;
879 } else if (countY < mMaxCountY) {
880 countY++;
881 }
882 if (countY == 0) countY++;
883 } else if ((countY - 1) * countX >= count && countY >= countX) {
884 countY = Math.max(0, countY - 1);
885 } else if ((countX - 1) * countY >= count) {
886 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700887 }
Adam Cohen7c693212011-05-18 15:26:57 -0700888 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700889 }
Adam Cohen7c693212011-05-18 15:26:57 -0700890 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700891 arrangeChildren(list);
892 }
893
894 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800895 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700896 }
897
898 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700899 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700900
901 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700902 int height = getFolderHeight();
Adam Cohen8e776a62011-06-28 18:10:06 -0700903 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700904
Adam Cohen307fe232012-08-16 17:55:58 -0700905 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700906
Adam Cohen307fe232012-08-16 17:55:58 -0700907 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
908 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700909 int centeredLeft = centerX - width / 2;
910 int centeredTop = centerY - height / 2;
911
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800912 int currentPage = mLauncher.getWorkspace().getCurrentPage();
913 // In case the workspace is scrolling, we need to use the final scroll to compute
914 // the folders bounds.
915 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700916 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800917 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700918 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700919 Rect bounds = new Rect();
920 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800921 // We reset the workspaces scroll
922 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700923
Adam Cohen35e7e642011-07-17 14:47:18 -0700924 // We need to bound the folder to the currently visible CellLayoutChildren
925 int left = Math.min(Math.max(bounds.left, centeredLeft),
926 bounds.left + bounds.width() - width);
927 int top = Math.min(Math.max(bounds.top, centeredTop),
928 bounds.top + bounds.height() - height);
929 // If the folder doesn't fit within the bounds, center it about the desired bounds
930 if (width >= bounds.width()) {
931 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700932 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700933 if (height >= bounds.height()) {
934 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700935 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700936
937 int folderPivotX = width / 2 + (centeredLeft - left);
938 int folderPivotY = height / 2 + (centeredTop - top);
939 setPivotX(folderPivotX);
940 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700941 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700942 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700943 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700944 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700945
Adam Cohen662b5982011-12-13 17:45:21 -0800946 lp.width = width;
947 lp.height = height;
948 lp.x = left;
949 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700950 }
951
Adam Cohen268c4752012-06-06 17:47:33 -0700952 float getPivotXForIconAnimation() {
953 return mFolderIconPivotX;
954 }
955 float getPivotYForIconAnimation() {
956 return mFolderIconPivotY;
957 }
958
Adam Cohen2801caf2011-05-13 20:57:39 -0700959 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700960 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700961
Adam Cohen8e776a62011-06-28 18:10:06 -0700962 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700963 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700964 lp = new DragLayer.LayoutParams(0, 0);
965 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700966 setLayoutParams(lp);
967 }
968 centerAboutIcon();
969 }
970
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700971 private int getFolderHeight() {
972 int contentAreaHeight = mContent.getDesiredHeight();
973 if (contentAreaHeight >= mMaxContentAreaHeight) {
974 // Subtract a bit so the user can see that it's scrollable.
975 contentAreaHeight = mMaxContentAreaHeight;
976 }
977 int height = getPaddingTop() + getPaddingBottom() + contentAreaHeight
Adam Cohenf4bb1cd2011-07-22 14:36:03 -0700978 + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700979 return height;
980 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700981
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700982 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohen234c4cd2011-07-17 21:03:04 -0700983
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700984 int contentAreaHeight = mContent.getDesiredHeight();
985 if (contentAreaHeight >= mMaxContentAreaHeight) {
986 // Subtract a bit so the user can see that it's scrollable.
987 contentAreaHeight = mMaxContentAreaHeight;
988 }
989
990 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
991 int height = getFolderHeight();
992 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
993 MeasureSpec.EXACTLY);
994 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentAreaHeight,
995 MeasureSpec.EXACTLY);
996
997 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
998 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
999 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -07001000 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
1001 setMeasuredDimension(width, height);
1002 }
1003
Adam Cohen2801caf2011-05-13 20:57:39 -07001004 private void arrangeChildren(ArrayList<View> list) {
1005 int[] vacant = new int[2];
1006 if (list == null) {
1007 list = getItemsInReadingOrder();
1008 }
1009 mContent.removeAllViews();
1010
1011 for (int i = 0; i < list.size(); i++) {
1012 View v = list.get(i);
1013 mContent.getVacantCell(vacant, 1, 1);
1014 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
1015 lp.cellX = vacant[0];
1016 lp.cellY = vacant[1];
1017 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -07001018 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
1019 info.cellX = vacant[0];
1020 info.cellY = vacant[1];
1021 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
1022 info.cellX, info.cellY);
1023 }
Adam Cohen2801caf2011-05-13 20:57:39 -07001024 boolean insert = false;
1025 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1026 }
Adam Cohen7c693212011-05-18 15:26:57 -07001027 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001028 }
1029
Adam Cohena9cf38f2011-05-02 15:36:58 -07001030 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001031 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001032 }
1033
1034 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001035 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001036 }
1037
Adam Cohen2801caf2011-05-13 20:57:39 -07001038 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001039 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001040 if (parent != null) {
1041 parent.removeView(this);
1042 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001043 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001044 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001045 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001046
Adam Cohen2801caf2011-05-13 20:57:39 -07001047 if (mRearrangeOnClose) {
1048 setupContentForNumItems(getItemCount());
1049 mRearrangeOnClose = false;
1050 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001051 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001052 if (!mDragInProgress && !mSuppressFolderDeletion) {
1053 replaceFolderWithFinalItem();
1054 } else if (mDragInProgress) {
1055 mDeleteFolderOnDropCompleted = true;
1056 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001057 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001058 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001059 }
1060
1061 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001062 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001063 Runnable onCompleteRunnable = new Runnable() {
1064 @Override
1065 public void run() {
1066 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001067
Adam Cohenc5e63f32012-07-12 16:16:57 -07001068 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001069 // Move the item from the folder to the workspace, in the position of the folder
1070 if (getItemCount() == 1) {
1071 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001072 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001073 finalItem);
1074 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
1075 mInfo.screen, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001076 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001077 if (getItemCount() <= 1) {
1078 // Remove the folder
1079 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1080 cellLayout.removeView(mFolderIcon);
1081 if (mFolderIcon instanceof DropTarget) {
1082 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1083 }
1084 mLauncher.removeFolder(mInfo);
1085 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001086 // We add the child after removing the folder to prevent both from existing at
1087 // the same time in the CellLayout.
1088 if (child != null) {
1089 mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screen,
1090 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1091 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001092 }
1093 };
1094 View finalChild = getItemAt(0);
1095 if (finalChild != null) {
1096 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001097 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001098 mDestroyed = true;
1099 }
1100
1101 boolean isDestroyed() {
1102 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001103 }
1104
Adam Cohenac56cff2011-09-28 20:45:37 -07001105 // This method keeps track of the last item in the folder for the purposes
1106 // of keyboard focus
1107 private void updateTextViewFocus() {
1108 View lastChild = getItemAt(getItemCount() - 1);
1109 getItemAt(getItemCount() - 1);
1110 if (lastChild != null) {
1111 mFolderName.setNextFocusDownId(lastChild.getId());
1112 mFolderName.setNextFocusRightId(lastChild.getId());
1113 mFolderName.setNextFocusLeftId(lastChild.getId());
1114 mFolderName.setNextFocusUpId(lastChild.getId());
1115 }
1116 }
1117
Adam Cohenbfbfd262011-06-13 16:55:12 -07001118 public void onDrop(DragObject d) {
1119 ShortcutInfo item;
1120 if (d.dragInfo instanceof ApplicationInfo) {
1121 // Came from all apps -- make a copy
1122 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1123 item.spanX = 1;
1124 item.spanY = 1;
1125 } else {
1126 item = (ShortcutInfo) d.dragInfo;
1127 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001128 // Dragged from self onto self, currently this is the only path possible, however
1129 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001130 if (item == mCurrentDragInfo) {
1131 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1132 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1133 si.cellX = lp.cellX = mEmptyCell[0];
1134 si.cellX = lp.cellY = mEmptyCell[1];
1135 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001136 if (d.dragView.hasDrawn()) {
1137 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1138 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001139 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001140 mCurrentDragView.setVisibility(VISIBLE);
1141 }
Adam Cohene9166b22011-07-08 17:11:11 -07001142 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001143 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001144 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001145 }
1146 mInfo.add(item);
1147 }
1148
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001149 // This is used so the item doesn't immediately appear in the folder when added. In one case
1150 // we need to create the illusion that the item isn't added back to the folder yet, to
1151 // to correspond to the animation of the icon back into the folder. This is
1152 public void hideItem(ShortcutInfo info) {
1153 View v = getViewForInfo(info);
1154 v.setVisibility(INVISIBLE);
1155 }
1156 public void showItem(ShortcutInfo info) {
1157 View v = getViewForInfo(info);
1158 v.setVisibility(VISIBLE);
1159 }
1160
Adam Cohenbfbfd262011-06-13 16:55:12 -07001161 public void onAdd(ShortcutInfo item) {
1162 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001163 // If the item was dropped onto this open folder, we have done the work associated
1164 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001165 if (mSuppressOnAdd) return;
1166 if (!findAndSetEmptyCells(item)) {
1167 // The current layout is full, can we expand it?
1168 setupContentForNumItems(getItemCount() + 1);
1169 findAndSetEmptyCells(item);
1170 }
1171 createAndAddShortcut(item);
1172 LauncherModel.addOrMoveItemInDatabase(
1173 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1174 }
1175
Adam Cohena9cf38f2011-05-02 15:36:58 -07001176 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001177 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001178 // If this item is being dragged from this open folder, we have already handled
1179 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001180 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001181 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001182 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001183 if (mState == STATE_ANIMATING) {
1184 mRearrangeOnClose = true;
1185 } else {
1186 setupContentForNumItems(getItemCount());
1187 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001188 if (getItemCount() <= 1) {
1189 replaceFolderWithFinalItem();
1190 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001191 }
Adam Cohen7c693212011-05-18 15:26:57 -07001192
Adam Cohendf1e4e82011-06-24 15:57:39 -07001193 private View getViewForInfo(ShortcutInfo item) {
1194 for (int j = 0; j < mContent.getCountY(); j++) {
1195 for (int i = 0; i < mContent.getCountX(); i++) {
1196 View v = mContent.getChildAt(i, j);
1197 if (v.getTag() == item) {
1198 return v;
1199 }
1200 }
1201 }
1202 return null;
1203 }
1204
Adam Cohen76078c42011-06-09 15:06:52 -07001205 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001206 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001207 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001208
Adam Cohen76fc0852011-06-17 13:26:23 -07001209 public void onTitleChanged(CharSequence title) {
1210 }
Adam Cohen76078c42011-06-09 15:06:52 -07001211
Adam Cohen7c693212011-05-18 15:26:57 -07001212 public ArrayList<View> getItemsInReadingOrder() {
1213 if (mItemsInvalidated) {
1214 mItemsInReadingOrder.clear();
1215 for (int j = 0; j < mContent.getCountY(); j++) {
1216 for (int i = 0; i < mContent.getCountX(); i++) {
1217 View v = mContent.getChildAt(i, j);
1218 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001219 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001220 }
1221 }
1222 }
1223 mItemsInvalidated = false;
1224 }
1225 return mItemsInReadingOrder;
1226 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001227
1228 public void getLocationInDragLayer(int[] loc) {
1229 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1230 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001231
1232 public void onFocusChange(View v, boolean hasFocus) {
1233 if (v == mFolderName && hasFocus) {
1234 startEditingFolderName();
1235 }
1236 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237}