Customize the camera view for Qr scanner using zbar lib

255 views
Skip to first unread message

amitj...@gmail.com

unread,
Oct 14, 2015, 9:12:07 AM10/14/15
to CodenameOne Discussions
I am using the Zbar library for scanning the QR code. Its working fine but I want to customize the camera view during scanning the QR code. Its opening in full screen, but I want to show it in a small screen inside my application.

Here is my Native code for it. Any help should be appreciated

        final android.app.Activity ctx = com.codename1.impl.android.AndroidNativeUtil.getActivity();
       Intent intent = new Intent(ctx, ZBarScannerActivity.class);
       intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
       intent.setSourceBounds(new Rect(5,5,25,25));  // This did not work , in re-sizing the camera view
       com.codename1.impl.android.AndroidNativeUtil.startActivityForResult(intent, new IntentResultListener() {
           public void onActivityResult(int requestCode, int resultCode, Intent data) {
               if (resultCode == Activity.RESULT_OK) {
               
                   QRScanner.getCallback().scanCompleted(data.getStringExtra(ZBarConstants.SCAN_RESULT), "QRCODE", data.getStringExtra(ZBarConstants.SCAN_RESULT).getBytes());
               } else if (resultCode == Activity.RESULT_CANCELED) {
                   if (data != null) {
                       String error = data.getStringExtra(ZBarConstants.ERROR_INFO);
                       if (!TextUtils.isEmpty(error)) {
                           QRScanner.getCallback().scanError(100, error);
                       } else {
                           QRScanner.getCallback().scanCanceled();
                       }
                   } else {
                       QRScanner.getCallback().scanCanceled();
                   }
               }
           }
       });
   }

Shai Almog

unread,
Oct 14, 2015, 10:58:55 PM10/14/15
to CodenameOne Discussions, amitj...@gmail.com
In order to show it within the app you will need to have an API that returns a View that you can embed rather than an Activity.
Then in a native interface use a PeerComponent as the returned component.

amitj...@gmail.com

unread,
Oct 15, 2015, 3:08:00 AM10/15/15
to CodenameOne Discussions, amitj...@gmail.com
Can you provide me a sample code for it, as its not clear from the description provided.

Shai Almog

unread,
Oct 15, 2015, 11:48:01 PM10/15/15
to CodenameOne Discussions, amitj...@gmail.com
Sure, the Google Maps implementation uses a PeerComponent to show its view: https://github.com/codenameone/codenameone-google-maps

amitj...@gmail.com

unread,
Oct 16, 2015, 9:14:52 AM10/16/15
to CodenameOne Discussions, amitj...@gmail.com
I tried looking thru the code specified in the link below, but was not able to understand it completely. Tried few times to integrate it with my code as pasted above but its giving me errors (like: My Native app code does not overide methods from interface. while this was a running code. Also on specifying the @overide attribute, it keeps on giving the same issue.)

Actually I am looking for this customization for long time now, but still could not figure out the code for it.

Can you provide me the sample CodenameOne application, that has the QR code reader in it and the camera view is customized in it, while scanning the QR code. Thanks.

Shai Almog

unread,
Oct 17, 2015, 12:49:17 AM10/17/15
to CodenameOne Discussions, amitj...@gmail.com
You asked two separate things. One is to embed the camera to which I answered thru a peer component.

Now you are asking about overlaying on top of the camera to which the answer is doing it in native. I can't really help much in that case because that's Android native code and I didn't write it.
Reply all
Reply to author
Forward
0 new messages