zxing-android-embedded
zxing-android-embedded copied to clipboard
Hardcoded color in ViewFinderView?
Description of the problem:
PS: If this have any similar issue that can help me please just closed this issue
Hi I tried to customize the color attribute in DecoratedBarcodeView from the xml layout.
Even if I have the access to zxing_possible_result_points, zxing_viewfinder_laser and etc, I can't seems to change the color even if I assign color code to it
Is there anyway I can change the color (Such as laser color, mask color and etc) without tempering with the library files?
I have the same problem , mask color & laser attributes seem no useful
Laser's alpha value is being animated in values {0, 64, 128, 192, 255, 192, 128, 64}
. See field SCANNER_ALPHA
in ViewfinderView
.
What's actually happens is this alpha value is "set" to transparent color (#00000000) and it changes to black (#FF000000).
The only workaround I can think is to change this SCANNER_ALPHA
array values to have only one 0
value.
private fun disableLaser(decoratedBarcodeView: DecoratedBarcodeView) {
val scannerAlphaField = ViewfinderView::class.java.getDeclaredField("SCANNER_ALPHA")
scannerAlphaField.isAccessible = true
scannerAlphaField.set(decoratedBarcodeView.viewFinder, intArrayOf(0))
}
Thanks for the pointer into the correct direction, I had to change the code a bit until it worked for me:
barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner);
barcodeView.decodeContinuous(callback);
ViewfinderView viewFinder = barcodeView.getViewFinder();
Field scannerAlphaField = null;
try {
scannerAlphaField = viewFinder.getClass().getDeclaredField("SCANNER_ALPHA");
scannerAlphaField.setAccessible(true);
scannerAlphaField.set(viewFinder, new int[1]);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
I would like to work on this bug, any objection?
Pull requests for this would be appreciated.
Will do, can you assign the issue to me?
Thanks for the pointer into the correct direction, I had to change the code a bit until it worked for me:
barcodeView = (DecoratedBarcodeView) findViewById(R.id.barcode_scanner); barcodeView.decodeContinuous(callback); ViewfinderView viewFinder = barcodeView.getViewFinder(); Field scannerAlphaField = null; try { scannerAlphaField = viewFinder.getClass().getDeclaredField("SCANNER_ALPHA"); scannerAlphaField.setAccessible(true); scannerAlphaField.set(viewFinder, new int[1]); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); }
This worked for me, Thanks