@@ -36,25 +36,35 @@ const ALIGN_PARENT_RIGHT = 11;
36
36
const CENTER_HORIZONTAL = 14 ;
37
37
const DIRECTORY_PICTURES = "DIRECTORY_PICTURES" ;
38
38
const DIRECTORY_MOVIES = "DIRECTORY_MOVIES" ;
39
- const CAMERA = ( android as any ) . Manifest . permission . CAMERA ;
40
- const RECORD_AUDIO = ( android as any ) . Manifest . permission . RECORD_AUDIO ;
41
39
const FOCUS_MODE_AUTO = "auto" ;
42
40
const FOCUS_MODE_EDOF = "edof" ;
43
41
const FOCUS_MODE_CONTINUOUS_PICTURE = "continuous-picture" ;
44
42
const FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video" ;
45
- const READ_EXTERNAL_STORAGE = ( android as any ) . Manifest . permission
46
- . READ_EXTERNAL_STORAGE ;
47
- const WRITE_EXTERNAL_STORAGE = ( android as any ) . Manifest . permission
48
- . WRITE_EXTERNAL_STORAGE ;
49
43
const FLASH_MODE_ON = "on" ;
50
44
const FLASH_MODE_OFF = "off" ;
51
45
const CAMERA_FACING_FRONT = 1 ; // front camera
52
46
const CAMERA_FACING_BACK = 0 ; // rear camera
53
47
const RESULT_CODE_PICKER_IMAGES = 415161 ;
54
48
const RESULT_OK = - 1 ;
55
49
50
+ // Snapshot-friendly functions
51
+ const CAMERA = ( ) => ( android as any ) . Manifest . permission . CAMERA ;
52
+ const RECORD_AUDIO = ( ) => ( android as any ) . Manifest . permission . RECORD_AUDIO ;
53
+ const READ_EXTERNAL_STORAGE = ( ) =>
54
+ ( android as any ) . Manifest . permission . READ_EXTERNAL_STORAGE ;
55
+ const WRITE_EXTERNAL_STORAGE = ( ) =>
56
+ ( android as any ) . Manifest . permission . WRITE_EXTERNAL_STORAGE ;
57
+
56
58
export class CameraPlus extends CameraPlusBase {
57
- @GetSetProperty ( ) public camera : android . hardware . Camera ;
59
+ // @GetSetProperty () public camera: android.hardware.Camera;
60
+ // Snapshot-friendly, since the decorator will include the snapshot-unknown object "android"
61
+ private _camera : android . hardware . Camera ;
62
+ public get camera ( ) : android . hardware . Camera {
63
+ return this . _camera ;
64
+ }
65
+ public set camera ( camera : android . hardware . Camera ) {
66
+ this . _camera = camera ;
67
+ }
58
68
@GetSetProperty ( ) public cameraId ;
59
69
@GetSetProperty ( ) public autoFocus : boolean = true ;
60
70
@GetSetProperty ( ) public flashOnIcon : string = "ic_flash_on_white" ;
@@ -138,7 +148,7 @@ export class CameraPlus extends CameraPlusBase {
138
148
// nativeView = new android.widget.RelativeLayout(this._context);
139
149
this . _nativeView = new android . widget . RelativeLayout ( this . _context ) ;
140
150
141
- permissions . requestPermission ( CAMERA ) . then (
151
+ permissions . requestPermission ( CAMERA ( ) ) . then (
142
152
( ) => {
143
153
// create the TextureView that will render the camera preview
144
154
this . _textureView = new android . view . TextureView ( this . _context ) ;
@@ -157,7 +167,7 @@ export class CameraPlus extends CameraPlusBase {
157
167
158
168
// setup SurfaceTextureListener
159
169
this . _textureView . setSurfaceTextureListener (
160
- new android . view . TextureView . SurfaceTextureListener ( {
170
+ new android . view . TextureView . SurfaceTextureListener ( < any > {
161
171
get owner ( ) {
162
172
return that . get ( ) ;
163
173
} ,
@@ -185,7 +195,7 @@ export class CameraPlus extends CameraPlusBase {
185
195
this . _initDefaultButtons ( ) ;
186
196
} else {
187
197
permissions
188
- . requestPermission ( CAMERA )
198
+ . requestPermission ( CAMERA ( ) )
189
199
. then ( ( ) => {
190
200
this . _initCamera ( this . cameraId ) ;
191
201
this . _initDefaultButtons ( ) ;
@@ -452,7 +462,6 @@ export class CameraPlus extends CameraPlusBase {
452
462
CLog ( "Exception preparing MediaRecorder" , e ) ;
453
463
this . _releaseMediaRecorder ( ) ;
454
464
this . isRecording = false ;
455
- return false ;
456
465
}
457
466
}
458
467
@@ -648,7 +657,10 @@ export class CameraPlus extends CameraPlusBase {
648
657
createThePickerIntent ( ) ;
649
658
} else {
650
659
permissions
651
- . requestPermissions ( [ READ_EXTERNAL_STORAGE , WRITE_EXTERNAL_STORAGE ] )
660
+ . requestPermissions ( [
661
+ READ_EXTERNAL_STORAGE ( ) ,
662
+ WRITE_EXTERNAL_STORAGE ( )
663
+ ] )
652
664
. then ( ( ) => {
653
665
createThePickerIntent ( ) ;
654
666
} ) ;
@@ -702,7 +714,7 @@ export class CameraPlus extends CameraPlusBase {
702
714
public requestCameraPermissions ( explanation : string = "" ) : Promise < boolean > {
703
715
return new Promise ( ( resolve , reject ) => {
704
716
permissions
705
- . requestPermission ( CAMERA , explanation )
717
+ . requestPermission ( CAMERA ( ) , explanation )
706
718
. then ( ( ) => {
707
719
resolve ( true ) ;
708
720
} )
@@ -721,7 +733,7 @@ export class CameraPlus extends CameraPlusBase {
721
733
* Returns true if the CAMERA permission has been granted.
722
734
*/
723
735
public hasCameraPermission ( ) : boolean {
724
- return permissions . hasPermission ( CAMERA ) ;
736
+ return permissions . hasPermission ( CAMERA ( ) ) ;
725
737
}
726
738
727
739
/**
@@ -731,7 +743,7 @@ export class CameraPlus extends CameraPlusBase {
731
743
public requestAudioPermissions ( explanation : string = "" ) : Promise < boolean > {
732
744
return new Promise ( ( resolve , reject ) => {
733
745
permissions
734
- . requestPermission ( RECORD_AUDIO , explanation )
746
+ . requestPermission ( RECORD_AUDIO ( ) , explanation )
735
747
. then ( ( ) => {
736
748
resolve ( true ) ;
737
749
} )
@@ -750,7 +762,7 @@ export class CameraPlus extends CameraPlusBase {
750
762
* Returns true if the RECORD_AUDIO permission has been granted.
751
763
*/
752
764
public hasAudioPermission ( ) : boolean {
753
- return permissions . hasPermission ( RECORD_AUDIO ) ;
765
+ return permissions . hasPermission ( RECORD_AUDIO ( ) ) ;
754
766
}
755
767
756
768
/**
@@ -761,7 +773,7 @@ export class CameraPlus extends CameraPlusBase {
761
773
return new Promise ( ( resolve , reject ) => {
762
774
permissions
763
775
. requestPermissions (
764
- [ WRITE_EXTERNAL_STORAGE , READ_EXTERNAL_STORAGE ] ,
776
+ [ WRITE_EXTERNAL_STORAGE ( ) , READ_EXTERNAL_STORAGE ( ) ] ,
765
777
explanation
766
778
)
767
779
. then ( ( ) => {
@@ -782,8 +794,8 @@ export class CameraPlus extends CameraPlusBase {
782
794
* Returns true if the WRITE_EXTERNAL_STORAGE && READ_EXTERNAL_STORAGE permissions have been granted.
783
795
*/
784
796
public hasStoragePermissions ( ) : boolean {
785
- const writePerm = permissions . hasPermission ( WRITE_EXTERNAL_STORAGE ) ;
786
- const readPerm = permissions . hasPermission ( READ_EXTERNAL_STORAGE ) ;
797
+ const writePerm = permissions . hasPermission ( WRITE_EXTERNAL_STORAGE ( ) ) ;
798
+ const readPerm = permissions . hasPermission ( READ_EXTERNAL_STORAGE ( ) ) ;
787
799
if ( writePerm === true && readPerm === true ) {
788
800
return true ;
789
801
} else {
@@ -796,7 +808,10 @@ export class CameraPlus extends CameraPlusBase {
796
808
) : Promise < boolean > {
797
809
return new Promise ( async ( resolve , reject ) => {
798
810
permissions
799
- . requestPermissions ( [ WRITE_EXTERNAL_STORAGE , RECORD_AUDIO ] , explanation )
811
+ . requestPermissions (
812
+ [ WRITE_EXTERNAL_STORAGE ( ) , RECORD_AUDIO ( ) ] ,
813
+ explanation
814
+ )
800
815
. then ( ( ) => {
801
816
resolve ( true ) ;
802
817
} )
@@ -812,8 +827,8 @@ export class CameraPlus extends CameraPlusBase {
812
827
}
813
828
814
829
public hasVideoRecordingPermissions ( ) {
815
- const writePerm = permissions . hasPermission ( WRITE_EXTERNAL_STORAGE ) ;
816
- const audio = permissions . hasPermission ( RECORD_AUDIO ) ;
830
+ const writePerm = permissions . hasPermission ( WRITE_EXTERNAL_STORAGE ( ) ) ;
831
+ const audio = permissions . hasPermission ( RECORD_AUDIO ( ) ) ;
817
832
if ( writePerm === true && audio === true ) {
818
833
return true ;
819
834
} else {
0 commit comments