Barcode scanner widget : very cool

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Barcode scanner widget : very cool

Post by bangkok » Thu Jul 25, 2019 12:32 pm

With the release of LC 9.5 rc1, the barcode library and the barcode scanner widget become part of indy licence (a wise decision from HQ).

I started to try it.

It's very cool !

As usual, we can regret a lack of "documentation materials" (just the dictionary actually), but very, very interesting. And it works well.
:D

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Barcode scanner widget : very cool

Post by SparkOut » Thu Jul 25, 2019 11:05 pm

Hi Bangkok
I am also keen to try the barcode reader widget, but have been stumped by the very little detail about it.
Could you give a little info about how to set up a basic app to read a barcode? Do you have to first take a picture of the barcode using camera tools? I have just included the libraries and widget so far but the widget doesn't even show up. How do I get the app to actually go looking for a barcode to read?
Thanks!
S

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Barcode scanner widget : very cool

Post by bangkok » Fri Jul 26, 2019 1:28 am

Here is my test stack.

Actually, on the area covered by the widget... you'll see your back camera working constantly (you can set up the "FPS").

The area of the widget is like... a lens.

Then with your phone "target" a barcode... focus by moving back and forth your phone... LC can display a red bar to help you focus, it's called "overlay guideline" on the preferences pan of the widget).... the barcode is then automatically "recognized" by LC (a white bar flashing)... and a message is fired up (barcodedetected, or barcodecliked if you tap the image)

and within the message, an array contains all the data linked to the barcode scanned.

I put the handler in the card script.

Code: Select all

on barcodeDetected pBC,pID
   put pBC["value format"]&cr&pBC["raw value"]&cr&pBC["display value"] into tResult
  answer tResult
end barcodeDetected
Attachments
BC2.zip
(1.82 KiB) Downloaded 292 times

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Barcode scanner widget : very cool

Post by sphere » Fri Jul 26, 2019 12:17 pm

-----------
Last edited by sphere on Mon Jul 29, 2019 4:04 pm, edited 1 time in total.

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Barcode scanner widget : very cool

Post by SparkOut » Fri Jul 26, 2019 4:33 pm

That is brilliant bangkok, thank you so much.
It works to show the widget straight away, where my test did not show the widget at all. I checked all the settings on my test app and as far as I can tell they are the same as yours.
I have made another new test app and got that to show the widget too.
But on all of them, I can't make the snapshotMode setting do anything useful. No matter what I set the snapshotMode to, it always acts as "detected" (at least how I would expect "detected" mode to behave).
The barcode reader still scans and sends the barcodeDetected message every time, whether I script it to "clicked" or "off".

The red guideline is centrally aligned vertically, looks good here. The bar does not stretch all the way to either edge, but gives a good representation of where to align the barcode, and turns white across the section of bsrcide detected.

(Compiling on Windows 10, using Samsung J7 and J5 phones. Could it be the phone model, or am I doing something wrong? Or could there be a bug?)

Apart from the snapshotMode issue, I am very impressed.

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Barcode scanner widget : very cool

Post by SparkOut » Fri Jul 26, 2019 8:11 pm

