/*条码扫描返回的结果处理*/ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); String bufString = ""; switch (requestCode) { case SCANNIN_GREQUEST_CODE: if (resultCode == RESULT_OK) { Bundle bundle = data.getExtras(); barcode.setText(bundle.getString("result")); btSent = false; bufString = "QUERY□" + barcode.getText().toString() + "□" + "DH001" + "□" + "UD" + "□" + "CK001"; barString = barcode.getText().toString().trim(); /*发送查询指令*/ if (isconnect) { isSearchinf = true; mysocket.writeData(SYS.SenData(bufString, fwq, androidID)); } else { SearchINF(barcode.getText().toString()); } } break; case REQUEST_CONNECT_DEVICE: if (resultCode == RESULT_OK) { String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); WriteReadSD.writex(address, "BTMAC", log.fdir); _device = MainActivity._bluetooth.getRemoteDevice(address); RKScan.mChatService.connect(_device); } break; case REQUEST_ENABLE_BT: // 判断蓝牙是否启用 if (resultCode == Activity.RESULT_OK) { setupChat(); } else { finish(); } break; case 4: if (resultCode == RESULT_OK) { String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); _device = MainActivity._bluetooth.getRemoteDevice(address); WriteReadSD.writex(address, "PTMAC", log.fdir); // 存放打印机的地址 RKScan.printService.connect(_device); } break; } }
/** * ********************************************************************************** * * <p>相关的连接操作 * * <p>********************************************************************************** */ public void connect() { Text_of_output = ""; Text_of_output = WriteReadSD.read("BTMAC", log.fdir); _device = null; /*有就直接连接*/ if (Text_of_output.length() > 0) { _device = MainActivity._bluetooth.getRemoteDevice(Text_of_output.trim()); RKScan.mChatService.connect(_device); } return; }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); androidID = telephonyManager.getDeviceId(); String[] str = null; /*读取文件获取员工编号和IP,端口号*/ setContentView(R.layout.jbzl); btzt = (TextView) findViewById(R.id.zlbt); yc = (TextView) findViewById(R.id.zlrk); wc = (TextView) findViewById(R.id.zlwc); Running = 21; b1 = (Button) findViewById(R.id.B2); b2 = (Button) findViewById(R.id.B3); b3 = (Button) findViewById(R.id.B4); b4 = (Button) findViewById(R.id.B5); b5 = (Button) findViewById(R.id.B6); b6 = (Button) findViewById(R.id.B7); b7 = (Button) findViewById(R.id.B8); b8 = (Button) findViewById(R.id.B9); b9 = (Button) findViewById(R.id.B10); b10 = (Button) findViewById(R.id.B1); inf1 = (EditText) findViewById(R.id.E1); inf2 = (EditText) findViewById(R.id.E2); inf3 = (EditText) findViewById(R.id.E3); inf4 = (EditText) findViewById(R.id.E4); inf5 = (EditText) findViewById(R.id.E5); inf6 = (EditText) findViewById(R.id.E6); inf7 = (EditText) findViewById(R.id.E7); inf8 = (EditText) findViewById(R.id.E8); inf9 = (EditText) findViewById(R.id.E9); inf10 = (EditText) findViewById(R.id.E10); printTextView = (TextView) findViewById(R.id.jbprint); String[] bufx = null; priString = WriteReadSD.read("isPrint", log.fdir); File file = new File(log.pdir, "商品资料.TXT"); if (file.exists()) { String[] bufStrings = null; Text_of_output = null; Text_of_output = WriteReadSD.readline("商品资料.TXT", log.pdir); if (Text_of_output.trim().length() > 0) { bufStrings = SYS.splitString(Text_of_output.trim(), "\n"); System.out.println("抬头是:" + bufStrings[0].trim()); bufx = SYS.splitString(bufStrings[0].trim(), "\t"); for (int i = 0; i < 11; i++) { System.out.println(bufx[i].trim()); } b1.setText(bufx[1].trim()); b2.setText(bufx[2].trim()); b3.setText(bufx[3].trim()); b4.setText(bufx[4].trim()); b5.setText(bufx[5].trim()); b6.setText(bufx[6].trim()); b7.setText(bufx[7].trim()); b8.setText(bufx[8].trim()); b9.setText(bufx[9].trim()); b10.setText(bufx[10].trim()); } else { bufx = new String[] {"条码", "名称", "货号", "规格", "型号", "进价", "售价", "单位", "备注一", "备注二", "备注三"}; } } else { bufx = new String[] {"条码", "名称", "货号", "规格", "型号", "进价", "售价", "单位", "备注一", "备注二", "备注三"}; } /*打印属性*/ sx1 = WriteReadSD.read("Print1", log.fdir); if (sx1.trim().equals("-1")) sx11 = ""; else { sx11 = bufx[Integer.parseInt(sx1) + 1]; } sx2 = WriteReadSD.read("Print2", log.fdir); if (sx2.trim().equals("-1")) sx12 = ""; else { sx12 = bufx[Integer.parseInt(sx2) + 1]; } yc.setText(R.string.Transferall); wc.setText(R.string.Transferpovit); yc.append(MainActivity.sentpovit + ""); wc.append((MainActivity.sentall - MainActivity.sentpovit) + ""); BTpower = (TextView) findViewById(R.id.zlDL); BTpower.setText(R.string.power); sjsm = (Button) findViewById(R.id.zlSJ); sendButton = (Button) findViewById(R.id.zlbc); ConnectButton = (Button) findViewById(R.id.zllj); printTextView.setOnClickListener(printClickListener); vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); btzt.setOnClickListener(Btset); barcode = (EditText) findViewById(R.id.zl_sendmessage); Text_of_output = ""; Text_of_output = WriteReadSD.read("IP", log.fdir); if (Text_of_output.length() > 0) { str = SYS.splitString(Text_of_output.trim(), ":"); iPString = str[0].trim(); portString = str[1].trim(); } else { // sys.disPlay(sView, dis, getString(R.string.Noset)+"\n"); //显示数据 } Text_of_output = ""; Text_of_output = WriteReadSD.read("FWQM", log.fdir); if (Text_of_output.length() > 0) { fwq = Text_of_output.trim(); } else { fwq = "RS"; } mysocket = new mySocket(mContext, mHandler, iPString, Integer.parseInt(portString)); if (iPString.length() > 0 && mysocket.getState() == mySocket.STATE_NONE) { mysocket.connect(); } else { ConnectButton.setText(R.string.SKconnected); } if (iPString.length() > 0) { ConnectButton.setOnClickListener(socketconnect); } if (!RKScan.Isbt) { btzt.setText(R.string.title_not_connected); } else { btzt.setText(R.string.title_connected_to); } if (!RKScan.isPrint) { printTextView.setText(R.string.printer_not_connected); } else { printTextView.setText(R.string.printer_connected_to); } if (RKScan.setInf) { String barcodeString = getIntent().getStringExtra("BARCODE"); if (barcodeString.trim().length() > 0) { barcode.setText(barcodeString); SearchINF(barcodeString.trim()); } } mHandler.postDelayed(socketRunnable, 50); mHandler.postDelayed(btRunnable, 5000); mHandler.postDelayed(printRunnable, 5000); mHandler.postDelayed(socketConnect, 1000 * 60); btzt.setOnClickListener(Btset); Button search = (Button) findViewById(R.id.zlSear); search.setOnClickListener(searchon); sjsm.setOnClickListener(scanClickListener); sendButton.setOnClickListener(sent); }