package com.fxy.base;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import sto.android.app.StoJNI;
import sto.android.app.StoTongJNI;

public class ScanBaseActivity{
    private Context mContext;
    private KlScanActivity scanActivity;

    public boolean initScanResults(Context context,Handler handler, String type){
        if ("kaicom".equals(type)) {
            scanActivity = new KlScanActivity(context, handler);
            scanActivity.start();

            return true;
        }
        return false;
    }
    public void scanStop(String type){
        if ("kaicom".equals(type)) {
            if (scanActivity != null) {
                scanActivity.stop();
            }
        }
    }
}

class KlScanActivity implements StoJNI.ScanCallBack {
    private Handler scanHandler;
    private Context mContext;
    @Override
    public void onScanResults(String str) {
        Message msg = new Message();
        msg.obj = str;
        scanHandler.sendMessage(msg);
    }

    @Override
    public void onScanResults(String str, int type) {

    }

    public void start(){
        String pdaBrand = StoTongJNI.getmPdaBrand();
        if (!pdaBrand.isEmpty()){
            StoTongJNI.getIns(mContext).setmScanCB(this);
            StoTongJNI.getIns(mContext).SetScannerOn();
        }
    }

    public void stop(){
        StoTongJNI.getIns(mContext).SetScannerStop();
        StoTongJNI.getIns(mContext).SetScannerOff();
    }

    KlScanActivity(Context context,Handler handler){
        scanHandler = handler;
        mContext = context;
    }
}

//多方方法
class DdScanActivity implements StoJNI.ScanCallBack {
    private Handler scanHandler;
    @Override
    public void onScanResults(String str) {
        Message msg = new Message();
        msg.obj = str;
        scanHandler.sendMessage(msg);
    }

    @Override
    public void onScanResults(String str, int type) {

    }

    public DdScanActivity(Handler handler){
        scanHandler = handler;
    }
}
