Browse Source

initial commit

master
munir ishak 4 years ago
commit
7e7e51d07d

+ 1
- 0
.gitattributes View File

@@ -0,0 +1 @@
1
+*.pbxproj -text

+ 42
- 0
.gitignore View File

@@ -0,0 +1,42 @@
1
+# OSX
2
+#
3
+.DS_Store
4
+
5
+# node.js
6
+#
7
+node_modules/
8
+npm-debug.log
9
+yarn-error.log
10
+
11
+# Xcode
12
+#
13
+build/
14
+*.pbxuser
15
+!default.pbxuser
16
+*.mode1v3
17
+!default.mode1v3
18
+*.mode2v3
19
+!default.mode2v3
20
+*.perspectivev3
21
+!default.perspectivev3
22
+xcuserdata
23
+*.xccheckout
24
+*.moved-aside
25
+DerivedData
26
+*.hmap
27
+*.ipa
28
+*.xcuserstate
29
+project.xcworkspace
30
+
31
+# Android/IntelliJ
32
+#
33
+build/
34
+.idea
35
+.gradle
36
+local.properties
37
+*.iml
38
+
39
+# BUCK
40
+buck-out/
41
+\.buckd/
42
+*.keystore

+ 0
- 0
.npmignore View File


+ 17
- 0
README.md View File

@@ -0,0 +1,17 @@
1
+# react-native-xprinter-mirfalahtech
2
+
3
+## Getting started
4
+
5
+`$ npm install react-native-xprinter-mirfalahtech --save`
6
+
7
+### Mostly automatic installation
8
+
9
+`$ react-native link react-native-xprinter-mirfalahtech`
10
+
11
+## Usage
12
+```javascript
13
+import XprinterMirfalahtech from 'react-native-xprinter-mirfalahtech';
14
+
15
+// TODO: What to do with the module?
16
+XprinterMirfalahtech;
17
+```

+ 14
- 0
android/README.md View File

@@ -0,0 +1,14 @@
1
+README
2
+======
3
+
4
+If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm:
5
+
6
+1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed
7
+2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
8
+```
9
+ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
10
+sdk.dir=/Users/{username}/Library/Android/sdk
11
+```
12
+3. Delete the `maven` folder
13
+4. Run `./gradlew installArchives`
14
+5. Verify that latest set of generated files is in the maven folder with the correct version number

+ 157
- 0
android/build.gradle View File

@@ -0,0 +1,157 @@
1
+// android/build.gradle
2
+
3
+// based on:
4
+//
5
+// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
6
+//   original location:
7
+//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
8
+//
9
+// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
10
+//   original location:
11
+//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
12
+
13
+def DEFAULT_COMPILE_SDK_VERSION = 28
14
+def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
15
+def DEFAULT_MIN_SDK_VERSION = 16
16
+def DEFAULT_TARGET_SDK_VERSION = 28
17
+
18
+def safeExtGet(prop, fallback) {
19
+    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
20
+}
21
+
22
+apply plugin: 'com.android.library'
23
+apply plugin: 'maven'
24
+
25
+buildscript {
26
+    // The Android Gradle plugin is only required when opening the android folder stand-alone.
27
+    // This avoids unnecessary downloads and potential conflicts when the library is included as a
28
+    // module dependency in an application project.
29
+    // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
30
+    if (project == rootProject) {
31
+        repositories {
32
+            google()
33
+            jcenter()
34
+        }
35
+        dependencies {
36
+            classpath 'com.android.tools.build:gradle:3.4.1'
37
+        }
38
+    }
39
+}
40
+
41
+apply plugin: 'com.android.library'
42
+apply plugin: 'maven'
43
+
44
+android {
45
+    compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
46
+    buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
47
+    defaultConfig {
48
+        minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
49
+        targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
50
+        versionCode 1
51
+        versionName "1.0"
52
+    }
53
+    lintOptions {
54
+        abortOnError false
55
+    }
56
+}
57
+
58
+repositories {
59
+    // ref: https://www.baeldung.com/maven-local-repository
60
+    mavenLocal()
61
+    maven {
62
+        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
63
+        url "$rootDir/../node_modules/react-native/android"
64
+    }
65
+    maven {
66
+        // Android JSC is installed from npm
67
+        url "$rootDir/../node_modules/jsc-android/dist"
68
+    }
69
+    google()
70
+    jcenter()
71
+}
72
+
73
+dependencies {
74
+    //noinspection GradleDynamicVersion
75
+    implementation 'com.facebook.react:react-native:+'  // From node_modules
76
+
77
+
78
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
79
+    //压缩
80
+
81
+    implementation 'com.zxy.android:tiny:0.0.6'
82
+    implementation files('libs/posprinterconnectandsendsdk.jar')
83
+    implementation files('libs/xprinterconnectandsendsdk.jar')
84
+}
85
+
86
+def configureReactNativePom(def pom) {
87
+    def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
88
+
89
+    pom.project {
90
+        name packageJson.title
91
+        artifactId packageJson.name
92
+        version = packageJson.version
93
+        group = "com.reactlibrary"
94
+        description packageJson.description
95
+        url packageJson.repository.baseUrl
96
+
97
+        licenses {
98
+            license {
99
+                name packageJson.license
100
+                url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
101
+                distribution 'repo'
102
+            }
103
+        }
104
+
105
+        developers {
106
+            developer {
107
+                id packageJson.author.username
108
+                name packageJson.author.name
109
+            }
110
+        }
111
+    }
112
+}
113
+
114
+afterEvaluate { project ->
115
+    // some Gradle build hooks ref:
116
+    // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
117
+    task androidJavadoc(type: Javadoc) {
118
+        source = android.sourceSets.main.java.srcDirs
119
+        classpath += files(android.bootClasspath)
120
+        classpath += files(project.getConfigurations().getByName('compile').asList())
121
+        include '**/*.java'
122
+    }
123
+
124
+    task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
125
+        classifier = 'javadoc'
126
+        from androidJavadoc.destinationDir
127
+    }
128
+
129
+    task androidSourcesJar(type: Jar) {
130
+        classifier = 'sources'
131
+        from android.sourceSets.main.java.srcDirs
132
+        include '**/*.java'
133
+    }
134
+
135
+    android.libraryVariants.all { variant ->
136
+        def name = variant.name.capitalize()
137
+        def javaCompileTask = variant.javaCompileProvider.get()
138
+
139
+        task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
140
+            from javaCompileTask.destinationDir
141
+        }
142
+    }
143
+
144
+    artifacts {
145
+        archives androidSourcesJar
146
+        archives androidJavadocJar
147
+    }
148
+
149
+    task installArchives(type: Upload) {
150
+        configuration = configurations.archives
151
+        repositories.mavenDeployer {
152
+            // Deploy to react-native-event-bridge/maven, ready to publish to npm
153
+            repository url: "file://${projectDir}/../android/maven"
154
+            configureReactNativePom pom
155
+        }
156
+    }
157
+}

BIN
android/gradle/wrapper/gradle-wrapper.jar View File


+ 6
- 0
android/gradle/wrapper/gradle-wrapper.properties View File

@@ -0,0 +1,6 @@
1
+#Mon Feb 03 01:02:16 MYT 2020
2
+distributionBase=GRADLE_USER_HOME
3
+distributionPath=wrapper/dists
4
+zipStoreBase=GRADLE_USER_HOME
5
+zipStorePath=wrapper/dists
6
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

