Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
pill_minder
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Phuengton Chummuel
pill_minder
Commits
f5552942
Commit
f5552942
authored
Mar 22, 2018
by
Phuengton Chummuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new react-native-camera
parent
c2002370
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
139 deletions
+61
-139
CameraScreen.js
src/screens/CameraScreen.js
+61
-139
No files found.
src/screens/CameraScreen.js
View file @
f5552942
import
React
,
{
Component
}
from
'react'
;
import
React
,
{
Component
}
from
'react'
;
import
{
BackHandler
,
ToastAndroid
,
Alert
}
from
'react-native'
;
import
{
BackHandler
,
ToastAndroid
,
Alert
}
from
'react-native'
;
import
{
import
{
Dimensions
,
StyleSheet
,
StyleSheet
,
Text
,
Text
,
View
View
,
TouchableOpacity
}
from
'react-native'
;
}
from
'react-native'
;
import
{
IMAGE_TO_TEXT
}
from
'./../ServiceUrl'
import
{
Container
,
Header
,
Content
,
Icon
,
Button
}
from
'native-base'
;
import
{
Container
,
Header
,
Content
,
Icon
,
Button
}
from
'native-base'
;
import
{
MaterialDialog
}
from
'react-native-material-dialog'
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
{
scheduleLocalNotification
,
appointmentNotification
}
from
'./../Utils'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
import
realm
from
'./../Database/'
;
import
realm
from
'./../Database/'
;
...
@@ -40,170 +41,91 @@ class AppCamera extends Component {
...
@@ -40,170 +41,91 @@ class AppCamera extends Component {
render
()
{
render
()
{
return
(
return
(
<
Container
style
=
{
styles
.
container
}
>
<
Container
style
=
{
styles
.
container
}
>
<
Camera
<
RN
Camera
ref
=
{
(
cam
)
=>
{
ref
=
{
ref
=>
{
this
.
camera
=
cam
;
this
.
camera
=
ref
;
}}
}}
style
=
{
styles
.
preview
}
style
=
{
styles
.
preview
}
aspect
=
{
Camera
.
constants
.
Aspect
.
fill
}
type
=
{
RNCamera
.
Constants
.
Type
.
back
}
captureTarget
=
{
Camera
.
constants
.
CaptureTarget
.
temp
}
permissionDialogTitle
=
{
'Permission to use camera'
}
playSoundOnCapture
=
{
false
}
permissionDialogMessage
=
{
'We need your permission to use your camera phone'
}
onBarCodeRead
=
{(
data
,
type
)
=>
this
.
_onBarCodeRead
(
data
,
type
)}
/
>
defaultTouchToFocus
>
<
View
style
=
{{
flex
:
0
,
flexDirection
:
'row'
,
justifyContent
:
'center'
,
}}
>
<
TouchableOpacity
<
Button
onPress
=
{
this
.
takePicture
.
bind
(
this
)}
style
=
{
styles
.
capture
}
>
onPress
=
{
this
.
takePicture
.
bind
(
this
)}
<
Text
>
[
CAPTURE
]
<
/Text
>
style
=
{
styles
.
capture
}
<
/Button
>
>
<
/Camera
>
<
Text
style
=
{{
fontSize
:
14
}}
>
SNAP
<
/Text
>
<
/TouchableOpacity
>
<
/View
>
<
/Container
>
<
/Container
>
);
);
}
}
takePicture
()
{
takePicture
=
async
function
()
{
const
options
=
{};
if
(
this
.
camera
)
{
//options.location = ...
const
options
=
{
quality
:
0.5
,
base64
:
true
};
this
.
camera
.
capture
({
metadata
:
options
})
const
data
=
await
this
.
camera
.
takePictureAsync
(
options
)
.
then
((
data
)
=>
{
const
image
=
new
FormData
()
// ToastAndroid.show(data.path, ToastAndroid.SHORT);
image
.
append
(
'image'
,
{
this
.
props
.
navigation
.
navigate
(
"PreviewPhoto"
,
{
photo
:
data
})
uri
:
data
.
uri
,
})
type
:
'imge/jpeg'
,
.
catch
(
err
=>
console
.
error
(
err
));
name
:
'image'
}
_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
()
})
})
})
this
.
props
.
navigation
.
goBack
(
null
)
fetch
(
IMAGE_TO_TEXT
,
{
}
method
:
'post'
,
},
body
:
image
],
}).
then
(
res
=>
{
{
cancelable
:
false
}
ToastAndroid
.
show
(
JSON
.
stringify
(
res
.
body
.
closeMatches
),
ToastAndroid
.
LONG
)
)
}).
catch
(
err
=>
{
}
ToastAndroid
.
show
(
JSON
.
stringify
(
err
),
ToastAndroid
.
LONG
)
_addAppointment
(
data
)
{
const
time
=
data
.
date
.
split
(
':'
)
Alert
.
alert
(
'Confirm'
,
"Doctor: "
+
data
.
doctorName
+
"
\n
Date: "
+
moment
(
data
.
date
).
format
(
"DD MMM YYYY"
)
+
"
\n
Time: "
+
moment
(
data
.
date
).
format
(
"HH:mm"
)
+
"
\n
Place: "
+
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
()
})
})
})
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
({
const
styles
=
StyleSheet
.
create
({
container
:
{
container
:
{
flex
:
1
,
flex
:
1
,
flexDirection
:
'row'
,
flexDirection
:
'column'
,
backgroundColor
:
'black'
},
},
preview
:
{
preview
:
{
flex
:
1
,
flex
:
1
,
justifyContent
:
'flex-end'
,
justifyContent
:
'flex-end'
,
alignItems
:
'center'
},
},
capture
:
{
capture
:
{
flex
:
0
,
flex
:
0
,
backgroundColor
:
'#fff'
,
backgroundColor
:
'#fff'
,
borderRadius
:
5
,
borderRadius
:
5
,
padding
:
1
0
,
padding
:
1
5
,
margin
:
4
0
,
paddingHorizontal
:
2
0
,
align
Items
:
'center'
,
align
Self
:
'center'
,
alignSelf
:
'center'
margin
:
20
}
}
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment