The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 21 | import android.animation.ObjectAnimator; |
| 22 | import android.animation.PropertyValuesHolder; |
| 23 | import android.animation.ValueAnimator; |
| 24 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.content.Context; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 26 | import android.content.res.Resources; |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 27 | import android.graphics.Rect; |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
Adam Cohen | 7a14d0b | 2011-06-24 11:36:35 -0700 | [diff] [blame] | 29 | import android.text.InputType; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | import android.util.AttributeSet; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 31 | import android.view.ActionMode; |
| 32 | import android.view.KeyEvent; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 33 | import android.view.LayoutInflater; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 34 | import android.view.Menu; |
| 35 | import android.view.MenuItem; |
Adam Cohen | 0c872ba | 2011-05-05 10:34:16 -0700 | [diff] [blame] | 36 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 37 | import android.view.View; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 38 | import android.view.animation.AccelerateInterpolator; |
| 39 | import android.view.animation.DecelerateInterpolator; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 40 | import android.view.inputmethod.EditorInfo; |
| 41 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 42 | import android.widget.LinearLayout; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 43 | import android.widget.TextView; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 44 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 45 | import com.android.launcher.R; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 46 | import com.android.launcher2.FolderInfo.FolderListener; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 47 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 48 | import java.util.ArrayList; |
| 49 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | /** |
| 51 | * Represents a set of icons chosen by the user or generated by the system. |
| 52 | */ |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 53 | public class Folder extends LinearLayout implements DragSource, View.OnClickListener, |
| 54 | View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 55 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 56 | private static final String TAG = "Launcher.Folder"; |
| 57 | |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 58 | protected DragController mDragController; |
| 59 | protected Launcher mLauncher; |
| 60 | protected FolderInfo mInfo; |
| 61 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 62 | static final int STATE_NONE = -1; |
| 63 | static final int STATE_SMALL = 0; |
| 64 | static final int STATE_ANIMATING = 1; |
| 65 | static final int STATE_OPEN = 2; |
| 66 | |
| 67 | private int mExpandDuration; |
| 68 | protected CellLayout mContent; |
| 69 | private final LayoutInflater mInflater; |
| 70 | private final IconCache mIconCache; |
| 71 | private int mState = STATE_NONE; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 72 | private static final int FULL_GROW = 0; |
| 73 | private static final int PARTIAL_GROW = 1; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 74 | private static final int REORDER_ANIMATION_DURATION = 230; |
| 75 | private static final int ON_EXIT_CLOSE_DELAY = 800; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 76 | private int mMode = PARTIAL_GROW; |
| 77 | private boolean mRearrangeOnClose = false; |
| 78 | private FolderIcon mFolderIcon; |
| 79 | private int mMaxCountX; |
| 80 | private int mMaxCountY; |
| 81 | private Rect mNewSize = new Rect(); |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 82 | private Rect mIconRect = new Rect(); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 83 | private ArrayList<View> mItemsInReadingOrder = new ArrayList<View>(); |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 84 | private Drawable mIconDrawable; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 85 | boolean mItemsInvalidated = false; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 86 | private ShortcutInfo mCurrentDragInfo; |
| 87 | private View mCurrentDragView; |
| 88 | boolean mSuppressOnAdd = false; |
| 89 | private int[] mTargetCell = new int[2]; |
| 90 | private int[] mPreviousTargetCell = new int[2]; |
| 91 | private int[] mEmptyCell = new int[2]; |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 92 | private int[] mTempXY = new int[2]; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 93 | private Alarm mReorderAlarm = new Alarm(); |
| 94 | private Alarm mOnExitAlarm = new Alarm(); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 95 | private TextView mFolderName; |
| 96 | private int mFolderNameHeight; |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 97 | private Rect mHitRect = new Rect(); |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 98 | private Rect mTempRect = new Rect(); |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 99 | private boolean mFirstOpen = true; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 100 | |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame^] | 101 | // Internal variable to track whether the folder was destroyed due to only a single |
| 102 | // item remaining |
| 103 | private boolean mDestroyed = false; |
| 104 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 105 | private boolean mIsEditingName = false; |
| 106 | private InputMethodManager mInputMethodManager; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 107 | |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 108 | private static String sDefaultFolderName; |
| 109 | private static String sHintText; |
| 110 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 111 | /** |
| 112 | * Used to inflate the Workspace from XML. |
| 113 | * |
| 114 | * @param context The application's context. |
| 115 | * @param attrs The attribtues set containing the Workspace's customization values. |
| 116 | */ |
| 117 | public Folder(Context context, AttributeSet attrs) { |
| 118 | super(context, attrs); |
| 119 | setAlwaysDrawnWithCacheEnabled(false); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 120 | mInflater = LayoutInflater.from(context); |
| 121 | mIconCache = ((LauncherApplication)context.getApplicationContext()).getIconCache(); |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 122 | mMaxCountX = LauncherModel.getCellCountX(); |
| 123 | mMaxCountY = LauncherModel.getCellCountY(); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 124 | |
| 125 | mInputMethodManager = (InputMethodManager) |
| 126 | mContext.getSystemService(Context.INPUT_METHOD_SERVICE); |
| 127 | |
| 128 | Resources res = getResources(); |
| 129 | mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 130 | |
| 131 | if (sDefaultFolderName == null) { |
| 132 | sDefaultFolderName = res.getString(R.string.folder_name); |
| 133 | } |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 134 | if (sHintText == null) { |
| 135 | sHintText = res.getString(R.string.folder_hint_text); |
| 136 | } |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 137 | |
| 138 | mLauncher = (Launcher) context; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | @Override |
| 142 | protected void onFinishInflate() { |
| 143 | super.onFinishInflate(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 144 | mContent = (CellLayout) findViewById(R.id.folder_content); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 145 | mContent.setGridSize(0, 0); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 146 | mFolderName = (TextView) findViewById(R.id.folder_name); |
| 147 | |
| 148 | // We find out how tall the text view wants to be (it is set to wrap_content), so that |
| 149 | // we can allocate the appropriate amount of space for it. |
| 150 | int measureSpec = MeasureSpec.UNSPECIFIED; |
| 151 | mFolderName.measure(measureSpec, measureSpec); |
| 152 | mFolderNameHeight = mFolderName.getMeasuredHeight(); |
| 153 | |
| 154 | // We disable action mode for now since it messes up the view on phones |
| 155 | mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback); |
| 156 | mFolderName.setCursorVisible(false); |
| 157 | mFolderName.setOnEditorActionListener(this); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 158 | mFolderName.setSelectAllOnFocus(true); |
Adam Cohen | 7a14d0b | 2011-06-24 11:36:35 -0700 | [diff] [blame] | 159 | mFolderName.setInputType(mFolderName.getInputType() | |
| 160 | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 161 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 162 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 163 | private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { |
| 164 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | public void onDestroyActionMode(ActionMode mode) { |
| 173 | } |
| 174 | |
| 175 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 176 | return false; |
| 177 | } |
| 178 | }; |
| 179 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 180 | public void onClick(View v) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 181 | Object tag = v.getTag(); |
| 182 | if (tag instanceof ShortcutInfo) { |
| 183 | // refactor this code from Folder |
| 184 | ShortcutInfo item = (ShortcutInfo) tag; |
| 185 | int[] pos = new int[2]; |
| 186 | v.getLocationOnScreen(pos); |
| 187 | item.intent.setSourceBounds(new Rect(pos[0], pos[1], |
| 188 | pos[0] + v.getWidth(), pos[1] + v.getHeight())); |
| 189 | mLauncher.startActivitySafely(item.intent, item); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 190 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 193 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 194 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 195 | mFolderName.getHitRect(mHitRect); |
| 196 | if (mHitRect.contains((int) ev.getX(), (int) ev.getY()) && !mIsEditingName) { |
| 197 | startEditingFolderName(); |
| 198 | } |
| 199 | } |
| 200 | return false; |
| 201 | } |
| 202 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 203 | public boolean onLongClick(View v) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 204 | Object tag = v.getTag(); |
| 205 | if (tag instanceof ShortcutInfo) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 206 | ShortcutInfo item = (ShortcutInfo) tag; |
| 207 | if (!v.isInTouchMode()) { |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | mLauncher.getWorkspace().onDragStartedWithItem(v); |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 212 | mLauncher.getWorkspace().beginDragShared(v, this); |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 213 | mIconDrawable = ((TextView) v).getCompoundDrawables()[1]; |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 214 | |
| 215 | mCurrentDragInfo = item; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 216 | mEmptyCell[0] = item.cellX; |
| 217 | mEmptyCell[1] = item.cellY; |
| 218 | mCurrentDragView = v; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 219 | |
| 220 | mContent.removeView(mCurrentDragView); |
| 221 | mInfo.remove(mCurrentDragInfo); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 222 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 223 | return true; |
| 224 | } |
| 225 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 226 | public boolean isEditingName() { |
| 227 | return mIsEditingName; |
| 228 | } |
| 229 | |
| 230 | public void startEditingFolderName() { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 231 | mFolderName.setHint(""); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 232 | mFolderName.setCursorVisible(true); |
| 233 | mIsEditingName = true; |
| 234 | } |
| 235 | |
| 236 | public void dismissEditingName() { |
| 237 | mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); |
| 238 | doneEditingFolderName(true); |
| 239 | } |
| 240 | |
| 241 | public void doneEditingFolderName(boolean commit) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 242 | mFolderName.setHint(sHintText); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 243 | mInfo.setTitle(mFolderName.getText()); |
| 244 | LauncherModel.updateItemInDatabase(mLauncher, mInfo); |
| 245 | mFolderName.setCursorVisible(false); |
| 246 | mFolderName.clearFocus(); |
| 247 | mIsEditingName = false; |
| 248 | } |
| 249 | |
| 250 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
| 251 | if (actionId == EditorInfo.IME_ACTION_DONE) { |
| 252 | dismissEditingName(); |
| 253 | return true; |
| 254 | } |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | public View getEditTextRegion() { |
| 259 | return mFolderName; |
| 260 | } |
| 261 | |
Adam Cohen | badf71e | 2011-05-26 19:08:29 -0700 | [diff] [blame] | 262 | public Drawable getDragDrawable() { |
| 263 | return mIconDrawable; |
| 264 | } |
| 265 | |
Adam Cohen | 0c872ba | 2011-05-05 10:34:16 -0700 | [diff] [blame] | 266 | /** |
| 267 | * We need to handle touch events to prevent them from falling through to the workspace below. |
| 268 | */ |
| 269 | @Override |
| 270 | public boolean onTouchEvent(MotionEvent ev) { |
| 271 | return true; |
| 272 | } |
| 273 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 274 | public void setDragController(DragController dragController) { |
| 275 | mDragController = dragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 278 | void setFolderIcon(FolderIcon icon) { |
| 279 | mFolderIcon = icon; |
| 280 | } |
| 281 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 282 | /** |
| 283 | * @return the FolderInfo object associated with this folder |
| 284 | */ |
| 285 | FolderInfo getInfo() { |
| 286 | return mInfo; |
| 287 | } |
| 288 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 289 | void onOpen() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 290 | // When the folder opens, we need to refresh the GridView's selection by |
| 291 | // forcing a layout |
| 292 | // TODO: find out if this is still necessary |
| 293 | mContent.requestLayout(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void onClose() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 297 | DragLayer parent = (DragLayer) getParent(); |
| 298 | parent.removeView(Folder.this); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 299 | clearFocus(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void bind(FolderInfo info) { |
| 303 | mInfo = info; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 304 | ArrayList<ShortcutInfo> children = info.contents; |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 305 | ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>(); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 306 | setupContentForNumItems(children.size()); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 307 | for (int i = 0; i < children.size(); i++) { |
| 308 | ShortcutInfo child = (ShortcutInfo) children.get(i); |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 309 | if (!createAndAddShortcut(child)) { |
| 310 | overflow.add(child); |
| 311 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 312 | } |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 313 | |
| 314 | // If our folder has too many items we prune them from the list. This is an issue |
| 315 | // when upgrading from the old Folders implementation which could contain an unlimited |
| 316 | // number of items. |
| 317 | for (ShortcutInfo item: overflow) { |
| 318 | mInfo.remove(item); |
| 319 | LauncherModel.deleteItemFromDatabase(mLauncher, item); |
| 320 | } |
| 321 | |
Adam Cohen | 4dbe6d9 | 2011-05-18 17:14:15 -0700 | [diff] [blame] | 322 | mItemsInvalidated = true; |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 323 | mInfo.addListener(this); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 324 | |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 325 | if (!sDefaultFolderName.contentEquals(mInfo.title)) { |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 326 | mFolderName.setText(mInfo.title); |
| 327 | } else { |
| 328 | mFolderName.setText(""); |
| 329 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Creates a new UserFolder, inflated from R.layout.user_folder. |
| 334 | * |
| 335 | * @param context The application's context. |
| 336 | * |
| 337 | * @return A new UserFolder. |
| 338 | */ |
| 339 | static Folder fromXml(Context context) { |
| 340 | return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * This method is intended to make the UserFolder to be visually identical in size and position |
| 345 | * to its associated FolderIcon. This allows for a seamless transition into the expanded state. |
| 346 | */ |
| 347 | private void positionAndSizeAsIcon() { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 348 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 349 | |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 350 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 351 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 352 | if (mMode == PARTIAL_GROW) { |
| 353 | setScaleX(0.8f); |
| 354 | setScaleY(0.8f); |
| 355 | setAlpha(0f); |
| 356 | } else { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 357 | mLauncher.getDragLayer().getDescendantRectRelativeToSelf(mFolderIcon, mIconRect); |
| 358 | lp.width = mIconRect.width(); |
| 359 | lp.height = mIconRect.height(); |
| 360 | lp.x = mIconRect.left; |
| 361 | lp.y = mIconRect.top; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 362 | mContent.setAlpha(0); |
| 363 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 364 | mState = STATE_SMALL; |
| 365 | } |
| 366 | |
| 367 | public void animateOpen() { |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 368 | if (mFirstOpen) { |
| 369 | setLayerType(LAYER_TYPE_HARDWARE, null); |
| 370 | buildLayer(); |
| 371 | mFirstOpen = false; |
| 372 | } |
| 373 | |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 374 | positionAndSizeAsIcon(); |
| 375 | |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 376 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 377 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 378 | ObjectAnimator oa; |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 379 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 380 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 381 | centerAboutIcon(); |
| 382 | if (mMode == PARTIAL_GROW) { |
| 383 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1); |
| 384 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 385 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 386 | oa = ObjectAnimator.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); |
| 387 | } else { |
| 388 | PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", mNewSize.width()); |
| 389 | PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", mNewSize.height()); |
| 390 | PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", mNewSize.left); |
| 391 | PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", mNewSize.top); |
| 392 | oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y); |
| 393 | oa.addUpdateListener(new AnimatorUpdateListener() { |
| 394 | public void onAnimationUpdate(ValueAnimator animation) { |
| 395 | requestLayout(); |
| 396 | } |
| 397 | }); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 398 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 399 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); |
| 400 | ObjectAnimator alphaOa = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha); |
| 401 | alphaOa.setDuration(mExpandDuration); |
| 402 | alphaOa.setInterpolator(new AccelerateInterpolator(2.0f)); |
| 403 | alphaOa.start(); |
| 404 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 405 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 406 | oa.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 407 | @Override |
| 408 | public void onAnimationStart(Animator animation) { |
| 409 | mState = STATE_ANIMATING; |
| 410 | } |
| 411 | @Override |
| 412 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 413 | mState = STATE_OPEN; |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 414 | setLayerType(LAYER_TYPE_NONE, null); |
| 415 | enableHardwareLayersForChildren(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 416 | } |
| 417 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 418 | oa.setDuration(mExpandDuration); |
| 419 | oa.start(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 422 | void enableHardwareLayersForChildren() { |
| 423 | ArrayList<View> children = getItemsInReadingOrder(); |
| 424 | for (View child: children) { |
| 425 | child.setLayerType(LAYER_TYPE_HARDWARE, null); |
| 426 | } |
| 427 | } |
| 428 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 429 | public void animateClosed() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 430 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 431 | setLayerType(LAYER_TYPE_HARDWARE, null); |
| 432 | buildLayer(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 433 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 434 | ObjectAnimator oa; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 435 | if (mMode == PARTIAL_GROW) { |
| 436 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 437 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f); |
| 438 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f); |
| 439 | oa = ObjectAnimator.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); |
| 440 | } else { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 441 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 442 | |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 443 | PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", mIconRect.width()); |
| 444 | PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", mIconRect.height()); |
| 445 | PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", mIconRect.left); |
| 446 | PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", mIconRect.top); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 447 | oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y); |
| 448 | oa.addUpdateListener(new AnimatorUpdateListener() { |
| 449 | public void onAnimationUpdate(ValueAnimator animation) { |
| 450 | requestLayout(); |
| 451 | } |
| 452 | }); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 453 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 454 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f); |
| 455 | ObjectAnimator alphaOa = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha); |
| 456 | alphaOa.setDuration(mExpandDuration); |
| 457 | alphaOa.setInterpolator(new DecelerateInterpolator(2.0f)); |
| 458 | alphaOa.start(); |
| 459 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 460 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 461 | oa.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 462 | @Override |
| 463 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 464 | onClose(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 465 | onCloseComplete(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 466 | mState = STATE_SMALL; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 467 | } |
| 468 | @Override |
| 469 | public void onAnimationStart(Animator animation) { |
| 470 | mState = STATE_ANIMATING; |
| 471 | } |
| 472 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 473 | oa.setDuration(mExpandDuration); |
| 474 | oa.start(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | void notifyDataSetChanged() { |
| 478 | // recreate all the children if the data set changes under us. We may want to do this more |
| 479 | // intelligently (ie just removing the views that should no longer exist) |
| 480 | mContent.removeAllViewsInLayout(); |
| 481 | bind(mInfo); |
| 482 | } |
| 483 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 484 | public boolean acceptDrop(DragObject d) { |
| 485 | final ItemInfo item = (ItemInfo) d.dragInfo; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 486 | final int itemType = item.itemType; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 487 | return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 488 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && |
| 489 | !isFull()); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 492 | protected boolean findAndSetEmptyCells(ShortcutInfo item) { |
| 493 | int[] emptyCell = new int[2]; |
| 494 | if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) { |
| 495 | item.cellX = emptyCell[0]; |
| 496 | item.cellY = emptyCell[1]; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 497 | return true; |
| 498 | } else { |
| 499 | return false; |
| 500 | } |
| 501 | } |
| 502 | |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 503 | protected boolean createAndAddShortcut(ShortcutInfo item) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 504 | final TextView textView = |
Adam Cohen | e87b924 | 2011-06-29 14:01:26 -0700 | [diff] [blame] | 505 | (TextView) mInflater.inflate(R.layout.application, this, false); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 506 | textView.setCompoundDrawablesWithIntrinsicBounds(null, |
| 507 | new FastBitmapDrawable(item.getIcon(mIconCache)), null, null); |
| 508 | textView.setText(item.title); |
| 509 | textView.setTag(item); |
| 510 | |
| 511 | textView.setOnClickListener(this); |
| 512 | textView.setOnLongClickListener(this); |
| 513 | |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 514 | // We need to check here to verify that the given item's location isn't already occupied |
| 515 | // by another item. If it is, we need to find the next available slot and assign |
| 516 | // it that position. This is an issue when upgrading from the old Folders implementation |
| 517 | // which could contain an unlimited number of items. |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame^] | 518 | if (mContent.getChildAt(item.cellX, item.cellY) != null || |
| 519 | item.cellX < 0 || item.cellY < 0) { |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 520 | if (!findAndSetEmptyCells(item)) { |
| 521 | return false; |
| 522 | } |
| 523 | } |
| 524 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 525 | CellLayout.LayoutParams lp = |
| 526 | new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY); |
| 527 | boolean insert = false; |
| 528 | mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int)item.id, lp, true); |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 529 | return true; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 532 | public void onDragEnter(DragObject d) { |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 533 | mPreviousTargetCell[0] = -1; |
| 534 | mPreviousTargetCell[1] = -1; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 535 | mOnExitAlarm.cancelAlarm(); |
| 536 | } |
| 537 | |
| 538 | OnAlarmListener mReorderAlarmListener = new OnAlarmListener() { |
| 539 | public void onAlarm(Alarm alarm) { |
| 540 | realTimeReorder(mEmptyCell, mTargetCell); |
| 541 | } |
| 542 | }; |
| 543 | |
| 544 | boolean readingOrderGreaterThan(int[] v1, int[] v2) { |
| 545 | if (v1[1] > v2[1] || (v1[1] == v2[1] && v1[0] > v2[0])) { |
| 546 | return true; |
| 547 | } else { |
| 548 | return false; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | private void realTimeReorder(int[] empty, int[] target) { |
| 553 | boolean wrap; |
| 554 | int startX; |
| 555 | int endX; |
| 556 | int startY; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 557 | int delay = 0; |
| 558 | float delayAmount = 30; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 559 | if (readingOrderGreaterThan(target, empty)) { |
| 560 | wrap = empty[0] >= mContent.getCountX() - 1; |
| 561 | startY = wrap ? empty[1] + 1 : empty[1]; |
| 562 | for (int y = startY; y <= target[1]; y++) { |
| 563 | startX = y == empty[1] ? empty[0] + 1 : 0; |
| 564 | endX = y < target[1] ? mContent.getCountX() - 1 : target[0]; |
| 565 | for (int x = startX; x <= endX; x++) { |
| 566 | View v = mContent.getChildAt(x,y); |
| 567 | if (mContent.animateChildToPosition(v, empty[0], empty[1], |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 568 | REORDER_ANIMATION_DURATION, delay)) { |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 569 | empty[0] = x; |
| 570 | empty[1] = y; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 571 | delay += delayAmount; |
| 572 | delayAmount *= 0.9; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | } |
| 576 | } else { |
| 577 | wrap = empty[0] == 0; |
| 578 | startY = wrap ? empty[1] - 1 : empty[1]; |
| 579 | for (int y = startY; y >= target[1]; y--) { |
| 580 | startX = y == empty[1] ? empty[0] - 1 : mContent.getCountX() - 1; |
| 581 | endX = y > target[1] ? 0 : target[0]; |
| 582 | for (int x = startX; x >= endX; x--) { |
| 583 | View v = mContent.getChildAt(x,y); |
| 584 | if (mContent.animateChildToPosition(v, empty[0], empty[1], |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 585 | REORDER_ANIMATION_DURATION, delay)) { |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 586 | empty[0] = x; |
| 587 | empty[1] = y; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 588 | delay += delayAmount; |
| 589 | delayAmount *= 0.9; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | } |
| 593 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 596 | public void onDragOver(DragObject d) { |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 597 | float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null); |
| 598 | mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1], 1, 1, mTargetCell); |
| 599 | |
| 600 | if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { |
| 601 | mReorderAlarm.cancelAlarm(); |
| 602 | mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); |
| 603 | mReorderAlarm.setAlarm(150); |
| 604 | mPreviousTargetCell[0] = mTargetCell[0]; |
| 605 | mPreviousTargetCell[1] = mTargetCell[1]; |
| 606 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 609 | // This is used to compute the visual center of the dragView. The idea is that |
| 610 | // the visual center represents the user's interpretation of where the item is, and hence |
| 611 | // is the appropriate point to use when determining drop location. |
| 612 | private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset, |
| 613 | DragView dragView, float[] recycle) { |
| 614 | float res[]; |
| 615 | if (recycle == null) { |
| 616 | res = new float[2]; |
| 617 | } else { |
| 618 | res = recycle; |
| 619 | } |
| 620 | |
| 621 | // These represent the visual top and left of drag view if a dragRect was provided. |
| 622 | // If a dragRect was not provided, then they correspond to the actual view left and |
| 623 | // top, as the dragRect is in that case taken to be the entire dragView. |
| 624 | // R.dimen.dragViewOffsetY. |
| 625 | int left = x - xOffset; |
| 626 | int top = y - yOffset; |
| 627 | |
| 628 | // In order to find the visual center, we shift by half the dragRect |
| 629 | res[0] = left + dragView.getDragRegion().width() / 2; |
| 630 | res[1] = top + dragView.getDragRegion().height() / 2; |
| 631 | |
| 632 | return res; |
| 633 | } |
| 634 | |
| 635 | OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() { |
| 636 | public void onAlarm(Alarm alarm) { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 637 | completeDragExit(); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 638 | } |
| 639 | }; |
| 640 | |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 641 | public void completeDragExit() { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 642 | mLauncher.closeFolder(); |
| 643 | mCurrentDragInfo = null; |
| 644 | mCurrentDragView = null; |
| 645 | mSuppressOnAdd = false; |
| 646 | mRearrangeOnClose = true; |
| 647 | } |
| 648 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 649 | public void onDragExit(DragObject d) { |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 650 | // We only close the folder if this is a true drag exit, ie. not because a drop |
| 651 | // has occurred above the folder. |
| 652 | if (!d.dragComplete) { |
| 653 | mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener); |
| 654 | mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY); |
| 655 | } |
| 656 | mReorderAlarm.cancelAlarm(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 659 | public void onDropCompleted(View target, DragObject d, boolean success) { |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 660 | mCurrentDragInfo = null; |
| 661 | mCurrentDragView = null; |
| 662 | mSuppressOnAdd = false; |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame^] | 663 | if (target != this) { |
| 664 | mOnExitAlarm.cancelAlarm(); |
| 665 | completeDragExit(); |
| 666 | } |
| 667 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 668 | if (!success) { |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame^] | 669 | if (!mDestroyed) { |
| 670 | mFolderIcon.onDrop(d); |
| 671 | } else { |
| 672 | // TODO: if the folder was removed, recreate it |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 673 | } |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 674 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | public boolean isDropEnabled() { |
| 678 | return true; |
| 679 | } |
| 680 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 681 | public DropTarget getDropTargetDelegate(DragObject d) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 682 | return null; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 683 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 684 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 685 | private void setupContentDimension(int count) { |
| 686 | ArrayList<View> list = getItemsInReadingOrder(); |
| 687 | |
| 688 | int countX = mContent.getCountX(); |
| 689 | int countY = mContent.getCountY(); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 690 | boolean done = false; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 691 | |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 692 | while (!done) { |
| 693 | int oldCountX = countX; |
| 694 | int oldCountY = countY; |
| 695 | if (countX * countY < count) { |
| 696 | // Current grid is too small, expand it |
| 697 | if (countX <= countY && countX < mMaxCountX) { |
| 698 | countX++; |
| 699 | } else if (countY < mMaxCountY) { |
| 700 | countY++; |
| 701 | } |
| 702 | if (countY == 0) countY++; |
| 703 | } else if ((countY - 1) * countX >= count && countY >= countX) { |
| 704 | countY = Math.max(0, countY - 1); |
| 705 | } else if ((countX - 1) * countY >= count) { |
| 706 | countX = Math.max(0, countX - 1); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 707 | } |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 708 | done = countX == oldCountX && countY == oldCountY; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 709 | } |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 710 | mContent.setGridSize(countX, countY); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 711 | arrangeChildren(list); |
| 712 | } |
| 713 | |
| 714 | public boolean isFull() { |
| 715 | return getItemCount() >= mMaxCountX * mMaxCountY; |
| 716 | } |
| 717 | |
| 718 | private void centerAboutIcon() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 719 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 720 | |
| 721 | int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); |
Adam Cohen | f4bb1cd | 2011-07-22 14:36:03 -0700 | [diff] [blame] | 722 | int height = getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() |
| 723 | + mFolderNameHeight; |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 724 | DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 725 | |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 726 | parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); |
| 727 | |
| 728 | int centerX = mTempRect.centerX(); |
| 729 | int centerY = mTempRect.centerY(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 730 | int centeredLeft = centerX - width / 2; |
| 731 | int centeredTop = centerY - height / 2; |
| 732 | |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 733 | // We first fetch the currently visible CellLayoutChildren |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 734 | CellLayout currentPage = mLauncher.getWorkspace().getCurrentDropLayout(); |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 735 | CellLayoutChildren boundingLayout = currentPage.getChildrenLayout(); |
| 736 | Rect bounds = new Rect(); |
| 737 | parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 738 | |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 739 | // We need to bound the folder to the currently visible CellLayoutChildren |
| 740 | int left = Math.min(Math.max(bounds.left, centeredLeft), |
| 741 | bounds.left + bounds.width() - width); |
| 742 | int top = Math.min(Math.max(bounds.top, centeredTop), |
| 743 | bounds.top + bounds.height() - height); |
| 744 | // If the folder doesn't fit within the bounds, center it about the desired bounds |
| 745 | if (width >= bounds.width()) { |
| 746 | left = bounds.left + (bounds.width() - width) / 2; |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 747 | } |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 748 | if (height >= bounds.height()) { |
| 749 | top = bounds.top + (bounds.height() - height) / 2; |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 750 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 751 | |
| 752 | int folderPivotX = width / 2 + (centeredLeft - left); |
| 753 | int folderPivotY = height / 2 + (centeredTop - top); |
| 754 | setPivotX(folderPivotX); |
| 755 | setPivotY(folderPivotY); |
| 756 | int folderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * |
| 757 | (1.0f * folderPivotX / width)); |
| 758 | int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * |
| 759 | (1.0f * folderPivotY / height)); |
| 760 | mFolderIcon.setPivotX(folderIconPivotX); |
| 761 | mFolderIcon.setPivotY(folderIconPivotY); |
| 762 | |
| 763 | if (mMode == PARTIAL_GROW) { |
| 764 | lp.width = width; |
| 765 | lp.height = height; |
| 766 | lp.x = left; |
| 767 | lp.y = top; |
| 768 | } else { |
| 769 | mNewSize.set(left, top, left + width, top + height); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | private void setupContentForNumItems(int count) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 774 | setupContentDimension(count); |
| 775 | |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 776 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 777 | if (lp == null) { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 778 | lp = new DragLayer.LayoutParams(0, 0); |
| 779 | lp.customPosition = true; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 780 | setLayoutParams(lp); |
| 781 | } |
| 782 | centerAboutIcon(); |
| 783 | } |
| 784 | |
Adam Cohen | 234c4cd | 2011-07-17 21:03:04 -0700 | [diff] [blame] | 785 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 786 | int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); |
Adam Cohen | f4bb1cd | 2011-07-22 14:36:03 -0700 | [diff] [blame] | 787 | int height = getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() |
| 788 | + mFolderNameHeight; |
Adam Cohen | 234c4cd | 2011-07-17 21:03:04 -0700 | [diff] [blame] | 789 | |
| 790 | int contentWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(), |
| 791 | MeasureSpec.EXACTLY); |
| 792 | int contentHeightSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredHeight(), |
| 793 | MeasureSpec.EXACTLY); |
| 794 | mContent.measure(contentWidthSpec, contentHeightSpec); |
| 795 | |
| 796 | mFolderName.measure(contentWidthSpec, |
| 797 | MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY)); |
| 798 | setMeasuredDimension(width, height); |
| 799 | } |
| 800 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 801 | private void arrangeChildren(ArrayList<View> list) { |
| 802 | int[] vacant = new int[2]; |
| 803 | if (list == null) { |
| 804 | list = getItemsInReadingOrder(); |
| 805 | } |
| 806 | mContent.removeAllViews(); |
| 807 | |
| 808 | for (int i = 0; i < list.size(); i++) { |
| 809 | View v = list.get(i); |
| 810 | mContent.getVacantCell(vacant, 1, 1); |
| 811 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams(); |
| 812 | lp.cellX = vacant[0]; |
| 813 | lp.cellY = vacant[1]; |
| 814 | ItemInfo info = (ItemInfo) v.getTag(); |
| 815 | info.cellX = vacant[0]; |
| 816 | info.cellY = vacant[1]; |
| 817 | boolean insert = false; |
| 818 | mContent.addViewToCellLayout(v, insert ? 0 : -1, (int)info.id, lp, true); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 819 | LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0, |
| 820 | info.cellX, info.cellY); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 821 | } |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 822 | mItemsInvalidated = true; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 825 | public int getItemCount() { |
| 826 | return mContent.getChildrenLayout().getChildCount(); |
| 827 | } |
| 828 | |
| 829 | public View getItemAt(int index) { |
| 830 | return mContent.getChildrenLayout().getChildAt(index); |
| 831 | } |
| 832 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 833 | private void onCloseComplete() { |
| 834 | if (mRearrangeOnClose) { |
| 835 | setupContentForNumItems(getItemCount()); |
| 836 | mRearrangeOnClose = false; |
| 837 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 838 | if (getItemCount() <= 1) { |
| 839 | replaceFolderWithFinalItem(); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | private void replaceFolderWithFinalItem() { |
| 844 | ItemInfo finalItem = null; |
| 845 | |
Adam Cohen | 228da5a | 2011-07-27 22:23:47 -0700 | [diff] [blame^] | 846 | mDestroyed = true; |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 847 | if (getItemCount() == 1) { |
| 848 | finalItem = mInfo.contents.get(0); |
| 849 | } |
| 850 | |
| 851 | // Remove the folder completely |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 852 | CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 853 | cellLayout.removeView(mFolderIcon); |
| 854 | if (mFolderIcon instanceof DropTarget) { |
| 855 | mDragController.removeDropTarget((DropTarget) mFolderIcon); |
| 856 | } |
| 857 | mLauncher.removeFolder(mInfo); |
| 858 | |
| 859 | if (finalItem != null) { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 860 | LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container, |
| 861 | mInfo.screen, mInfo.cellX, mInfo.cellY); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 862 | } |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 863 | LauncherModel.deleteItemFromDatabase(mLauncher, mInfo); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 864 | |
| 865 | // Add the last remaining child to the workspace in place of the folder |
| 866 | if (finalItem != null) { |
| 867 | View child = mLauncher.createShortcut(R.layout.application, cellLayout, |
| 868 | (ShortcutInfo) finalItem); |
| 869 | |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 870 | mLauncher.getWorkspace().addInScreen(child, mInfo.container, mInfo.screen, mInfo.cellX, |
| 871 | mInfo.cellY, mInfo.spanX, mInfo.spanY); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 872 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 875 | public void onDrop(DragObject d) { |
| 876 | ShortcutInfo item; |
| 877 | if (d.dragInfo instanceof ApplicationInfo) { |
| 878 | // Came from all apps -- make a copy |
| 879 | item = ((ApplicationInfo) d.dragInfo).makeShortcut(); |
| 880 | item.spanX = 1; |
| 881 | item.spanY = 1; |
| 882 | } else { |
| 883 | item = (ShortcutInfo) d.dragInfo; |
| 884 | } |
| 885 | // Dragged from self onto self |
| 886 | if (item == mCurrentDragInfo) { |
| 887 | ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag(); |
| 888 | CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams(); |
| 889 | si.cellX = lp.cellX = mEmptyCell[0]; |
| 890 | si.cellX = lp.cellY = mEmptyCell[1]; |
| 891 | mContent.addViewToCellLayout(mCurrentDragView, -1, (int)item.id, lp, true); |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 892 | if (d.dragView.hasDrawn()) { |
| 893 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView); |
| 894 | } else { |
| 895 | mCurrentDragView.setVisibility(VISIBLE); |
| 896 | } |
Adam Cohen | e9166b2 | 2011-07-08 17:11:11 -0700 | [diff] [blame] | 897 | mItemsInvalidated = true; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 898 | setupContentDimension(getItemCount()); |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 899 | mSuppressOnAdd = true; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 900 | } |
| 901 | mInfo.add(item); |
| 902 | } |
| 903 | |
| 904 | public void onAdd(ShortcutInfo item) { |
| 905 | mItemsInvalidated = true; |
| 906 | if (mSuppressOnAdd) return; |
| 907 | if (!findAndSetEmptyCells(item)) { |
| 908 | // The current layout is full, can we expand it? |
| 909 | setupContentForNumItems(getItemCount() + 1); |
| 910 | findAndSetEmptyCells(item); |
| 911 | } |
| 912 | createAndAddShortcut(item); |
| 913 | LauncherModel.addOrMoveItemInDatabase( |
| 914 | mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); |
| 915 | } |
| 916 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 917 | public void onRemove(ShortcutInfo item) { |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 918 | mItemsInvalidated = true; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 919 | if (item == mCurrentDragInfo) return; |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 920 | View v = getViewForInfo(item); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 921 | mContent.removeView(v); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 922 | if (mState == STATE_ANIMATING) { |
| 923 | mRearrangeOnClose = true; |
| 924 | } else { |
| 925 | setupContentForNumItems(getItemCount()); |
| 926 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 927 | if (getItemCount() <= 1) { |
| 928 | replaceFolderWithFinalItem(); |
| 929 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 930 | } |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 931 | |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 932 | private View getViewForInfo(ShortcutInfo item) { |
| 933 | for (int j = 0; j < mContent.getCountY(); j++) { |
| 934 | for (int i = 0; i < mContent.getCountX(); i++) { |
| 935 | View v = mContent.getChildAt(i, j); |
| 936 | if (v.getTag() == item) { |
| 937 | return v; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | return null; |
| 942 | } |
| 943 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 944 | public void onItemsChanged() { |
| 945 | } |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 946 | public void onTitleChanged(CharSequence title) { |
| 947 | } |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 948 | |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 949 | public ArrayList<View> getItemsInReadingOrder() { |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 950 | return getItemsInReadingOrder(true); |
| 951 | } |
| 952 | |
| 953 | public ArrayList<View> getItemsInReadingOrder(boolean includeCurrentDragItem) { |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 954 | if (mItemsInvalidated) { |
| 955 | mItemsInReadingOrder.clear(); |
| 956 | for (int j = 0; j < mContent.getCountY(); j++) { |
| 957 | for (int i = 0; i < mContent.getCountX(); i++) { |
| 958 | View v = mContent.getChildAt(i, j); |
| 959 | if (v != null) { |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 960 | ShortcutInfo info = (ShortcutInfo) v.getTag(); |
| 961 | if (info != mCurrentDragInfo || includeCurrentDragItem) { |
| 962 | mItemsInReadingOrder.add(v); |
| 963 | } |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | } |
| 967 | mItemsInvalidated = false; |
| 968 | } |
| 969 | return mItemsInReadingOrder; |
| 970 | } |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 971 | |
| 972 | public void getLocationInDragLayer(int[] loc) { |
| 973 | mLauncher.getDragLayer().getLocationInDragLayer(this, loc); |
| 974 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 975 | } |