-
Notifications
You must be signed in to change notification settings - Fork 9
/
Flash light
51 lines (44 loc) · 1.05 KB
/
Flash light
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Do not forget to give CAMARA permision
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.app.Activity;
import android.content.pm.PackageManager;
public static Camera cam = null;
boolean on, is_flash_available;
Activity act;
void setup () {
fullScreen ();
background (0);
orientation (PORTRAIT);
act = this.getActivity ();
is_flash_available = act.getApplicationContext ().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
cam = Camera.open();
}
void draw () {
}
void mousePressed () {
Parameters p = cam.getParameters();
if (p.getFlashMode() != null && is_flash_available) {
if (on) {
p.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(p);
cam.stopPreview();
} else {
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
}
}
on = ! on;
}
void onStop () {
cam.release();
cam = null;
act.finish();
}
void onPause () {
cam.release();
cam = null;
act.finish();
}