+ 172
- 0
android/gradlew View File

@@ -0,0 +1,172 @@
1
+#!/usr/bin/env sh
2
+
3
+##############################################################################
4
+##
5
+##  Gradle start up script for UN*X
6
+##
7
+##############################################################################
8
+
9
+# Attempt to set APP_HOME
10
+# Resolve links: $0 may be a link
11
+PRG="$0"
12
+# Need this for relative symlinks.
13
+while [ -h "$PRG" ] ; do
14
+    ls=`ls -ld "$PRG"`
15
+    link=`expr "$ls" : '.*-> \(.*\)$'`
16
+    if expr "$link" : '/.*' > /dev/null; then
17
+        PRG="$link"
18
+    else
19
+        PRG=`dirname "$PRG"`"/$link"
20
+    fi
21
+done
22
+SAVED="`pwd`"
23
+cd "`dirname \"$PRG\"`/" >/dev/null
24
+APP_HOME="`pwd -P`"
25
+cd "$SAVED" >/dev/null
26
+
27
+APP_NAME="Gradle"
28
+APP_BASE_NAME=`basename "$0"`
29
+
30
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31
+DEFAULT_JVM_OPTS=""
32
+
33
+# Use the maximum available, or set MAX_FD != -1 to use that value.
34
+MAX_FD="maximum"
35
+
36
+warn () {
37
+    echo "$*"
38
+}
39
+
40
+die () {
41
+    echo
42
+    echo "$*"
43
+    echo
44
+    exit 1
45
+}
46
+
47
+# OS specific support (must be 'true' or 'false').
48
+cygwin=false
49
+msys=false
50
+darwin=false
51
+nonstop=false
52
+case "`uname`" in
53
+  CYGWIN* )
54
+    cygwin=true
55
+    ;;
56
+  Darwin* )
57
+    darwin=true
58
+    ;;
59
+  MINGW* )
60
+    msys=true
61
+    ;;
62
+  NONSTOP* )
63
+    nonstop=true
64
+    ;;
65
+esac
66
+
67
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68
+
69
+# Determine the Java command to use to start the JVM.
70
+if [ -n "$JAVA_HOME" ] ; then
71
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72
+        # IBM's JDK on AIX uses strange locations for the executables
73
+        JAVACMD="$JAVA_HOME/jre/sh/java"
74
+    else
75
+        JAVACMD="$JAVA_HOME/bin/java"
76
+    fi
77
+    if [ ! -x "$JAVACMD" ] ; then
78
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79
+
80
+Please set the JAVA_HOME variable in your environment to match the
81
+location of your Java installation."
82
+    fi
83
+else
84
+    JAVACMD="java"
85
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86
+
87
+Please set the JAVA_HOME variable in your environment to match the
88
+location of your Java installation."
89
+fi
90
+
91
+# Increase the maximum file descriptors if we can.
92
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93
+    MAX_FD_LIMIT=`ulimit -H -n`
94
+    if [ $? -eq 0 ] ; then
95
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96
+            MAX_FD="$MAX_FD_LIMIT"
97
+        fi
98
+        ulimit -n $MAX_FD
99
+        if [ $? -ne 0 ] ; then
100
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
101
+        fi
102
+    else
103
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104
+    fi
105
+fi
106
+
107
+# For Darwin, add options to specify how the application appears in the dock
108
+if $darwin; then
109
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110
+fi
111
+
112
+# For Cygwin, switch paths to Windows format before running java
113
+if $cygwin ; then
114
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116
+    JAVACMD=`cygpath --unix "$JAVACMD"`
117
+
118
+    # We build the pattern for arguments to be converted via cygpath
119
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120
+    SEP=""
121
+    for dir in $ROOTDIRSRAW ; do
122
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
123
+        SEP="|"
124
+    done
125
+    OURCYGPATTERN="(^($ROOTDIRS))"
126
+    # Add a user-defined pattern to the cygpath arguments
127
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129
+    fi
130
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
131
+    i=0
132
+    for arg in "$@" ; do
133
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
135
+
136
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
137
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138
+        else
139
+            eval `echo args$i`="\"$arg\""
140
+        fi
141
+        i=$((i+1))
142
+    done
143
+    case $i in
144
+        (0) set -- ;;
145
+        (1) set -- "$args0" ;;
146
+        (2) set -- "$args0" "$args1" ;;
147
+        (3) set -- "$args0" "$args1" "$args2" ;;
148
+        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149
+        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150
+        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151
+        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152
+        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153
+        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154
+    esac
155
+fi
156
+
157
+# Escape application args
158
+save () {
159
+    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160
+    echo " "
161
+}
162
+APP_ARGS=$(save "$@")
163
+
164
+# Collect all arguments for the java command, following the shell quoting and substitution rules
165
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166
+
167
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169
+  cd "$(dirname "$0")"
170
+fi
171
+
172
+exec "$JAVACMD" "$@"

+ 84
- 0
android/gradlew.bat View File

@@ -0,0 +1,84 @@
1
+@if "%DEBUG%" == "" @echo off
2
+@rem ##########################################################################
3
+@rem
4
+@rem  Gradle startup script for Windows
5
+@rem
6
+@rem ##########################################################################
7
+
8
+@rem Set local scope for the variables with windows NT shell
9
+if "%OS%"=="Windows_NT" setlocal
10
+
11
+set DIRNAME=%~dp0
12
+if "%DIRNAME%" == "" set DIRNAME=.
13
+set APP_BASE_NAME=%~n0
14
+set APP_HOME=%DIRNAME%
15
+
16
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17
+set DEFAULT_JVM_OPTS=
18
+
19
+@rem Find java.exe
20
+if defined JAVA_HOME goto findJavaFromJavaHome
21
+
22
+set JAVA_EXE=java.exe
23
+%JAVA_EXE% -version >NUL 2>&1
24
+if "%ERRORLEVEL%" == "0" goto init
25
+
26
+echo.
27
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
+echo.
29
+echo Please set the JAVA_HOME variable in your environment to match the
30
+echo location of your Java installation.
31
+
32
+goto fail
33
+
34
+:findJavaFromJavaHome
35
+set JAVA_HOME=%JAVA_HOME:"=%
36
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
+
38
+if exist "%JAVA_EXE%" goto init
39
+
40
+echo.
41
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
+echo.
43
+echo Please set the JAVA_HOME variable in your environment to match the
44
+echo location of your Java installation.
45
+
46
+goto fail
47
+
48
+:init
49
+@rem Get command-line arguments, handling Windows variants
50
+
51
+if not "%OS%" == "Windows_NT" goto win9xME_args
52
+
53
+:win9xME_args
54
+@rem Slurp the command line arguments.
55
+set CMD_LINE_ARGS=
56
+set _SKIP=2
57
+
58
+:win9xME_args_slurp
59
+if "x%~1" == "x" goto execute
60
+
61
+set CMD_LINE_ARGS=%*
62
+
63
+:execute
64
+@rem Setup the command line
65
+
66
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67
+
68
+@rem Execute Gradle
69
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70
+
71
+:end
72
+@rem End local scope for the variables with windows NT shell
73
+if "%ERRORLEVEL%"=="0" goto mainEnd
74
+
75
+:fail
76
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77
+rem the _cmd.exe /c_ return code!
78
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79
+exit /b 1
80
+
81
+:mainEnd
82
+if "%OS%"=="Windows_NT" endlocal
83
+
84
+:omega

