zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

Hardcoded color in ViewFinderView?

Open JerryThl opened this issue 7 years ago • 7 comments

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?

capture screenshot_20171102-130637

JerryThl avatar Nov 02 '17 05:11 JerryThl

I have the same problem , mask color & laser attributes seem no useful

YouthLee avatar Dec 05 '17 06:12 YouthLee

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))
    }

rafakob avatar Dec 17 '17 15:12 rafakob

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();
        }

robertschulze avatar Feb 26 '18 00:02 robertschulze

I would like to work on this bug, any objection?

ippschi avatar Oct 17 '19 09:10 ippschi

Pull requests for this would be appreciated.

rkistner avatar Oct 17 '19 09:10 rkistner

Will do, can you assign the issue to me?

ippschi avatar Oct 17 '19 09:10 ippschi

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

thomas-b-n-davis avatar Nov 16 '19 15:11 thomas-b-n-davis