@Override public boolean onTouchEvent(MotionEvent ev) { // Log.d("DragLayer","onTouchEvent"); boolean handled = false; int action = ev.getAction(); int x = (int) ev.getX(); int y = (int) ev.getY(); if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (handleTouchDown(ev, false)) { return true; } } } if (mCurrentResizeFrame != null) { handled = true; switch (action) { case MotionEvent.ACTION_MOVE: mCurrentResizeFrame.visualizeResizeForDelta(x - mXDown, y - mYDown); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mCurrentResizeFrame.visualizeResizeForDelta(x - mXDown, y - mYDown); mCurrentResizeFrame.onTouchUp(); mCurrentResizeFrame = null; } } if (handled) return true; return mDragController.onTouchEvent(ev.getRawX(), ev.getRawY(), ev); }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub if (mDragController.onInterceptTouchEvent(ev)) { return true; } return super.onInterceptTouchEvent(ev); }
public DragNDropLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext = context; mDragController = new DragController(context); mDragController.setDragListener(this); mScaleFactor = 1.0f; scaleDetector = new ScaleGestureDetector(context, new ScaleListener()); detector = new GestureDetector(context, new FlingListener()); }
public void startDrag(View view, Object info) { int count = this.getChildCount(); for (int i = 0; i < count; i++) { View v = getChildAt(i); if (v == view) { mDragController.startDrag(view, info); } } }
public void onDragEnd() { if (mTrashMode) { mTrashMode = false; mDragController.setDeleteRegion(null); startAnimation(mOutAnimation); mHandle.startAnimation(mHandleInAnimation); setVisibility(GONE); } }
public void clearAnimatedView() { if (mDropAnim != null) { mDropAnim.cancel(); } if (mDropView != null) { mDragController.onDeferredEndDrag(mDropView); } mDropView = null; invalidate(); }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // Log.d("DragLayer","onInterceptTouchEvent"); if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (handleTouchDown(ev, true)) { return true; } } clearAllResizeFrames(); return mDragController.onInterceptTouchEvent(ev); }
/** * A drag has begun. * * @param source An object representing where the drag originated * @param info The data associated with the object that is being dragged * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE} or {@link * DragController#DRAG_ACTION_COPY} */ public void onDragStart(DragSource source, Object info, int dragAction) { // We are starting a drag. // Build up a list of DropTargets from the child views of the GridView. // Tell the drag controller about them. if (mGridView != null) { int numVisibleChildren = mGridView.getChildCount(); for (int i = 0; i < numVisibleChildren; i++) { DropTarget view = (DropTarget) mGridView.getChildAt(i); mDragController.addDropTarget(view); } } // Always add the delete_zone so there is a place to get rid of views. // Find the delete_zone and add it as a drop target. // That gives the user a place to drag views to get them off the screen. View v = findViewById(R.id.delete_zone_view); if (v != null) { DeleteZone dz = (DeleteZone) v; mDragController.addDropTarget(dz); } }
@Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub if (mDragController.onTouchEvent(event)) { return true; } scaleDetector.onTouchEvent(event); if (detector.onTouchEvent(event)) { return true; } super.onTouchEvent(event); return true; }
public void setup(Launcher launcher, DragController dragController) { dragController.addDragListener(this); dragController.setFlingToDeleteDropTarget(mDeleteDropTarget); dragController.addDragListener(mInfoDropTarget); dragController.addDragListener(mDeleteDropTarget); dragController.addDragListener(mUninstallDropTarget); dragController.addDropTarget(mInfoDropTarget); dragController.addDropTarget(mDeleteDropTarget); dragController.addDropTarget(mUninstallDropTarget); mInfoDropTarget.setLauncher(launcher); mDeleteDropTarget.setLauncher(launcher); mUninstallDropTarget.setLauncher(launcher); }
public void onDragStart(DragSource source, Object info, int dragAction) { final ItemInfo item = (ItemInfo) info; if (item != null) { mTrashMode = true; createAnimations(); final int[] location = mLocation; getLocationOnScreen(location); mRegion.set( location[0], location[1], location[0] + mRight - mLeft, location[1] + mBottom - mTop); mDragController.setDeleteRegion(mRegion); mTransition.resetTransition(); startAnimation(mInAnimation); mHandle.startAnimation(mHandleOutAnimation); setVisibility(VISIBLE); } }
private void onCloseComplete() { DragLayer parent = (DragLayer) getParent(); parent.removeView(this); mDragController.removeDropTarget((DropTarget) this); clearFocus(); mFolderIcon.requestFocus(); if (mRearrangeOnClose) { setupContentForNumItems(getItemCount()); mRearrangeOnClose = false; } if (getItemCount() <= 1) { if (!mDragInProgress && !mSuppressFolderDeletion) { replaceFolderWithFinalItem(); } else if (mDragInProgress) { mDeleteFolderOnDropCompleted = true; } } mSuppressFolderDeletion = false; }
public void setup(Launcher launcher, DragController dragController) { dragController.addDragListener(this); dragController.addDragListener(mInfoDropTarget); dragController.addDragListener(mDeleteDropTarget); dragController.addDropTarget(mInfoDropTarget); dragController.addDropTarget(mDeleteDropTarget); dragController.setFlingToDeleteDropTarget(mDeleteDropTarget); mInfoDropTarget.setLauncher(launcher); mDeleteDropTarget.setLauncher(launcher); mQSBSearchBar = launcher.getQsbBar(); if (mEnableDropDownDropTargets) { mQSBSearchBarAnim = LauncherAnimUtils.ofFloat(mQSBSearchBar, "translationY", 0, -mBarHeight); } else { mQSBSearchBarAnim = LauncherAnimUtils.ofFloat(mQSBSearchBar, "alpha", 1f, 0f); } setupAnimation(mQSBSearchBarAnim, mQSBSearchBar); }
private void replaceFolderWithFinalItem() { ItemInfo finalItem = null; if (getItemCount() == 1) { finalItem = mInfo.contents.get(0); } // Remove the folder completely CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen); cellLayout.removeView(mFolderIcon); if (mFolderIcon instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) mFolderIcon); } mLauncher.removeFolder(mInfo); if (finalItem != null) { LauncherModel.addOrMoveItemInDatabase( mLauncher, finalItem, mInfo.container, mInfo.screen, mInfo.cellX, mInfo.cellY); } LauncherModel.deleteItemFromDatabase(mLauncher, mInfo); // Add the last remaining child to the workspace in place of the folder if (finalItem != null) { View child = mLauncher.createShortcut(R.layout.application, cellLayout, (ShortcutInfo) finalItem); mLauncher .getWorkspace() .addInScreen( child, mInfo.container, mInfo.screen, mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); } }
public void cancelDrag() { mDragController.cancelDrag(); }
public void animateOpen() { if (!(getParent() instanceof DragLayer)) return; Animator openFolderAnim = null; final Runnable onCompleteRunnable; if (!Utilities.isLmpOrAbove()) { positionAndSizeAsIcon(); centerAboutIcon(); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); oa.setDuration(mExpandDuration); openFolderAnim = oa; setLayerType(LAYER_TYPE_HARDWARE, null); onCompleteRunnable = new Runnable() { @Override public void run() { setLayerType(LAYER_TYPE_NONE, null); } }; } else { prepareReveal(); centerAboutIcon(); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getFolderHeight(); float transX = -0.075f * (width / 2 - getPivotX()); float transY = -0.075f * (height / 2 - getPivotY()); setTranslationX(transX); setTranslationY(transY); PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, 0); PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, 0); int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX()); int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY()); float radius = (float) Math.sqrt(rx * rx + ry * ry); AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); Animator reveal = LauncherAnimUtils.createCircularReveal( this, (int) getPivotX(), (int) getPivotY(), 0, radius); reveal.setDuration(mMaterialExpandDuration); reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); mContent.setAlpha(0f); Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContent, "alpha", 0f, 1f); iconsAlpha.setDuration(mMaterialExpandDuration); iconsAlpha.setStartDelay(mMaterialExpandStagger); iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); mFolderName.setAlpha(0f); Animator textAlpha = LauncherAnimUtils.ofFloat(mFolderName, "alpha", 0f, 1f); textAlpha.setDuration(mMaterialExpandDuration); textAlpha.setStartDelay(mMaterialExpandStagger); textAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty); drift.setDuration(mMaterialExpandDuration); drift.setStartDelay(mMaterialExpandStagger); drift.setInterpolator(new LogDecelerateInterpolator(60, 0)); anim.play(drift); anim.play(iconsAlpha); anim.play(textAlpha); anim.play(reveal); openFolderAnim = anim; mContent.setLayerType(LAYER_TYPE_HARDWARE, null); onCompleteRunnable = new Runnable() { @Override public void run() { mContent.setLayerType(LAYER_TYPE_NONE, null); } }; } openFolderAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { sendCustomAccessibilityEvent( AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, String.format( getContext().getString(R.string.folder_opened), mContent.getCountX(), mContent.getCountY())); mState = STATE_ANIMATING; } @Override public void onAnimationEnd(Animator animation) { mState = STATE_OPEN; if (onCompleteRunnable != null) { onCompleteRunnable.run(); } setFocusOnFirstChild(); } }); openFolderAnim.start(); // Make sure the folder picks up the last drag move even if the finger doesn't move. if (mDragController.isDragging()) { mDragController.forceTouchMove(); } }
@Override public boolean onLongClick(View v) { DragController.create().startDragFromStack(draggedView, v.getRootView()); return true; }
@Override public boolean dispatchUnhandledMove(View focused, int direction) { return mDragController.dispatchUnhandledMove(focused, direction); }
@Override public boolean onTouchEvent(MotionEvent ev) { return mDragController.onTouchEvent(ev); }
@Override public boolean dispatchKeyEvent(KeyEvent event) { return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event); }
public void show() { DragController.getInstance(null).dragModeStart(this); }
/** A drag-drop operation has eneded. */ public void onDragEnd() { mDragController.removeAllDropTargets(); }
public void removeSelfInParent(DragController dragController) { clearAnimation(); AnimManager.getInstance().removeControllers(this); dragController.removeDropTarget((DropTarget) this); ((CellLayout) getParent()).removeView(this); }