下面列出了android.graphics.RectF#offsetTo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
@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);
}
}
@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));
}
}
@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));
}
}
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());
}
@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);
}
@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);
}