Android Question Convert to B4A

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Help to transform this Java Class to B4A
Thanks πŸ™ πŸ™ πŸ™
Java:
import android.R.integer;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import java.nio.charset.Charset;
import java.util.Arrays;
public final class TransactionIn implements Parcelable {
    private static final int AMOUNT_SIZE = 12;
    private static final int CURRENCY_CODE_SIZE = 3;
    private static final int OPERATION_SIZE = 1;
    private static final int TERM_NUM_SIZE = 8;
    private static final int AUTHORIZATION_TYPE_SIZE = 1;
    private static final int CTRL_CHEQUE_SIZE = 1;
    private static final int PAN_SIZE = 19;
    private static final int AUTHORIZATION_NUM_SIZE = 9;
    private static final int ISO2_SIZE = 38;
    private static final int CMC7_SIZE = 35;
    private static final int END_DATE_VALIDITY_SIZE = 4;
    private static final int USER_DATA_SIZE = 32;
    private static final int ERROR_CODE_SIZE = 4;
    private static final byte EMPTY_CHARACTER_CODE = 32;
    byte[] cAmount;
    byte[] cCurrencyCode;
    byte[] cAmount2;
    byte[] cCurrencyCode2;
    byte[] cOperation;
    byte[] cTenderType;
    byte[] cReaderType;
    byte[] cCustomerPresent;
    byte[] cTermNum;
    byte[] cCashNum;
    byte[] cTrnsNum;
    byte[] cPan;
    byte[] cCryptoVAD;
    byte[] cDateInitValidite;
    byte[] cDateFinValidite;
    byte[] cIso2;
    byte[] cAutoType;
    byte[] cNumContexte;
    byte[] cNumAuto;
    byte[] cCtrlCheque;
    byte[] cIdentCheque;
    byte[] cCmc7;
    byte[] cUserData1;
    byte[] cUserData2;
    byte[] cOption;
    byte[] cTutorialMode;
    byte[] cNumTicket;
    byte[] cNumDossier;
    byte[] cTypeFacture;
    byte[] FFU;
    public static final Parcelable.Creator<TransactionIn> CREATOR = new Parcelable.Creator() {
        public TransactionIn createFromParcel(Parcel in) {
            return new TransactionIn();
        }
        public TransactionIn[] newArray(int size) {
            return new TransactionIn[size];
        }
    };
    public TransactionIn() {
        Init();
    }
    private void Init() {
        this.cAmount = new byte[12];
        this.cCurrencyCode = new byte[3];
        this.cAmount2 = new byte[12];
        this.cCurrencyCode2 = new byte[3];
        this.cOperation = new byte[1];
        this.cTenderType = new byte[2];
        this.cReaderType = new byte[2];
        this.cCustomerPresent = new byte[1];
        this.cTermNum = new byte[8];
        this.cCashNum = new byte[8];
        this.cTrnsNum = new byte[4];
        this.cPan = new byte[19];
        this.cCryptoVAD = new byte[3];
        this.cDateInitValidite = new byte[4];
        this.cDateFinValidite = new byte[4];
        this.cIso2 = new byte[40];
        this.cAutoType = new byte[1];
        this.cNumContexte = new byte[8];
        this.cNumAuto = new byte[9];
        this.cCtrlCheque = new byte[1];
        this.cIdentCheque = new byte[1];
        this.cCmc7 = new byte[35];
        this.cUserData1 = new byte[32];
        this.cUserData2 = new byte[32];
        this.cOption = new byte[8];
        this.cTutorialMode = new byte[1];
        this.cNumTicket = new byte[8];
        this.cNumDossier = new byte[12];
        this.cTypeFacture = new byte[1];
        this.FFU = new byte[109];
        Arrays.fill(this.cAmount, (byte) 32);
        Arrays.fill(this.cCurrencyCode, (byte) 32);
        Arrays.fill(this.cAmount2, (byte) 32);
        Arrays.fill(this.cCurrencyCode2, (byte) 32);
        Arrays.fill(this.cOperation, (byte) 32);
        Arrays.fill(this.cTenderType, (byte) 32);
        Arrays.fill(this.cReaderType, (byte) 32);
        Arrays.fill(this.cCustomerPresent, (byte) 32);
        Arrays.fill(this.cTermNum, (byte) 32);
        Arrays.fill(this.cCashNum, (byte) 32);
        Arrays.fill(this.cTrnsNum, (byte) 32);
        Arrays.fill(this.cPan, (byte) 32);
        Arrays.fill(this.cCryptoVAD, (byte) 32);
        Arrays.fill(this.cDateInitValidite, (byte) 32);
        Arrays.fill(this.cDateFinValidite, (byte) 32);
        Arrays.fill(this.cIso2, (byte) 32);
        Arrays.fill(this.cAutoType, (byte) 32);
        Arrays.fill(this.cNumContexte, (byte) 32);
        Arrays.fill(this.cNumAuto, (byte) 32);
        Arrays.fill(this.cCtrlCheque, (byte) 32);
        Arrays.fill(this.cIdentCheque, (byte) 32);
        Arrays.fill(this.cCmc7, (byte) 32);
        Arrays.fill(this.cUserData1, (byte) 32);
        Arrays.fill(this.cUserData2, (byte) 32);
        Arrays.fill(this.cOption, (byte) 32);
        Arrays.fill(this.cTutorialMode, (byte) 32);
        Arrays.fill(this.cNumTicket, (byte) 32);
        Arrays.fill(this.cNumDossier, (byte) 32);
        Arrays.fill(this.cTypeFacture, (byte) 32);
        Arrays.fill(this.FFU, (byte) 32);
    }
    private void FillWithZero(byte[] dest, String src) {
        byte[] srcByteArray = src.getBytes(Charset.defaultCharset());
        for (int i = 0; i < dest.length; i++)
            dest[i] = 48;
        for (int i = dest.length - src.length(); i < dest.length; i++)
            dest[i] = srcByteArray[(i - dest.length + src.length())];
    }
    private boolean setData(byte[] dest, int size, String src) {
        if (src.length() > size)
            return false;
        FillWithZero(dest, src);
        return true;
    }
    private String getData(byte[] src) {
        return new String(src);
    }
    public boolean setAmount(String amount) {
        return setData(this.cAmount, 12, amount);
    }
    public boolean setTermNum(String termNum) {
        return setData(this.cTermNum, 8, termNum);
    }
    public boolean setCurrencyCode(String currency) {
        return setData(this.cCurrencyCode, 3, currency);
    }
    public boolean setOperation(String operation) {
        return setData(this.cOperation, 1, operation);
    }
    public boolean setAuthorizationType(String type) {
        return setData(this.cAutoType, 1, type);
    }
    public boolean setCtrlCheque(String ctrlCheque) {
        return setData(this.cCtrlCheque, 1, ctrlCheque);
    }
    public boolean setUserData1(String data) {
        return setData(this.cUserData1, 32, data);
    }
    public String getAmount() {
        return getData(this.cAmount);
    }
    public String getTermNum() {
        return getData(this.cTermNum);
    }
    public String getCurrencyCode() {
        return getData(this.cCurrencyCode);
    }
    public String getOperation() {
        return getData(this.cOperation);
    }
    public String getAuthorizationType() {
        return getData(this.cAutoType);
    }
    public String getCtrlCheque() {
        return getData(this.cCtrlCheque);
    }
    public String getUserData1() {
        return getData(this.cUserData1);
    }
    private TransactionIn(Parcel in) {
        Init();
        readFromParcel(in);
    }
    public void writeToParcel(Parcel out, int flags) {
        out.writeByteArray(this.cAmount);
        out.writeByteArray(this.cCurrencyCode);
        out.writeByteArray(this.cAmount2);
        out.writeByteArray(this.cCurrencyCode2);
        out.writeByteArray(this.cOperation);
        out.writeByteArray(this.cTenderType);
        out.writeByteArray(this.cReaderType);
        out.writeByteArray(this.cCustomerPresent);
        out.writeByteArray(this.cTermNum);
        out.writeByteArray(this.cCashNum);
        out.writeByteArray(this.cTrnsNum);
        out.writeByteArray(this.cPan);
        out.writeByteArray(this.cCryptoVAD);
        out.writeByteArray(this.cDateInitValidite);
        out.writeByteArray(this.cDateFinValidite);
        out.writeByteArray(this.cIso2);
        out.writeByteArray(this.cAutoType);
        out.writeByteArray(this.cNumContexte);
        out.writeByteArray(this.cNumAuto);
        out.writeByteArray(this.cCtrlCheque);
        out.writeByteArray(this.cIdentCheque);
        out.writeByteArray(this.cCmc7);
        out.writeByteArray(this.cUserData1);
        out.writeByteArray(this.cUserData2);
        out.writeByteArray(this.cOption);
        out.writeByteArray(this.cTutorialMode);
        out.writeByteArray(this.cNumTicket);
        out.writeByteArray(this.cNumDossier);
        out.writeByteArray(this.cTypeFacture);
        out.writeByteArray(this.FFU);
    }
    public void readFromParcel(Parcel in) {
        in.readByteArray(this.cAmount);
        in.readByteArray(this.cCurrencyCode);
        in.readByteArray(this.cAmount2);
        in.readByteArray(this.cCurrencyCode2);
        in.readByteArray(this.cOperation);
        in.readByteArray(this.cTenderType);
        in.readByteArray(this.cReaderType);
        in.readByteArray(this.cCustomerPresent);
        in.readByteArray(this.cTermNum);
        in.readByteArray(this.cCashNum);
        in.readByteArray(this.cTrnsNum);
        in.readByteArray(this.cPan);
        in.readByteArray(this.cCryptoVAD);
        in.readByteArray(this.cDateInitValidite);
        in.readByteArray(this.cDateFinValidite);
        in.readByteArray(this.cIso2);
        in.readByteArray(this.cAutoType);
        in.readByteArray(this.cNumContexte);
        in.readByteArray(this.cNumAuto);
        in.readByteArray(this.cCtrlCheque);
        in.readByteArray(this.cIdentCheque);
        in.readByteArray(this.cCmc7);
        in.readByteArray(this.cUserData1);
        in.readByteArray(this.cUserData2);
        in.readByteArray(this.cOption);
        in.readByteArray(this.cTutorialMode);
        in.readByteArray(this.cNumTicket);
        in.readByteArray(this.cNumDossier);
        in.readByteArray(this.cTypeFacture);
        in.readByteArray(this.FFU);
    }
    public int describeContents() {
        return 0;
    }
    public int getLength() {
        int length = 0;
        length = this.cAmount.length + this.cCurrencyCode.length + this.cAmount2.length + this.cCurrencyCode2.length
                + this.cOperation.length + this.cTenderType.length + this.cReaderType.length
                + this.cCustomerPresent.length + this.cTermNum.length + this.cCashNum.length + this.cTrnsNum.length
                + this.cPan.length + this.cCryptoVAD.length + this.cDateInitValidite.length
                + this.cDateFinValidite.length + this.cIso2.length + this.cAutoType.length + this.cNumContexte.length
                + this.cNumAuto.length + this.cCtrlCheque.length + this.cIdentCheque.length + this.cCmc7.length
                + this.cUserData1.length + this.cUserData2.length + this.cOption.length + this.cTutorialMode.length
                + this.cNumTicket.length + this.cNumDossier.length + this.cTypeFacture.length + this.FFU.length;
        return length;
    }
    public static enum CheckControl {
        CHECK_CONTROL_FNCI("1"), CHECK_CONTROL_GUARANTEE("2");
        private String str;
        private CheckControl(String val) {
            this.str = val;
        }
        public String toString() {
            return this.str;
        }
    }
    public static enum AuthorizationType {
        AUTHORIZATION_FORCED("1"),
        AUTHORIZATION_NOT_FORCED("2");
        private String str;
        private AuthorizationType(String val) {
            this.str = val;
        }
        public String toString() {
            return this.str;
        }
    }
    public static enum OperationType {
        OPERATION_DEBIT("C"), OPERATION_CREDIT("D"), OPERATION_CANCEL("J"), OPERATION_DUPLICATE("K");
        private String str;
        private OperationType(String val) {
            this.str = val;
        }
        public String toString() {
            return this.str;
        }
    }
}
 

