diff --git a/Camera.js b/Camera.js new file mode 100644 index 00000000..79585db3 --- /dev/null +++ b/Camera.js @@ -0,0 +1,143 @@ +'use strict'; +import React, { PureComponent } from 'react'; +import { StyleSheet, Text, TouchableOpacity, View, PermissionsAndroid } from 'react-native'; +import { IconButton, Colors, Avatar } from 'react-native-paper'; +import CameraRoll from "@react-native-community/cameraroll"; +import { RNCamera } from 'react-native-camera'; +import { withNavigationFocus } from 'react-navigation'; +import { CheckConnectivity } from './InternetCheck'; +//import React, { Component } from "react"; +//import { View, Text, Button, Alert, NetInfo, Platform } from "react-native"; +//import { firebase } from '@react-native-firebase/ml-vision'; + +class Camera extends PureComponent { + + constructor(props) { + super(props) + this.state = { + flashOn: false, + cameraPermission: false + } + } + + componentDidMount() { + } + + sendData = () => { + this.props.parentCallback([this.state.snaped, this.state.dataUri]); + } + + + + render() { + const { isFocused } = this.props + const { hasCameraPermission } = this.state; + console.log(hasCameraPermission) + if (hasCameraPermission === null) { + return ; + } else if (hasCameraPermission === false) { + return No access to camera; + } else if (isFocused) { + return ( + + { + this.camera = ref; + }} + style={styles.preview} + type={RNCamera.Constants.Type.back} + flashMode={this.state.flashOn ? RNCamera.Constants.FlashMode.on : RNCamera.Constants.FlashMode.off} + androidCameraPermissionOptions={{ + title: 'Permission to use camera', + message: 'We need your permission to use your camera', + buttonPositive: 'Ok', + buttonNegative: 'Cancel', + }} + captureAudio={false} + playSoundOnCapture={true} + // onGoogleVisionBarcodesDetected={({ barcodes }) => { + // console.log(barcodes); + // }} + // onFacesDetected={(face)=>{ + // console.log(face); + // }} + // onTextRecognized={(text)=>{ + // console.log(text); + // }} + > + this.setState({ flashOn: !this.state.flashOn })} + + > + + + + + this.takePicture()} //check internet also at this point + animated={true} + style={{ backgroundColor: "grey" }} + /> + + + ); + } else { + return ; + } + } + + takePicture = async () => { + if (this.camera.state.isAuthorized) { + const options = { quality: 0.5, base64: true }; + const data = await this.camera.takePictureAsync(options); + try { + const granted = await PermissionsAndroid.request( + PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, + ); + if (granted === PermissionsAndroid.RESULTS.GRANTED) { + CameraRoll.saveToCameraRoll(data.uri); + this.setState({ + snaped: true, + dataUri: data.uri + }) + CheckConnectivity(data.uri) + this.sendData() + + } else { + await PermissionsAndroid.request( + PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, + ); + } + } catch (err) { + return false + } + } + }; +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: 'white', + height: "100%", + width: "100%" + + }, + preview: { + justifyContent: 'flex-start', + height: "70%", + width: "100%" + }, + bottom: { + flex: 1, + justifyContent: 'flex-end', + alignItems: 'center', + marginBottom: 10 + }, +}); + +export default withNavigationFocus(Camera); \ No newline at end of file diff --git a/InternetCheck.js b/InternetCheck.js new file mode 100644 index 00000000..b956df9e --- /dev/null +++ b/InternetCheck.js @@ -0,0 +1,64 @@ +import React, { Component } from "react"; +import { View, Text, Button, Alert, NetInfo, Platform } from "react-native"; +import { firebase } from '@react-native-firebase/ml-vision'; + +export default class InternetCheck extends Component { + constructor(props) { + super(props); + this.state = {}; + } + + CheckConnectivity = async(filePath) => { + // For Android devices + if (Platform.OS === "android") { + NetInfo.isConnected.fetch().then(isConnected => { + if (isConnected) { //Cloud image labeling + const labels = await firebase.vision().cloudImageLabelerProcessImage(filePath, { + confidenceThreshold: 0.8, //Returns an array of results with the predicted name(text), entity ID(if available),confidence level + }); + console.log(labels); + + //Alert.alert("You are online!"); //imageLabel-Cloud + } else { //imageLabel-Local + const labels = await firebase.vision().imageLabelerProcessImage(filePath, { + confidenceThreshold: 0.8, + }); + console.log(labels); + // Alert.alert("You are offline!"); + } + }); + } else { + // For iOS devices + NetInfo.isConnected.addEventListener( + "connectionChange", + this.handleFirstConnectivityChange + ); + } + }; + + handleFirstConnectivityChange = isConnected => { + NetInfo.isConnected.removeEventListener( + "connectionChange", + this.handleFirstConnectivityChange + ); + + if (isConnected === false) { + Alert.alert("You are offline!"); //ImageLabel-Local + } else { + Alert.alert("You are online!"); //ImageLabel-Cloud + } + }; + + /*render() { + return ( + +