BIN
android/libs/posprinterconnectandsendsdk.jar View File


BIN
android/libs/xprinterconnectandsendsdk.jar View File


+ 4
- 0
android/src/main/AndroidManifest.xml View File

@@ -0,0 +1,4 @@
1
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+          package="com.mirfalahtech.xprinter">
3
+
4
+</manifest>

+ 57
- 0
android/src/main/java/com/mirfalahtech/xprinter/PrinterCommands.java View File

@@ -0,0 +1,57 @@
1
+package com.mirfalahtech.xprinter;
2
+
3
+public class PrinterCommands {
4
+    public static final byte HT = 0x9;
5
+    public static final byte LF = 0x0A;
6
+    public static final byte CR = 0x0D;
7
+    public static final byte ESC = 0x1B;
8
+    public static final byte DLE = 0x10;
9
+    public static final byte GS = 0x1D;
10
+    public static final byte FS = 0x1C;
11
+    public static final byte STX = 0x02;
12
+    public static final byte US = 0x1F;
13
+    public static final byte CAN = 0x18;
14
+    public static final byte CLR = 0x0C;
15
+    public static final byte EOT = 0x04;
16
+
17
+    public static final byte[] INIT = {27, 64};
18
+    public static byte[] FEED_LINE = {10};
19
+
20
+    public static byte[] SELECT_FONT_A = {20, 33, 0};
21
+
22
+    public static byte[] SET_BAR_CODE_HEIGHT = {29, 104, 100};
23
+    public static byte[] PRINT_BAR_CODE_1 = {29, 107, 2};
24
+    public static byte[] SEND_NULL_BYTE = {0x00};
25
+
26
+    public static byte[] SELECT_PRINT_SHEET = {0x1B, 0x63, 0x30, 0x02};
27
+    public static byte[] FEED_PAPER_AND_CUT = {0x1D, 0x56, 66, 0x00};
28
+
29
+    public static byte[] SELECT_CYRILLIC_CHARACTER_CODE_TABLE = {0x1B, 0x74, 0x11};
30
+
31
+    public static byte[] SELECT_BIT_IMAGE_MODE = {0x1B, 0x2A, 33, -128, 0};
32
+    public static byte[] SET_LINE_SPACING_24 = {0x1B, 0x33, 24};
33
+    public static byte[] SET_LINE_SPACING_30 = {0x1B, 0x33, 30};
34
+
35
+    public static byte[] TRANSMIT_DLE_PRINTER_STATUS = {0x10, 0x04, 0x01};
36
+    public static byte[] TRANSMIT_DLE_OFFLINE_PRINTER_STATUS = {0x10, 0x04, 0x02};
37
+    public static byte[] TRANSMIT_DLE_ERROR_STATUS = {0x10, 0x04, 0x03};
38
+    public static byte[] TRANSMIT_DLE_ROLL_PAPER_SENSOR_STATUS = {0x10, 0x04, 0x04};
39
+
40
+    public static final byte[] ESC_FONT_COLOR_DEFAULT = new byte[] { 0x1B, 'r',0x00 };
41
+    public static final byte[] FS_FONT_ALIGN = new byte[] { 0x1C, 0x21, 1, 0x1B,
42
+            0x21, 1 };
43
+    public static final byte[] ESC_ALIGN_LEFT = new byte[] { 0x1b, 'a', 0x00 };
44
+    public static final byte[] ESC_ALIGN_RIGHT = new byte[] { 0x1b, 'a', 0x02 };
45
+    public static final byte[] ESC_ALIGN_CENTER = new byte[] { 0x1b, 'a', 0x01 };
46
+    public static final byte[] ESC_CANCEL_BOLD = new byte[] { 0x1B, 0x45, 0 };
47
+
48
+
49
+    /*********************************************/
50
+    public static final byte[] ESC_HORIZONTAL_CENTERS = new byte[] { 0x1B, 0x44, 20, 28, 00};
51
+    public static final byte[] ESC_CANCLE_HORIZONTAL_CENTERS = new byte[] { 0x1B, 0x44, 00 };
52
+    /*********************************************/
53
+
54
+    public static final byte[] ESC_ENTER = new byte[] { 0x1B, 0x4A, 0x40 };
55
+    public static final byte[] PRINTE_TEST = new byte[] { 0x1D, 0x28, 0x41 };
56
+
57
+}

+ 342
- 0
android/src/main/java/com/mirfalahtech/xprinter/RNXNetprinter.java View File

@@ -0,0 +1,342 @@
1
+package com.mirfalahtech.xprinter;
2
+
3
+import android.content.ComponentName;
4
+import android.content.Intent;
5
+import android.content.ServiceConnection;
6
+import android.graphics.Matrix;
7
+import android.os.IBinder;
8
+import android.util.Log;
9
+import java.util.Set;
10
+
11
+import android.graphics.Bitmap;
12
+import android.os.Handler;
13
+import android.os.Message;
14
+
15
+import android.graphics.BitmapFactory;
16
+import android.util.Base64;
17
+
18
+import com.facebook.react.bridge.Arguments;
19
+import com.facebook.react.bridge.Promise;
20
+import com.facebook.react.bridge.ReactApplicationContext;
21
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
22
+import com.facebook.react.bridge.ReactMethod;
23
+import com.facebook.react.bridge.WritableArray;
24
+import com.facebook.react.bridge.WritableMap;
25
+
26
+import net.posprinter.posprinterface.IMyBinder;
27
+
28
+import com.mirfalahtech.xprinter.StringUtils;
29
+import com.zxy.tiny.Tiny;
30
+import com.zxy.tiny.callback.BitmapCallback;
31
+
32
+import net.posprinter.posprinterface.ProcessData;
33
+import net.posprinter.posprinterface.UiExecute;
34
+import net.posprinter.service.PosprinterService;
35
+import net.posprinter.utils.BitmapToByteData;
36
+import net.posprinter.utils.DataForSendToPrinterPos58;
37
+import net.posprinter.utils.DataForSendToPrinterPos80;
38
+import net.posprinter.utils.PosPrinterDev;
39
+
40
+import java.util.ArrayList;
41
+import java.util.List;
42
+
43
+import static android.content.Context.BIND_AUTO_CREATE;
44
+
45
+public class RNXNetprinter extends ReactContextBaseJavaModule {
46
+  private String LOG_TAG = "RNXNetprinter";
47
+  private ReactApplicationContext context;
48
+
49
+  private byte[] mBuffer = new byte[0];
50
+
51
+  // Net
52
+  public static IMyBinder binder;
53
+  public static boolean ISCONNECT;
54
+
55
+//bindService connection
56
+ServiceConnection conn= new ServiceConnection() {
57
+    @Override
58
+    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
59
+        //Bind successfully
60
+        binder= (IMyBinder) iBinder;
61
+        Log.e("binder","connected");
62
+    }
63
+
64
+    @Override
65
+    public void onServiceDisconnected(ComponentName componentName) {
66
+        Log.e("disbinder","disconnected");
67
+    }
68
+};
69
+
70
+  public RNXNetprinter(ReactApplicationContext reactContext) {
71
+    super(reactContext);
72
+
73
+    this.context = reactContext;
74
+
75
+    Intent intent=new Intent(this.context, PosprinterService.class);
76
+    this.context.bindService(intent, conn, BIND_AUTO_CREATE);
77
+    Log.v(LOG_TAG, "RNXNetprinter alloc");
78
+  }
79
+
80
+  @Override
81
+  public String getName() {
82
+    return "RNXNetprinter";
83
+  }
84
+
85
+  @ReactMethod
86
+  public void connectPrinter(String address, final Promise promise){
87
+    binder.connectNetPort(address,9100, new UiExecute() {
88
+      @Override
89
+      public void onsucess() {
90
+
91
+          ISCONNECT=true;
92
+          //in this ,you could call acceptdatafromprinter(),when disconnect ,will execute onfailed();
93
+          binder.acceptdatafromprinter(new UiExecute() {
94
+              @Override
95
+              public void onsucess() {
96
+                promise.resolve(true);
97
+              }
98
+
99
+              @Override
100
+              public void onfailed() {
101
+                  ISCONNECT=false;
102
+                  promise.reject("-105", "Device address not exist.");
103
+              }
104
+          });
105
+      }
106
+
107
+      @Override
108
+      public void onfailed() {
109
+        ISCONNECT=false;
110
+        promise.reject("-105", "Device address not exist.");
111
+      }
112
+    });
113
+  }
114
+
115
+  @ReactMethod
116
+  public void pushText(String text, final int size){
117
+
118
+      final String tempText = text;
119
+    binder.writeDataByYouself(
120
+      new UiExecute() {
121
+          @Override
122
+          public void onsucess() {
123
+              Log.v(LOG_TAG, "pushText onsucess");
124
+          }
125
+
126
+          @Override
127
+          public void onfailed() {
128
+              Log.v(LOG_TAG, "pushText onfailed");
129
+          }
130
+      }, new ProcessData() {
131
+          @Override
132
+          public List<byte[]> processDataBeforeSend() {
133
+
134
+              List<byte[]> list=new ArrayList<byte[]>();
135
+              //creat a text ,and make it to byte[],
136
+              String str=tempText;
137
+              if (str.equals(null)||str.equals("")){
138
+              }else {
139
+                  //initialize the printer
140
+//                            list.add( DataForSendToPrinterPos58.initializePrinter());
141
+                  list.add(DataForSendToPrinterPos80.initializePrinter());
142
+                  byte[] data1= StringUtils.strTobytes(str);
143
+                  list.add(PrinterCommands.ESC_ALIGN_CENTER);
144
+                  list.add(DataForSendToPrinterPos80.selectCharacterSize(size));
145
+                  list.add(data1);
146
+                  //should add the command of print and feed line,because print only when one line is complete, not one line, no print
147
+                  list.add(DataForSendToPrinterPos80.printAndFeedLine());
148
+                  return list;
149
+              }
150
+              return null;
151
+          }
152
+      }
153
+    );
154
+  }
155
+
156
+
157
+  private Bitmap b1;//grey-scale bitmap
158
+  private  Bitmap b2;//compress bitmap
159
+
160
+  @ReactMethod
161
+  private void printImage(String base64img, final int width){
162
+    byte [] bytes = Base64.decode(base64img, Base64.DEFAULT);                
163
+    Bitmap b = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
164
+    
165
+    if (b != null) {
166
+      b1=convertGreyImg(b);
167
+      Message message=new Message();
168
+      message.what=1;
169
+      handler.handleMessage(message);
170
+
171
+      //compress the bitmap
172
+      Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions();
173
+      Tiny.getInstance().source(b1).asBitmap().withOptions(options).compress(new BitmapCallback() {
174
+          @Override
175
+          public void callback(boolean isSuccess, Bitmap bitmap) {
176
+              if (isSuccess){
177
+  //                            Toast.makeText(PosActivity.this,"bitmap: "+bitmap.getByteCount(),Toast.LENGTH_LONG).show();
178
+                  b2=bitmap;
179
+                  b2=resizeImage(b2,width,false);
180
+                  Message message=new Message();
181
+                  message.what=2;
182
+                  handler.handleMessage(message);
183
+              }
184
+
185
+
186
+          }
187
+      });
188
+    }
189
+  }
190
+
191
+    public static Bitmap resizeImage(Bitmap bitmap, int w,boolean ischecked)
192
+    {
193
+
194
+        Bitmap BitmapOrg = bitmap;
195
+        Bitmap resizedBitmap = null;
196
+        int width = BitmapOrg.getWidth();
197
+        int height = BitmapOrg.getHeight();
198
+        if (width<=w) {
199
+            return bitmap;
200
+        }
201
+        if (!ischecked) {
202
+            int newWidth = w;
203
+            int newHeight = height*w/width;
204
+
205
+            float scaleWidth = ((float) newWidth) / width;
206
+            float scaleHeight = ((float) newHeight) / height;
207
+
208
+            Matrix matrix = new Matrix();
209
+            matrix.postScale(scaleWidth, scaleHeight);
210
+            // if you want to rotate the Bitmap
211
+            // matrix.postRotate(45);
212
+            resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,
213
+                    height, matrix, true);
214
+        }else {
215
+            resizedBitmap=Bitmap.createBitmap(BitmapOrg, 0, 0, w, height);
216
+        }
217
+
218
+        return resizedBitmap;
219
+    }
220
+
221
+  private void printpicCode(final Bitmap printBmp){
222
+    binder.writeDataByYouself(new UiExecute() {
223
+      @Override
224
+      public void onsucess() {
225
+          Log.v(LOG_TAG, "printpicCode onsucess");
226
+      }
227
+
228
+      @Override
229
+      public void onfailed() {
230
+          Log.v(LOG_TAG, "printpicCode onfailed");
231
+      }
232
+    }, new ProcessData() {
233
+        @Override
234
+        public List<byte[]> processDataBeforeSend() {
235
+            List<byte[]> list=new ArrayList<byte[]>();
236
+            list.add(DataForSendToPrinterPos80.initializePrinter());
237
+            list.add(PrinterCommands.ESC_ALIGN_CENTER);
238
+            list.add(DataForSendToPrinterPos80.printRasterBmp(
239
+                    0,printBmp, BitmapToByteData.BmpType.Threshold, BitmapToByteData.AlignType.Left,576));
240
+  //                list.add(DataForSendToPrinterPos80.printAndFeedForward(3));
241
+            return list;
242
+        }
243
+    });
244
+  }
245
+
246
+  public Handler handler=new Handler(){
247
+    @Override
248
+    public void handleMessage(Message msg) {
249
+        super.handleMessage(msg);
250
+        switch (msg.what){
251
+            case 2:
252
+                printpicCode(b2);
253
+                break;
254
+        }
255
+
256
+    }
257
+};
258
+
259
+public Bitmap convertGreyImg(Bitmap img) {
260
+  int width = img.getWidth();
261
+  int height = img.getHeight();
262
+
263
+  int[] pixels = new int[width * height];
264
+
265
+  img.getPixels(pixels, 0, width, 0, 0, width, height);
266
+
267
+
268
+  //The arithmetic average of a grayscale image; a threshold
269
+  double redSum=0,greenSum=0,blueSun=0;
270
+  double total=width*height;
271
+
272
+  for(int i = 0; i < height; i++)  {
273
+      for(int j = 0; j < width; j++) {
274
+          int grey = pixels[width * i + j];
275
+
276
+          int red = ((grey  & 0x00FF0000 ) >> 16);
277
+          int green = ((grey & 0x0000FF00) >> 8);
278
+          int blue = (grey & 0x000000FF);
279
+
280
+
281
+
282
+          redSum+=red;
283
+          greenSum+=green;
284
+          blueSun+=blue;
285
+
286
+
287
+      }
288
+  }
289
+  int m=(int) (redSum/total);
290
+
291
+  //Conversion monochrome diagram
292
+  for(int i = 0; i < height; i++)  {
293
+      for(int j = 0; j < width; j++) {
294
+          int grey = pixels[width * i + j];
295
+
296
+          int alpha1 = 0xFF << 24;
297
+          int red = ((grey  & 0x00FF0000 ) >> 16);
298
+          int green = ((grey & 0x0000FF00) >> 8);
299
+          int blue = (grey & 0x000000FF);
300
+
301
+
302
+          if (red>=m) {
303
+              red=green=blue=255;
304
+          }else{
305
+              red=green=blue=0;
306
+          }
307
+          grey = alpha1 | (red << 16) | (green << 8) | blue;
308
+          pixels[width*i+j]=grey;
309
+
310
+
311
+      }
312
+  }
313
+  Bitmap mBitmap=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
314
+  mBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
315
+
316
+
317
+
318
+  return mBitmap;
319
+}
320
+
321
+  @ReactMethod
322
+  public void pushCutPaper(){
323
+      binder.writeDataByYouself(new UiExecute() {
324
+          @Override
325
+          public void onsucess() {
326
+              Log.v(LOG_TAG, "pushCutPaper onsucess");
327
+          }
328
+
329
+          @Override
330
+          public void onfailed() {
331
+              Log.v(LOG_TAG, "pushCutPaper onfailed");
332
+          }
333
+      }, new ProcessData() {
334
+          @Override
335
+          public List<byte[]> processDataBeforeSend() {
336
+              List<byte[]> list=new ArrayList<byte[]>();
337
+              list.add(DataForSendToPrinterPos80.selectCutPagerModerAndCutPager(66,1));
338
+              return list;
339
+          }
340
+      });
341
+  }
342
+}

