import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
-import android.os.AsyncTask;
import android.os.Build;
+import android.os.Handler;
+import android.os.Looper;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherModel;
import com.android.launcher3.LogDecelerateInterpolator;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.UiThreadCircularReveal;
-import java.util.ArrayList;
import java.util.List;
/**
deferDrag(originalIcon);
// Load the shortcuts on a background thread and update the container as it animates.
+ final Looper workerLooper = LauncherModel.getWorkerLooper();
+ final Handler uiHandler = new Handler(Looper.getMainLooper());
final ItemInfo originalInfo = (ItemInfo) originalIcon.getTag();
final UserHandleCompat user = originalInfo.user;
final ComponentName activity = originalInfo.getTargetComponent();
- new AsyncTask<Void, Void, List<ShortcutInfo>>() {
- public List<ShortcutInfo> doInBackground(Void ... args) {
- List<ShortcutInfoCompat> shortcuts = mDeepShortcutsManager
+ new Handler(workerLooper).postAtFrontOfQueue(new Runnable() {
+ @Override
+ public void run() {
+ final List<ShortcutInfoCompat> shortcuts = mDeepShortcutsManager
.queryForAllAppShortcuts(activity, ids, user);
- List<ShortcutInfo> shortcutInfos = new ArrayList<>(shortcuts.size());
- for (ShortcutInfoCompat shortcut : shortcuts) {
- shortcutInfos.add(ShortcutInfo.fromDeepShortcutInfo(shortcut, mLauncher));
+ for (int i = 0; i < shortcuts.size(); i++) {
+ final ShortcutInfoCompat shortcut = shortcuts.get(i);
+ final ShortcutInfo launcherShortcutInfo = ShortcutInfo
+ .fromDeepShortcutInfo(shortcut, mLauncher);
+ uiHandler.post(new UpdateShortcutChild(i, launcherShortcutInfo));
}
- return shortcutInfos;
}
+ });
+ }
- // TODO: implement onProgressUpdate() to load shortcuts one at a time.
+ /** Updates the child of this container at the given index based on the given shortcut info. */
+ private class UpdateShortcutChild implements Runnable {
+ private int mShortcutChildIndex;
+ private ShortcutInfo mShortcutChildInfo;
- @Override
- protected void onPostExecute(List<ShortcutInfo> shortcuts) {
- for (int i = 0; i < shortcuts.size(); i++) {
- DeepShortcutView iconAndText = (DeepShortcutView) getChildAt(i);
- ShortcutInfo launcherShortcutInfo = shortcuts.get(i);
- iconAndText.applyFromShortcutInfo(launcherShortcutInfo,
- LauncherAppState.getInstance().getIconCache());
- iconAndText.setOnClickListener(mLauncher);
- iconAndText.setOnLongClickListener(DeepShortcutsContainer.this);
- iconAndText.setOnTouchListener(DeepShortcutsContainer.this);
- int viewId = mLauncher.getViewIdForItem(originalInfo);
- iconAndText.setId(viewId);
- }
- }
- }.execute();
+ public UpdateShortcutChild(int shortcutChildIndex, ShortcutInfo shortcutChildInfo) {
+ mShortcutChildIndex = shortcutChildIndex;
+ mShortcutChildInfo = shortcutChildInfo;
+ }
+
+ @Override
+ public void run() {
+ DeepShortcutView shortcutView = (DeepShortcutView) getChildAt(mShortcutChildIndex);
+ shortcutView.applyFromShortcutInfo(mShortcutChildInfo,
+ LauncherAppState.getInstance().getIconCache());
+ shortcutView.setOnClickListener(mLauncher);
+ shortcutView.setOnLongClickListener(DeepShortcutsContainer.this);
+ shortcutView.setOnTouchListener(DeepShortcutsContainer.this);
+ }
}
// TODO: update this animation
mDragView.show(motionDownX, motionDownY);
}
- public boolean onForwardedEvent(MotionEvent ev, int activePointerId, MotionEvent touchDownEvent) {
- mTouchDown = new Point((int) touchDownEvent.getX(), (int) touchDownEvent.getY());
+ public boolean onForwardedEvent(MotionEvent ev, int activePointerId, Point touchDown) {
mActivePointerId = activePointerId;
+ mTouchDown = touchDown;
return dispatchTouchEvent(ev);
}
* @param y the y touch coordinate relative to this container
*/
private boolean shouldStartDeferredDrag(int x, int y, boolean containerContainsTouch) {
- Point closestEdge = new Point(mTouchDown.x, mIsAboveIcon ? getMeasuredHeight() : 0);
- double distToEdge = Math.hypot(mTouchDown.x - closestEdge.x, mTouchDown.y - closestEdge.y);
- double newDistToEdge = Math.hypot(x - closestEdge.x, y - closestEdge.y);
+ int closestEdgeY = mIsAboveIcon ? getMeasuredHeight() : 0;
+ double distToEdge = Math.abs(mTouchDown.y - closestEdgeY);
+ double newDistToEdge = Math.hypot(x - mTouchDown.x, y - closestEdgeY);
return !containerContainsTouch && (newDistToEdge - distToEdge > mStartDragThreshold);
}
package com.android.launcher3.shortcuts;
import android.content.Context;
+import android.graphics.Point;
import android.os.SystemClock;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
private Launcher mLauncher;
private DragLayer mDragLayer;
private MotionEvent mTouchDownEvent;
+ /** The coordinates of the touch down, relative do the shortcuts container. */
+ private final Point mTouchDown;
public ShortcutsContainerListener(BubbleTextView icon) {
mSrcIcon = icon;
icon.addOnAttachStateChangeListener(this);
mLauncher = Launcher.getLauncher(mSrcIcon.getContext());
-
mDragLayer = mLauncher.getDragLayer();
+ mTouchDown = new Point();
}
@Override
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
+ if (mTouchDownEvent != null) {
+ mTouchDownEvent.recycle();
+ }
mTouchDownEvent = MotionEvent.obtainNoHistory(event);
}
deepShortcutsContainer.populateAndShow(mSrcIcon, ids);
mSrcIcon.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
+
+ // Convert touch down event to the container's coordinates.
+ Utilities.translateEventCoordinates(mSrcIcon, deepShortcutsContainer, mTouchDownEvent);
+ mTouchDown.set((int) mTouchDownEvent.getX(), (int) mTouchDownEvent.getY());
return true;
}
return false;
final MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
Utilities.translateEventCoordinates(src, dst, dstEvent);
- // Convert touch down event to destination-local coordinates.
- // TODO: only create this once, or just store the x and y.
- final MotionEvent touchDownEvent = MotionEvent.obtainNoHistory(mTouchDownEvent);
- Utilities.translateEventCoordinates(src, dst, touchDownEvent);
-
// Forward converted event to destination view, then recycle it.
// TODO: don't create objects in onForwardedEvent.
- final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId, touchDownEvent);
+ final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId, mTouchDown);
dstEvent.recycle();
- touchDownEvent.recycle();
// Always cancel forwarding when the touch stream ends.
final int action = srcEvent.getActionMasked();