/** * Starts a drag. * * @param b The bitmap to display as the drag image. It will be re-scaled to the enlarged size. * @param screenX The x position on screen of the left-top of the bitmap. * @param screenY The y position on screen of the left-top of the bitmap. * @param textureLeft The left edge of the region inside b to use. * @param textureTop The top edge of the region inside b to use. * @param textureWidth The width of the region inside b to use. * @param textureHeight The height of the region inside b to use. * @param source An object representing where the drag originated * @param dragInfo The data associated with the object that is being dragged * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or {@link * #DRAG_ACTION_COPY} */ public void startDrag( Bitmap b, int screenX, int screenY, int textureLeft, int textureTop, int textureWidth, int textureHeight, DragSource source, Object dragInfo, int dragAction) { if (PROFILE_DRAWING_DURING_DRAG) { android.os.Debug.startMethodTracing("Launcher"); } // Hide soft keyboard, if visible if (mInputMethodManager == null) { mInputMethodManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); } mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0); if (mListener != null) { mListener.onDragStart(source, dragInfo, dragAction); } int registrationX = ((int) mMotionDownX) - screenX; int registrationY = ((int) mMotionDownY) - screenY; mTouchOffsetX = mMotionDownX - screenX; mTouchOffsetY = mMotionDownY - screenY; mDragging = true; mDragSource = source; mDragInfo = dragInfo; mVibrator.vibrate(VIBRATE_DURATION); DragView dragView = mDragView = new DragView( mContext, b, registrationX, registrationY, textureLeft, textureTop, textureWidth, textureHeight); if (mDragView != null) { mDragView.setmOriginalWidth(textureWidth); mDragView.setmOriginalHeight(textureHeight); dragView.setmOriginalWidth(textureWidth); dragView.setmOriginalHeight(textureHeight); } dragView.show(mWindowToken, (int) mMotionDownX, (int) mMotionDownY); }
/** * Starts a drag. * * @param b The bitmap to display as the drag image. It will be re-scaled to the enlarged size. * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap. * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap. * @param source An object representing where the drag originated * @param dragInfo The data associated with the object that is being dragged * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or {@link * #DRAG_ACTION_COPY} * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. Makes * dragging feel more precise, e.g. you can clip out a transparent border */ public void startDrag( Bitmap b, int dragLayerX, int dragLayerY, DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion, float initialDragViewScale) { if (PROFILE_DRAWING_DURING_DRAG) { android.os.Debug.startMethodTracing("Launcher"); } // Hide soft keyboard, if visible if (mInputMethodManager == null) { mInputMethodManager = (InputMethodManager) mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE); } mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0); for (DragListener listener : mListeners) { listener.onDragStart(source, dragInfo, dragAction); } final int registrationX = mMotionDownX - dragLayerX; final int registrationY = mMotionDownY - dragLayerY; final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left; final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top; mDragging = true; mDragObject = new DropTarget.DragObject(); mDragObject.dragComplete = false; mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft); mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop); mDragObject.dragSource = source; mDragObject.dragInfo = dragInfo; final DragView dragView = mDragObject.dragView = new DragView( mLauncher, b, registrationX, registrationY, 0, 0, b.getWidth(), b.getHeight(), initialDragViewScale); if (dragOffset != null) { dragView.setDragVisualizeOffset(new Point(dragOffset)); } if (dragRegion != null) { dragView.setDragRegion(new Rect(dragRegion)); } mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); dragView.show(mMotionDownX, mMotionDownY); handleMoveEvent(mMotionDownX, mMotionDownY); }
public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) { if (PROFILE_DRAWING_DURING_DRAG) { android.os.Debug.startMethodTracing("Launcher"); } mTagPopup = v.getTag(R.id.TAG_PREVIEW); // Hide soft keyboard, if visible if (mInputMethodManager == null) { mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); } mInputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); // Faruq: ArrayList For Each for (DragListener l : mListener) { l.onDragStart(v, source, dragInfo, dragAction); } Rect r = mDragRect; r.set(v.getScrollX(), v.getScrollY(), 0, 0); mOriginalX = mLastMotionX; mOriginalY = mLastMotionY; offsetDescendantRectToMyCoords(v, r); mTouchOffsetX = mLastMotionX - r.left; mTouchOffsetY = mLastMotionY - r.top; v.clearFocus(); v.setPressed(false); boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent // for the duration of this operation int color = v.getDrawingCacheBackgroundColor(); v.setDrawingCacheBackgroundColor(0); if (color != 0) { v.destroyDrawingCache(); } v.buildDrawingCache(); Bitmap viewBitmap = v.getDrawingCache(); if (viewBitmap != null) { mDrawModeBitmap = true; int width = viewBitmap.getWidth(); int height = viewBitmap.getHeight(); Matrix scale = new Matrix(); float scaleFactor = v.getWidth(); scaleFactor = (scaleFactor + DRAG_SCALE) / scaleFactor; scale.setScale(scaleFactor, scaleFactor); mAnimationTo = 1.0f; mAnimationFrom = 1.0f / scaleFactor; mAnimationDuration = ANIMATION_SCALE_UP_DURATION; mAnimationState = ANIMATION_STATE_STARTING; mAnimationType = ANIMATION_TYPE_SCALE; try { mDragBitmap = Bitmap.createBitmap(viewBitmap, 0, 0, width, height, scale, true); final Bitmap dragBitmap = mDragBitmap; mBitmapOffsetX = (dragBitmap.getWidth() - width) / 2; mBitmapOffsetY = (dragBitmap.getHeight() - height) / 2; } catch (OutOfMemoryError e) { mDrawModeBitmap = false; width = v.getWidth(); height = v.getHeight(); scaleFactor = v.getWidth(); scaleFactor = (scaleFactor + DRAG_SCALE) / scaleFactor; mDrawWidth = (int) (v.getWidth() * scaleFactor); mDrawHeight = (int) (v.getHeight() * scaleFactor); mAnimationTo = 1.0f; mAnimationFrom = 1.0f / scaleFactor; mAnimationDuration = ANIMATION_SCALE_UP_DURATION; mAnimationState = ANIMATION_STATE_STARTING; mAnimationType = ANIMATION_TYPE_SCALE; mBitmapOffsetX = (mDrawWidth - width) / 2; mBitmapOffsetY = (mDrawHeight - height) / 2; } v.destroyDrawingCache(); v.setWillNotCacheDrawing(willNotCache); v.setDrawingCacheBackgroundColor(color); } else { mDrawModeBitmap = false; int width = v.getWidth(); int height = v.getHeight(); float scaleFactor = v.getWidth(); scaleFactor = (scaleFactor + DRAG_SCALE) / scaleFactor; mDrawWidth = (int) (v.getWidth() * scaleFactor); mDrawHeight = (int) (v.getHeight() * scaleFactor); mAnimationTo = 1.0f; mAnimationFrom = 1.0f / scaleFactor; mAnimationDuration = ANIMATION_SCALE_UP_DURATION; mAnimationState = ANIMATION_STATE_STARTING; mAnimationType = ANIMATION_TYPE_SCALE; mBitmapOffsetX = (mDrawWidth - width) / 2; mBitmapOffsetY = (mDrawHeight - height) / 2; } if (dragAction == DRAG_ACTION_MOVE) { v.setVisibility(GONE); } mDragPaint = null; mDragging = true; mShouldDrop = true; mOriginator = v; mDragSource = source; mDragInfo = dragInfo; performHapticFeedback( HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); mEnteredRegion = false; invalidate(); }