Search in sources :

Example 11 with Point

use of android.graphics.Point in project Launcher3 by chislon.

the class CropView method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    int action = event.getActionMasked();
    final boolean pointerUp = action == MotionEvent.ACTION_POINTER_UP;
    final int skipIndex = pointerUp ? event.getActionIndex() : -1;
    // Determine focal point
    float sumX = 0, sumY = 0;
    final int count = event.getPointerCount();
    for (int i = 0; i < count; i++) {
        if (skipIndex == i)
            continue;
        sumX += event.getX(i);
        sumY += event.getY(i);
    }
    final int div = pointerUp ? count - 1 : count;
    float x = sumX / div;
    float y = sumY / div;
    if (action == MotionEvent.ACTION_DOWN) {
        mFirstX = x;
        mFirstY = y;
        mTouchDownTime = System.currentTimeMillis();
        if (mTouchCallback != null) {
            mTouchCallback.onTouchDown();
        }
    } else if (action == MotionEvent.ACTION_UP) {
        ViewConfiguration config = ViewConfiguration.get(getContext());
        float squaredDist = (mFirstX - x) * (mFirstX - x) + (mFirstY - y) * (mFirstY - y);
        float slop = config.getScaledTouchSlop() * config.getScaledTouchSlop();
        long now = System.currentTimeMillis();
        if (mTouchCallback != null) {
            // only do this if it's a small movement
            if (squaredDist < slop && now < mTouchDownTime + ViewConfiguration.getTapTimeout()) {
                mTouchCallback.onTap();
            }
            mTouchCallback.onTouchUp();
        }
    }
    if (!mTouchEnabled) {
        return true;
    }
    synchronized (mLock) {
        mScaleGestureDetector.onTouchEvent(event);
        switch(action) {
            case MotionEvent.ACTION_MOVE:
                float[] point = mTempPoint;
                point[0] = (mLastX - x) / mRenderer.scale;
                point[1] = (mLastY - y) / mRenderer.scale;
                mInverseRotateMatrix.mapPoints(point);
                mCenterX += point[0];
                mCenterY += point[1];
                updateCenter();
                invalidate();
                break;
        }
        if (mRenderer.source != null) {
            // Adjust position so that the wallpaper covers the entire area
            // of the screen
            final RectF edges = mTempEdges;
            getEdgesHelper(edges);
            final float scale = mRenderer.scale;
            float[] coef = mTempCoef;
            coef[0] = 1;
            coef[1] = 1;
            mRotateMatrix.mapPoints(coef);
            float[] adjustment = mTempAdjustment;
            mTempAdjustment[0] = 0;
            mTempAdjustment[1] = 0;
            if (edges.left > 0) {
                adjustment[0] = edges.left / scale;
            } else if (edges.right < getWidth()) {
                adjustment[0] = (edges.right - getWidth()) / scale;
            }
            if (edges.top > 0) {
                adjustment[1] = FloatMath.ceil(edges.top / scale);
            } else if (edges.bottom < getHeight()) {
                adjustment[1] = (edges.bottom - getHeight()) / scale;
            }
            for (int dim = 0; dim <= 1; dim++) {
                if (coef[dim] > 0)
                    adjustment[dim] = FloatMath.ceil(adjustment[dim]);
            }
            mInverseRotateMatrix.mapPoints(adjustment);
            mCenterX += adjustment[0];
            mCenterY += adjustment[1];
            updateCenter();
        }
    }
    mLastX = x;
    mLastY = y;
    return true;
}
Also used : RectF(android.graphics.RectF) ViewConfiguration(android.view.ViewConfiguration) Point(android.graphics.Point)

Example 12 with Point

use of android.graphics.Point in project Launcher3 by chislon.

the class DragController method startDrag.

