-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2537 from kaloudis/zeus-modules-react-native-qrco…
…de-local-image deps: pull react-native-qrcode-local-image into zeus_modules
- Loading branch information
Showing
20 changed files
with
783 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
zeus_modules/@remobile/react-native-qrcode-local-image/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.[aod] | ||
*.DS_Store | ||
.DS_Store | ||
*Thumbs.db | ||
*.iml | ||
.gradle | ||
.idea | ||
node_modules | ||
npm-debug.log | ||
/android/build | ||
/ios/**/*xcuserdata* | ||
/ios/**/*xcshareddata* |
12 changes: 12 additions & 0 deletions
12
zeus_modules/@remobile/react-native-qrcode-local-image/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.DS_Store | ||
.DS_Store | ||
*Thumbs.db | ||
.gradle | ||
.idea | ||
*.iml | ||
npm-debug.log | ||
node_modules | ||
/android/build | ||
/ios/**/*xcuserdata* | ||
/ios/**/*xcshareddata* | ||
|
22 changes: 22 additions & 0 deletions
22
zeus_modules/@remobile/react-native-qrcode-local-image/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(The MIT License) | ||
|
||
Copyright (c) 2015-2016 YunJiang.Fang <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
102 changes: 102 additions & 0 deletions
102
zeus_modules/@remobile/react-native-qrcode-local-image/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# React Native QRCodeLocalImage (remobile) | ||
A local qrcode image parse for react-native, support for ios and android | ||
|
||
## Installation | ||
```sh | ||
npm install @remobile/react-native-qrcode-local-image --save | ||
``` | ||
### Installation (iOS) | ||
* Drag RCTQRCodeLocalImage.xcodeproj to your project on Xcode. | ||
* Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag libRCTQRCodeLocalImage.a from the Products folder inside the RCTQRCodeLocalImage.xcodeproj. | ||
* Look for Header Search Paths and make sure it contains $(SRCROOT)/../../../react-native/React as recursive. | ||
|
||
### Installation (Android) | ||
```gradle | ||
... | ||
include ':react-native-qrcode-local-image' | ||
project(':react-native-qrcode-local-image').projectDir = new File(settingsDir, '../node_modules/@remobile/react-native-qrcode-local-image/android') | ||
``` | ||
|
||
* In `android/app/build.gradle` | ||
|
||
```gradle | ||
... | ||
dependencies { | ||
... | ||
compile project(':react-native-qrcode-local-image') | ||
} | ||
``` | ||
|
||
* register module (in MainApplication.java) | ||
|
||
```java | ||
...... | ||
import com.remobile.qrcodeLocalImage.RCTQRCodeLocalImagePackage; // <--- import | ||
|
||
...... | ||
|
||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
...... | ||
new RCTQRCodeLocalImagePackage() // <------ add here | ||
...... | ||
} | ||
|
||
``` | ||
|
||
## Usage | ||
|
||
### Example | ||
```js | ||
'use strict'; | ||
|
||
var React = require('react'); | ||
var ReactNative = require('react-native'); | ||
var { | ||
StyleSheet, | ||
View, | ||
Text, | ||
} = ReactNative; | ||
|
||
var Button = require('@remobile/react-native-simple-button'); | ||
var QRCode = require('@remobile/react-native-qrcode-local-image'); | ||
|
||
|
||
module.exports = React.createClass({ | ||
getInitialState() { | ||
return {text: ''} | ||
}, | ||
onPress() { | ||
QRCode.decode(!app.isandroid?'/Users/fang/Desktop/qr.png':'/sdcard/qr.png', (error, result)=>{ | ||
this.setState({text: JSON.stringify({error, result})}); | ||
}); | ||
}, | ||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<Button onPress={this.onPress}>测试</Button> | ||
<Text> | ||
{this.state.text} | ||
</Text> | ||
</View> | ||
); | ||
} | ||
}); | ||
|
||
|
||
var styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: 'transparent', | ||
justifyContent: 'space-around', | ||
paddingVertical: 150, | ||
}, | ||
}); | ||
``` | ||
|
||
### method | ||
- `decode(path, callback)` path canbe local image or url | ||
|
||
|
||
### see detail use | ||
* https://github.com/remobile/react-native-template |
26 changes: 26 additions & 0 deletions
26
zeus_modules/@remobile/react-native-qrcode-local-image/android/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.get('compileSdkVersion') | ||
buildToolsVersion rootProject.ext.get('buildToolsVersion') | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion rootProject.ext.get('targetSdkVersion') | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:23.0.1' | ||
implementation 'com.facebook.react:react-native:+' | ||
implementation 'com.google.zxing:core:3.2.0' | ||
} |
3 changes: 3 additions & 0 deletions
3
zeus_modules/@remobile/react-native-qrcode-local-image/android/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.remobile.qrcodeLocalImage"> | ||
</manifest> |
120 changes: 120 additions & 0 deletions
120
...-local-image/android/src/main/java/com/remobile/qrcodeLocalImage/RCTQRCodeLocalImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.remobile.qrcodeLocalImage; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.net.Uri; | ||
import android.util.Base64; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.Callback; | ||
import com.google.zxing.BinaryBitmap; | ||
import com.google.zxing.DecodeHintType; | ||
import com.google.zxing.RGBLuminanceSource; | ||
import com.google.zxing.Result; | ||
import com.google.zxing.common.HybridBinarizer; | ||
import com.google.zxing.qrcode.QRCodeReader; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.Hashtable; | ||
|
||
|
||
public class RCTQRCodeLocalImage extends ReactContextBaseJavaModule { | ||
|
||
private Context context; | ||
|
||
public RCTQRCodeLocalImage(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "RCTQRCodeLocalImage"; | ||
} | ||
|
||
@ReactMethod | ||
public void decode(String path, Callback callback) { | ||
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>(); | ||
hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码 | ||
BitmapFactory.Options options = new BitmapFactory.Options(); | ||
options.inSampleSize = 4; | ||
options.inPreferredConfig = Bitmap.Config.RGB_565; | ||
options.inPurgeable = true; | ||
|
||
Bitmap scanBitmap = null; | ||
if (path.startsWith("http://")||path.startsWith("https://")) { | ||
scanBitmap = getbitmap(path); | ||
} else if (path.startsWith("content://")) { | ||
try { | ||
final Uri imagePath = Uri.parse(path.replace("file://", "").replace("file:/", "")); | ||
InputStream inputStream = this.context.getContentResolver().openInputStream(imagePath); | ||
if (inputStream != null) { | ||
scanBitmap = BitmapFactory.decodeStream(inputStream, null, options); | ||
inputStream.close(); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
scanBitmap = null; | ||
} | ||
} else if (path.startsWith("base64://")) { | ||
try { | ||
byte[] decodedBytes = Base64.decode(path.replace("base64://", ""), 0); | ||
scanBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
scanBitmap = null; | ||
} | ||
} else { | ||
scanBitmap = BitmapFactory.decodeFile(path.replace("file://", ""), options); | ||
} | ||
|
||
if (scanBitmap == null) { | ||
callback.invoke("cannot load image"); | ||
return; | ||
} | ||
|
||
int[] intArray = new int[scanBitmap.getWidth()*scanBitmap.getHeight()]; | ||
scanBitmap.getPixels(intArray, 0, scanBitmap.getWidth(), 0, 0, scanBitmap.getWidth(), scanBitmap.getHeight()); | ||
|
||
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap.getWidth(), scanBitmap.getHeight(), intArray); | ||
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); | ||
QRCodeReader reader = new QRCodeReader(); | ||
try { | ||
Result result = reader.decode(bitmap, hints); | ||
if (result == null) { | ||
callback.invoke("image format error"); | ||
} else { | ||
callback.invoke(null, result.toString()); | ||
} | ||
|
||
} catch (Exception e) { | ||
callback.invoke("decode error"); | ||
} | ||
} | ||
|
||
public static Bitmap getbitmap(String imageUri) { | ||
Bitmap bitmap = null; | ||
try { | ||
URL myFileUrl = new URL(imageUri); | ||
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection(); | ||
conn.setDoInput(true); | ||
conn.connect(); | ||
InputStream is = conn.getInputStream(); | ||
bitmap = BitmapFactory.decodeStream(is); | ||
is.close(); | ||
} catch (OutOfMemoryError e) { | ||
e.printStackTrace(); | ||
bitmap = null; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
bitmap = null; | ||
} | ||
return bitmap; | ||
} | ||
} |
Oops, something went wrong.