summaryrefslogtreecommitdiff
path: root/src/com/android/barcodes/BarcodesPreferenceActivity.java
blob: abe34357226f377531b14481235ae4bff62e11c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (C) 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.barcodes;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceScreen;
import android.preference.CheckBoxPreference;

public class BarcodesPreferenceActivity extends android.preference.PreferenceActivity
        implements OnSharedPreferenceChangeListener {

    static final String KEY_DECODE_1D = "preferences_decode_1D";
    static final String KEY_DECODE_QR = "preferences_decode_QR";
    static final String KEY_PLAY_BEEP = "preferences_play_beep";

    CheckBoxPreference mDecode1D;
    CheckBoxPreference mDecodeQR;
    CheckBoxPreference mPlayBeep;

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        addPreferencesFromResource(R.xml.preferences);

        PreferenceScreen preferences = getPreferenceScreen();
        preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
        mDecode1D = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_1D);
        mDecodeQR = (CheckBoxPreference) preferences.findPreference(KEY_DECODE_QR);
        mPlayBeep = (CheckBoxPreference) preferences.findPreference(KEY_PLAY_BEEP);
    }

    // Prevent the user from turning off both decode options
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (key.equals(KEY_DECODE_1D)) {
            mDecodeQR.setEnabled(mDecode1D.isChecked());
            mDecodeQR.setChecked(true);
        } else if (key.equals(KEY_DECODE_QR)) {
            mDecode1D.setEnabled(mDecodeQR.isChecked());
            mDecode1D.setChecked(true);
        }
    }

}