Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let visibility of "laser scanner" be set #503

Merged
merged 6 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sample/src/main/java/example/zxing/CustomScannerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
capture.decode();

changeMaskColor(null);
changeLaserVisibility(true);
}

@Override
Expand Down Expand Up @@ -102,6 +103,10 @@ public void changeMaskColor(View view) {
viewfinderView.setMaskColor(color);
}

public void changeLaserVisibility(boolean visible) {
viewfinderView.setLaserVisibility(visible);
}

@Override
public void onTorchOn() {
switchFlashlightButton.setText(R.string.turn_off_flashlight);
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/layout/custom_barcode_scanner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
app:zxing_possible_result_points="@color/zxing_custom_possible_result_points"
app:zxing_result_view="@color/zxing_custom_result_view"
app:zxing_viewfinder_laser="@color/zxing_custom_viewfinder_laser"
app:zxing_viewfinder_laser_visibility="true"
app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask"/>

<TextView
Expand Down
1 change: 1 addition & 0 deletions zxing-android-embedded/res/values/zxing_attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<attr name="zxing_result_view" format="color"/>
<attr name="zxing_viewfinder_laser" format="color"/>
<attr name="zxing_viewfinder_mask" format="color"/>
<attr name="zxing_viewfinder_laser_visibility" format="boolean"/>
</declare-styleable>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ViewfinderView extends View {
protected final int resultColor;
protected final int laserColor;
protected final int resultPointColor;
protected boolean laserVisibility;
protected int scannerAlpha;
protected List<ResultPoint> possibleResultPoints;
protected List<ResultPoint> lastPossibleResultPoints;
Expand Down Expand Up @@ -84,6 +85,8 @@ public ViewfinderView(Context context, AttributeSet attrs) {
resources.getColor(R.color.zxing_viewfinder_laser));
this.resultPointColor = attributes.getColor(R.styleable.zxing_finder_zxing_possible_result_points,
resources.getColor(R.color.zxing_possible_result_points));
this.laserVisibility = attributes.getBoolean(R.styleable.zxing_finder_zxing_viewfinder_laser_visibility,
true);

attributes.recycle();

Expand Down Expand Up @@ -160,13 +163,16 @@ public void onDraw(Canvas canvas) {
paint.setAlpha(CURRENT_POINT_OPACITY);
canvas.drawBitmap(resultBitmap, null, frame, paint);
} else {
// If wanted, draw a red "laser scanner" line through the middle to show decoding is active
if (laserVisibility) {
paint.setColor(laserColor);

// Draw a red "laser scanner" line through the middle to show decoding is active
paint.setColor(laserColor);
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;
final int middle = frame.height() / 2 + frame.top;
canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
paint.setAlpha(SCANNER_ALPHA[scannerAlpha]);
scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length;

final int middle = frame.height() / 2 + frame.top;
canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint);
}

final float scaleX = this.getWidth() / (float) previewSize.width;
final float scaleY = this.getHeight() / (float) previewSize.height;
Expand Down Expand Up @@ -247,4 +253,8 @@ public void addPossibleResultPoint(ResultPoint point) {
public void setMaskColor(int maskColor) {
this.maskColor = maskColor;
}

public void setLaserVisibility(boolean visible) {
this.laserVisibility = visible;
}
}