fix stroboscope on some devices, by sarevd

This commit is contained in:
tibbi 2017-02-09 22:23:58 +01:00
parent 90f1e3034b
commit 333727cee7

View File

@ -1,12 +1,15 @@
package com.simplemobiletools.flashlight; package com.simplemobiletools.flashlight;
import android.content.Context; import android.content.Context;
import android.graphics.SurfaceTexture;
import android.hardware.Camera; import android.hardware.Camera;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import java.io.IOException;
public class MyCameraImpl { public class MyCameraImpl {
private static final String TAG = MyCameraImpl.class.getSimpleName(); private static final String TAG = MyCameraImpl.class.getSimpleName();
@ -223,6 +226,15 @@ public class MyCameraImpl {
torchOn.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); torchOn.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
torchOff.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); torchOff.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
SurfaceTexture dummy = new SurfaceTexture(1);
try {
mCamera.setPreviewTexture(dummy);
} catch (IOException e) {
Log.e(TAG, "setup stroboscope1 " + e.getMessage());
}
mCamera.startPreview();
while (!mShouldStroboscopeStop) { while (!mShouldStroboscopeStop) {
try { try {
mCamera.setParameters(torchOn); mCamera.setParameters(torchOn);
@ -244,8 +256,8 @@ public class MyCameraImpl {
mCamera = null; mCamera = null;
} }
} }
} catch (RuntimeException ignored) { } catch (RuntimeException e) {
Log.e(TAG, "setup stroboscope2 " + e.getMessage());
} }
} }