Android Question How to receive events from the INLINE Java code

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi there!

I have a class in Java written to wrap a complex payment java library

I have instantiated the class and now everything fine, however I have some events happening and I need to comunicate with the B4A code to take action:

B4X:
    @Override
    public void onPrinterError(String s) {
    }
   
    @Override
    public void onConfig() {
        BA.Log("Transaction.onConfig");
    }

    @Override
    public void onBegin() {
        BA.Log("Transaction.onBegin");
    }

    @Override
    public void onProgress(String progressMessage) {
        BA.Log("Transaction.onProgress "+progressMessage);
    }

where is this BA.Log I need to call the B4A code eventually passing some param and receiving some information back.

How It can be done?


my full code above:
B4X:
#Region  Project Attributes
    #ApplicationLabel: yNexu
    #VersionCode: 1
    #VersionName: 1.1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalJar: NexuPayment-release-114.aar
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim nexu, nexupayment As JavaObject
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
End Sub

Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    If FirstTime Then
        nexu.InitializeContext
    End If
    
    Activity.LoadLayout("layout")
    
End Sub

#if java
import android.content.Context;
//import android.app.Activity;

import java.util.HashMap;
import java.util.List;

import ca.nexu.nexupayment.NexuPayment;
import ca.nexu.nexupayment.NexuPaymentPrinterListener;
import ca.nexu.nexupayment.NexuPaymentTransactionListener;

public static class nexutransaction implements NexuPaymentTransactionListener, NexuPaymentPrinterListener {

    public nexutransaction() {
        // Required empty public constructor
    }

    public NexuPayment nexuPayment;

    public void Teste(Activity a) {
        BA.Log("Transaction.Teste c");
    }

    public void Pagar(Context c, Activity a) {
        BA.Log("Transaction.Pagar loadSDK");

        NexuPayment.loadSDK(c);
    
        BA.Log("Transaction.Pagar NexuPayment");
 
         nexuPayment = new NexuPayment(this, c, a, null, null);

        BA.Log("Transaction.Ativar NexuPayment.configurar");
        // configurar parametros
        nexuPayment.configurar("1.1.0", "DASHEN",
                "**** DASHEN ****", null);

        BA.Log("Transaction.Ativar NexuPayment.ativar");
        nexuPayment.pagar(1, "debito", 1, false);
    }

    public void Ativar(Context c, Activity a) {

        BA.Log("Transaction.Ativar loadSDK");

        NexuPayment.loadSDK(c);
    
        BA.Log("Transaction.Ativar NexuPayment");
 
         nexuPayment = new NexuPayment(this, c, a, null, null);

        BA.Log("Transaction.Ativar NexuPayment.configurar");
        // configurar parametros
        nexuPayment.configurar("1.1.0", "DASHEN",
                "**** DASHEN ****", null);

        BA.Log("Transaction.Ativar NexuPayment.ativar");
        // executar a transação
        nexuPayment.ativar("21.333.292/0001-54");
        BA.Log("Transaction.Ativar done");
//        nexuPayment.pagar(1, "debito", 1, false);

    }


    @Override
    public void onPrinterError(String s) {
    }
    
    @Override
    public void onConfig() {
        BA.Log("Transaction.onConfig");
    }

    @Override
    public void onBegin() {
        BA.Log("Transaction.onBegin");
    }

    @Override
    public void onProgress(String progressMessage) {
        BA.Log("Transaction.onProgress "+progressMessage);
    }

    @Override
    public void onBeforeDone() {
        BA.Log("Transaction.onBeforeDone");
    }

    @Override
    public void onTransactionDone(HashMap<String, String> hashMap) {
        BA.Log("Transaction.onTransactionDone ");

    }
    
    @Override
    public void onEnd() {
        BA.Log("Transaction.onEnd");
    }

    @Override
    public void onAbort(int abortCode) {
        BA.Log("Transaction.onAbort"+abortCode);
    }

    @Override
    public void onDebug(String s) {
        BA.Log("Transaction.onDebug "+s);
    }

    @Override
    public void onShowPinpad(boolean b) {
    }

    @Override
    public void onSetKeyboard() {
    }

    @Override
    public void onDisplayPinpadMessage(List<String> list) {
        // to be implemented
    }
    

}

#End If

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    Dim J As JavaObject
    J.initializeContext

    nexupayment = nexu.InitializeNewInstance("yashar.ynexu.main.nexutransaction", Null)
    nexupayment.RunMethod("Ativar", Array(GetContext, J))

End Sub

Private Sub Button2_Click
    Dim J As JavaObject
    J.initializeContext
    
    nexupayment = nexu.InitializeNewInstance("yashar.ynexu.main.nexutransaction", Null)
    nexupayment.RunMethod("Pagar", Array(GetContext, J))
End Sub

Thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…