+ 148
- 0
android/src/main/java/com/mirfalahtech/xprinter/RNXprinter.java View File

@@ -0,0 +1,148 @@
1
+package com.mirfalahtech.xprinter;
2
+
3
+import android.util.Log;
4
+import android.bluetooth.BluetoothAdapter;
5
+import android.bluetooth.BluetoothDevice;
6
+import java.util.Set;
7
+
8
+import com.facebook.react.bridge.Arguments;
9
+import com.facebook.react.bridge.Promise;
10
+import com.facebook.react.bridge.ReactApplicationContext;
11
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
12
+import com.facebook.react.bridge.ReactMethod;
13
+import com.facebook.react.bridge.WritableArray;
14
+import com.facebook.react.bridge.WritableMap;
15
+
16
+import net.xprinter.utils.XPrinterDev;
17
+import net.xprinter.utils.XPrinterDev.*;
18
+import net.xprinter.utils.DataForSendToPrinterXp80;
19
+
20
+public class RNXprinter extends ReactContextBaseJavaModule {
21
+  private String LOG_TAG = "RNXprinter";
22
+  private ReactApplicationContext context;
23
+
24
+  private byte[] mBuffer = new byte[0];
25
+
26
+  // Bluetooth
27
+  private Set<BluetoothDevice> mPairedDevices;
28
+  private XPrinterDev mBluetoothPrinter = null;
29
+
30
+  public RNXprinter(ReactApplicationContext reactContext) {
31
+    super(reactContext);
32
+
33
+    this.context = reactContext;
34
+
35
+    Log.v(LOG_TAG, "RNXprinter alloc");
36
+  }
37
+
38
+  @Override
39
+  public String getName() {
40
+    return "RNXprinter";
41
+  }
42
+
43
+  @ReactMethod
44
+  public void getDeviceList(Promise promise){
45
+    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
46
+    if (bluetoothAdapter == null) {
47
+      promise.reject("-100", "Not bluetooth adapter");
48
+    }
49
+    else if (bluetoothAdapter.isEnabled()) {
50
+      mPairedDevices = bluetoothAdapter.getBondedDevices();
51
+      WritableArray pairedDeviceList = Arguments.createArray();
52
+      for (BluetoothDevice device : mPairedDevices) {
53
+        WritableMap deviceMap = Arguments.createMap();
54
+        deviceMap.putString("name", device.getName());
55
+        deviceMap.putString("address", device.getAddress());
56
+        pairedDeviceList.pushMap(deviceMap);
57
+      }
58
+      promise.resolve(pairedDeviceList);
59
+    }
60
+    else {
61
+      promise.reject("-103", "BluetoothAdapter not open...");
62
+    }
63
+  }
64
+
65
+  @ReactMethod
66
+  public void selectDevice(String address, Promise promise){
67
+    for (BluetoothDevice device : mPairedDevices) {
68
+      Log.d(LOG_TAG, "Checking:" + device.getAddress() + " : " + address);
69
+      if(device.getAddress().equals(address)){
70
+        mBluetoothPrinter = new XPrinterDev(PortType.Bluetooth, address);
71
+        promise.resolve(true);
72
+        return;
73
+      }
74
+    }
75
+    promise.reject("-105", "Device address not exist.");
76
+  }
77
+
78
+  @ReactMethod
79
+  public void pushText(String text, Integer size){
80
+    if(size < 0 || size > 7) {
81
+      size = 0;
82
+    }
83
+    Log.d(LOG_TAG, "Set Font Size:" + size);
84
+    pushByteToBuffer(DataForSendToPrinterXp80.selectCharacterSize(size * 17));
85
+    Log.d(LOG_TAG, "Print String:" + text);
86
+    pushByteToBuffer(DataForSendToPrinterXp80.strTobytes(text + "\n"));
87
+  }
88
+
89
+  @ReactMethod
90
+  public void pushFlashImage(Integer index){
91
+    Log.d(LOG_TAG, "Print FLASH Image:" + index);
92
+    pushByteToBuffer(DataForSendToPrinterXp80.printBmpInFLASH(index, 0));
93
+  }
94
+
95
+  @ReactMethod
96
+  public void pushCutPaper(){
97
+    Log.d(LOG_TAG, "Cut Paper");
98
+    pushByteToBuffer(DataForSendToPrinterXp80.selectCutPagerModerAndCutPager(66, 0));
99
+  }
100
+
101
+  @ReactMethod
102
+  public void print(Promise promise){
103
+    if(mBluetoothPrinter == null){
104
+      promise.reject("-107", "Must select printer first.");
105
+      return;
106
+    }
107
+    if(mBuffer.length == 0){
108
+      promise.reject("-109", "Buffer is empty");
109
+      return;
110
+    }
111
+    ReturnMessage returnMessage = mBluetoothPrinter.Open();
112
+    Log.d(LOG_TAG, "Open device:" + returnMessage.GetErrorStrings());
113
+    returnMessage = mBluetoothPrinter.Write(mBuffer);
114
+    Log.d(LOG_TAG, "Write data:" + returnMessage.GetErrorStrings());
115
+    clearBuffer();
116
+    returnMessage = mBluetoothPrinter.Close();
117
+    Log.d(LOG_TAG, "Close device:" + returnMessage.GetErrorStrings());
118
+    promise.resolve(true);
119
+  }
120
+
121
+  @ReactMethod
122
+  public void clearPrintBuffer(){
123
+    clearBuffer();
124
+  }
125
+
126
+  @ReactMethod
127
+  public void printDemoPage(Promise promise){
128
+    clearBuffer();
129
+    pushFlashImage(1);
130
+    pushText("Xprinter TEST\n", 2);
131
+    pushText("如果您看到這個列印結果,表示您離成功非常的近了!加油!!!\n\n", 1);
132
+    pushText("Powered by FuGood MyBigDay Team", 0);
133
+    pushCutPaper();
134
+    print(promise);
135
+  }
136
+
137
+  private void pushByteToBuffer(byte[] input){
138
+    byte[] newByte = new byte[mBuffer.length + input.length];
139
+    System.arraycopy(mBuffer, 0, newByte, 0, mBuffer.length);
140
+    System.arraycopy(input, 0, newByte, mBuffer.length, input.length);
141
+    mBuffer = newByte;
142
+    Log.d(LOG_TAG, "Push buffer:" + mBuffer.length);
143
+  }
144
+  private void clearBuffer(){
145
+    mBuffer = new byte[0];
146
+    Log.d(LOG_TAG, "Clear buffer:" + mBuffer.length);
147
+  }
148
+}

