package pda3506newsdkwrapper;
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Pixel;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.keywords.Common.DesignerCustomView;
import anywheresoftware.b4a.objects.LabelWrapper;
import anywheresoftware.b4a.objects.PanelWrapper;
import anywheresoftware.b4a.objects.ViewWrapper;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.IOnActivityResult;
import anywheresoftware.b4a.BA.Permissions;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.graphics.Color;
import java.util.ArrayList;
//import com.qs.acivity.MainActivity;
import com.qs.demo3506.R;
import com.qs.service.ScanService;
import com.qs.service.ScanService.IMyBinder;
import com.qs.wiget.App;
import android.posapi.PosApi;
import android.posapi.PosApi.OnCommEventListener;
import android.widget.Toast;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.Binder;
import android.content.ComponentName;
//@ActivityObject
@ShortName("PDA3506NewSDK_2")
@Events(values={"scan_result(scanresult As String)", "onbind()"})
//@Author("Github: Jean Carlos, Wrapped by: Johan Schoeman")
//@Version(1.00f)
@DependsOn(values={"IdCardUartLib", "core123", "zypos1.8"})
@Permissions(values={"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.NFC", "android.permission.READ_PHONE_STATE", "android.permission.READ_EXTERNAL_STORAGE",
"android.permission.RECEIVE_BOOT_COMPLETED"})
public class pda3506newsdkWrapper_2 {
@Hide
public static BA ba;
@Hide
public static String eventName;
private byte mGpioPower = 0x1E ;//PB14
private byte mGpioTrig = 0x29 ;//PC9
private int mCurSerialNo = 3; //usart3
private int mBaudrate = 4; //9600
// private PosApi mApi;
private ScanService scanservice = null;
private ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
//Bind successfully
scanservice = ((IMyBinder) iBinder).getService();
BA.Log("scanservice = " + scanservice);
if (ba.subExists(eventName + "_onbind")) {
ba.raiseEvent2(ba, false, eventName + "_onbind", true, new Object[] {});
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
BA.Log("scanservice disconnected");
scanservice = null;
//ba.raiseEventFromDifferentThread(ba.applicationContext, null, 0, eventName + "_onunbind", true, new Object[] {});
}
};
IMyBinder binder;
Intent intent;
public void Initialize(BA paramBA, String EventName) {
this.eventName = EventName.toLowerCase(BA.cul);
ba = paramBA;
BA.Log("in Initialize");
}
public void setStartIntent() {
intent = new Intent(ba.context,ScanService.class);
ba.context.bindService(intent, conn, 1);
}
private void openDevice(){
//open power
scanservice.mApi.gpioControl(mGpioPower,0,1);
scanservice.mApi.extendSerialInit(mCurSerialNo, mBaudrate, 1, 1, 1, 1);
}
public void closeDevice(){
//close power
scanservice.mApi.gpioControl(mGpioPower,0,0);
scanservice.mApi.extendSerialClose(mCurSerialNo);
ba.context.unbindService(conn);
conn = null;
scanservice = null;
}
public void scanCode() {
BA.Log("in scanCode");
addListener3();
scanservice.mApi.gpioControl(mGpioPower,0,0);
scanservice.mApi.gpioControl(mGpioPower,0,1);
scanservice.mApi.extendSerialInit(mCurSerialNo, mBaudrate, 1, 1, 1, 1);
scanservice.mApi.gpioControl(mGpioTrig, 0, 1);
scanservice.mApi.gpioControl(mGpioTrig, 0, 0);
}
private void stopScanCode() {
scanservice.mApi.gpioControl(mGpioTrig, 0, 1);
}
@Hide
public void addListener3(){
BA.Log("in addListener3");
scanservice.setCallback(new ScanService.Callback() {
@Override
public void scan_result() {
if (ba.subExists(eventName + "_scan_result")) {
ba.raiseEvent2(ba, false, eventName + "_scan_result", true, new Object[]{scanservice.getScanValue()});
}
}
});
}
}