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

how i can make edge color in CompoundBarcodeView #352

Closed
YanisSalos opened this issue Nov 28, 2017 · 12 comments
Closed

how i can make edge color in CompoundBarcodeView #352

YanisSalos opened this issue Nov 28, 2017 · 12 comments

Comments

@YanisSalos
Copy link

YanisSalos commented Nov 28, 2017

how i can make edge color blue in CompoundBarcodeView

like this : https://lh6.ggpht.com/-LHkE5TWqK0bWUdreGY2m28wJa9YsMvkkXiL-1u7ZRcBs2gXP8bsTTpo9IWWdY1hhaw=w170

I have search but i didnt reach my point please help and thanks

@kronismax
Copy link

I also would like to know how to do it.

@bhavesh-hirpara
Copy link

Did anyone find solution. Im still not getting.

@kronismax
Copy link

kronismax commented Dec 21, 2017

@luminousman @YanisSalos
in ViewfinderView add following in onDraw method:

Paint paint1 = new Paint();
paint1.setColor(context.getResources().getColor(R.color.zxing_colorAccent));
int frameLength = (int) (32 * getResources().getDisplayMetrics().density + 0.5f);
int frameWidth = (int) (3 * getResources().getDisplayMetrics().density + 0.5f);
canvas.drawRect(frame.left, frame.top, frame.left + frameLength, frame.top + frameWidth, paint1);
canvas.drawRect(frame.left, frame.top, frame.left + frameWidth, frame.top + frameLength, paint1);
canvas.drawRect(frame.left, frame.bottom - frameLength, frame.left + frameWidth, frame.bottom, paint1);
canvas.drawRect(frame.left, frame.bottom - frameWidth, frame.left + frameLength, frame.bottom, paint1);
canvas.drawRect(frame.right - frameWidth, frame.bottom - frameLength, frame.right, frame.bottom, paint1);
canvas.drawRect(frame.right - frameLength, frame.bottom - frameWidth, frame.right, frame.bottom, paint1);
canvas.drawRect(frame.right - frameWidth, frame.top, frame.right, frame.top + frameLength, paint1);
canvas.drawRect(frame.right - frameLength, frame.top, frame.right, frame.top + frameWidth, paint1);

it is not optimized but works
To modify this class you should import module as gradle project and include it in setting.gradle. Also remove compile dependecies from build.gralde file in app folder.

@romaopedro
Copy link

romaopedro commented Jan 9, 2018

The simple solution is to follow the custom scanner activity. Create a new layout and there you can add a view your background.

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:parentTag="android.widget.LinearLayout">

    <com.journeyapps.barcodescanner.BarcodeView
        android:id="@+id/zxing_barcode_surface"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:zxing_framing_rect_height="250dp"
        app:zxing_framing_rect_width="250dp" />

    <!-- This view makes magic -->
    <View
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="@drawable/img_qr_frame"
        android:layout_gravity="center">
    </View>

    <com.journeyapps.barcodescanner.ViewfinderView
        android:id="@+id/zxing_viewfinder_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:zxing_possible_result_points="@color/color_secundary_green"
        app:zxing_result_view="@color/zxing_custom_result_view"
        app:zxing_viewfinder_laser="@color/color_secundary_green"
        app:zxing_viewfinder_mask="@color/zxing_custom_viewfinder_mask" />

    <TextView
        android:id="@+id/zxing_status_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:background="@color/zxing_transparent"
        android:text="@string/zxing_msg_default_status"
        android:textColor="@color/zxing_status_text" />

</merge>

@beryindo
Copy link

beryindo commented Mar 19, 2018

Can you spesific for tutorial ? how to Mainactivity connecting to new custom layout ?

@pedroromao-acceptto
Copy link

Step by step:

  1. Create a custom layout.
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:orientation="vertical"
    tools:parentTag="android.widget.LinearLayout">

    <com.journeyapps.barcodescanner.BarcodeView
        android:id="@+id/zxing_barcode_surface"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:zxing_framing_rect_height="250dp"
        app:zxing_framing_rect_width="250dp" />

    <View
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_gravity="center"
        android:background="@drawable/img_qr_frame" />

    <com.journeyapps.barcodescanner.ViewfinderView
        android:id="@+id/zxing_viewfinder_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:zxing_possible_result_points="@color/color_secundary_green"
        app:zxing_result_view="@color/zxing_custom_result_view"
        app:zxing_viewfinder_laser="@color/color_secundary_green"
        app:zxing_viewfinder_mask="@android:color/transparent" />

    <com.accepttomobile.common.ui.customviews.GloberTextView
        android:id="@+id/zxing_status_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:background="@color/zxing_transparent"
        android:text="@string/zxing_msg_default_status"
        android:textColor="@color/zxing_status_text"
        android:visibility="gone"/>

</merge>
  1. Create a layout for you activity and include the previous custom layout.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.journeyapps.barcodescanner.CompoundBarcodeView
        android:id="@+id/scanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:zxing_scanner_layout="@layout/qrcode_custom" />

    <FrameLayout
        android:id="@+id/fl_scanner"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
  1. Create an activity and set the layout with some of the logic
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_qrcode_scanner)


        mBarcodeScannerView = findViewById(R.id.scanner)
        mCaptureManager = CaptureManager(this, mBarcodeScannerView!!)
        mCaptureManager?.initializeFromIntent(intent, savedInstanceState)
        mCaptureManager?.decode()
        mBarcodeScannerView?.decodeSingle(object : BarcodeCallback {
            override fun barcodeResult(result: BarcodeResult?) {

                if (result != null) {
                    if (!result.text.isNullOrBlank()) {
                        finishWithData(false, result.text)
                    } else {
                        finishWithData(false, null)
                    }
                } else {
                    finishWithData(false, null)
                }
            }

            override fun possibleResultPoints(resultPoints: MutableList<ResultPoint>?) {

            }
        })
        mBarcodeScannerView?.resume()
    }

@beryindo
Copy link

beryindo commented Apr 1, 2018

I am can't found mBarcodeScannerView, mCaptureManager. I am uses implementation 'com.journeyapps:zxing-android-embedded:3.6.0@aar'

@pedroromao-acceptto
Copy link

pedroromao-acceptto commented Apr 1, 2018

mBarcodeScannerView = CompoundBarcodeView
mCaptureManager = CaptureManager

@beryindo next time dont bother to make a question without searching on repository. The samples has all you need with CaptureManager.

@chathura2020
Copy link

here is how I achieved it - https://stackoverflow.com/a/50556050/1134412
the code should go inside the onDraw method of ViewfinderView class. Hope this helps :)

@pedrooa
Copy link

pedrooa commented Jun 10, 2018

@chathura2020 Sorry for the ignorance, but how exactly were you able to edit the ViewfinderView class?
did you import the project locally in android studio?

@chathura2020
Copy link

@pedrooa yes, I keep the library source locally

@rkistner
Copy link
Member

rkistner commented Sep 7, 2019

Thanks for the examples posted here.

Note that you don't need to copy the entire library if you want to modify this - you only need to copy and modify ViewfinderView and DecoratedBarcodeView.

@rkistner rkistner closed this as completed Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants