-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
225 lines (200 loc) · 5.5 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import { Constants, Camera, FileSystem, Permissions } from 'expo';
import React from 'react';
import { Button, StyleSheet, Text, View, TouchableOpacity, Slider, Vibration } from 'react-native';
import GalleryScreen from './GalleryScreen';
import isIPhoneX from 'react-native-is-iphonex';
import Clarifai from 'clarifai';
import { resolve } from 'url';
import Spinner from './Spinner';
process.nextTick = setImmediate;
const ClarifaiApp = new Clarifai.App({
apiKey: 'f4650648f3b1455fbdab7d06569a8268'
});
function updater(linkNamer){
return ClarifaiApp.models.predict("coiner app", {base64: linkNamer}).then(
function(response){
par1 = response['outputs'][0]['data']['concepts'][0];
console.log(par1);
return(par1);
});
}
export default class CameraScreen extends React.Component {
state = {
flash: 'off',
zoom: 0,
autoFocus: 'on',
depth: 0,
type: 'back',
whiteBalance: 'auto',
ratio: '16:9',
ratios: [],
photoId: 1,
showGallery: false,
photos: [],
faces: [],
permissionsGranted: false,
getAll: '',
loading: false,
success: null,
funda: false,
buttono: 'SNAP',
refresher: true,
fullo: true
};
async componentWillMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({ permissionsGranted: status === 'granted' });
}
componentDidMount() {
FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'photos').catch(e => {
console.log(e, 'Directory exists');
});
}
setFocusDepth(depth) {
this.setState({
depth,
});
}
takePicture = async function() {
this.setState({ loading: true })
if (this.camera) {
this.camera.takePictureAsync({ base64: true }).then(data => {
console.log('data: ', data.base64);
updater(data.base64).then(getAll => { this.setState({ getAll: getAll.name, getAll2: getAll.value })
this.setState({ loading: null })
});
});
}
}
loadMe(){
if (this.state.loading == true) {
return <Spinner size="small" />;
}
else if(this.state.loading == false || this.state.fullo == false){
return (<Text style={{fontSize: 22, marginLeft:5, marginRight: 5, textAlign: 'center'}}>Please take a close snap of your coin.</Text>);
}
else if(this.state.loading == null){
if(this.state.getAll2 > 0.8){
return (
<View>
<Text style={{fontSize: 22, marginLeft:5, marginRight: 5, textAlign: 'center'}}>We detected a rare {this.state.getAll} coin with an accuracy of '{this.state.getAll2*100}' </Text>
</View>
);
}
else{
return(
<View>
<Text style={{fontSize: 22, marginLeft:5, marginRight: 5, textAlign: 'center'}}> Sorry, but we didn't detect a rare coin. </Text>
</View>
);
}
}
}
renderNoPermissions() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', padding: 10 }}>
<Text style={{ color: 'white' }}>
Camera permissions not granted - cannot open camera preview.
</Text>
</View>
);
}
renderCamera() {
//const { getAll, getAll2 } = this.state;
//console.log(this.getCoinDetails);
return (
<Camera
ref={ref => {
this.camera = ref;
}}
style={{
flex: 1,
}}
>
<View
style={{
flex: 0.5,
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent: 'space-around',
paddingTop: Constants.statusBarHeight / 2,
}}>
</View>
<View
style={{
flex: 0.4,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
marginBottom: -5,
}}>
{this.loadMe()}
</View>
<View
style={{
flex: 0.1,
paddingBottom: isIPhoneX ? 20 : 0,
backgroundColor: 'transparent',
flexDirection: 'row',
alignSelf: 'flex-end',
}}>
<TouchableOpacity
style={[styles.flipButton, styles.picButton, { flex: 0.3, alignSelf: 'flex-end' }]}
onPress={this.takePicture.bind(this)}>
<Text style={styles.flipText}> {this.state.buttono} </Text>
</TouchableOpacity>
</View>
</Camera>
);
}
render() {
if(this.state.refresher){
const cameraScreenContent = this.state.permissionsGranted
? this.renderCamera()
: this.renderNoPermissions();
const content = this.state.showGallery ? this.renderGallery() : cameraScreenContent;
return <View key={this.state.refresher} style={styles.container}>{content}</View>;
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000',
},
navigation: {
flex: 1,
},
item: {
margin: 4,
backgroundColor: 'indianred',
height: 35,
width: 80,
borderRadius: 5,
alignItems: 'center',
justifyContent: 'center',
},
picButton: {
backgroundColor: 'darkseagreen',
},
row: {
flexDirection: 'row',
},
flipButton: {
flex: 0.3,
height: 40,
marginHorizontal: 2,
marginBottom: 10,
marginTop: 20,
borderRadius: 8,
borderColor: 'white',
borderWidth: 1,
padding: 5,
alignItems: 'center',
justifyContent: 'center',
},
flipText: {
color: 'white',
fontSize: 15,
}
});