android.graphics.RectF#offset ( )源码实例Demo

下面列出了android.graphics.RectF#offset ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: fritz-examples   文件: CameraConnectionFragment.java
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale =
                Math.max(
                        (float) viewHeight / previewSize.getHeight(),
                        (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}
 
源代码2 项目: Paideia   文件: CameraConnectionFragment.java
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
  final Activity activity = getActivity();
  if (null == textureView || null == previewSize || null == activity) {
    return;
  }
  final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  final Matrix matrix = new Matrix();
  final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  final float centerX = viewRect.centerX();
  final float centerY = viewRect.centerY();
  if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
    bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
    matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
    final float scale =
        Math.max(
            (float) viewHeight / previewSize.getHeight(),
            (float) viewWidth / previewSize.getWidth());
    matrix.postScale(scale, scale, centerX, centerY);
    matrix.postRotate(90 * (rotation - 2), centerX, centerY);
  } else if (Surface.ROTATION_180 == rotation) {
    matrix.postRotate(180, centerX, centerY);
  }
  textureView.setTransform(matrix);
}
 
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale =
                Math.max(
                        (float) viewHeight / previewSize.getHeight(),
                        (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}
 
private void computeWindowBoundsInScreen(WindowState windowState, Rect outBounds) {
    // Get the touchable frame.
    Region touchableRegion = mTempRegion1;
    windowState.getTouchableRegion(touchableRegion);
    Rect touchableFrame = mTempRect;
    touchableRegion.getBounds(touchableFrame);

    // Move to origin as all transforms are captured by the matrix.
    RectF windowFrame = mTempRectF;
    windowFrame.set(touchableFrame);
    windowFrame.offset(-windowState.mFrame.left, -windowState.mFrame.top);

    // Map the frame to get what appears on the screen.
    Matrix matrix = mTempMatrix;
    populateTransformationMatrixLocked(windowState, matrix);
    matrix.mapRect(windowFrame);

    // Got the bounds.
    outBounds.set((int) windowFrame.left, (int) windowFrame.top,
            (int) windowFrame.right, (int) windowFrame.bottom);
}
 
源代码5 项目: DeviceConnect-Android   文件: Camera2Wrapper.java
/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    Size previewSize = mSettings.getPreviewSize();
    int rotation = Camera2Helper.getDisplayRotation(mContext);
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
 
源代码6 项目: polling-station-app   文件: CameraFragment.java
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
public void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
    overlay.setRect(CameraFragmentUtil.getScanRect(scanSegment));
}
 
源代码7 项目: Cam2Caption   文件: Camera2BasicFragment.java
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
 
源代码8 项目: fritz-examples   文件: CameraConnectionFragment.java
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale =
                Math.max(
                        (float) viewHeight / previewSize.getHeight(),
                        (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}
 
源代码9 项目: MultiMediaSample   文件: Camera2Fragment.java
/**
 * Configures the necessary {@link Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max(
                (float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
}
 
/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 */
private void configureTransform(int viewWidth, int viewHeight) {
    if (isViewAvailable()) {
        if (null == activityView.getTextureView()) {
            return;
        }
        int rotation = activityView.getWindowManager().getDefaultDisplay().getRotation();
        Matrix matrix = new Matrix();
        RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
        RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
        float centerX = viewRect.centerX();
        float centerY = viewRect.centerY();
        if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
            bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
            matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
            float scale = Math.max(
                    (float) viewHeight / previewSize.getHeight(),
                    (float) viewWidth / previewSize.getWidth());
            matrix.postScale(scale, scale, centerX, centerY);
            matrix.postRotate(90 * (rotation - 2), centerX, centerY);
        } else if (Surface.ROTATION_180 == rotation) {
            matrix.postRotate(180, centerX, centerY);
        }
        activityView.getTextureView().setTransform(matrix);
    }
}
 
/** Center move only changes the position of the crop window without changing the size. */
private void moveCenter(
    RectF rect, float x, float y, RectF bounds, int viewWidth, int viewHeight, float snapRadius) {
  float dx = x - rect.centerX();
  float dy = y - rect.centerY();
  if (rect.left + dx < 0
      || rect.right + dx > viewWidth
      || rect.left + dx < bounds.left
      || rect.right + dx > bounds.right) {
    dx /= 1.05f;
    mTouchOffset.x -= dx / 2;
  }
  if (rect.top + dy < 0
      || rect.bottom + dy > viewHeight
      || rect.top + dy < bounds.top
      || rect.bottom + dy > bounds.bottom) {
    dy /= 1.05f;
    mTouchOffset.y -= dy / 2;
  }
  rect.offset(dx, dy);
  snapEdgesToBounds(rect, bounds, snapRadius);
}
 
源代码12 项目: GLEXP-Team-onebillion   文件: OC_Count20_S4.java
public void setSceneXX(String scene)
{
    if (currentSceneIsPriorToScene("4l"))
    {
        currNo++;
        OBControl obj = objectDict.get(String.format("obj%d",currNo+1));
        RectF f = obj.frame;
        PointF currPos = obj.position();
        PointF origPos = (PointF)obj.propertyValue("origpos");
        PointF offset = OB_Maths.DiffPoints(origPos, currPos);
        f.offset(offset.x, offset.y);
        OBControl dottedline = objectDict.get("dottedline");
        PointF pt = OBUtils.pointFromString(((Map<String,String>)dottedline.propertyValue("attrs")).get("pos"));
        pt = OB_Maths.locationForRect(pt, f );
        dottedline.setPosition(pt);
        dottedline.show();
    }
    else
    {
        loadEvent(scene);
        String s = eventAttributes.get("targetno");
        if (s != null)
            currNo = Integer.parseInt(s)-11;
    }
}
 
/**
 * Adjust top and bottom edges by current crop window width and the given aspect ratio, both top
 * and bottom edges adjusts equally relative to center to keep aspect ratio to the width.
 */
private void adjustTopBottomByAspectRatio(RectF rect, RectF bounds, float aspectRatio) {
  rect.inset(0, (rect.height() - rect.width() / aspectRatio) / 2);
  if (rect.top < bounds.top) {
    rect.offset(0, bounds.top - rect.top);
  }
  if (rect.bottom > bounds.bottom) {
    rect.offset(0, bounds.bottom - rect.bottom);
  }
}
 
源代码14 项目: document-viewer   文件: SinglePageController.java
private void invalidatePageSize(final PageAlign pageAlign, final Page page, final int width, final int height) {
    final RectF pageBounds = calcPageBounds(pageAlign, page.getAspectRatio(), width, height);
    // if the screen is larger than the page, center the page within the screen
    final float pageWidth = pageBounds.width();
    if (width > pageWidth) {
        final float widthDelta = (width - pageWidth) / 2;
        pageBounds.offset(widthDelta, 0);
    }
    final float pageHeight= pageBounds.height();
    if (height > pageHeight) {
        final float heightDelta = (height - pageHeight) / 2;
        pageBounds.offset(0, heightDelta);
    }
    page.setBounds(pageBounds);
}
 
源代码15 项目: Lassi-Android   文件: CropWindowMoveHandler.java
/**
 * Adjust left and right edges by current crop window height and the given aspect ratio, both
 * right and left edges adjusts equally relative to center to keep aspect ratio to the height.
 */
private void adjustLeftRightByAspectRatio(RectF rect, RectF bounds, float aspectRatio) {
    rect.inset((rect.width() - rect.height() * aspectRatio) / 2, 0);
    if (rect.left < bounds.left) {
        rect.offset(bounds.left - rect.left, 0);
    }
    if (rect.right > bounds.right) {
        rect.offset(bounds.right - rect.right, 0);
    }
}
 
源代码16 项目: giffun   文件: CropWindowMoveHandler.java
/** Check if edges have gone out of bounds (including snap margin), and fix if needed. */
private void snapEdgesToBounds(RectF edges, RectF bounds, float margin) {
  if (edges.left < bounds.left + margin) {
    edges.offset(bounds.left - edges.left, 0);
  }
  if (edges.top < bounds.top + margin) {
    edges.offset(0, bounds.top - edges.top);
  }
  if (edges.right > bounds.right - margin) {
    edges.offset(bounds.right - edges.right, 0);
  }
  if (edges.bottom > bounds.bottom - margin) {
    edges.offset(0, bounds.bottom - edges.bottom);
  }
}
 
private float calculateRevealCenterY(
    @NonNull View dependency, @NonNull View child, @NonNull Positioning positioning) {
  RectF dependencyBounds = tmpRectF1;
  RectF childBounds = tmpRectF2;

  calculateDependencyWindowBounds(dependency, dependencyBounds);
  calculateWindowBounds(child, childBounds);

  float translationY = calculateTranslationY(dependency, child, positioning);
  childBounds.offset(0, -translationY);

  return dependencyBounds.centerY() - childBounds.top;
}
 
源代码18 项目: YGuider   文件: ScanTarget.java
public RectF viewToRegion(int offsetX, int offsetY){
    if (!mIsRegion){
        RectF rectF = getViewLocationRectF(mTargetView);
        rectF.offset(offsetX,offsetY);
        setRegion(rectF);
    }
    return mRegion;
}
 
private static void cornerArc(Path path, float cx, float cy, float r, float startAngle, float sweepAngle) {
	final RectF ovalRect = new RectF(-r, -r, r, r);
	ovalRect.offset(cx, cy);
	path.arcTo(ovalRect, startAngle, sweepAngle);
}
 
源代码20 项目: XERUNG   文件: HighlightView.java
void growBy(float dx, float dy) {
    if (maintainAspectRatio) {
        if (dx != 0) {
            dy = dx / initialAspectRatio;
        } else if (dy != 0) {
            dx = dy * initialAspectRatio;
        }
    }

    // Don't let the cropping rectangle grow too fast.
    // Grow at most half of the difference between the image rectangle and
    // the cropping rectangle.
    RectF r = new RectF(cropRect);
    if (dx > 0F && r.width() + 2 * dx > imageRect.width()) {
        dx = (imageRect.width() - r.width()) / 2F;
        if (maintainAspectRatio) {
            dy = dx / initialAspectRatio;
        }
    }
    if (dy > 0F && r.height() + 2 * dy > imageRect.height()) {
        dy = (imageRect.height() - r.height()) / 2F;
        if (maintainAspectRatio) {
            dx = dy * initialAspectRatio;
        }
    }

    r.inset(-dx, -dy);

    // Don't let the cropping rectangle shrink too fast
    final float widthCap = 25F;
    if (r.width() < widthCap) {
        r.inset(-(widthCap - r.width()) / 2F, 0F);
    }
    float heightCap = maintainAspectRatio
            ? (widthCap / initialAspectRatio)
            : widthCap;
    if (r.height() < heightCap) {
        r.inset(0F, -(heightCap - r.height()) / 2F);
    }

    // Put the cropping rectangle inside the image rectangle
    if (r.left < imageRect.left) {
        r.offset(imageRect.left - r.left, 0F);
    } else if (r.right > imageRect.right) {
        r.offset(-(r.right - imageRect.right), 0F);
    }
    if (r.top < imageRect.top) {
        r.offset(0F, imageRect.top - r.top);
    } else if (r.bottom > imageRect.bottom) {
        r.offset(0F, -(r.bottom - imageRect.bottom));
    }

    cropRect.set(r);
    drawRect = computeLayout();
    viewContext.invalidate();
}