143 lines
5.4 KiB
Java
143 lines
5.4 KiB
Java
package com.google.zxing.client.android;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.LinearGradient;
|
|
import android.graphics.Paint;
|
|
import android.graphics.Rect;
|
|
import android.graphics.Shader;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import com.google.zxing.ResultPoint;
|
|
import com.google.zxing.client.android.camera.CameraManager;
|
|
import com.ubtrobot.jimu.robotapi.PeripheralType;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class ViewfinderView extends View {
|
|
private static final int[] i = {0, 64, PeripheralType.SERVO, 192, 255, 192, PeripheralType.SERVO, 64};
|
|
private CameraManager a;
|
|
private final Paint b;
|
|
private Bitmap c;
|
|
private final int d;
|
|
private final int e;
|
|
private final int[] f;
|
|
private int g;
|
|
private List<ResultPoint> h;
|
|
|
|
public ViewfinderView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.b = new Paint(1);
|
|
Resources resources = getResources();
|
|
this.d = resources.getColor(R$color.viewfinder_mask);
|
|
this.e = resources.getColor(R$color.result_view);
|
|
resources.getColor(R$color.possible_result_points);
|
|
this.f = new int[]{getResources().getColor(R$color.laser_start), getResources().getColor(R$color.laser_end), getResources().getColor(R$color.laser_start)};
|
|
this.g = 0;
|
|
this.h = new ArrayList(5);
|
|
}
|
|
|
|
private void a(Canvas canvas, Rect rect) {
|
|
int width = canvas.getWidth();
|
|
int height = canvas.getHeight();
|
|
int dimensionPixelSize = getResources().getDimensionPixelSize(R$dimen.corner_width);
|
|
this.b.setColor(this.c != null ? this.e : this.d);
|
|
float f = width;
|
|
canvas.drawRect(0.0f, 0.0f, f, rect.top, this.b);
|
|
canvas.drawRect(0.0f, rect.top, rect.left, rect.bottom + 1, this.b);
|
|
canvas.drawRect(rect.right + 1, rect.top, f, rect.bottom + 1, this.b);
|
|
canvas.drawRect(0.0f, rect.bottom + 1, f, height, this.b);
|
|
this.b.setAlpha(255);
|
|
Bitmap decodeResource = BitmapFactory.decodeResource(getResources(), R$drawable.scan_ic_top_left);
|
|
Rect rect2 = new Rect(0, 0, decodeResource.getWidth(), decodeResource.getHeight());
|
|
int i2 = rect.left;
|
|
int i3 = rect.top;
|
|
canvas.drawBitmap(decodeResource, (Rect) null, new Rect(i2, i3, i2 + dimensionPixelSize, i3 + dimensionPixelSize), this.b);
|
|
canvas.save();
|
|
int i4 = dimensionPixelSize / 2;
|
|
canvas.rotate(90.0f, rect.right - i4, rect.top + i4);
|
|
int i5 = rect.right;
|
|
int i6 = rect.top;
|
|
canvas.drawBitmap(decodeResource, rect2, new Rect(i5 - dimensionPixelSize, i6, i5, i6 + dimensionPixelSize), this.b);
|
|
canvas.restore();
|
|
canvas.save();
|
|
canvas.rotate(180.0f, rect.right - i4, rect.bottom - i4);
|
|
int i7 = rect.right;
|
|
int i8 = rect.bottom;
|
|
canvas.drawBitmap(decodeResource, rect2, new Rect(i7 - dimensionPixelSize, i8 - dimensionPixelSize, i7, i8), this.b);
|
|
canvas.restore();
|
|
canvas.save();
|
|
canvas.rotate(270.0f, rect.left + i4, rect.bottom - i4);
|
|
int i9 = rect.left;
|
|
int i10 = rect.bottom;
|
|
canvas.drawBitmap(decodeResource, rect2, new Rect(i9, i10 - dimensionPixelSize, dimensionPixelSize + i9, i10), this.b);
|
|
canvas.restore();
|
|
}
|
|
|
|
private void b(Canvas canvas, Rect rect) {
|
|
this.b.setAlpha(i[this.g]);
|
|
this.g = (this.g + 1) % i.length;
|
|
int height = (rect.height() / 2) + rect.top;
|
|
int dimensionPixelSize = getResources().getDimensionPixelSize(R$dimen.laser_height) / 2;
|
|
this.b.setShader(new LinearGradient(rect.left + 2, height - 1, rect.right - 1, height + 2, this.f, (float[]) null, Shader.TileMode.REPEAT));
|
|
canvas.drawRect(rect.left + 2, height - dimensionPixelSize, rect.right - 1, height + dimensionPixelSize, this.b);
|
|
this.b.setShader(null);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
@SuppressLint({"DrawAllocation"})
|
|
public void onDraw(Canvas canvas) {
|
|
CameraManager cameraManager = this.a;
|
|
if (cameraManager == null) {
|
|
return;
|
|
}
|
|
Rect c = cameraManager.c();
|
|
Rect d = this.a.d();
|
|
if (c == null || d == null) {
|
|
return;
|
|
}
|
|
a(canvas, c);
|
|
if (this.c != null) {
|
|
this.b.setAlpha(160);
|
|
canvas.drawBitmap(this.c, (Rect) null, c, this.b);
|
|
} else {
|
|
b(canvas, c);
|
|
postInvalidateDelayed(80L, c.left - 6, c.top - 6, c.right + 6, c.bottom + 6);
|
|
}
|
|
}
|
|
|
|
public void setCameraManager(CameraManager cameraManager) {
|
|
this.a = cameraManager;
|
|
}
|
|
|
|
public void a() {
|
|
Bitmap bitmap = this.c;
|
|
this.c = null;
|
|
if (bitmap != null) {
|
|
bitmap.recycle();
|
|
}
|
|
invalidate();
|
|
}
|
|
|
|
public void a(Bitmap bitmap) {
|
|
this.c = bitmap;
|
|
invalidate();
|
|
}
|
|
|
|
public void a(ResultPoint resultPoint) {
|
|
List<ResultPoint> list = this.h;
|
|
synchronized (list) {
|
|
list.add(resultPoint);
|
|
int size = list.size();
|
|
if (size > 20) {
|
|
list.subList(0, size - 10).clear();
|
|
}
|
|
}
|
|
}
|
|
}
|