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