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