Recent

Author Topic: [LAMW] How to create a callback ? (eg. Datalogic)  (Read 1637 times)

af0815

  • Hero Member
  • *****
  • Posts: 1409
[LAMW] How to create a callback ? (eg. Datalogic)
« on: March 22, 2024, 01:56:51 pm »
I used the information from lamw_create_new_datalogic_component and the other information to get the API from datalogic working.

The samplecode from lamw_create_new_datalogic_component is working, but is only the first step. if you want wo work with the barcodescanner you have to use in java the "BarcodeManager" from the API. This the major part. Initializing is not the problem, but the API is based on get the information only with callbacks

If you look inside the samples of the API (DecodeSampleAPI) you see the declaration
Code: Java  [Select][+][-]
  1. public class MainScanActivity extends Activity implements ReadListener,
  2.         StartListener, TimeoutListener, StopListener {

The four callback (Activity in Java) implents the working part and the four callbacks are bound or unbound to the Barcodemanager
Code: Java  [Select][+][-]
  1.     // Register this activity as a listener for several scanner events
  2.     private void registerListeners() {
  3.         try {
  4.             mBarcodeManager.addReadListener(this);
  5.             mBarcodeManager.addStartListener(this);
  6.             mBarcodeManager.addStopListener(this);
  7.             mBarcodeManager.addTimeoutListener(this);
  8.         } catch (Exception e) {
  9.             Log.e(TAG, "Cannot add listener, the app won't work");
  10.             showMessage("ERROR! Check logcat");
  11.             finish();
  12.         }
  13.     }
  14.  
  15.     // Unregister this activity as a listener
  16.     private void releaseListeners() {
  17.         try {
  18.             mBarcodeManager.removeReadListener(this);
  19.             mBarcodeManager.removeStartListener(this);
  20.             mBarcodeManager.removeStopListener(this);
  21.             mBarcodeManager.removeTimeoutListener(this);
  22.         } catch (DecodeException e) {
  23.             Log.e(TAG, "Cannot remove listeners, the app won't work", e);
  24.             showMessage("ERROR! Check logcat");
  25.             finish();
  26.         }
  27.     }
  28.  
and on of the listener itselft
Code: Java  [Select][+][-]
  1.    @Override
  2.     public void onRead(DecodeResult result) {
  3.         String string = result.getText();
  4.         if( string!= null) {
  5.             showScanResult.append("Result: " + string);
  6.         }
  7.     }
  8.  
and this onRead and the other Activities are my problem.

I have tried to write a java programm to work with the BarcodeManager, but i have the same problem - how can i send the data back to my pascal in a OnData call. ?!


« Last Edit: March 22, 2024, 01:58:39 pm by af0815 »
regards
Andreas

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: [LAMW] How to create a callback ? (eg. Datalogic)
« Reply #1 on: March 26, 2024, 04:16:30 am »
Hi, af0815!


Regrettably, the doc "How_to_add_an_online_library_to_LAMW.txt" relative to "lamw_create_new_datalogic_component" ignore this important topic, but you can find more information looking for "how_to_create_new_components.txt",    more specifically the section  "4. Added "native" [events] methods to your component"....

Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

af0815

  • Hero Member
  • *****
  • Posts: 1409
Re: [LAMW] How to create a callback ? (eg. Datalogic)
« Reply #2 on: March 26, 2024, 06:27:31 am »
Thx for the hint, I will look for it in the next days.

regards
Andreas

af0815

  • Hero Member
  • *****
  • Posts: 1409
Re: [LAMW] How to create a callback ? (eg. Datalogic)
« Reply #3 on: March 28, 2024, 03:48:16 pm »
I have tried this with your explanation and created a branch https://github.com/afriess/lazandroidmodulewizard/tree/Andi_WIP on github, where my actual not working changes are stored.

I did not full find the missing link between the two world (actual i am landed in 'never man's land' :-)  between Pascal and Java)

Edit: I have tried to make all the routines are the same like in the sample "spinner". I can compile a sample and transfer it to the device, but the event is never coming and fired in the pascal part.
The branch is up to date
« Last Edit: March 29, 2024, 10:48:04 am by af0815 »
regards
Andreas

 

TinyPortal © 2005-2018