From b0da10650e8b64f1679678ef133aca1da8ab09c9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 25 Sep 2016 22:28:42 +0200 Subject: [PATCH] couple smaller fixes --- .../flashlight/MyCameraImpl.java | 15 ++++++++++----- .../flashlight/activities/MainActivity.java | 11 +++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/flashlight/MyCameraImpl.java b/app/src/main/java/com/simplemobiletools/flashlight/MyCameraImpl.java index 3ede2b0..63b1dd9 100644 --- a/app/src/main/java/com/simplemobiletools/flashlight/MyCameraImpl.java +++ b/app/src/main/java/com/simplemobiletools/flashlight/MyCameraImpl.java @@ -219,13 +219,18 @@ public class MyCameraImpl { } } - if (mCamera != null) { - mCamera.setParameters(torchOff); - if (!mShouldEnableFlashlight || mIsMarshmallow) { - mCamera.release(); - mCamera = null; + try { + if (mCamera != null) { + mCamera.setParameters(torchOff); + if (!mShouldEnableFlashlight || mIsMarshmallow) { + mCamera.release(); + mCamera = null; + } } + } catch (RuntimeException ignored) { + } + mIsStroboscopeRunning = false; mShouldStroboscopeStop = false; diff --git a/app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java index 4cea0c9..6d29d84 100644 --- a/app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java @@ -39,6 +39,7 @@ public class MainActivity extends SimpleActivity { private static Bus mBus; private MyCameraImpl mCameraImpl; + private boolean mJustGrantedPermission; @Override protected void onCreate(Bundle savedInstanceState) { @@ -99,7 +100,6 @@ public class MainActivity extends SimpleActivity { @OnClick(R.id.toggle_btn) public void toggleFlashlight() { - mStroboscopeBar.setVisibility(View.INVISIBLE); mCameraImpl.toggleFlashlight(); } @@ -131,6 +131,7 @@ public class MainActivity extends SimpleActivity { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == CAMERA_PERMISSION) { + mJustGrantedPermission = true; if (isCameraPermissionGranted()) { toggleStroboscope(); } else { @@ -152,6 +153,10 @@ public class MainActivity extends SimpleActivity { @Override protected void onResume() { super.onResume(); + if (mJustGrantedPermission) { + mJustGrantedPermission = false; + return; + } mCameraImpl.handleCameraSetup(); mCameraImpl.checkFlashlight(); @@ -197,9 +202,11 @@ public class MainActivity extends SimpleActivity { } public void enableFlashlight() { - changeIconColor(R.color.translucent_white, mStroboscopeBtn); changeIconColor(R.color.colorPrimary, mToggleBtn); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + changeIconColor(R.color.translucent_white, mStroboscopeBtn); + mStroboscopeBar.setVisibility(View.INVISIBLE); } public void disableFlashlight() {