And now I am more disconcerted and less impressed. trying another test app, I get, instead of the barcodeDeted message returning data that I can access in the "pBarcode" array, I get a (really unkown how) message onscreen (like I had said "answer <something>" where the something is a numeric value eg -17781367418 (this has NO relation to any barcode being scanned, and may be either a positive or negative value).
A further test has produced an app that behaves more normally but I can no longer get a guide overlay, and especially cannot set the previewwidth or previewHeight. No matter whether I set by script or by hand in the property inspector the camera image is distorted and only a few pixels high.
setting the disabled, or any of the snapshotmodes of the widget does not seem to have any effect.
I can see that I would have been wrong with the snapshotMode idea before - the widget will always detect a barcode in the preview and send a barcodeDetected message, whatever the snapshotMode. It will only send a snapshot with the snapshot data if the mode is set accordingly. I get that now. But apart from one random time when snapshot data was passed with the message, I find it impossible to test for the snapshot data, nothing is passed.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Barcode scanner widget : very cool

Post by bangkok » Sat Jul 27, 2019 3:00 am

SparkOut wrote:
Fri Jul 26, 2019 8:11 pm
But apart from one random time when snapshot data was passed with the message, I find it impossible to test for the snapshot data, nothing is passed.
Well... for that matter, I still haven't figured out what is exactly... the "snapshot mode".
:D

I guess with time, we shall get some kind of documentation and/or users experiences.

Each widget should have its own set of demo stacks, or at least some kind of documentation.

It's a little bit frustrating, but that's the LC's way.

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Barcode scanner widget : very cool

Post by SparkOut » Sat Jul 27, 2019 4:52 am

Yes, it's a problem with all LCB stuff for me.

As far as the barcode scanner goes, can you get it to change the preview size and get any different overlay views? Or disable it? These just simply do not work for me.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Barcode scanner widget : very cool

Post by bangkok » Sat Jul 27, 2019 5:22 am

SparkOut wrote:
Sat Jul 27, 2019 4:52 am
As far as the barcode scanner goes, can you get it to change the preview size and get any different overlay views? Or disable it? These just simply do not work for me.
I'm still doing tests (but it's boring : change something in the IDE, compile, copy .apk on the phone, uninstall previous version, install new one, etc.)

Regarding property inspector of the widget, so far :
-"preview width" and "preview height" : no effect. i can't see any difference

-what matters though is the SIZE of the widget (rect) And yes better results if it's square shape

-overlay : it works (enable or disable)

-snapshot mode : i guess it takes a "picture" of the barcode that has been scanned

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Barcode scanner widget : very cool

Post by [-hh] » Sat Jul 27, 2019 6:35 am

The dictionary is not (yet) complete for that. If you know what to look for (e.g. snapshotMode) you can find it.
Set the snapshotMode to specify if and when a snapshot of a barcode should be
returned. If set to "off", barcode snapshots will never be taken. If set to
"detected", a snapshot will be taken each time a barcode is detected and sent as
part of the barcode array with the barcodeDetected message. If set to
"clicked", a snapshot will be taken each time a barcode is clicked and sent as
part of the barcode array with the barcodeClicked message.
Defaults to "off".
For a full list of entries use Bernd's tinydict:
http://livecodeshare.runrev.com/stack/8 ... Dictionary
and select android.barcodescanner from the Dicts menu.

May be you also have to remove the dictionary cache before that so that it is rebuilt with the next startup of LC.
You could use Mark Wieder's "cache cleaner" for removing:
http://livecodeshare.runrev.com/stack/8 ... he-Cleaner

Here the "how-to-find-the-caches" from his stack:

Code: Select all

function cacheLocation
   local tCacheFolder
   switch the platform
      case "Win32"
         put specialFolderPath("support") into tCacheFolder # AppData/Roaming
         set the itemDelimiter to "/"
         put "/local/RunRev/Documentation Cache/" into item -1 of tCacheFolder
         break
      case "MacOS"
         put specialFolderPath("home") & "/Library/Application Support/RunRev/Documentation Cache/" into tCacheFolder
         break
      default
      case "linux"
         put specialFolderPath("home") & "/.runrev/documentationcache/" into tCacheFolder
         break
   end switch
   return tCacheFolder
end cacheLocation
shiftLock happens

SparkOut
Posts: 2834
Joined: Sun Sep 23, 2007 4:58 pm

Re: Barcode scanner widget : very cool

Post by SparkOut » Sat Jul 27, 2019 12:49 pm

Thanks Hermann
I did get the snapshotMode intent already but this helps. I have been testing and playing, and have managed to brute force a view that seems to consistently work to scan a barcode on a given device, as long as no snapshotMode settings are applied, and previewWidth/previewHeight are not played with.
I have made a bug report https://quality.livecode.com/show_bug.cgi?id=22268 which will hopefully elicit some fix/workaround/information that will help understanding and development, even if not necessarily an actual bug.

Post Reply

Return to “Android Deployment”