android.graphics.PointF Java Examples

The following examples show how to use android.graphics.PointF. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotePreviewActivity.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
private void handlePreViewImageItem(int index, List<String> data, List<ImagePreViewAdapter.ImagePreViewEntity> imageData, OnCompleteListener listener) {
    String original = data.get(index);
    ImageLoader.download(this, original, file -> {
        if (file == null) {
            listener.onComplete(null);
            return;
        }
        String absolutePath = file.getAbsolutePath();
        float imageScale = getImageScale(absolutePath);
        imageData.add(new ImagePreViewAdapter.ImagePreViewEntity(original, absolutePath, imageScale + 3.0f,
                ImageSource.uri(Uri.fromFile(file)), new ImageViewState(imageScale, new PointF(0, 0), 0)));
        final int nextIndex = index + 1;
        if (nextIndex == data.size()) {
            listener.onComplete(imageData);
        } else {
            handlePreViewImageItem(nextIndex, data, imageData, listener);
        }
    });
}
 
Example #2
Source File: SubsamplingScaleImageView.java    From Matisse-Kotlin with Apache License 2.0 6 votes vote down vote up
/**
 * Double tap zoom handler triggered from gesture detector or on touch, depending on whether
 * quick scale is enabled.
 */
private void doubleTapZoom(PointF sCenter, PointF vFocus) {
    if (!panEnabled) {
        if (sRequestedCenter != null) {
            // With a center specified from code, zoom around that point.
            sCenter.x = sRequestedCenter.x;
            sCenter.y = sRequestedCenter.y;
        } else {
            // With no requested center, scale around the image center.
            sCenter.x = sWidth()/2;
            sCenter.y = sHeight()/2;
        }
    }
    float doubleTapZoomScale = Math.min(maxScale, SubsamplingScaleImageView.this.doubleTapZoomScale);
    boolean zoomIn = scale <= doubleTapZoomScale * 0.9;
    float targetScale = zoomIn ? doubleTapZoomScale : minScale();
    if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) {
        setScaleAndCenter(targetScale, sCenter);
    } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn || !panEnabled) {
        new AnimationBuilder(targetScale, sCenter).withInterruptible(false).withDuration(doubleTapZoomDuration).withOrigin(ORIGIN_DOUBLE_TAP_ZOOM).start();
    } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) {
        new AnimationBuilder(targetScale, sCenter, vFocus).withInterruptible(false).withDuration(doubleTapZoomDuration).withOrigin(ORIGIN_DOUBLE_TAP_ZOOM).start();
    }
    invalidate();
}
 
Example #3
Source File: Layout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @param e                 The {@link MotionEvent} to consider.
 * @param offsets           The current touch offsets that should be applied to the
 *                          {@link EventFilter}s.
 * @param isKeyboardShowing Whether or not the keyboard is showing.
 * @return The {@link EventFilter} the {@link Layout} is listening to.
 */
public EventFilter findInterceptingEventFilter(
        MotionEvent e, PointF offsets, boolean isKeyboardShowing) {
    // The last added overlay will be drawn on top of everything else, therefore the last
    // filter added should have the first chance to intercept any touch events.
    for (int i = mSceneOverlays.size() - 1; i >= 0; i--) {
        EventFilter eventFilter = mSceneOverlays.get(i).getEventFilter();
        if (eventFilter == null) continue;
        if (offsets != null) eventFilter.setCurrentMotionEventOffsets(offsets.x, offsets.y);
        if (eventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) return eventFilter;
    }

    EventFilter layoutEventFilter = getEventFilter();
    if (layoutEventFilter != null) {
        if (offsets != null) {
            layoutEventFilter.setCurrentMotionEventOffsets(offsets.x, offsets.y);
        }
        if (layoutEventFilter.onInterceptTouchEvent(e, isKeyboardShowing)) {
            return layoutEventFilter;
        }
    }
    return null;
}
 
Example #4
Source File: GestureImageView.java    From ViewPagerTabIndicator with Artistic License 2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    viewSize = new PointF(width, height);

    //��ȡ��ǰDrawable�Ĵ�С
    Drawable drawable = getDrawable();
    if (drawable == null) {
        Log.e("no drawable", "drawable is nullPtr");
    } else {
        imageSize = new PointF(drawable.getMinimumWidth(), drawable.getMinimumHeight());
    }

    FitCenter();
}
 
Example #5
Source File: TouchManagerView.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
protected Region getRegion(final PointF startPoint, final PointF endPoint) {
    final float width = getWidth();
    final float height = getHeight();
    final float xStep = width / GRID_X;
    final float yStep = height / GRID_Y;

    final float cellWidth = 100 / GRID_X;
    final float cellHeight = 100 / GRID_X;

    float left = MathUtils.fmin(startPoint.x, endPoint.x);
    float right = MathUtils.fmax(startPoint.x, endPoint.x);
    float top = MathUtils.fmin(startPoint.y, endPoint.y);
    float bottom = MathUtils.fmax(startPoint.y, endPoint.y);

    left = cellWidth * (float) Math.floor(left / xStep);
    right = cellWidth * (float) Math.floor(right / xStep) + cellWidth;
    top = cellHeight * (float) Math.floor(top / yStep);
    bottom = cellHeight * (float) Math.floor(bottom / yStep) + cellHeight;

    return new Region(MathUtils.rect(left, top, right, bottom));
}
 
Example #6
Source File: OC_SectionIT.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public void setUpDragObjectsForEvent(String ev)
{
    Map<String,Object> event = (Map<String, Object>) eventsDict.get(ev);
    Map<String, Map<String, Object>> objectsdict = (Map<String, Map<String, Object>>) event.get("objectsdict");

    for (String k : objectsdict.keySet())
    {
        OBControl c = objectDict.get(k);
        PointF pt = c.position();
        c.setProperty("origpos",new PointF(pt.x,pt.y));
        c.setProperty("destpos",pointFromObjectsDict(objectsdict,k));
        Map<String,Object>odict = objectsdict.get(k);
        Map<String,Object>oattrs = (Map<String, Object>) odict.get("attrs");
        String fstr = (String) oattrs.get("scalex");
        if (fstr != null)
        {
            c.setProperty("scale",c.scale());
            float f = Float.parseFloat(fstr);
            c.setProperty("destscale",f);
        }
        c.setProperty("destcontainer",oattrs.get("parent"));
    }
}
 
Example #7
Source File: ImageControlActivity.java    From GestureViews with Apache License 2.0 6 votes vote down vote up
private void resetImage(boolean animate) {
    final GestureController controller = imageView.getController();

    if (controller.isAnimating()) {
        return; // Waiting for animation end
    }

    if (animate) {
        final State state = controller.getState().copy();
        final PointF pivot = getPivot();

        // Restoring initial image zoom and rotation
        final float minZoom = controller.getStateController().getMinZoom(state);
        state.zoomTo(minZoom, pivot.x, pivot.y);
        state.rotateTo(0f, pivot.x, pivot.y);

        // Animating state changes. Do not forget to make a state's copy prior to any changes.
        controller.setPivot(pivot.x, pivot.y);
        controller.animateStateTo(state);
    } else {
        // Immediately resetting the state
        controller.resetState();
    }
}
 
Example #8
Source File: Camera1.java    From Lassi-Android with MIT License 6 votes vote down vote up
@Override
void setExposureCorrection(final float EVvalue, @NonNull final float[] bounds,
                           @Nullable final PointF[] points, final boolean notify) {
    schedule(mExposureCorrectionTask, true, new Runnable() {
        @Override
        public void run() {
            if (!mCameraOptions.isExposureCorrectionSupported()) return;

            float value = EVvalue;
            float max = mCameraOptions.getExposureCorrectionMaxValue();
            float min = mCameraOptions.getExposureCorrectionMinValue();
            value = value < min ? min : value > max ? max : value; // cap
            mExposureCorrectionValue = value;
            Camera.Parameters params = mCamera.getParameters();
            int indexValue = (int) (value / params.getExposureCompensationStep());
            params.setExposureCompensation(indexValue);
            mCamera.setParameters(params);

            if (notify) {
                mCameraCallbacks.dispatchOnExposureCorrectionChanged(value, bounds, points);
            }
        }
    });
}
 
Example #9
Source File: OC_PlayZoneMenu.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public void moveMediaIconsBySpeedFrac(float frameFrac)
{
    float speedX = (float)mediaIconsGroup.propertyValue("speedx");
    if(speedX == 0)
        return;
    PointF loc = OBMisc.copyPoint(mediaIconsGroup.position());
    loc.x += speedX * frameFrac;
    float decay = (float)Math.pow(0.99f,frameFrac);
    if(Math.abs(speedX) > MAX_SPEED*0.1)
        speedX *= decay;
    else
        speedX = 0;
    if(!setMediaIconsGroupLoc(loc))
    {
        setControlSpeed(mediaIconsGroup,0.0f,0.0f);
    }
    else
    {
        setControlSpeed(mediaIconsGroup,speedX,0.0f);
    }
}
 
Example #10
Source File: BeaconMap.java    From BLE-Indoor-Positioning with Apache License 2.0 6 votes vote down vote up
protected void drawDeviceHistory(Canvas canvas) {
    PointF deviceCenter;
    float heatmapRadius = (float) canvasProjection.getCanvasUnitsFromMeters(1);
    float recencyScore;
    int alpha;

    for (Location location : recentLocations) {
        if (location == null || !location.hasLatitudeAndLongitude()) {
            continue;
        }
        deviceCenter = getPointFromLocation(location);
        recencyScore = getRecencyScore(location.getTimestamp(), TimeUnit.SECONDS.toMillis(10));
        alpha = (int) (255 * 0.25 * recencyScore);
        historyFillPaint.setAlpha(alpha);
        RadialGradient gradient = new RadialGradient(deviceCenter.x, deviceCenter.y, heatmapRadius,
                new int[]{secondaryFillPaint.getColor(), Color.TRANSPARENT}, null, Shader.TileMode.CLAMP);
        historyFillPaint.setShader(gradient);
        canvas.drawCircle(deviceCenter.x, deviceCenter.y, heatmapRadius, historyFillPaint);
    }
}
 
Example #11
Source File: FaceGraphic.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
private void drawHat(Canvas canvas, PointF facePosition, float faceWidth, float faceHeight, PointF noseBasePosition) {
    final float HAT_FACE_WIDTH_RATIO = (float)(4.0 / 4.0);
    final float HAT_FACE_HEIGHT_RATIO = (float)(3.0 / 6.0);
    final float HAT_CENTER_Y_OFFSET_FACTOR = (float)(1.0 / 8.0);

    float hatCenterY = facePosition.y + (faceHeight * HAT_CENTER_Y_OFFSET_FACTOR);
    float hatWidth = faceWidth * HAT_FACE_WIDTH_RATIO;
    float hatHeight = faceHeight * HAT_FACE_HEIGHT_RATIO;

    int left = (int)(noseBasePosition.x - (hatWidth / 2));
    int right = (int)(noseBasePosition.x + (hatWidth / 2));
    int top = (int)(hatCenterY - (hatHeight / 2));
    int bottom = (int)(hatCenterY + (hatHeight / 2));
    mHatGraphic.setBounds(left, top, right, bottom);
    mHatGraphic.draw(canvas);
}
 
Example #12
Source File: DragPinchManager.java    From AndroidPDF with Apache License 2.0 5 votes vote down vote up
@Override
public void onPinch(float dr, PointF pivot) {
    float wantedZoom = pdfView.getZoom() * dr;
    if (wantedZoom < MINIMUM_ZOOM) {
        dr = MINIMUM_ZOOM / pdfView.getZoom();
    } else if (wantedZoom > MAXIMUM_ZOOM) {
        dr = MAXIMUM_ZOOM / pdfView.getZoom();
    }
    pdfView.zoomCenteredRelativeTo(dr, pivot);
}
 
Example #13
Source File: SmileBar.java    From SmileBar with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    for (int i = 0; i < MAX_RATE; i++) {
        PointF pos = points[i];
        canvas.save();
        canvas.translate(pos.x, pos.y);
        drawSmile(canvas, i);
        canvas.restore();
    }
}
 
Example #14
Source File: DistancedSort.java    From spruce-android with MIT License 5 votes vote down vote up
@Override
public void sortChildren(ViewGroup parent, List<View> children) {
    final PointF comparisonPoint = getDistancePoint(parent, children);
    Collections.sort(children, new Comparator<View>() {
        @Override
        public int compare(View left, View right) {
            double leftDistance = getDistanceBetweenPoints(Utils.viewToPoint(left), comparisonPoint);
            double rightDistance = getDistanceBetweenPoints(Utils.viewToPoint(right), comparisonPoint);
            if (reversed) {
                return Double.compare(rightDistance, leftDistance);
            }
            return Double.compare(leftDistance, rightDistance);
        }
    });
}
 
Example #15
Source File: CustomSubsamplingScaleImageView.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
public void longTapZoom(int x, int y) {
    if (zoomEnabled && longTapZoomEnabled && readySent) {

        vCenterStart = new PointF(x, y);
        PointF sCenter = viewToSourceCoord(vCenterStart);

        new AnimationBuilder(doubleTapZoomScale, sCenter).withInterruptible(false).withDuration(doubleTapZoomDuration).withOrigin(AnimOrigin.LONG_TAP_ZOOM).start();

        isPanning = true;
        isLongTapZooming = true;
        // Panning gesture management will align itself on the new vTranslate coordinates calculated by the animator
        vTranslateStart = null;
    }
}
 
