Skip to content

Commit

Permalink
add text aligning and constant value
Browse files Browse the repository at this point in the history
  • Loading branch information
nowarzz committed Jul 8, 2019
1 parent 934824e commit eb63c9b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
39 changes: 39 additions & 0 deletions android/src/main/java/com/nowarzz/rrnepson/EpsonTM82.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.epson.epos2.printer.ReceiveListener;

import java.util.Map;
import java.util.HashMap;

public class EpsonTM82 implements MyPrinter, ReceiveListener {

Expand Down Expand Up @@ -49,6 +50,7 @@ public EpsonTM82(final Context context, final PrinterEventListener eventListener
this.listener.onInitializeSuccess("Success Connected");
}


@Override
public MyReturnValue writeText(String text, ReadableMap property) {
MyReturnValue res = new MyReturnValue();
Expand Down Expand Up @@ -85,6 +87,43 @@ public MyReturnValue writeText(String text, ReadableMap property) {
return res;
}


@Override
public MyReturnValue addTextAlign(int align){
MyReturnValue res = new MyReturnValue();
if (this.mPrinter == null) {
res.success = false;
res.message = "Printer belum di inisiasi";
return res;
}
try{
this.mPrinter.addTextAlign(align);
}catch(Epos2Exception e){
String message;
int errorStatus = e.getErrorStatus();
switch (errorStatus) {
case Epos2Exception.ERR_PARAM:
message = "Parameter Invalid";
break;
case Epos2Exception.ERR_MEMORY:
message = "Out of memory";
break;
case Epos2Exception.ERR_FAILURE:
message = "Unknown Error";
break;
default:
message = Integer.toString(errorStatus);
}
Toast.makeText(this.reactContext, message, 1).show();
res.success = false;
res.message = message;
return res;
}
res.success = true;
res.message="Sukses";
return res;
}

@Override
public void writeQRCode(String content, ReadableMap property) {
Toast.makeText(this.reactContext, "Currently Not Supported", 1).show();
Expand Down
1 change: 1 addition & 0 deletions android/src/main/java/com/nowarzz/rrnepson/MyPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public interface MyPrinter {
MyReturnValue writeText(String text, ReadableMap property);
void writeQRCode(String content, ReadableMap property);
MyReturnValue addTextAlign(int align);
MyReturnValue writeImage(Bitmap data, int x, int y, int width, int height);
MyReturnValue writeFeed(int length);
MyReturnValue writeCut(ReadableMap property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import java.util.ArrayList;
import javax.annotation.Nullable;

import java.util.Map;
import java.util.HashMap;

import com.epson.epos2.printer.Printer;

public class RNReactNativeEpsonTm82Module extends ReactContextBaseJavaModule implements PrinterEventListener {

Expand Down Expand Up @@ -85,6 +89,16 @@ public void initializeDiscovery(Promise promise){
promise.resolve(null);
}

@Override
public Map<String,Object> getConstants(){
final Map<String, Object> constants = new HashMap<>();
constants.put("ALIGN_LEFT", Printer.ALIGN_LEFT);
constants.put("ALIGN_CENTER", Printer.ALIGN_CENTER);
constants.put("ALIGN_RIGHT", Printer.ALIGN_RIGHT);
constants.put("PARAM_DEFAULT", Printer.PARAM_DEFAULT);
return constants;
}



@ReactMethod
Expand Down Expand Up @@ -123,6 +137,16 @@ public void writeText(String text, ReadableMap property,Promise promise) {
}
}

@ReactMethod
public void addTextAlign(int align, Promise promise){
MyReturnValue res = printer.addTextAlign(align);
if(res.success){
promise.resolve(null);
}else{
promise.reject(res.message);
}
}

@ReactMethod
public void printColumn(ReadableArray columnWidths, ReadableArray columnAligns, ReadableArray columnTexts, @Nullable ReadableMap options, final Promise promise){
if(columnWidths.size() != columnTexts.size() || columnWidths.size() != columnAligns.size()){
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ function CheckPlatformSupport() {
return true;
}


export default {
RNThermalPrinter,
initialize : ()=> {
RNThermalPrinter.initilize();
},
addTextAlign: (align)=>{
RNThermalPrinter.addTextAlign(align);
},
writeText :(text, property) => {
RNThermalPrinter.writeText(text, property);
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rn-epson-tm82",
"version": "1.0.0",
"version": "1.1.0",
"description": "Project Under Development! Do Not Use Until It Launch.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit eb63c9b

Please sign in to comment.