couple smaller fixes
This commit is contained in:
parent
ec5d7cf0ad
commit
b0da10650e
|
@ -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;
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue