use of com.google.zxing.ResultPoint in project BlogSource by TeachCourse.
the class ViewfinderView method onDraw.
@Override
public void onDraw(Canvas canvas) {
// 中间的扫描框,你要修改扫描框的大小,去CameraManager里面修改
Rect frame = cameraManager.getFramingRect();
if (frame == null) {
return;
}
// 初始化中间线滑动的最上边和最下边
if (!isFirst) {
isFirst = true;
slideTop = frame.top;
slideBottom = frame.bottom;
}
// 获取屏幕的宽和高
int width = canvas.getWidth();
int height = canvas.getHeight();
paint.setColor(resultBitmap != null ? resultColor : maskColor);
// 画出扫描框外面的阴影部分,共四个部分,扫描框的上面到屏幕上面,扫描框的下面到屏幕下面,扫描框的左边面到屏幕左边,扫描框的右边到屏幕右边
canvas.drawRect(0, 0, width, frame.top, paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
if (resultBitmap != null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(OPAQUE);
canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
} else {
// Draw a two pixel solid black border inside the framing rect
paint.setColor(0xffffffff);
canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint);
canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint);
canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, paint);
canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, paint);
// 这里画取景框四个角落的夹角
paint.setColor(0xff0ec3ff);
paint.setAntiAlias(true);
canvas.drawRect(frame.left - CORNER_WIDTH + 2, frame.top - CORNER_WIDTH + 2, frame.left + ScreenRate - CORNER_WIDTH + 2, frame.top + 2, paint);
canvas.drawRect(frame.left - CORNER_WIDTH + 2, frame.top - CORNER_WIDTH + 2, frame.left + 2, frame.top + ScreenRate - CORNER_WIDTH + 2, paint);
canvas.drawRect(frame.right - ScreenRate + CORNER_WIDTH - 2, frame.top - CORNER_WIDTH + 2, frame.right + CORNER_WIDTH - 2, frame.top + 2, paint);
canvas.drawRect(frame.right - 2, frame.top - CORNER_WIDTH + 2, frame.right + CORNER_WIDTH - 2, frame.top + ScreenRate - CORNER_WIDTH + 2, paint);
canvas.drawRect(frame.left - CORNER_WIDTH + 2, frame.bottom - 2, frame.left + ScreenRate - CORNER_WIDTH + 2, frame.bottom + CORNER_WIDTH - 2, paint);
canvas.drawRect(frame.left - CORNER_WIDTH + 2, frame.bottom - ScreenRate + CORNER_WIDTH - 2, frame.left + 2, frame.bottom + CORNER_WIDTH - 2, paint);
canvas.drawRect(frame.right - ScreenRate + CORNER_WIDTH - 2, frame.bottom - 2, frame.right + CORNER_WIDTH - 2, frame.bottom + CORNER_WIDTH - 2, paint);
canvas.drawRect(frame.right - 2, frame.bottom - ScreenRate + CORNER_WIDTH - 2, frame.right + CORNER_WIDTH - 2, frame.bottom + CORNER_WIDTH - 2, paint);
// 绘制中间的线,每次刷新界面,中间的线往下移动SPEEN_DISTANCE
slideTop += SPEEN_DISTANCE;
if (slideTop >= frame.bottom) {
slideTop = frame.top;
}
Rect lineRect = new Rect();
lineRect.left = frame.left;
lineRect.right = frame.right;
lineRect.top = slideTop;
lineRect.bottom = slideTop + 18;
canvas.drawBitmap(((BitmapDrawable) (getResources().getDrawable(R.drawable.qr_scan_line))).getBitmap(), null, lineRect, paint);
/**
* 不显示关键点
* Collection<ResultPoint> currentPossible = possibleResultPoints;
* Collection<ResultPoint> currentLast = lastPossibleResultPoints;
* if (currentPossible.isEmpty()) {
* lastPossibleResultPoints = null;
* } else {
* possibleResultPoints = new HashSet<ResultPoint>(5);
* lastPossibleResultPoints = currentPossible;
* paint.setAlpha(OPAQUE);
* paint.setColor(resultPointColor);
* for (ResultPoint point : currentPossible) {
* canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);
* }
* }
* if (currentLast != null) {
* paint.setAlpha(OPAQUE / 2);
* paint.setColor(resultPointColor);
* for (ResultPoint point : currentLast) {
* canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint);
* }
* }
*/
// 只刷新扫描框的内容,其他地方不刷新
postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);
}
}
use of com.google.zxing.ResultPoint in project MyBaseApplication by BanShouWeng.
the class ViewfinderView method onDraw.
@Override
public void onDraw(Canvas canvas) {
try {
// 中间的扫描框,你要修改扫描框的大小,去CameraManager里面修改
Rect frame = cameraManager.getFramingRect();
Rect frame1 = new Rect();
frame1.top = frame.top + frameAdjust;
frame1.bottom = frame.bottom - frameAdjust;
frame1.left = frame.left + frameAdjust;
frame1.right = frame.right - frameAdjust;
if (frame == null) {
return;
}
// 初始化中间线滑动的最上边和最下边
if (!isFirst) {
isFirst = true;
slideTop = frame.top;
slideBottom = frame.bottom;
}
// 获取屏幕的宽和高
int width = canvas.getWidth();
int height = canvas.getHeight();
paint.setColor(resultBitmap != null ? resultColor : maskColor);
// 画出扫描框外面的阴影部分,共四个部分,扫描框的上面到屏幕上面,扫描框的下面到屏幕下面
// 扫描框的左边面到屏幕左边,扫描框的右边到屏幕右边
canvas.drawRect(0, 0, width, frame1.top, paint);
canvas.drawRect(0, frame1.top, frame1.left, frame1.bottom + 1, paint);
canvas.drawRect(frame1.right + 1, frame1.top, width, frame1.bottom + 1, paint);
canvas.drawRect(0, frame1.bottom + 1, width, height, paint);
if (resultBitmap != null) {
paint.setAlpha(OPAQUE);
canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
} else {
paint.setColor(getResources().getColor(R.color.blue_border));
canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, frame.top + CORNER_WIDTH, paint);
canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + ScreenRate, paint);
canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, frame.top + CORNER_WIDTH, paint);
canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + ScreenRate, paint);
canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + ScreenRate, frame.bottom, paint);
canvas.drawRect(frame.left, frame.bottom - ScreenRate, frame.left + CORNER_WIDTH, frame.bottom, paint);
canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, frame.right, frame.bottom, paint);
canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, frame.right, frame.bottom, paint);
slideTop += SPEEN_DISTANCE;
if (slideTop >= frame.bottom) {
slideTop = frame.top;
}
// canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - MIDDLE_LINE_WIDTH / 2, frame.right - MIDDLE_LINE_PADDING, slideTop + MIDDLE_LINE_WIDTH / 2, paint);
Rect lineRect = new Rect();
lineRect.left = frame.left;
lineRect.right = frame.right;
lineRect.top = slideTop;
lineRect.bottom = slideTop + 18;
canvas.drawBitmap(((BitmapDrawable) (getResources().getDrawable(R.mipmap.scan_code_pic))).getBitmap(), null, lineRect, paint);
// ��ɨ����������
paint.setColor(getResources().getColor(android.R.color.transparent));
Rect rect = new Rect((int) (TEXT_PADDING_TOP * density), (int) (frame.bottom + (float) TEXT_PADDING_TOP * density * 4), width - (int) (TEXT_PADDING_TOP * density), frame.bottom);
canvas.drawRect(rect, paint);
paint.setColor(Color.WHITE);
paint.setTextSize(TEXT_SIZE * density);
paint.setAlpha(0x90);
paint.setTypeface(Typeface.create("System", Typeface.NORMAL));
paint.setTextAlign(Paint.Align.CENTER);
Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
canvas.drawText("扫一扫", rect.centerX(), rect.centerY(), paint);
Collection<ResultPoint> currentPossible = possibleResultPoints;
Collection<ResultPoint> currentLast = lastPossibleResultPoints;
if (currentPossible.isEmpty()) {
lastPossibleResultPoints = null;
} else {
possibleResultPoints = new HashSet<ResultPoint>(5);
lastPossibleResultPoints = currentPossible;
paint.setAlpha(OPAQUE);
paint.setColor(resultPointColor);
for (ResultPoint point : currentPossible) {
canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);
}
}
/* if (currentLast != null) {
*/
/*paint.setAlpha(OPAQUE / 2);
paint.setColor(resultPointColor);
for (ResultPoint point : currentLast) {
canvas.drawCircle(frame.left + point.getX(), frame.top
+ point.getY(), 3.0f, paint);
}*/
/*
}*/
// ֻˢ��ɨ�������ݣ�����ط���ˢ��
postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);
}
} catch (Exception e) {
Log.e("扫一扫", e.getMessage());
}
}
use of com.google.zxing.ResultPoint in project krypton-android by kryptco.
the class AdminScan method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_teams_invite_inperson_scan, container, false);
lastScannedPayload.set(null);
barcodeView = v.findViewById(R.id.camera_preview_in_person_scan);
barcodeView.decodeContinuous(new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
if (result.getText() != null) {
try {
Sigchain.MemberQRPayload qr = JSON.fromJson(result.getText(), Sigchain.QRPayload.class).memberQRPayload;
if (qr == null) {
Error.shortToast(getContext(), "Make sure you are scanning a member that is trying to join the team.");
return;
}
if (lastScannedPayload.compareAndSet(null, qr)) {
Transitions.beginSlide(AdminScan.this).addToBackStack(null).replace(R.id.fragmentOverlay, new AdminVerify()).commitAllowingStateLoss();
} else {
Log.i(TAG, "not first scan");
}
} catch (JsonParseException e) {
Log.e(TAG, "could not parse QR code", e);
Error.shortToast(getContext(), "Invalid QR code");
}
}
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
}
});
AppCompatTextView detailText = v.findViewById(R.id.inPersonScanDetail);
detailText.setText("Scan your team member's QR code to add them to your team.");
return v;
}
use of com.google.zxing.ResultPoint in project wechat by motianhuo.
the class ViewfinderView method onDraw.
@Override
public void onDraw(Canvas canvas) {
Rect frame = CameraManager.get().getFramingRect();
if (frame == null) {
return;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap != null ? resultColor : maskColor);
canvas.drawRect(0, 0, width, frame.top, paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
if (resultBitmap != null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(OPAQUE);
canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
} else {
int linewidht = 10;
paint.setColor(frameColor);
canvas.drawRect(15 + frame.left, 15 + frame.top, 15 + (linewidht + frame.left), 15 + (50 + frame.top), paint);
canvas.drawRect(15 + frame.left, 15 + frame.top, 15 + (50 + frame.left), 15 + (linewidht + frame.top), paint);
canvas.drawRect(-15 + ((0 - linewidht) + frame.right), 15 + frame.top, -15 + (1 + frame.right), 15 + (50 + frame.top), paint);
canvas.drawRect(-15 + (-50 + frame.right), 15 + frame.top, -15 + frame.right, 15 + (linewidht + frame.top), paint);
canvas.drawRect(15 + frame.left, -15 + (-49 + frame.bottom), 15 + (linewidht + frame.left), -15 + (1 + frame.bottom), paint);
canvas.drawRect(15 + frame.left, -15 + ((0 - linewidht) + frame.bottom), 15 + (50 + frame.left), -15 + (1 + frame.bottom), paint);
canvas.drawRect(-15 + ((0 - linewidht) + frame.right), -15 + (-49 + frame.bottom), -15 + (1 + frame.right), -15 + (1 + frame.bottom), paint);
canvas.drawRect(-15 + (-50 + frame.right), -15 + ((0 - linewidht) + frame.bottom), -15 + frame.right, -15 + (linewidht - (linewidht - 1) + frame.bottom), paint);
paint.setColor(laserColor);
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
// juns 2015年5月13日16:36:29 去掉中间+
int vmiddle = frame.height() / 2 + frame.top;
int hmiddle = frame.width() / 2 + frame.left;
canvas.drawRect(frame.left + 2, vmiddle - 1, frame.right - 1, vmiddle + 2, paint);
canvas.drawRect(hmiddle - 1, frame.top + 2, hmiddle + 2, frame.bottom - 1, paint);
Collection<ResultPoint> currentPossible = possibleResultPoints;
Collection<ResultPoint> currentLast = lastPossibleResultPoints;
if (currentPossible.isEmpty()) {
lastPossibleResultPoints = null;
} else {
possibleResultPoints = new HashSet<ResultPoint>(5);
lastPossibleResultPoints = currentPossible;
paint.setAlpha(OPAQUE);
paint.setColor(resultPointColor);
for (ResultPoint point : currentPossible) {
canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);
}
}
if (currentLast != null) {
paint.setAlpha(OPAQUE / 2);
paint.setColor(resultPointColor);
for (ResultPoint point : currentLast) {
canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint);
}
}
// Request another update at the animation interval, but only
// repaint the laser line,
// not the entire viewfinder mask.
postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);
}
}
use of com.google.zxing.ResultPoint in project android-zxingLibrary by yipianfengye.
the class ViewfinderView method onDraw.
@Override
public void onDraw(Canvas canvas) {
Rect frame = CameraManager.get().getFramingRect();
if (frame == null) {
return;
}
int width = canvas.getWidth();
int height = canvas.getHeight();
// Draw the exterior (i.e. outside the framing rect) darkened
paint.setColor(resultBitmap != null ? resultColor : maskColor);
canvas.drawRect(0, 0, width, frame.top, paint);
canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
canvas.drawRect(0, frame.bottom + 1, width, height, paint);
if (resultBitmap != null) {
// Draw the opaque result bitmap over the scanning rectangle
paint.setAlpha(OPAQUE);
canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
} else {
drawFrameBounds(canvas, frame);
drawScanLight(canvas, frame);
Collection<ResultPoint> currentPossible = possibleResultPoints;
Collection<ResultPoint> currentLast = lastPossibleResultPoints;
if (currentPossible.isEmpty()) {
lastPossibleResultPoints = null;
} else {
possibleResultPoints = new HashSet<ResultPoint>(5);
lastPossibleResultPoints = currentPossible;
paint.setAlpha(OPAQUE);
paint.setColor(resultPointColor);
if (isCircle) {
for (ResultPoint point : currentPossible) {
canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);
}
}
}
if (currentLast != null) {
paint.setAlpha(OPAQUE / 2);
paint.setColor(resultPointColor);
if (isCircle) {
for (ResultPoint point : currentLast) {
canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint);
}
}
}
postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);
}
}
Aggregations