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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
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 | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 21 | import android.animation.AnimatorSet; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 22 | import android.animation.ObjectAnimator; |
| 23 | import android.animation.PropertyValuesHolder; |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 24 | import android.annotation.TargetApi; |
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; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 27 | import android.graphics.PointF; |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 28 | import android.graphics.Rect; |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 29 | import android.os.Build; |
Adam Cohen | 7a14d0b | 2011-06-24 11:36:35 -0700 | [diff] [blame] | 30 | import android.text.InputType; |
Adam Cohen | e601a43 | 2011-07-26 21:51:30 -0700 | [diff] [blame] | 31 | import android.text.Selection; |
| 32 | import android.text.Spannable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 33 | import android.util.AttributeSet; |
Adam Cohen | 3bf84d3 | 2012-05-07 20:17:14 -0700 | [diff] [blame] | 34 | import android.util.Log; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 35 | import android.view.ActionMode; |
| 36 | import android.view.KeyEvent; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 37 | import android.view.LayoutInflater; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 38 | import android.view.Menu; |
| 39 | import android.view.MenuItem; |
Adam Cohen | 0c872ba | 2011-05-05 10:34:16 -0700 | [diff] [blame] | 40 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | import android.view.View; |
Sunny Goyal | c491835 | 2015-03-10 18:15:48 -0700 | [diff] [blame^] | 42 | import android.view.ViewGroup; |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 43 | import android.view.accessibility.AccessibilityEvent; |
| 44 | import android.view.accessibility.AccessibilityManager; |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 45 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 46 | import android.view.inputmethod.EditorInfo; |
| 47 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 48 | import android.widget.LinearLayout; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 49 | import android.widget.TextView; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 50 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 51 | import com.android.launcher3.FolderInfo.FolderListener; |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 52 | import com.android.launcher3.Workspace.ItemOperator; |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 53 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 54 | import java.util.ArrayList; |
Adam Cohen | 3bf84d3 | 2012-05-07 20:17:14 -0700 | [diff] [blame] | 55 | import java.util.Collections; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 56 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 57 | /** |
| 58 | * Represents a set of icons chosen by the user or generated by the system. |
| 59 | */ |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 60 | public class Folder extends LinearLayout implements DragSource, View.OnClickListener, |
Adam Cohen | ea0818d | 2011-09-30 20:06:58 -0700 | [diff] [blame] | 61 | View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener, |
| 62 | View.OnFocusChangeListener { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 63 | private static final String TAG = "Launcher.Folder"; |
| 64 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 65 | /** |
| 66 | * We avoid measuring {@link #mContentWrapper} with a 0 width or height, as this |
| 67 | * results in CellLayout being measured as UNSPECIFIED, which it does not support. |
| 68 | */ |
| 69 | private static final int MIN_CONTENT_DIMEN = 5; |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 70 | private static final boolean ALLOW_FOLDER_SCROLL = true; |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 71 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 72 | static final int STATE_NONE = -1; |
| 73 | static final int STATE_SMALL = 0; |
| 74 | static final int STATE_ANIMATING = 1; |
| 75 | static final int STATE_OPEN = 2; |
| 76 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 77 | private static final int REORDER_DELAY = 250; |
Adam Cohen | 5d518fa | 2013-12-05 14:16:23 -0800 | [diff] [blame] | 78 | private static final int ON_EXIT_CLOSE_DELAY = 400; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 79 | private static final Rect sTempRect = new Rect(); |
| 80 | |
| 81 | private static String sDefaultFolderName; |
| 82 | private static String sHintText; |
| 83 | |
| 84 | private final Alarm mReorderAlarm = new Alarm(); |
| 85 | private final Alarm mOnExitAlarm = new Alarm(); |
| 86 | |
| 87 | private final ArrayList<View> mItemsInReadingOrder = new ArrayList<View>(); |
| 88 | |
| 89 | private final int mExpandDuration; |
| 90 | private final int mMaterialExpandDuration; |
| 91 | private final int mMaterialExpandStagger; |
| 92 | |
| 93 | private final InputMethodManager mInputMethodManager; |
| 94 | |
| 95 | protected final Launcher mLauncher; |
| 96 | protected DragController mDragController; |
| 97 | protected FolderInfo mInfo; |
| 98 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 99 | private FolderIcon mFolderIcon; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 100 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 101 | private FolderContent mContent; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 102 | private View mContentWrapper; |
| 103 | FolderEditText mFolderName; |
| 104 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 105 | private View mFooter; |
| 106 | private int mFooterHeight; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 107 | |
| 108 | // Cell ranks used for drag and drop |
| 109 | private int mTargetRank, mPrevTargetRank, mEmptyCellRank; |
| 110 | |
| 111 | private int mState = STATE_NONE; |
| 112 | private boolean mRearrangeOnClose = false; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 113 | boolean mItemsInvalidated = false; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 114 | private ShortcutInfo mCurrentDragInfo; |
| 115 | private View mCurrentDragView; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 116 | private boolean mIsExternalDrag; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 117 | boolean mSuppressOnAdd = false; |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 118 | private boolean mDragInProgress = false; |
| 119 | private boolean mDeleteFolderOnDropCompleted = false; |
| 120 | private boolean mSuppressFolderDeletion = false; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 121 | private boolean mItemAddedBackToSelfViaIcon = false; |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 122 | private float mFolderIconPivotX; |
| 123 | private float mFolderIconPivotY; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 124 | private boolean mIsEditingName = false; |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 125 | |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 126 | private boolean mDestroyed; |
| 127 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 128 | private Runnable mDeferredAction; |
| 129 | private boolean mDeferDropAfterUninstall; |
| 130 | private boolean mUninstallSuccessful; |
| 131 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 132 | /** |
| 133 | * Used to inflate the Workspace from XML. |
| 134 | * |
| 135 | * @param context The application's context. |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 136 | * @param attrs The attributes set containing the Workspace's customization values. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 137 | */ |
| 138 | public Folder(Context context, AttributeSet attrs) { |
| 139 | super(context, attrs); |
| 140 | setAlwaysDrawnWithCacheEnabled(false); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 141 | mInputMethodManager = (InputMethodManager) |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 142 | getContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 143 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 144 | Resources res = getResources(); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 145 | mExpandDuration = res.getInteger(R.integer.config_folderExpandDuration); |
| 146 | mMaterialExpandDuration = res.getInteger(R.integer.config_materialFolderExpandDuration); |
| 147 | mMaterialExpandStagger = res.getInteger(R.integer.config_materialFolderExpandStagger); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 148 | |
| 149 | if (sDefaultFolderName == null) { |
| 150 | sDefaultFolderName = res.getString(R.string.folder_name); |
| 151 | } |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 152 | if (sHintText == null) { |
| 153 | sHintText = res.getString(R.string.folder_hint_text); |
| 154 | } |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 155 | mLauncher = (Launcher) context; |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 156 | // We need this view to be focusable in touch mode so that when text editing of the folder |
| 157 | // name is complete, we have something to focus on, thus hiding the cursor and giving |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 158 | // reliable behavior when clicking the text field (since it will always gain focus on click). |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 159 | setFocusableInTouchMode(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | @Override |
| 163 | protected void onFinishInflate() { |
| 164 | super.onFinishInflate(); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 165 | mContentWrapper = findViewById(R.id.folder_content_wrapper); |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 166 | mContent = (FolderContent) findViewById(R.id.folder_content); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 167 | mContent.setFolder(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 168 | |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 169 | mFolderName = (FolderEditText) findViewById(R.id.folder_name); |
| 170 | mFolderName.setFolder(this); |
Adam Cohen | ea0818d | 2011-09-30 20:06:58 -0700 | [diff] [blame] | 171 | mFolderName.setOnFocusChangeListener(this); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 172 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 173 | // We disable action mode for now since it messes up the view on phones |
| 174 | mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 175 | mFolderName.setOnEditorActionListener(this); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 176 | mFolderName.setSelectAllOnFocus(true); |
Adam Cohen | 7a14d0b | 2011-06-24 11:36:35 -0700 | [diff] [blame] | 177 | mFolderName.setInputType(mFolderName.getInputType() | |
| 178 | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 179 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 180 | mFooter = ALLOW_FOLDER_SCROLL ? findViewById(R.id.folder_footer) : mFolderName; |
| 181 | // We find out how tall footer wants to be (it is set to wrap_content), so that |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 182 | // we can allocate the appropriate amount of space for it. |
| 183 | int measureSpec = MeasureSpec.UNSPECIFIED; |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 184 | mFooter.measure(measureSpec, measureSpec); |
| 185 | mFooterHeight = mFooter.getMeasuredHeight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 186 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 187 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 188 | private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { |
| 189 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | public void onDestroyActionMode(ActionMode mode) { |
| 198 | } |
| 199 | |
| 200 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 201 | return false; |
| 202 | } |
| 203 | }; |
| 204 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 205 | public void onClick(View v) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 206 | Object tag = v.getTag(); |
| 207 | if (tag instanceof ShortcutInfo) { |
Adam Cohen | b5fe60c | 2013-06-06 22:03:51 -0700 | [diff] [blame] | 208 | mLauncher.onClick(v); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 209 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 213 | // Return if global dragging is not enabled |
| 214 | if (!mLauncher.isDraggingEnabled()) return true; |
| 215 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 216 | Object tag = v.getTag(); |
| 217 | if (tag instanceof ShortcutInfo) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 218 | ShortcutInfo item = (ShortcutInfo) tag; |
| 219 | if (!v.isInTouchMode()) { |
| 220 | return false; |
| 221 | } |
| 222 | |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 223 | mLauncher.getWorkspace().beginDragShared(v, this); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 224 | |
| 225 | mCurrentDragInfo = item; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 226 | mEmptyCellRank = item.rank; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 227 | mCurrentDragView = v; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 228 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 229 | mContent.removeItem(mCurrentDragView); |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 230 | mInfo.remove(mCurrentDragInfo); |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 231 | mDragInProgress = true; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 232 | mItemAddedBackToSelfViaIcon = false; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 233 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 234 | return true; |
| 235 | } |
| 236 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 237 | public boolean isEditingName() { |
| 238 | return mIsEditingName; |
| 239 | } |
| 240 | |
| 241 | public void startEditingFolderName() { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 242 | mFolderName.setHint(""); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 243 | mIsEditingName = true; |
| 244 | } |
| 245 | |
| 246 | public void dismissEditingName() { |
| 247 | mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); |
| 248 | doneEditingFolderName(true); |
| 249 | } |
| 250 | |
| 251 | public void doneEditingFolderName(boolean commit) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 252 | mFolderName.setHint(sHintText); |
Adam Cohen | 1df26a3 | 2011-08-12 16:15:23 -0700 | [diff] [blame] | 253 | // Convert to a string here to ensure that no other state associated with the text field |
| 254 | // gets saved. |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 255 | String newTitle = mFolderName.getText().toString(); |
| 256 | mInfo.setTitle(newTitle); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 257 | LauncherModel.updateItemInDatabase(mLauncher, mInfo); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 258 | |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 259 | if (commit) { |
| 260 | sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 261 | String.format(getContext().getString(R.string.folder_renamed), newTitle)); |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 262 | } |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 263 | // In order to clear the focus from the text field, we set the focus on ourself. This |
| 264 | // ensures that every time the field is clicked, focus is gained, giving reliable behavior. |
| 265 | requestFocus(); |
| 266 | |
Adam Cohen | e601a43 | 2011-07-26 21:51:30 -0700 | [diff] [blame] | 267 | Selection.setSelection((Spannable) mFolderName.getText(), 0, 0); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 268 | mIsEditingName = false; |
| 269 | } |
| 270 | |
| 271 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
| 272 | if (actionId == EditorInfo.IME_ACTION_DONE) { |
| 273 | dismissEditingName(); |
| 274 | return true; |
| 275 | } |
| 276 | return false; |
| 277 | } |
| 278 | |
| 279 | public View getEditTextRegion() { |
| 280 | return mFolderName; |
| 281 | } |
| 282 | |
Adam Cohen | 0c872ba | 2011-05-05 10:34:16 -0700 | [diff] [blame] | 283 | /** |
| 284 | * We need to handle touch events to prevent them from falling through to the workspace below. |
| 285 | */ |
| 286 | @Override |
| 287 | public boolean onTouchEvent(MotionEvent ev) { |
| 288 | return true; |
| 289 | } |
| 290 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 291 | public void setDragController(DragController dragController) { |
| 292 | mDragController = dragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 295 | public void setFolderIcon(FolderIcon icon) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 296 | mFolderIcon = icon; |
| 297 | } |
| 298 | |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 299 | @Override |
| 300 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 301 | // When the folder gets focus, we don't want to announce the list of items. |
| 302 | return true; |
| 303 | } |
| 304 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 305 | /** |
| 306 | * @return the FolderInfo object associated with this folder |
| 307 | */ |
| 308 | FolderInfo getInfo() { |
| 309 | return mInfo; |
| 310 | } |
| 311 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 312 | void bind(FolderInfo info) { |
| 313 | mInfo = info; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 314 | ArrayList<ShortcutInfo> children = info.contents; |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 315 | Collections.sort(children, Utilities.RANK_COMPARATOR); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 316 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 317 | ArrayList<ShortcutInfo> overflow = mContent.bindItems(children); |
Adam Cohen | 0057bbc | 2011-08-12 18:30:51 -0700 | [diff] [blame] | 318 | |
Jason Monk | 4ff7388 | 2014-04-24 16:48:07 -0400 | [diff] [blame] | 319 | // If our folder has too many items we prune them from the list. This is an issue |
Adam Cohen | c508b2d | 2011-06-28 14:41:44 -0700 | [diff] [blame] | 320 | // when upgrading from the old Folders implementation which could contain an unlimited |
| 321 | // number of items. |
| 322 | for (ShortcutInfo item: overflow) { |
| 323 | mInfo.remove(item); |
| 324 | LauncherModel.deleteItemFromDatabase(mLauncher, item); |
| 325 | } |
| 326 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 327 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
| 328 | if (lp == null) { |
| 329 | lp = new DragLayer.LayoutParams(0, 0); |
| 330 | lp.customPosition = true; |
| 331 | setLayoutParams(lp); |
| 332 | } |
| 333 | centerAboutIcon(); |
| 334 | |
Adam Cohen | 4dbe6d9 | 2011-05-18 17:14:15 -0700 | [diff] [blame] | 335 | mItemsInvalidated = true; |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 336 | updateTextViewFocus(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 337 | mInfo.addListener(this); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 338 | |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 339 | if (!sDefaultFolderName.contentEquals(mInfo.title)) { |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 340 | mFolderName.setText(mInfo.title); |
| 341 | } else { |
| 342 | mFolderName.setText(""); |
| 343 | } |
Winson Chung | 33231f5 | 2013-12-09 16:57:45 -0800 | [diff] [blame] | 344 | |
| 345 | // In case any children didn't come across during loading, clean up the folder accordingly |
| 346 | mFolderIcon.post(new Runnable() { |
| 347 | public void run() { |
| 348 | if (getItemCount() <= 1) { |
| 349 | replaceFolderWithFinalItem(); |
| 350 | } |
| 351 | } |
| 352 | }); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Creates a new UserFolder, inflated from R.layout.user_folder. |
| 357 | * |
| 358 | * @param context The application's context. |
| 359 | * |
| 360 | * @return A new UserFolder. |
| 361 | */ |
| 362 | static Folder fromXml(Context context) { |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 363 | return (Folder) LayoutInflater.from(context).inflate( |
| 364 | ALLOW_FOLDER_SCROLL ? R.layout.user_folder_scroll : R.layout.user_folder, null); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /** |
| 368 | * This method is intended to make the UserFolder to be visually identical in size and position |
| 369 | * to its associated FolderIcon. This allows for a seamless transition into the expanded state. |
| 370 | */ |
| 371 | private void positionAndSizeAsIcon() { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 372 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | 662b598 | 2011-12-13 17:45:21 -0800 | [diff] [blame] | 373 | setScaleX(0.8f); |
| 374 | setScaleY(0.8f); |
| 375 | setAlpha(0f); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 376 | mState = STATE_SMALL; |
| 377 | } |
| 378 | |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 379 | private void prepareReveal() { |
| 380 | setScaleX(1f); |
| 381 | setScaleY(1f); |
| 382 | setAlpha(1f); |
| 383 | mState = STATE_SMALL; |
| 384 | } |
| 385 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 386 | public void animateOpen() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 387 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | 6441de0 | 2011-12-14 14:25:32 -0800 | [diff] [blame] | 388 | |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 389 | Animator openFolderAnim = null; |
| 390 | final Runnable onCompleteRunnable; |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 391 | if (!Utilities.isLmpOrAbove()) { |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 392 | positionAndSizeAsIcon(); |
| 393 | centerAboutIcon(); |
| 394 | |
| 395 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1); |
| 396 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 397 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 398 | final ObjectAnimator oa = |
| 399 | LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); |
| 400 | oa.setDuration(mExpandDuration); |
| 401 | openFolderAnim = oa; |
| 402 | |
| 403 | setLayerType(LAYER_TYPE_HARDWARE, null); |
| 404 | onCompleteRunnable = new Runnable() { |
| 405 | @Override |
| 406 | public void run() { |
| 407 | setLayerType(LAYER_TYPE_NONE, null); |
| 408 | } |
| 409 | }; |
| 410 | } else { |
| 411 | prepareReveal(); |
| 412 | centerAboutIcon(); |
| 413 | |
| 414 | int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); |
| 415 | int height = getFolderHeight(); |
| 416 | |
| 417 | float transX = - 0.075f * (width / 2 - getPivotX()); |
| 418 | float transY = - 0.075f * (height / 2 - getPivotY()); |
| 419 | setTranslationX(transX); |
| 420 | setTranslationY(transY); |
| 421 | PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, 0); |
| 422 | PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, 0); |
| 423 | |
| 424 | int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX()); |
| 425 | int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY()); |
| 426 | float radius = (float) Math.sqrt(rx * rx + ry * ry); |
| 427 | AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
| 428 | Animator reveal = LauncherAnimUtils.createCircularReveal(this, (int) getPivotX(), |
| 429 | (int) getPivotY(), 0, radius); |
| 430 | reveal.setDuration(mMaterialExpandDuration); |
| 431 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 432 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 433 | mContentWrapper.setAlpha(0f); |
| 434 | Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContentWrapper, "alpha", 0f, 1f); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 435 | iconsAlpha.setDuration(mMaterialExpandDuration); |
| 436 | iconsAlpha.setStartDelay(mMaterialExpandStagger); |
| 437 | iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 438 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 439 | mFooter.setAlpha(0f); |
| 440 | Animator textAlpha = LauncherAnimUtils.ofFloat(mFooter, "alpha", 0f, 1f); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 441 | textAlpha.setDuration(mMaterialExpandDuration); |
| 442 | textAlpha.setStartDelay(mMaterialExpandStagger); |
| 443 | textAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 444 | |
| 445 | Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty); |
| 446 | drift.setDuration(mMaterialExpandDuration); |
| 447 | drift.setStartDelay(mMaterialExpandStagger); |
| 448 | drift.setInterpolator(new LogDecelerateInterpolator(60, 0)); |
| 449 | |
| 450 | anim.play(drift); |
| 451 | anim.play(iconsAlpha); |
| 452 | anim.play(textAlpha); |
| 453 | anim.play(reveal); |
| 454 | |
| 455 | openFolderAnim = anim; |
| 456 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 457 | mContentWrapper.setLayerType(LAYER_TYPE_HARDWARE, null); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 458 | onCompleteRunnable = new Runnable() { |
| 459 | @Override |
| 460 | public void run() { |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 461 | mContentWrapper.setLayerType(LAYER_TYPE_NONE, null); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 462 | } |
| 463 | }; |
| 464 | } |
| 465 | openFolderAnim.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 466 | @Override |
| 467 | public void onAnimationStart(Animator animation) { |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 468 | sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 469 | mContent.getAccessibilityDescription()); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 470 | mState = STATE_ANIMATING; |
| 471 | } |
| 472 | @Override |
| 473 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 474 | mState = STATE_OPEN; |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 475 | |
| 476 | if (onCompleteRunnable != null) { |
| 477 | onCompleteRunnable.run(); |
| 478 | } |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 479 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 480 | mContent.setFocusOnFirstChild(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 481 | } |
| 482 | }); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 483 | openFolderAnim.start(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 484 | |
| 485 | // Make sure the folder picks up the last drag move even if the finger doesn't move. |
| 486 | if (mDragController.isDragging()) { |
| 487 | mDragController.forceTouchMove(); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | public void beginExternalDrag(ShortcutInfo item) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 492 | mCurrentDragInfo = item; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 493 | mEmptyCellRank = mContent.allocateNewLastItemRank(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 494 | mIsExternalDrag = true; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 495 | mDragInProgress = true; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 498 | private void sendCustomAccessibilityEvent(int type, String text) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 499 | AccessibilityManager accessibilityManager = (AccessibilityManager) |
| 500 | getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 501 | if (accessibilityManager.isEnabled()) { |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 502 | AccessibilityEvent event = AccessibilityEvent.obtain(type); |
| 503 | onInitializeAccessibilityEvent(event); |
| 504 | event.getText().add(text); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 505 | accessibilityManager.sendAccessibilityEvent(event); |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 509 | public void animateClosed() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 510 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | 662b598 | 2011-12-13 17:45:21 -0800 | [diff] [blame] | 511 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 512 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f); |
| 513 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f); |
Michael Jurka | 032e6ba | 2013-04-22 15:08:42 +0200 | [diff] [blame] | 514 | final ObjectAnimator oa = |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 515 | LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 516 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 517 | oa.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 518 | @Override |
| 519 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 520 | onCloseComplete(); |
Michael Jurka | 0121c3e | 2012-05-31 08:36:04 -0700 | [diff] [blame] | 521 | setLayerType(LAYER_TYPE_NONE, null); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 522 | mState = STATE_SMALL; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 523 | } |
| 524 | @Override |
| 525 | public void onAnimationStart(Animator animation) { |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 526 | sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 527 | getContext().getString(R.string.folder_closed)); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 528 | mState = STATE_ANIMATING; |
| 529 | } |
| 530 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 531 | oa.setDuration(mExpandDuration); |
Michael Jurka | 0121c3e | 2012-05-31 08:36:04 -0700 | [diff] [blame] | 532 | setLayerType(LAYER_TYPE_HARDWARE, null); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 533 | oa.start(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 536 | public boolean acceptDrop(DragObject d) { |
| 537 | final ItemInfo item = (ItemInfo) d.dragInfo; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 538 | final int itemType = item.itemType; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 539 | return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 540 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && |
| 541 | !isFull()); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 544 | public void onDragEnter(DragObject d) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 545 | mPrevTargetRank = -1; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 546 | mOnExitAlarm.cancelAlarm(); |
| 547 | } |
| 548 | |
| 549 | OnAlarmListener mReorderAlarmListener = new OnAlarmListener() { |
| 550 | public void onAlarm(Alarm alarm) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 551 | mContent.realTimeReorder(mEmptyCellRank, mTargetRank); |
| 552 | mEmptyCellRank = mTargetRank; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 553 | } |
| 554 | }; |
| 555 | |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 556 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
Adam Cohen | 2374abf | 2013-04-16 14:56:57 -0700 | [diff] [blame] | 557 | public boolean isLayoutRtl() { |
| 558 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 559 | } |
| 560 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 561 | public void onDragOver(DragObject d) { |
Sunny Goyal | 1587d53 | 2015-01-29 09:57:16 -0800 | [diff] [blame] | 562 | final float[] r = d.getVisualCenter(null); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 563 | r[0] -= getPaddingLeft(); |
| 564 | r[1] -= getPaddingTop(); |
| 565 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 566 | mTargetRank = mContent.findNearestArea((int) r[0], (int) r[1]); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 567 | if (mTargetRank != mPrevTargetRank) { |
Alan Viverette | 4cda5b7 | 2013-08-28 17:53:41 -0700 | [diff] [blame] | 568 | mReorderAlarm.cancelAlarm(); |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 569 | mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); |
| 570 | mReorderAlarm.setAlarm(REORDER_DELAY); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 571 | mPrevTargetRank = mTargetRank; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 572 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 575 | OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() { |
| 576 | public void onAlarm(Alarm alarm) { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 577 | completeDragExit(); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 578 | } |
| 579 | }; |
| 580 | |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 581 | public void completeDragExit() { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 582 | mLauncher.closeFolder(); |
| 583 | mCurrentDragInfo = null; |
| 584 | mCurrentDragView = null; |
| 585 | mSuppressOnAdd = false; |
| 586 | mRearrangeOnClose = true; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 587 | mIsExternalDrag = false; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 590 | public void onDragExit(DragObject d) { |
Mindy DelliCarpini | 53b8d07 | 2013-07-03 08:23:13 -0700 | [diff] [blame] | 591 | // We only close the folder if this is a true drag exit, ie. not because |
| 592 | // a drop has occurred above the folder. |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 593 | if (!d.dragComplete) { |
| 594 | mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener); |
| 595 | mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY); |
| 596 | } |
| 597 | mReorderAlarm.cancelAlarm(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 600 | public void onDropCompleted(final View target, final DragObject d, |
| 601 | final boolean isFlingToDelete, final boolean success) { |
| 602 | if (mDeferDropAfterUninstall) { |
Michael Jurka | f300758 | 2013-08-21 14:33:57 +0200 | [diff] [blame] | 603 | Log.d(TAG, "Deferred handling drop because waiting for uninstall."); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 604 | mDeferredAction = new Runnable() { |
| 605 | public void run() { |
| 606 | onDropCompleted(target, d, isFlingToDelete, success); |
| 607 | mDeferredAction = null; |
| 608 | } |
| 609 | }; |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | boolean beingCalledAfterUninstall = mDeferredAction != null; |
| 614 | boolean successfulDrop = |
| 615 | success && (!beingCalledAfterUninstall || mUninstallSuccessful); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 616 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 617 | if (successfulDrop) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 618 | if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) { |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 619 | replaceFolderWithFinalItem(); |
| 620 | } |
| 621 | } else { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 622 | rearrangeChildren(); |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 623 | // The drag failed, we need to return the item to the folder |
| 624 | mFolderIcon.onDrop(d); |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | if (target != this) { |
| 628 | if (mOnExitAlarm.alarmPending()) { |
| 629 | mOnExitAlarm.cancelAlarm(); |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 630 | if (!successfulDrop) { |
Adam Cohen | 7a8b82b | 2013-05-29 18:41:50 -0700 | [diff] [blame] | 631 | mSuppressFolderDeletion = true; |
| 632 | } |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 633 | completeDragExit(); |
| 634 | } |
Adam Cohen | 9c58d82 | 2013-12-13 17:18:10 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 637 | mDeleteFolderOnDropCompleted = false; |
| 638 | mDragInProgress = false; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 639 | mItemAddedBackToSelfViaIcon = false; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 640 | mCurrentDragInfo = null; |
| 641 | mCurrentDragView = null; |
| 642 | mSuppressOnAdd = false; |
Adam Cohen | 4045eb7 | 2011-10-06 11:44:26 -0700 | [diff] [blame] | 643 | |
| 644 | // Reordering may have occured, and we need to save the new item locations. We do this once |
| 645 | // at the end to prevent unnecessary database operations. |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 646 | updateItemLocationsInDatabaseBatch(); |
Adam Cohen | 4045eb7 | 2011-10-06 11:44:26 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 649 | public void deferCompleteDropAfterUninstallActivity() { |
| 650 | mDeferDropAfterUninstall = true; |
| 651 | } |
| 652 | |
| 653 | public void onUninstallActivityReturned(boolean success) { |
| 654 | mDeferDropAfterUninstall = false; |
| 655 | mUninstallSuccessful = success; |
| 656 | if (mDeferredAction != null) { |
| 657 | mDeferredAction.run(); |
| 658 | } |
| 659 | } |
| 660 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 661 | @Override |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 662 | public float getIntrinsicIconScaleFactor() { |
| 663 | return 1f; |
| 664 | } |
| 665 | |
| 666 | @Override |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 667 | public boolean supportsFlingToDelete() { |
| 668 | return true; |
| 669 | } |
| 670 | |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 671 | @Override |
| 672 | public boolean supportsAppInfoDropTarget() { |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | @Override |
| 677 | public boolean supportsDeleteDropTarget() { |
| 678 | return true; |
| 679 | } |
| 680 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 681 | public void onFlingToDelete(DragObject d, int x, int y, PointF vec) { |
| 682 | // Do nothing |
| 683 | } |
| 684 | |
| 685 | @Override |
| 686 | public void onFlingToDeleteCompleted() { |
| 687 | // Do nothing |
| 688 | } |
| 689 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 690 | private void updateItemLocationsInDatabaseBatch() { |
| 691 | ArrayList<View> list = getItemsInReadingOrder(); |
| 692 | ArrayList<ItemInfo> items = new ArrayList<ItemInfo>(); |
| 693 | for (int i = 0; i < list.size(); i++) { |
| 694 | View v = list.get(i); |
| 695 | ItemInfo info = (ItemInfo) v.getTag(); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 696 | info.rank = i; |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 697 | items.add(info); |
| 698 | } |
| 699 | |
| 700 | LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0); |
| 701 | } |
| 702 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 703 | public void addItemLocationsInDatabase() { |
| 704 | ArrayList<View> list = getItemsInReadingOrder(); |
| 705 | for (int i = 0; i < list.size(); i++) { |
| 706 | View v = list.get(i); |
| 707 | ItemInfo info = (ItemInfo) v.getTag(); |
| 708 | LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0, |
| 709 | info.cellX, info.cellY, false); |
| 710 | } |
| 711 | } |
| 712 | |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 713 | public void notifyDrop() { |
| 714 | if (mDragInProgress) { |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 715 | mItemAddedBackToSelfViaIcon = true; |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 716 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | public boolean isDropEnabled() { |
| 720 | return true; |
| 721 | } |
| 722 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 723 | public boolean isFull() { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 724 | return mContent.isFull(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | private void centerAboutIcon() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 728 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 729 | |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 730 | DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 731 | int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 732 | int height = getFolderHeight(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 733 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 734 | float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, sTempRect); |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 735 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 736 | LauncherAppState app = LauncherAppState.getInstance(); |
| 737 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 738 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 739 | int centerX = (int) (sTempRect.left + sTempRect.width() * scale / 2); |
| 740 | int centerY = (int) (sTempRect.top + sTempRect.height() * scale / 2); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 741 | int centeredLeft = centerX - width / 2; |
| 742 | int centeredTop = centerY - height / 2; |
Winson Chung | 3057b1c | 2013-10-10 17:35:35 -0700 | [diff] [blame] | 743 | int currentPage = mLauncher.getWorkspace().getNextPage(); |
Adam Cohen | 7cc1bc4 | 2011-12-13 21:28:43 -0800 | [diff] [blame] | 744 | // In case the workspace is scrolling, we need to use the final scroll to compute |
| 745 | // the folders bounds. |
| 746 | mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 747 | // We first fetch the currently visible CellLayoutChildren |
Adam Cohen | 7cc1bc4 | 2011-12-13 21:28:43 -0800 | [diff] [blame] | 748 | CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 749 | ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 750 | Rect bounds = new Rect(); |
| 751 | parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); |
Adam Cohen | 7cc1bc4 | 2011-12-13 21:28:43 -0800 | [diff] [blame] | 752 | // We reset the workspaces scroll |
| 753 | mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 754 | |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 755 | // We need to bound the folder to the currently visible CellLayoutChildren |
| 756 | int left = Math.min(Math.max(bounds.left, centeredLeft), |
| 757 | bounds.left + bounds.width() - width); |
| 758 | int top = Math.min(Math.max(bounds.top, centeredTop), |
| 759 | bounds.top + bounds.height() - height); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 760 | if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) { |
| 761 | // Center the folder if it is full (on phones only) |
| 762 | left = (grid.availableWidthPx - width) / 2; |
| 763 | } else if (width >= bounds.width()) { |
| 764 | // If the folder doesn't fit within the bounds, center it about the desired bounds |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 765 | left = bounds.left + (bounds.width() - width) / 2; |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 766 | } |
Adam Cohen | 35e7e64 | 2011-07-17 14:47:18 -0700 | [diff] [blame] | 767 | if (height >= bounds.height()) { |
| 768 | top = bounds.top + (bounds.height() - height) / 2; |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 769 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 770 | |
| 771 | int folderPivotX = width / 2 + (centeredLeft - left); |
| 772 | int folderPivotY = height / 2 + (centeredTop - top); |
| 773 | setPivotX(folderPivotX); |
| 774 | setPivotY(folderPivotY); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 775 | mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 776 | (1.0f * folderPivotX / width)); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 777 | mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 778 | (1.0f * folderPivotY / height)); |
Adam Cohen | 3bf84d3 | 2012-05-07 20:17:14 -0700 | [diff] [blame] | 779 | |
Adam Cohen | 662b598 | 2011-12-13 17:45:21 -0800 | [diff] [blame] | 780 | lp.width = width; |
| 781 | lp.height = height; |
| 782 | lp.x = left; |
| 783 | lp.y = top; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 786 | float getPivotXForIconAnimation() { |
| 787 | return mFolderIconPivotX; |
| 788 | } |
| 789 | float getPivotYForIconAnimation() { |
| 790 | return mFolderIconPivotY; |
| 791 | } |
| 792 | |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 793 | private int getContentAreaHeight() { |
| 794 | LauncherAppState app = LauncherAppState.getInstance(); |
| 795 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 796 | Rect workspacePadding = grid.getWorkspacePadding(grid.isLandscape ? |
| 797 | CellLayout.LANDSCAPE : CellLayout.PORTRAIT); |
| 798 | int maxContentAreaHeight = grid.availableHeightPx - |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 799 | workspacePadding.top - workspacePadding.bottom - |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 800 | mFooterHeight; |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 801 | int height = Math.min(maxContentAreaHeight, |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 802 | mContent.getDesiredHeight()); |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 803 | return Math.max(height, MIN_CONTENT_DIMEN); |
| 804 | } |
| 805 | |
| 806 | private int getContentAreaWidth() { |
| 807 | return Math.max(mContent.getDesiredWidth(), MIN_CONTENT_DIMEN); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 810 | private int getFolderHeight() { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 811 | return getFolderHeight(getContentAreaHeight()); |
| 812 | } |
| 813 | |
| 814 | private int getFolderHeight(int contentAreaHeight) { |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 815 | return getPaddingTop() + getPaddingBottom() + contentAreaHeight + mFooterHeight; |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 816 | } |
Adam Cohen | 234c4cd | 2011-07-17 21:03:04 -0700 | [diff] [blame] | 817 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 818 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 819 | int contentWidth = getContentAreaWidth(); |
| 820 | int contentHeight = getContentAreaHeight(); |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 821 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 822 | int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY); |
| 823 | int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentHeight, MeasureSpec.EXACTLY); |
| 824 | |
| 825 | mContent.setFixedSize(contentWidth, contentHeight); |
| 826 | mContentWrapper.measure(contentAreaWidthSpec, contentAreaHeightSpec); |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 827 | mFooter.measure(contentAreaWidthSpec, |
| 828 | MeasureSpec.makeMeasureSpec(mFooterHeight, MeasureSpec.EXACTLY)); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 829 | |
| 830 | int folderWidth = getPaddingLeft() + getPaddingRight() + contentWidth; |
| 831 | int folderHeight = getFolderHeight(contentHeight); |
| 832 | setMeasuredDimension(folderWidth, folderHeight); |
Adam Cohen | 234c4cd | 2011-07-17 21:03:04 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 835 | /** |
| 836 | * Rearranges the children based on their rank. |
| 837 | */ |
| 838 | public void rearrangeChildren() { |
| 839 | rearrangeChildren(-1); |
| 840 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 841 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 842 | /** |
| 843 | * Rearranges the children based on their rank. |
| 844 | * @param itemCount if greater than the total children count, empty spaces are left at the end, |
| 845 | * otherwise it is ignored. |
| 846 | */ |
| 847 | public void rearrangeChildren(int itemCount) { |
| 848 | ArrayList<View> views = getItemsInReadingOrder(); |
| 849 | mContent.arrangeChildren(views, Math.max(itemCount, views.size())); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 850 | mItemsInvalidated = true; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Sunny Goyal | c491835 | 2015-03-10 18:15:48 -0700 | [diff] [blame^] | 853 | // TODO remove this once GSA code fix is submitted |
| 854 | public ViewGroup getContent() { |
| 855 | return (ViewGroup) mContent; |
| 856 | } |
| 857 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 858 | public int getItemCount() { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 859 | return mContent.getItemCount(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 862 | private void onCloseComplete() { |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 863 | DragLayer parent = (DragLayer) getParent(); |
Michael Jurka | 5649c28 | 2012-06-18 10:33:21 -0700 | [diff] [blame] | 864 | if (parent != null) { |
| 865 | parent.removeView(this); |
| 866 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 867 | mDragController.removeDropTarget((DropTarget) this); |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 868 | clearFocus(); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 869 | mFolderIcon.requestFocus(); |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 870 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 871 | if (mRearrangeOnClose) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 872 | rearrangeChildren(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 873 | mRearrangeOnClose = false; |
| 874 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 875 | if (getItemCount() <= 1) { |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 876 | if (!mDragInProgress && !mSuppressFolderDeletion) { |
| 877 | replaceFolderWithFinalItem(); |
| 878 | } else if (mDragInProgress) { |
| 879 | mDeleteFolderOnDropCompleted = true; |
| 880 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 881 | } |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 882 | mSuppressFolderDeletion = false; |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | private void replaceFolderWithFinalItem() { |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 886 | // Add the last remaining child to the workspace in place of the folder |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 887 | Runnable onCompleteRunnable = new Runnable() { |
| 888 | @Override |
| 889 | public void run() { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 890 | CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 891 | |
Winson Chung | 33231f5 | 2013-12-09 16:57:45 -0800 | [diff] [blame] | 892 | View child = null; |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 893 | // Move the item from the folder to the workspace, in the position of the folder |
| 894 | if (getItemCount() == 1) { |
| 895 | ShortcutInfo finalItem = mInfo.contents.get(0); |
Adam Cohen | c5e63f3 | 2012-07-12 16:16:57 -0700 | [diff] [blame] | 896 | child = mLauncher.createShortcut(R.layout.application, cellLayout, |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 897 | finalItem); |
| 898 | LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 899 | mInfo.screenId, mInfo.cellX, mInfo.cellY); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 900 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 901 | if (getItemCount() <= 1) { |
| 902 | // Remove the folder |
| 903 | LauncherModel.deleteItemFromDatabase(mLauncher, mInfo); |
Dan Sandler | 0eb687f | 2014-01-10 13:24:55 -0500 | [diff] [blame] | 904 | if (cellLayout != null) { |
| 905 | // b/12446428 -- sometimes the cell layout has already gone away? |
| 906 | cellLayout.removeView(mFolderIcon); |
| 907 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 908 | if (mFolderIcon instanceof DropTarget) { |
| 909 | mDragController.removeDropTarget((DropTarget) mFolderIcon); |
| 910 | } |
| 911 | mLauncher.removeFolder(mInfo); |
| 912 | } |
Adam Cohen | c5e63f3 | 2012-07-12 16:16:57 -0700 | [diff] [blame] | 913 | // We add the child after removing the folder to prevent both from existing at |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 914 | // the same time in the CellLayout. We need to add the new item with addInScreenFromBind() |
| 915 | // to ensure that hotseat items are placed correctly. |
Adam Cohen | c5e63f3 | 2012-07-12 16:16:57 -0700 | [diff] [blame] | 916 | if (child != null) { |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 917 | mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId, |
Adam Cohen | c5e63f3 | 2012-07-12 16:16:57 -0700 | [diff] [blame] | 918 | mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); |
| 919 | } |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 920 | } |
| 921 | }; |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 922 | View finalChild = mContent.getLastItem(); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 923 | if (finalChild != null) { |
| 924 | mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable); |
Winson Chung | 33231f5 | 2013-12-09 16:57:45 -0800 | [diff] [blame] | 925 | } else { |
| 926 | onCompleteRunnable.run(); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 927 | } |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 928 | mDestroyed = true; |
| 929 | } |
| 930 | |
| 931 | boolean isDestroyed() { |
| 932 | return mDestroyed; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 935 | // This method keeps track of the last item in the folder for the purposes |
| 936 | // of keyboard focus |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 937 | public void updateTextViewFocus() { |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 938 | View lastChild = mContent.getLastItem(); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 939 | if (lastChild != null) { |
| 940 | mFolderName.setNextFocusDownId(lastChild.getId()); |
| 941 | mFolderName.setNextFocusRightId(lastChild.getId()); |
| 942 | mFolderName.setNextFocusLeftId(lastChild.getId()); |
| 943 | mFolderName.setNextFocusUpId(lastChild.getId()); |
| 944 | } |
| 945 | } |
| 946 | |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 947 | public void onDrop(DragObject d) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 948 | Runnable cleanUpRunnable = null; |
| 949 | |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 950 | // If we are coming from All Apps space, we defer removing the extra empty screen |
| 951 | // until the folder closes |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 952 | if (d.dragSource != mLauncher.getWorkspace() && !(d.dragSource instanceof Folder)) { |
| 953 | cleanUpRunnable = new Runnable() { |
| 954 | @Override |
| 955 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 956 | mLauncher.exitSpringLoadedDragModeDelayed(true, |
| 957 | Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 958 | null); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 959 | } |
| 960 | }; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 961 | } |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 962 | |
| 963 | View currentDragView; |
| 964 | ShortcutInfo si = mCurrentDragInfo; |
| 965 | if (mIsExternalDrag) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 966 | currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 967 | // Actually move the item in the database if it was an external drag. Call this |
| 968 | // before creating the view, so that ShortcutInfo is updated appropriately. |
| 969 | LauncherModel.addOrMoveItemInDatabase( |
| 970 | mLauncher, si, mInfo.id, 0, si.cellX, si.cellY); |
| 971 | |
| 972 | // We only need to update the locations if it doesn't get handled in #onDropCompleted. |
| 973 | if (d.dragSource != this) { |
| 974 | updateItemLocationsInDatabaseBatch(); |
| 975 | } |
| 976 | mIsExternalDrag = false; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 977 | } else { |
| 978 | currentDragView = mCurrentDragView; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 979 | mContent.addViewForRank(currentDragView, si, mEmptyCellRank); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 980 | } |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 981 | |
| 982 | if (d.dragView.hasDrawn()) { |
| 983 | |
| 984 | // Temporarily reset the scale such that the animation target gets calculated correctly. |
| 985 | float scaleX = getScaleX(); |
| 986 | float scaleY = getScaleY(); |
| 987 | setScaleX(1.0f); |
| 988 | setScaleY(1.0f); |
| 989 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, |
| 990 | cleanUpRunnable, null); |
| 991 | setScaleX(scaleX); |
| 992 | setScaleY(scaleY); |
| 993 | } else { |
| 994 | d.deferDragViewCleanupPostAnimation = false; |
| 995 | currentDragView.setVisibility(VISIBLE); |
| 996 | } |
| 997 | mItemsInvalidated = true; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 998 | rearrangeChildren(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 999 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1000 | // Temporarily suppress the listener, as we did all the work already here. |
| 1001 | mSuppressOnAdd = true; |
| 1002 | mInfo.add(si); |
| 1003 | mSuppressOnAdd = false; |
Sunny Goyal | 4b02017 | 2014-08-28 14:51:14 -0700 | [diff] [blame] | 1004 | // Clear the drag info, as it is no longer being dragged. |
| 1005 | mCurrentDragInfo = null; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Adam Cohen | 7a8b82b | 2013-05-29 18:41:50 -0700 | [diff] [blame] | 1008 | // This is used so the item doesn't immediately appear in the folder when added. In one case |
| 1009 | // we need to create the illusion that the item isn't added back to the folder yet, to |
| 1010 | // to correspond to the animation of the icon back into the folder. This is |
| 1011 | public void hideItem(ShortcutInfo info) { |
| 1012 | View v = getViewForInfo(info); |
| 1013 | v.setVisibility(INVISIBLE); |
| 1014 | } |
| 1015 | public void showItem(ShortcutInfo info) { |
| 1016 | View v = getViewForInfo(info); |
| 1017 | v.setVisibility(VISIBLE); |
| 1018 | } |
| 1019 | |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1020 | public void onAdd(ShortcutInfo item) { |
| 1021 | mItemsInvalidated = true; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 1022 | // If the item was dropped onto this open folder, we have done the work associated |
| 1023 | // with adding the item to the folder, as indicated by mSuppressOnAdd being set |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1024 | if (mSuppressOnAdd) return; |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1025 | mContent.createAndAddViewForRank(item, mContent.allocateNewLastItemRank()); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1026 | LauncherModel.addOrMoveItemInDatabase( |
| 1027 | mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); |
| 1028 | } |
| 1029 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1030 | public void onRemove(ShortcutInfo item) { |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1031 | mItemsInvalidated = true; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 1032 | // If this item is being dragged from this open folder, we have already handled |
| 1033 | // the work associated with removing the item, so we don't have to do anything here. |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1034 | if (item == mCurrentDragInfo) return; |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 1035 | View v = getViewForInfo(item); |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 1036 | mContent.removeItem(v); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1037 | if (mState == STATE_ANIMATING) { |
| 1038 | mRearrangeOnClose = true; |
| 1039 | } else { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1040 | rearrangeChildren(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1041 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1042 | if (getItemCount() <= 1) { |
| 1043 | replaceFolderWithFinalItem(); |
| 1044 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1045 | } |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1046 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1047 | private View getViewForInfo(final ShortcutInfo item) { |
| 1048 | return mContent.iterateOverItems(new ItemOperator() { |
| 1049 | |
| 1050 | @Override |
| 1051 | public boolean evaluate(ItemInfo info, View view, View parent) { |
| 1052 | return info == item; |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 1053 | } |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1054 | }); |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 1057 | public void onItemsChanged() { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1058 | updateTextViewFocus(); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 1059 | } |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1060 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 1061 | public void onTitleChanged(CharSequence title) { |
| 1062 | } |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 1063 | |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1064 | public ArrayList<View> getItemsInReadingOrder() { |
| 1065 | if (mItemsInvalidated) { |
| 1066 | mItemsInReadingOrder.clear(); |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1067 | mContent.iterateOverItems(new ItemOperator() { |
| 1068 | |
| 1069 | @Override |
| 1070 | public boolean evaluate(ItemInfo info, View view, View parent) { |
| 1071 | mItemsInReadingOrder.add(view); |
| 1072 | return false; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1073 | } |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1074 | }); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1075 | mItemsInvalidated = false; |
| 1076 | } |
| 1077 | return mItemsInReadingOrder; |
| 1078 | } |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 1079 | |
| 1080 | public void getLocationInDragLayer(int[] loc) { |
| 1081 | mLauncher.getDragLayer().getLocationInDragLayer(this, loc); |
| 1082 | } |
Adam Cohen | ea0818d | 2011-09-30 20:06:58 -0700 | [diff] [blame] | 1083 | |
| 1084 | public void onFocusChange(View v, boolean hasFocus) { |
| 1085 | if (v == mFolderName && hasFocus) { |
| 1086 | startEditingFolderName(); |
| 1087 | } |
| 1088 | } |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 1089 | |
| 1090 | @Override |
| 1091 | public void getHitRectRelativeToDragLayer(Rect outRect) { |
| 1092 | getHitRect(outRect); |
| 1093 | } |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1094 | |
| 1095 | public static interface FolderContent { |
| 1096 | void setFolder(Folder f); |
| 1097 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 1098 | void removeItem(View v); |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1099 | |
| 1100 | boolean isFull(); |
| 1101 | int getItemCount(); |
| 1102 | |
| 1103 | int getDesiredWidth(); |
| 1104 | int getDesiredHeight(); |
| 1105 | void setFixedSize(int width, int height); |
| 1106 | |
| 1107 | /** |
| 1108 | * Iterates over all its items in a reading order. |
| 1109 | * @return the view for which the operator returned true. |
| 1110 | */ |
| 1111 | View iterateOverItems(ItemOperator op); |
| 1112 | View getLastItem(); |
| 1113 | |
| 1114 | String getAccessibilityDescription(); |
| 1115 | |
| 1116 | /** |
| 1117 | * Binds items to the layout. |
| 1118 | * @return list of items that could not be bound, probably because we hit the max size limit. |
| 1119 | */ |
| 1120 | ArrayList<ShortcutInfo> bindItems(ArrayList<ShortcutInfo> children); |
| 1121 | |
| 1122 | /** |
| 1123 | * Create space for a new item at the end, and returns the rank for that item. |
| 1124 | * Resizes the content if necessary. |
| 1125 | */ |
| 1126 | int allocateNewLastItemRank(); |
| 1127 | |
| 1128 | View createAndAddViewForRank(ShortcutInfo item, int rank); |
| 1129 | |
| 1130 | /** |
| 1131 | * Adds the {@param view} to the layout based on {@param rank} and updated the position |
| 1132 | * related attributes. It assumes that {@param item} is already attached to the view. |
| 1133 | */ |
| 1134 | void addViewForRank(View view, ShortcutInfo item, int rank); |
| 1135 | |
| 1136 | /** |
| 1137 | * Reorders the items such that the {@param empty} spot moves to {@param target} |
| 1138 | */ |
| 1139 | void realTimeReorder(int empty, int target); |
| 1140 | |
| 1141 | /** |
| 1142 | * @return the rank of the cell nearest to the provided pixel position. |
| 1143 | */ |
| 1144 | int findNearestArea(int pixelX, int pixelY); |
| 1145 | |
| 1146 | /** |
| 1147 | * Updates position and rank of all the children in the view based. |
| 1148 | * @param list the ordered list of children. |
| 1149 | * @param itemCount if greater than the total children count, empty spaces are left |
| 1150 | * at the end. |
| 1151 | */ |
| 1152 | void arrangeChildren(ArrayList<View> list, int itemCount); |
| 1153 | |
| 1154 | /** |
| 1155 | * Sets the focus on the first visible child. |
| 1156 | */ |
| 1157 | void setFocusOnFirstChild(); |
| 1158 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1159 | } |