Commit 3e2f9301c40027b886e3d41e45c1de3fe00869e1

Authored by 杜方
1 parent e4eb73bf

畅游通标准:修复打印数据为空时报错

src/android_serialport_api/print_tool/MobilePrintTool.java
@@ -516,130 +516,142 @@ public class MobilePrintTool extends Activity { @@ -516,130 +516,142 @@ public class MobilePrintTool extends Activity {
516 } 516 }
517 } 517 }
518 518
519 - // 蓝牙连接等待弹框  
520 - private ProgressDialog dialog = null;  
521 - // 连接的设备的名称  
522 - private String mConnectedDeviceName = null;  
523 - // 更新标题栏右边状态和读写状态的Handler  
524 - @SuppressLint("HandlerLeak")  
525 - private final Handler mHandler = new Handler() {  
526 - @Override  
527 - public void handleMessage(Message msg) {  
528 - switch (msg.what) {  
529 - case BluetoothService.MESSAGE_STATE_CHANGE:  
530 - switch (msg.arg1) {  
531 - case BluetoothService.STATE_CONNECTED:  
532 - MyApp.getInstance().setBluConnection(true);  
533 - if (!isprint) {  
534 - isprint = true;  
535 - isprint2 = true;  
536 - }  
537 - print(info);  
538 - if (dialog != null) {  
539 - dialog.dismiss();  
540 - dialog = null;  
541 - }  
542 - break;  
543 - case BluetoothService.STATE_CONNECTING:  
544 - if (dialog == null) {  
545 - // 显示ProgressDialog  
546 - dialog = new ProgressDialog(MobilePrintTool.this);  
547 - dialog.setMessage("连接打印机中...");  
548 - dialog.setCanceledOnTouchOutside(true);  
549 - dialog.setCancelable(true);  
550 - if (type == DeviceType.HANDSET.getValue()) {  
551 - dialog.getWindow()  
552 - .setType(  
553 - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);  
554 - }  
555 - try {  
556 - dialog.show();  
557 - } catch (Exception e) {  
558 - e.printStackTrace();  
559 - }  
560 - } else {  
561 - dialog.setMessage("连接打印机中...");  
562 - }  
563 - break;  
564 - case BluetoothService.STATE_NONE:  
565 - break;  
566 - case BluetoothService.STATE_LISTEN:  
567 - // MyApp.getInstance().setBluConnection(false);  
568 - if (dialog != null) {  
569 - dialog.dismiss();  
570 - dialog = null;  
571 - }  
572 - break;  
573 - case BluetoothService.STATE_FAILL:  
574 - if (dialog != null) {  
575 - dialog.dismiss();  
576 - dialog = null;  
577 - }  
578 - finish();  
579 - break;  
580 - }  
581 - break;  
582 - case BluetoothService.STATE_FAILL:  
583 - if (dialog != null) {  
584 - dialog.dismiss();  
585 - dialog = null;  
586 - }  
587 - finish();  
588 - break;  
589 - case BluetoothService.MESSAGE_WRITE:  
590 - break;  
591 - case BluetoothService.MESSAGE_READ:  
592 - break;  
593 - case BluetoothService.MESSAGE_DEVICE_NAME:  
594 - // 保存连接设备的名字  
595 - mConnectedDeviceName = msg.getData().getString(  
596 - BluetoothService.DEVICE_NAME);  
597 - if (type != null && type == DeviceType.HANDSET.getValue()) {  
598 - MToast.makeText(MobilePrintTool.this,  
599 - "连接到" + mConnectedDeviceName, MToast.LENGTH_SHORT)  
600 - .show();  
601 - } else {  
602 - Toast.makeText(MobilePrintTool.this,  
603 - "连接到" + mConnectedDeviceName, Toast.LENGTH_SHORT)  
604 - .show();  
605 - }  
606 - if (!isprint) {  
607 - isprint = true;  
608 - isprint2 = true;  
609 - }  
610 - print(info);  
611 - break;  
612 - case BluetoothService.MESSAGE_TOAST:  
613 - if (!msg.getData().getBoolean("sucess", false)) {  
614 - finish();  
615 - return;  
616 - }  
617 - if (Thread.currentThread() != Looper.getMainLooper()  
618 - .getThread()) {  
619 - Looper.prepare();  
620 - }  
621 - String info = msg.getData().getString(BluetoothService.TOAST);  
622 - if (info != null && !info.equals("")) {  
623 - if (type != null && type == DeviceType.HANDSET.getValue()) {  
624 - MToast.makeText(  
625 - MobilePrintTool.this,  
626 - msg.getData().getString(BluetoothService.TOAST),  
627 - MToast.LENGTH_LONG).show();  
628 - } else {  
629 - Toast.makeText(  
630 - MobilePrintTool.this,  
631 - msg.getData().getString(BluetoothService.TOAST),  
632 - Toast.LENGTH_LONG).show();  
633 - }  
634 - if (Thread.currentThread() != Looper.getMainLooper()  
635 - .getThread()) {  
636 - Looper.loop();  
637 - }  
638 - }  
639 - break;  
640 - }  
641 - }  
642 - }; 519 + // 蓝牙连接等待弹框
  520 + private ProgressDialog dialog = null;
  521 + // 连接的设备的名称
  522 + private String mConnectedDeviceName = null;
  523 + // 更新标题栏右边状态和读写状态的Handler
  524 + @SuppressLint("HandlerLeak")
  525 + private final Handler mHandler = new Handler() {
  526 + @Override
  527 + public void handleMessage(Message msg) {
  528 + switch (msg.what) {
  529 + case BluetoothService.MESSAGE_STATE_CHANGE:
  530 + switch (msg.arg1) {
  531 + case BluetoothService.STATE_CONNECTED:
  532 + MyApp.getInstance().setBluConnection(true);
  533 + if (!isprint) {
  534 + isprint = true;
  535 + isprint2 = true;
  536 + }
  537 + if (!TextUtils.isEmpty(info)) {
  538 + print(info);
  539 + } else {
  540 + Toast.makeText(MobilePrintTool.this,
  541 + "没有可打印数据!", Toast.LENGTH_SHORT)
  542 + .show();
  543 + }
  544 + if (dialog != null) {
  545 + dialog.dismiss();
  546 + dialog = null;
  547 + }
  548 + break;
  549 + case BluetoothService.STATE_CONNECTING:
  550 + if (dialog == null) {
  551 + // 显示ProgressDialog
  552 + dialog = new ProgressDialog(MobilePrintTool.this);
  553 + dialog.setMessage("连接打印机中...");
  554 + dialog.setCanceledOnTouchOutside(true);
  555 + dialog.setCancelable(true);
  556 + if (type == DeviceType.HANDSET.getValue()) {
  557 + dialog.getWindow()
  558 + .setType(
  559 + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
  560 + }
  561 + try {
  562 + dialog.show();
  563 + } catch (Exception e) {
  564 + e.printStackTrace();
  565 + }
  566 + } else {
  567 + dialog.setMessage("连接打印机中...");
  568 + }
  569 + break;
  570 + case BluetoothService.STATE_NONE:
  571 + break;
  572 + case BluetoothService.STATE_LISTEN:
  573 + // MyApp.getInstance().setBluConnection(false);
  574 + if (dialog != null) {
  575 + dialog.dismiss();
  576 + dialog = null;
  577 + }
  578 + break;
  579 + case BluetoothService.STATE_FAILL:
  580 + if (dialog != null) {
  581 + dialog.dismiss();
  582 + dialog = null;
  583 + }
  584 + finish();
  585 + break;
  586 + }
  587 + break;
  588 + case BluetoothService.STATE_FAILL:
  589 + if (dialog != null) {
  590 + dialog.dismiss();
  591 + dialog = null;
  592 + }
  593 + finish();
  594 + break;
  595 + case BluetoothService.MESSAGE_WRITE:
  596 + break;
  597 + case BluetoothService.MESSAGE_READ:
  598 + break;
  599 + case BluetoothService.MESSAGE_DEVICE_NAME:
  600 + // 保存连接设备的名字
  601 + mConnectedDeviceName = msg.getData().getString(
  602 + BluetoothService.DEVICE_NAME);
  603 + if (type != null && type == DeviceType.HANDSET.getValue()) {
  604 + MToast.makeText(MobilePrintTool.this,
  605 + "连接到" + mConnectedDeviceName, MToast.LENGTH_SHORT)
  606 + .show();
  607 + } else {
  608 + Toast.makeText(MobilePrintTool.this,
  609 + "连接到" + mConnectedDeviceName, Toast.LENGTH_SHORT)
  610 + .show();
  611 + }
  612 + if (!isprint) {
  613 + isprint = true;
  614 + isprint2 = true;
  615 + }
  616 + if (!TextUtils.isEmpty(info)) {
  617 + print(info);
  618 + } else {
  619 + Toast.makeText(MobilePrintTool.this,
  620 + "没有可打印数据!", Toast.LENGTH_SHORT)
  621 + .show();
  622 + }
  623 + break;
  624 + case BluetoothService.MESSAGE_TOAST:
  625 + if (!msg.getData().getBoolean("sucess", false)) {
  626 + finish();
  627 + return;
  628 + }
  629 + if (Thread.currentThread() != Looper.getMainLooper()
  630 + .getThread()) {
  631 + Looper.prepare();
  632 + }
  633 + String info = msg.getData().getString(BluetoothService.TOAST);
  634 + if (info != null && !info.equals("")) {
  635 + if (type != null && type == DeviceType.HANDSET.getValue()) {
  636 + MToast.makeText(
  637 + MobilePrintTool.this,
  638 + msg.getData().getString(BluetoothService.TOAST),
  639 + MToast.LENGTH_LONG).show();
  640 + } else {
  641 + Toast.makeText(
  642 + MobilePrintTool.this,
  643 + msg.getData().getString(BluetoothService.TOAST),
  644 + Toast.LENGTH_LONG).show();
  645 + }
  646 + if (Thread.currentThread() != Looper.getMainLooper()
  647 + .getThread()) {
  648 + Looper.loop();
  649 + }
  650 + }
  651 + break;
  652 + }
  653 + }
  654 + };
643 655
644 @Override 656 @Override
645 protected void onDestroy() { 657 protected void onDestroy() {