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