+ 33
- 0
android/src/main/java/com/mirfalahtech/xprinter/RNXprinterPackage.java View File

@@ -0,0 +1,33 @@
1
+package com.mirfalahtech.xprinter;
2
+
3
+import java.util.*;
4
+
5
+import android.app.Activity;
6
+
7
+import com.facebook.react.ReactPackage;
8
+import com.facebook.react.bridge.NativeModule;
9
+import com.facebook.react.bridge.JavaScriptModule;
10
+import com.facebook.react.bridge.ReactApplicationContext;
11
+import com.facebook.react.uimanager.ViewManager;
12
+
13
+public class RNXprinterPackage implements ReactPackage {
14
+  
15
+  @Override
16
+  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
17
+    List<NativeModule> modules = new ArrayList<>();
18
+
19
+     modules.add(new RNXprinter(reactContext));
20
+    modules.add(new RNXNetprinter(reactContext));
21
+    return modules;
22
+  }
23
+
24
+  // @Override
25
+  // public List<Class<? extends JavaScriptModule>> createJSModules() {
26
+  //   return Collections.emptyList();
27
+  // }
28
+
29
+  @Override
30
+  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
31
+    return Arrays.<ViewManager>asList();
32
+  }
33
+}

+ 44
- 0
android/src/main/java/com/mirfalahtech/xprinter/StringUtils.java View File

@@ -0,0 +1,44 @@
1
+package com.mirfalahtech.xprinter;
2
+
3
+import java.io.UnsupportedEncodingException;
4
+
5
+/**
6
+ * Created by kylin on 2017/4/6.
7
+ */
8
+
9
+public class StringUtils {
10
+    /**
11
+     * string to byte[]
12
+     * */
13
+    public static byte[] strTobytes(String str){
14
+        byte[] b=null,data=null;
15
+        try {
16
+            b = str.getBytes("utf-8");
17
+            data=new String(b,"utf-8").getBytes("gbk");
18
+        } catch (UnsupportedEncodingException e) {
19
+            // TODO Auto-generated catch block
20
+            e.printStackTrace();
21
+        }
22
+        return data;
23
+    }
24
+    /**
25
+     * byte[] merger
26
+     * */
27
+    public static   byte[] byteMerger(byte[] byte_1, byte[] byte_2){
28
+        byte[] byte_3 = new byte[byte_1.length+byte_2.length];
29
+        System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
30
+        System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
31
+        return byte_3;
32
+    }
33
+    public static byte[] strTobytes(String str ,String charset){
34
+        byte[] b=null,data=null;
35
+        try {
36
+            b = str.getBytes("utf-8");
37
+            data=new String(b,"utf-8").getBytes(charset);
38
+        } catch (UnsupportedEncodingException e) {
39
+            // TODO Auto-generated catch block
40
+            e.printStackTrace();
41
+        }
42
+        return data;
43
+    }
44
+}

+ 67
- 0
index.js View File

@@ -0,0 +1,67 @@
1
+import React from 'react';
2
+import { NativeModules, AsyncStorage, Alert } from 'react-native';
3
+
4
+let RNXprinter = NativeModules.RNXprinter;
5
+let RNXNetprinter = NativeModules.RNXNetprinter;
6
+
7
+module.exports = {
8
+  initialize: async () => {
9
+    try{
10
+      let netAddress = await AsyncStorage.getItem('@ReactNativeXprinter:default_net_printer');
11
+      if(netAddress && netAddress != ""){
12
+        console.log('Get default printer:' + address);
13
+        await RNXNetprinter.connectPrinter(address);
14
+      }
15
+
16
+      let address = await AsyncStorage.getItem('@ReactNativeXprinter:default_printer');
17
+      let printerList = await RNXprinter.getDeviceList();
18
+      if(address && address != "" && printerList.find((printer) => { return printer.address == address})){
19
+        console.log('Get default printer:' + address);
20
+        await RNXprinter.selectDevice(address);
21
+      }
22
+    }
23
+    catch(err){
24
+      console.log('No default printer');
25
+    }
26
+  },
27
+  getDeviceList: RNXprinter.getDeviceList,
28
+  selectDevice: async (address) => {
29
+    await RNXprinter.selectDevice(address);
30
+    await AsyncStorage.setItem('@ReactNativeXprinter:default_printer', address);
31
+  },
32
+  connectPrinter: async (address) => {
33
+    await RNXNetprinter.connectPrinter(address);
34
+    await AsyncStorage.setItem('@ReactNativeXprinter:default_net_printer', address);
35
+  },
36
+  pickPrinter: async () => {
37
+    try{
38
+      let printerList = await RNXprinter.getDeviceList();
39
+      Alert.alert(
40
+        'Please pick one printer',
41
+        'If your printer not in this list, please go to bluetooth setting panel connect your device first',
42
+        printerList.map((printer) => {
43
+          return {
44
+            text: `${printer.name}(${printer.address})`,
45
+            onPress: async () => {
46
+              await RNXprinter.selectDevice(printer.address);
47
+              await AsyncStorage.setItem('@ReactNativeXprinter:default_printer', printer.address);
48
+            }
49
+          };
50
+        })
51
+      );
52
+    }
53
+    catch(error){
54
+      console.log(error);
55
+    }
56
+  },
57
+  pushText: RNXprinter.pushText,
58
+  pushFlashImage: RNXprinter.pushFlashImage,
59
+  pushCutPaper: RNXprinter.pushCutPaper,
60
+
61
+  netPushText: RNXNetprinter.pushText,
62
+  netPushImage: RNXNetprinter.printImage,
63
+  netPushCutPaper: RNXNetprinter.pushCutPaper,
64
+
65
+  print: RNXprinter.print,
66
+  printDemoPage: RNXprinter.printDemoPage,
67
+};

+ 5
- 0
ios/XprinterMirfalahtech.h View File

@@ -0,0 +1,5 @@
1
+#import <React/RCTBridgeModule.h>
2
+
3
+@interface XprinterMirfalahtech : NSObject <RCTBridgeModule>
4
+
5
+@end

+ 14
- 0
ios/XprinterMirfalahtech.m View File

@@ -0,0 +1,14 @@
1
+#import "XprinterMirfalahtech.h"
2
+
3
+
4
+@implementation XprinterMirfalahtech
5
+
6
+RCT_EXPORT_MODULE()
7
+
8
+RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback)
9
+{
10
+    // TODO: Implement some actually useful functionality
11
+    callback(@[[NSString stringWithFormat: @"numberArgument: %@ stringArgument: %@", numberArgument, stringArgument]]);
12
+}
13
+
14
+@end

