|
@@ -100,6 +100,7 @@ import androidx.core.app.ActivityCompat;
|
|
|
import androidx.core.content.ContextCompat;
|
|
import androidx.core.content.ContextCompat;
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
|
|
|
|
|
|
+import android.util.Size;
|
|
|
import static net.posprinter.TSPLConst.FNT_SIMPLIFIED_CHINESE;
|
|
import static net.posprinter.TSPLConst.FNT_SIMPLIFIED_CHINESE;
|
|
|
import static net.posprinter.TSPLConst.ROTATION_90;
|
|
import static net.posprinter.TSPLConst.ROTATION_90;
|
|
|
|
|
|
|
@@ -107,6 +108,7 @@ import android_serialport_api.SerialPortFinder;
|
|
|
|
|
|
|
|
public class MainActivity extends BaseActivity {
|
|
public class MainActivity extends BaseActivity {
|
|
|
private final String TAG = "HomeActivity";
|
|
private final String TAG = "HomeActivity";
|
|
|
|
|
+ private final String TAG2 = "BleBle";
|
|
|
|
|
|
|
|
private WebView mWebView;
|
|
private WebView mWebView;
|
|
|
private LinearLayout ll_nonet;
|
|
private LinearLayout ll_nonet;
|
|
@@ -439,7 +441,8 @@ public class MainActivity extends BaseActivity {
|
|
|
if (data == null) {
|
|
if (data == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- startPrint(data);
|
|
|
|
|
|
|
+ // startPrint(data);
|
|
|
|
|
+ startPrint_1(data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
@@ -452,7 +455,7 @@ public class MainActivity extends BaseActivity {
|
|
|
if (data == null) {
|
|
if (data == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- startPrint2(data);
|
|
|
|
|
|
|
+ startPrint2_1(data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
@@ -470,13 +473,13 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
|
public void startScan(String name) {
|
|
public void startScan(String name) {
|
|
|
- Log.e(TAG, "startScan name"+name);
|
|
|
|
|
|
|
+ Log.e(TAG2, "startScan name"+name);
|
|
|
checkPermissions(name);
|
|
checkPermissions(name);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@JavascriptInterface
|
|
@JavascriptInterface
|
|
|
public void closeScan() {
|
|
public void closeScan() {
|
|
|
- Log.e(TAG, "closeScan");
|
|
|
|
|
|
|
+ Log.e(TAG2, "closeScan");
|
|
|
toCloseScan();
|
|
toCloseScan();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -746,6 +749,8 @@ public class MainActivity extends BaseActivity {
|
|
|
// -------------------------------------获取usb口状态结束---------------------------------
|
|
// -------------------------------------获取usb口状态结束---------------------------------
|
|
|
|
|
|
|
|
// -------------------------------------拍照相关方法结束----------------------------------
|
|
// -------------------------------------拍照相关方法结束----------------------------------
|
|
|
|
|
+ int retryCount = 0;
|
|
|
|
|
+ int maxRetries = 10;
|
|
|
private void toCloseCamera() {
|
|
private void toCloseCamera() {
|
|
|
// 如果相机预览还开着, 则关闭
|
|
// 如果相机预览还开着, 则关闭
|
|
|
cameraIsOpening = false;
|
|
cameraIsOpening = false;
|
|
@@ -823,8 +828,10 @@ public class MainActivity extends BaseActivity {
|
|
|
@SuppressLint("RestrictedApi")
|
|
@SuppressLint("RestrictedApi")
|
|
|
@Override
|
|
@Override
|
|
|
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
|
|
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
|
|
|
- Log.e("-------->","------>savePath="+outputFileResults.getSavedUri().getPath());
|
|
|
|
|
- Log.e("-------->","------>保存成功");
|
|
|
|
|
|
|
+ Log.e("takePhoto","------>savePath="+outputFileResults.getSavedUri().getPath());
|
|
|
|
|
+ Log.e("takePhoto","------>保存成功");
|
|
|
|
|
+ Log.e("takePhoto","------>重试数:" + retryCount);
|
|
|
|
|
+ retryCount = 0;
|
|
|
// Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
|
|
// Toast.makeText(MainActivity.this, "保存成功", Toast.LENGTH_SHORT).show();
|
|
|
savePicture(file, path, name);
|
|
savePicture(file, path, name);
|
|
|
mWebView.loadUrl("javascript:uploadPhotoPath('" + outputFileOptions.getFile().getAbsolutePath() + "')");
|
|
mWebView.loadUrl("javascript:uploadPhotoPath('" + outputFileOptions.getFile().getAbsolutePath() + "')");
|
|
@@ -832,8 +839,19 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onError(@NonNull ImageCaptureException exception) {
|
|
public void onError(@NonNull ImageCaptureException exception) {
|
|
|
- Log.e("----------->","------->"+exception.getMessage());
|
|
|
|
|
-// Toast.makeText(MainActivity.this, "Error: " + exception.getMessage(), Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
+ Log.e("takePhoto","------>保存失败: "+exception.getMessage());
|
|
|
|
|
+ Log.e("takePhoto","------>重试数:" + retryCount);
|
|
|
|
|
+ if (retryCount < maxRetries) {
|
|
|
|
|
+ retryCount++;
|
|
|
|
|
+ // 重试拍照
|
|
|
|
|
+ imageCapture.takePicture(
|
|
|
|
|
+ // 第一个参数 OutputFileOptions 指定了照片保存的位置和格式等信息。
|
|
|
|
|
+ outputFileOptions,
|
|
|
|
|
+ // 第二个参数 Executor 指定了保存照片时要运行的线程。
|
|
|
|
|
+ ContextCompat.getMainExecutor(MainActivity.this),
|
|
|
|
|
+ this
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -906,6 +924,8 @@ public class MainActivity extends BaseActivity {
|
|
|
videoCapture = null;
|
|
videoCapture = null;
|
|
|
imageCapture = new ImageCapture.Builder()
|
|
imageCapture = new ImageCapture.Builder()
|
|
|
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
|
|
|
+ .setTargetResolution(new Size(1280, 720))
|
|
|
|
|
+ .setFlashMode(ImageCapture.FLASH_MODE_OFF) // 关闭闪光灯
|
|
|
// 设置JPEG的质量为85%
|
|
// 设置JPEG的质量为85%
|
|
|
.setJpegQuality(85)
|
|
.setJpegQuality(85)
|
|
|
.build();
|
|
.build();
|
|
@@ -963,9 +983,10 @@ public class MainActivity extends BaseActivity {
|
|
|
static int fontSizeMultiple = 2;//字体倍数
|
|
static int fontSizeMultiple = 2;//字体倍数
|
|
|
static int fontSizeMultiple1 = 3;//字体倍数
|
|
static int fontSizeMultiple1 = 3;//字体倍数
|
|
|
static int mOffsetY = 5;//打印开始点离左边的距离(Y轴),5mm
|
|
static int mOffsetY = 5;//打印开始点离左边的距离(Y轴),5mm
|
|
|
- static int mOffsetX = mPaperWidth-5;//打印开始点离上边的距离(X轴),5mm
|
|
|
|
|
|
|
+ static int mOffsetX = mPaperWidth-6;//打印开始点离上边的距离(X轴),5mm
|
|
|
static int mFontWidth = mWFont * fontSizeMultiple;//文字的宽度
|
|
static int mFontWidth = mWFont * fontSizeMultiple;//文字的宽度
|
|
|
static int mFontHeight = mHFont * fontSizeMultiple;//文字的高度
|
|
static int mFontHeight = mHFont * fontSizeMultiple;//文字的高度
|
|
|
|
|
+ static int mFontHeightDistanceHalf = mHFont * (fontSizeMultiple1 - fontSizeMultiple) / 2;//文字的高度
|
|
|
static int mSpace = 4;//行列间隔-----5mm
|
|
static int mSpace = 4;//行列间隔-----5mm
|
|
|
static int mTextSpace = 1;//换行间距----2mm
|
|
static int mTextSpace = 1;//换行间距----2mm
|
|
|
static int mCodeSize = 30;//二维码宽高----30mm
|
|
static int mCodeSize = 30;//二维码宽高----30mm
|
|
@@ -1020,7 +1041,73 @@ public class MainActivity extends BaseActivity {
|
|
|
printer.print();
|
|
printer.print();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ private void startPrint_1(List<PrintModule> data) {
|
|
|
|
|
+ for (PrintModule module:data) {
|
|
|
|
|
+ printer.sizeMm(mPaperWidth, mPaperHeight) // 纸张尺寸
|
|
|
|
|
+ .density(15) // 字体颜色浓淡
|
|
|
|
|
+ .reference(mPaperWidth*mPot, 0) // 定义打印坐标原点
|
|
|
|
|
+ .direction(TSPLConst.DIRECTION_FORWARD)
|
|
|
|
|
+ .cls()
|
|
|
|
|
+ .text(mOffsetX*mPot - mFontHeightDistanceHalf / 2, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "订单号:")
|
|
|
|
|
+ .text(mOffsetX*mPot, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.exe_sale_order_b.no)
|
|
|
|
|
+ .text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "产 品:");
|
|
|
|
|
+ String[] productName = getStrs(module.material_code_show, (mPaperHeight-2*mOffsetY-mSpace-mCodeSize)*mPot-5*mFontWidth);
|
|
|
|
|
+ printer.text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[0]);
|
|
|
|
|
+ int currentHeight = (mOffsetX-mSpace)*mPot-2*mFontHeight;
|
|
|
|
|
+ if (!TextUtils.isEmpty(productName[1])){
|
|
|
|
|
+ currentHeight = currentHeight-mTextSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[1]);
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ currentHeight = currentHeight-mTextSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, " ");
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight;
|
|
|
|
|
+ }
|
|
|
|
|
+ currentHeight = currentHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "花 色:") // 花色 -> module.decor_code_show
|
|
|
|
|
+ .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.decor_code_show);
|
|
|
|
|
+ // 测试用
|
|
|
|
|
+ //module.box_order_product.color_two = "第二花色 第二花色";
|
|
|
|
|
+ if (module.decor_two_code_show !=null){
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.decor_code_show)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.decor_two_code_show);
|
|
|
|
|
+ }
|
|
|
|
|
+// // 工艺部分
|
|
|
|
|
+// currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+// printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "工 艺:") // 工艺 -> module.craft_type_code_show
|
|
|
|
|
+// .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.craft_type_code_show);
|
|
|
|
|
+// // 测试用
|
|
|
|
|
+// module.box_order_product.process_title_two = "第二工艺 第二工艺";
|
|
|
|
|
+// if (module.craft_type_two_code_show!=null){
|
|
|
|
|
+// printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.craft_type_code_show)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.craft_type_two_code_show);
|
|
|
|
|
+// }
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "经销商:"); // 经销商: -> module.exe_sale_order_b.customer_name
|
|
|
|
|
+ String[] customerName = getStrs(module.exe_sale_order_b.customer_name , mPaperHeight*mPot-5*mFontWidth);
|
|
|
|
|
+ if (!TextUtils.isEmpty(customerName[0])){
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, customerName[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!TextUtils.isEmpty(customerName[1])){
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, customerName[1]);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, "");
|
|
|
|
|
+ }
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot/8;
|
|
|
|
|
+ printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装数量:") // 包装数量 -> module.box_num
|
|
|
|
|
+ .text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_num)
|
|
|
|
|
+ .text(currentHeight + mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.box_no)-getStrLength("包装单号:"), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装单号: ") // 包装单号 -> module.box_no
|
|
|
|
|
+ .text(currentHeight+ mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.box_no), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.box_no)
|
|
|
|
|
+ .text(currentHeight - 3 * mFontHeight / 4, (mPaperHeight-5)*mPot-getStrLength(module.box_no)-getStrLength("包装单号:"), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.now_date);
|
|
|
|
|
+ // 二维码 qrX:32 qrY:30 cellWidth:10
|
|
|
|
|
+ // 二维码 qrX:25 qrY:25 cellWidth:8
|
|
|
|
|
+ int qrX = (mOffsetX - 26)* mPot;
|
|
|
|
|
+ int qrY = (mPaperHeight - 5 - 28) * mPot;
|
|
|
|
|
+ printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 9, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.box_no);
|
|
|
|
|
+ printer.print();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
private void startPrint2(List<PrintModule2> data) {
|
|
private void startPrint2(List<PrintModule2> data) {
|
|
|
for (PrintModule2 module:data) {
|
|
for (PrintModule2 module:data) {
|
|
|
printer.sizeMm(mPaperWidth, mPaperHeight)
|
|
printer.sizeMm(mPaperWidth, mPaperHeight)
|
|
@@ -1071,11 +1158,78 @@ public class MainActivity extends BaseActivity {
|
|
|
printer.print();
|
|
printer.print();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ private void startPrint2_1(List<PrintModule2> data) {
|
|
|
|
|
+ for (PrintModule2 module:data) {
|
|
|
|
|
+ printer.sizeMm(mPaperWidth, mPaperHeight) // 纸张尺寸
|
|
|
|
|
+ .density(15) // 字体颜色浓淡
|
|
|
|
|
+ .reference(mPaperWidth*mPot, 0) // 定义打印坐标原点
|
|
|
|
|
+ .direction(TSPLConst.DIRECTION_FORWARD)
|
|
|
|
|
+ .cls()
|
|
|
|
|
+ .text(mOffsetX*mPot - mFontHeightDistanceHalf / 2, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "订单号:")
|
|
|
|
|
+ .text(mOffsetX*mPot, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.order_no)
|
|
|
|
|
+ .text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "产 品:");
|
|
|
|
|
+ String[] productName = getStrs(module.box_order_product.material_title, (mPaperHeight-2*mOffsetY-mSpace-mCodeSize)*mPot-5*mFontWidth);
|
|
|
|
|
+ printer.text((mOffsetX-mSpace)*mPot-mFontHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[0]);
|
|
|
|
|
+ int currentHeight = (mOffsetX-mSpace)*mPot-2*mFontHeight;
|
|
|
|
|
+ if (!TextUtils.isEmpty(productName[1])){
|
|
|
|
|
+ currentHeight = currentHeight-mTextSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, productName[1]);
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ currentHeight = currentHeight-mTextSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, " ");
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight;
|
|
|
|
|
+ }
|
|
|
|
|
+ currentHeight = currentHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "花 色:") // 花色 -> module.decor_code_show
|
|
|
|
|
+ .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.color);
|
|
|
|
|
+ // 测试用
|
|
|
|
|
+// module.box_order_product.color_two = "第二花色 第二花色";
|
|
|
|
|
+ if (module.box_order_product.color_two !=null){
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.box_order_product.color)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.color_two);
|
|
|
|
|
+ }
|
|
|
|
|
+// // 工艺部分
|
|
|
|
|
+// currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+// printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "工 艺:") // 工艺 -> module.craft_type_code_show
|
|
|
|
|
+// .text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.process_title);
|
|
|
|
|
+// // 测试用
|
|
|
|
|
+// module.box_order_product.process_title_two = "第二工艺 第二工艺";
|
|
|
|
|
+// if (module.box_order_product.process_title_two!=null){
|
|
|
|
|
+// printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth)+getStrLength2(module.box_order_product.process_title)+mSpace*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.process_title_two);
|
|
|
|
|
+// }
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "经销商:"); // 经销商: -> module.exe_sale_order_b.customer_name
|
|
|
|
|
+ String[] customerName = getStrs(module.box_order_product.customer_name, mPaperHeight*mPot - 12 * mFontWidth);
|
|
|
|
|
+ if (!TextUtils.isEmpty(customerName[0])){
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, customerName[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!TextUtils.isEmpty(customerName[1])){
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, customerName[1]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot+(4*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, " ");
|
|
|
|
|
+ }
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ currentHeight = currentHeight - mFontHeight-mSpace*mPot/8;
|
|
|
|
|
+ printer.text(currentHeight - mFontHeightDistanceHalf, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装数量:") // 包装数量 -> module.box_num
|
|
|
|
|
+ .text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple1,fontSizeMultiple1, module.box_order_product.box_num)
|
|
|
|
|
+ .text(currentHeight + mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.no)-getStrLength("包装单号: "), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装单号: ") // 包装单号 -> module.box_no
|
|
|
|
|
+ .text(currentHeight+ mFontHeight/2, (mPaperHeight-5)*mPot-getStrLength(module.no), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.no)
|
|
|
|
|
+ .text(currentHeight - 3 * mFontHeight / 4, (mPaperHeight-5)*mPot-getStrLength(module.no)-getStrLength("包装单号: "), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.now_date);
|
|
|
|
|
+ // 二维码 qrX:32 qrY:30 cellWidth:10
|
|
|
|
|
+ // 二维码 qrX:25 qrY:25 cellWidth:8
|
|
|
|
|
+ int qrX = (mOffsetX - 26)* mPot;
|
|
|
|
|
+ int qrY = (mPaperHeight - 5 - 28) * mPot;
|
|
|
|
|
+ printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 9, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.no);
|
|
|
|
|
+ printer.print();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
private void startPrint3(List<PrintModule3> data) {
|
|
private void startPrint3(List<PrintModule3> data) {
|
|
|
for (PrintModule3 module:data) {
|
|
for (PrintModule3 module:data) {
|
|
|
printer.sizeMm(mPaperWidth, mPaperHeight)
|
|
printer.sizeMm(mPaperWidth, mPaperHeight)
|
|
|
- .density(10)
|
|
|
|
|
|
|
+ .density(15)
|
|
|
.reference(mPaperWidth*mPot, 0)
|
|
.reference(mPaperWidth*mPot, 0)
|
|
|
.direction(TSPLConst.DIRECTION_FORWARD)
|
|
.direction(TSPLConst.DIRECTION_FORWARD)
|
|
|
.cls()
|
|
.cls()
|
|
@@ -1095,12 +1249,23 @@ public class MainActivity extends BaseActivity {
|
|
|
printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "商标编码:")
|
|
printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "商标编码:")
|
|
|
.text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.material_code);
|
|
.text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.material_code);
|
|
|
currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
- printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "余标:")
|
|
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "余 标:")
|
|
|
.text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.qty);
|
|
.text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.qty);
|
|
|
- printer.text(currentHeight, (mPaperHeight-5)*mPot-getStrLength(module.roll_qr_code), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.roll_qr_code);
|
|
|
|
|
currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
- printer.text(currentHeight - 2, (mPaperHeight-5)*mPot-getStrLength(module.now_date), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.now_date);
|
|
|
|
|
- int qrX = (mOffsetX - 37) * mPot;
|
|
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "卷 码:")
|
|
|
|
|
+ .text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.roll_qr_code);
|
|
|
|
|
+ currentHeight = currentHeight-mFontHeight-mSpace*mPot;
|
|
|
|
|
+ String[] no;
|
|
|
|
|
+ try {
|
|
|
|
|
+ no = module.now_date.split(":");
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, no[0] + ":")
|
|
|
|
|
+ .text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, no[1]);
|
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
|
+ printer.text(currentHeight, mOffsetY*mPot, FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, "包装日期:")
|
|
|
|
|
+ .text(currentHeight, mOffsetY*mPot+(5*mFontWidth), FNT_SIMPLIFIED_CHINESE, ROTATION_90, fontSizeMultiple,fontSizeMultiple, module.now_date);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int qrX = (mOffsetX - 31) * mPot;
|
|
|
int qrY = (mPaperHeight - 5 - 30) * mPot;
|
|
int qrY = (mPaperHeight - 5 - 30) * mPot;
|
|
|
printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 10, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.roll_qr_code);
|
|
printer.qrcode(qrX, qrY, TSPLConst.EC_LEVEL_H, 10, TSPLConst.QRCODE_MODE_MANUAL, TSPLConst.ROTATION_0, module.roll_qr_code);
|
|
|
printer.print();
|
|
printer.print();
|
|
@@ -1121,6 +1286,20 @@ public class MainActivity extends BaseActivity {
|
|
|
return xmLength;
|
|
return xmLength;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static int getStrLength2(String xm){
|
|
|
|
|
+ int xmLength = 0;
|
|
|
|
|
+ for (int i = 0; i < xm.length(); i++) {
|
|
|
|
|
+ char chr = xm.charAt(i);
|
|
|
|
|
+ if (isChinese(chr)){
|
|
|
|
|
+ xmLength+=(mWFont*fontSizeMultiple1);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ xmLength+=(mWFont*fontSizeMultiple1/2);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Log.e("------->","----->xmStrLength="+xmLength);
|
|
|
|
|
+ return xmLength;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static String[] getStrs(String xm, int maxLength){
|
|
public static String[] getStrs(String xm, int maxLength){
|
|
|
Log.e("------->","----->maxLength="+maxLength);
|
|
Log.e("------->","----->maxLength="+maxLength);
|
|
|
String[] resultStrs = new String[3];
|
|
String[] resultStrs = new String[3];
|
|
@@ -1225,7 +1404,7 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
private void setScanRule() {
|
|
private void setScanRule() {
|
|
|
BleScanRuleConfig scanRuleConfig = new BleScanRuleConfig.Builder()
|
|
BleScanRuleConfig scanRuleConfig = new BleScanRuleConfig.Builder()
|
|
|
- .setScanTimeOut(10000) // 扫描超时时间,可选,默认10秒
|
|
|
|
|
|
|
+ .setScanTimeOut(15000) // 扫描超时时间,可选,默认15秒
|
|
|
.build();
|
|
.build();
|
|
|
BleManager.getInstance().initScanRule(scanRuleConfig);
|
|
BleManager.getInstance().initScanRule(scanRuleConfig);
|
|
|
}
|
|
}
|
|
@@ -1235,13 +1414,16 @@ public class MainActivity extends BaseActivity {
|
|
|
// Toast.makeText(MainActivity.this, "开始连接", Toast.LENGTH_SHORT).show();
|
|
// Toast.makeText(MainActivity.this, "开始连接", Toast.LENGTH_SHORT).show();
|
|
|
if(mBleDevice == null) {
|
|
if(mBleDevice == null) {
|
|
|
// 蓝牙未连接过 或 连接的蓝牙不存在
|
|
// 蓝牙未连接过 或 连接的蓝牙不存在
|
|
|
|
|
+ Log.i(TAG2, "startScan: " + name + "未连接过");
|
|
|
doStartScan(name);
|
|
doStartScan(name);
|
|
|
} else if (!mBleDevice.getDevice().getName().contains(name)){
|
|
} else if (!mBleDevice.getDevice().getName().contains(name)){
|
|
|
// 要连接的蓝牙名字和之前的蓝牙设备不一致
|
|
// 要连接的蓝牙名字和之前的蓝牙设备不一致
|
|
|
// 关闭先前的蓝牙, 再扫描新的蓝牙
|
|
// 关闭先前的蓝牙, 再扫描新的蓝牙
|
|
|
|
|
+ Log.i(TAG2, "startScan: " + name + "与之前连接的蓝牙" + mBleDevice.getDevice().getName() + "不同");
|
|
|
toCloseScan();
|
|
toCloseScan();
|
|
|
doStartScan(name);
|
|
doStartScan(name);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ Log.i(TAG2, "startScan: " + "连接了相同的蓝牙" + name);
|
|
|
runOnUiThread(() -> {
|
|
runOnUiThread(() -> {
|
|
|
mWebView.loadUrl("javascript:responseCode('6')");
|
|
mWebView.loadUrl("javascript:responseCode('6')");
|
|
|
});
|
|
});
|
|
@@ -1263,6 +1445,7 @@ public class MainActivity extends BaseActivity {
|
|
|
@Override
|
|
@Override
|
|
|
public void onScanning(BleDevice bleDevice) {
|
|
public void onScanning(BleDevice bleDevice) {
|
|
|
if ((name+"BLE").equals(bleDevice.getName())){
|
|
if ((name+"BLE").equals(bleDevice.getName())){
|
|
|
|
|
+ Log.i(TAG2, "onScanning: 找到了蓝牙" + bleDevice.getName());
|
|
|
// Toast.makeText(MainActivity.this, "名字匹配去链接", Toast.LENGTH_SHORT).show();
|
|
// Toast.makeText(MainActivity.this, "名字匹配去链接", Toast.LENGTH_SHORT).show();
|
|
|
if (!BleManager.getInstance().isConnected(bleDevice)) {
|
|
if (!BleManager.getInstance().isConnected(bleDevice)) {
|
|
|
BleManager.getInstance().cancelScan();
|
|
BleManager.getInstance().cancelScan();
|
|
@@ -1285,11 +1468,14 @@ public class MainActivity extends BaseActivity {
|
|
|
// Toast.makeText(MainActivity.this, "扫描完成,是否成功="+isScanSuccess, Toast.LENGTH_SHORT).show();
|
|
// Toast.makeText(MainActivity.this, "扫描完成,是否成功="+isScanSuccess, Toast.LENGTH_SHORT).show();
|
|
|
if (isScanSuccess){
|
|
if (isScanSuccess){
|
|
|
// 找到了匹配的蓝牙
|
|
// 找到了匹配的蓝牙
|
|
|
|
|
+ Log.i(TAG2, "onScanFinished: 找到了匹配的蓝牙");
|
|
|
mWebView.loadUrl("javascript:responseCode('1')");
|
|
mWebView.loadUrl("javascript:responseCode('1')");
|
|
|
}else{
|
|
}else{
|
|
|
// 没找到匹配的蓝牙
|
|
// 没找到匹配的蓝牙
|
|
|
// 返回不等于6的code
|
|
// 返回不等于6的code
|
|
|
|
|
+ Log.i(TAG2, "onScanFinished: 没找到匹配的蓝牙");
|
|
|
mWebView.loadUrl("javascript:responseCode('2')");
|
|
mWebView.loadUrl("javascript:responseCode('2')");
|
|
|
|
|
+ XToast.showToast("未找到匹配蓝牙,请等待15秒后重试");
|
|
|
mBleDevice = null;
|
|
mBleDevice = null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1305,14 +1491,15 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onConnectFail(BleDevice bleDevice, BleException exception) {
|
|
public void onConnectFail(BleDevice bleDevice, BleException exception) {
|
|
|
- Log.e("-------->","------>连接失败");
|
|
|
|
|
|
|
+ Log.e(TAG2,"------>连接失败");
|
|
|
|
|
+ XToast.showToast("蓝牙连接失败,请等待15秒后重试");
|
|
|
// Toast.makeText(MainActivity.this, "连接失败", Toast.LENGTH_SHORT).show();
|
|
// Toast.makeText(MainActivity.this, "连接失败", Toast.LENGTH_SHORT).show();
|
|
|
mWebView.loadUrl("javascript:responseCode('2')");
|
|
mWebView.loadUrl("javascript:responseCode('2')");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
|
|
public void onConnectSuccess(BleDevice bleDevice, BluetoothGatt gatt, int status) {
|
|
|
- Log.e("-------->","------>连接成功");
|
|
|
|
|
|
|
+ Log.e(TAG2,"------>连接成功");
|
|
|
// Toast.makeText(MainActivity.this, "连接成功", Toast.LENGTH_SHORT).show();
|
|
// Toast.makeText(MainActivity.this, "连接成功", Toast.LENGTH_SHORT).show();
|
|
|
mBleDevice = bleDevice;
|
|
mBleDevice = bleDevice;
|
|
|
mWebView.loadUrl("javascript:responseCode('3')");
|
|
mWebView.loadUrl("javascript:responseCode('3')");
|
|
@@ -1341,7 +1528,7 @@ public class MainActivity extends BaseActivity {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
// Toast.makeText(MainActivity.this, "打开通知成功", Toast.LENGTH_SHORT).show();
|
|
// Toast.makeText(MainActivity.this, "打开通知成功", Toast.LENGTH_SHORT).show();
|
|
|
- Log.e("-------->","-------->打开通知成功");
|
|
|
|
|
|
|
+ Log.e(TAG2,"-------->打开通知成功");
|
|
|
mWebView.loadUrl("javascript:responseCode('6')");
|
|
mWebView.loadUrl("javascript:responseCode('6')");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -1349,7 +1536,7 @@ public class MainActivity extends BaseActivity {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onNotifyFailure(final BleException exception) {
|
|
public void onNotifyFailure(final BleException exception) {
|
|
|
- Log.e("-------->","------>打开通知失败");
|
|
|
|
|
|
|
+ Log.e(TAG2,"------>打开通知失败");
|
|
|
runOnUiThread(new Runnable() {
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
@@ -1384,10 +1571,10 @@ public class MainActivity extends BaseActivity {
|
|
|
public void onDisConnected(boolean isActiveDisConnected, BleDevice bleDevice, BluetoothGatt gatt, int status) {
|
|
public void onDisConnected(boolean isActiveDisConnected, BleDevice bleDevice, BluetoothGatt gatt, int status) {
|
|
|
mBleDevice = null;
|
|
mBleDevice = null;
|
|
|
if (isActiveDisConnected) {
|
|
if (isActiveDisConnected) {
|
|
|
- Log.e("-------->","------>断开了");
|
|
|
|
|
|
|
+ Log.e(TAG2,"------>断开了");
|
|
|
mWebView.loadUrl("javascript:responseCode('4')");
|
|
mWebView.loadUrl("javascript:responseCode('4')");
|
|
|
} else {
|
|
} else {
|
|
|
- Log.e("-------->","------>连接断开");
|
|
|
|
|
|
|
+ Log.e(TAG2,"------>连接断开");
|
|
|
mWebView.loadUrl("javascript:responseCode('5')");
|
|
mWebView.loadUrl("javascript:responseCode('5')");
|
|
|
ObserverManager.getInstance().notifyObserver(bleDevice);
|
|
ObserverManager.getInstance().notifyObserver(bleDevice);
|
|
|
}
|
|
}
|