1
1
package io .github .edufolly .fluttermobilevision ;
2
2
3
3
import android .Manifest ;
4
+ import android .annotation .SuppressLint ;
4
5
import android .app .Activity ;
5
6
import android .content .Intent ;
6
7
import android .content .pm .PackageManager ;
@@ -52,7 +53,7 @@ public class FlutterMobileVisionPlugin implements MethodCallHandler,
52
53
private boolean showText = false ;
53
54
private int previewWidth = 640 ;
54
55
private int previewHeight = 480 ;
55
- private int facing = CameraSource .CAMERA_FACING_BACK ;
56
+ private int camera = CameraSource .CAMERA_FACING_BACK ;
56
57
private float fps = 15.0f ;
57
58
58
59
/**
@@ -76,10 +77,14 @@ private FlutterMobileVisionPlugin(Activity activity) {
76
77
@ Override
77
78
public void onMethodCall (MethodCall call , Result result ) {
78
79
79
- final Map <String , Object > arguments = call .arguments ();
80
-
81
80
this .result = result ;
82
81
82
+ Map <String , Object > arguments = new HashMap <>();
83
+
84
+ if (call .arguments () != null ) {
85
+ arguments = call .arguments ();
86
+ }
87
+
83
88
if (arguments .containsKey ("flash" )) {
84
89
useFlash = (boolean ) arguments .get ("flash" );
85
90
}
@@ -117,7 +122,7 @@ public void onMethodCall(MethodCall call, Result result) {
117
122
}
118
123
119
124
if (arguments .containsKey ("camera" )) {
120
- facing = (int ) arguments .get ("camera" );
125
+ camera = (int ) arguments .get ("camera" );
121
126
}
122
127
123
128
if (arguments .containsKey ("fps" )) {
@@ -139,16 +144,29 @@ public void onMethodCall(MethodCall call, Result result) {
139
144
Intent intent ;
140
145
int res ;
141
146
142
- if ("cameraSizes" .equals (call .method )) {
143
- List <Size > sizeList = CameraSource .getSizesForCameraFacing (facing );
144
- List <Map <String , Object >> list = new ArrayList <>();
145
- for (Size size : sizeList ) {
146
- Map <String , Object > ret = new HashMap <>();
147
- ret .put ("width" , size .getWidth ());
148
- ret .put ("height" , size .getHeight ());
149
- list .add (ret );
147
+ if ("start" .equals (call .method )) {
148
+
149
+ @ SuppressLint ("UseSparseArrays" )
150
+ Map <Integer , List > map = new HashMap <>();
151
+
152
+ int [] cameras = new int []{CameraSource .CAMERA_FACING_BACK , CameraSource .CAMERA_FACING_FRONT };
153
+
154
+ for (int facing : cameras ) {
155
+
156
+ List <Size > sizeList = CameraSource .getSizesForCameraFacing (facing );
157
+
158
+ List <Map <String , Object >> list = new ArrayList <>();
159
+ for (Size size : sizeList ) {
160
+ Map <String , Object > ret = new HashMap <>();
161
+ ret .put ("width" , size .getWidth ());
162
+ ret .put ("height" , size .getHeight ());
163
+ list .add (ret );
164
+ }
165
+
166
+ map .put (facing , list );
150
167
}
151
- result .success (list );
168
+
169
+ result .success (map );
152
170
return ;
153
171
} else if ("scan" .equals (call .method )) {
154
172
intent = new Intent (activity , BarcodeCaptureActivity .class );
@@ -172,7 +190,7 @@ public void onMethodCall(MethodCall call, Result result) {
172
190
intent .putExtra (AbstractCaptureActivity .SHOW_TEXT , showText );
173
191
intent .putExtra (AbstractCaptureActivity .PREVIEW_WIDTH , previewWidth );
174
192
intent .putExtra (AbstractCaptureActivity .PREVIEW_HEIGHT , previewHeight );
175
- intent .putExtra (AbstractCaptureActivity .CAMERA , facing );
193
+ intent .putExtra (AbstractCaptureActivity .CAMERA , camera );
176
194
intent .putExtra (AbstractCaptureActivity .FPS , fps );
177
195
activity .startActivityForResult (intent , res );
178
196
}
0 commit comments