-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8b823c
commit 4ffdc41
Showing
19 changed files
with
8,427 additions
and
7,175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "interactive" | ||
} | ||
"java.configuration.updateBuildConfiguration": "interactive", | ||
"editor.formatOnSave": true, | ||
"prettier.tabWidth": 4, | ||
"workbench.colorTheme": "Default Dark Modern", | ||
"editor.detectIndentation": false, | ||
"prettier.printWidth": 120, | ||
"prettier.bracketSameLine": false, | ||
"prettier.htmlWhitespaceSensitivity": "strict", | ||
"prettier.bracketSpacing": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
android/app/src/main/aidl/net/nyx/printerservice/print/IPrinterService.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package net.nyx.printerservice.print; | ||
|
||
import android.graphics.Bitmap; | ||
import net.nyx.printerservice.print.PrintTextFormat; | ||
|
||
interface IPrinterService { | ||
|
||
String getServiceVersion(); | ||
|
||
int getPrinterVersion(out String[] ver); | ||
|
||
int getPrinterModel(out String[] model); | ||
|
||
int getPrinterStatus(); | ||
|
||
int paperOut(int px); | ||
|
||
int paperBack(int px); | ||
|
||
int printText(String text, in PrintTextFormat textFormat); | ||
|
||
/** | ||
* Print text | ||
* | ||
* @param text text content | ||
* @param textFormat text format | ||
* @param textWidth maximum text width, <384px | ||
* @param align The alignment of the maximum text width relative to the 384px printing paper | ||
* The default is 0. 0--Align left, 1--Align center, 2--Align right | ||
* @return Print result | ||
*/ | ||
int printText2(String text, in PrintTextFormat textFormat, int textWidth, int align); | ||
|
||
/** | ||
* Print barcode | ||
* | ||
* @param content barcode content | ||
* @param width barcode width, px | ||
* @param height barcode height, px | ||
* @param textPosition barcode content text position, the default is 0. | ||
* 0--don't print barcode content | ||
* 1--content above the barcode | ||
* 2--content below the barcode | ||
* 3--text print both the top and bottom of the barcode | ||
* @param align alignment, the default is 0. 0--Align left, 1--Align center, 2--Align right | ||
* @return Print result | ||
*/ | ||
int printBarcode(String content, int width, int height, int textPosition, int align); | ||
|
||
/** | ||
* Print QR code | ||
* | ||
* @param content QRCode content | ||
* @param width QRCode width, px | ||
* @param height QRCode height, px | ||
* @param align alignment, the default is 0. 0--Align left, 1--Align center, 2--Align right | ||
* @return Print result | ||
*/ | ||
int printQrCode(String content, int width, int height, int align); | ||
|
||
/** | ||
* Print bitmap | ||
* | ||
* @param bitmap Android bitmap object | ||
* @param type printer render type, the default is 0. | ||
* 0--black and white bitmap | ||
* 1--grayscale bitmap, suitable for rich color images | ||
* @param align alignment, the default is 0. 0--Align left, 1--Align center, 2--Align right | ||
* @return Print result | ||
*/ | ||
int printBitmap(in Bitmap bitmap, int type, int align); | ||
|
||
/** | ||
* Locate the next label | ||
* | ||
* @param labelHeight label paper height, px | ||
* @param labelGap label paper gap, px | ||
* @return Result | ||
*/ | ||
int labelLocate(int labelHeight, int labelGap); | ||
|
||
/** | ||
* Label printing ends, paper automatically moves to the tear-off position. | ||
* This method must appear in pairs with {@link #labelLocate} | ||
* | ||
* @return Result | ||
*/ | ||
int labelPrintEnd(); | ||
|
||
/** | ||
* Auto locate label. This method only can be called on the system that has performed | ||
* label learning by {@link #labelDetectAuto} | ||
* | ||
* @return Result | ||
*/ | ||
int labelLocateAuto(); | ||
|
||
/** | ||
* Label learning by automatic label detection. This method will start label learning | ||
* | ||
* @return Result | ||
*/ | ||
int labelDetectAuto(); | ||
|
||
/** | ||
* Label learning has been performed | ||
* | ||
* @return Result | ||
*/ | ||
boolean hasLabelLearning(); | ||
|
||
/** | ||
* Clear label learning data | ||
* | ||
* @return Result | ||
*/ | ||
int clearLabelLearning(); | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
android/app/src/main/aidl/net/nyx/printerservice/print/PrintTextFormat.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.nyx.printerservice.print; | ||
|
||
parcelable PrintTextFormat; |
111 changes: 111 additions & 0 deletions
111
android/app/src/main/java/net/nyx/printerclient/Result.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package net.nyx.printerclient; | ||
import org.boltcard.boltcardpos.R; | ||
public class Result { | ||
|
||
public static String msg(int code) { | ||
String s; | ||
switch (code) { | ||
case SdkResult.SDK_SENT_ERR: | ||
s = Utils.getApp().getString(R.string.result_sent_err); | ||
break; | ||
case SdkResult.SDK_RECV_ERR: | ||
s = Utils.getApp().getString(R.string.result_recv_err); | ||
break; | ||
case SdkResult.SDK_TIMEOUT: | ||
s = Utils.getApp().getString(R.string.result_timeout); | ||
break; | ||
case SdkResult.SDK_PARAM_ERR: | ||
s = Utils.getApp().getString(R.string.result_params_err); | ||
break; | ||
case SdkResult.SDK_UNKNOWN_ERR: | ||
s = Utils.getApp().getString(R.string.result_unknown_err); | ||
break; | ||
case SdkResult.DEVICE_NOT_CONNECT: | ||
s = Utils.getApp().getString(R.string.result_device_not_conn); | ||
break; | ||
case SdkResult.DEVICE_DISCONNECT: | ||
s = Utils.getApp().getString(R.string.result_device_disconnect); | ||
break; | ||
case SdkResult.DEVICE_CONN_ERR: | ||
s = Utils.getApp().getString(R.string.result_conn_err); | ||
break; | ||
case SdkResult.DEVICE_CONNECTED: | ||
s = Utils.getApp().getString(R.string.result_device_connected); | ||
break; | ||
case SdkResult.DEVICE_NOT_SUPPORT: | ||
s = Utils.getApp().getString(R.string.result_device_not_support); | ||
break; | ||
case SdkResult.DEVICE_NOT_FOUND: | ||
s = Utils.getApp().getString(R.string.result_device_not_found); | ||
break; | ||
case SdkResult.DEVICE_OPEN_ERR: | ||
s = Utils.getApp().getString(R.string.result_device_open_err); | ||
break; | ||
case SdkResult.DEVICE_NO_PERMISSION: | ||
s = Utils.getApp().getString(R.string.result_device_no_permission); | ||
break; | ||
case SdkResult.BT_NOT_OPEN: | ||
s = Utils.getApp().getString(R.string.result_bt_not_open); | ||
break; | ||
case SdkResult.BT_NO_LOCATION: | ||
s = Utils.getApp().getString(R.string.result_bt_no_location); | ||
break; | ||
case SdkResult.BT_NO_BONDED_DEVICE: | ||
s = Utils.getApp().getString(R.string.result_bt_no_bonded); | ||
break; | ||
case SdkResult.BT_SCAN_TIMEOUT: | ||
s = Utils.getApp().getString(R.string.result_bt_scan_timeout); | ||
break; | ||
case SdkResult.BT_SCAN_ERR: | ||
s = Utils.getApp().getString(R.string.result_bt_scan_err); | ||
break; | ||
case SdkResult.BT_SCAN_STOP: | ||
s = Utils.getApp().getString(R.string.result_bt_scan_stop); | ||
break; | ||
case SdkResult.PRN_COVER_OPEN: | ||
s = Utils.getApp().getString(R.string.result_prn_cover_open); | ||
break; | ||
case SdkResult.PRN_PARAM_ERR: | ||
s = Utils.getApp().getString(R.string.result_prn_params_err); | ||
break; | ||
case SdkResult.PRN_NO_PAPER: | ||
s = Utils.getApp().getString(R.string.result_prn_no_paper); | ||
break; | ||
case SdkResult.PRN_OVERHEAT: | ||
s = Utils.getApp().getString(R.string.result_prn_overheat); | ||
break; | ||
case SdkResult.PRN_UNKNOWN_ERR: | ||
s = Utils.getApp().getString(R.string.result_prn_unknown_err); | ||
break; | ||
case SdkResult.PRN_PRINTING: | ||
s = Utils.getApp().getString(R.string.result_prn_printing); | ||
break; | ||
case SdkResult.PRN_NO_NFC: | ||
s = Utils.getApp().getString(R.string.result_prn_no_nfc); | ||
break; | ||
case SdkResult.PRN_NFC_NO_PAPER: | ||
s = Utils.getApp().getString(R.string.result_nfc_no_paper); | ||
break; | ||
case SdkResult.PRN_LOW_BATTERY: | ||
s = Utils.getApp().getString(R.string.result_prn_low_battery); | ||
break; | ||
case SdkResult.PRN_LBL_LOCATE_ERR: | ||
s = Utils.getApp().getString(R.string.result_prn_locate_err); | ||
break; | ||
case SdkResult.PRN_LBL_DETECT_ERR: | ||
s = Utils.getApp().getString(R.string.result_prn_detect_err); | ||
break; | ||
case SdkResult.PRN_LBL_NO_DETECT: | ||
s = Utils.getApp().getString(R.string.result_prn_no_detect); | ||
break; | ||
case SdkResult.PRN_UNKNOWN_CMD: | ||
case SdkResult.SDK_UNKNOWN_CMD: | ||
s = Utils.getApp().getString(R.string.result_unknown_cmd); | ||
break; | ||
default: | ||
s = "" + code; | ||
break; | ||
} | ||
return s; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
android/app/src/main/java/net/nyx/printerclient/SdkResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.nyx.printerclient; | ||
|
||
public class SdkResult { | ||
public static final int SDK_OK = 0; | ||
public static final int SDK_BASE_ERR = -1000; | ||
public static final int SDK_SENT_ERR = -1001; //发送失败 | ||
public static final int SDK_PARAM_ERR = -1002; //参数错误 | ||
public static final int SDK_TIMEOUT = -1003; //超时 | ||
public static final int SDK_RECV_ERR = -1004; //接受错误 | ||
public static final int SDK_UNKNOWN_ERR = -1005; //其他异常 | ||
public static final int SDK_CMD_ERR = -1006; //收发指令不一致 | ||
public static final int SDK_UNKNOWN_CMD = -1015; //未知命令 | ||
public static final int SDK_FEATURE_NOT_SUPPORT = -1099; //功能不支持 | ||
|
||
//设备连接 | ||
public static final int DEVICE_NOT_CONNECT = -1100; // 未连接 | ||
public static final int DEVICE_DISCONNECT = -1101; // 断开连接 | ||
public static final int DEVICE_CONNECTED = -1102; // 已连接 | ||
public static final int DEVICE_CONN_ERR = -1103; // 连接失败 | ||
public static final int DEVICE_NOT_SUPPORT = -1104; | ||
public static final int DEVICE_NOT_FOUND = -1105; | ||
public static final int DEVICE_OPEN_ERR = -1106; | ||
public static final int DEVICE_NO_PERMISSION = -1107; | ||
|
||
public static final int BT_NOT_SUPPORT = -1108; | ||
public static final int BT_NOT_OPEN = -1109; | ||
public static final int BT_NO_LOCATION = -1110; | ||
public static final int BT_NO_BONDED_DEVICE = -1111; | ||
public static final int BT_SCAN_TIMEOUT = -1112; | ||
public static final int BT_SCAN_ERR = -1113; | ||
public static final int BT_SCAN_STOP = -1114; | ||
|
||
//打印机 | ||
public static final int PRN_BASE_ERR = -1200; | ||
public static final int PRN_COVER_OPEN = (PRN_BASE_ERR -1); //打印机仓盖未关闭 | ||
public static final int PRN_PARAM_ERR = (PRN_BASE_ERR -2); //参数错误 | ||
public static final int PRN_NO_PAPER = (PRN_BASE_ERR -3); //打印机缺纸 | ||
public static final int PRN_OVERHEAT = (PRN_BASE_ERR -4); //打印机过热 | ||
public static final int PRN_UNKNOWN_ERR = (PRN_BASE_ERR -5); //打印机未知异常 | ||
public static final int PRN_PRINTING = (PRN_BASE_ERR -6); //打印机正在打印 | ||
public static final int PRN_NO_NFC = (PRN_BASE_ERR -7); //打印机无NFC标签 | ||
public static final int PRN_NFC_NO_PAPER = (PRN_BASE_ERR -8); //打印机NFC标签没有剩余次数 | ||
public static final int PRN_LOW_BATTERY = (PRN_BASE_ERR -9); //打印机低电量 | ||
public static final int PRN_UNKNOWN_CMD = (PRN_BASE_ERR -15);//打印机未知命令 | ||
public static final int PRN_LBL_LOCATE_ERR = (PRN_BASE_ERR -90);//打印机标签定位错误 | ||
public static final int PRN_LBL_DETECT_ERR = (PRN_BASE_ERR -91);//打印机标签纸检测错误 | ||
public static final int PRN_LBL_NO_DETECT = (PRN_BASE_ERR -92);//打印机未检测标签纸 | ||
|
||
//fw | ||
public static final int FW_BASE_ERR = -1300; | ||
public static final int FW_BIN_ERR = (FW_BASE_ERR -1); //固件文件错误 | ||
public static final int FW_CRC_ERR = (FW_BASE_ERR -2); //CRC错误 | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
android/app/src/main/java/net/nyx/printerclient/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.nyx.printerclient; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.Application; | ||
|
||
/** | ||
* Created by yyzz on 2019/1/4. | ||
*/ | ||
public class Utils { | ||
|
||
private static final String TAG = "Utils"; | ||
|
||
private static Application sApplication; | ||
private static Utils sUtils; | ||
|
||
public static Utils getInstance() { | ||
if (sUtils == null) | ||
sUtils = new Utils(); | ||
return sUtils; | ||
} | ||
|
||
public static Utils init(final Application app) { | ||
getInstance(); | ||
if (sApplication == null) { | ||
if (app == null) { | ||
sApplication = getApplicationByReflect(); | ||
} else { | ||
sApplication = app; | ||
} | ||
} else { | ||
if (app != null && app.getClass() != sApplication.getClass()) { | ||
sApplication = app; | ||
} | ||
} | ||
return sUtils; | ||
} | ||
|
||
public static Application getApp() { | ||
if (sApplication != null) | ||
return sApplication; | ||
Application app = getApplicationByReflect(); | ||
init(app); | ||
return app; | ||
} | ||
|
||
private static Application getApplicationByReflect() { | ||
try { | ||
@SuppressLint("PrivateApi") | ||
Class<?> activityThread = Class.forName("android.app.ActivityThread"); | ||
Object thread = activityThread.getMethod("currentActivityThread").invoke(null); | ||
Object app = activityThread.getMethod("getApplication").invoke(thread); | ||
if (app == null) { | ||
throw new NullPointerException("u should init first"); | ||
} | ||
return (Application) app; | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
throw new NullPointerException("u should init first"); | ||
} | ||
} |
Oops, something went wrong.