2 * Copyright (C) 2008 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.client.android;
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.PreferenceActivity;
24 import android.preference.PreferenceScreen;
27 * The main settings activity.
29 * @author dswitkin@google.com (Daniel Switkin)
31 public final class PreferencesActivity extends PreferenceActivity
32 implements OnSharedPreferenceChangeListener {
34 static final String KEY_DECODE_1D = "preferences_decode_1D";
35 static final String KEY_DECODE_QR = "preferences_decode_QR";
36 public static final String KEY_CUSTOM_PRODUCT_SEARCH = "preferences_custom_product_search";
38 static final String KEY_PLAY_BEEP = "preferences_play_beep";
39 static final String KEY_VIBRATE = "preferences_vibrate";
40 static final String KEY_COPY_TO_CLIPBOARD = "preferences_copy_to_clipboard";
42 static final String KEY_HELP_VERSION_SHOWN = "preferences_help_version_shown";
44 private CheckBoxPreference decode1D;
45 private CheckBoxPreference decodeQR;
48 protected void onCreate(Bundle icicle) {
49 super.onCreate(icicle);
50 addPreferencesFromResource(R.xml.preferences);
52 PreferenceScreen preferences = getPreferenceScreen();
53 preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
54 decode1D = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_1D);
55 decodeQR = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_QR);
58 // Prevent the user from turning off both decode options
59 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
60 if (key.equals(KEY_DECODE_1D)) {
61 decodeQR.setEnabled(decode1D.isChecked());
62 decodeQR.setChecked(true);
63 } else if (key.equals(KEY_DECODE_QR)) {
64 decode1D.setEnabled(decodeQR.isChecked());
65 decode1D.setChecked(true);