Skip to content

Commit a4080d3

Browse files
committed
constructor overloading
Signed-off-by: Umair Khan <[email protected]>
1 parent 6fefe58 commit a4080d3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/in/omerjerk/processing/video/android/Capture.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,29 @@ public class Capture extends PImage implements PConstants {
1414

1515
private static Context context;
1616

17-
private static ArrayList<String> camerasList = new ArrayList<>();
17+
private static ArrayList<String> camerasList = new ArrayList<String>();
1818

1919
private static final String KEY_FRONT_CAMERA = "front-camera-%d";
2020
private static final String KEY_BACK_CAMERA = "back-camera-%d";
2121

22+
private int selectedCamera = 0;
23+
2224
public Capture (PApplet context) {
23-
Capture.context = context;
25+
this(context, null);
2426
}
2527

28+
public Capture (PApplet context, String camera) {
29+
Capture.context = context;
30+
if (camera == null || camera.equals("")) {
31+
selectedCamera = 0;
32+
} else {
33+
selectedCamera = camerasList.indexOf(camera);
34+
}
35+
}
36+
2637
public static String[] list() {
2738
ensureContext();
28-
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
39+
if (true) {
2940
int nOfCameras = Camera.getNumberOfCameras();
3041
for (int i = 0; i < nOfCameras; ++i) {
3142
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
@@ -46,7 +57,10 @@ public static String[] list() {
4657

4758
private static void ensureContext() {
4859
if (context == null) {
49-
throw new RuntimeException("Create the instance of Capture class first.");
60+
context = PApplet.getInstance();
61+
if (context == null) {
62+
throw new RuntimeException("Create the instance of Capture class first.");
63+
}
5064
}
5165
}
5266
}

0 commit comments

Comments
 (0)