Search in sources :

Example 16 with Point

use of android.graphics.Point in project UltimateRecyclerView by cymcsg.

the class FloatingActionButton method init.

protected void init(Context context, AttributeSet attributeSet) {
    mColorNormal = getColor(android.R.color.holo_blue_dark);
    mColorPressed = getColor(android.R.color.holo_blue_light);
    mIcon = 0;
    mSize = SIZE_NORMAL;
    if (attributeSet != null) {
        initAttributes(context, attributeSet);
    }
    mCircleSize = getCircleSize(mSize);
    mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
    mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
    mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius);
    //point size overhead
    WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        mYHidden = size.y;
    } else
        mYHidden = display.getHeight();
    updateBackground();
}
Also used : Point(android.graphics.Point) WindowManager(android.view.WindowManager) Display(android.view.Display)

Example 17 with Point

use of android.graphics.Point in project subsampling-scale-image-view by davemorrissey.

the class SubsamplingScaleImageView method onTouchEventInternal.

@SuppressWarnings("deprecation")
private boolean onTouchEventInternal(@NonNull MotionEvent event) {
    int touchCount = event.getPointerCount();
    switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_1_DOWN:
        case MotionEvent.ACTION_POINTER_2_DOWN:
            anim = null;
            requestDisallowInterceptTouchEvent(true);
            maxTouchCount = Math.max(maxTouchCount, touchCount);
            if (touchCount >= 2) {
                if (zoomEnabled) {
                    // Start pinch to zoom. Calculate distance between touch points and center point of the pinch.
                    float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                    scaleStart = scale;
                    vDistStart = distance;
                    vTranslateStart.set(vTranslate.x, vTranslate.y);
                    vCenterStart.set((event.getX(0) + event.getX(1)) / 2, (event.getY(0) + event.getY(1)) / 2);
                } else {
                    // Abort all gestures on second touch
                    maxTouchCount = 0;
                }
                // Cancel long click timer
                handler.removeMessages(MESSAGE_LONG_CLICK);
            } else if (!isQuickScaling) {
                // Start one-finger pan
                vTranslateStart.set(vTranslate.x, vTranslate.y);
                vCenterStart.set(event.getX(), event.getY());
                // Start long click timer
                handler.sendEmptyMessageDelayed(MESSAGE_LONG_CLICK, 600);
            }
            return true;
        case MotionEvent.ACTION_MOVE:
            boolean consumed = false;
            if (maxTouchCount > 0) {
                if (touchCount >= 2) {
                    // Calculate new distance between touch points, to scale and pan relative to start values.
                    float vDistEnd = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                    float vCenterEndX = (event.getX(0) + event.getX(1)) / 2;
                    float vCenterEndY = (event.getY(0) + event.getY(1)) / 2;
                    if (zoomEnabled && (distance(vCenterStart.x, vCenterEndX, vCenterStart.y, vCenterEndY) > 5 || Math.abs(vDistEnd - vDistStart) > 5 || isPanning)) {
                        isZooming = true;
                        isPanning = true;
                        consumed = true;
                        double previousScale = scale;
                        scale = Math.min(maxScale, (vDistEnd / vDistStart) * scaleStart);
                        if (scale <= minScale()) {
                            // Minimum scale reached so don't pan. Adjust start settings so any expand will zoom in.
                            vDistStart = vDistEnd;
                            scaleStart = minScale();
                            vCenterStart.set(vCenterEndX, vCenterEndY);
                            vTranslateStart.set(vTranslate);
                        } else if (panEnabled) {
                            // Translate to place the source image coordinate that was at the center of the pinch at the start
                            // at the center of the pinch now, to give simultaneous pan + zoom.
                            float vLeftStart = vCenterStart.x - vTranslateStart.x;
                            float vTopStart = vCenterStart.y - vTranslateStart.y;
                            float vLeftNow = vLeftStart * (scale / scaleStart);
                            float vTopNow = vTopStart * (scale / scaleStart);
                            vTranslate.x = vCenterEndX - vLeftNow;
                            vTranslate.y = vCenterEndY - vTopNow;
                            if ((previousScale * sHeight() < getHeight() && scale * sHeight() >= getHeight()) || (previousScale * sWidth() < getWidth() && scale * sWidth() >= getWidth())) {
                                fitToBounds(true);
                                vCenterStart.set(vCenterEndX, vCenterEndY);
                                vTranslateStart.set(vTranslate);
                                scaleStart = scale;
                                vDistStart = vDistEnd;
                            }
                        } else if (sRequestedCenter != null) {
                            // With a center specified from code, zoom around that point.
                            vTranslate.x = (getWidth() / 2) - (scale * sRequestedCenter.x);
                            vTranslate.y = (getHeight() / 2) - (scale * sRequestedCenter.y);
                        } else {
                            // With no requested center, scale around the image center.
                            vTranslate.x = (getWidth() / 2) - (scale * (sWidth() / 2));
                            vTranslate.y = (getHeight() / 2) - (scale * (sHeight() / 2));
                        }
                        fitToBounds(true);
                        refreshRequiredTiles(false);
                    }
                } else if (isQuickScaling) {
                    // One finger zoom
                    // Stole Google's Magical Formula™ to make sure it feels the exact same
                    float dist = Math.abs(quickScaleVStart.y - event.getY()) * 2 + quickScaleThreshold;
                    if (quickScaleLastDistance == -1f) {
                        quickScaleLastDistance = dist;
                    }
                    boolean isUpwards = event.getY() > quickScaleVLastPoint.y;
                    quickScaleVLastPoint.set(0, event.getY());
                    float spanDiff = Math.abs(1 - (dist / quickScaleLastDistance)) * 0.5f;
                    if (spanDiff > 0.03f || quickScaleMoved) {
                        quickScaleMoved = true;
                        float multiplier = 1;
                        if (quickScaleLastDistance > 0) {
                            multiplier = isUpwards ? (1 + spanDiff) : (1 - spanDiff);
                        }
                        double previousScale = scale;
                        scale = Math.max(minScale(), Math.min(maxScale, scale * multiplier));
                        if (panEnabled) {
                            float vLeftStart = vCenterStart.x - vTranslateStart.x;
                            float vTopStart = vCenterStart.y - vTranslateStart.y;
                            float vLeftNow = vLeftStart * (scale / scaleStart);
                            float vTopNow = vTopStart * (scale / scaleStart);
                            vTranslate.x = vCenterStart.x - vLeftNow;
                            vTranslate.y = vCenterStart.y - vTopNow;
                            if ((previousScale * sHeight() < getHeight() && scale * sHeight() >= getHeight()) || (previousScale * sWidth() < getWidth() && scale * sWidth() >= getWidth())) {
                                fitToBounds(true);
                                vCenterStart.set(sourceToViewCoord(quickScaleSCenter));
                                vTranslateStart.set(vTranslate);
                                scaleStart = scale;
                                dist = 0;
                            }
                        } else if (sRequestedCenter != null) {
                            // With a center specified from code, zoom around that point.
                            vTranslate.x = (getWidth() / 2) - (scale * sRequestedCenter.x);
                            vTranslate.y = (getHeight() / 2) - (scale * sRequestedCenter.y);
                        } else {
                            // With no requested center, scale around the image center.
                            vTranslate.x = (getWidth() / 2) - (scale * (sWidth() / 2));
                            vTranslate.y = (getHeight() / 2) - (scale * (sHeight() / 2));
                        }
                    }
                    quickScaleLastDistance = dist;
                    fitToBounds(true);
                    refreshRequiredTiles(false);
                    consumed = true;
                } else if (!isZooming) {
                    // One finger pan - translate the image. We do this calculation even with pan disabled so click
                    // and long click behaviour is preserved.
                    float dx = Math.abs(event.getX() - vCenterStart.x);
                    float dy = Math.abs(event.getY() - vCenterStart.y);
                    //On the Samsung S6 long click event does not work, because the dx > 5 usually true
                    float offset = density * 5;
                    if (dx > offset || dy > offset || isPanning) {
                        consumed = true;
                        vTranslate.x = vTranslateStart.x + (event.getX() - vCenterStart.x);
                        vTranslate.y = vTranslateStart.y + (event.getY() - vCenterStart.y);
                        float lastX = vTranslate.x;
                        float lastY = vTranslate.y;
                        fitToBounds(true);
                        boolean atXEdge = lastX != vTranslate.x;
                        boolean edgeXSwipe = atXEdge && dx > dy && !isPanning;
                        boolean yPan = lastY == vTranslate.y && dy > offset * 3;
                        if (!edgeXSwipe && (!atXEdge || yPan || isPanning)) {
                            isPanning = true;
                        } else if (dx > offset) {
                            // Haven't panned the image, and we're at the left or right edge. Switch to page swipe.
                            maxTouchCount = 0;
                            handler.removeMessages(MESSAGE_LONG_CLICK);
                            requestDisallowInterceptTouchEvent(false);
                        }
                        if (!panEnabled) {
                            vTranslate.x = vTranslateStart.x;
                            vTranslate.y = vTranslateStart.y;
                            requestDisallowInterceptTouchEvent(false);
                        }
                        refreshRequiredTiles(false);
                    }
                }
            }
            if (consumed) {
                handler.removeMessages(MESSAGE_LONG_CLICK);
                invalidate();
                return true;
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_POINTER_2_UP:
            handler.removeMessages(MESSAGE_LONG_CLICK);
            if (isQuickScaling) {
                isQuickScaling = false;
                if (!quickScaleMoved) {
                    doubleTapZoom(quickScaleSCenter, vCenterStart);
                }
            }
            if (maxTouchCount > 0 && (isZooming || isPanning)) {
                if (isZooming && touchCount == 2) {
                    // Convert from zoom to pan with remaining touch
                    isPanning = true;
                    vTranslateStart.set(vTranslate.x, vTranslate.y);
                    if (event.getActionIndex() == 1) {
                        vCenterStart.set(event.getX(0), event.getY(0));
                    } else {
                        vCenterStart.set(event.getX(1), event.getY(1));
                    }
                }
                if (touchCount < 3) {
                    // End zooming when only one touch point
                    isZooming = false;
                }
                if (touchCount < 2) {
                    // End panning when no touch points
                    isPanning = false;
                    maxTouchCount = 0;
                }
                // Trigger load of tiles now required
                refreshRequiredTiles(true);
                return true;
            }
            if (touchCount == 1) {
                isZooming = false;
                isPanning = false;
                maxTouchCount = 0;
            }
            return true;
    }
    return false;
}
Also used : Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 18 with Point

