mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-06-05 21:59:19 +02:00
fix the flashlight on Android 7
This commit is contained in:
parent
5a61ad7957
commit
0e89b6e3c6
@ -50,6 +50,7 @@ public class MyCameraImpl {
|
|||||||
if (!mIsStroboscopeRunning)
|
if (!mIsStroboscopeRunning)
|
||||||
disableFlashlight();
|
disableFlashlight();
|
||||||
|
|
||||||
|
if (!Utils.isNougat()) {
|
||||||
if (mCamera == null) {
|
if (mCamera == null) {
|
||||||
initCamera();
|
initCamera();
|
||||||
}
|
}
|
||||||
@ -58,6 +59,7 @@ public class MyCameraImpl {
|
|||||||
Utils.showToast(mContext, R.string.camera_error);
|
Utils.showToast(mContext, R.string.camera_error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mIsStroboscopeRunning) {
|
if (mIsStroboscopeRunning) {
|
||||||
stopStroboscope();
|
stopStroboscope();
|
||||||
@ -181,6 +183,7 @@ public class MyCameraImpl {
|
|||||||
mBus.unregister(this);
|
mBus.unregister(this);
|
||||||
}
|
}
|
||||||
mIsFlashlightOn = false;
|
mIsFlashlightOn = false;
|
||||||
|
mShouldStroboscopeStop = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMarshmallow() {
|
private boolean isMarshmallow() {
|
||||||
@ -197,6 +200,20 @@ public class MyCameraImpl {
|
|||||||
mShouldStroboscopeStop = false;
|
mShouldStroboscopeStop = false;
|
||||||
mIsStroboscopeRunning = true;
|
mIsStroboscopeRunning = true;
|
||||||
|
|
||||||
|
if (Utils.isNougat()) {
|
||||||
|
while (!mShouldStroboscopeStop) {
|
||||||
|
try {
|
||||||
|
mMarshmallowCamera.toggleMarshmallowFlashlight(mBus, true);
|
||||||
|
Thread.sleep(mStroboFrequency);
|
||||||
|
mMarshmallowCamera.toggleMarshmallowFlashlight(mBus, false);
|
||||||
|
Thread.sleep(mStroboFrequency);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
mShouldStroboscopeStop = true;
|
||||||
|
} catch (RuntimeException ignored) {
|
||||||
|
mShouldStroboscopeStop = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (mCamera == null) {
|
if (mCamera == null) {
|
||||||
initCamera();
|
initCamera();
|
||||||
}
|
}
|
||||||
@ -230,6 +247,7 @@ public class MyCameraImpl {
|
|||||||
} catch (RuntimeException ignored) {
|
} catch (RuntimeException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mIsStroboscopeRunning = false;
|
mIsStroboscopeRunning = false;
|
||||||
mShouldStroboscopeStop = false;
|
mShouldStroboscopeStop = false;
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
@ -20,4 +21,8 @@ public class Utils {
|
|||||||
public static void showToast(Context context, int resId) {
|
public static void showToast(Context context, int resId) {
|
||||||
Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, context.getResources().getString(resId), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNougat() {
|
||||||
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class MainActivity extends SimpleActivity {
|
|||||||
|
|
||||||
private void toggleStroboscope() {
|
private void toggleStroboscope() {
|
||||||
// use the old Camera API for stroboscope, the new Camera Manager is way too slow
|
// use the old Camera API for stroboscope, the new Camera Manager is way too slow
|
||||||
if (isCameraPermissionGranted()) {
|
if (isCameraPermissionGranted() || Utils.isNougat()) {
|
||||||
if (mCameraImpl.toggleStroboscope()) {
|
if (mCameraImpl.toggleStroboscope()) {
|
||||||
mStroboscopeBar.setVisibility(mStroboscopeBar.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
|
mStroboscopeBar.setVisibility(mStroboscopeBar.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
|
||||||
changeIconColor(mStroboscopeBar.getVisibility() == View.VISIBLE ? R.color.colorPrimary : R.color.translucent_white, mStroboscopeBtn);
|
changeIconColor(mStroboscopeBar.getVisibility() == View.VISIBLE ? R.color.colorPrimary : R.color.translucent_white, mStroboscopeBtn);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user