From 4ed7e4ac9680c47cc7694b42990218b4aac3f846 Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 13 Jul 2010 10:34:13 +0000 Subject: [PATCH] Make sure checkboxes are enabled correctly on first load git-svn-id: https://zxing.googlecode.com/svn/trunk@1479 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../client/android/PreferencesActivity.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/android/src/com/google/zxing/client/android/PreferencesActivity.java b/android/src/com/google/zxing/client/android/PreferencesActivity.java index 9a37e78f3..04e144104 100755 --- a/android/src/com/google/zxing/client/android/PreferencesActivity.java +++ b/android/src/com/google/zxing/client/android/PreferencesActivity.java @@ -56,16 +56,26 @@ public final class PreferencesActivity extends PreferenceActivity preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this); decode1D = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_1D); decodeQR = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_QR); + disableLastCheckedPref(); } - // Prevent the user from turning off both decode options public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (key.equals(KEY_DECODE_1D)) { - decodeQR.setEnabled(decode1D.isChecked()); + disableLastCheckedPref(); + } + + private void disableLastCheckedPref() { + if (decode1D.isChecked()) { + decodeQR.setEnabled(true); + } else { + decodeQR.setEnabled(false); decodeQR.setChecked(true); - } else if (key.equals(KEY_DECODE_QR)) { - decode1D.setEnabled(decodeQR.isChecked()); + } + if (decodeQR.isChecked()) { + decode1D.setEnabled(true); + } else { + decode1D.setEnabled(false); decode1D.setChecked(true); } } + }