summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/preferences/ClearOnShutdownPref.java
blob: 5218cd06db98b081c875a23a06490eed9a715b69 (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
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.preferences;

import java.util.HashSet;
import java.util.Set;

import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.util.PrefUtils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.Preference;

public class ClearOnShutdownPref implements GeckoPreferences.PrefHandler {
    public static final String PREF = GeckoPreferences.NON_PREF_PREFIX + "history.clear_on_exit";

    @Override
    public boolean setupPref(Context context, Preference pref) {
        // The pref is initialized asynchronously. Read the pref explicitly
        // here to make sure we have the data.
        final SharedPreferences prefs = GeckoSharedPrefs.forProfile(context);
        final Set<String> clearItems = PrefUtils.getStringSet(prefs, PREF, new HashSet<String>());
        ((ListCheckboxPreference) pref).setChecked(clearItems.size() > 0);
        return true;
    }

    @Override
    @SuppressWarnings("unchecked")
    public void onChange(Context context, Preference pref, Object newValue) {
        final Set<String> vals = (Set<String>) newValue;
        ((ListCheckboxPreference) pref).setChecked(vals.size() > 0);
    }
}