From 5f25a760d97d58ca46d56648fa28440d06b74041 Mon Sep 17 00:00:00 2001 From: Arcadius Ahouansou Date: Mon, 10 May 2021 08:09:28 +0100 Subject: [PATCH] - Option to remove battery info from response - Default align to top left --- package.json | 2 +- plugin.xml | 8 ++++--- src/android/BasePrint.java | 22 ++++++++++++++++--- src/android/BrotherPrinter.java | 13 +++++++++-- .../PrinterInputParameterConstant.java | 14 ++++++++++++ 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/android/PrinterInputParameterConstant.java diff --git a/package.json b/package.json index d28b633..34cb972 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-brother-label-printer", - "version": "1.5.1", + "version": "1.5.4", "description": "Cordova plugin for brother label printers", "cordova": { "id": "cordova-plugin-brother-label-printer", diff --git a/plugin.xml b/plugin.xml index 7f644ce..5a69f53 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,7 +3,7 @@ + version="1.5.4"> BrotherPrinter @@ -28,11 +28,13 @@ - + - + + + diff --git a/src/android/BasePrint.java b/src/android/BasePrint.java index 8342004..9099c15 100644 --- a/src/android/BasePrint.java +++ b/src/android/BasePrint.java @@ -33,7 +33,8 @@ import java.util.List; import java.util.Map; -import static com.threescreens.cordova.plugin.brotherPrinter.BrotherPrinter.TAG; +import static com.threescreens.cordova.plugin.brotherprinter.BrotherPrinter.TAG; +import static com.threescreens.cordova.plugin.brotherprinter.PrinterInputParameterConstant.INCLUDE_BATTERY_STATUS; @SuppressWarnings("ALL") public abstract class BasePrint { @@ -284,13 +285,13 @@ private void getPreferences() { mPrinterInfo.pjFeedMode = PrinterInfo.PjFeedMode .valueOf(sharedPreferences.getString("pjFeedMode", PrinterInfo.PjFeedMode.PJ_FEED_MODE_FIXEDPAGE.toString())); mPrinterInfo.align = PrinterInfo.Align.valueOf(sharedPreferences - .getString("align", PrinterInfo.Align.CENTER.toString())); + .getString("align", PrinterInfo.Align.LEFT.toString())); input = sharedPreferences.getString("leftMargin", ""); if (input.equals("")) input = "0"; mPrinterInfo.margin.left = Integer.parseInt(input); mPrinterInfo.valign = PrinterInfo.VAlign.valueOf(sharedPreferences - .getString("valign", PrinterInfo.VAlign.MIDDLE.name())); + .getString("valign", PrinterInfo.VAlign.TOP.name())); input = sharedPreferences.getString("topMargin", ""); if (input.equals("")) input = "0"; @@ -566,6 +567,13 @@ public String showResult() { */ public String getBattery() { + boolean includeBatteryStatus = Boolean.parseBoolean(sharedPreferences + .getString(INCLUDE_BATTERY_STATUS, "")); + + if(!includeBatteryStatus){ + return ""; + } + if (mPrintResult.isACConnected == BatteryTernary.Yes) { return Common.BatteryStatus.ACADAPTER.toString(); } @@ -638,6 +646,14 @@ public String getBatteryDetail() { if (mPrintResult == null) { return ""; } + + boolean includeBatteryStatus = Boolean.parseBoolean(sharedPreferences + .getString(INCLUDE_BATTERY_STATUS, "")); + + if(!includeBatteryStatus){ + return ""; + } + return String.format("%d/%d(AC=%s,BM=%s)", mPrintResult.batteryResidualQuantityLevel, mPrintResult.maxOfBatteryResidualQuantityLevel, diff --git a/src/android/BrotherPrinter.java b/src/android/BrotherPrinter.java index 38f08c4..aff740b 100644 --- a/src/android/BrotherPrinter.java +++ b/src/android/BrotherPrinter.java @@ -1,4 +1,4 @@ -package com.threescreens.cordova.plugin.brotherPrinter; +package com.threescreens.cordova.plugin.brotherprinter; import java.util.ArrayList; import java.util.HashMap; @@ -54,6 +54,7 @@ import com.brother.ptouch.sdk.printdemo.common.MsgHandle; import com.brother.ptouch.sdk.printdemo.printprocess.ImageBitmapPrint; import com.brother.ptouch.sdk.printdemo.printprocess.ImageFilePrint; +import static com.threescreens.cordova.plugin.brotherprinter.PrinterInputParameterConstant.INCLUDE_BATTERY_STATUS; public class BrotherPrinter extends CordovaPlugin { //token to make it easy to grep logcat @@ -149,6 +150,7 @@ private class DiscoveredPrinter { public String location; public String paperLabelName; public String orientation; + public String includeBatteryStatus; public DiscoveredPrinter(BluetoothDevice device) { port = PrinterInfo.Port.BLUETOOTH; @@ -224,6 +226,12 @@ public DiscoveredPrinter(JSONObject object) throws JSONException { orientation = object.getString("orientation"); } + if (object.has(INCLUDE_BATTERY_STATUS)) { + includeBatteryStatus = object.getString(INCLUDE_BATTERY_STATUS); + } else { + includeBatteryStatus = Boolean.FALSE.toString(); + } + } public JSONObject toJSON() throws JSONException { @@ -372,6 +380,7 @@ private void setPrinter(JSONArray args, final CallbackContext callbackctx) { editor.putString("macAddress", printer.macAddress); editor.putString("paperSize", printer.paperLabelName != null ? printer.paperLabelName : LabelInfo.QL700.W62.toString()); editor.putString("orientation", printer.orientation != null ? printer.orientation : PrinterInfo.Orientation.LANDSCAPE.toString()); + editor.putString(INCLUDE_BATTERY_STATUS, printer.includeBatteryStatus); editor.commit(); @@ -481,7 +490,7 @@ public void run() { return; } - final String ACTION_USB_PERMISSION = "com.threescreens.cordova.plugin.brotherPrinter.USB_PERMISSION"; + final String ACTION_USB_PERMISSION = "com.threescreens.cordova.plugin.brotherprinter.USB_PERMISSION"; PendingIntent permissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0); usbManager.requestPermission(usbDevice, permissionIntent); diff --git a/src/android/PrinterInputParameterConstant.java b/src/android/PrinterInputParameterConstant.java new file mode 100644 index 0000000..9c4dbb0 --- /dev/null +++ b/src/android/PrinterInputParameterConstant.java @@ -0,0 +1,14 @@ +package com.threescreens.cordova.plugin.brotherprinter; + +public class PrinterInputParameterConstant { + public static final String PRINTER_MODEL = "printerModel"; + public static final String PORT = "port"; + public static final String IP_ADDRESS = "ipAddress"; + public static final String MAC_ADDRESS = "macAddress"; + public static final String PAPER_SIZE = "paperSize"; + public static final String ORIENTATION = "orientation"; + public static final String INCLUDE_BATTERY_STATUS = "includeBatteryStatus"; + + private PrinterInputParameterConstant() { + } +}