Java Code Examples for android.graphics.RectF#offsetTo()

The following examples show how to use android.graphics.RectF#offsetTo() . 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: ScanActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    try {
        final Camera camera = cameraManager.open(previewView, displayRotation(), !DISABLE_CONTINUOUS_AUTOFOCUS);

        final Rect framingRect = cameraManager.getFrame();
        final RectF framingRectInPreview = new RectF(cameraManager.getFramePreview());
        framingRectInPreview.offsetTo(0, 0);
        final boolean cameraFlip = cameraManager.getFacing() == CameraInfo.CAMERA_FACING_FRONT;
        final int cameraRotation = cameraManager.getOrientation();

        runOnUiThread(() -> scannerView.setFraming(framingRect, framingRectInPreview, displayRotation(), cameraRotation, cameraFlip));

        final String focusMode = camera.getParameters().getFocusMode();
        final boolean nonContinuousAutoFocus = Camera.Parameters.FOCUS_MODE_AUTO.equals(focusMode)
                || Camera.Parameters.FOCUS_MODE_MACRO.equals(focusMode);

        if (nonContinuousAutoFocus)
            cameraHandler.post(new AutoFocusRunnable(camera));

        cameraHandler.post(fetchAndDecodeRunnable);
    } catch (final Exception x) {
        Log.d(Config.LOGTAG, "problem opening camera", x);
    }
}
 
Example 2
Source File: ScanActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
	try {
		final Camera camera = cameraManager.open(previewView, displayRotation(), !DISABLE_CONTINUOUS_AUTOFOCUS);

		final Rect framingRect = cameraManager.getFrame();
		final RectF framingRectInPreview = new RectF(cameraManager.getFramePreview());
		framingRectInPreview.offsetTo(0, 0);
		final boolean cameraFlip = cameraManager.getFacing() == CameraInfo.CAMERA_FACING_FRONT;
		final int cameraRotation = cameraManager.getOrientation();

		runOnUiThread(() -> scannerView.setFraming(framingRect, framingRectInPreview, displayRotation(), cameraRotation, cameraFlip));

		final String focusMode = camera.getParameters().getFocusMode();
		final boolean nonContinuousAutoFocus = Camera.Parameters.FOCUS_MODE_AUTO.equals(focusMode)
				|| Camera.Parameters.FOCUS_MODE_MACRO.equals(focusMode);

		if (nonContinuousAutoFocus)
			cameraHandler.post(new AutoFocusRunnable(camera));

		cameraHandler.post(fetchAndDecodeRunnable);
	} catch (final Exception x) {
		Log.d(Config.LOGTAG, "problem opening camera", x);
	}
}
 
Example 3
Source File: ScanActivity.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    try {
        final Camera camera = cameraManager.open(previewView, displayRotation());

        final Rect framingRect = cameraManager.getFrame();
        final RectF framingRectInPreview = new RectF(cameraManager.getFramePreview());
        framingRectInPreview.offsetTo(0, 0);
        final boolean cameraFlip = cameraManager.getFacing() == Camera.CameraInfo.CAMERA_FACING_FRONT;
        final int cameraRotation = cameraManager.getOrientation();

        runOnUiThread(() ->
                      scannerView.setFraming(framingRect, framingRectInPreview, displayRotation(),
                                             cameraRotation,
                                             cameraFlip));

        final String focusMode = camera.getParameters().getFocusMode();
        final boolean nonContinuousAutoFocus = Camera.Parameters.FOCUS_MODE_AUTO.equals(focusMode)
                                               || Camera.Parameters.FOCUS_MODE_MACRO.equals(focusMode);

        if (nonContinuousAutoFocus)
            cameraHandler.post(new AutoFocusRunnable(camera));

        maybeTriggerSceneTransition();
        cameraHandler.post(fetchAndDecodeRunnable);
    } catch (final Exception x) {
        log.info("problem opening camera", x);
        runOnUiThread(() -> showDialog(DIALOG_CAMERA_PROBLEM));
    }
}
 
Example 4
Source File: ScanForResultActivity.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    try {
        final Camera camera = cameraManager.open(previewView, displayRotation());

        final Rect framingRect = cameraManager.getFrame();
        final RectF framingRectInPreview = new RectF(cameraManager.getFramePreview());
        framingRectInPreview.offsetTo(0, 0);
        final boolean cameraFlip = cameraManager.getFacing() == Camera.CameraInfo.CAMERA_FACING_FRONT;
        final int cameraRotation = cameraManager.getOrientation();

        runOnUiThread(() -> scannerView.setFraming(framingRect, framingRectInPreview, displayRotation(),
                                                   cameraRotation,
                                                   cameraFlip));

        final String focusMode = camera.getParameters().getFocusMode();
        final boolean nonContinuousAutoFocus = Camera.Parameters.FOCUS_MODE_AUTO.equals(focusMode)
                                               || Camera.Parameters.FOCUS_MODE_MACRO.equals(focusMode);

        if (nonContinuousAutoFocus)
            cameraHandler.post(new AutoFocusRunnable(camera));

        maybeTriggerSceneTransition();
        cameraHandler.post(fetchAndDecodeRunnable);
    } catch (final Exception x) {
        log.info("problem opening camera", x);
        runOnUiThread(() -> showDialog(DIALOG_CAMERA_PROBLEM));
    }
}
 
Example 5
Source File: FabTransformationBehavior.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void calculateWindowBounds(@NonNull View view, RectF rect) {
  RectF windowBounds = rect;
  windowBounds.set(0, 0, view.getWidth(), view.getHeight());

  int[] windowLocation = tmpArray;
  view.getLocationInWindow(windowLocation);

  windowBounds.offsetTo(windowLocation[0], windowLocation[1]);

  // We specifically want to take into account the transformations of all parents only.
  // The idea is that only this transformation should modify the translation of the views itself.
  windowBounds.offset((int) -view.getTranslationX(), (int) -view.getTranslationY());
}
 
Example 6
Source File: PieChart.java    From EazeGraph with Apache License 2.0 5 votes vote down vote up
@Override
protected void onGraphSizeChanged(int w, int h, int oldw, int oldh) {
    super.onGraphSizeChanged(w, h, oldw, oldh);

    // Figure out how big we can make the pie.
    mPieDiameter = Math.min(w, h);
    mPieRadius = mPieDiameter / 2.f;
    // calculate the left and right space to be center aligned
    float centeredValueWidth  = (w - mPieDiameter) / 2f;
    float centeredValueHeight = (h - mPieDiameter) / 2f;
    mGraphBounds = new RectF(
            0.0f,
            0.0f,
            mPieDiameter,
            mPieDiameter);
    mGraphBounds.offsetTo(centeredValueWidth, centeredValueHeight);

    mCalculatedInnerPadding         = (mPieRadius / 100) * mInnerPadding;
    mCalculatedInnerPaddingOutline  = (mPieRadius / 100) * mInnerPaddingOutline;

    mInnerBounds = new RectF(
            mGraphBounds.centerX() - mCalculatedInnerPadding - mCalculatedInnerPaddingOutline,
            mGraphBounds.centerY() - mCalculatedInnerPadding - mCalculatedInnerPaddingOutline,
            mGraphBounds.centerX() + mCalculatedInnerPadding + mCalculatedInnerPaddingOutline,
            mGraphBounds.centerY() + mCalculatedInnerPadding + mCalculatedInnerPaddingOutline);

    mInnerOutlineBounds = new RectF(
            mGraphBounds.centerX() - mCalculatedInnerPadding,
            mGraphBounds.centerY() - mCalculatedInnerPadding,
            mGraphBounds.centerX() + mCalculatedInnerPadding,
            mGraphBounds.centerY() + mCalculatedInnerPadding);
}
 
Example 7
Source File: VirtualKeyboard.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public boolean pointerDragged(int pointer, float x, float y) {
	if (skip) {
		return checkPointerHandled(x, y);
	}
	switch (layoutEditMode) {
		case LAYOUT_EOF:
			if (pointer > associatedKeys.length) {
				return checkPointerHandled(x, y);
			}
			if (associatedKeys[pointer] == null) {
				pointerPressed(pointer, x, y);
			} else if (!associatedKeys[pointer].contains(x, y)) {
				repeater.remove(associatedKeys[pointer]);
				target.postKeyReleased(associatedKeys[pointer].getKeyCode());
				if (associatedKeys[pointer].getSecondKeyCode() != 0) {
					target.postKeyReleased(associatedKeys[pointer].getSecondKeyCode());
				}
				associatedKeys[pointer].setSelected(false);
				associatedKeys[pointer] = null;
				repaint();
				pointerPressed(pointer, x, y);
			}
			break;
		case LAYOUT_KEYS:
			if (editedIndex >= 0) {
				RectF rect = keypad[editedIndex].getRect();
				rect.offsetTo(x - offsetX, y - offsetY);
				snapModes[editedIndex] = RectSnap.NO_SNAP;
				for (int i = 0; i < keypad.length; i++) {
					if (i != editedIndex && findSnap(editedIndex, i)) {
						break;
					}
				}
				if (snapModes[editedIndex] == RectSnap.NO_SNAP) {
					snapModes[editedIndex] = RectSnap.getSnap(rect, screen, snapOffsets[editedIndex]);
					snapOrigins[editedIndex] = SCREEN;
					if (Math.abs(snapOffsets[editedIndex].x) <= snapRadius) {
						snapOffsets[editedIndex].x = 0;
					}
					if (Math.abs(snapOffsets[editedIndex].y) <= snapRadius) {
						snapOffsets[editedIndex].y = 0;
					}
				}
				snapKey(editedIndex, 0);
				snapKeys();
				repaint();
			}
			break;
		case LAYOUT_SCALES:
			float dx = x - offsetX;
			float dy = offsetY - y;
			float delta;
			if (Math.abs(dx) > Math.abs(dy)) {
				delta = dx;
			} else {
				delta = dy;
			}
			float scale = prevScale + delta / Math.max(screen.width(), screen.height());
			if (Math.abs(1 - scale) <= SCALE_SNAP_RADIUS) {
				scale = 1;
			} else {
				for (int i = 0; i < keyScales.length; i++) {
					if (i != editedIndex && Math.abs(keyScales[i] - scale) <= SCALE_SNAP_RADIUS) {
						scale = keyScales[i];
						break;
					}
				}
			}
			keyScales[editedIndex] = scale;
			resizeKeyGroup(editedIndex);
			snapKeys();
			repaint();
			break;
	}
	return checkPointerHandled(x, y);
}