setup the icons properly on resume

This commit is contained in:
tibbi 2016-06-19 00:43:36 +02:00
parent cfded9650e
commit 0021981bcc
1 changed files with 20 additions and 12 deletions

View File

@ -214,22 +214,25 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
return; return;
} }
mIsFlashEnabled = !mIsFlashEnabled;
checkFlash();
}
private void checkFlash() {
if (mIsFlashEnabled) { if (mIsFlashEnabled) {
disableFlash();
} else {
enableFlash(); enableFlash();
} else {
disableFlash();
} }
} }
private void disableFlash() { private void disableFlash() {
mPreview.disableFlash(); mPreview.disableFlash();
mIsFlashEnabled = false;
mToggleFlashBtn.setImageResource(R.mipmap.flash_off); mToggleFlashBtn.setImageResource(R.mipmap.flash_off);
} }
private void enableFlash() { private void enableFlash() {
mPreview.enableFlash(); mPreview.enableFlash();
mIsFlashEnabled = true;
mToggleFlashBtn.setImageResource(R.mipmap.flash_on); mToggleFlashBtn.setImageResource(R.mipmap.flash_on);
} }
@ -300,7 +303,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
if (mIsInPhotoMode) { if (mIsInPhotoMode) {
initPhotoButtons(); initPhotoButtons();
} else { } else {
initVideoButtons(true); initVideoButtons();
} }
} }
@ -311,19 +314,24 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
mPreview.initPhotoMode(); mPreview.initPhotoMode();
} }
private void initVideoButtons(boolean warnOnError) { private void initVideoButtons() {
if (mPreview.initRecorder()) { if (mPreview.initRecorder()) {
final Resources res = getResources(); setupVideoIcons();
mTogglePhotoVideoBtn.setImageDrawable(res.getDrawable(R.mipmap.photo));
mShutterBtn.setImageDrawable(res.getDrawable(R.mipmap.video_rec));
mToggleCameraBtn.setVisibility(View.VISIBLE);
} else { } else {
if (!mIsVideoCaptureIntent && warnOnError) { if (!mIsVideoCaptureIntent) {
Utils.showToast(getApplicationContext(), R.string.video_mode_error); Utils.showToast(getApplicationContext(), R.string.video_mode_error);
} }
} }
} }
private void setupVideoIcons() {
final Resources res = getResources();
mTogglePhotoVideoBtn.setImageDrawable(res.getDrawable(R.mipmap.photo));
mToggleCameraBtn.setVisibility(View.VISIBLE);
mShutterBtn.setImageDrawable(res.getDrawable(R.mipmap.video_rec));
checkFlash();
}
private void hideNavigationBarIcons() { private void hideNavigationBarIcons() {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
} }
@ -378,7 +386,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
} }
if (!mIsInPhotoMode) { if (!mIsInPhotoMode) {
initVideoButtons(false); setupVideoIcons();
} }
} else { } else {
Utils.showToast(getApplicationContext(), R.string.camera_switch_error); Utils.showToast(getApplicationContext(), R.string.camera_switch_error);