package cilico.tools.barcode;


import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.widget.Toast;

import cilico.tools.barcode.ddjc.BroadcastConfig;
import cn.jymf.scan.CaptureActivity;
import cn.jymf.scan.idatascanlibrary.IdataScanSetting;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.common.config.ConfigCreateService;
import cn.net.caoyao.cpzshandset.common.util.CacheGet;
import cn.net.caoyao.cpzshandset.ui.activity.base.BaseScanActivity;
import cn.net.handsetlib.common.HandsetConstant;

/**
 * 扫描和摄像头切换
 *
 * @author zwj
 * <p>
 * 2015-3-10
 */
public class PhoneScanner extends Scanner {
    static public boolean isPhone = false;
    static boolean open;

    static public void Read(ConfigCreateService createService, CacheGet cacheG, Context context) {
        int scannerMode = createService.getScannerMode(cacheG, context);
        if (scannerMode == 1) {
            Intent intent = new Intent(context, CaptureActivity.class);
            context.startActivity(intent);
        } else if (SeuicScanSetting.isHandPhone()) {

            //东大集成的手持机扫码
//            Intent intent = new Intent(BroadcastConfig.SCAN_START);
//            context.sendBroadcast(intent);
//            com.seuic.scanner.Scanner scanner = ScannerFactory.getScanner(context.getApplicationContext());
            if (context.getClass().getSuperclass() == BaseScanActivity.class) {
//                SeuicScanSetting.startHandScan();
            }
//			Intent intent = new Intent();
//			intent.setAction("com.barcode.sendBroadcastScan");
//			sendBroadcast(intent);
        } else if (IdataScanSetting.isHandPhone()) {
            IdataScanSetting.startHandScan();
        } else {
            // 2021-08-12
            if(HandsetConstant.isHHW()){
                Intent intent = new Intent(BroadcastConfig.SCAN_START);
                context.sendBroadcast(intent);
            }else{
                String version = android.os.Build.VERSION.RELEASE;
                if (version.equals("4.2.2")) {

                    Read();
                }else {
                    // 2021-08-12   富力叶的 手动扫描
                    Intent intent = new Intent(BroadcastConfig.SCAN_START);
                    context.sendBroadcast(intent);
                }
//				ScanHelper.setScanSound(MainActivity.this, bsound);
            }
        }
    }

    /**
     * 屏蔽返回，搜索，菜单三个按钮， HOME这个键无法屏蔽，暂时没找到好的办法 2014-7-23下午9:21:47
     *
     * @param keyCode
     * @return
     */
    public static boolean isShieldKey(int keyCode) {
        if (keyCode == KeyEvent.KEYCODE_HOME || keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_SEARCH
                || keyCode == KeyEvent.KEYCODE_BACK) {
            // KEYCODE_HOME这个键无法屏蔽，暂时没找到好的办法
            return true;
        }
        return false;
    }

    /**
     * 点击两次后才返回或者退出 2014-7-22下午9:16:14
     *
     * @param difTime 时间差 1s内点击两次作为退出
     * @param context
     * @return
     */
    public static boolean doubleBack(Long difTime, Context context) {
        if (difTime < 1000) {
            return true;
        } else {
            // 这样就显示一次Toast
            Toast.makeText(context, context.getString(R.string.dialog_back_ui), Toast.LENGTH_SHORT).show();
        }
        return false;
    }
}
