就差打印格式了
This commit is contained in:
commit
e0015cb8b8
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/../../../../:\printerPlugin\bluetoothPrinter\.idea/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
9
.idea/bluetoothPrinter.iml
Normal file
9
.idea/bluetoothPrinter.iml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
36
.idea/inspectionProfiles/Project_Default.xml
Normal file
36
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="INNER_CLASS_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="METHOD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="FIELD_OPTIONS">
|
||||
<value>
|
||||
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||
<option name="REQUIRED_TAGS" value="" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IGNORE_DEPRECATED" value="false" />
|
||||
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||
<option name="myAdditionalJavadocTags" value="date" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Android API 23 Platform" project-jdk-type="Android SDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/bluetoothPrinter.iml" filepath="$PROJECT_DIR$/.idea/bluetoothPrinter.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "cordova-plugin-JcPrinter",
|
||||
"version": "1.0.0",
|
||||
"description": "for Niimbot B32 printer",
|
||||
"cordova": {
|
||||
"id": "cordova.plugin.JcPrinter",
|
||||
"platforms": []
|
||||
},
|
||||
"keywords": [
|
||||
"ecosystem:cordova"
|
||||
],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
44
plugin.xml
Normal file
44
plugin.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<plugin id="cordova.plugin.JcPrinter" version="1.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<name>bluetoothPrinter</name>
|
||||
<js-module name="jcPrinter" src="www/jcPrinter.js">
|
||||
<clobbers target="cordova.plugins.jcprinter" />
|
||||
</js-module>
|
||||
<platform name="android">
|
||||
<config-file parent="/*" target="res/xml/config.xml">
|
||||
<feature name="JcPrinter">
|
||||
<param name="android-package" value="cordova.plugin.jcprinter.JcPrinter"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/android/cordova/plugin/jcprinter/JcPrinter.java"
|
||||
target-dir="cordova/plugin/jcprinter"/>
|
||||
<source-file src="src/android/cordova/plugin/jcprinter/Util.java"
|
||||
target-dir="cordova/plugin/jcprinter"/>
|
||||
<source-file src="src/android/cordova/plugin/jcprinter/MyApplication.java"
|
||||
target-dir="cordova/plugin/jcprinter"/>
|
||||
|
||||
<lib-file src="src/android/3.1.8-release.aar" />
|
||||
<lib-file src="src/android/image-2.0.10-release.aar" />
|
||||
|
||||
<resource-file src="src/android/3.1.8-release.aar" target="libs/3.1.8-release.aar" />
|
||||
<resource-file src="src/android/image-2.0.10-release.aar" target="libs/image-2.0.10-release.aar" />
|
||||
<framework src="src/android/jcPrinter.gradle" custom="true" type="gradleReference" />
|
||||
|
||||
|
||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||
<!--Android12 的蓝牙权限 如果您的应用与已配对的蓝牙设备通信或者获取当前手机蓝牙是否打开-->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
|
||||
<!--Android12 的蓝牙权限 如果您的应用查找蓝牙设备(如蓝牙低功耗 (BLE) 外围设备)-->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
|
||||
<!--Android12 的蓝牙权限 如果您的应用使当前设备可被其他蓝牙设备检测到-->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
|
||||
<!--Android 6-11 定位权限-->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
</config-file>
|
||||
</platform>
|
||||
</plugin>
|
BIN
src/android/3.1.8-release.aar
Normal file
BIN
src/android/3.1.8-release.aar
Normal file
Binary file not shown.
476
src/android/cordova/plugin/jcprinter/JcPrinter.java
Normal file
476
src/android/cordova/plugin/jcprinter/JcPrinter.java
Normal file
@ -0,0 +1,476 @@
|
||||
package cordova.plugin.jcprinter;
|
||||
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.gengcon.www.jcprintersdk.bean.ImageDataInfo;
|
||||
import com.gengcon.www.jcprintersdk.callback.PrintCallback;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class JcPrinter extends CordovaPlugin {
|
||||
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
private static final String RB_THERMAL = "热转印";
|
||||
private Context context;
|
||||
/**
|
||||
* 图像数据
|
||||
*/
|
||||
private ArrayList<String> jsonList;
|
||||
/**
|
||||
* 图像处理数据
|
||||
*/
|
||||
private ArrayList<String> infoList;
|
||||
/**
|
||||
* 总页数
|
||||
*/
|
||||
private int pageCount;
|
||||
|
||||
/**
|
||||
* 页打印份数
|
||||
*/
|
||||
private int quantity;
|
||||
/**
|
||||
* 是否打印错误
|
||||
*/
|
||||
private boolean isError;
|
||||
/**
|
||||
* 是否取消打印
|
||||
*/
|
||||
private boolean isCancel;
|
||||
|
||||
/**
|
||||
* 打印模式
|
||||
*/
|
||||
private int printMode;
|
||||
|
||||
/**
|
||||
* 打印浓度
|
||||
*/
|
||||
private int printDensity;
|
||||
|
||||
/**
|
||||
* 打印倍率(分辨率)
|
||||
*/
|
||||
private Float printMultiple;
|
||||
|
||||
private final static int START_PRINT = 1;
|
||||
|
||||
|
||||
@Override
|
||||
protected void pluginInitialize() {
|
||||
super.pluginInitialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
System.out.println("action = " + action);
|
||||
switch (action) {
|
||||
case "print":
|
||||
this.print(args, callbackContext);
|
||||
return true;
|
||||
|
||||
case "getList":
|
||||
this.getList(callbackContext);
|
||||
return true;
|
||||
case "connectPrinter":
|
||||
this.connectPrinter(args, callbackContext);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印标签
|
||||
*
|
||||
* @param pages 页数(页表示数据不一样)
|
||||
* @param copies 份数
|
||||
*/
|
||||
private void print(JSONArray args, CallbackContext callbackContext) {
|
||||
|
||||
//重置错误状态变量
|
||||
isError = false;
|
||||
//重置取消打印状态变量
|
||||
isCancel = false;
|
||||
//清除数据
|
||||
initPrintData();
|
||||
//总打印份数
|
||||
|
||||
final int[] generatedPrintDataPageCount = {0};
|
||||
pageCount = 1;
|
||||
quantity = 1;
|
||||
int totalQuantity = pageCount * quantity;
|
||||
//总打印份数,表示所有页面的打印份数之和。例如,如果你有3页需要打印,第一页打印3份,第二页打印2份,第三页打印5份,那么count的值应为10(3+2+5)。
|
||||
Util.getInstance().setTotalQuantityOfPrints(totalQuantity);
|
||||
printDensity = 8;
|
||||
printMode = 2;
|
||||
Log.d(TAG, "测试:参数设置-打印浓度: " + printDensity + ",打印模式:" + printMode);
|
||||
/*
|
||||
* 参数1:打印浓度 ,参数2:纸张类型 参数3:打印模式
|
||||
* 打印浓度 B50/B50W/T6/T7/T8 建议设置6或8,Z401/B32建议设置8,B3S/B21/B203/B1建议设置3
|
||||
*/
|
||||
Util.getInstance().startPrintJob(printDensity, 2, printMode, new PrintCallback() {
|
||||
@Override
|
||||
public void onProgress(int pageIndex, int quantityIndex, HashMap<String, Object> hashMap) {
|
||||
Log.d(TAG, "测试:打印进度:已打印到第" + pageIndex + "页,第" + quantityIndex + "份");
|
||||
//打印进度回调
|
||||
if (pageIndex == pageCount && quantityIndex == quantity) {
|
||||
if (Util.getInstance().endJob()) {
|
||||
Log.d(TAG, "结束打印成功");
|
||||
callbackContext.success("结束打印成功");
|
||||
} else {
|
||||
Log.d(TAG, "结束打印失败");
|
||||
callbackContext.error("结束打印失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int i) {
|
||||
callbackContext.error(i);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onError(int errorCode, int printState) {
|
||||
isError = true;
|
||||
String errorMsg = "";
|
||||
//错误回调
|
||||
switch (errorCode) {
|
||||
case 1:
|
||||
errorMsg = "盒盖打开";
|
||||
break;
|
||||
case 2:
|
||||
errorMsg = "缺纸";
|
||||
break;
|
||||
case 3:
|
||||
errorMsg = "电量不足";
|
||||
break;
|
||||
case 4:
|
||||
errorMsg = "电池异常";
|
||||
break;
|
||||
case 5:
|
||||
errorMsg = "手动停止";
|
||||
break;
|
||||
case 6:
|
||||
errorMsg = "数据错误";
|
||||
break;
|
||||
case 7:
|
||||
errorMsg = "温度过高";
|
||||
break;
|
||||
case 8:
|
||||
errorMsg = "出纸异常";
|
||||
break;
|
||||
case 9:
|
||||
errorMsg = "正在打印";
|
||||
break;
|
||||
case 10:
|
||||
errorMsg = "没有检测到打印头";
|
||||
break;
|
||||
case 11:
|
||||
errorMsg = "环境温度过低";
|
||||
break;
|
||||
case 12:
|
||||
errorMsg = "打印头未锁紧";
|
||||
break;
|
||||
case 13:
|
||||
errorMsg = "未检测到碳带";
|
||||
break;
|
||||
case 14:
|
||||
errorMsg = "不匹配的碳带";
|
||||
break;
|
||||
case 15:
|
||||
errorMsg = "用完的碳带";
|
||||
break;
|
||||
case 16:
|
||||
errorMsg = "不支持的纸张类型";
|
||||
break;
|
||||
case 17:
|
||||
errorMsg = "纸张类型设置失败";
|
||||
break;
|
||||
case 18:
|
||||
errorMsg = "打印模式设置失败";
|
||||
break;
|
||||
case 19:
|
||||
errorMsg = "设置浓度失败";
|
||||
break;
|
||||
case 20:
|
||||
errorMsg = "写入rfid失败";
|
||||
break;
|
||||
case 21:
|
||||
errorMsg = "边距设置失败";
|
||||
break;
|
||||
case 22:
|
||||
errorMsg = "通讯异常";
|
||||
break;
|
||||
case 23:
|
||||
errorMsg = "打印机连接断开";
|
||||
break;
|
||||
case 24:
|
||||
errorMsg = "画板参数错误";
|
||||
break;
|
||||
case 25:
|
||||
errorMsg = "旋转角度错误";
|
||||
break;
|
||||
case 26:
|
||||
errorMsg = "json参数错误";
|
||||
break;
|
||||
case 27:
|
||||
errorMsg = "出纸异常(B3S)";
|
||||
break;
|
||||
case 28:
|
||||
errorMsg = "检查纸张类型";
|
||||
break;
|
||||
case 29:
|
||||
errorMsg = "RFID标签未进行写入操作";
|
||||
break;
|
||||
case 30:
|
||||
errorMsg = "不支持浓度设置";
|
||||
break;
|
||||
case 31:
|
||||
errorMsg = "不支持的打印模式";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
String finalErrorMsg = errorMsg;
|
||||
callbackContext.error(finalErrorMsg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelJob(boolean isSuccess) {
|
||||
//取消打印成功回调
|
||||
isCancel = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBufferFree(int pageIndex, int bufferSize) {
|
||||
//pageIndex下一页的打印索引,bufferSize缓存控件
|
||||
if (isError || isCancel) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pageIndex > pageCount) {
|
||||
return;
|
||||
}
|
||||
//已生成数据的页数小于总页数才生成数据
|
||||
if (generatedPrintDataPageCount[0] < pageCount) {
|
||||
//需要生成的数据长度
|
||||
int commitDataLength = Math.min((pageCount - generatedPrintDataPageCount[0]), bufferSize);
|
||||
generateMultiPagePrintData(generatedPrintDataPageCount[0], generatedPrintDataPageCount[0] + commitDataLength);
|
||||
Util.getInstance().commitData(
|
||||
jsonList.subList(generatedPrintDataPageCount[0], generatedPrintDataPageCount[0] + commitDataLength),
|
||||
infoList.subList(generatedPrintDataPageCount[0], generatedPrintDataPageCount[0] + commitDataLength));
|
||||
generatedPrintDataPageCount[0] += commitDataLength;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initPrintData() {
|
||||
jsonList = new ArrayList<>();
|
||||
infoList = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void connectPrinter(JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
JSONObject obj = args.getJSONObject(0);
|
||||
String address = obj.getString("address");
|
||||
int connectResult = Util.openPrinter(address);
|
||||
cordova.getActivity().runOnUiThread(() -> {
|
||||
String hint = "";
|
||||
switch (connectResult) {
|
||||
case 0:
|
||||
hint = "连接成功";
|
||||
callbackContext.success(hint);
|
||||
break;
|
||||
case -1:
|
||||
hint = "连接失败";
|
||||
callbackContext.error(hint);
|
||||
break;
|
||||
case -2:
|
||||
hint = "不支持的机型";
|
||||
callbackContext.error(hint);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/***
|
||||
* Find Zebra printers we can connect to
|
||||
* @return
|
||||
*/
|
||||
@SuppressLint("MissingPermission")
|
||||
private JSONArray getList(CallbackContext callbackContext) {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
int blueTooth_permission = ContextCompat.checkSelfPermission(cordova.getContext(), Manifest.permission.BLUETOOTH);
|
||||
int blueTooth_admin_permission = ContextCompat.checkSelfPermission(cordova.getContext(), Manifest.permission.BLUETOOTH_ADMIN);
|
||||
int blueTooth_privileged_permission = ContextCompat.checkSelfPermission(cordova.getContext(), Manifest.permission.BLUETOOTH_PRIVILEGED);
|
||||
int blueTooth_connect_permission = ContextCompat.checkSelfPermission(cordova.getContext(), "android.permission.BLUETOOTH_CONNECT");
|
||||
System.out.println("blueTooth_permission = " + blueTooth_permission);
|
||||
System.out.println("blueTooth_admin_permission = " + blueTooth_admin_permission);
|
||||
System.out.println("blueTooth_privileged_permission = " + blueTooth_privileged_permission);
|
||||
System.out.println("blueTooth_connect_permission = " + blueTooth_connect_permission);
|
||||
if (blueTooth_permission == PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(cordova.getActivity(), new String[]{Manifest.permission.BLUETOOTH}, 1001);
|
||||
}
|
||||
if (blueTooth_admin_permission == PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(cordova.getActivity(), new String[]{Manifest.permission.BLUETOOTH_ADMIN}, 1002);
|
||||
}
|
||||
if (blueTooth_privileged_permission == PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(cordova.getActivity(), new String[]{Manifest.permission.BLUETOOTH_PRIVILEGED}, 1003);
|
||||
}
|
||||
if (blueTooth_connect_permission == PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(cordova.getActivity(), new String[]{"android.permission.BLUETOOTH_CONNECT"}, 1004);
|
||||
}
|
||||
}
|
||||
JSONArray printers = new JSONArray();
|
||||
|
||||
try {
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
Set<BluetoothDevice> devices = adapter.getBondedDevices();
|
||||
|
||||
for (BluetoothDevice device : devices) {
|
||||
String name = device.getName();
|
||||
String mac = device.getAddress();
|
||||
|
||||
JSONObject p = new JSONObject();
|
||||
p.put("name", name);
|
||||
p.put("address", mac);
|
||||
printers.put(p);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
System.out.println("printers = " + printers);
|
||||
callbackContext.success(printers);
|
||||
return printers;
|
||||
}
|
||||
|
||||
private void generateMultiPagePrintData(int index, int cycleIndex) {
|
||||
while (index < cycleIndex) {
|
||||
float width = 40;
|
||||
float height = 60;
|
||||
int orientation = 0;
|
||||
float marginX = 2.0F;
|
||||
float marginY = 2.0F;
|
||||
//矩形框类型
|
||||
float rectangleWidth = width - marginX * 2;
|
||||
float rectangleHeight = height - marginY * 2;
|
||||
float lineWidth = 0.5F;
|
||||
//1.圆 2.椭圆 3.矩形 4.圆角矩形
|
||||
int graphType = 3;
|
||||
|
||||
float lineHeight = rectangleHeight / 5.0F;
|
||||
|
||||
float titleWidth = rectangleWidth * 2 / 5.0F;
|
||||
float contentWidth = rectangleWidth * 3 / 5.0F;
|
||||
|
||||
float fontSize = 3.0F;
|
||||
float offsetY = 0F;
|
||||
float offsetX = 0F;
|
||||
|
||||
|
||||
/*
|
||||
* 设置画布大小
|
||||
*
|
||||
* @param width 画布宽度
|
||||
* @param height 画布高度
|
||||
* @param orientation 画布旋转角度
|
||||
* @param fontDir 字体路径暂不可用,默认""即可
|
||||
*
|
||||
*/
|
||||
Util.getInstance().drawEmptyLabel(width, height, orientation, "");
|
||||
// Util.getInstance().drawLabelText(2.5F, 2.0F, rectangleWidth, rectangleHeight, "型号", "宋体", fontSize, 0, 0, 0, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
|
||||
//绘制图形
|
||||
Util.getInstance().drawLabelGraph(marginX + offsetX, marginY + offsetY, rectangleWidth, rectangleHeight, graphType, 0, 2, lineWidth, 1, new float[]{0.7575f, 0.7575f});
|
||||
|
||||
//换行模式使用6,宽高固定,内容过大时缩放(区别于模式1的地方在于 文字内容按预算字号,预算文本框宽度排版后未超出预设高度时,不会放大文字,而是按照预设对齐方式将文字对齐文本框)
|
||||
|
||||
//绘制线条
|
||||
Util.getInstance().drawLabelLine(marginX + offsetX, marginY + lineHeight - lineWidth + offsetY, rectangleWidth, lineWidth, 0, 1, new float[]{});
|
||||
Util.getInstance().drawLabelLine(marginX + offsetX, marginY + lineHeight * 2 - lineWidth + offsetY, rectangleWidth, lineWidth, 0, 1, new float[]{});
|
||||
Util.getInstance().drawLabelLine(marginX + offsetX, marginY + lineHeight * 3 - lineWidth + offsetY, rectangleWidth, lineWidth, 0, 1, new float[]{});
|
||||
Util.getInstance().drawLabelLine(marginX + offsetX, marginY + lineHeight * 4 - lineWidth + offsetY, rectangleWidth, lineWidth, 0, 1, new float[]{});
|
||||
|
||||
Util.getInstance().drawLabelLine(marginX + titleWidth - lineWidth + offsetX, marginY + lineHeight + offsetY, lineWidth, rectangleHeight - lineHeight, 0, 1, new float[]{});
|
||||
|
||||
//绘制大标题,换行模式使用6,宽高固定,内容过大时缩放(区别于模式1的地方在于 文字内容按预算字号,预算文本框宽度排版后未超出预设高度时,不会放大文字,而是按照预设对齐方式将文字对齐文本框)
|
||||
|
||||
Util.getInstance().drawLabelText(marginX * 3 + offsetX, marginY + offsetY, rectangleWidth - marginX * 4, lineHeight, "|AA|1052535|01|2389W08559|#奥莱斯#12R22.5-AR535", "宋体", fontSize * 1.5F, 0, 1, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
// 绘制小标题
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + offsetX, marginY + lineHeight - lineWidth + offsetY, titleWidth - marginX * 3, lineHeight, "型号", "宋体", fontSize, 0, 1, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + offsetX, marginY + lineHeight * 2 - lineWidth + offsetY, titleWidth - marginX * 3, lineHeight, "资产编号", "宋体", fontSize, 0, 1, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + offsetX, marginY + lineHeight * 3 - lineWidth + offsetY, titleWidth - marginX * 3, lineHeight, "启用日期", "宋体", fontSize, 0, 1, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + offsetX, marginY + lineHeight * 4 - lineWidth + offsetY, titleWidth - marginX * 3, lineHeight, "存放地点", "宋体", fontSize, 0, 1, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, marginY + lineHeight - lineWidth + offsetY, contentWidth - marginX * 3, lineHeight, "DELL显示器 E6540", "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, marginY + lineHeight * 2 - lineWidth + offsetY, contentWidth - marginX * 3, lineHeight, "C212004", "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, marginY + lineHeight * 3 - lineWidth + offsetY, contentWidth - marginX * 3, lineHeight, "2014-06-10", "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
Util.getInstance().drawLabelText(marginX * 2.5f + titleWidth + offsetX, marginY + lineHeight * 4 - lineWidth + offsetY, contentWidth - marginX * 3, lineHeight, (index + 1) + "号办公室", "宋体", fontSize, 0, 0, 1, 6, 0, 1, new boolean[]{false, false, false, false});
|
||||
|
||||
|
||||
//生成打印数据
|
||||
byte[] jsonByte = Util.getInstance().generateLabelJson();
|
||||
|
||||
//转换为jsonStr
|
||||
String jsonStr = new String(jsonByte);
|
||||
|
||||
|
||||
jsonList.add(jsonStr);
|
||||
//除B32/Z401/T8的printMultiple为11.81,其他的为8
|
||||
//printQuantity属性用于指定当前页的打印份数。例如,如果你需要打印3页,第一页打印3份,第二页打印2份,第三页打印5份,那么在3次提交数据时,printQuantity值分别应为3,2,5。
|
||||
String jsonInfo = "{ " +
|
||||
"\"printerImageProcessingInfo\": " + "{ " +
|
||||
"\"orientation\":" + orientation + "," +
|
||||
" \"margin\": [ 0, 0, 0, 0 ], " +
|
||||
" \"printQuantity\": " + quantity + ", " +
|
||||
" \"horizontalOffset\": 0, " +
|
||||
" \"verticalOffset\": 0, " +
|
||||
" \"width\":" + width + "," +
|
||||
" \"height\":" + height + "," +
|
||||
"\"printMultiple\":" + printMultiple + "," +
|
||||
" \"epc\": \"\" }}";
|
||||
infoList.add(jsonInfo);
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
src/android/cordova/plugin/jcprinter/MyApplication.java
Normal file
23
src/android/cordova/plugin/jcprinter/MyApplication.java
Normal file
@ -0,0 +1,23 @@
|
||||
package cordova.plugin.jcprinter;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* 自定义Application
|
||||
*
|
||||
* @author zhangbin
|
||||
*/
|
||||
public class MyApplication extends Application {
|
||||
private static MyApplication app;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
app = this;
|
||||
}
|
||||
|
||||
public static MyApplication getInstance() {
|
||||
return app;
|
||||
}
|
||||
}
|
92
src/android/cordova/plugin/jcprinter/Util.java
Normal file
92
src/android/cordova/plugin/jcprinter/Util.java
Normal file
@ -0,0 +1,92 @@
|
||||
package cordova.plugin.jcprinter;
|
||||
|
||||
import com.gengcon.www.jcprintersdk.JCPrintApi;
|
||||
import com.gengcon.www.jcprintersdk.callback.Callback;
|
||||
import cordova.plugin.jcprinter.MyApplication;
|
||||
|
||||
public class Util {
|
||||
|
||||
|
||||
private static final Callback CALLBACK = new Callback() {
|
||||
@Override
|
||||
public void onConnectSuccess(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisConnect() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onElectricityChange(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoverStatus(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPaperStatus(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRfidReadStatus(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrinterIsFree(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHeartDisConnect() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFirmErrors() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private static JCPrintApi api;
|
||||
|
||||
|
||||
public static JCPrintApi getInstance() {
|
||||
if (api == null) {
|
||||
api = JCPrintApi.getInstance(CALLBACK);
|
||||
api.init(MyApplication.getInstance());
|
||||
api.initImageProcessingDefault("", "");
|
||||
|
||||
|
||||
// Log.d(TAG, "api.init"+api.init(MyApplication.getInstance()));
|
||||
// Log.d(TAG, "api.initImageProcessingDefault"+ api.initImageProcessingDefault("", ""));
|
||||
}
|
||||
|
||||
return api;
|
||||
|
||||
}
|
||||
|
||||
private static final String TAG = "PrintUtil";
|
||||
|
||||
public static int openPrinter(String address) {
|
||||
getInstance();
|
||||
return api.openPrinterByAddress(address);
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
getInstance();
|
||||
api.close();
|
||||
}
|
||||
|
||||
public static int isConnection() {
|
||||
getInstance();
|
||||
return api.isConnection();
|
||||
}
|
||||
|
||||
}
|
BIN
src/android/image-2.0.10-release.aar
Normal file
BIN
src/android/image-2.0.10-release.aar
Normal file
Binary file not shown.
18
src/android/jcPrinter.gradle
Normal file
18
src/android/jcPrinter.gradle
Normal file
@ -0,0 +1,18 @@
|
||||
repositories{
|
||||
jcenter()
|
||||
flatDir {
|
||||
dirs 'src/main/libs'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(name:'3.1.8-release', ext:'aar')
|
||||
implementation(name:'image-2.0.10-release', ext:'aar')
|
||||
}
|
||||
|
||||
android {
|
||||
packagingOptions {
|
||||
exclude 'META-INF/NOTICE'
|
||||
exclude 'META-INF/LICENSE'
|
||||
}
|
||||
}
|
13
www/jcPrinter.js
Normal file
13
www/jcPrinter.js
Normal file
@ -0,0 +1,13 @@
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
exports.print = function (arg0, success, error) {
|
||||
exec(success, error, 'JcPrinter', 'print', [arg0]);
|
||||
};
|
||||
|
||||
exports.getList = function (arg0, success, error) {
|
||||
exec(success, error, 'JcPrinter', 'getList', [arg0]);
|
||||
};
|
||||
|
||||
exports.connectPrinter = function (arg0, success, error) {
|
||||
exec(success, error, 'JcPrinter', 'connectPrinter', [arg0]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user