@@ -19,7 +19,7 @@ export var takePicture = function (options?): Promise<any> {
19
19
20
20
let types : typeof typesModule = require ( "utils/types" ) ;
21
21
let utils : typeof utilsModule = require ( "utils/utils" ) ;
22
-
22
+
23
23
let saveToGallery ;
24
24
let reqWidth ;
25
25
let reqHeight ;
@@ -39,7 +39,7 @@ export var takePicture = function (options?): Promise<any> {
39
39
40
40
let takePictureIntent = new android . content . Intent ( android . provider . MediaStore . ACTION_IMAGE_CAPTURE ) ;
41
41
let dateStamp = createDateTimeStamp ( ) ;
42
-
42
+
43
43
let picturePath : string ;
44
44
let nativeFile ;
45
45
let tempPictureUri ;
@@ -52,38 +52,38 @@ export var takePicture = function (options?): Promise<any> {
52
52
picturePath = utils . ad . getApplicationContext ( ) . getExternalFilesDir ( null ) . getAbsolutePath ( ) + "/" + "NSIMG_" + dateStamp + ".jpg" ;
53
53
nativeFile = new java . io . File ( picturePath ) ;
54
54
}
55
-
55
+
56
56
let sdkVersionInt = parseInt ( platform . device . sdkVersion ) ;
57
57
if ( sdkVersionInt >= 21 ) {
58
58
tempPictureUri = ( < any > android . support . v4 . content ) . FileProvider . getUriForFile ( applicationModule . android . currentContext , applicationModule . android . nativeApp . getPackageName ( ) + ".provider" , nativeFile ) ;
59
59
}
60
60
else {
61
61
tempPictureUri = android . net . Uri . fromFile ( nativeFile ) ;
62
62
}
63
-
63
+
64
64
takePictureIntent . putExtra ( android . provider . MediaStore . EXTRA_OUTPUT , tempPictureUri ) ;
65
65
66
66
if ( takePictureIntent . resolveActivity ( utils . ad . getApplicationContext ( ) . getPackageManager ( ) ) != null ) {
67
67
68
68
let appModule : typeof applicationModule = require ( "application" ) ;
69
69
70
- let previousResult = appModule . android . onActivityResult ;
71
- appModule . android . onActivityResult = ( requestCode : number , resultCode : number , data : android . content . Intent ) => {
72
- appModule . android . onActivityResult = previousResult ;
70
+ appModule . android . on ( "activityResult" , ( args ) => {
71
+ const requestCode = args . requestCode ;
72
+ const resultCode = args . resultCode ;
73
73
74
74
if ( requestCode === REQUEST_IMAGE_CAPTURE && resultCode === android . app . Activity . RESULT_OK ) {
75
75
if ( saveToGallery ) {
76
76
try {
77
77
let callback = new android . media . MediaScannerConnection . OnScanCompletedListener ( {
78
- onScanCompleted : function ( path , uri ) {
79
- if ( trace . enabled ) {
78
+ onScanCompleted : function ( path , uri ) {
79
+ if ( trace . isEnabled ( ) ) {
80
80
trace . write ( `image from path ${ path } has been successfully scanned!` , trace . categories . Debug ) ;
81
81
}
82
82
}
83
83
} ) ;
84
84
android . media . MediaScannerConnection . scanFile ( appModule . android . context , [ picturePath ] , null , callback ) ;
85
85
} catch ( ex ) {
86
- if ( trace . enabled ) {
86
+ if ( trace . isEnabled ( ) ) {
87
87
trace . write ( `An error occurred while scanning file ${ picturePath } : ${ ex . message } !` , trace . categories . Debug ) ;
88
88
}
89
89
}
@@ -97,7 +97,7 @@ export var takePicture = function (options?): Promise<any> {
97
97
} ;
98
98
resolve ( asset ) ;
99
99
}
100
- } ;
100
+ } ) ;
101
101
102
102
appModule . android . foregroundActivity . startActivityForResult ( takePictureIntent , REQUEST_IMAGE_CAPTURE ) ;
103
103
@@ -112,7 +112,7 @@ export var takePicture = function (options?): Promise<any> {
112
112
113
113
export var isAvailable = function ( ) {
114
114
var utils : typeof utilsModule = require ( "utils/utils" ) ;
115
-
115
+
116
116
return utils . ad . getApplicationContext ( ) . getPackageManager ( ) . hasSystemFeature ( android . content . pm . PackageManager . FEATURE_CAMERA )
117
117
}
118
118
@@ -126,11 +126,11 @@ export var requestPermissions = function () {
126
126
var createDateTimeStamp = function ( ) {
127
127
let result = "" ;
128
128
let date = new Date ( ) ;
129
- result = date . getFullYear ( ) . toString ( ) +
130
- ( ( date . getMonth ( ) + 1 ) < 10 ? "0" + ( date . getMonth ( ) + 1 ) . toString ( ) : ( date . getMonth ( ) + 1 ) . toString ( ) ) +
131
- ( date . getDate ( ) < 10 ? "0" + date . getDate ( ) . toString ( ) : date . getDate ( ) . toString ( ) ) + "_" +
132
- date . getHours ( ) . toString ( ) +
133
- date . getMinutes ( ) . toString ( ) +
134
- date . getSeconds ( ) . toString ( ) ;
129
+ result = date . getFullYear ( ) . toString ( ) +
130
+ ( ( date . getMonth ( ) + 1 ) < 10 ? "0" + ( date . getMonth ( ) + 1 ) . toString ( ) : ( date . getMonth ( ) + 1 ) . toString ( ) ) +
131
+ ( date . getDate ( ) < 10 ? "0" + date . getDate ( ) . toString ( ) : date . getDate ( ) . toString ( ) ) + "_" +
132
+ date . getHours ( ) . toString ( ) +
133
+ date . getMinutes ( ) . toString ( ) +
134
+ date . getSeconds ( ) . toString ( ) ;
135
135
return result ;
136
136
}
0 commit comments