I'm getting weird results trying to use the method I usually use to get the duration:
float start = System.nanoTime();
//Do stuff
float duration = System.nanoTime() - start;
float durationInSeconds = duration / 1000000000.0f;
So I tried that in this flashlight app I'm making to create a strobe:
public void onClick(DialogInterface dialog, int id) {
isFlashOn = true;
isStrobeActive = true;
// Perform actual strobe
strobeHandler.post(new Runnable() {
float currDuration = 0;
final float deltaTime = 1/60f;
final float deltaTimeInMil = deltaTime * 1000;
@Override
public void run() {
float strobePerSecond = 1 / currentStrobeValue;
if (!isStrobeLightOn) {
if (currDuration > strobePerSecond) {
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(params);
currDuration -= strobePerSecond;
isStrobeLightOn = true;
}
} else {
params = camera.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(params);
isStrobeLightOn = false;
}
currDuration += deltaTime;
strobeHandler.postDelayed(this, (long) deltaTimeInMil);
}
});
}
The logs, however, return either 0.0 or 3.052E-5. I'm not exactly sure what I'm doing wrong, but I thing I need some help to figure it out. As always thanks.
Edit: I'm assuming that the start and end times are so similar, when they are subtracted and rounded, they are 0.