Skip to content

Commit b0da106

Browse files
committed
couple smaller fixes
1 parent ec5d7cf commit b0da106

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/src/main/java/com/simplemobiletools/flashlight/MyCameraImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,18 @@ public void run() {
219219
}
220220
}
221221

222-
if (mCamera != null) {
223-
mCamera.setParameters(torchOff);
224-
if (!mShouldEnableFlashlight || mIsMarshmallow) {
225-
mCamera.release();
226-
mCamera = null;
222+
try {
223+
if (mCamera != null) {
224+
mCamera.setParameters(torchOff);
225+
if (!mShouldEnableFlashlight || mIsMarshmallow) {
226+
mCamera.release();
227+
mCamera = null;
228+
}
227229
}
230+
} catch (RuntimeException ignored) {
231+
228232
}
233+
229234
mIsStroboscopeRunning = false;
230235
mShouldStroboscopeStop = false;
231236

app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class MainActivity extends SimpleActivity {
3939

4040
private static Bus mBus;
4141
private MyCameraImpl mCameraImpl;
42+
private boolean mJustGrantedPermission;
4243

4344
@Override
4445
protected void onCreate(Bundle savedInstanceState) {
@@ -99,7 +100,6 @@ private void setupCameraImpl() {
99100

100101
@OnClick(R.id.toggle_btn)
101102
public void toggleFlashlight() {
102-
mStroboscopeBar.setVisibility(View.INVISIBLE);
103103
mCameraImpl.toggleFlashlight();
104104
}
105105

@@ -131,6 +131,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
131131
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
132132

133133
if (requestCode == CAMERA_PERMISSION) {
134+
mJustGrantedPermission = true;
134135
if (isCameraPermissionGranted()) {
135136
toggleStroboscope();
136137
} else {
@@ -152,6 +153,10 @@ protected void onStart() {
152153
@Override
153154
protected void onResume() {
154155
super.onResume();
156+
if (mJustGrantedPermission) {
157+
mJustGrantedPermission = false;
158+
return;
159+
}
155160
mCameraImpl.handleCameraSetup();
156161
mCameraImpl.checkFlashlight();
157162

@@ -197,9 +202,11 @@ public void stateChangedEvent(Events.StateChanged event) {
197202
}
198203

199204
public void enableFlashlight() {
200-
changeIconColor(R.color.translucent_white, mStroboscopeBtn);
201205
changeIconColor(R.color.colorPrimary, mToggleBtn);
202206
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
207+
208+
changeIconColor(R.color.translucent_white, mStroboscopeBtn);
209+
mStroboscopeBar.setVisibility(View.INVISIBLE);
203210
}
204211

205212
public void disableFlashlight() {

0 commit comments

Comments
 (0)