Example #16
Source File: PointMath.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private static List<PointF> simplificationOf(List<PointF> vertices, double distanceThreshold) {
    List<PointF> simplifiedVertices = new ArrayList<>();
    Double maxDistance = null;
    int maxDistancePointFIdx = 0;
    int lastPointFIdx = vertices.size() - 1;
    int currentIdx = 0;
    for (PointF aVertex : vertices) {
        if (currentIdx != 0 && currentIdx != lastPointFIdx) {
            Double distance = shortestDistanceToSegment(aVertex, vertices.get(0), vertices.get(lastPointFIdx));
            if (maxDistance == null || distance > maxDistance) {
                maxDistancePointFIdx = currentIdx;
                maxDistance = distance;
            }
        }
        currentIdx++;
    }

    if (maxDistance != null) {
        if (maxDistance > distanceThreshold) {
            List<PointF> sub = simplify(vertices.subList(0, maxDistancePointFIdx + 1), distanceThreshold);
            List<PointF> sup = simplify(vertices.subList(maxDistancePointFIdx, lastPointFIdx + 1), distanceThreshold);

            simplifiedVertices.addAll(sub);
            simplifiedVertices.addAll(sup);

        } else {
            simplifiedVertices.add(vertices.get(0));
            simplifiedVertices.add(vertices.get(lastPointFIdx));
        }
    }
    return simplifiedVertices;
}
 
Example #17
Source File: StrokeElement.java    From cidrawing with Apache License 2.0 5 votes vote down vote up
@Override
protected void cloneTo(BaseElement element) {
    super.cloneTo(element);
    if (element instanceof StrokeElement) {
        StrokeElement obj = (StrokeElement) element;
        if (points != null) {
            obj.points = new ArrayList<>();
            for (PointF p : points) {
                obj.points.add(new PointF(p.x, p.y));
            }
        }
        obj.closeStroke = closeStroke;
    }
}
 
Example #18
Source File: OB_Maths.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public static PointF cubicbez(float t, float c0x, float c0y, float c1x, float c1y)
{
    float p0x = 0f,p0y = 0f;
    float p1x = 1.0f, p1y = 1.0f;
    float tprime = 1.0f - t;
    float tprime2 = tprime * tprime;
    float t2 = t * t;
    float f0x = p0x * tprime * tprime2,f0y = p0y * tprime * tprime2;
    float fc0x = c0x * tprime2 * 3 * t,fc0y = c0y * tprime2 * 3 * t;
    float fc1x = c1x * tprime * t2 * 3,fc1y = c1y * tprime * t2 * 3;
    float f1x = t2 * t * p1x,f1y = t2 * t * p1y;
    return new PointF(f0x+fc0x+fc1x+f1x,f0y+fc0y+fc1y+f1y);
}
 
Example #19
Source File: TouchImageView.java    From Ecommerce-Retronight-Android with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);        
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX , finalY);
}
 
Example #20
Source File: OC_Spell3.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public void setSceneXX(String  scene)
{
    super.setSceneXX(scene);
    dashes = layOutDashesForLabels(staticLabels);
    int i = 0;
    for(OBLabel sl : staticLabels)
    {
        PointF pt = new PointF();
        pt.set(sl.position());
        pt.x = dashes.get(i).position().x;
        sl.setPosition(pt);
        sl.setProperty("dashpos",pt);
        i++;
    }
}
 
Example #21
Source File: BarLineChartTouchListener.java    From Notification-Analyser with MIT License 5 votes vote down vote up
/**
 * returns the correct translation depending on the provided x and y touch
 * points
 * 
 * @param e
 * @return
 */
public PointF getTrans(float x, float y) {

    float xTrans = x - mChart.getOffsetLeft();
    float yTrans = 0f;

    // check if axis is inverted
    if (!mChart.isInvertYAxisEnabled()) {
        yTrans = -(mChart.getMeasuredHeight() - y - mChart.getOffsetBottom());
    } else {
        yTrans = -(y - mChart.getOffsetTop());
    }

    return new PointF(xTrans, yTrans);
}
 
Example #22
Source File: HeightBehavior.java    From Carbon with Apache License 2.0 5 votes vote down vote up
@Override
public PointF onScroll(float scrollX, float scrollY) {
    if (direction == Direction.Down && scrollY > 0 || direction == Direction.Up && scrollY < 0)
        return new PointF(scrollX, scrollY);
    int height = getTarget().getHeight();
    int newHeight = (int) MathUtils.constrain(height - scrollY, minHeight, maxHeight);
    setHeight(newHeight);
    float scrollLeft = 0;
    if (scrollY > 0) {
        scrollLeft = Math.max(0, scrollY - (height - newHeight));
    } else {
        scrollLeft = Math.max(0, -scrollY - (newHeight - height));
    }
    return new PointF(scrollX, scrollLeft);
}
 
