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 | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 24 | import android.annotation.SuppressLint; |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 25 | import android.annotation.TargetApi; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 26 | import android.content.Context; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 27 | import android.content.res.Resources; |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 28 | import android.graphics.Point; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 29 | import android.graphics.PointF; |
Romain Guy | fb5411e | 2010-02-24 10:04:17 -0800 | [diff] [blame] | 30 | import android.graphics.Rect; |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 31 | import android.os.Build; |
Winson Chung | 8f1eff7 | 2015-05-28 17:33:40 -0700 | [diff] [blame] | 32 | import android.os.Bundle; |
Adam Cohen | 7a14d0b | 2011-06-24 11:36:35 -0700 | [diff] [blame] | 33 | import android.text.InputType; |
Adam Cohen | e601a43 | 2011-07-26 21:51:30 -0700 | [diff] [blame] | 34 | import android.text.Selection; |
| 35 | import android.text.Spannable; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 36 | import android.util.AttributeSet; |
Adam Cohen | 3bf84d3 | 2012-05-07 20:17:14 -0700 | [diff] [blame] | 37 | import android.util.Log; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 38 | import android.view.ActionMode; |
| 39 | import android.view.KeyEvent; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 40 | import android.view.Menu; |
| 41 | import android.view.MenuItem; |
Adam Cohen | 0c872ba | 2011-05-05 10:34:16 -0700 | [diff] [blame] | 42 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 43 | import android.view.View; |
Sunny Goyal | c491835 | 2015-03-10 18:15:48 -0700 | [diff] [blame] | 44 | import android.view.ViewGroup; |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 45 | import android.view.accessibility.AccessibilityEvent; |
| 46 | import android.view.accessibility.AccessibilityManager; |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 47 | import android.view.animation.AccelerateInterpolator; |
Sunny Goyal | c1cd23b | 2015-06-01 17:15:34 -0700 | [diff] [blame] | 48 | import android.view.animation.AnimationUtils; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 49 | import android.view.inputmethod.EditorInfo; |
| 50 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 51 | import android.widget.LinearLayout; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 52 | import android.widget.TextView; |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 53 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 54 | import com.android.launcher3.CellLayout.CellInfo; |
Sunny Goyal | f406615 | 2015-04-15 09:42:19 -0700 | [diff] [blame] | 55 | import com.android.launcher3.DragController.DragListener; |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 56 | import com.android.launcher3.FolderInfo.FolderListener; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 57 | import com.android.launcher3.UninstallDropTarget.UninstallSource; |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 58 | import com.android.launcher3.Workspace.ItemOperator; |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 59 | import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 60 | import com.android.launcher3.util.Thunk; |
Sunny Goyal | 2245fa2 | 2015-07-06 11:45:18 -0700 | [diff] [blame] | 61 | import com.android.launcher3.util.UiThreadCircularReveal; |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 62 | |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 63 | import java.util.ArrayList; |
Adam Cohen | 3bf84d3 | 2012-05-07 20:17:14 -0700 | [diff] [blame] | 64 | import java.util.Collections; |
Sunny Goyal | 1dd0f8b | 2015-07-06 13:04:02 -0700 | [diff] [blame] | 65 | import java.util.Comparator; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 66 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 67 | /** |
| 68 | * Represents a set of icons chosen by the user or generated by the system. |
| 69 | */ |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 70 | public class Folder extends LinearLayout implements DragSource, View.OnClickListener, |
Adam Cohen | ea0818d | 2011-09-30 20:06:58 -0700 | [diff] [blame] | 71 | View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener, |
Winson Chung | 8f1eff7 | 2015-05-28 17:33:40 -0700 | [diff] [blame] | 72 | View.OnFocusChangeListener, DragListener, UninstallSource, AccessibilityDragSource, |
| 73 | Stats.LaunchSourceProvider { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 74 | private static final String TAG = "Launcher.Folder"; |
| 75 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 76 | /** |
| 77 | * We avoid measuring {@link #mContentWrapper} with a 0 width or height, as this |
| 78 | * results in CellLayout being measured as UNSPECIFIED, which it does not support. |
| 79 | */ |
| 80 | private static final int MIN_CONTENT_DIMEN = 5; |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 81 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 82 | static final int STATE_NONE = -1; |
| 83 | static final int STATE_SMALL = 0; |
| 84 | static final int STATE_ANIMATING = 1; |
| 85 | static final int STATE_OPEN = 2; |
| 86 | |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 87 | /** |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 88 | * Time for which the scroll hint is shown before automatically changing page. |
| 89 | */ |
| 90 | public static final int SCROLL_HINT_DURATION = DragController.SCROLL_DELAY; |
| 91 | |
| 92 | /** |
| 93 | * Fraction of icon width which behave as scroll region. |
| 94 | */ |
| 95 | private static final float ICON_OVERSCROLL_WIDTH_FACTOR = 0.45f; |
| 96 | |
Sunny Goyal | a07c2f5 | 2015-06-01 11:00:38 -0700 | [diff] [blame] | 97 | private static final int FOLDER_NAME_ANIMATION_DURATION = 633; |
Sunny Goyal | b7e15ad | 2015-05-07 14:51:31 -0700 | [diff] [blame] | 98 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 99 | private static final int REORDER_DELAY = 250; |
Adam Cohen | 5d518fa | 2013-12-05 14:16:23 -0800 | [diff] [blame] | 100 | private static final int ON_EXIT_CLOSE_DELAY = 400; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 101 | private static final Rect sTempRect = new Rect(); |
| 102 | |
| 103 | private static String sDefaultFolderName; |
| 104 | private static String sHintText; |
| 105 | |
| 106 | private final Alarm mReorderAlarm = new Alarm(); |
| 107 | private final Alarm mOnExitAlarm = new Alarm(); |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 108 | private final Alarm mOnScrollHintAlarm = new Alarm(); |
| 109 | @Thunk final Alarm mScrollPauseAlarm = new Alarm(); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 110 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 111 | @Thunk final ArrayList<View> mItemsInReadingOrder = new ArrayList<View>(); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 112 | |
| 113 | private final int mExpandDuration; |
| 114 | private final int mMaterialExpandDuration; |
| 115 | private final int mMaterialExpandStagger; |
| 116 | |
| 117 | private final InputMethodManager mInputMethodManager; |
| 118 | |
| 119 | protected final Launcher mLauncher; |
| 120 | protected DragController mDragController; |
| 121 | protected FolderInfo mInfo; |
| 122 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 123 | @Thunk FolderIcon mFolderIcon; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 124 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 125 | @Thunk FolderPagedView mContent; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 126 | @Thunk View mContentWrapper; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 127 | FolderEditText mFolderName; |
| 128 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 129 | private View mFooter; |
| 130 | private int mFooterHeight; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 131 | |
| 132 | // Cell ranks used for drag and drop |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 133 | @Thunk int mTargetRank, mPrevTargetRank, mEmptyCellRank; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 134 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 135 | @Thunk int mState = STATE_NONE; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 136 | private boolean mRearrangeOnClose = false; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 137 | boolean mItemsInvalidated = false; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 138 | private ShortcutInfo mCurrentDragInfo; |
| 139 | private View mCurrentDragView; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 140 | private boolean mIsExternalDrag; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 141 | boolean mSuppressOnAdd = false; |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 142 | private boolean mDragInProgress = false; |
| 143 | private boolean mDeleteFolderOnDropCompleted = false; |
| 144 | private boolean mSuppressFolderDeletion = false; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 145 | private boolean mItemAddedBackToSelfViaIcon = false; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 146 | @Thunk float mFolderIconPivotX; |
| 147 | @Thunk float mFolderIconPivotY; |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 148 | private boolean mIsEditingName = false; |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 149 | |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 150 | private boolean mDestroyed; |
| 151 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 152 | @Thunk Runnable mDeferredAction; |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 153 | private boolean mDeferDropAfterUninstall; |
| 154 | private boolean mUninstallSuccessful; |
| 155 | |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 156 | // Folder scrolling |
| 157 | private int mScrollAreaOffset; |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 158 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 159 | @Thunk int mScrollHintDir = DragController.SCROLL_NONE; |
| 160 | @Thunk int mCurrentScrollDir = DragController.SCROLL_NONE; |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 161 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 162 | /** |
| 163 | * Used to inflate the Workspace from XML. |
| 164 | * |
| 165 | * @param context The application's context. |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 166 | * @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] | 167 | */ |
| 168 | public Folder(Context context, AttributeSet attrs) { |
| 169 | super(context, attrs); |
| 170 | setAlwaysDrawnWithCacheEnabled(false); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 171 | mInputMethodManager = (InputMethodManager) |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 172 | getContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 173 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 174 | Resources res = getResources(); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 175 | mExpandDuration = res.getInteger(R.integer.config_folderExpandDuration); |
| 176 | mMaterialExpandDuration = res.getInteger(R.integer.config_materialFolderExpandDuration); |
| 177 | mMaterialExpandStagger = res.getInteger(R.integer.config_materialFolderExpandStagger); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 178 | |
| 179 | if (sDefaultFolderName == null) { |
| 180 | sDefaultFolderName = res.getString(R.string.folder_name); |
| 181 | } |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 182 | if (sHintText == null) { |
| 183 | sHintText = res.getString(R.string.folder_hint_text); |
| 184 | } |
Adam Cohen | 4eac29a | 2011-07-11 17:53:37 -0700 | [diff] [blame] | 185 | mLauncher = (Launcher) context; |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 186 | // We need this view to be focusable in touch mode so that when text editing of the folder |
| 187 | // 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] | 188 | // 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] | 189 | setFocusableInTouchMode(true); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
| 193 | protected void onFinishInflate() { |
| 194 | super.onFinishInflate(); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 195 | mContentWrapper = findViewById(R.id.folder_content_wrapper); |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 196 | mContent = (FolderPagedView) findViewById(R.id.folder_content); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 197 | mContent.setFolder(this); |
Sunny Goyal | dcbcc86 | 2014-08-12 15:58:36 -0700 | [diff] [blame] | 198 | |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 199 | mFolderName = (FolderEditText) findViewById(R.id.folder_name); |
| 200 | mFolderName.setFolder(this); |
Adam Cohen | ea0818d | 2011-09-30 20:06:58 -0700 | [diff] [blame] | 201 | mFolderName.setOnFocusChangeListener(this); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 202 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 203 | // We disable action mode for now since it messes up the view on phones |
| 204 | mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 205 | mFolderName.setOnEditorActionListener(this); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 206 | mFolderName.setSelectAllOnFocus(true); |
Adam Cohen | 7a14d0b | 2011-06-24 11:36:35 -0700 | [diff] [blame] | 207 | mFolderName.setInputType(mFolderName.getInputType() | |
| 208 | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 209 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 210 | mFooter = findViewById(R.id.folder_footer); |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 211 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 212 | // 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] | 213 | // we can allocate the appropriate amount of space for it. |
| 214 | int measureSpec = MeasureSpec.UNSPECIFIED; |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 215 | mFooter.measure(measureSpec, measureSpec); |
| 216 | mFooterHeight = mFooter.getMeasuredHeight(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 217 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 218 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 219 | private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { |
| 220 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | public void onDestroyActionMode(ActionMode mode) { |
| 229 | } |
| 230 | |
| 231 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 232 | return false; |
| 233 | } |
| 234 | }; |
| 235 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 236 | public void onClick(View v) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 237 | Object tag = v.getTag(); |
| 238 | if (tag instanceof ShortcutInfo) { |
Adam Cohen | b5fe60c | 2013-06-06 22:03:51 -0700 | [diff] [blame] | 239 | mLauncher.onClick(v); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 240 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | public boolean onLongClick(View v) { |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 244 | // Return if global dragging is not enabled |
| 245 | if (!mLauncher.isDraggingEnabled()) return true; |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 246 | return beginDrag(v, false); |
| 247 | } |
Winson Chung | 36a62fe | 2012-05-06 18:04:42 -0700 | [diff] [blame] | 248 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 249 | private boolean beginDrag(View v, boolean accessible) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 250 | Object tag = v.getTag(); |
| 251 | if (tag instanceof ShortcutInfo) { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 252 | ShortcutInfo item = (ShortcutInfo) tag; |
| 253 | if (!v.isInTouchMode()) { |
| 254 | return false; |
| 255 | } |
| 256 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 257 | mLauncher.getWorkspace().beginDragShared(v, new Point(), this, accessible); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 258 | |
| 259 | mCurrentDragInfo = item; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 260 | mEmptyCellRank = item.rank; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 261 | mCurrentDragView = v; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 262 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 263 | mContent.removeItem(mCurrentDragView); |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 264 | mInfo.remove(mCurrentDragInfo); |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 265 | mDragInProgress = true; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 266 | mItemAddedBackToSelfViaIcon = false; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 267 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 268 | return true; |
| 269 | } |
| 270 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 271 | @Override |
| 272 | public void startDrag(CellInfo cellInfo, boolean accessible) { |
| 273 | beginDrag(cellInfo.cell, accessible); |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void enableAccessibleDrag(boolean enable) { |
| 278 | mLauncher.getSearchBar().enableAccessibleDrag(enable); |
| 279 | for (int i = 0; i < mContent.getChildCount(); i++) { |
| 280 | mContent.getPageAt(i).enableAccessibleDrag(enable, CellLayout.FOLDER_ACCESSIBILITY_DRAG); |
| 281 | } |
Sunny Goyal | ccc414b | 2015-04-30 12:28:16 -0700 | [diff] [blame] | 282 | |
| 283 | mFooter.setImportantForAccessibility(enable ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS : |
| 284 | IMPORTANT_FOR_ACCESSIBILITY_AUTO); |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 285 | mLauncher.getWorkspace().setAddNewPageOnDrag(!enable); |
| 286 | } |
| 287 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 288 | public boolean isEditingName() { |
| 289 | return mIsEditingName; |
| 290 | } |
| 291 | |
| 292 | public void startEditingFolderName() { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 293 | mFolderName.setHint(""); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 294 | mIsEditingName = true; |
| 295 | } |
| 296 | |
| 297 | public void dismissEditingName() { |
| 298 | mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); |
| 299 | doneEditingFolderName(true); |
| 300 | } |
| 301 | |
| 302 | public void doneEditingFolderName(boolean commit) { |
Adam Cohen | a65beee | 2011-06-27 21:32:23 -0700 | [diff] [blame] | 303 | mFolderName.setHint(sHintText); |
Adam Cohen | 1df26a3 | 2011-08-12 16:15:23 -0700 | [diff] [blame] | 304 | // Convert to a string here to ensure that no other state associated with the text field |
| 305 | // gets saved. |
Sunny Goyal | 230eade | 2015-06-18 12:48:51 -0700 | [diff] [blame] | 306 | String newTitle = mFolderName.getText().toString(); |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 307 | mInfo.setTitle(newTitle); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 308 | LauncherModel.updateItemInDatabase(mLauncher, mInfo); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 309 | |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 310 | if (commit) { |
| 311 | sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, |
Sunny Goyal | 230eade | 2015-06-18 12:48:51 -0700 | [diff] [blame] | 312 | String.format(getContext().getString(R.string.folder_renamed), newTitle)); |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 313 | } |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 314 | // In order to clear the focus from the text field, we set the focus on ourself. This |
| 315 | // ensures that every time the field is clicked, focus is gained, giving reliable behavior. |
| 316 | requestFocus(); |
| 317 | |
Adam Cohen | e601a43 | 2011-07-26 21:51:30 -0700 | [diff] [blame] | 318 | Selection.setSelection((Spannable) mFolderName.getText(), 0, 0); |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 319 | mIsEditingName = false; |
| 320 | } |
| 321 | |
| 322 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
| 323 | if (actionId == EditorInfo.IME_ACTION_DONE) { |
| 324 | dismissEditingName(); |
| 325 | return true; |
| 326 | } |
| 327 | return false; |
| 328 | } |
| 329 | |
| 330 | public View getEditTextRegion() { |
| 331 | return mFolderName; |
| 332 | } |
| 333 | |
Adam Cohen | 0c872ba | 2011-05-05 10:34:16 -0700 | [diff] [blame] | 334 | /** |
| 335 | * We need to handle touch events to prevent them from falling through to the workspace below. |
| 336 | */ |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 337 | @SuppressLint("ClickableViewAccessibility") |
Adam Cohen | 0c872ba | 2011-05-05 10:34:16 -0700 | [diff] [blame] | 338 | @Override |
| 339 | public boolean onTouchEvent(MotionEvent ev) { |
| 340 | return true; |
| 341 | } |
| 342 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 343 | public void setDragController(DragController dragController) { |
| 344 | mDragController = dragController; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 347 | public void setFolderIcon(FolderIcon icon) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 348 | mFolderIcon = icon; |
| 349 | } |
| 350 | |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 351 | @Override |
| 352 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 353 | // When the folder gets focus, we don't want to announce the list of items. |
| 354 | return true; |
| 355 | } |
| 356 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 357 | /** |
| 358 | * @return the FolderInfo object associated with this folder |
| 359 | */ |
Sunny Goyal | 83a8f04 | 2015-05-19 12:52:12 -0700 | [diff] [blame] | 360 | public FolderInfo getInfo() { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 361 | return mInfo; |
| 362 | } |
| 363 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 364 | void bind(FolderInfo info) { |
| 365 | mInfo = info; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 366 | ArrayList<ShortcutInfo> children = info.contents; |
Sunny Goyal | 1dd0f8b | 2015-07-06 13:04:02 -0700 | [diff] [blame] | 367 | Collections.sort(children, ITEM_POS_COMPARATOR); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 368 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 369 | ArrayList<ShortcutInfo> overflow = mContent.bindItems(children); |
Adam Cohen | 0057bbc | 2011-08-12 18:30:51 -0700 | [diff] [blame] | 370 | |
Jason Monk | 4ff7388 | 2014-04-24 16:48:07 -0400 | [diff] [blame] | 371 | // 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] | 372 | // when upgrading from the old Folders implementation which could contain an unlimited |
| 373 | // number of items. |
| 374 | for (ShortcutInfo item: overflow) { |
| 375 | mInfo.remove(item); |
| 376 | LauncherModel.deleteItemFromDatabase(mLauncher, item); |
| 377 | } |
| 378 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 379 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
| 380 | if (lp == null) { |
| 381 | lp = new DragLayer.LayoutParams(0, 0); |
| 382 | lp.customPosition = true; |
| 383 | setLayoutParams(lp); |
| 384 | } |
| 385 | centerAboutIcon(); |
| 386 | |
Adam Cohen | 4dbe6d9 | 2011-05-18 17:14:15 -0700 | [diff] [blame] | 387 | mItemsInvalidated = true; |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 388 | updateTextViewFocus(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 389 | mInfo.addListener(this); |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 390 | |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 391 | if (!sDefaultFolderName.contentEquals(mInfo.title)) { |
Adam Cohen | 4ef610f | 2011-06-21 22:37:36 -0700 | [diff] [blame] | 392 | mFolderName.setText(mInfo.title); |
| 393 | } else { |
| 394 | mFolderName.setText(""); |
| 395 | } |
Winson Chung | 33231f5 | 2013-12-09 16:57:45 -0800 | [diff] [blame] | 396 | |
| 397 | // In case any children didn't come across during loading, clean up the folder accordingly |
| 398 | mFolderIcon.post(new Runnable() { |
| 399 | public void run() { |
| 400 | if (getItemCount() <= 1) { |
| 401 | replaceFolderWithFinalItem(); |
| 402 | } |
| 403 | } |
| 404 | }); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Creates a new UserFolder, inflated from R.layout.user_folder. |
| 409 | * |
| 410 | * @param context The application's context. |
| 411 | * |
| 412 | * @return A new UserFolder. |
| 413 | */ |
Sunny Goyal | c23da84 | 2015-05-14 20:44:01 -0700 | [diff] [blame] | 414 | @SuppressLint("InflateParams") |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 415 | static Folder fromXml(Launcher launcher) { |
Sunny Goyal | c23da84 | 2015-05-14 20:44:01 -0700 | [diff] [blame] | 416 | return (Folder) launcher.getLayoutInflater().inflate(R.layout.user_folder, null); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /** |
| 420 | * This method is intended to make the UserFolder to be visually identical in size and position |
| 421 | * to its associated FolderIcon. This allows for a seamless transition into the expanded state. |
| 422 | */ |
| 423 | private void positionAndSizeAsIcon() { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 424 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | 662b598 | 2011-12-13 17:45:21 -0800 | [diff] [blame] | 425 | setScaleX(0.8f); |
| 426 | setScaleY(0.8f); |
| 427 | setAlpha(0f); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 428 | mState = STATE_SMALL; |
| 429 | } |
| 430 | |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 431 | private void prepareReveal() { |
| 432 | setScaleX(1f); |
| 433 | setScaleY(1f); |
| 434 | setAlpha(1f); |
| 435 | mState = STATE_SMALL; |
| 436 | } |
| 437 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 438 | public void animateOpen() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 439 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | 6441de0 | 2011-12-14 14:25:32 -0800 | [diff] [blame] | 440 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 441 | mContent.completePendingPageChanges(); |
Sunny Goyal | 8167dc2 | 2015-04-27 13:44:01 -0700 | [diff] [blame] | 442 | if (!mDragInProgress) { |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 443 | // Open on the first page. |
| 444 | mContent.snapToPageImmediately(0); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 447 | Animator openFolderAnim = null; |
| 448 | final Runnable onCompleteRunnable; |
Kenny Guy | d794a3f | 2014-09-16 15:17:58 +0100 | [diff] [blame] | 449 | if (!Utilities.isLmpOrAbove()) { |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 450 | positionAndSizeAsIcon(); |
| 451 | centerAboutIcon(); |
| 452 | |
| 453 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1); |
| 454 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); |
| 455 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); |
| 456 | final ObjectAnimator oa = |
| 457 | LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); |
| 458 | oa.setDuration(mExpandDuration); |
| 459 | openFolderAnim = oa; |
| 460 | |
| 461 | setLayerType(LAYER_TYPE_HARDWARE, null); |
| 462 | onCompleteRunnable = new Runnable() { |
| 463 | @Override |
| 464 | public void run() { |
| 465 | setLayerType(LAYER_TYPE_NONE, null); |
| 466 | } |
| 467 | }; |
| 468 | } else { |
| 469 | prepareReveal(); |
| 470 | centerAboutIcon(); |
| 471 | |
Sunny Goyal | 2245fa2 | 2015-07-06 11:45:18 -0700 | [diff] [blame] | 472 | AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 473 | int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); |
| 474 | int height = getFolderHeight(); |
| 475 | |
| 476 | float transX = - 0.075f * (width / 2 - getPivotX()); |
| 477 | float transY = - 0.075f * (height / 2 - getPivotY()); |
| 478 | setTranslationX(transX); |
| 479 | setTranslationY(transY); |
| 480 | PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, 0); |
| 481 | PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, 0); |
| 482 | |
Sunny Goyal | 2245fa2 | 2015-07-06 11:45:18 -0700 | [diff] [blame] | 483 | Animator drift = ObjectAnimator.ofPropertyValuesHolder(this, tx, ty); |
Sunny Goyal | 75deaf3 | 2015-05-07 16:13:12 -0700 | [diff] [blame] | 484 | drift.setDuration(mMaterialExpandDuration); |
| 485 | drift.setStartDelay(mMaterialExpandStagger); |
| 486 | drift.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 487 | |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 488 | int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX()); |
| 489 | int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY()); |
Sunny Goyal | f7a29e8 | 2015-04-24 15:20:43 -0700 | [diff] [blame] | 490 | float radius = (float) Math.hypot(rx, ry); |
Sunny Goyal | 75deaf3 | 2015-05-07 16:13:12 -0700 | [diff] [blame] | 491 | |
Sunny Goyal | 2245fa2 | 2015-07-06 11:45:18 -0700 | [diff] [blame] | 492 | Animator reveal = UiThreadCircularReveal.createCircularReveal(this, (int) getPivotX(), |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 493 | (int) getPivotY(), 0, radius); |
| 494 | reveal.setDuration(mMaterialExpandDuration); |
| 495 | reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); |
| 496 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 497 | mContentWrapper.setAlpha(0f); |
Sunny Goyal | 2245fa2 | 2015-07-06 11:45:18 -0700 | [diff] [blame] | 498 | Animator iconsAlpha = ObjectAnimator.ofFloat(mContentWrapper, "alpha", 0f, 1f); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 499 | iconsAlpha.setDuration(mMaterialExpandDuration); |
| 500 | iconsAlpha.setStartDelay(mMaterialExpandStagger); |
| 501 | iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 502 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 503 | mFooter.setAlpha(0f); |
Sunny Goyal | 2245fa2 | 2015-07-06 11:45:18 -0700 | [diff] [blame] | 504 | Animator textAlpha = ObjectAnimator.ofFloat(mFooter, "alpha", 0f, 1f); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 505 | textAlpha.setDuration(mMaterialExpandDuration); |
| 506 | textAlpha.setStartDelay(mMaterialExpandStagger); |
| 507 | textAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); |
| 508 | |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 509 | anim.play(drift); |
| 510 | anim.play(iconsAlpha); |
| 511 | anim.play(textAlpha); |
| 512 | anim.play(reveal); |
| 513 | |
| 514 | openFolderAnim = anim; |
| 515 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 516 | mContentWrapper.setLayerType(LAYER_TYPE_HARDWARE, null); |
Sunny Goyal | 75deaf3 | 2015-05-07 16:13:12 -0700 | [diff] [blame] | 517 | mFooter.setLayerType(LAYER_TYPE_HARDWARE, null); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 518 | onCompleteRunnable = new Runnable() { |
| 519 | @Override |
| 520 | public void run() { |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 521 | mContentWrapper.setLayerType(LAYER_TYPE_NONE, null); |
Sunny Goyal | 75deaf3 | 2015-05-07 16:13:12 -0700 | [diff] [blame] | 522 | mContentWrapper.setLayerType(LAYER_TYPE_NONE, null); |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 523 | } |
| 524 | }; |
| 525 | } |
| 526 | openFolderAnim.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 527 | @Override |
| 528 | public void onAnimationStart(Animator animation) { |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 529 | sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 530 | mContent.getAccessibilityDescription()); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 531 | mState = STATE_ANIMATING; |
| 532 | } |
| 533 | @Override |
| 534 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 535 | mState = STATE_OPEN; |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 536 | |
| 537 | if (onCompleteRunnable != null) { |
| 538 | onCompleteRunnable.run(); |
| 539 | } |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 540 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 541 | mContent.setFocusOnFirstChild(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 542 | } |
| 543 | }); |
Sunny Goyal | b7e15ad | 2015-05-07 14:51:31 -0700 | [diff] [blame] | 544 | |
| 545 | // Footer animation |
| 546 | if (mContent.getPageCount() > 1 && !mInfo.hasOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION)) { |
| 547 | int footerWidth = mContent.getDesiredWidth() |
| 548 | - mFooter.getPaddingLeft() - mFooter.getPaddingRight(); |
| 549 | |
| 550 | float textWidth = mFolderName.getPaint().measureText(mFolderName.getText().toString()); |
Sunny Goyal | a07c2f5 | 2015-06-01 11:00:38 -0700 | [diff] [blame] | 551 | float translation = (footerWidth - textWidth) / 2; |
| 552 | mFolderName.setTranslationX(mContent.mIsRtl ? -translation : translation); |
Sunny Goyal | b7e15ad | 2015-05-07 14:51:31 -0700 | [diff] [blame] | 553 | mContent.setMarkerScale(0); |
| 554 | |
| 555 | // Do not update the flag if we are in drag mode. The flag will be updated, when we |
| 556 | // actually drop the icon. |
| 557 | final boolean updateAnimationFlag = !mDragInProgress; |
| 558 | openFolderAnim.addListener(new AnimatorListenerAdapter() { |
| 559 | |
| 560 | @Override |
| 561 | public void onAnimationEnd(Animator animation) { |
Sunny Goyal | a07c2f5 | 2015-06-01 11:00:38 -0700 | [diff] [blame] | 562 | mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION) |
| 563 | .translationX(0) |
Sunny Goyal | c1cd23b | 2015-06-01 17:15:34 -0700 | [diff] [blame] | 564 | .setInterpolator(Utilities.isLmpOrAbove() ? |
| 565 | AnimationUtils.loadInterpolator(mLauncher, |
| 566 | android.R.interpolator.fast_out_slow_in) |
| 567 | : new LogDecelerateInterpolator(100, 0)); |
Sunny Goyal | b7e15ad | 2015-05-07 14:51:31 -0700 | [diff] [blame] | 568 | mContent.animateMarkers(); |
| 569 | |
| 570 | if (updateAnimationFlag) { |
| 571 | mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher); |
| 572 | } |
| 573 | } |
| 574 | }); |
| 575 | } else { |
| 576 | mFolderName.setTranslationX(0); |
| 577 | mContent.setMarkerScale(1); |
| 578 | } |
| 579 | |
Adam Cohen | c4fe9ea | 2014-08-18 18:54:10 -0700 | [diff] [blame] | 580 | openFolderAnim.start(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 581 | |
| 582 | // Make sure the folder picks up the last drag move even if the finger doesn't move. |
| 583 | if (mDragController.isDragging()) { |
| 584 | mDragController.forceTouchMove(); |
| 585 | } |
Sunny Goyal | 34b6527 | 2015-03-11 16:56:52 -0700 | [diff] [blame] | 586 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 587 | FolderPagedView pages = (FolderPagedView) mContent; |
| 588 | pages.verifyVisibleHighResIcons(pages.getNextPage()); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | public void beginExternalDrag(ShortcutInfo item) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 592 | mCurrentDragInfo = item; |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 593 | mEmptyCellRank = mContent.allocateRankForNewItem(item); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 594 | mIsExternalDrag = true; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 595 | mDragInProgress = true; |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 596 | |
Sunny Goyal | f406615 | 2015-04-15 09:42:19 -0700 | [diff] [blame] | 597 | // Since this folder opened by another controller, it might not get onDrop or |
| 598 | // onDropComplete. Perform cleanup once drag-n-drop ends. |
| 599 | mDragController.addDragListener(this); |
| 600 | } |
| 601 | |
| 602 | @Override |
| 603 | public void onDragStart(DragSource source, Object info, int dragAction) { } |
| 604 | |
| 605 | @Override |
| 606 | public void onDragEnd() { |
| 607 | if (mIsExternalDrag && mDragInProgress) { |
| 608 | completeDragExit(); |
| 609 | } |
| 610 | mDragController.removeDragListener(this); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 613 | @Thunk void sendCustomAccessibilityEvent(int type, String text) { |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 614 | AccessibilityManager accessibilityManager = (AccessibilityManager) |
| 615 | getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 616 | if (accessibilityManager.isEnabled()) { |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 617 | AccessibilityEvent event = AccessibilityEvent.obtain(type); |
| 618 | onInitializeAccessibilityEvent(event); |
| 619 | event.getText().add(text); |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 620 | accessibilityManager.sendAccessibilityEvent(event); |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 624 | public void animateClosed() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 625 | if (!(getParent() instanceof DragLayer)) return; |
Adam Cohen | 662b598 | 2011-12-13 17:45:21 -0800 | [diff] [blame] | 626 | PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); |
| 627 | PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f); |
| 628 | PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f); |
Michael Jurka | 032e6ba | 2013-04-22 15:08:42 +0200 | [diff] [blame] | 629 | final ObjectAnimator oa = |
Michael Jurka | 2ecf995 | 2012-06-18 12:52:28 -0700 | [diff] [blame] | 630 | LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 631 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 632 | oa.addListener(new AnimatorListenerAdapter() { |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 633 | @Override |
| 634 | public void onAnimationEnd(Animator animation) { |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 635 | onCloseComplete(); |
Michael Jurka | 0121c3e | 2012-05-31 08:36:04 -0700 | [diff] [blame] | 636 | setLayerType(LAYER_TYPE_NONE, null); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 637 | mState = STATE_SMALL; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 638 | } |
| 639 | @Override |
| 640 | public void onAnimationStart(Animator animation) { |
Adam Cohen | 3371da0 | 2011-10-25 21:38:29 -0700 | [diff] [blame] | 641 | sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 642 | getContext().getString(R.string.folder_closed)); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 643 | mState = STATE_ANIMATING; |
| 644 | } |
| 645 | }); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 646 | oa.setDuration(mExpandDuration); |
Michael Jurka | 0121c3e | 2012-05-31 08:36:04 -0700 | [diff] [blame] | 647 | setLayerType(LAYER_TYPE_HARDWARE, null); |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 648 | oa.start(); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 651 | public boolean acceptDrop(DragObject d) { |
| 652 | final ItemInfo item = (ItemInfo) d.dragInfo; |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 653 | final int itemType = item.itemType; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 654 | return ((itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || |
| 655 | itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) && |
| 656 | !isFull()); |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 659 | public void onDragEnter(DragObject d) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 660 | mPrevTargetRank = -1; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 661 | mOnExitAlarm.cancelAlarm(); |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 662 | // Get the area offset such that the folder only closes if half the drag icon width |
| 663 | // is outside the folder area |
| 664 | mScrollAreaOffset = d.dragView.getDragRegionWidth() / 2 - d.xOffset; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | OnAlarmListener mReorderAlarmListener = new OnAlarmListener() { |
| 668 | public void onAlarm(Alarm alarm) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 669 | mContent.realTimeReorder(mEmptyCellRank, mTargetRank); |
| 670 | mEmptyCellRank = mTargetRank; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 671 | } |
| 672 | }; |
| 673 | |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 674 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
Adam Cohen | 2374abf | 2013-04-16 14:56:57 -0700 | [diff] [blame] | 675 | public boolean isLayoutRtl() { |
| 676 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 677 | } |
| 678 | |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 679 | @Override |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 680 | public void onDragOver(DragObject d) { |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 681 | onDragOver(d, REORDER_DELAY); |
| 682 | } |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 683 | |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 684 | private int getTargetRank(DragObject d, float[] recycle) { |
| 685 | recycle = d.getVisualCenter(recycle); |
| 686 | return mContent.findNearestArea( |
| 687 | (int) recycle[0] - getPaddingLeft(), (int) recycle[1] - getPaddingTop()); |
| 688 | } |
| 689 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 690 | @Thunk void onDragOver(DragObject d, int reorderDelay) { |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 691 | if (mScrollPauseAlarm.alarmPending()) { |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 692 | return; |
| 693 | } |
| 694 | final float[] r = new float[2]; |
| 695 | mTargetRank = getTargetRank(d, r); |
| 696 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 697 | if (mTargetRank != mPrevTargetRank) { |
Alan Viverette | 4cda5b7 | 2013-08-28 17:53:41 -0700 | [diff] [blame] | 698 | mReorderAlarm.cancelAlarm(); |
Sunny Goyal | c46bfef | 2015-01-05 12:40:08 -0800 | [diff] [blame] | 699 | mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); |
| 700 | mReorderAlarm.setAlarm(REORDER_DELAY); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 701 | mPrevTargetRank = mTargetRank; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 702 | } |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 703 | |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 704 | float x = r[0]; |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 705 | int currentPage = mContent.getNextPage(); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 706 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 707 | float cellOverlap = mContent.getCurrentCellLayout().getCellWidth() |
Sunny Goyal | 3b0883f | 2015-04-07 09:27:07 -0700 | [diff] [blame] | 708 | * ICON_OVERSCROLL_WIDTH_FACTOR; |
| 709 | boolean isOutsideLeftEdge = x < cellOverlap; |
| 710 | boolean isOutsideRightEdge = x > (getWidth() - cellOverlap); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 711 | |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 712 | if (currentPage > 0 && (mContent.mIsRtl ? isOutsideRightEdge : isOutsideLeftEdge)) { |
Sunny Goyal | 3b0883f | 2015-04-07 09:27:07 -0700 | [diff] [blame] | 713 | showScrollHint(DragController.SCROLL_LEFT, d); |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 714 | } else if (currentPage < (mContent.getPageCount() - 1) |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 715 | && (mContent.mIsRtl ? isOutsideLeftEdge : isOutsideRightEdge)) { |
Sunny Goyal | 3b0883f | 2015-04-07 09:27:07 -0700 | [diff] [blame] | 716 | showScrollHint(DragController.SCROLL_RIGHT, d); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 717 | } else { |
| 718 | mOnScrollHintAlarm.cancelAlarm(); |
| 719 | if (mScrollHintDir != DragController.SCROLL_NONE) { |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 720 | mContent.clearScrollHint(); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 721 | mScrollHintDir = DragController.SCROLL_NONE; |
| 722 | } |
| 723 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Sunny Goyal | 3b0883f | 2015-04-07 09:27:07 -0700 | [diff] [blame] | 726 | private void showScrollHint(int direction, DragObject d) { |
| 727 | // Show scroll hint on the right |
| 728 | if (mScrollHintDir != direction) { |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 729 | mContent.showScrollHint(direction); |
Sunny Goyal | 3b0883f | 2015-04-07 09:27:07 -0700 | [diff] [blame] | 730 | mScrollHintDir = direction; |
| 731 | } |
| 732 | |
| 733 | // Set alarm for when the hint is complete |
| 734 | if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != direction) { |
| 735 | mCurrentScrollDir = direction; |
| 736 | mOnScrollHintAlarm.cancelAlarm(); |
| 737 | mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d)); |
| 738 | mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION); |
| 739 | |
| 740 | mReorderAlarm.cancelAlarm(); |
| 741 | mTargetRank = mEmptyCellRank; |
| 742 | } |
| 743 | } |
| 744 | |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 745 | OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() { |
| 746 | public void onAlarm(Alarm alarm) { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 747 | completeDragExit(); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 748 | } |
| 749 | }; |
| 750 | |
Adam Cohen | 95bb800 | 2011-07-03 23:40:28 -0700 | [diff] [blame] | 751 | public void completeDragExit() { |
Sunny Goyal | f406615 | 2015-04-15 09:42:19 -0700 | [diff] [blame] | 752 | if (mInfo.opened) { |
| 753 | mLauncher.closeFolder(); |
| 754 | mRearrangeOnClose = true; |
Sunny Goyal | 31abc29 | 2015-05-01 10:42:32 -0700 | [diff] [blame] | 755 | } else if (mState == STATE_ANIMATING) { |
| 756 | mRearrangeOnClose = true; |
Sunny Goyal | f406615 | 2015-04-15 09:42:19 -0700 | [diff] [blame] | 757 | } else { |
| 758 | rearrangeChildren(); |
Sunny Goyal | 31abc29 | 2015-05-01 10:42:32 -0700 | [diff] [blame] | 759 | clearDragInfo(); |
Sunny Goyal | f406615 | 2015-04-15 09:42:19 -0700 | [diff] [blame] | 760 | } |
Sunny Goyal | 31abc29 | 2015-05-01 10:42:32 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | private void clearDragInfo() { |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 764 | mCurrentDragInfo = null; |
| 765 | mCurrentDragView = null; |
| 766 | mSuppressOnAdd = false; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 767 | mIsExternalDrag = false; |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 770 | public void onDragExit(DragObject d) { |
Mindy DelliCarpini | 53b8d07 | 2013-07-03 08:23:13 -0700 | [diff] [blame] | 771 | // We only close the folder if this is a true drag exit, ie. not because |
| 772 | // a drop has occurred above the folder. |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 773 | if (!d.dragComplete) { |
| 774 | mOnExitAlarm.setOnAlarmListener(mOnExitAlarmListener); |
| 775 | mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY); |
| 776 | } |
| 777 | mReorderAlarm.cancelAlarm(); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 778 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 779 | mOnScrollHintAlarm.cancelAlarm(); |
| 780 | mScrollPauseAlarm.cancelAlarm(); |
| 781 | if (mScrollHintDir != DragController.SCROLL_NONE) { |
| 782 | mContent.clearScrollHint(); |
| 783 | mScrollHintDir = DragController.SCROLL_NONE; |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 784 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Sunny Goyal | e9b651e | 2015-04-24 11:44:51 -0700 | [diff] [blame] | 787 | /** |
| 788 | * When performing an accessibility drop, onDrop is sent immediately after onDragEnter. So we |
| 789 | * need to complete all transient states based on timers. |
| 790 | */ |
| 791 | @Override |
| 792 | public void prepareAccessibilityDrop() { |
| 793 | if (mReorderAlarm.alarmPending()) { |
| 794 | mReorderAlarm.cancelAlarm(); |
| 795 | mReorderAlarmListener.onAlarm(mReorderAlarm); |
| 796 | } |
| 797 | } |
| 798 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 799 | public void onDropCompleted(final View target, final DragObject d, |
| 800 | final boolean isFlingToDelete, final boolean success) { |
| 801 | if (mDeferDropAfterUninstall) { |
Michael Jurka | f300758 | 2013-08-21 14:33:57 +0200 | [diff] [blame] | 802 | Log.d(TAG, "Deferred handling drop because waiting for uninstall."); |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 803 | mDeferredAction = new Runnable() { |
| 804 | public void run() { |
| 805 | onDropCompleted(target, d, isFlingToDelete, success); |
| 806 | mDeferredAction = null; |
| 807 | } |
| 808 | }; |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | boolean beingCalledAfterUninstall = mDeferredAction != null; |
| 813 | boolean successfulDrop = |
| 814 | success && (!beingCalledAfterUninstall || mUninstallSuccessful); |
Winson Chung | 5f8afe6 | 2013-08-12 16:19:28 -0700 | [diff] [blame] | 815 | |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 816 | if (successfulDrop) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 817 | if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) { |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 818 | replaceFolderWithFinalItem(); |
| 819 | } |
| 820 | } else { |
| 821 | // The drag failed, we need to return the item to the folder |
Sunny Goyal | b8c663c | 2015-04-23 11:43:48 -0700 | [diff] [blame] | 822 | ShortcutInfo info = (ShortcutInfo) d.dragInfo; |
| 823 | View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info) |
| 824 | ? mCurrentDragView : mContent.createNewView(info); |
| 825 | ArrayList<View> views = getItemsInReadingOrder(); |
| 826 | views.add(info.rank, icon); |
| 827 | mContent.arrangeChildren(views, views.size()); |
| 828 | mItemsInvalidated = true; |
| 829 | |
| 830 | mSuppressOnAdd = true; |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 831 | mFolderIcon.onDrop(d); |
Sunny Goyal | b8c663c | 2015-04-23 11:43:48 -0700 | [diff] [blame] | 832 | mSuppressOnAdd = false; |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | if (target != this) { |
| 836 | if (mOnExitAlarm.alarmPending()) { |
| 837 | mOnExitAlarm.cancelAlarm(); |
Michael Jurka | 5455425 | 2013-08-01 12:52:23 +0200 | [diff] [blame] | 838 | if (!successfulDrop) { |
Adam Cohen | 7a8b82b | 2013-05-29 18:41:50 -0700 | [diff] [blame] | 839 | mSuppressFolderDeletion = true; |
| 840 | } |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 841 | mScrollPauseAlarm.cancelAlarm(); |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 842 | completeDragExit(); |
| 843 | } |
Adam Cohen | 9c58d82 | 2013-12-13 17:18:10 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 846 | mDeleteFolderOnDropCompleted = false; |
| 847 | mDragInProgress = false; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 848 | mItemAddedBackToSelfViaIcon = false; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 849 | mCurrentDragInfo = null; |
| 850 | mCurrentDragView = null; |
| 851 | mSuppressOnAdd = false; |
Adam Cohen | 4045eb7 | 2011-10-06 11:44:26 -0700 | [diff] [blame] | 852 | |
| 853 | // Reordering may have occured, and we need to save the new item locations. We do this once |
| 854 | // at the end to prevent unnecessary database operations. |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 855 | updateItemLocationsInDatabaseBatch(); |
Sunny Goyal | b7e15ad | 2015-05-07 14:51:31 -0700 | [diff] [blame] | 856 | |
| 857 | // Use the item count to check for multi-page as the folder UI may not have |
| 858 | // been refreshed yet. |
| 859 | if (getItemCount() <= mContent.itemsPerPage()) { |
| 860 | // Show the animation, next time something is added to the folder. |
| 861 | mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, false, mLauncher); |
| 862 | } |
| 863 | |
Adam Cohen | 4045eb7 | 2011-10-06 11:44:26 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 866 | @Override |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 867 | public void deferCompleteDropAfterUninstallActivity() { |
| 868 | mDeferDropAfterUninstall = true; |
| 869 | } |
| 870 | |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 871 | @Override |
Michael Jurka | 1e2f465 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 872 | public void onUninstallActivityReturned(boolean success) { |
| 873 | mDeferDropAfterUninstall = false; |
| 874 | mUninstallSuccessful = success; |
| 875 | if (mDeferredAction != null) { |
| 876 | mDeferredAction.run(); |
| 877 | } |
| 878 | } |
| 879 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 880 | @Override |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 881 | public float getIntrinsicIconScaleFactor() { |
| 882 | return 1f; |
| 883 | } |
| 884 | |
| 885 | @Override |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 886 | public boolean supportsFlingToDelete() { |
| 887 | return true; |
| 888 | } |
| 889 | |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 890 | @Override |
| 891 | public boolean supportsAppInfoDropTarget() { |
| 892 | return false; |
| 893 | } |
| 894 | |
| 895 | @Override |
| 896 | public boolean supportsDeleteDropTarget() { |
| 897 | return true; |
| 898 | } |
| 899 | |
Sunny Goyal | ddec734 | 2015-04-29 18:12:37 -0700 | [diff] [blame] | 900 | @Override |
| 901 | public void onFlingToDelete(DragObject d, PointF vec) { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 902 | // Do nothing |
| 903 | } |
| 904 | |
| 905 | @Override |
| 906 | public void onFlingToDeleteCompleted() { |
| 907 | // Do nothing |
| 908 | } |
| 909 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 910 | private void updateItemLocationsInDatabaseBatch() { |
| 911 | ArrayList<View> list = getItemsInReadingOrder(); |
| 912 | ArrayList<ItemInfo> items = new ArrayList<ItemInfo>(); |
| 913 | for (int i = 0; i < list.size(); i++) { |
| 914 | View v = list.get(i); |
| 915 | ItemInfo info = (ItemInfo) v.getTag(); |
Sunny Goyal | 08f7261 | 2015-01-05 13:41:43 -0800 | [diff] [blame] | 916 | info.rank = i; |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 917 | items.add(info); |
| 918 | } |
| 919 | |
| 920 | LauncherModel.moveItemsInDatabase(mLauncher, items, mInfo.id, 0); |
| 921 | } |
| 922 | |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 923 | public void addItemLocationsInDatabase() { |
| 924 | ArrayList<View> list = getItemsInReadingOrder(); |
| 925 | for (int i = 0; i < list.size(); i++) { |
| 926 | View v = list.get(i); |
| 927 | ItemInfo info = (ItemInfo) v.getTag(); |
| 928 | LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0, |
Winson Chung | 8f1eff7 | 2015-05-28 17:33:40 -0700 | [diff] [blame] | 929 | info.cellX, info.cellY); |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 930 | } |
| 931 | } |
| 932 | |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 933 | public void notifyDrop() { |
| 934 | if (mDragInProgress) { |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 935 | mItemAddedBackToSelfViaIcon = true; |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 936 | } |
Adam Cohen | df2cc41 | 2011-04-27 16:56:57 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | public boolean isDropEnabled() { |
| 940 | return true; |
| 941 | } |
| 942 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 943 | public boolean isFull() { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 944 | return mContent.isFull(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | private void centerAboutIcon() { |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 948 | DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 949 | |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 950 | DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 951 | int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 952 | int height = getFolderHeight(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 953 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 954 | float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, sTempRect); |
Adam Cohen | 8e776a6 | 2011-06-28 18:10:06 -0700 | [diff] [blame] | 955 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 956 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 957 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 958 | int centerX = (int) (sTempRect.left + sTempRect.width() * scale / 2); |
| 959 | int centerY = (int) (sTempRect.top + sTempRect.height() * scale / 2); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 960 | int centeredLeft = centerX - width / 2; |
| 961 | int centeredTop = centerY - height / 2; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 962 | |
Sunny Goyal | 41d8417 | 2015-07-08 23:28:51 -0700 | [diff] [blame^] | 963 | // We need to bound the folder to the currently visible workspace area |
| 964 | mLauncher.getWorkspace().getPageAreaRelativeToDragLayer(sTempRect); |
| 965 | int left = Math.min(Math.max(sTempRect.left, centeredLeft), |
| 966 | sTempRect.left + sTempRect.width() - width); |
| 967 | int top = Math.min(Math.max(sTempRect.top, centeredTop), |
| 968 | sTempRect.top + sTempRect.height() - height); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 969 | if (grid.isPhone && (grid.availableWidthPx - width) < grid.iconSizePx) { |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 970 | // Center the folder if it is full (on phones only) |
| 971 | left = (grid.availableWidthPx - width) / 2; |
Sunny Goyal | 41d8417 | 2015-07-08 23:28:51 -0700 | [diff] [blame^] | 972 | } else if (width >= sTempRect.width()) { |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 973 | // If the folder doesn't fit within the bounds, center it about the desired bounds |
Sunny Goyal | 41d8417 | 2015-07-08 23:28:51 -0700 | [diff] [blame^] | 974 | left = sTempRect.left + (sTempRect.width() - width) / 2; |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 975 | } |
Sunny Goyal | 41d8417 | 2015-07-08 23:28:51 -0700 | [diff] [blame^] | 976 | if (height >= sTempRect.height()) { |
| 977 | top = sTempRect.top + (sTempRect.height() - height) / 2; |
Adam Cohen | 0e4857c | 2011-06-30 17:05:14 -0700 | [diff] [blame] | 978 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 979 | |
| 980 | int folderPivotX = width / 2 + (centeredLeft - left); |
| 981 | int folderPivotY = height / 2 + (centeredTop - top); |
| 982 | setPivotX(folderPivotX); |
| 983 | setPivotY(folderPivotY); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 984 | mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 985 | (1.0f * folderPivotX / width)); |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 986 | mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 987 | (1.0f * folderPivotY / height)); |
Adam Cohen | 3bf84d3 | 2012-05-07 20:17:14 -0700 | [diff] [blame] | 988 | |
Adam Cohen | 662b598 | 2011-12-13 17:45:21 -0800 | [diff] [blame] | 989 | lp.width = width; |
| 990 | lp.height = height; |
| 991 | lp.x = left; |
| 992 | lp.y = top; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Adam Cohen | 268c475 | 2012-06-06 17:47:33 -0700 | [diff] [blame] | 995 | float getPivotXForIconAnimation() { |
| 996 | return mFolderIconPivotX; |
| 997 | } |
| 998 | float getPivotYForIconAnimation() { |
| 999 | return mFolderIconPivotY; |
| 1000 | } |
| 1001 | |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1002 | private int getContentAreaHeight() { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 1003 | DeviceProfile grid = mLauncher.getDeviceProfile(); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 1004 | Rect workspacePadding = grid.getWorkspacePadding(mContent.mIsRtl); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1005 | int maxContentAreaHeight = grid.availableHeightPx - |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1006 | workspacePadding.top - workspacePadding.bottom - |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 1007 | mFooterHeight; |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 1008 | int height = Math.min(maxContentAreaHeight, |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1009 | mContent.getDesiredHeight()); |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 1010 | return Math.max(height, MIN_CONTENT_DIMEN); |
| 1011 | } |
| 1012 | |
| 1013 | private int getContentAreaWidth() { |
| 1014 | return Math.max(mContent.getDesiredWidth(), MIN_CONTENT_DIMEN); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 1017 | private int getFolderHeight() { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1018 | return getFolderHeight(getContentAreaHeight()); |
| 1019 | } |
| 1020 | |
| 1021 | private int getFolderHeight(int contentAreaHeight) { |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 1022 | return getPaddingTop() + getPaddingBottom() + contentAreaHeight + mFooterHeight; |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 1023 | } |
Adam Cohen | 234c4cd | 2011-07-17 21:03:04 -0700 | [diff] [blame] | 1024 | |
Adam Cohen | f0f4eda | 2013-06-06 21:27:03 -0700 | [diff] [blame] | 1025 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1026 | int contentWidth = getContentAreaWidth(); |
| 1027 | int contentHeight = getContentAreaHeight(); |
Adam Cohen | 1960ea4 | 2013-11-12 11:33:14 +0000 | [diff] [blame] | 1028 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1029 | int contentAreaWidthSpec = MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY); |
| 1030 | int contentAreaHeightSpec = MeasureSpec.makeMeasureSpec(contentHeight, MeasureSpec.EXACTLY); |
| 1031 | |
| 1032 | mContent.setFixedSize(contentWidth, contentHeight); |
| 1033 | mContentWrapper.measure(contentAreaWidthSpec, contentAreaHeightSpec); |
Sunny Goyal | a07c2f5 | 2015-06-01 11:00:38 -0700 | [diff] [blame] | 1034 | |
| 1035 | if (mContent.getChildCount() > 0) { |
| 1036 | int cellIconGap = (mContent.getPageAt(0).getCellWidth() |
| 1037 | - mLauncher.getDeviceProfile().iconSizePx) / 2; |
| 1038 | mFooter.setPadding(mContent.getPaddingLeft() + cellIconGap, |
| 1039 | mFooter.getPaddingTop(), |
| 1040 | mContent.getPaddingRight() + cellIconGap, |
| 1041 | mFooter.getPaddingBottom()); |
| 1042 | } |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 1043 | mFooter.measure(contentAreaWidthSpec, |
| 1044 | MeasureSpec.makeMeasureSpec(mFooterHeight, MeasureSpec.EXACTLY)); |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1045 | |
| 1046 | int folderWidth = getPaddingLeft() + getPaddingRight() + contentWidth; |
| 1047 | int folderHeight = getFolderHeight(contentHeight); |
| 1048 | setMeasuredDimension(folderWidth, folderHeight); |
Adam Cohen | 234c4cd | 2011-07-17 21:03:04 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1051 | /** |
| 1052 | * Rearranges the children based on their rank. |
| 1053 | */ |
| 1054 | public void rearrangeChildren() { |
| 1055 | rearrangeChildren(-1); |
| 1056 | } |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1057 | |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1058 | /** |
| 1059 | * Rearranges the children based on their rank. |
| 1060 | * @param itemCount if greater than the total children count, empty spaces are left at the end, |
| 1061 | * otherwise it is ignored. |
| 1062 | */ |
| 1063 | public void rearrangeChildren(int itemCount) { |
| 1064 | ArrayList<View> views = getItemsInReadingOrder(); |
| 1065 | mContent.arrangeChildren(views, Math.max(itemCount, views.size())); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1066 | mItemsInvalidated = true; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Sunny Goyal | c491835 | 2015-03-10 18:15:48 -0700 | [diff] [blame] | 1069 | // TODO remove this once GSA code fix is submitted |
| 1070 | public ViewGroup getContent() { |
| 1071 | return (ViewGroup) mContent; |
| 1072 | } |
| 1073 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1074 | public int getItemCount() { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1075 | return mContent.getItemCount(); |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 1078 | @Thunk void onCloseComplete() { |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 1079 | DragLayer parent = (DragLayer) getParent(); |
Michael Jurka | 5649c28 | 2012-06-18 10:33:21 -0700 | [diff] [blame] | 1080 | if (parent != null) { |
| 1081 | parent.removeView(this); |
| 1082 | } |
Adam Cohen | 4554ee1 | 2011-08-03 16:13:21 -0700 | [diff] [blame] | 1083 | mDragController.removeDropTarget((DropTarget) this); |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 1084 | clearFocus(); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1085 | mFolderIcon.requestFocus(); |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 1086 | |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1087 | if (mRearrangeOnClose) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1088 | rearrangeChildren(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1089 | mRearrangeOnClose = false; |
| 1090 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1091 | if (getItemCount() <= 1) { |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 1092 | if (!mDragInProgress && !mSuppressFolderDeletion) { |
| 1093 | replaceFolderWithFinalItem(); |
| 1094 | } else if (mDragInProgress) { |
| 1095 | mDeleteFolderOnDropCompleted = true; |
| 1096 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1097 | } |
Adam Cohen | 67bd9cc | 2011-07-29 14:07:04 -0700 | [diff] [blame] | 1098 | mSuppressFolderDeletion = false; |
Sunny Goyal | 31abc29 | 2015-05-01 10:42:32 -0700 | [diff] [blame] | 1099 | clearDragInfo(); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 1102 | @Thunk void replaceFolderWithFinalItem() { |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1103 | // 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] | 1104 | Runnable onCompleteRunnable = new Runnable() { |
| 1105 | @Override |
| 1106 | public void run() { |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1107 | CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1108 | |
Winson Chung | 33231f5 | 2013-12-09 16:57:45 -0800 | [diff] [blame] | 1109 | View child = null; |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 1110 | // Move the item from the folder to the workspace, in the position of the folder |
| 1111 | if (getItemCount() == 1) { |
| 1112 | ShortcutInfo finalItem = mInfo.contents.get(0); |
Sunny Goyal | dfaccf6 | 2015-05-11 16:30:44 -0700 | [diff] [blame] | 1113 | child = mLauncher.createShortcut(cellLayout, finalItem); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 1114 | LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container, |
Adam Cohen | dcd297f | 2013-06-18 13:13:40 -0700 | [diff] [blame] | 1115 | mInfo.screenId, mInfo.cellX, mInfo.cellY); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 1116 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 1117 | if (getItemCount() <= 1) { |
| 1118 | // Remove the folder |
| 1119 | LauncherModel.deleteItemFromDatabase(mLauncher, mInfo); |
Dan Sandler | 0eb687f | 2014-01-10 13:24:55 -0500 | [diff] [blame] | 1120 | if (cellLayout != null) { |
| 1121 | // b/12446428 -- sometimes the cell layout has already gone away? |
| 1122 | cellLayout.removeView(mFolderIcon); |
| 1123 | } |
Adam Cohen | 487f7dd | 2012-06-28 18:12:10 -0700 | [diff] [blame] | 1124 | if (mFolderIcon instanceof DropTarget) { |
| 1125 | mDragController.removeDropTarget((DropTarget) mFolderIcon); |
| 1126 | } |
| 1127 | mLauncher.removeFolder(mInfo); |
| 1128 | } |
Adam Cohen | c5e63f3 | 2012-07-12 16:16:57 -0700 | [diff] [blame] | 1129 | // 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] | 1130 | // the same time in the CellLayout. We need to add the new item with addInScreenFromBind() |
| 1131 | // to ensure that hotseat items are placed correctly. |
Adam Cohen | c5e63f3 | 2012-07-12 16:16:57 -0700 | [diff] [blame] | 1132 | if (child != null) { |
Winson Chung | 0e6a713 | 2013-08-23 12:55:10 -0700 | [diff] [blame] | 1133 | mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId, |
Adam Cohen | c5e63f3 | 2012-07-12 16:16:57 -0700 | [diff] [blame] | 1134 | mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); |
| 1135 | } |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 1136 | } |
| 1137 | }; |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1138 | View finalChild = mContent.getLastItem(); |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 1139 | if (finalChild != null) { |
| 1140 | mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable); |
Winson Chung | 33231f5 | 2013-12-09 16:57:45 -0800 | [diff] [blame] | 1141 | } else { |
| 1142 | onCompleteRunnable.run(); |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1143 | } |
Adam Cohen | fb91f30 | 2012-06-11 15:45:18 -0700 | [diff] [blame] | 1144 | mDestroyed = true; |
| 1145 | } |
| 1146 | |
| 1147 | boolean isDestroyed() { |
| 1148 | return mDestroyed; |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1151 | // This method keeps track of the last item in the folder for the purposes |
| 1152 | // of keyboard focus |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 1153 | public void updateTextViewFocus() { |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1154 | View lastChild = mContent.getLastItem(); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1155 | if (lastChild != null) { |
| 1156 | mFolderName.setNextFocusDownId(lastChild.getId()); |
| 1157 | mFolderName.setNextFocusRightId(lastChild.getId()); |
| 1158 | mFolderName.setNextFocusLeftId(lastChild.getId()); |
| 1159 | mFolderName.setNextFocusUpId(lastChild.getId()); |
| 1160 | } |
| 1161 | } |
| 1162 | |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1163 | public void onDrop(DragObject d) { |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1164 | Runnable cleanUpRunnable = null; |
| 1165 | |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 1166 | // If we are coming from All Apps space, we defer removing the extra empty screen |
| 1167 | // until the folder closes |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1168 | if (d.dragSource != mLauncher.getWorkspace() && !(d.dragSource instanceof Folder)) { |
| 1169 | cleanUpRunnable = new Runnable() { |
| 1170 | @Override |
| 1171 | public void run() { |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 1172 | mLauncher.exitSpringLoadedDragModeDelayed(true, |
| 1173 | Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, |
| 1174 | null); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1175 | } |
| 1176 | }; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1177 | } |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1178 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 1179 | // If the icon was dropped while the page was being scrolled, we need to compute |
| 1180 | // the target location again such that the icon is placed of the final page. |
| 1181 | if (!mContent.rankOnCurrentPage(mEmptyCellRank)) { |
| 1182 | // Reorder again. |
| 1183 | mTargetRank = getTargetRank(d, null); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1184 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 1185 | // Rearrange items immediately. |
| 1186 | mReorderAlarmListener.onAlarm(mReorderAlarm); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1187 | |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 1188 | mOnScrollHintAlarm.cancelAlarm(); |
| 1189 | mScrollPauseAlarm.cancelAlarm(); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1190 | } |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 1191 | mContent.completePendingPageChanges(); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1192 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1193 | View currentDragView; |
| 1194 | ShortcutInfo si = mCurrentDragInfo; |
| 1195 | if (mIsExternalDrag) { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1196 | currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank); |
Sunny Goyal | 95abbb3 | 2014-08-04 10:53:22 -0700 | [diff] [blame] | 1197 | // Actually move the item in the database if it was an external drag. Call this |
| 1198 | // before creating the view, so that ShortcutInfo is updated appropriately. |
| 1199 | LauncherModel.addOrMoveItemInDatabase( |
| 1200 | mLauncher, si, mInfo.id, 0, si.cellX, si.cellY); |
| 1201 | |
| 1202 | // We only need to update the locations if it doesn't get handled in #onDropCompleted. |
| 1203 | if (d.dragSource != this) { |
| 1204 | updateItemLocationsInDatabaseBatch(); |
| 1205 | } |
| 1206 | mIsExternalDrag = false; |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1207 | } else { |
| 1208 | currentDragView = mCurrentDragView; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1209 | mContent.addViewForRank(currentDragView, si, mEmptyCellRank); |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1210 | } |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1211 | |
| 1212 | if (d.dragView.hasDrawn()) { |
| 1213 | |
| 1214 | // Temporarily reset the scale such that the animation target gets calculated correctly. |
| 1215 | float scaleX = getScaleX(); |
| 1216 | float scaleY = getScaleY(); |
| 1217 | setScaleX(1.0f); |
| 1218 | setScaleY(1.0f); |
| 1219 | mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, |
| 1220 | cleanUpRunnable, null); |
| 1221 | setScaleX(scaleX); |
| 1222 | setScaleY(scaleY); |
| 1223 | } else { |
| 1224 | d.deferDragViewCleanupPostAnimation = false; |
| 1225 | currentDragView.setVisibility(VISIBLE); |
| 1226 | } |
| 1227 | mItemsInvalidated = true; |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1228 | rearrangeChildren(); |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1229 | |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 1230 | // Temporarily suppress the listener, as we did all the work already here. |
| 1231 | mSuppressOnAdd = true; |
| 1232 | mInfo.add(si); |
| 1233 | mSuppressOnAdd = false; |
Sunny Goyal | 4b02017 | 2014-08-28 14:51:14 -0700 | [diff] [blame] | 1234 | // Clear the drag info, as it is no longer being dragged. |
| 1235 | mCurrentDragInfo = null; |
Sunny Goyal | f406615 | 2015-04-15 09:42:19 -0700 | [diff] [blame] | 1236 | mDragInProgress = false; |
Sunny Goyal | b7e15ad | 2015-05-07 14:51:31 -0700 | [diff] [blame] | 1237 | |
| 1238 | if (mContent.getPageCount() > 1) { |
| 1239 | // The animation has already been shown while opening the folder. |
| 1240 | mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher); |
| 1241 | } |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Adam Cohen | 7a8b82b | 2013-05-29 18:41:50 -0700 | [diff] [blame] | 1244 | // This is used so the item doesn't immediately appear in the folder when added. In one case |
| 1245 | // we need to create the illusion that the item isn't added back to the folder yet, to |
| 1246 | // to correspond to the animation of the icon back into the folder. This is |
| 1247 | public void hideItem(ShortcutInfo info) { |
| 1248 | View v = getViewForInfo(info); |
| 1249 | v.setVisibility(INVISIBLE); |
| 1250 | } |
| 1251 | public void showItem(ShortcutInfo info) { |
| 1252 | View v = getViewForInfo(info); |
| 1253 | v.setVisibility(VISIBLE); |
| 1254 | } |
| 1255 | |
Sunny Goyal | b7e15ad | 2015-05-07 14:51:31 -0700 | [diff] [blame] | 1256 | @Override |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1257 | public void onAdd(ShortcutInfo item) { |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 1258 | // If the item was dropped onto this open folder, we have done the work associated |
| 1259 | // 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] | 1260 | if (mSuppressOnAdd) return; |
Sunny Goyal | 5d85c44 | 2015-03-10 13:14:47 -0700 | [diff] [blame] | 1261 | mContent.createAndAddViewForRank(item, mContent.allocateRankForNewItem(item)); |
Sunny Goyal | 2e688a8 | 2015-03-18 10:23:39 -0700 | [diff] [blame] | 1262 | mItemsInvalidated = true; |
Adam Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 1263 | LauncherModel.addOrMoveItemInDatabase( |
| 1264 | mLauncher, item, mInfo.id, 0, item.cellX, item.cellY); |
| 1265 | } |
| 1266 | |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1267 | public void onRemove(ShortcutInfo item) { |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1268 | mItemsInvalidated = true; |
Adam Cohen | 05e0f40 | 2011-08-01 12:12:49 -0700 | [diff] [blame] | 1269 | // If this item is being dragged from this open folder, we have already handled |
| 1270 | // 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] | 1271 | if (item == mCurrentDragInfo) return; |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 1272 | View v = getViewForInfo(item); |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 1273 | mContent.removeItem(v); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1274 | if (mState == STATE_ANIMATING) { |
| 1275 | mRearrangeOnClose = true; |
| 1276 | } else { |
Sunny Goyal | c3a609f | 2015-02-26 17:43:50 -0800 | [diff] [blame] | 1277 | rearrangeChildren(); |
Adam Cohen | 2801caf | 2011-05-13 20:57:39 -0700 | [diff] [blame] | 1278 | } |
Adam Cohen | afb01ee | 2011-06-23 15:38:03 -0700 | [diff] [blame] | 1279 | if (getItemCount() <= 1) { |
| 1280 | replaceFolderWithFinalItem(); |
| 1281 | } |
Adam Cohen | a9cf38f | 2011-05-02 15:36:58 -0700 | [diff] [blame] | 1282 | } |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1283 | |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1284 | private View getViewForInfo(final ShortcutInfo item) { |
| 1285 | return mContent.iterateOverItems(new ItemOperator() { |
| 1286 | |
| 1287 | @Override |
| 1288 | public boolean evaluate(ItemInfo info, View view, View parent) { |
| 1289 | return info == item; |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 1290 | } |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1291 | }); |
Adam Cohen | df1e4e8 | 2011-06-24 15:57:39 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 1294 | public void onItemsChanged() { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1295 | updateTextViewFocus(); |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 1296 | } |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 1297 | |
Adam Cohen | 76fc085 | 2011-06-17 13:26:23 -0700 | [diff] [blame] | 1298 | public void onTitleChanged(CharSequence title) { |
| 1299 | } |
Adam Cohen | 76078c4 | 2011-06-09 15:06:52 -0700 | [diff] [blame] | 1300 | |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1301 | public ArrayList<View> getItemsInReadingOrder() { |
| 1302 | if (mItemsInvalidated) { |
| 1303 | mItemsInReadingOrder.clear(); |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1304 | mContent.iterateOverItems(new ItemOperator() { |
| 1305 | |
| 1306 | @Override |
| 1307 | public boolean evaluate(ItemInfo info, View view, View parent) { |
| 1308 | mItemsInReadingOrder.add(view); |
| 1309 | return false; |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1310 | } |
Sunny Goyal | bc75335 | 2015-03-05 09:40:44 -0800 | [diff] [blame] | 1311 | }); |
Adam Cohen | 7c69321 | 2011-05-18 15:26:57 -0700 | [diff] [blame] | 1312 | mItemsInvalidated = false; |
| 1313 | } |
| 1314 | return mItemsInReadingOrder; |
| 1315 | } |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 1316 | |
| 1317 | public void getLocationInDragLayer(int[] loc) { |
| 1318 | mLauncher.getDragLayer().getLocationInDragLayer(this, loc); |
| 1319 | } |
Adam Cohen | ea0818d | 2011-09-30 20:06:58 -0700 | [diff] [blame] | 1320 | |
| 1321 | public void onFocusChange(View v, boolean hasFocus) { |
| 1322 | if (v == mFolderName && hasFocus) { |
| 1323 | startEditingFolderName(); |
| 1324 | } |
| 1325 | } |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 1326 | |
| 1327 | @Override |
| 1328 | public void getHitRectRelativeToDragLayer(Rect outRect) { |
| 1329 | getHitRect(outRect); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1330 | outRect.left -= mScrollAreaOffset; |
| 1331 | outRect.right += mScrollAreaOffset; |
| 1332 | } |
| 1333 | |
Winson Chung | 8f1eff7 | 2015-05-28 17:33:40 -0700 | [diff] [blame] | 1334 | @Override |
| 1335 | public void fillInLaunchSourceData(Bundle sourceData) { |
| 1336 | // Fill in from the folder icon's launch source provider first |
| 1337 | Stats.LaunchSourceUtils.populateSourceDataFromAncestorProvider(mFolderIcon, sourceData); |
| 1338 | sourceData.putString(Stats.SOURCE_EXTRA_SUB_CONTAINER, Stats.SUB_CONTAINER_FOLDER); |
| 1339 | sourceData.putInt(Stats.SOURCE_EXTRA_SUB_CONTAINER_PAGE, mContent.getCurrentPage()); |
| 1340 | } |
| 1341 | |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1342 | private class OnScrollHintListener implements OnAlarmListener { |
| 1343 | |
| 1344 | private final DragObject mDragObject; |
| 1345 | |
| 1346 | OnScrollHintListener(DragObject object) { |
| 1347 | mDragObject = object; |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * Scroll hint has been shown long enough. Now scroll to appropriate page. |
| 1352 | */ |
| 1353 | @Override |
| 1354 | public void onAlarm(Alarm alarm) { |
| 1355 | if (mCurrentScrollDir == DragController.SCROLL_LEFT) { |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 1356 | mContent.scrollLeft(); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1357 | mScrollHintDir = DragController.SCROLL_NONE; |
| 1358 | } else if (mCurrentScrollDir == DragController.SCROLL_RIGHT) { |
Sunny Goyal | b863415 | 2015-04-09 14:17:14 -0700 | [diff] [blame] | 1359 | mContent.scrollRight(); |
Sunny Goyal | 4846193 | 2015-03-09 17:41:09 -0700 | [diff] [blame] | 1360 | mScrollHintDir = DragController.SCROLL_NONE; |
| 1361 | } else { |
| 1362 | // This should not happen |
| 1363 | return; |
| 1364 | } |
| 1365 | mCurrentScrollDir = DragController.SCROLL_NONE; |
| 1366 | |
| 1367 | // Pause drag event until the scrolling is finished |
| 1368 | mScrollPauseAlarm.setOnAlarmListener(new OnScrollFinishedListener(mDragObject)); |
| 1369 | mScrollPauseAlarm.setAlarm(DragController.RESCROLL_DELAY); |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | private class OnScrollFinishedListener implements OnAlarmListener { |
| 1374 | |
| 1375 | private final DragObject mDragObject; |
| 1376 | |
| 1377 | OnScrollFinishedListener(DragObject object) { |
| 1378 | mDragObject = object; |
| 1379 | } |
| 1380 | |
| 1381 | /** |
| 1382 | * Page scroll is complete. |
| 1383 | */ |
| 1384 | @Override |
| 1385 | public void onAlarm(Alarm alarm) { |
| 1386 | // Reorder immediately on page change. |
| 1387 | onDragOver(mDragObject, 1); |
| 1388 | } |
Adam Cohen | 7d30a37 | 2013-07-01 17:03:59 -0700 | [diff] [blame] | 1389 | } |
Sunny Goyal | 1dd0f8b | 2015-07-06 13:04:02 -0700 | [diff] [blame] | 1390 | |
| 1391 | // Compares item position based on rank and position giving priority to the rank. |
| 1392 | private static final Comparator<ItemInfo> ITEM_POS_COMPARATOR = new Comparator<ItemInfo>() { |
| 1393 | |
| 1394 | @Override |
| 1395 | public int compare(ItemInfo lhs, ItemInfo rhs) { |
| 1396 | if (lhs.rank != rhs.rank) { |
| 1397 | return lhs.rank - rhs.rank; |
| 1398 | } else if (lhs.cellY != rhs.cellY) { |
| 1399 | return lhs.cellY - rhs.cellY; |
| 1400 | } else { |
| 1401 | return lhs.cellX - rhs.cellX; |
| 1402 | } |
| 1403 | } |
| 1404 | }; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1405 | } |