+ 271
- 0
ios/XprinterMirfalahtech.xcodeproj/project.pbxproj View File

@@ -0,0 +1,271 @@
1
+// !$*UTF8*$!
2
+{
3
+	archiveVersion = 1;
4
+	classes = {
5
+	};
6
+	objectVersion = 46;
7
+	objects = {
8
+
9
+/* Begin PBXBuildFile section */
10
+		B3E7B58A1CC2AC0600A0062D /* XprinterMirfalahtech.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* XprinterMirfalahtech.m */; };
11
+/* End PBXBuildFile section */
12
+
13
+/* Begin PBXCopyFilesBuildPhase section */
14
+		58B511D91A9E6C8500147676 /* CopyFiles */ = {
15
+			isa = PBXCopyFilesBuildPhase;
16
+			buildActionMask = 2147483647;
17
+			dstPath = "include/$(PRODUCT_NAME)";
18
+			dstSubfolderSpec = 16;
19
+			files = (
20
+			);
21
+			runOnlyForDeploymentPostprocessing = 0;
22
+		};
23
+/* End PBXCopyFilesBuildPhase section */
24
+
25
+/* Begin PBXFileReference section */
26
+		134814201AA4EA6300B7C361 /* libXprinterMirfalahtech.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libXprinterMirfalahtech.a; sourceTree = BUILT_PRODUCTS_DIR; };
27
+		B3E7B5881CC2AC0600A0062D /* XprinterMirfalahtech.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XprinterMirfalahtech.h; sourceTree = "<group>"; };
28
+		B3E7B5891CC2AC0600A0062D /* XprinterMirfalahtech.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XprinterMirfalahtech.m; sourceTree = "<group>"; };
29
+/* End PBXFileReference section */
30
+
31
+/* Begin PBXFrameworksBuildPhase section */
32
+		58B511D81A9E6C8500147676 /* Frameworks */ = {
33
+			isa = PBXFrameworksBuildPhase;
34
+			buildActionMask = 2147483647;
35
+			files = (
36
+			);
37
+			runOnlyForDeploymentPostprocessing = 0;
38
+		};
39
+/* End PBXFrameworksBuildPhase section */
40
+
41
+/* Begin PBXGroup section */
42
+		134814211AA4EA7D00B7C361 /* Products */ = {
43
+			isa = PBXGroup;
44
+			children = (
45
+				134814201AA4EA6300B7C361 /* libXprinterMirfalahtech.a */,
46
+			);
47
+			name = Products;
48
+			sourceTree = "<group>";
49
+		};
50
+		58B511D21A9E6C8500147676 = {
51
+			isa = PBXGroup;
52
+			children = (
53
+				B3E7B5881CC2AC0600A0062D /* XprinterMirfalahtech.h */,
54
+				B3E7B5891CC2AC0600A0062D /* XprinterMirfalahtech.m */,
55
+				134814211AA4EA7D00B7C361 /* Products */,
56
+			);
57
+			sourceTree = "<group>";
58
+		};
59
+/* End PBXGroup section */
60
+
61
+/* Begin PBXNativeTarget section */
62
+		58B511DA1A9E6C8500147676 /* XprinterMirfalahtech */ = {
63
+			isa = PBXNativeTarget;
64
+			buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "XprinterMirfalahtech" */;
65
+			buildPhases = (
66
+				58B511D71A9E6C8500147676 /* Sources */,
67
+				58B511D81A9E6C8500147676 /* Frameworks */,
68
+				58B511D91A9E6C8500147676 /* CopyFiles */,
69
+			);
70
+			buildRules = (
71
+			);
72
+			dependencies = (
73
+			);
74
+			name = XprinterMirfalahtech;
75
+			productName = RCTDataManager;
76
+			productReference = 134814201AA4EA6300B7C361 /* libXprinterMirfalahtech.a */;
77
+			productType = "com.apple.product-type.library.static";
78
+		};
79
+/* End PBXNativeTarget section */
80
+
81
+/* Begin PBXProject section */
82
+		58B511D31A9E6C8500147676 /* Project object */ = {
83
+			isa = PBXProject;
84
+			attributes = {
85
+				LastUpgradeCheck = 0920;
86
+				ORGANIZATIONNAME = Facebook;
87
+				TargetAttributes = {
88
+					58B511DA1A9E6C8500147676 = {
89
+						CreatedOnToolsVersion = 6.1.1;
90
+					};
91
+				};
92
+			};
93
+			buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "XprinterMirfalahtech" */;
94
+			compatibilityVersion = "Xcode 3.2";
95
+			developmentRegion = English;
96
+			hasScannedForEncodings = 0;
97
+			knownRegions = (
98
+				en,
99
+			);
100
+			mainGroup = 58B511D21A9E6C8500147676;
101
+			productRefGroup = 58B511D21A9E6C8500147676;
102
+			projectDirPath = "";
103
+			projectRoot = "";
104
+			targets = (
105
+				58B511DA1A9E6C8500147676 /* XprinterMirfalahtech */,
106
+			);
107
+		};
108
+/* End PBXProject section */
109
+
110
+/* Begin PBXSourcesBuildPhase section */
111
+		58B511D71A9E6C8500147676 /* Sources */ = {
112
+			isa = PBXSourcesBuildPhase;
113
+			buildActionMask = 2147483647;
114
+			files = (
115
+				B3E7B58A1CC2AC0600A0062D /* XprinterMirfalahtech.m in Sources */,
116
+			);
117
+			runOnlyForDeploymentPostprocessing = 0;
118
+		};
119
+/* End PBXSourcesBuildPhase section */
120
+
121
+/* Begin XCBuildConfiguration section */
122
+		58B511ED1A9E6C8500147676 /* Debug */ = {
123
+			isa = XCBuildConfiguration;
124
+			buildSettings = {
125
+				ALWAYS_SEARCH_USER_PATHS = NO;
126
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
127
+				CLANG_CXX_LIBRARY = "libc++";
128
+				CLANG_ENABLE_MODULES = YES;
129
+				CLANG_ENABLE_OBJC_ARC = YES;
130
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
131
+				CLANG_WARN_BOOL_CONVERSION = YES;
132
+				CLANG_WARN_COMMA = YES;
133
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
134
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
135
+				CLANG_WARN_EMPTY_BODY = YES;
136
+				CLANG_WARN_ENUM_CONVERSION = YES;
137
+				CLANG_WARN_INFINITE_RECURSION = YES;
138
+				CLANG_WARN_INT_CONVERSION = YES;
139
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
140
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
141
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
142
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
143
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
144
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
145
+				CLANG_WARN_UNREACHABLE_CODE = YES;
146
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
147
+				COPY_PHASE_STRIP = NO;
148
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
149
+				ENABLE_TESTABILITY = YES;
150
+				GCC_C_LANGUAGE_STANDARD = gnu99;
151
+				GCC_DYNAMIC_NO_PIC = NO;
152
+				GCC_NO_COMMON_BLOCKS = YES;
153
+				GCC_OPTIMIZATION_LEVEL = 0;
154
+				GCC_PREPROCESSOR_DEFINITIONS = (
155
+					"DEBUG=1",
156
+					"$(inherited)",
157
+				);
158
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
159
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
160
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
161
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
162
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
163
+				GCC_WARN_UNUSED_FUNCTION = YES;
164
+				GCC_WARN_UNUSED_VARIABLE = YES;
165
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
166
+				MTL_ENABLE_DEBUG_INFO = YES;
167
+				ONLY_ACTIVE_ARCH = YES;
168
+				SDKROOT = iphoneos;
169
+			};
170
+			name = Debug;
171
+		};
172
+		58B511EE1A9E6C8500147676 /* Release */ = {
173
+			isa = XCBuildConfiguration;
174
+			buildSettings = {
175
+				ALWAYS_SEARCH_USER_PATHS = NO;
176
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
177
+				CLANG_CXX_LIBRARY = "libc++";
178
+				CLANG_ENABLE_MODULES = YES;
179
+				CLANG_ENABLE_OBJC_ARC = YES;
180
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
181
+				CLANG_WARN_BOOL_CONVERSION = YES;
182
+				CLANG_WARN_COMMA = YES;
183
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
184
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
185
+				CLANG_WARN_EMPTY_BODY = YES;
186
+				CLANG_WARN_ENUM_CONVERSION = YES;
187
+				CLANG_WARN_INFINITE_RECURSION = YES;
188
+				CLANG_WARN_INT_CONVERSION = YES;
189
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
190
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
191
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
192
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
193
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
194
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
195
+				CLANG_WARN_UNREACHABLE_CODE = YES;
196
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
197
+				COPY_PHASE_STRIP = YES;
198
+				ENABLE_NS_ASSERTIONS = NO;
199
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
200
+				GCC_C_LANGUAGE_STANDARD = gnu99;
201
+				GCC_NO_COMMON_BLOCKS = YES;
202
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
203
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
204
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
205
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
206
+				GCC_WARN_UNUSED_FUNCTION = YES;
207
+				GCC_WARN_UNUSED_VARIABLE = YES;
208
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
209
+				MTL_ENABLE_DEBUG_INFO = NO;
210
+				SDKROOT = iphoneos;
211
+				VALIDATE_PRODUCT = YES;
212
+			};
213
+			name = Release;
214
+		};
215
+		58B511F01A9E6C8500147676 /* Debug */ = {
216
+			isa = XCBuildConfiguration;
217
+			buildSettings = {
218
+				HEADER_SEARCH_PATHS = (
219
+				"$(inherited)",
220
+					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
221
+					"$(SRCROOT)/../../../React/**",
222
+					"$(SRCROOT)/../../react-native/React/**",
223
+				);
224
+				LIBRARY_SEARCH_PATHS = "$(inherited)";
225
+				OTHER_LDFLAGS = "-ObjC";
226
+				PRODUCT_NAME = XprinterMirfalahtech;
227
+				SKIP_INSTALL = YES;
228
+			};
229
+			name = Debug;
230
+		};
231
+		58B511F11A9E6C8500147676 /* Release */ = {
232
+			isa = XCBuildConfiguration;
233
+			buildSettings = {
234
+				HEADER_SEARCH_PATHS = (
235
+					"$(inherited)",
236
+					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
237
+					"$(SRCROOT)/../../../React/**",
238
+					"$(SRCROOT)/../../react-native/React/**",
239
+				);
240
+				LIBRARY_SEARCH_PATHS = "$(inherited)";
241
+				OTHER_LDFLAGS = "-ObjC";
242
+				PRODUCT_NAME = XprinterMirfalahtech;
243
+				SKIP_INSTALL = YES;
244
+			};
245
+			name = Release;
246
+		};
247
+/* End XCBuildConfiguration section */
248
+
249
+/* Begin XCConfigurationList section */
250
+		58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "XprinterMirfalahtech" */ = {
251
+			isa = XCConfigurationList;
252
+			buildConfigurations = (
253
+				58B511ED1A9E6C8500147676 /* Debug */,
254
+				58B511EE1A9E6C8500147676 /* Release */,
255
+			);
256
+			defaultConfigurationIsVisible = 0;
257
+			defaultConfigurationName = Release;
258
+		};
259
+		58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "XprinterMirfalahtech" */ = {
260
+			isa = XCConfigurationList;
261
+			buildConfigurations = (
262
+				58B511F01A9E6C8500147676 /* Debug */,
263
+				58B511F11A9E6C8500147676 /* Release */,
264
+			);
265
+			defaultConfigurationIsVisible = 0;
266
+			defaultConfigurationName = Release;
267
+		};
268
+/* End XCConfigurationList section */
269
+	};
270
+	rootObject = 58B511D31A9E6C8500147676 /* Project object */;
271
+}

