98542ee8a1ced97dfbb14aa19538657985157414
[zxing.git] / android / src / com / google / zxing / client / android / PreferencesActivity.java
1 /*
2  * Copyright (C) 2008 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.client.android;
18
19 import android.content.SharedPreferences;
20 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
21 import android.os.Bundle;
22 import android.preference.CheckBoxPreference;
23 import android.preference.PreferenceScreen;
24
25 public final class PreferencesActivity extends android.preference.PreferenceActivity
26     implements OnSharedPreferenceChangeListener {
27
28   static final String KEY_DECODE_1D = "preferences_decode_1D";
29   static final String KEY_DECODE_QR = "preferences_decode_QR";
30
31   static final String KEY_PLAY_BEEP = "preferences_play_beep";
32   static final String KEY_VIBRATE = "preferences_vibrate";
33   static final String KEY_COPY_TO_CLIPBOARD = "preferences_copy_to_clipboard";
34
35   static final String KEY_HELP_VERSION_SHOWN = "preferences_help_version_shown";
36
37   CheckBoxPreference mDecode1D;
38   CheckBoxPreference mDecodeQR;
39
40   @Override
41   protected void onCreate(Bundle icicle) {
42     super.onCreate(icicle);
43     addPreferencesFromResource(R.xml.preferences);
44
45     PreferenceScreen preferences = getPreferenceScreen();
46     preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
47     mDecode1D = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_1D);
48     mDecodeQR = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_QR);
49   }
50
51   // Prevent the user from turning off both decode options
52   public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
53     if (key.equals(KEY_DECODE_1D)) {
54       mDecodeQR.setEnabled(mDecode1D.isChecked());
55       mDecodeQR.setChecked(true);
56     } else if (key.equals(KEY_DECODE_QR)) {
57       mDecode1D.setEnabled(mDecodeQR.isChecked());
58       mDecode1D.setChecked(true);
59     }
60   }
61
62 }