couple smaller fixes
This commit is contained in:
parent
ec5d7cf0ad
commit
b0da10650e
|
@ -219,13 +219,18 @@ public class MyCameraImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mCamera != null) {
|
try {
|
||||||
mCamera.setParameters(torchOff);
|
if (mCamera != null) {
|
||||||
if (!mShouldEnableFlashlight || mIsMarshmallow) {
|
mCamera.setParameters(torchOff);
|
||||||
mCamera.release();
|
if (!mShouldEnableFlashlight || mIsMarshmallow) {
|
||||||
mCamera = null;
|
mCamera.release();
|
||||||
|
mCamera = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (RuntimeException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsStroboscopeRunning = false;
|
mIsStroboscopeRunning = false;
|
||||||
mShouldStroboscopeStop = false;
|
mShouldStroboscopeStop = false;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class MainActivity extends SimpleActivity {
|
||||||
|
|
||||||
private static Bus mBus;
|
private static Bus mBus;
|
||||||
private MyCameraImpl mCameraImpl;
|
private MyCameraImpl mCameraImpl;
|
||||||
|
private boolean mJustGrantedPermission;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -99,7 +100,6 @@ public class MainActivity extends SimpleActivity {
|
||||||
|
|
||||||
@OnClick(R.id.toggle_btn)
|
@OnClick(R.id.toggle_btn)
|
||||||
public void toggleFlashlight() {
|
public void toggleFlashlight() {
|
||||||
mStroboscopeBar.setVisibility(View.INVISIBLE);
|
|
||||||
mCameraImpl.toggleFlashlight();
|
mCameraImpl.toggleFlashlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +131,7 @@ public class MainActivity extends SimpleActivity {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
|
||||||
if (requestCode == CAMERA_PERMISSION) {
|
if (requestCode == CAMERA_PERMISSION) {
|
||||||
|
mJustGrantedPermission = true;
|
||||||
if (isCameraPermissionGranted()) {
|
if (isCameraPermissionGranted()) {
|
||||||
toggleStroboscope();
|
toggleStroboscope();
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,6 +153,10 @@ public class MainActivity extends SimpleActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
if (mJustGrantedPermission) {
|
||||||
|
mJustGrantedPermission = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
mCameraImpl.handleCameraSetup();
|
mCameraImpl.handleCameraSetup();
|
||||||
mCameraImpl.checkFlashlight();
|
mCameraImpl.checkFlashlight();
|
||||||
|
|
||||||
|
@ -197,9 +202,11 @@ public class MainActivity extends SimpleActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableFlashlight() {
|
public void enableFlashlight() {
|
||||||
changeIconColor(R.color.translucent_white, mStroboscopeBtn);
|
|
||||||
changeIconColor(R.color.colorPrimary, mToggleBtn);
|
changeIconColor(R.color.colorPrimary, mToggleBtn);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
|
||||||
|
changeIconColor(R.color.translucent_white, mStroboscopeBtn);
|
||||||
|
mStroboscopeBar.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableFlashlight() {
|
public void disableFlashlight() {
|
||||||
|
|
Loading…
Reference in New Issue