remember the last flashlight state

This commit is contained in:
tibbi 2016-10-10 19:32:35 +02:00
parent 126e626a9c
commit 69ebbaf9d6
3 changed files with 15 additions and 0 deletions

View File

@ -78,4 +78,12 @@ public class Config {
public void setLastUsedCamera(int cameraId) { public void setLastUsedCamera(int cameraId) {
mPrefs.edit().putInt(Constants.LAST_USED_CAMERA, cameraId).apply(); mPrefs.edit().putInt(Constants.LAST_USED_CAMERA, cameraId).apply();
} }
public boolean getLastFlashlightState() {
return mPrefs.getBoolean(Constants.LAST_FLASHLIGHT_STATE, false);
}
public void setLastFlashlightState(boolean enabled) {
mPrefs.edit().putBoolean(Constants.LAST_FLASHLIGHT_STATE, enabled).apply();
}
} }

View File

@ -15,4 +15,5 @@ public class Constants {
public static final String MAX_RESOLUTION = "max_resolution"; public static final String MAX_RESOLUTION = "max_resolution";
public static final String MAX_VIDEO_RESOLUTION = "max_video_resolution"; public static final String MAX_VIDEO_RESOLUTION = "max_video_resolution";
public static final String LAST_USED_CAMERA = "last_used_camera"; public static final String LAST_USED_CAMERA = "last_used_camera";
public static final String LAST_FLASHLIGHT_STATE = "last_flashlight_state";
} }

View File

@ -172,6 +172,7 @@ public class MainActivity extends SimpleActivity
mIsInPhotoMode = true; mIsInPhotoMode = true;
mTimerHandler = new Handler(); mTimerHandler = new Handler();
mFadeHandler = new Handler(); mFadeHandler = new Handler();
mIsFlashEnabled = mConfig.getLastFlashlightState();
setupPreviewImage(true); setupPreviewImage(true);
} }
@ -270,11 +271,15 @@ public class MainActivity extends SimpleActivity
private void disableFlash() { private void disableFlash() {
mPreview.disableFlash(); mPreview.disableFlash();
mToggleFlashBtn.setImageResource(R.mipmap.flash_off); mToggleFlashBtn.setImageResource(R.mipmap.flash_off);
mIsFlashEnabled = false;
mConfig.setLastFlashlightState(mIsFlashEnabled);
} }
private void enableFlash() { private void enableFlash() {
mPreview.enableFlash(); mPreview.enableFlash();
mToggleFlashBtn.setImageResource(R.mipmap.flash_on); mToggleFlashBtn.setImageResource(R.mipmap.flash_on);
mIsFlashEnabled = true;
mConfig.setLastFlashlightState(mIsFlashEnabled);
} }
@OnClick(R.id.shutter) @OnClick(R.id.shutter)
@ -547,6 +552,7 @@ public class MainActivity extends SimpleActivity
if (mPreview.setCamera(mCurrCamera)) { if (mPreview.setCamera(mCurrCamera)) {
hideNavigationBarIcons(); hideNavigationBarIcons();
checkFlash();
if (mSensorManager != null) { if (mSensorManager != null) {
final Sensor accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); final Sensor accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);