blob: d5133afb64ed5b755c0f8f86f964041961e12568 [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;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -070043import android.view.animation.AccelerateInterpolator;
44import android.view.animation.Interpolator;
Adam Cohen76fc0852011-06-17 13:26:23 -070045import android.view.inputmethod.EditorInfo;
46import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.widget.LinearLayout;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070048import android.widget.ScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070049import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050
Daniel Sandler325dc232013-06-05 22:57:57 -040051import com.android.launcher3.R;
52import com.android.launcher3.FolderInfo.FolderListener;
Romain Guyedcce092010-03-04 13:03:17 -080053
Adam Cohenc0dcf592011-06-01 15:30:43 -070054import java.util.ArrayList;
Adam Cohen3bf84d32012-05-07 20:17:14 -070055import java.util.Collections;
56import java.util.Comparator;
Adam Cohenc0dcf592011-06-01 15:30:43 -070057
The Android Open Source Project31dd5032009-03-03 19:32:27 -080058/**
59 * Represents a set of icons chosen by the user or generated by the system.
60 */
Adam Cohen8dfcba42011-07-07 16:38:18 -070061public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
Adam Cohenea0818d2011-09-30 20:06:58 -070062 View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
63 View.OnFocusChangeListener {
Adam Cohendf2cc412011-04-27 16:56:57 -070064 private static final String TAG = "Launcher.Folder";
65
Adam Cohen4eac29a2011-07-11 17:53:37 -070066 protected DragController mDragController;
67 protected Launcher mLauncher;
68 protected FolderInfo mInfo;
69
Adam Cohendf2cc412011-04-27 16:56:57 -070070 static final int STATE_NONE = -1;
71 static final int STATE_SMALL = 0;
72 static final int STATE_ANIMATING = 1;
73 static final int STATE_OPEN = 2;
74
75 private int mExpandDuration;
76 protected CellLayout mContent;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070077 private ScrollView mScrollView;
Adam Cohendf2cc412011-04-27 16:56:57 -070078 private final LayoutInflater mInflater;
79 private final IconCache mIconCache;
80 private int mState = STATE_NONE;
Adam Cohenbfbfd262011-06-13 16:55:12 -070081 private static final int REORDER_ANIMATION_DURATION = 230;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070082 private static final int REORDER_DELAY = 250;
Adam Cohenbfbfd262011-06-13 16:55:12 -070083 private static final int ON_EXIT_CLOSE_DELAY = 800;
Adam Cohen2801caf2011-05-13 20:57:39 -070084 private boolean mRearrangeOnClose = false;
85 private FolderIcon mFolderIcon;
86 private int mMaxCountX;
87 private int mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -070088 private int mMaxVisibleX;
89 private int mMaxVisibleY;
90 private int mMaxContentAreaHeight = 0;
Adam Cohen78dc83e2011-11-15 17:10:00 -080091 private int mMaxNumItems;
Adam Cohen7c693212011-05-18 15:26:57 -070092 private ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
Adam Cohenbadf71e2011-05-26 19:08:29 -070093 private Drawable mIconDrawable;
Adam Cohen7c693212011-05-18 15:26:57 -070094 boolean mItemsInvalidated = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -070095 private ShortcutInfo mCurrentDragInfo;
96 private View mCurrentDragView;
97 boolean mSuppressOnAdd = false;
98 private int[] mTargetCell = new int[2];
99 private int[] mPreviousTargetCell = new int[2];
100 private int[] mEmptyCell = new int[2];
101 private Alarm mReorderAlarm = new Alarm();
102 private Alarm mOnExitAlarm = new Alarm();
Adam Cohen76fc0852011-06-17 13:26:23 -0700103 private int mFolderNameHeight;
Adam Cohen8e776a62011-06-28 18:10:06 -0700104 private Rect mTempRect = new Rect();
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700105 private boolean mDragInProgress = false;
106 private boolean mDeleteFolderOnDropCompleted = false;
107 private boolean mSuppressFolderDeletion = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700108 private boolean mItemAddedBackToSelfViaIcon = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700109 FolderEditText mFolderName;
Adam Cohen268c4752012-06-06 17:47:33 -0700110 private float mFolderIconPivotX;
111 private float mFolderIconPivotY;
Adam Cohen228da5a2011-07-27 22:23:47 -0700112
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700113 private static final int SCROLL_CUT_OFF_AMOUNT = 60;
Mindy DelliCarpini2e7471c2013-06-27 08:45:11 -0700114
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700115 private static final float MAX_SCROLL_VELOCITY = 1500f;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700116
Adam Cohen76fc0852011-06-17 13:26:23 -0700117 private boolean mIsEditingName = false;
118 private InputMethodManager mInputMethodManager;
Adam Cohendf2cc412011-04-27 16:56:57 -0700119
Adam Cohena65beee2011-06-27 21:32:23 -0700120 private static String sDefaultFolderName;
121 private static String sHintText;
122
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700123 private int DRAG_MODE_NONE = 0;
124 private int DRAG_MODE_REORDER = 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700125 private int mDragMode = DRAG_MODE_NONE;
126
Adam Cohenfb91f302012-06-11 15:45:18 -0700127 private boolean mDestroyed;
128
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700129 private AutoScroller mAutoScroller;
130
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 /**
132 * Used to inflate the Workspace from XML.
133 *
134 * @param context The application's context.
135 * @param attrs The attribtues set containing the Workspace's customization values.
136 */
137 public Folder(Context context, AttributeSet attrs) {
138 super(context, attrs);
139 setAlwaysDrawnWithCacheEnabled(false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700140 mInflater = LayoutInflater.from(context);
Daniel Sandlercc8befa2013-06-11 14:45:48 -0400141 mIconCache = (LauncherAppState.getInstance()).getIconCache();
Adam Cohen78dc83e2011-11-15 17:10:00 -0800142
143 Resources res = getResources();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700144 mMaxCountX = mMaxVisibleX = res.getInteger(R.integer.folder_max_count_x);
145 mMaxCountY = mMaxVisibleY = res.getInteger(R.integer.folder_max_count_y);
Adam Cohen78dc83e2011-11-15 17:10:00 -0800146 mMaxNumItems = res.getInteger(R.integer.folder_max_num_items);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700147
148 if (mMaxCountY == -1) {
149 // -2 indicates unlimited
150 mMaxCountY = Integer.MAX_VALUE;
151 mMaxVisibleX = LauncherModel.getCellCountX() + 1;
152 }
153 if (mMaxNumItems == -1) {
154 // -2 indicates unlimited
155 mMaxNumItems = Integer.MAX_VALUE;
156 mMaxVisibleY = LauncherModel.getCellCountY() + 1;
157 }
158 if (mMaxCountX == 0) {
159 mMaxCountX = mMaxVisibleX = LauncherModel.getCellCountX();
160 mMaxVisibleX++;
161 }
162 if (mMaxCountY == 0) {
163 mMaxCountY = mMaxVisibleY = LauncherModel.getCellCountY();
164 mMaxVisibleY++;
165 }
166 if (mMaxNumItems == 0) {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800167 mMaxNumItems = mMaxCountX * mMaxCountY;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700168 if (mMaxNumItems < 0) {
169 mMaxNumItems = Integer.MAX_VALUE;
170 }
Adam Cohen78dc83e2011-11-15 17:10:00 -0800171 }
Adam Cohen76fc0852011-06-17 13:26:23 -0700172
173 mInputMethodManager = (InputMethodManager)
Michael Jurka8b805b12012-04-18 14:23:14 -0700174 getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Adam Cohen76fc0852011-06-17 13:26:23 -0700175
Adam Cohen76fc0852011-06-17 13:26:23 -0700176 mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700177
178 if (sDefaultFolderName == null) {
179 sDefaultFolderName = res.getString(R.string.folder_name);
180 }
Adam Cohena65beee2011-06-27 21:32:23 -0700181 if (sHintText == null) {
182 sHintText = res.getString(R.string.folder_hint_text);
183 }
Adam Cohen4eac29a2011-07-11 17:53:37 -0700184 mLauncher = (Launcher) context;
Adam Cohenac56cff2011-09-28 20:45:37 -0700185 // We need this view to be focusable in touch mode so that when text editing of the folder
186 // name is complete, we have something to focus on, thus hiding the cursor and giving
187 // reliable behvior when clicking the text field (since it will always gain focus on click).
188 setFocusableInTouchMode(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800189 }
190
191 @Override
192 protected void onFinishInflate() {
193 super.onFinishInflate();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700194 mScrollView = (ScrollView) findViewById(R.id.scroll_view);
Adam Cohendf2cc412011-04-27 16:56:57 -0700195 mContent = (CellLayout) findViewById(R.id.folder_content);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700196
197 // Beyond this height, the area scrolls
198 mContent.setGridSize(mMaxVisibleX, mMaxVisibleY);
199 mMaxContentAreaHeight = mContent.getDesiredHeight() - SCROLL_CUT_OFF_AMOUNT;
200
Adam Cohen2801caf2011-05-13 20:57:39 -0700201 mContent.setGridSize(0, 0);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700202 mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
Adam Cohen2374abf2013-04-16 14:56:57 -0700203 mContent.setInvertIfRtl(true);
Adam Cohenac56cff2011-09-28 20:45:37 -0700204 mFolderName = (FolderEditText) findViewById(R.id.folder_name);
205 mFolderName.setFolder(this);
Adam Cohenea0818d2011-09-30 20:06:58 -0700206 mFolderName.setOnFocusChangeListener(this);
Adam Cohen76fc0852011-06-17 13:26:23 -0700207
208 // We find out how tall the text view wants to be (it is set to wrap_content), so that
209 // we can allocate the appropriate amount of space for it.
210 int measureSpec = MeasureSpec.UNSPECIFIED;
211 mFolderName.measure(measureSpec, measureSpec);
212 mFolderNameHeight = mFolderName.getMeasuredHeight();
213
214 // We disable action mode for now since it messes up the view on phones
215 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
Adam Cohen76fc0852011-06-17 13:26:23 -0700216 mFolderName.setOnEditorActionListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700217 mFolderName.setSelectAllOnFocus(true);
Adam Cohen7a14d0b2011-06-24 11:36:35 -0700218 mFolderName.setInputType(mFolderName.getInputType() |
219 InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700220 mAutoScroller = new AutoScroller(mScrollView);
221 mAutoScroller.setMaximumVelocityAbsolute(MAX_SCROLL_VELOCITY, MAX_SCROLL_VELOCITY);
222 mAutoScroller.setExtendsBeyondEdges(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700224
Adam Cohen76fc0852011-06-17 13:26:23 -0700225 private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
226 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
227 return false;
228 }
229
230 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
231 return false;
232 }
233
234 public void onDestroyActionMode(ActionMode mode) {
235 }
236
237 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
238 return false;
239 }
240 };
241
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242 public void onClick(View v) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700243 Object tag = v.getTag();
244 if (tag instanceof ShortcutInfo) {
Adam Cohenb5fe60c2013-06-06 22:03:51 -0700245 mLauncher.onClick(v);
Adam Cohendf2cc412011-04-27 16:56:57 -0700246 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800247 }
248
249 public boolean onLongClick(View v) {
Winson Chung36a62fe2012-05-06 18:04:42 -0700250 // Return if global dragging is not enabled
251 if (!mLauncher.isDraggingEnabled()) return true;
252
Adam Cohendf2cc412011-04-27 16:56:57 -0700253 Object tag = v.getTag();
254 if (tag instanceof ShortcutInfo) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700255 ShortcutInfo item = (ShortcutInfo) tag;
256 if (!v.isInTouchMode()) {
257 return false;
258 }
259
Winson Chung7d7541e2011-09-16 20:14:36 -0700260 mLauncher.dismissFolderCling(null);
261
Adam Cohendf2cc412011-04-27 16:56:57 -0700262 mLauncher.getWorkspace().onDragStartedWithItem(v);
Adam Cohenac8c8762011-07-13 11:15:27 -0700263 mLauncher.getWorkspace().beginDragShared(v, this);
Adam Cohenbadf71e2011-05-26 19:08:29 -0700264 mIconDrawable = ((TextView) v).getCompoundDrawables()[1];
Adam Cohen76078c42011-06-09 15:06:52 -0700265
266 mCurrentDragInfo = item;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700267 mEmptyCell[0] = item.cellX;
268 mEmptyCell[1] = item.cellY;
269 mCurrentDragView = v;
Adam Cohenfc53cd22011-07-20 15:45:11 -0700270
271 mContent.removeView(mCurrentDragView);
272 mInfo.remove(mCurrentDragInfo);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700273 mDragInProgress = true;
Adam Cohen05e0f402011-08-01 12:12:49 -0700274 mItemAddedBackToSelfViaIcon = false;
Adam Cohendf2cc412011-04-27 16:56:57 -0700275 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800276 return true;
277 }
278
Adam Cohen76fc0852011-06-17 13:26:23 -0700279 public boolean isEditingName() {
280 return mIsEditingName;
281 }
282
283 public void startEditingFolderName() {
Adam Cohena65beee2011-06-27 21:32:23 -0700284 mFolderName.setHint("");
Adam Cohen76fc0852011-06-17 13:26:23 -0700285 mIsEditingName = true;
286 }
287
288 public void dismissEditingName() {
289 mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
290 doneEditingFolderName(true);
291 }
292
293 public void doneEditingFolderName(boolean commit) {
Adam Cohena65beee2011-06-27 21:32:23 -0700294 mFolderName.setHint(sHintText);
Adam Cohen1df26a32011-08-12 16:15:23 -0700295 // Convert to a string here to ensure that no other state associated with the text field
296 // gets saved.
Adam Cohen3371da02011-10-25 21:38:29 -0700297 String newTitle = mFolderName.getText().toString();
298 mInfo.setTitle(newTitle);
Adam Cohen76fc0852011-06-17 13:26:23 -0700299 LauncherModel.updateItemInDatabase(mLauncher, mInfo);
Adam Cohenac56cff2011-09-28 20:45:37 -0700300
Adam Cohen3371da02011-10-25 21:38:29 -0700301 if (commit) {
302 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700303 String.format(getContext().getString(R.string.folder_renamed), newTitle));
Adam Cohen3371da02011-10-25 21:38:29 -0700304 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700305 // In order to clear the focus from the text field, we set the focus on ourself. This
306 // ensures that every time the field is clicked, focus is gained, giving reliable behavior.
307 requestFocus();
308
Adam Cohene601a432011-07-26 21:51:30 -0700309 Selection.setSelection((Spannable) mFolderName.getText(), 0, 0);
Adam Cohen76fc0852011-06-17 13:26:23 -0700310 mIsEditingName = false;
311 }
312
313 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
314 if (actionId == EditorInfo.IME_ACTION_DONE) {
315 dismissEditingName();
316 return true;
317 }
318 return false;
319 }
320
321 public View getEditTextRegion() {
322 return mFolderName;
323 }
324
Adam Cohenbadf71e2011-05-26 19:08:29 -0700325 public Drawable getDragDrawable() {
326 return mIconDrawable;
327 }
328
Adam Cohen0c872ba2011-05-05 10:34:16 -0700329 /**
330 * We need to handle touch events to prevent them from falling through to the workspace below.
331 */
332 @Override
333 public boolean onTouchEvent(MotionEvent ev) {
334 return true;
335 }
336
Joe Onorato00acb122009-08-04 16:04:30 -0400337 public void setDragController(DragController dragController) {
338 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800339 }
340
Adam Cohen2801caf2011-05-13 20:57:39 -0700341 void setFolderIcon(FolderIcon icon) {
342 mFolderIcon = icon;
343 }
344
Adam Cohen3371da02011-10-25 21:38:29 -0700345 @Override
346 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
347 // When the folder gets focus, we don't want to announce the list of items.
348 return true;
349 }
350
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351 /**
352 * @return the FolderInfo object associated with this folder
353 */
354 FolderInfo getInfo() {
355 return mInfo;
356 }
357
Adam Cohen3bf84d32012-05-07 20:17:14 -0700358 private class GridComparator implements Comparator<ShortcutInfo> {
359 int mNumCols;
360 public GridComparator(int numCols) {
361 mNumCols = numCols;
362 }
363
364 @Override
365 public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
366 int lhIndex = lhs.cellY * mNumCols + lhs.cellX;
367 int rhIndex = rhs.cellY * mNumCols + rhs.cellX;
368 return (lhIndex - rhIndex);
369 }
Adam Cohen3bf84d32012-05-07 20:17:14 -0700370 }
371
372 private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
373 int maxX = 0;
374 int count = items.size();
375 for (int i = 0; i < count; i++) {
376 ShortcutInfo item = items.get(i);
377 if (item.cellX > maxX) {
378 maxX = item.cellX;
379 }
380 }
Adam Cohen691a5792012-05-11 14:27:30 -0700381
382 GridComparator gridComparator = new GridComparator(maxX + 1);
Adam Cohen3bf84d32012-05-07 20:17:14 -0700383 Collections.sort(items, gridComparator);
384 final int countX = mContent.getCountX();
385 for (int i = 0; i < count; i++) {
386 int x = i % countX;
387 int y = i / countX;
388 ShortcutInfo item = items.get(i);
389 item.cellX = x;
390 item.cellY = y;
391 }
392 }
393
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800394 void bind(FolderInfo info) {
395 mInfo = info;
Adam Cohendf2cc412011-04-27 16:56:57 -0700396 ArrayList<ShortcutInfo> children = info.contents;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700397 ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
Adam Cohen7c693212011-05-18 15:26:57 -0700398 setupContentForNumItems(children.size());
Adam Cohen3bf84d32012-05-07 20:17:14 -0700399 placeInReadingOrder(children);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700400 int count = 0;
Adam Cohendf2cc412011-04-27 16:56:57 -0700401 for (int i = 0; i < children.size(); i++) {
402 ShortcutInfo child = (ShortcutInfo) children.get(i);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700403 if (!createAndAddShortcut(child)) {
404 overflow.add(child);
Adam Cohen0057bbc2011-08-12 18:30:51 -0700405 } else {
406 count++;
Adam Cohenc508b2d2011-06-28 14:41:44 -0700407 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700408 }
Adam Cohenc508b2d2011-06-28 14:41:44 -0700409
Adam Cohen0057bbc2011-08-12 18:30:51 -0700410 // We rearrange the items in case there are any empty gaps
411 setupContentForNumItems(count);
412
Adam Cohenc508b2d2011-06-28 14:41:44 -0700413 // If our folder has too many items we prune them from the list. This is an issue
414 // when upgrading from the old Folders implementation which could contain an unlimited
415 // number of items.
416 for (ShortcutInfo item: overflow) {
417 mInfo.remove(item);
418 LauncherModel.deleteItemFromDatabase(mLauncher, item);
419 }
420
Adam Cohen4dbe6d92011-05-18 17:14:15 -0700421 mItemsInvalidated = true;
Adam Cohenac56cff2011-09-28 20:45:37 -0700422 updateTextViewFocus();
Adam Cohena9cf38f2011-05-02 15:36:58 -0700423 mInfo.addListener(this);
Adam Cohen4ef610f2011-06-21 22:37:36 -0700424
Adam Cohenafb01ee2011-06-23 15:38:03 -0700425 if (!sDefaultFolderName.contentEquals(mInfo.title)) {
Adam Cohen4ef610f2011-06-21 22:37:36 -0700426 mFolderName.setText(mInfo.title);
427 } else {
428 mFolderName.setText("");
429 }
Adam Cohen691a5792012-05-11 14:27:30 -0700430 updateItemLocationsInDatabase();
Adam Cohendf2cc412011-04-27 16:56:57 -0700431 }
432
433 /**
434 * Creates a new UserFolder, inflated from R.layout.user_folder.
435 *
436 * @param context The application's context.
437 *
438 * @return A new UserFolder.
439 */
440 static Folder fromXml(Context context) {
441 return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
442 }
443
444 /**
445 * This method is intended to make the UserFolder to be visually identical in size and position
446 * to its associated FolderIcon. This allows for a seamless transition into the expanded state.
447 */
448 private void positionAndSizeAsIcon() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700449 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800450 setScaleX(0.8f);
451 setScaleY(0.8f);
452 setAlpha(0f);
Adam Cohendf2cc412011-04-27 16:56:57 -0700453 mState = STATE_SMALL;
454 }
455
456 public void animateOpen() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700457 positionAndSizeAsIcon();
458
Adam Cohen8e776a62011-06-28 18:10:06 -0700459 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen2801caf2011-05-13 20:57:39 -0700460 centerAboutIcon();
Adam Cohen662b5982011-12-13 17:45:21 -0800461 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
462 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
463 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200464 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700465 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohen6441de02011-12-14 14:25:32 -0800466
Adam Cohen2801caf2011-05-13 20:57:39 -0700467 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700468 @Override
469 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700470 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700471 String.format(getContext().getString(R.string.folder_opened),
Adam Cohen3371da02011-10-25 21:38:29 -0700472 mContent.getCountX(), mContent.getCountY()));
Adam Cohendf2cc412011-04-27 16:56:57 -0700473 mState = STATE_ANIMATING;
474 }
475 @Override
476 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700477 mState = STATE_OPEN;
Michael Jurka0121c3e2012-05-31 08:36:04 -0700478 setLayerType(LAYER_TYPE_NONE, null);
Winson Chung7a74ac92011-09-20 17:43:51 -0700479 Cling cling = mLauncher.showFirstRunFoldersCling();
480 if (cling != null) {
481 cling.bringToFront();
482 }
Adam Cohenac56cff2011-09-28 20:45:37 -0700483 setFocusOnFirstChild();
Adam Cohendf2cc412011-04-27 16:56:57 -0700484 }
485 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700486 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700487 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100488 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700489 }
490
Adam Cohen3371da02011-10-25 21:38:29 -0700491 private void sendCustomAccessibilityEvent(int type, String text) {
Michael Jurka8b805b12012-04-18 14:23:14 -0700492 AccessibilityManager accessibilityManager = (AccessibilityManager)
493 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
494 if (accessibilityManager.isEnabled()) {
Adam Cohen3371da02011-10-25 21:38:29 -0700495 AccessibilityEvent event = AccessibilityEvent.obtain(type);
496 onInitializeAccessibilityEvent(event);
497 event.getText().add(text);
Michael Jurka8b805b12012-04-18 14:23:14 -0700498 accessibilityManager.sendAccessibilityEvent(event);
Adam Cohen3371da02011-10-25 21:38:29 -0700499 }
500 }
501
Adam Cohenac56cff2011-09-28 20:45:37 -0700502 private void setFocusOnFirstChild() {
503 View firstChild = mContent.getChildAt(0, 0);
504 if (firstChild != null) {
505 firstChild.requestFocus();
506 }
507 }
508
Adam Cohendf2cc412011-04-27 16:56:57 -0700509 public void animateClosed() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700510 if (!(getParent() instanceof DragLayer)) return;
Adam Cohen662b5982011-12-13 17:45:21 -0800511 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
512 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
513 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
Michael Jurka032e6ba2013-04-22 15:08:42 +0200514 final ObjectAnimator oa =
Michael Jurka2ecf9952012-06-18 12:52:28 -0700515 LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
Adam Cohendf2cc412011-04-27 16:56:57 -0700516
Adam Cohen2801caf2011-05-13 20:57:39 -0700517 oa.addListener(new AnimatorListenerAdapter() {
Adam Cohendf2cc412011-04-27 16:56:57 -0700518 @Override
519 public void onAnimationEnd(Animator animation) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700520 onCloseComplete();
Michael Jurka0121c3e2012-05-31 08:36:04 -0700521 setLayerType(LAYER_TYPE_NONE, null);
Adam Cohen2801caf2011-05-13 20:57:39 -0700522 mState = STATE_SMALL;
Adam Cohendf2cc412011-04-27 16:56:57 -0700523 }
524 @Override
525 public void onAnimationStart(Animator animation) {
Adam Cohen3371da02011-10-25 21:38:29 -0700526 sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
Michael Jurka8b805b12012-04-18 14:23:14 -0700527 getContext().getString(R.string.folder_closed));
Adam Cohendf2cc412011-04-27 16:56:57 -0700528 mState = STATE_ANIMATING;
529 }
530 });
Adam Cohen2801caf2011-05-13 20:57:39 -0700531 oa.setDuration(mExpandDuration);
Michael Jurka0121c3e2012-05-31 08:36:04 -0700532 setLayerType(LAYER_TYPE_HARDWARE, null);
Michael Jurkaf1ad6082013-03-13 12:55:46 +0100533 oa.start();
Adam Cohendf2cc412011-04-27 16:56:57 -0700534 }
535
536 void notifyDataSetChanged() {
537 // recreate all the children if the data set changes under us. We may want to do this more
538 // intelligently (ie just removing the views that should no longer exist)
539 mContent.removeAllViewsInLayout();
540 bind(mInfo);
541 }
542
Adam Cohencb3382b2011-05-24 14:07:08 -0700543 public boolean acceptDrop(DragObject d) {
544 final ItemInfo item = (ItemInfo) d.dragInfo;
Adam Cohendf2cc412011-04-27 16:56:57 -0700545 final int itemType = item.itemType;
Adam Cohen2801caf2011-05-13 20:57:39 -0700546 return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
547 itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) &&
548 !isFull());
Adam Cohendf2cc412011-04-27 16:56:57 -0700549 }
550
Adam Cohendf2cc412011-04-27 16:56:57 -0700551 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
552 int[] emptyCell = new int[2];
553 if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
554 item.cellX = emptyCell[0];
555 item.cellY = emptyCell[1];
Adam Cohendf2cc412011-04-27 16:56:57 -0700556 return true;
557 } else {
558 return false;
559 }
560 }
561
Adam Cohenc508b2d2011-06-28 14:41:44 -0700562 protected boolean createAndAddShortcut(ShortcutInfo item) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700563 final TextView textView =
Adam Cohene87b9242011-06-29 14:01:26 -0700564 (TextView) mInflater.inflate(R.layout.application, this, false);
Adam Cohendf2cc412011-04-27 16:56:57 -0700565 textView.setCompoundDrawablesWithIntrinsicBounds(null,
566 new FastBitmapDrawable(item.getIcon(mIconCache)), null, null);
567 textView.setText(item.title);
568 textView.setTag(item);
569
570 textView.setOnClickListener(this);
571 textView.setOnLongClickListener(this);
572
Adam Cohenc508b2d2011-06-28 14:41:44 -0700573 // We need to check here to verify that the given item's location isn't already occupied
Adam Cohen3bf84d32012-05-07 20:17:14 -0700574 // by another item.
Adam Cohen0057bbc2011-08-12 18:30:51 -0700575 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0
576 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) {
Adam Cohen3bf84d32012-05-07 20:17:14 -0700577 // This shouldn't happen, log it.
578 Log.e(TAG, "Folder order not properly persisted during bind");
Adam Cohenc508b2d2011-06-28 14:41:44 -0700579 if (!findAndSetEmptyCells(item)) {
580 return false;
581 }
582 }
583
Adam Cohendf2cc412011-04-27 16:56:57 -0700584 CellLayout.LayoutParams lp =
585 new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
586 boolean insert = false;
Adam Cohenac56cff2011-09-28 20:45:37 -0700587 textView.setOnKeyListener(new FolderKeyEventListener());
Adam Cohendf2cc412011-04-27 16:56:57 -0700588 mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true);
Adam Cohenc508b2d2011-06-28 14:41:44 -0700589 return true;
Adam Cohendf2cc412011-04-27 16:56:57 -0700590 }
591
Adam Cohencb3382b2011-05-24 14:07:08 -0700592 public void onDragEnter(DragObject d) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700593 mPreviousTargetCell[0] = -1;
594 mPreviousTargetCell[1] = -1;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700595 mOnExitAlarm.cancelAlarm();
596 }
597
598 OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
599 public void onAlarm(Alarm alarm) {
600 realTimeReorder(mEmptyCell, mTargetCell);
601 }
602 };
603
604 boolean readingOrderGreaterThan(int[] v1, int[] v2) {
605 if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) {
606 return true;
607 } else {
608 return false;
609 }
610 }
611
612 private void realTimeReorder(int[] empty, int[] target) {
613 boolean wrap;
614 int startX;
615 int endX;
616 int startY;
Adam Cohen76fc0852011-06-17 13:26:23 -0700617 int delay = 0;
618 float delayAmount = 30;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700619 if (readingOrderGreaterThan(target, empty)) {
620 wrap = empty[0] >= mContent.getCountX() - 1;
621 startY = wrap ? empty[1] + 1 : empty[1];
622 for (int y = startY; y <= target[1]; y++) {
623 startX = y == empty[1] ? empty[0] + 1 : 0;
624 endX = y < target[1] ? mContent.getCountX() - 1 : target[0];
625 for (int x = startX; x <= endX; x++) {
626 View v = mContent.getChildAt(x,y);
627 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800628 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700629 empty[0] = x;
630 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700631 delay += delayAmount;
632 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700633 }
634 }
635 }
636 } else {
637 wrap = empty[0] == 0;
638 startY = wrap ? empty[1] - 1 : empty[1];
639 for (int y = startY; y >= target[1]; y--) {
640 startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1;
641 endX = y > target[1] ? 0 : target[0];
642 for (int x = startX; x >= endX; x--) {
643 View v = mContent.getChildAt(x,y);
644 if (mContent.animateChildToPosition(v, empty[0], empty[1],
Adam Cohen482ed822012-03-02 14:15:13 -0800645 REORDER_ANIMATION_DURATION, delay, true, true)) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700646 empty[0] = x;
647 empty[1] = y;
Adam Cohen76fc0852011-06-17 13:26:23 -0700648 delay += delayAmount;
649 delayAmount *= 0.9;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700650 }
651 }
652 }
653 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700654 }
655
Adam Cohen2374abf2013-04-16 14:56:57 -0700656 public boolean isLayoutRtl() {
657 return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
658 }
659
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700660 private Rect getDragObjectDrawingRect(View dragView, float[] r) {
661 final Rect drawingRect = mTempRect;
662 drawingRect.left = (int) r[0];
663 drawingRect.top = (int) r[1];
664 drawingRect.right = drawingRect.left + dragView.getMeasuredWidth();
665 drawingRect.bottom = drawingRect.top + dragView.getMeasuredHeight();
666 return drawingRect;
667 }
668
Adam Cohencb3382b2011-05-24 14:07:08 -0700669 public void onDragOver(DragObject d) {
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700670 int scrollOffset = mScrollView.getScrollY();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700671 float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700672 r[0] -= getPaddingLeft();
673 r[1] -= getPaddingTop();
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700674 if (!mAutoScroller.onTouch(this, getDragObjectDrawingRect(d.dragView, r))) {
675 mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1,
676 mTargetCell);
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700677
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700678 if (isLayoutRtl()) {
679 mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700680 }
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700681 if (mTargetCell[0] != mPreviousTargetCell[0]
682 || mTargetCell[1] != mPreviousTargetCell[1]) {
683 mReorderAlarm.cancelAlarm();
684 mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
685 mReorderAlarm.setAlarm(REORDER_DELAY);
686 mPreviousTargetCell[0] = mTargetCell[0];
687 mPreviousTargetCell[1] = mTargetCell[1];
688 mDragMode = DRAG_MODE_REORDER;
689 } else {
690 mDragMode = DRAG_MODE_NONE;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700691 }
Adam Cohenbfbfd262011-06-13 16:55:12 -0700692 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700693 }
694
Adam Cohenbfbfd262011-06-13 16:55:12 -0700695 // This is used to compute the visual center of the dragView. The idea is that
696 // the visual center represents the user's interpretation of where the item is, and hence
697 // is the appropriate point to use when determining drop location.
698 private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
699 DragView dragView, float[] recycle) {
700 float res[];
701 if (recycle == null) {
702 res = new float[2];
703 } else {
704 res = recycle;
705 }
706
707 // These represent the visual top and left of drag view if a dragRect was provided.
708 // If a dragRect was not provided, then they correspond to the actual view left and
709 // top, as the dragRect is in that case taken to be the entire dragView.
710 // R.dimen.dragViewOffsetY.
711 int left = x - xOffset;
712 int top = y - yOffset;
713
714 // In order to find the visual center, we shift by half the dragRect
715 res[0] = left + dragView.getDragRegion().width() / 2;
716 res[1] = top + dragView.getDragRegion().height() / 2;
717
718 return res;
719 }
720
721 OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
722 public void onAlarm(Alarm alarm) {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700723 completeDragExit();
Adam Cohenbfbfd262011-06-13 16:55:12 -0700724 }
725 };
726
Adam Cohen95bb8002011-07-03 23:40:28 -0700727 public void completeDragExit() {
Adam Cohen3e8f8112011-07-02 18:03:00 -0700728 mLauncher.closeFolder();
729 mCurrentDragInfo = null;
730 mCurrentDragView = null;
731 mSuppressOnAdd = false;
732 mRearrangeOnClose = true;
733 }
734
Adam Cohencb3382b2011-05-24 14:07:08 -0700735 public void onDragExit(DragObject d) {
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700736 // Exiting folder; stop the auto scroller.
737 mAutoScroller.stop();
738 // We only close the folder if this is a true drag exit, ie. not because
739 // a drop has occurred above the folder.
Adam Cohenbfbfd262011-06-13 16:55:12 -0700740 if (!d.dragComplete) {
741 mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener);
742 mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
743 }
744 mReorderAlarm.cancelAlarm();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700745 mDragMode = DRAG_MODE_NONE;
Adam Cohen2801caf2011-05-13 20:57:39 -0700746 }
747
Winson Chunga48487a2012-03-20 16:19:37 -0700748 public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete,
749 boolean success) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700750 if (success) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700751 if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700752 replaceFolderWithFinalItem();
753 }
754 } else {
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700755 setupContentForNumItems(getItemCount());
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700756 // The drag failed, we need to return the item to the folder
757 mFolderIcon.onDrop(d);
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700758 }
759
760 if (target != this) {
761 if (mOnExitAlarm.alarmPending()) {
762 mOnExitAlarm.cancelAlarm();
Adam Cohen7a8b82b2013-05-29 18:41:50 -0700763 if (!success) {
764 mSuppressFolderDeletion = true;
765 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700766 completeDragExit();
767 }
768 }
769 mDeleteFolderOnDropCompleted = false;
770 mDragInProgress = false;
Adam Cohen05e0f402011-08-01 12:12:49 -0700771 mItemAddedBackToSelfViaIcon = false;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700772 mCurrentDragInfo = null;
773 mCurrentDragView = null;
774 mSuppressOnAdd = false;
Adam Cohen4045eb72011-10-06 11:44:26 -0700775
776 // Reordering may have occured, and we need to save the new item locations. We do this once
777 // at the end to prevent unnecessary database operations.
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700778 updateItemLocationsInDatabaseBatch();
Adam Cohen4045eb72011-10-06 11:44:26 -0700779 }
780
Winson Chunga48487a2012-03-20 16:19:37 -0700781 @Override
Winson Chung043f2af2012-03-01 16:09:54 -0800782 public boolean supportsFlingToDelete() {
783 return true;
784 }
785
Winson Chunga48487a2012-03-20 16:19:37 -0700786 public void onFlingToDelete(DragObject d, int x, int y, PointF vec) {
787 // Do nothing
788 }
789
790 @Override
791 public void onFlingToDeleteCompleted() {
792 // Do nothing
793 }
794
Adam Cohen4045eb72011-10-06 11:44:26 -0700795 private void updateItemLocationsInDatabase() {
796 ArrayList<View> list = getItemsInReadingOrder();
797 for (int i = 0; i < list.size(); i++) {
798 View v = list.get(i);
799 ItemInfo info = (ItemInfo) v.getTag();
800 LauncherModel.moveItemInDatabase(mLauncher, info, mInfo.id, 0,
801 info.cellX, info.cellY);
802 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700803 }
Adam Cohen228da5a2011-07-27 22:23:47 -0700804
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700805 private void updateItemLocationsInDatabaseBatch() {
806 ArrayList<View> list = getItemsInReadingOrder();
807 ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
808 for (int i = 0; i < list.size(); i++) {
809 View v = list.get(i);
810 ItemInfo info = (ItemInfo) v.getTag();
811 items.add(info);
812 }
813
814 LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0);
815 }
816
Adam Cohene25af792013-06-06 23:08:25 -0700817 public void addItemLocationsInDatabase() {
818 ArrayList<View> list = getItemsInReadingOrder();
819 for (int i = 0; i < list.size(); i++) {
820 View v = list.get(i);
821 ItemInfo info = (ItemInfo) v.getTag();
822 LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
823 info.cellX, info.cellY, false);
824 }
825 }
826
Adam Cohen67bd9cc2011-07-29 14:07:04 -0700827 public void notifyDrop() {
828 if (mDragInProgress) {
Adam Cohen05e0f402011-08-01 12:12:49 -0700829 mItemAddedBackToSelfViaIcon = true;
Adam Cohen76078c42011-06-09 15:06:52 -0700830 }
Adam Cohendf2cc412011-04-27 16:56:57 -0700831 }
832
833 public boolean isDropEnabled() {
834 return true;
835 }
836
Adam Cohencb3382b2011-05-24 14:07:08 -0700837 public DropTarget getDropTargetDelegate(DragObject d) {
Adam Cohendf2cc412011-04-27 16:56:57 -0700838 return null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839 }
Adam Cohena9cf38f2011-05-02 15:36:58 -0700840
Adam Cohen4045eb72011-10-06 11:44:26 -0700841 private void setupContentDimensions(int count) {
Adam Cohen2801caf2011-05-13 20:57:39 -0700842 ArrayList<View> list = getItemsInReadingOrder();
843
844 int countX = mContent.getCountX();
845 int countY = mContent.getCountY();
Adam Cohen7c693212011-05-18 15:26:57 -0700846 boolean done = false;
Adam Cohen2801caf2011-05-13 20:57:39 -0700847
Adam Cohen7c693212011-05-18 15:26:57 -0700848 while (!done) {
849 int oldCountX = countX;
850 int oldCountY = countY;
851 if (countX * countY < count) {
852 // Current grid is too small, expand it
Adam Cohen78dc83e2011-11-15 17:10:00 -0800853 if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) {
Adam Cohen7c693212011-05-18 15:26:57 -0700854 countX++;
855 } else if (countY < mMaxCountY) {
856 countY++;
857 }
858 if (countY == 0) countY++;
859 } else if ((countY - 1) * countX >= count && countY >= countX) {
860 countY = Math.max(0, countY - 1);
861 } else if ((countX - 1) * countY >= count) {
862 countX = Math.max(0, countX - 1);
Adam Cohen2801caf2011-05-13 20:57:39 -0700863 }
Adam Cohen7c693212011-05-18 15:26:57 -0700864 done = countX == oldCountX && countY == oldCountY;
Adam Cohen2801caf2011-05-13 20:57:39 -0700865 }
Adam Cohen7c693212011-05-18 15:26:57 -0700866 mContent.setGridSize(countX, countY);
Adam Cohen2801caf2011-05-13 20:57:39 -0700867 arrangeChildren(list);
868 }
869
870 public boolean isFull() {
Adam Cohen78dc83e2011-11-15 17:10:00 -0800871 return getItemCount() >= mMaxNumItems;
Adam Cohen2801caf2011-05-13 20:57:39 -0700872 }
873
874 private void centerAboutIcon() {
Adam Cohen8e776a62011-06-28 18:10:06 -0700875 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700876
877 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700878 int height = getFolderHeight();
Adam Cohen8e776a62011-06-28 18:10:06 -0700879 DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
Adam Cohen2801caf2011-05-13 20:57:39 -0700880
Adam Cohen307fe232012-08-16 17:55:58 -0700881 float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);
Adam Cohen8e776a62011-06-28 18:10:06 -0700882
Adam Cohen307fe232012-08-16 17:55:58 -0700883 int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2);
884 int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2);
Adam Cohen2801caf2011-05-13 20:57:39 -0700885 int centeredLeft = centerX - width / 2;
886 int centeredTop = centerY - height / 2;
887
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800888 int currentPage = mLauncher.getWorkspace().getCurrentPage();
889 // In case the workspace is scrolling, we need to use the final scroll to compute
890 // the folders bounds.
891 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage);
Adam Cohen35e7e642011-07-17 14:47:18 -0700892 // We first fetch the currently visible CellLayoutChildren
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800893 CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage);
Michael Jurkaa52570f2012-03-20 03:18:20 -0700894 ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets();
Adam Cohen35e7e642011-07-17 14:47:18 -0700895 Rect bounds = new Rect();
896 parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);
Adam Cohen7cc1bc42011-12-13 21:28:43 -0800897 // We reset the workspaces scroll
898 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage);
Adam Cohen2801caf2011-05-13 20:57:39 -0700899
Adam Cohen35e7e642011-07-17 14:47:18 -0700900 // We need to bound the folder to the currently visible CellLayoutChildren
901 int left = Math.min(Math.max(bounds.left, centeredLeft),
902 bounds.left + bounds.width() - width);
903 int top = Math.min(Math.max(bounds.top, centeredTop),
904 bounds.top + bounds.height() - height);
905 // If the folder doesn't fit within the bounds, center it about the desired bounds
906 if (width >= bounds.width()) {
907 left = bounds.left + (bounds.width() - width) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700908 }
Adam Cohen35e7e642011-07-17 14:47:18 -0700909 if (height >= bounds.height()) {
910 top = bounds.top + (bounds.height() - height) / 2;
Adam Cohen0e4857c2011-06-30 17:05:14 -0700911 }
Adam Cohen2801caf2011-05-13 20:57:39 -0700912
913 int folderPivotX = width / 2 + (centeredLeft - left);
914 int folderPivotY = height / 2 + (centeredTop - top);
915 setPivotX(folderPivotX);
916 setPivotY(folderPivotY);
Adam Cohen268c4752012-06-06 17:47:33 -0700917 mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700918 (1.0f * folderPivotX / width));
Adam Cohen268c4752012-06-06 17:47:33 -0700919 mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() *
Adam Cohen2801caf2011-05-13 20:57:39 -0700920 (1.0f * folderPivotY / height));
Adam Cohen3bf84d32012-05-07 20:17:14 -0700921
Adam Cohen662b5982011-12-13 17:45:21 -0800922 lp.width = width;
923 lp.height = height;
924 lp.x = left;
925 lp.y = top;
Adam Cohen2801caf2011-05-13 20:57:39 -0700926 }
927
Adam Cohen268c4752012-06-06 17:47:33 -0700928 float getPivotXForIconAnimation() {
929 return mFolderIconPivotX;
930 }
931 float getPivotYForIconAnimation() {
932 return mFolderIconPivotY;
933 }
934
Adam Cohen2801caf2011-05-13 20:57:39 -0700935 private void setupContentForNumItems(int count) {
Adam Cohen4045eb72011-10-06 11:44:26 -0700936 setupContentDimensions(count);
Adam Cohen2801caf2011-05-13 20:57:39 -0700937
Adam Cohen8e776a62011-06-28 18:10:06 -0700938 DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
Adam Cohen2801caf2011-05-13 20:57:39 -0700939 if (lp == null) {
Adam Cohen8e776a62011-06-28 18:10:06 -0700940 lp = new DragLayer.LayoutParams(0, 0);
941 lp.customPosition = true;
Adam Cohen2801caf2011-05-13 20:57:39 -0700942 setLayoutParams(lp);
943 }
944 centerAboutIcon();
945 }
946
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700947 private int getFolderHeight() {
948 int contentAreaHeight = mContent.getDesiredHeight();
949 if (contentAreaHeight >= mMaxContentAreaHeight) {
950 // Subtract a bit so the user can see that it's scrollable.
951 contentAreaHeight = mMaxContentAreaHeight;
952 }
953 int height = getPaddingTop() + getPaddingBottom() + contentAreaHeight
Adam Cohenf4bb1cd2011-07-22 14:36:03 -0700954 + mFolderNameHeight;
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700955 return height;
956 }
Adam Cohen234c4cd2011-07-17 21:03:04 -0700957
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700958 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Adam Cohen234c4cd2011-07-17 21:03:04 -0700959
Adam Cohenf0f4eda2013-06-06 21:27:03 -0700960 int contentAreaHeight = mContent.getDesiredHeight();
961 if (contentAreaHeight >= mMaxContentAreaHeight) {
962 // Subtract a bit so the user can see that it's scrollable.
963 contentAreaHeight = mMaxContentAreaHeight;
964 }
965
966 int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
967 int height = getFolderHeight();
968 int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(),
969 MeasureSpec.EXACTLY);
970 int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentAreaHeight,
971 MeasureSpec.EXACTLY);
972
973 mContent.setFixedSize(mContent.getDesiredWidth(), mContent.getDesiredHeight());
974 mScrollView.measure(contentAreaWidthSpec, contentAreaHeightSpec);
975 mFolderName.measure(contentAreaWidthSpec,
Adam Cohen234c4cd2011-07-17 21:03:04 -0700976 MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY));
977 setMeasuredDimension(width, height);
978 }
979
Adam Cohen2801caf2011-05-13 20:57:39 -0700980 private void arrangeChildren(ArrayList<View> list) {
981 int[] vacant = new int[2];
982 if (list == null) {
983 list = getItemsInReadingOrder();
984 }
985 mContent.removeAllViews();
986
987 for (int i = 0; i < list.size(); i++) {
988 View v = list.get(i);
989 mContent.getVacantCell(vacant, 1, 1);
990 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
991 lp.cellX = vacant[0];
992 lp.cellY = vacant[1];
993 ItemInfo info = (ItemInfo) v.getTag();
Adam Cohen2792a332011-09-26 21:09:47 -0700994 if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
995 info.cellX = vacant[0];
996 info.cellY = vacant[1];
997 LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0,
998 info.cellX, info.cellY);
999 }
Adam Cohen2801caf2011-05-13 20:57:39 -07001000 boolean insert = false;
1001 mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true);
1002 }
Adam Cohen7c693212011-05-18 15:26:57 -07001003 mItemsInvalidated = true;
Adam Cohen2801caf2011-05-13 20:57:39 -07001004 }
1005
Adam Cohena9cf38f2011-05-02 15:36:58 -07001006 public int getItemCount() {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001007 return mContent.getShortcutsAndWidgets().getChildCount();
Adam Cohena9cf38f2011-05-02 15:36:58 -07001008 }
1009
1010 public View getItemAt(int index) {
Michael Jurkaa52570f2012-03-20 03:18:20 -07001011 return mContent.getShortcutsAndWidgets().getChildAt(index);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001012 }
1013
Adam Cohen2801caf2011-05-13 20:57:39 -07001014 private void onCloseComplete() {
Adam Cohen05e0f402011-08-01 12:12:49 -07001015 DragLayer parent = (DragLayer) getParent();
Michael Jurka5649c282012-06-18 10:33:21 -07001016 if (parent != null) {
1017 parent.removeView(this);
1018 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001019 mDragController.removeDropTarget((DropTarget) this);
Adam Cohen05e0f402011-08-01 12:12:49 -07001020 clearFocus();
Adam Cohenac56cff2011-09-28 20:45:37 -07001021 mFolderIcon.requestFocus();
Adam Cohen05e0f402011-08-01 12:12:49 -07001022
Adam Cohen2801caf2011-05-13 20:57:39 -07001023 if (mRearrangeOnClose) {
1024 setupContentForNumItems(getItemCount());
1025 mRearrangeOnClose = false;
1026 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001027 if (getItemCount() <= 1) {
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001028 if (!mDragInProgress && !mSuppressFolderDeletion) {
1029 replaceFolderWithFinalItem();
1030 } else if (mDragInProgress) {
1031 mDeleteFolderOnDropCompleted = true;
1032 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001033 }
Adam Cohen67bd9cc2011-07-29 14:07:04 -07001034 mSuppressFolderDeletion = false;
Adam Cohenafb01ee2011-06-23 15:38:03 -07001035 }
1036
1037 private void replaceFolderWithFinalItem() {
Adam Cohenafb01ee2011-06-23 15:38:03 -07001038 // Add the last remaining child to the workspace in place of the folder
Adam Cohenfb91f302012-06-11 15:45:18 -07001039 Runnable onCompleteRunnable = new Runnable() {
1040 @Override
1041 public void run() {
Adam Cohendcd297f2013-06-18 13:13:40 -07001042 CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001043
Adam Cohenc5e63f32012-07-12 16:16:57 -07001044 View child = null;
Adam Cohenfb91f302012-06-11 15:45:18 -07001045 // Move the item from the folder to the workspace, in the position of the folder
1046 if (getItemCount() == 1) {
1047 ShortcutInfo finalItem = mInfo.contents.get(0);
Adam Cohenc5e63f32012-07-12 16:16:57 -07001048 child = mLauncher.createShortcut(R.layout.application, cellLayout,
Adam Cohenfb91f302012-06-11 15:45:18 -07001049 finalItem);
1050 LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container,
Adam Cohendcd297f2013-06-18 13:13:40 -07001051 mInfo.screenId, mInfo.cellX, mInfo.cellY);
Adam Cohenfb91f302012-06-11 15:45:18 -07001052 }
Adam Cohen487f7dd2012-06-28 18:12:10 -07001053 if (getItemCount() <= 1) {
1054 // Remove the folder
1055 LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
1056 cellLayout.removeView(mFolderIcon);
1057 if (mFolderIcon instanceof DropTarget) {
1058 mDragController.removeDropTarget((DropTarget) mFolderIcon);
1059 }
1060 mLauncher.removeFolder(mInfo);
1061 }
Adam Cohenc5e63f32012-07-12 16:16:57 -07001062 // We add the child after removing the folder to prevent both from existing at
1063 // the same time in the CellLayout.
1064 if (child != null) {
Adam Cohendcd297f2013-06-18 13:13:40 -07001065 mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screenId,
Adam Cohenc5e63f32012-07-12 16:16:57 -07001066 mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY);
1067 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001068 }
1069 };
1070 View finalChild = getItemAt(0);
1071 if (finalChild != null) {
1072 mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
Adam Cohenafb01ee2011-06-23 15:38:03 -07001073 }
Adam Cohenfb91f302012-06-11 15:45:18 -07001074 mDestroyed = true;
1075 }
1076
1077 boolean isDestroyed() {
1078 return mDestroyed;
Adam Cohen2801caf2011-05-13 20:57:39 -07001079 }
1080
Adam Cohenac56cff2011-09-28 20:45:37 -07001081 // This method keeps track of the last item in the folder for the purposes
1082 // of keyboard focus
1083 private void updateTextViewFocus() {
1084 View lastChild = getItemAt(getItemCount() - 1);
1085 getItemAt(getItemCount() - 1);
1086 if (lastChild != null) {
1087 mFolderName.setNextFocusDownId(lastChild.getId());
1088 mFolderName.setNextFocusRightId(lastChild.getId());
1089 mFolderName.setNextFocusLeftId(lastChild.getId());
1090 mFolderName.setNextFocusUpId(lastChild.getId());
1091 }
1092 }
1093
Adam Cohenbfbfd262011-06-13 16:55:12 -07001094 public void onDrop(DragObject d) {
1095 ShortcutInfo item;
1096 if (d.dragInfo instanceof ApplicationInfo) {
1097 // Came from all apps -- make a copy
1098 item = ((ApplicationInfo) d.dragInfo).makeShortcut();
1099 item.spanX = 1;
1100 item.spanY = 1;
1101 } else {
1102 item = (ShortcutInfo) d.dragInfo;
1103 }
Adam Cohen05e0f402011-08-01 12:12:49 -07001104 // Dragged from self onto self, currently this is the only path possible, however
1105 // we keep this as a distinct code path.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001106 if (item == mCurrentDragInfo) {
1107 ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
1108 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
1109 si.cellX = lp.cellX = mEmptyCell[0];
1110 si.cellX = lp.cellY = mEmptyCell[1];
1111 mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true);
Adam Cohenfc53cd22011-07-20 15:45:11 -07001112 if (d.dragView.hasDrawn()) {
1113 mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
1114 } else {
Winson Chung2c4cf412012-05-08 14:03:21 -07001115 d.deferDragViewCleanupPostAnimation = false;
Adam Cohenfc53cd22011-07-20 15:45:11 -07001116 mCurrentDragView.setVisibility(VISIBLE);
1117 }
Adam Cohene9166b22011-07-08 17:11:11 -07001118 mItemsInvalidated = true;
Adam Cohen4045eb72011-10-06 11:44:26 -07001119 setupContentDimensions(getItemCount());
Adam Cohen716b51e2011-06-30 12:09:54 -07001120 mSuppressOnAdd = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -07001121 }
1122 mInfo.add(item);
1123 }
1124
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001125 // This is used so the item doesn't immediately appear in the folder when added. In one case
1126 // we need to create the illusion that the item isn't added back to the folder yet, to
1127 // to correspond to the animation of the icon back into the folder. This is
1128 public void hideItem(ShortcutInfo info) {
1129 View v = getViewForInfo(info);
1130 v.setVisibility(INVISIBLE);
1131 }
1132 public void showItem(ShortcutInfo info) {
1133 View v = getViewForInfo(info);
1134 v.setVisibility(VISIBLE);
1135 }
1136
Adam Cohenbfbfd262011-06-13 16:55:12 -07001137 public void onAdd(ShortcutInfo item) {
1138 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001139 // If the item was dropped onto this open folder, we have done the work associated
1140 // with adding the item to the folder, as indicated by mSuppressOnAdd being set
Adam Cohenbfbfd262011-06-13 16:55:12 -07001141 if (mSuppressOnAdd) return;
1142 if (!findAndSetEmptyCells(item)) {
1143 // The current layout is full, can we expand it?
1144 setupContentForNumItems(getItemCount() + 1);
1145 findAndSetEmptyCells(item);
1146 }
1147 createAndAddShortcut(item);
1148 LauncherModel.addOrMoveItemInDatabase(
1149 mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
1150 }
1151
Adam Cohena9cf38f2011-05-02 15:36:58 -07001152 public void onRemove(ShortcutInfo item) {
Adam Cohen7c693212011-05-18 15:26:57 -07001153 mItemsInvalidated = true;
Adam Cohen05e0f402011-08-01 12:12:49 -07001154 // If this item is being dragged from this open folder, we have already handled
1155 // the work associated with removing the item, so we don't have to do anything here.
Adam Cohenbfbfd262011-06-13 16:55:12 -07001156 if (item == mCurrentDragInfo) return;
Adam Cohendf1e4e82011-06-24 15:57:39 -07001157 View v = getViewForInfo(item);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001158 mContent.removeView(v);
Adam Cohen2801caf2011-05-13 20:57:39 -07001159 if (mState == STATE_ANIMATING) {
1160 mRearrangeOnClose = true;
1161 } else {
1162 setupContentForNumItems(getItemCount());
1163 }
Adam Cohenafb01ee2011-06-23 15:38:03 -07001164 if (getItemCount() <= 1) {
1165 replaceFolderWithFinalItem();
1166 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001167 }
Adam Cohen7c693212011-05-18 15:26:57 -07001168
Adam Cohendf1e4e82011-06-24 15:57:39 -07001169 private View getViewForInfo(ShortcutInfo item) {
1170 for (int j = 0; j < mContent.getCountY(); j++) {
1171 for (int i = 0; i < mContent.getCountX(); i++) {
1172 View v = mContent.getChildAt(i, j);
1173 if (v.getTag() == item) {
1174 return v;
1175 }
1176 }
1177 }
1178 return null;
1179 }
1180
Adam Cohen76078c42011-06-09 15:06:52 -07001181 public void onItemsChanged() {
Adam Cohenac56cff2011-09-28 20:45:37 -07001182 updateTextViewFocus();
Adam Cohen76078c42011-06-09 15:06:52 -07001183 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001184
Adam Cohen76fc0852011-06-17 13:26:23 -07001185 public void onTitleChanged(CharSequence title) {
1186 }
Adam Cohen76078c42011-06-09 15:06:52 -07001187
Adam Cohen7c693212011-05-18 15:26:57 -07001188 public ArrayList<View> getItemsInReadingOrder() {
1189 if (mItemsInvalidated) {
1190 mItemsInReadingOrder.clear();
1191 for (int j = 0; j < mContent.getCountY(); j++) {
1192 for (int i = 0; i < mContent.getCountX(); i++) {
1193 View v = mContent.getChildAt(i, j);
1194 if (v != null) {
Adam Cohen7a8b82b2013-05-29 18:41:50 -07001195 mItemsInReadingOrder.add(v);
Adam Cohen7c693212011-05-18 15:26:57 -07001196 }
1197 }
1198 }
1199 mItemsInvalidated = false;
1200 }
1201 return mItemsInReadingOrder;
1202 }
Adam Cohen8dfcba42011-07-07 16:38:18 -07001203
1204 public void getLocationInDragLayer(int[] loc) {
1205 mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
1206 }
Adam Cohenea0818d2011-09-30 20:06:58 -07001207
1208 public void onFocusChange(View v, boolean hasFocus) {
1209 if (v == mFolderName && hasFocus) {
1210 startEditingFolderName();
1211 }
1212 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213}