Attachments

  • PclServiceLib_2.04.00.jar
    123.4 KB · Views: 119
Last edited:

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Why not try to wrap to a library or use inline Java?
I tried but it doesn't work
1649292500741.png
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Help to transform this Java Class to B4A
Thanks πŸ™ πŸ™ πŸ™
Java:
import android.R.integer;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import java.nio.charset.Charset;
import java.util.Arrays;
public final class TransactionIn implements Parcelable {
    private static final int AMOUNT_SIZE = 12;
    private static final int CURRENCY_CODE_SIZE = 3;
    private static final int OPERATION_SIZE = 1;
    private static final int TERM_NUM_SIZE = 8;
    private static final int AUTHORIZATION_TYPE_SIZE = 1;
    private static final int CTRL_CHEQUE_SIZE = 1;
    private static final int PAN_SIZE = 19;
    private static final int AUTHORIZATION_NUM_SIZE = 9;
    private static final int ISO2_SIZE = 38;
    private static final int CMC7_SIZE = 35;
    private static final int END_DATE_VALIDITY_SIZE = 4;
    private static final int USER_DATA_SIZE = 32;
    private static final int ERROR_CODE_SIZE = 4;
    private static final byte EMPTY_CHARACTER_CODE = 32;
    byte[] cAmount;
    byte[] cCurrencyCode;
    byte[] cAmount2;
    byte[] cCurrencyCode2;
    byte[] cOperation;
    byte[] cTenderType;
    byte[] cReaderType;
    byte[] cCustomerPresent;
    byte[] cTermNum;
    byte[] cCashNum;
    byte[] cTrnsNum;
    byte[] cPan;
    byte[] cCryptoVAD;
    byte[] cDateInitValidite;
    byte[] cDateFinValidite;
    byte[] cIso2;
    byte[] cAutoType;
    byte[] cNumContexte;
    byte[] cNumAuto;
    byte[] cCtrlCheque;
    byte[] cIdentCheque;
    byte[] cCmc7;
    byte[] cUserData1;
    byte[] cUserData2;
    byte[] cOption;
    byte[] cTutorialMode;
    byte[] cNumTicket;
    byte[] cNumDossier;
    byte[] cTypeFacture;
    byte[] FFU;
    public static final Parcelable.Creator<TransactionIn> CREATOR = new Parcelable.Creator() {
        public TransactionIn createFromParcel(Parcel in) {
            return new TransactionIn();
        }
        public TransactionIn[] newArray(int size) {
            return new TransactionIn[size];
        }
    };
    public TransactionIn() {
        Init();
    }
    private void Init() {
        this.cAmount = new byte[12];
        this.cCurrencyCode = new byte[3];
        this.cAmount2 = new byte[12];
        this.cCurrencyCode2 = new byte[3];
        this.cOperation = new byte[1];
        this.cTenderType = new byte[2];
        this.cReaderType = new byte[2];
        this.cCustomerPresent = new byte[1];
        this.cTermNum = new byte[8];
        this.cCashNum = new byte[8];
        this.cTrnsNum = new byte[4];
        this.cPan = new byte[19];
        this.cCryptoVAD = new byte[3];
        this.cDateInitValidite = new byte[4];
        this.cDateFinValidite = new byte[4];
        this.cIso2 = new byte[40];
        this.cAutoType = new byte[1];
        this.cNumContexte = new byte[8];
        this.cNumAuto = new byte[9];
        this.cCtrlCheque = new byte[1];
        this.cIdentCheque = new byte[1];
        this.cCmc7 = new byte[35];
        this.cUserData1 = new byte[32];
        this.cUserData2 = new byte[32];
        this.cOption = new byte[8];
        this.cTutorialMode = new byte[1];
        this.cNumTicket = new byte[8];
        this.cNumDossier = new byte[12];
        this.cTypeFacture = new byte[1];
        this.FFU = new byte[109];
        Arrays.fill(this.cAmount, (byte) 32);
        Arrays.fill(this.cCurrencyCode, (byte) 32);
        Arrays.fill(this.cAmount2, (byte) 32);
        Arrays.fill(this.cCurrencyCode2, (byte) 32);
        Arrays.fill(this.cOperation, (byte) 32);
        Arrays.fill(this.cTenderType, (byte) 32);
        Arrays.fill(this.cReaderType, (byte) 32);
        Arrays.fill(this.cCustomerPresent, (byte) 32);
        Arrays.fill(this.cTermNum, (byte) 32);
        Arrays.fill(this.cCashNum, (byte) 32);
        Arrays.fill(this.cTrnsNum, (byte) 32);
        Arrays.fill(this.cPan, (byte) 32);
        Arrays.fill(this.cCryptoVAD, (byte) 32);
        Arrays.fill(this.cDateInitValidite, (byte) 32);
        Arrays.fill(this.cDateFinValidite, (byte) 32);
        Arrays.fill(this.cIso2, (byte) 32);
        Arrays.fill(this.cAutoType, (byte) 32);
        Arrays.fill(this.cNumContexte, (byte) 32);
        Arrays.fill(this.cNumAuto, (byte) 32);
        Arrays.fill(this.cCtrlCheque, (byte) 32);
        Arrays.fill(this.cIdentCheque, (byte) 32);
        Arrays.fill(this.cCmc7, (byte) 32);
        Arrays.fill(this.cUserData1, (byte) 32);
        Arrays.fill(this.cUserData2, (byte) 32);
        Arrays.fill(this.cOption, (byte) 32);
        Arrays.fill(this.cTutorialMode, (byte) 32);
        Arrays.fill(this.cNumTicket, (byte) 32);
        Arrays.fill(this.cNumDossier, (byte) 32);
        Arrays.fill(this.cTypeFacture, (byte) 32);
        Arrays.fill(this.FFU, (byte) 32);
    }
    private void FillWithZero(byte[] dest, String src) {
        byte[] srcByteArray = src.getBytes(Charset.defaultCharset());
        for (int i = 0; i < dest.length; i++)
            dest[i] = 48;
        for (int i = dest.length - src.length(); i < dest.length; i++)
            dest[i] = srcByteArray[(i - dest.length + src.length())];
    }
    private boolean setData(byte[] dest, int size, String src) {
        if (src.length() > size)
            return false;
        FillWithZero(dest, src);
        return true;
    }
    private String getData(byte[] src) {
        return new String(src);
    }
    public boolean setAmount(String amount) {
        return setData(this.cAmount, 12, amount);
    }
    public boolean setTermNum(String termNum) {
        return setData(this.cTermNum, 8, termNum);
    }
    public boolean setCurrencyCode(String currency) {
        return setData(this.cCurrencyCode, 3, currency);
    }
    public boolean setOperation(String operation) {
        return setData(this.cOperation, 1, operation);
    }
    public boolean setAuthorizationType(String type) {
        return setData(this.cAutoType, 1, type);
    }
    public boolean setCtrlCheque(String ctrlCheque) {
        return setData(this.cCtrlCheque, 1, ctrlCheque);
    }
    public boolean setUserData1(String data) {
        return setData(this.cUserData1, 32, data);
    }
    public String getAmount() {
        return getData(this.cAmount);
    }
    public String getTermNum() {
        return getData(this.cTermNum);
    }
    public String getCurrencyCode() {
        return getData(this.cCurrencyCode);
    }
    public String getOperation() {
        return getData(this.cOperation);
    }
    public String getAuthorizationType() {
        return getData(this.cAutoType);
    }
    public String getCtrlCheque() {
        return getData(this.cCtrlCheque);
    }
    public String getUserData1() {
        return getData(this.cUserData1);
    }
    private TransactionIn(Parcel in) {
        Init();
        readFromParcel(in);
    }
    public void writeToParcel(Parcel out, int flags) {
        out.writeByteArray(this.cAmount);
        out.writeByteArray(this.cCurrencyCode);
        out.writeByteArray(this.cAmount2);
        out.writeByteArray(this.cCurrencyCode2);
        out.writeByteArray(this.cOperation);
        out.writeByteArray(this.cTenderType);
        out.writeByteArray(this.cReaderType);
        out.writeByteArray(this.cCustomerPresent);
        out.writeByteArray(this.cTermNum);
        out.writeByteArray(this.cCashNum);
        out.writeByteArray(this.cTrnsNum);
        out.writeByteArray(this.cPan);
        out.writeByteArray(this.cCryptoVAD);
        out.writeByteArray(this.cDateInitValidite);
        out.writeByteArray(this.cDateFinValidite);
        out.writeByteArray(this.cIso2);
        out.writeByteArray(this.cAutoType);
        out.writeByteArray(this.cNumContexte);
        out.writeByteArray(this.cNumAuto);
        out.writeByteArray(this.cCtrlCheque);
        out.writeByteArray(this.cIdentCheque);
        out.writeByteArray(this.cCmc7);
        out.writeByteArray(this.cUserData1);
        out.writeByteArray(this.cUserData2);
        out.writeByteArray(this.cOption);
        out.writeByteArray(this.cTutorialMode);
        out.writeByteArray(this.cNumTicket);
        out.writeByteArray(this.cNumDossier);
        out.writeByteArray(this.cTypeFacture);
        out.writeByteArray(this.FFU);
    }
    public void readFromParcel(Parcel in) {
        in.readByteArray(this.cAmount);
        in.readByteArray(this.cCurrencyCode);
        in.readByteArray(this.cAmount2);
        in.readByteArray(this.cCurrencyCode2);
        in.readByteArray(this.cOperation);
        in.readByteArray(this.cTenderType);
        in.readByteArray(this.cReaderType);
        in.readByteArray(this.cCustomerPresent);
        in.readByteArray(this.cTermNum);
        in.readByteArray(this.cCashNum);
        in.readByteArray(this.cTrnsNum);
        in.readByteArray(this.cPan);
        in.readByteArray(this.cCryptoVAD);
        in.readByteArray(this.cDateInitValidite);
        in.readByteArray(this.cDateFinValidite);
        in.readByteArray(this.cIso2);
        in.readByteArray(this.cAutoType);
        in.readByteArray(this.cNumContexte);
        in.readByteArray(this.cNumAuto);
        in.readByteArray(this.cCtrlCheque);
        in.readByteArray(this.cIdentCheque);
        in.readByteArray(this.cCmc7);
        in.readByteArray(this.cUserData1);
        in.readByteArray(this.cUserData2);
        in.readByteArray(this.cOption);
        in.readByteArray(this.cTutorialMode);
        in.readByteArray(this.cNumTicket);
        in.readByteArray(this.cNumDossier);
        in.readByteArray(this.cTypeFacture);
        in.readByteArray(this.FFU);
    }
    public int describeContents() {
        return 0;
    }
    public int getLength() {
        int length = 0;
        length = this.cAmount.length + this.cCurrencyCode.length + this.cAmount2.length + this.cCurrencyCode2.length
                + this.cOperation.length + this.cTenderType.length + this.cReaderType.length
                + this.cCustomerPresent.length + this.cTermNum.length + this.cCashNum.length + this.cTrnsNum.length
                + this.cPan.length + this.cCryptoVAD.length + this.cDateInitValidite.length
                + this.cDateFinValidite.length + this.cIso2.length + this.cAutoType.length + this.cNumContexte.length
                + this.cNumAuto.length + this.cCtrlCheque.length + this.cIdentCheque.length + this.cCmc7.length
                + this.cUserData1.length + this.cUserData2.length + this.cOption.length + this.cTutorialMode.length
                + this.cNumTicket.length + this.cNumDossier.length + this.cTypeFacture.length + this.FFU.length;
        return length;
    }
    public static enum CheckControl {
        CHECK_CONTROL_FNCI("1"), CHECK_CONTROL_GUARANTEE("2");
        private String str;
        private CheckControl(String val) {
            this.str = val;
        }
        public String toString() {
            return this.str;
        }
    }
    public static enum AuthorizationType {
        AUTHORIZATION_FORCED("1"),
        AUTHORIZATION_NOT_FORCED("2");
        private String str;
        private AuthorizationType(String val) {
            this.str = val;
        }
        public String toString() {
            return this.str;
        }
    }
    public static enum OperationType {
        OPERATION_DEBIT("C"), OPERATION_CREDIT("D"), OPERATION_CANCEL("J"), OPERATION_DUPLICATE("K");
        private String str;
        private OperationType(String val) {
            this.str = val;
        }
        public String toString() {
            return this.str;
        }
    }
}
@Erel,@Peter Simpson
Hello help me to convert this Java code in B4X or someone?
Thanks
 
Upvote 0
Top