Example #23
Source File: AnimatablePathValue.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public BaseKeyframeAnimation<?, PointF> createAnimation() {
  if (!hasAnimation()) {
    return new StaticKeyframeAnimation<>(initialPoint);
  }

  return new PathKeyframeAnimation(keyframes);
}
 
Example #24
Source File: SubsamplingScaleImageView.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * Creates a scale animation builder, that when started will animate a zoom in or out. If this would move the image
 * beyond the panning limits, the image is automatically panned during the animation.
 * @param scale Target scale.
 * @param sCenter Target source center.
 * @return {@link AnimationBuilder} instance. Call {@link AnimationBuilder#start()} to start the anim.
 */
@Nullable
public AnimationBuilder animateScaleAndCenter(float scale, PointF sCenter) {
    if (!isReady()) {
        return null;
    }
    return new AnimationBuilder(scale, sCenter);
}
 
Example #25
Source File: CameraUtil.java    From 361Camera with Apache License 2.0 5 votes vote down vote up
public static PointF normalizedSensorCoordsForNormalizedDisplayCoords(
        float nx, float ny, int sensorOrientation) {
    switch (sensorOrientation) {
        case 0:
            return new PointF(nx, ny);
        case 90:
            return new PointF(ny, 1.0f - nx);
        case 180:
            return new PointF(1.0f - nx, 1.0f - ny);
        case 270:
            return new PointF(1.0f - ny, nx);
        default:
            return null;
    }
}
 
Example #26
Source File: OC_Alpha1.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public void layOutBoxes()
{
    OBPath c = (OBPath) objectDict.get("_box1");
    PointF topleft = c.position();
    c = (OBPath) objectDict.get("_box2");
    PointF bottomright = c.position();
    boxLowColour = c.fillColor();
    List<OBControl> mBoxes = new ArrayList<>();
    int i = 0,row=0,col=0;
    float y = topleft.y;
    yinc = bottomright.y - y;
    while(i < letters.size() )
    {
        OBControl box = c.copy();
        float x = OB_Maths.interpolateVal(topleft.x, bottomright.x, col * 1.0f /(boxesPerRow - 1));
        box.setPosition(x, y);
        attachControl(box);
        mBoxes.add(box);
        i++;
        col++;
        if(col >= boxesPerRow)
        {
            row++;
            col = 0;
            y += yinc;
        }
    }
    boxes = mBoxes;
    c = (OBPath) objectDict.get("boxhiswatch");
    boxHighColour = c.fillColor();
}
 
Example #27
Source File: OC_SectionController.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public void moveScenePointer(PointF point, float time, String audio, float wait) throws Exception
{
    movePointerToPoint(point,time,true);
    if (audio != null)
    {
        playAudio(audio);
        waitAudio();
    }
    waitForSecs(wait);
}
 
Example #28
Source File: FaceDetectorUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public FaceParsed camera2Parse(Face face, View view, PointF scale, int rotation,
    boolean isFrontCamera) {
  //Parse face
  RectF rect = new RectF(face.getBounds());
  Matrix matrix = new Matrix();
  matrix.setScale(isFrontCamera ? -1 : 1, 1);
  matrix.postRotate(rotation);
  matrix.postScale(1f, 1f);
  matrix.postTranslate(view.getWidth(), view.getHeight());
  matrix.mapRect(rect);
  return getFace(rect, scale, view);
}
 
Example #29
Source File: PathUnit.java    From InDoorSurfaceView with Apache License 2.0 5 votes vote down vote up
public PathUnit(List<PointF> list) {
    int i = 0;
    path = new Path();
    for (PointF point : list) {
        if (i == 0) path.moveTo(point.x, point.y);
        path.lineTo(point.x, point.y);
        i++;
    }
    RectF rectF = new RectF();
    path.computeBounds(rectF, true);
    region = new Region();
    region.setPath(path, new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
}
 
Example #30
Source File: PhotoImageView.java    From MoeQuest with Apache License 2.0 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 *
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {

  matrix.getValues(m);
  float origW = getDrawable().getIntrinsicWidth();
  float origH = getDrawable().getIntrinsicHeight();
  float px = bx / origW;
  float py = by / origH;
  float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
  float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
  return new PointF(finalX, finalY);
}