+ 7
- 0
ios/XprinterMirfalahtech.xcworkspace/contents.xcworkspacedata View File

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<Workspace
3
+   version = "1.0">
4
+   <FileRef
5
+      location = "group:XprinterMirfalahtech.xcodeproj">
6
+   </FileRef>
7
+</Workspace>

+ 33
- 0
package.json View File

@@ -0,0 +1,33 @@
1
+{
2
+  "name": "react-native-xprinter-mirfalahtech",
3
+  "title": "React Native Xprinter Mirfalahtech",
4
+  "version": "1.0.11",
5
+  "description": "TODO",
6
+  "main": "index.js",
7
+  "scripts": {
8
+    "test": "echo \"Error: no test specified\" && exit 1"
9
+  },
10
+  "repository": {
11
+    "type": "git",
12
+    "url": "git+https://github.com/github_account/react-native-xprinter-mirfalahtech.git",
13
+    "baseUrl": "https://github.com/github_account/react-native-xprinter-mirfalahtech"
14
+  },
15
+  "keywords": [
16
+    "react-native"
17
+  ],
18
+  "author": {
19
+    "name": "Your Name",
20
+    "email": "yourname@email.com"
21
+  },
22
+  "license": "MIT",
23
+  "licenseFilename": "LICENSE",
24
+  "readmeFilename": "README.md",
25
+  "peerDependencies": {
26
+    "react": "^16.8.1",
27
+    "react-native": ">=0.59.0-rc.0 <1.0.x"
28
+  },
29
+  "devDependencies": {
30
+    "react": "^16.8.3",
31
+    "react-native": "^0.59.10"
32
+  }
33
+}

+ 26
- 0
react-native-xprinter-mirfalahtech.podspec View File

@@ -0,0 +1,26 @@
1
+require "json"
2
+
3
+package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+Pod::Spec.new do |s|
6
+  s.name         = "react-native-xprinter-mirfalahtech"
7
+  s.version      = package["version"]
8
+  s.summary      = package["description"]
9
+  s.description  = <<-DESC
10
+                  react-native-xprinter-mirfalahtech
11
+                   DESC
12
+  s.homepage     = "https://github.com/github_account/react-native-xprinter-mirfalahtech"
13
+  s.license      = "MIT"
14
+  # s.license    = { :type => "MIT", :file => "FILE_LICENSE" }
15
+  s.authors      = { "Your Name" => "yourname@email.com" }
16
+  s.platforms    = { :ios => "9.0" }
17
+  s.source       = { :git => "https://github.com/github_account/react-native-xprinter-mirfalahtech.git", :tag => "#{s.version}" }
18
+
19
+  s.source_files = "ios/**/*.{h,m,swift}"
20
+  s.requires_arc = true
21
+
22
+  s.dependency "React"
23
+  # ...
24
+  # s.dependency "..."
25
+end
26
+

+ 4541
- 0
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save