use of android.graphics.Point in project subsampling-scale-image-view by davemorrissey.

the class SubsamplingScaleImageView method initialiseTileMap.

/**
     * Once source image and view dimensions are known, creates a map of sample size to tile grid.
     */
private void initialiseTileMap(Point maxTileDimensions) {
    debug("initialiseTileMap maxTileDimensions=%dx%d", maxTileDimensions.x, maxTileDimensions.y);
    this.tileMap = new LinkedHashMap<>();
    int sampleSize = fullImageSampleSize;
    int xTiles = 1;
    int yTiles = 1;
    while (true) {
        int sTileWidth = sWidth() / xTiles;
        int sTileHeight = sHeight() / yTiles;
        int subTileWidth = sTileWidth / sampleSize;
        int subTileHeight = sTileHeight / sampleSize;
        while (subTileWidth + xTiles + 1 > maxTileDimensions.x || (subTileWidth > getWidth() * 1.25 && sampleSize < fullImageSampleSize)) {
            xTiles += 1;
            sTileWidth = sWidth() / xTiles;
            subTileWidth = sTileWidth / sampleSize;
        }
        while (subTileHeight + yTiles + 1 > maxTileDimensions.y || (subTileHeight > getHeight() * 1.25 && sampleSize < fullImageSampleSize)) {
            yTiles += 1;
            sTileHeight = sHeight() / yTiles;
            subTileHeight = sTileHeight / sampleSize;
        }
        List<Tile> tileGrid = new ArrayList<>(xTiles * yTiles);
        for (int x = 0; x < xTiles; x++) {
            for (int y = 0; y < yTiles; y++) {
                Tile tile = new Tile();
                tile.sampleSize = sampleSize;
                tile.visible = sampleSize == fullImageSampleSize;
                tile.sRect = new Rect(x * sTileWidth, y * sTileHeight, x == xTiles - 1 ? sWidth() : (x + 1) * sTileWidth, y == yTiles - 1 ? sHeight() : (y + 1) * sTileHeight);
                tile.vRect = new Rect(0, 0, 0, 0);
                tile.fileSRect = new Rect(tile.sRect);
                tileGrid.add(tile);
            }
        }
        tileMap.put(sampleSize, tileGrid);
        if (sampleSize == 1) {
            break;
        } else {
            sampleSize /= 2;
        }
    }
}
Also used : Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 19 with Point

use of android.graphics.Point in project FlexibleAdapter by davideas.

the class FromTopItemAnimator method animateRemoveImpl.

@Override
protected ViewPropertyAnimatorCompat animateRemoveImpl(ViewHolder holder) {
    Point screen = Utils.getScreenDimensions(holder.itemView.getContext());
    int top = holder.itemView.getTop();
    return ViewCompat.animate(holder.itemView).rotation(80).translationY(screen.y - top).setInterpolator(new AccelerateInterpolator());
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) Point(android.graphics.Point) Point(android.graphics.Point)

Example 20 with Point

use of android.graphics.Point in project UltimateAndroid by cymcsg.

the class ZoomPanLayout method getDistance.

// sugar to calculate distance between 2 Points, because android.graphics.Point is horrible
private static double getDistance(Point p1, Point p2) {
    int x = p1.x - p2.x;
    int y = p1.y - p2.y;
    return Math.sqrt(x * x + y * y);
}
Also used : Point(android.graphics.Point)

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