2 * Copyright (C) 2008 Google Inc.
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.
16 package com.android.barcodes;
18 import android.content.SharedPreferences;
19 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
20 import android.os.Bundle;
21 import android.preference.PreferenceScreen;
22 import android.preference.CheckBoxPreference;
24 public class BarcodesPreferenceActivity extends android.preference.PreferenceActivity
25 implements OnSharedPreferenceChangeListener {
27 static final String KEY_DECODE_1D = "preferences_decode_1D";
28 static final String KEY_DECODE_QR = "preferences_decode_QR";
29 static final String KEY_PLAY_BEEP = "preferences_play_beep";
31 CheckBoxPreference mDecode1D;
32 CheckBoxPreference mDecodeQR;
33 CheckBoxPreference mPlayBeep;
36 protected void onCreate(Bundle icicle) {
37 super.onCreate(icicle);
38 addPreferencesFromResource(R.xml.preferences);
40 PreferenceScreen preferences = getPreferenceScreen();
41 preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
42 mDecode1D = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_1D);
43 mDecodeQR = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_QR);
44 mPlayBeep = (CheckBoxPreference) preferences.findPreference(KEY_PLAY_BEEP);
47 // Prevent the user from turning off both decode options
48 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
49 if (key.equals(KEY_DECODE_1D)) {
50 mDecodeQR.setEnabled(mDecode1D.isChecked());
51 mDecodeQR.setChecked(true);
52 } else if (key.equals(KEY_DECODE_QR)) {
53 mDecode1D.setEnabled(mDecodeQR.isChecked());
54 mDecode1D.setChecked(true);