Skip to content

Commit 8be24ed

Browse files
committed
React Native ESC POS Printer Library v0.0.1
This is the first release.
0 parents  commit 8be24ed

File tree

10 files changed

+475
-0
lines changed

10 files changed

+475
-0
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
android/build
3+
android/build/*

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## React Native Android Library For ESC POS PRINTER

android/build.gradle

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import groovy.json.JsonSlurper
2+
3+
def computeVersionName() {
4+
// dynamically retrieve version from package.json
5+
def slurper = new JsonSlurper()
6+
def json = slurper.parse(file('../package.json'), "utf-8")
7+
return json.version
8+
}
9+
10+
buildscript {
11+
repositories {
12+
jcenter()
13+
}
14+
15+
dependencies {
16+
classpath 'com.android.tools.build:gradle:1.5.0'
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
22+
android {
23+
compileSdkVersion 23
24+
buildToolsVersion "23.0.1"
25+
26+
defaultConfig {
27+
minSdkVersion 16
28+
targetSdkVersion 22
29+
versionCode 1
30+
// get version name from package.json version
31+
versionName computeVersionName()
32+
33+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
34+
}
35+
lintOptions {
36+
abortOnError false
37+
}
38+
buildTypes {
39+
release {
40+
minifyEnabled false
41+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
42+
}
43+
}
44+
}
45+
46+
repositories {
47+
mavenCentral()
48+
}
49+
50+
dependencies {
51+
compile fileTree(dir: 'libs', include: ['*.jar'])
52+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
53+
exclude group: 'com.android.support', module: 'support-annotations'
54+
})
55+
compile 'com.android.support:appcompat-v7:21.2.1'
56+
compile 'com.facebook.react:react-native:+'
57+
58+
}
59+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.bondwp322.react_native.esc_pos_lib">
3+
</manifest>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.bondwp322.react_native.esc_pos_lib;
2+
3+
4+
import android.hardware.usb.UsbDevice;
5+
6+
import com.facebook.react.bridge.Arguments;
7+
import com.facebook.react.bridge.Promise;
8+
import com.facebook.react.bridge.ReactApplicationContext;
9+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
10+
import com.facebook.react.bridge.ReactMethod;
11+
import com.facebook.react.bridge.WritableArray;
12+
import com.facebook.react.bridge.WritableMap;
13+
14+
import java.util.List;
15+
16+
public class RNPrinterModule extends ReactContextBaseJavaModule {
17+
18+
19+
private USBPrinterAdapter adapter;
20+
public RNPrinterModule(ReactApplicationContext reactContext){
21+
super(reactContext);
22+
this.adapter = USBPrinterAdapter.getInstance();
23+
this.adapter.init(reactContext);
24+
}
25+
26+
@Override
27+
public String getName() {
28+
return "RNPrinter";
29+
}
30+
31+
32+
@ReactMethod
33+
public void getUSBDeviceList(Promise promise) {
34+
List<UsbDevice> usbDevices = adapter.getDeviceList();
35+
WritableArray pairedDeviceList = Arguments.createArray();
36+
for (UsbDevice usbDevice : usbDevices) {
37+
WritableMap deviceMap = Arguments.createMap();
38+
deviceMap.putString("device_name", usbDevice.getDeviceName());
39+
deviceMap.putInt("device_id", usbDevice.getDeviceId());
40+
deviceMap.putInt("vendor_id", usbDevice.getVendorId());
41+
deviceMap.putInt("product_id", usbDevice.getProductId());
42+
pairedDeviceList.pushMap(deviceMap);
43+
}
44+
promise.resolve(pairedDeviceList);
45+
}
46+
47+
48+
@ReactMethod
49+
public void connectPrinter(Integer vendorId, Integer productId, Promise promise) {
50+
if(!adapter.selectDevice(vendorId, productId)){
51+
promise.resolve(false);
52+
}else{
53+
promise.resolve(true);
54+
}
55+
}
56+
57+
58+
@ReactMethod
59+
public void closeConn(Promise promise) {
60+
adapter.closeConnectionIfExists();
61+
promise.resolve(null);
62+
}
63+
64+
65+
66+
67+
@ReactMethod
68+
public void printText(String text) {
69+
adapter.printText(text);
70+
}
71+
72+
@ReactMethod
73+
public void printRawData(String base64Data) {
74+
adapter.printRawData(base64Data);
75+
}
76+
77+
}
78+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.bondwp322.react_native.esc_pos_lib;
2+
3+
import com.facebook.react.ReactPackage;
4+
import com.facebook.react.bridge.NativeModule;
5+
import com.facebook.react.bridge.ReactApplicationContext;
6+
import com.facebook.react.uimanager.ViewManager;
7+
8+
import java.util.Arrays;
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
public class RNPrinterPackage implements ReactPackage {
13+
@Override
14+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15+
return Arrays.asList(new NativeModule[]{
16+
new RNPrinterModule(reactContext)
17+
});
18+
}
19+
20+
@Override
21+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
22+
return Collections.emptyList();
23+
}
24+
}

0 commit comments

Comments
 (0)