/**
     * 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);
}
Also used : Rect(android.graphics.Rect) Point(android.graphics.Point) Point(android.graphics.Point)

Example 13 with Point

use of android.graphics.Point in project Launcher3 by chislon.

the class AppsCustomizePagedView method beginDraggingWidget.

private boolean beginDraggingWidget(View v) {
    mDraggingWidget = true;
    // Get the widget preview as the drag representation
    ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
    PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();
    // we abort the drag.
    if (image.getDrawable() == null) {
        mDraggingWidget = false;
        return false;
    }
    // Compose the drag image
    Bitmap preview;
    Bitmap outline;
    float scale = 1f;
    Point previewPadding = null;
    if (createItemInfo instanceof PendingAddWidgetInfo) {
        // the widget if this is null, so we break out.
        if (mCreateWidgetInfo == null) {
            return false;
        }
        PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
        createItemInfo = createWidgetInfo;
        int spanX = createItemInfo.spanX;
        int spanY = createItemInfo.spanY;
        int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true);
        FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
        float minScale = 1.25f;
        int maxWidth, maxHeight;
        maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
        maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);
        int[] previewSizeBeforeScale = new int[1];
        preview = mWidgetPreviewLoader.generateWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage, createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight, null, previewSizeBeforeScale);
        // Compare the size of the drag preview to the preview in the AppsCustomize tray
        int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0], mWidgetPreviewLoader.maxWidthForWidgetPreview(spanX));
        scale = previewWidthInAppsCustomize / (float) preview.getWidth();
        // might be extra pixels around the preview itself - this accounts for that
        if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) {
            int padding = (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2;
            previewPadding = new Point(padding, 0);
        }
    } else {
        PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag();
        Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo);
        preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        mCanvas.setBitmap(preview);
        mCanvas.save();
        WidgetPreviewLoader.renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
        mCanvas.restore();
        mCanvas.setBitmap(null);
        createItemInfo.spanX = createItemInfo.spanY = 1;
    }
    // Don't clip alpha values for the drag outline if we're using the default widget preview
    boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));
    // Save the preview for the outline generation, then dim the preview
    outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false);
    // Start the drag
    mLauncher.lockScreenOrientation();
    mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha);
    mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY, previewPadding, scale);
    outline.recycle();
    preview.recycle();
    return true;
}
Also used : Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) Point(android.graphics.Point) Point(android.graphics.Point)

Example 14 with Point

use of android.graphics.Point in project Launcher3 by chislon.

the class CellLayout method setTagToCellInfoForPoint.

public void setTagToCellInfoForPoint(int touchX, int touchY) {
    final CellInfo cellInfo = mCellInfo;
    Rect frame = mRect;
    final int x = touchX + getScrollX();
    final int y = touchY + getScrollY();
    final int count = mShortcutsAndWidgets.getChildCount();
    boolean found = false;
    for (int i = count - 1; i >= 0; i--) {
        final View child = mShortcutsAndWidgets.getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if ((child.getVisibility() == VISIBLE || child.getAnimation() != null) && lp.isLockedToGrid) {
            child.getHitRect(frame);
            float scale = child.getScaleX();
            frame = new Rect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
            // The child hit rect is relative to the CellLayoutChildren parent, so we need to
            // offset that by this CellLayout's padding to test an (x,y) point that is relative
            // to this view.
            frame.offset(getPaddingLeft(), getPaddingTop());
            frame.inset((int) (frame.width() * (1f - scale) / 2), (int) (frame.height() * (1f - scale) / 2));
            if (frame.contains(x, y)) {
                cellInfo.cell = child;
                cellInfo.cellX = lp.cellX;
                cellInfo.cellY = lp.cellY;
                cellInfo.spanX = lp.cellHSpan;
                cellInfo.spanY = lp.cellVSpan;
                found = true;
                break;
            }
        }
    }
    mLastDownOnOccupiedCell = found;
    if (!found) {
        final int[] cellXY = mTmpXY;
        pointToCellExact(x, y, cellXY);
        cellInfo.cell = null;
        cellInfo.cellX = cellXY[0];
        cellInfo.cellY = cellXY[1];
        cellInfo.spanX = 1;
        cellInfo.spanY = 1;
    }
    setTag(cellInfo);
}
Also used : Rect(android.graphics.Rect) View(android.view.View) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 15 with Point

use of android.graphics.Point in project Launcher3 by chislon.

the class CellLayout method cellToPoint.

/**
     * Given a cell coordinate, return the point that represents the upper left corner of that cell
     *
     * @param cellX X coordinate of the cell
     * @param cellY Y coordinate of the cell
     *
     * @param result Array of 2 ints to hold the x and y coordinate of the point
     */
void cellToPoint(int cellX, int cellY, int[] result) {
    final int hStartPadding = getPaddingLeft();
    final int vStartPadding = getPaddingTop();
    result[0] = hStartPadding + cellX * (mCellWidth + mWidthGap);
    result[1] = vStartPadding + cellY * (mCellHeight + mHeightGap);
}
Also used : Point(android.graphics.Point) Paint(android.graphics.Paint)

Aggregations

Point (android.graphics.Point)1121 Display (android.view.Display)211 Rect (android.graphics.Rect)194 Paint (android.graphics.Paint)164 WindowManager (android.view.WindowManager)131 RemoteException (android.os.RemoteException)76 RectF (android.graphics.RectF)55 Bitmap (android.graphics.Bitmap)54 Resources (android.content.res.Resources)41 View (android.view.View)40 ArrayList (java.util.ArrayList)40 ImageView (android.widget.ImageView)37 Camera (android.hardware.Camera)36 Canvas (android.graphics.Canvas)31 Matrix (android.graphics.Matrix)29 Animator (android.animation.Animator)27 SuppressLint (android.annotation.SuppressLint)26 Configuration (android.content.res.Configuration)26 IOException (java.io.IOException)24 Message (android.os.Message)22