|
@@ -9,6 +9,7 @@ import android.os.Bundle;
|
|
import android.os.CountDownTimer;
|
|
import android.os.CountDownTimer;
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
import android.os.RemoteException;
|
|
import android.os.RemoteException;
|
|
|
|
+import android.provider.Settings;
|
|
import android.view.Gravity;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import android.view.WindowManager;
|
|
@@ -18,7 +19,6 @@ import android.widget.Toast;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.blankj.utilcode.util.ToastUtils;
|
|
|
|
import com.hjq.bar.OnTitleBarListener;
|
|
import com.hjq.bar.OnTitleBarListener;
|
|
import com.hjq.bar.TitleBar;
|
|
import com.hjq.bar.TitleBar;
|
|
import com.hw.nativeapp.MApplication;
|
|
import com.hw.nativeapp.MApplication;
|
|
@@ -27,6 +27,7 @@ import com.hw.nativeapp.httpnet.ErrorConsumer;
|
|
import com.hw.nativeapp.httpnet.ResponseConsumer;
|
|
import com.hw.nativeapp.httpnet.ResponseConsumer;
|
|
import com.hw.nativeapp.utils.RxUtil;
|
|
import com.hw.nativeapp.utils.RxUtil;
|
|
import com.hw.nativeapp.utils.StringUtils;
|
|
import com.hw.nativeapp.utils.StringUtils;
|
|
|
|
+import com.hw.nativeapp.utils.ToastUtils;
|
|
import com.sunmi.extprinterservice.ExtPrinterService;
|
|
import com.sunmi.extprinterservice.ExtPrinterService;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -89,11 +90,13 @@ public class IssueTicketsActivity extends BaseActivity {
|
|
selfIndex();
|
|
selfIndex();
|
|
getPageTransmitParams();
|
|
getPageTransmitParams();
|
|
bindExtPrinterService();
|
|
bindExtPrinterService();
|
|
|
|
+ logReport("onCreate");
|
|
// initPageView();
|
|
// initPageView();
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
protected void onStop() {
|
|
protected void onStop() {
|
|
super.onStop();
|
|
super.onStop();
|
|
|
|
+ logReport("onStop ");
|
|
if (serviceConnection != null) {
|
|
if (serviceConnection != null) {
|
|
try {
|
|
try {
|
|
unbindService(serviceConnection);
|
|
unbindService(serviceConnection);
|
|
@@ -102,10 +105,12 @@ public class IssueTicketsActivity extends BaseActivity {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ logReport("onStop 2");
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
|
+ logReport("onDestroy 1");
|
|
if (serviceConnection != null) {
|
|
if (serviceConnection != null) {
|
|
try {
|
|
try {
|
|
unbindService(serviceConnection);
|
|
unbindService(serviceConnection);
|
|
@@ -114,6 +119,7 @@ public class IssueTicketsActivity extends BaseActivity {
|
|
}
|
|
}
|
|
serviceConnection = null;
|
|
serviceConnection = null;
|
|
}
|
|
}
|
|
|
|
+ logReport("onDestroy 2");
|
|
}
|
|
}
|
|
//获取页面传递参数
|
|
//获取页面传递参数
|
|
private void getPageTransmitParams(){
|
|
private void getPageTransmitParams(){
|
|
@@ -133,24 +139,39 @@ public class IssueTicketsActivity extends BaseActivity {
|
|
// 出票完成
|
|
// 出票完成
|
|
private void finishView( boolean isSuccess) {
|
|
private void finishView( boolean isSuccess) {
|
|
if (isSuccess){
|
|
if (isSuccess){
|
|
- Toast.makeText(IssueTicketsActivity.this, "出票完成!", Toast.LENGTH_SHORT).show();
|
|
|
|
- tx_issue_status_text.setText("出票完成~");
|
|
|
|
- tx_issue_txt.setText("请取票!");
|
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ ToastUtils.showShortToast(this, "出票完成!");
|
|
|
|
+ tx_issue_status_text.setVisibility(View.VISIBLE);
|
|
|
|
+ tx_issue_txt.setVisibility(View.VISIBLE);
|
|
|
|
+ tx_issue_status_text.setText("出票完成~");
|
|
|
|
+ tx_issue_txt.setText("请取票!");
|
|
|
|
+ });
|
|
|
|
+ logReport("出票完成");
|
|
}else {
|
|
}else {
|
|
- Toast.makeText(IssueTicketsActivity.this, "出票失败!", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ ToastUtils.showShortToast(this, "出票失败!");
|
|
|
|
+ });
|
|
// tx_issue_status_text.setText("出票失败~");
|
|
// tx_issue_status_text.setText("出票失败~");
|
|
// tx_issue_txt.setText("即将退出!");
|
|
// tx_issue_txt.setText("即将退出!");
|
|
|
|
+ logReport("出票失败");
|
|
finish();
|
|
finish();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SuppressLint("CheckResult")
|
|
private void selfIndex(){
|
|
private void selfIndex(){
|
|
MApplication.getApiService().selfIndex( System.currentTimeMillis() / 1000)
|
|
MApplication.getApiService().selfIndex( System.currentTimeMillis() / 1000)
|
|
.compose(RxUtil.applyObservableAsync())
|
|
.compose(RxUtil.applyObservableAsync())
|
|
.subscribe(new ResponseConsumer<JSONObject>() {
|
|
.subscribe(new ResponseConsumer<JSONObject>() {
|
|
@Override
|
|
@Override
|
|
public void onSuccess(JSONObject data) {
|
|
public void onSuccess(JSONObject data) {
|
|
- tx_customerMobile.setText("客服电话:" + data.getString("customerMobile"));
|
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ tx_customerMobile.setText("客服电话:" + data.getString("customerMobile"));
|
|
|
|
+ });
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -207,27 +228,36 @@ public class IssueTicketsActivity extends BaseActivity {
|
|
* 4 打印机过热
|
|
* 4 打印机过热
|
|
* */
|
|
* */
|
|
int printerStatus = ext.getPrinterStatus(); //
|
|
int printerStatus = ext.getPrinterStatus(); //
|
|
- Toast.makeText(IssueTicketsActivity.this, "printerStatus=" + printerStatus, Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ ToastUtils.showShortToast(IssueTicketsActivity.this, "打印机状态:" + printerStatus);
|
|
|
|
+ });
|
|
|
|
+
|
|
if(printerStatus == 2) {
|
|
if(printerStatus == 2) {
|
|
- tx_issue_not.setVisibility(View.VISIBLE);
|
|
|
|
- tx_issue_txt.setVisibility(View.GONE);
|
|
|
|
- img_issue_tickets.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.take_not));
|
|
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ tx_issue_not.setVisibility(View.VISIBLE);
|
|
|
|
+ tx_issue_txt.setVisibility(View.GONE);
|
|
|
|
+ img_issue_tickets.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.take_not));
|
|
|
|
+ });
|
|
|
|
+
|
|
}
|
|
}
|
|
if(printerStatus != 0 && printerStatus != 3){
|
|
if(printerStatus != 0 && printerStatus != 3){
|
|
- String msg = printerStatus == -1 ? "打印机脱机或打印服务还未连接打印机" : printerStatus == 1 ? "打印机开盖" : printerStatus == 2 ? "打印机缺纸" : printerStatus == 3 ? "打印机即将缺纸" : "打印机过热";
|
|
|
|
- ToastUtils Toast = new ToastUtils();
|
|
|
|
- Toast.setGravity(Gravity.TOP, 0, 200);
|
|
|
|
- Toast.setTextSize(32);
|
|
|
|
- Toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
|
|
|
|
- Toast.show(msg);
|
|
|
|
|
|
+ String msg = printerStatus == -1 ? "打印机脱机或打印服务还未连接打印机" : printerStatus == 1 ? "打印机开盖" : printerStatus == 2
|
|
|
|
+ ? "打印机缺纸" : printerStatus == 3 ? "打印机即将缺纸" : "打印机过热";
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ ToastUtils.showShortToast(this, msg);
|
|
|
|
+ });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
ext.startTransBuffer(); //启⽤事务模式
|
|
ext.startTransBuffer(); //启⽤事务模式
|
|
int index = 1;
|
|
int index = 1;
|
|
for (JSONObject it : printList){
|
|
for (JSONObject it : printList){
|
|
- Toast.makeText(IssueTicketsActivity.this, "开始打印:" + index, Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
+ logReport("开始打印:" + index);
|
|
printExecute(it);
|
|
printExecute(it);
|
|
|
|
+ logReport("打印结束:" + index);
|
|
index++;
|
|
index++;
|
|
}
|
|
}
|
|
ext.endTransBuffer(); //结束事务模式
|
|
ext.endTransBuffer(); //结束事务模式
|
|
@@ -243,64 +273,82 @@ public class IssueTicketsActivity extends BaseActivity {
|
|
.toJavaList(JSONObject.class);
|
|
.toJavaList(JSONObject.class);
|
|
if (rowItem != null && !rowItem.isEmpty()){
|
|
if (rowItem != null && !rowItem.isEmpty()){
|
|
for (JSONObject itemJson : rowItem){
|
|
for (JSONObject itemJson : rowItem){
|
|
|
|
+ logReport("打印中:ITEM:" + itemJson.toJSONString());
|
|
// 打印文本
|
|
// 打印文本
|
|
String printType = itemJson.getString("printType");
|
|
String printType = itemJson.getString("printType");
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("text")){
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("text")){
|
|
int hori = itemJson.get("hori") == null ? 1 : itemJson.getInteger("hori");
|
|
int hori = itemJson.get("hori") == null ? 1 : itemJson.getInteger("hori");
|
|
int veri = itemJson.get("veri")== null ? 1 : itemJson.getInteger("veri");
|
|
int veri = itemJson.get("veri")== null ? 1 : itemJson.getInteger("veri");
|
|
|
|
+ int alignMode =itemJson.get("alignMode") == null ? 1 : itemJson.getInteger("alignMode");
|
|
|
|
+ String printContent = itemJson.containsKey("printContent")?itemJson.getString("printContent"):"";
|
|
|
|
+ logReport("文本打印开始::hori:" + hori + " veri:" + veri + " alignMode:" + alignMode + " printContent:" + printContent);
|
|
ext.setFontZoom(hori, veri);
|
|
ext.setFontZoom(hori, veri);
|
|
// 对其方式
|
|
// 对其方式
|
|
- int alignMode =itemJson.get("alignMode") == null ? 1 : itemJson.getInteger("alignMode");
|
|
|
|
ext.setAlignMode(alignMode);
|
|
ext.setAlignMode(alignMode);
|
|
- String printContent = itemJson.containsKey("printContent")?itemJson.getString("printContent"):"";
|
|
|
|
ext.printText(printContent);
|
|
ext.printText(printContent);
|
|
|
|
+ logReport("文本打印结束");
|
|
}
|
|
}
|
|
// 打印二维码
|
|
// 打印二维码
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("qrcode")){
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("qrcode")){
|
|
// 对其方式
|
|
// 对其方式
|
|
int alignMode = itemJson.get("alignMode") == null ? 1 : itemJson.getInteger("alignMode");
|
|
int alignMode = itemJson.get("alignMode") == null ? 1 : itemJson.getInteger("alignMode");
|
|
- ext.setAlignMode(alignMode);
|
|
|
|
-
|
|
|
|
String eqCode = itemJson.get("printContent") == null ? "" : itemJson.getString("printContent");
|
|
String eqCode = itemJson.get("printContent") == null ? "" : itemJson.getString("printContent");
|
|
int qrcodeSize = itemJson.get("qrcodeSize") == null ? 0 : itemJson.getInteger("qrcodeSize");
|
|
int qrcodeSize = itemJson.get("qrcodeSize") == null ? 0 : itemJson.getInteger("qrcodeSize");
|
|
|
|
+ logReport("二维码打印开始::alignMode:" + alignMode + " eqCode:" + eqCode + " qrcodeSize:" + qrcodeSize );
|
|
|
|
+ ext.setAlignMode(alignMode);
|
|
ext.printQrCode(eqCode, qrcodeSize, 0);
|
|
ext.printQrCode(eqCode, qrcodeSize, 0);
|
|
|
|
+ logReport("二维码打印结束");
|
|
}
|
|
}
|
|
// 打印条形码
|
|
// 打印条形码
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("barCode")){
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("barCode")){
|
|
// 对其方式
|
|
// 对其方式
|
|
int alignMode = itemJson.get("alignMode") == null ? 0 : itemJson.getInteger("alignMode");
|
|
int alignMode = itemJson.get("alignMode") == null ? 0 : itemJson.getInteger("alignMode");
|
|
- ext.setAlignMode(alignMode);
|
|
|
|
-
|
|
|
|
String barCode = itemJson.get("printContent") == null ? "" : itemJson.getString("printContent");
|
|
String barCode = itemJson.get("printContent") == null ? "" : itemJson.getString("printContent");
|
|
int barCodeType = itemJson.get("barCodeType") == null ? 0 : itemJson.getInteger("barCodeType");
|
|
int barCodeType = itemJson.get("barCodeType") == null ? 0 : itemJson.getInteger("barCodeType");
|
|
int width =itemJson.get("width") == null ? 0 : itemJson.getInteger("width");
|
|
int width =itemJson.get("width") == null ? 0 : itemJson.getInteger("width");
|
|
int height = itemJson.get("height") == null ? 0 : itemJson.getInteger("height");
|
|
int height = itemJson.get("height") == null ? 0 : itemJson.getInteger("height");
|
|
|
|
+ logReport("条形码打印开始::alignMode:" + alignMode + " barCode:" + barCode + " barCodeType:" + barCodeType +
|
|
|
|
+ " width:" + width + " height:" + height);
|
|
|
|
+ ext.setAlignMode(alignMode);
|
|
ext.printBarCode(barCode, barCodeType, width, height, 1);
|
|
ext.printBarCode(barCode, barCodeType, width, height, 1);
|
|
|
|
+ logReport("条形码打印结束");
|
|
}
|
|
}
|
|
// 打印走纸
|
|
// 打印走纸
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("wrpe")){
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("wrpe")){
|
|
// 走纸类型: 1-按行 2-按像素
|
|
// 走纸类型: 1-按行 2-按像素
|
|
int wrapType = itemJson.get("wrapType") == null ? 0 : itemJson.getInteger("wrapType");
|
|
int wrapType = itemJson.get("wrapType") == null ? 0 : itemJson.getInteger("wrapType");
|
|
int wrapLen = itemJson.get("wrapLen") == null ? 0 : itemJson.getInteger("wrapLen");
|
|
int wrapLen = itemJson.get("wrapLen") == null ? 0 : itemJson.getInteger("wrapLen");
|
|
|
|
+ logReport("打印走纸开始::wrapType:" + wrapType + " wrapLen:" + wrapLen );
|
|
if(wrapType == 1) {
|
|
if(wrapType == 1) {
|
|
ext.lineWrap(wrapLen);
|
|
ext.lineWrap(wrapLen);
|
|
} else if (wrapType == 2) {
|
|
} else if (wrapType == 2) {
|
|
ext.pixelWrap(wrapLen);
|
|
ext.pixelWrap(wrapLen);
|
|
}
|
|
}
|
|
|
|
+ logReport("打印走纸结束");
|
|
}
|
|
}
|
|
// 打印切纸
|
|
// 打印切纸
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("cut")){
|
|
if(!StringUtils.isEmpty(printType) && printType.equals("cut")){
|
|
int cutPx = itemJson.get("cutPx") == null ? 0 : itemJson.getInteger("cutPx");
|
|
int cutPx = itemJson.get("cutPx") == null ? 0 : itemJson.getInteger("cutPx");
|
|
int cutType = itemJson.get("cutType") == null ? 0 : itemJson.getInteger("cutType");
|
|
int cutType = itemJson.get("cutType") == null ? 0 : itemJson.getInteger("cutType");
|
|
|
|
+ logReport("打印切纸开始::cutPx:" + cutPx + " cutType:" + cutType );
|
|
ext.cutPaper(cutType, cutPx);
|
|
ext.cutPaper(cutType, cutPx);
|
|
|
|
+ logReport("打印走纸结束");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
- Toast.makeText(IssueTicketsActivity.this, "打印数据为空", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
+ logReport("打印数据为空");
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ ToastUtils.showShortToast(this, "打印数据为空");
|
|
|
|
+ });
|
|
finishView(true);
|
|
finishView(true);
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
- Toast.makeText(IssueTicketsActivity.this, "打印数据不存在", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
+ logReport("打印数据不存在");
|
|
|
|
+ runOnUiThread(() -> {
|
|
|
|
+ // 更新用户界面
|
|
|
|
+ ToastUtils.showShortToast(this, "打印数据不存在");
|
|
|
|
+ });
|
|
finishView(true);
|
|
finishView(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -319,9 +367,40 @@ public class IssueTicketsActivity extends BaseActivity {
|
|
ext = ExtPrinterService.Stub.asInterface(service);
|
|
ext = ExtPrinterService.Stub.asInterface(service);
|
|
initPageView();
|
|
initPageView();
|
|
}
|
|
}
|
|
- @Override public void onServiceDisconnected(ComponentName name) {}
|
|
|
|
- @Override public void onBindingDied(ComponentName name) {}
|
|
|
|
- @Override public void onNullBinding(ComponentName name) {}
|
|
|
|
|
|
+ @Override public void onServiceDisconnected(ComponentName name) {
|
|
|
|
+ logReport("onServiceDisconnected");
|
|
|
|
+ }
|
|
|
|
+ @Override public void onBindingDied(ComponentName name) {
|
|
|
|
+ logReport("onBindingDied");
|
|
|
|
+ }
|
|
|
|
+ @Override public void onNullBinding(ComponentName name) {
|
|
|
|
+ logReport("onNullBinding");
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @SuppressLint("CheckResult")
|
|
|
|
+ private void logReport(String content){
|
|
|
|
+ JSONObject options = new JSONObject();
|
|
|
|
+ String deviceId = "";
|
|
|
|
+ try {
|
|
|
|
+ deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
|
|
|
+ }catch (Exception ignored){}
|
|
|
|
+ options.put("apkId", "1");
|
|
|
|
+ options.put("apkTag", deviceId);
|
|
|
|
+ options.put("content", content);
|
|
|
|
+ MApplication.getApiService().apkLog( options, System.currentTimeMillis() / 1000)
|
|
|
|
+ .compose(RxUtil.applyObservableAsync())
|
|
|
|
+ .subscribe(new ResponseConsumer<JSONObject>() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onSuccess(JSONObject data) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFailed(int code, String msg) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }, new ErrorConsumer());
|
|
|
|
+ }
|
|
}
|
|
}
|