Skip to content

Commit

Permalink
- Option to remove battery info from response
Browse files Browse the repository at this point in the history
- Default align to top left
  • Loading branch information
arcadius committed May 10, 2021
1 parent d43ec92 commit 5f25a76
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 5 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-brother-label-printer"
version="1.5.1">
version="1.5.4">

<name>BrotherPrinter</name>

Expand All @@ -28,11 +28,13 @@
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="BrotherPrinter">
<param name="android-package" value="com.threescreens.cordova.plugin.brotherPrinter.BrotherPrinter"/>
<param name="android-package" value="com.threescreens.cordova.plugin.brotherprinter.BrotherPrinter"/>
</feature>
</config-file>

<source-file src="src/android/BrotherPrinter.java" target-dir="src/com/threescreens/cordova/plugin/brotherPrinter" />
<source-file src="src/android/BrotherPrinter.java" target-dir="src/com/threescreens/cordova/plugin/brotherprinter" />
<source-file src="src/android/PrinterInputParameterConstant.java" target-dir="src/com/threescreens/cordova/plugin/brotherprinter" />


<source-file src="src/android/Common.java" target-dir="src/com/brother/ptouch/sdk/printdemo/common" />
<source-file src="src/android/MsgHandle.java" target-dir="src/com/brother/ptouch/sdk/printdemo/common" />
Expand Down
22 changes: 19 additions & 3 deletions src/android/BasePrint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions src/android/BrotherPrinter.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.threescreens.cordova.plugin.brotherPrinter;
package com.threescreens.cordova.plugin.brotherprinter;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/android/PrinterInputParameterConstant.java
Original file line number Diff line number Diff line change
@@ -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() {
}
}

0 comments on commit 5f25a76

Please sign in to comment.