Commit 23fb75a0 authored by Phuengton Chummuel's avatar Phuengton Chummuel

Merge branch 'newCamera' into 'develop'

New camera

See merge request !1
parents 98a82f75 5da048dc
......@@ -7,13 +7,13 @@ import io.realm.react.RealmReactPackage;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import co.apptailor.googlesignin.RNGoogleSigninPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.lwansbrough.RCTCamera.RCTCameraPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.auth.RNFirebaseAuthPackage;
import org.reactnative.camera.RNCameraPackage;
import java.util.Arrays;
import java.util.List;
......@@ -34,9 +34,9 @@ public class MainApplication extends Application implements ReactApplication {
new ReactNativePushNotificationPackage(),
new RNGoogleSigninPackage(),
new VectorIconsPackage(),
new RCTCameraPackage(),
new RNFirebasePackage(),
new RNFirebaseAuthPackage()
new RNFirebaseAuthPackage(),
new RNCameraPackage()
);
}
......
......@@ -24,5 +24,8 @@ allprojects {
maven {
url 'https://maven.google.com'
}
maven {
url "https://jitpack.io"
}
}
}
......@@ -60,6 +60,7 @@
927EF671A5C4448E994607B0 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5E9F027A7DD4E43BE07B2BF /* AddressBook.framework */; };
E171D72366A84D4F895C1793 /* libRealmReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3810037A43F84AEF8BE2AEDF /* libRealmReact.a */; };
3E4551D5ECD34C78B5CA9466 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 83B233663AAC4D56B48CE593 /* libc++.tbd */; };
EC83982BEE5B40FE8C6A1CBF /* libRNCamera.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E75D49961054457590A5CFEF /* libRNCamera.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -316,6 +317,8 @@
2E3477DB564D4B6CB4679C62 /* RealmReact.xcodeproj */ = {isa = PBXFileReference; name = "RealmReact.xcodeproj"; path = "../node_modules/realm/react-native/ios/RealmReact.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
3810037A43F84AEF8BE2AEDF /* libRealmReact.a */ = {isa = PBXFileReference; name = "libRealmReact.a"; path = "libRealmReact.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
83B233663AAC4D56B48CE593 /* libc++.tbd */ = {isa = PBXFileReference; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; fileEncoding = undefined; lastKnownFileType = sourcecode.text-based-dylib-definition; explicitFileType = undefined; includeInIndex = 0; };
8984A4BE9AA646DFA3628D48 /* RNCamera.xcodeproj */ = {isa = PBXFileReference; name = "RNCamera.xcodeproj"; path = "../node_modules/react-native-camera/ios/RNCamera.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
E75D49961054457590A5CFEF /* libRNCamera.a */ = {isa = PBXFileReference; name = "libRNCamera.a"; path = "libRNCamera.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -354,6 +357,7 @@
927EF671A5C4448E994607B0 /* AddressBook.framework in Frameworks */,
E171D72366A84D4F895C1793 /* libRealmReact.a in Frameworks */,
3E4551D5ECD34C78B5CA9466 /* libc++.tbd in Frameworks */,
EC83982BEE5B40FE8C6A1CBF /* libRNCamera.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -527,6 +531,7 @@
FDB8C3D7010E4DB486612DDA /* RNFirebase.xcodeproj */,
8DBECF570FB04728BF3A6D66 /* RNGoogleSignin.xcodeproj */,
2E3477DB564D4B6CB4679C62 /* RealmReact.xcodeproj */,
8984A4BE9AA646DFA3628D48 /* RNCamera.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
......@@ -1130,6 +1135,7 @@
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
......@@ -1138,6 +1144,7 @@
"$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**",
"$(SRCROOT)/../node_modules/react-native-google-signin/ios/RNGoogleSignin/**",
"$(SRCROOT)/../node_modules/realm/src/**",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
);
};
name = Debug;
......@@ -1163,6 +1170,7 @@
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
......@@ -1171,6 +1179,7 @@
"$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**",
"$(SRCROOT)/../node_modules/react-native-google-signin/ios/RNGoogleSignin/**",
"$(SRCROOT)/../node_modules/realm/src/**",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
);
};
name = Release;
......@@ -1197,6 +1206,7 @@
"$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**",
"$(SRCROOT)/../node_modules/react-native-google-signin/ios/RNGoogleSignin/**",
"$(SRCROOT)/../node_modules/realm/src/**",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
);
};
name = Debug;
......@@ -1222,6 +1232,7 @@
"$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**",
"$(SRCROOT)/../node_modules/react-native-google-signin/ios/RNGoogleSignin/**",
"$(SRCROOT)/../node_modules/realm/src/**",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
);
};
name = Release;
......@@ -1256,6 +1267,7 @@
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
......@@ -1264,6 +1276,7 @@
"$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**",
"$(SRCROOT)/../node_modules/react-native-google-signin/ios/RNGoogleSignin/**",
"$(SRCROOT)/../node_modules/realm/src/**",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
);
};
name = Debug;
......@@ -1298,6 +1311,7 @@
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
......@@ -1306,6 +1320,7 @@
"$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**",
"$(SRCROOT)/../node_modules/react-native-google-signin/ios/RNGoogleSignin/**",
"$(SRCROOT)/../node_modules/realm/src/**",
"$(SRCROOT)/../node_modules/react-native-camera/ios/**",
);
};
name = Release;
......@@ -1335,6 +1350,7 @@
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
};
name = Debug;
......@@ -1364,6 +1380,7 @@
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
};
name = Release;
......
......@@ -7242,11 +7242,19 @@
}
},
"react-native-camera": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/react-native-camera/-/react-native-camera-0.12.0.tgz",
"integrity": "sha512-Ja0/cfiaE/p8qbNpvRu/r6gaJqpXsZyVWO0g8s3yrdC/JgyMMMrzemGmptSCdkYvrfuEN8pga94O+a07uD4i3w==",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/react-native-camera/-/react-native-camera-1.0.2.tgz",
"integrity": "sha1-SQ51sUGWrw7JcqdZu2AnaTrUqtY=",
"requires": {
"lodash": "4.17.5",
"prop-types": "15.6.0"
},
"dependencies": {
"lodash": {
"version": "4.17.5",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="
}
}
},
"react-native-datepicker": {
......
......@@ -11,7 +11,7 @@
"native-base": "^2.3.3",
"react": "16.0.0",
"react-native": "0.50.3",
"react-native-camera": "^0.12.0",
"react-native-camera": "^1.0.2",
"react-native-datepicker": "^1.6.0",
"react-native-firebase": "^3.1.0",
"react-native-google-signin": "^0.12.0",
......
export const MAIN_HOST = 'http://192.168.1.7:8000';
export const IMAGE_TO_TEXT = MAIN_HOST + '/uploadimg'
\ No newline at end of file
import React, { Component } from 'react';
import { BackHandler, ToastAndroid, Alert } from 'react-native';
import {
Dimensions,
StyleSheet,
Text,
View
View,
TouchableOpacity
} from 'react-native';
import { IMAGE_TO_TEXT } from './../ServiceUrl'
import { Container, Header, Content, Icon, Button } from 'native-base';
import { MaterialDialog } from 'react-native-material-dialog'
import Camera from 'react-native-camera';
import { RNCamera } from 'react-native-camera'
import { scheduleLocalNotification, appointmentNotification } from './../Utils';
import moment from 'moment';
import realm from './../Database/';
......@@ -40,170 +41,91 @@ class AppCamera extends Component {
render() {
return (
<Container style={styles.container}>
<Camera
ref={(cam) => {
this.camera = cam;
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
captureTarget={Camera.constants.CaptureTarget.temp}
playSoundOnCapture={false}
onBarCodeRead={(data, type) => this._onBarCodeRead(data, type)}
defaultTouchToFocus>
<Button onPress={this.takePicture.bind(this)} style={styles.capture}>
<Text>[CAPTURE]</Text>
</Button>
</Camera>
type={RNCamera.Constants.Type.back}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'We need your permission to use your camera phone'}
/>
<View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center', }}>
<TouchableOpacity
onPress={this.takePicture.bind(this)}
style={styles.capture}
>
<Text style={{ fontSize: 14 }}> SNAP </Text>
</TouchableOpacity>
</View>
</Container >
);
}
takePicture() {
const options = {};
//options.location = ...
this.camera.capture({ metadata: options })
.then((data) => {
// ToastAndroid.show(data.path, ToastAndroid.SHORT);
this.props.navigation.navigate("PreviewPhoto", { photo: data })
})
.catch(err => console.error(err));
}
_onBarCodeRead(data, type) {
if (data.type == 'QR_CODE') {
var tmpData = JSON.parse(decodeURI(data.data))
switch (tmpData.type) {
case "medicine":
if (this.state.addItemVisible) {
this._addMedicine(tmpData)
this.setState({ addItemVisible: false })
}
break;
case "appointment":
if (this.state.addItemVisible) {
this._addAppointment(tmpData)
this.setState({ addItemVisible: false })
}
break;
}
}
}
_addMedicine(data) {
var time = null
switch (data.period) {
case 1:
time = this.state.morningTime.split(":")
break;
case 2:
time = this.state.afternoonTime.split(":")
break;
case 3:
time = this.state.eveningTime.split(":")
break;
case 4:
time = this.state.nightTime.split(":")
break;
}
var timePeriod = data.period == 1 ? 'เช้า' : data.period == 2 ? 'กลางวัน' : data.period == 3 ? 'เย็น' : 'ค่ำ';
var beforeMeal = data.beforeMeal ? "\tก่อนอาหาร" : "\tหลังอาหาร";
Alert.alert(
'Confirm',
'ชื่อยา: ' + data.medName + '\nก่อน/หลัง อาหาร: ' + beforeMeal + '\nช่วงเวลา: ' + timePeriod + '\nจำนวน: ' + data.dose,
[
{ text: 'CANCLE', onPress: () => this.setState({ addItemVisible: true }) },
{
text: 'OK', onPress: () => {
var id = Math.random() * 10000
var reminderDate = moment().hour(time[0]).minute(time[1]).second(0).toDate()
var msg = "แจ้งเตือนกินยา\n" + "เวลา: " + time[0] + ":" + time[1] + "\nยา: " + data.medName + beforeMeal;
scheduleLocalNotification(msg, reminderDate, id)
realm.write(() => {
realm.create('Reminder', {
id: id,
medName: data.medName,
reminderTime: reminderDate,
meal: beforeMeal.trim(),
period: data.period,
dose: data.dose.toString(),
timeStamp: moment().toDate()
})
takePicture = async function () {
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options)
const image = new FormData()
image.append('image', {
uri: data.uri,
type: 'imge/jpeg',
name: 'image'
})
this.props.navigation.goBack(null)
}
},
],
{ cancelable: false }
)
}
_addAppointment(data) {
const time = data.date.split(':')
Alert.alert(
'Confirm',
"Doctor: " + data.doctorName + "\nDate: " + moment(data.date).format("DD MMM YYYY") + "\nTime: " + moment(data.date).format("HH:mm") + "\nPlace: " + data.place,
[
{ text: 'CANCLE', onPress: () => this.setState({ addItemVisible: true }) },
{
text: 'OK', onPress: () => {
var id = Math.random() * 10000
var appointmentDate = moment(data.date).hour(time[0]).minute(time[1]).second(0).toDate()
var msg = "แจ้งเตือนการนัดพบแพทย์\n" + "แพทย์: " + data.doctorName + "เวลา: " + moment(data.date).format("HH:mm")
appointmentNotification(msg, appointmentDate, id)
realm.write(() => {
realm.create('Appointments', {
id: id,
doctorName: data.doctorName,
date: appointmentDate,
place: data.place,
timeStamp: moment().toDate()
})
fetch(IMAGE_TO_TEXT, {
method: 'post',
body: image
}).then(res => {
ToastAndroid.show(JSON.stringify(res.body.closeMatches), ToastAndroid.LONG)
}).catch(err => {
ToastAndroid.show(JSON.stringify(err), ToastAndroid.LONG)
})
this.props.navigation.goBack(null)
}
},
],
{ cancelable: false }
)
}
// _onBarCodeRead(data, type) {
// if (data.type == 'QR_CODE') {
// var tmpData = JSON.parse(decodeURI(data.data))
// switch (tmpData.type) {
// case "medicine":
// if (this.state.addItemVisible) {
// this._addMedicine(tmpData)
// this.setState({ addItemVisible: false })
// }
// break;
// case "appointment":
// if (this.state.addItemVisible) {
// this._addAppointment(tmpData)
// this.setState({ addItemVisible: false })
// }
// break;
// }
// }
// }
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
flexDirection: 'column',
backgroundColor: 'black'
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
},
capture: {
flex: 0,
backgroundColor: '#fff',
borderRadius: 5,
padding: 10,
margin: 40,
alignItems: 'center',
alignSelf: 'center'
padding: 15,
paddingHorizontal: 20,
alignSelf: 'center',
margin: 20
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment