1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- 2 * This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 package org.mozilla.gecko.preferences; 7 8 import java.util.HashSet; 9 import java.util.Set; 10 11 import org.mozilla.gecko.GeckoSharedPrefs; 12 import org.mozilla.gecko.util.PrefUtils; 13 14 import android.content.Context; 15 import android.content.SharedPreferences; 16 import android.preference.Preference; 17 18 public class ClearOnShutdownPref implements GeckoPreferences.PrefHandler { 19 public static final String PREF = GeckoPreferences.NON_PREF_PREFIX + "history.clear_on_exit"; 20 21 @Override setupPref(Context context, Preference pref)22 public boolean setupPref(Context context, Preference pref) { 23 // The pref is initialized asynchronously. Read the pref explicitly 24 // here to make sure we have the data. 25 final SharedPreferences prefs = GeckoSharedPrefs.forProfile(context); 26 final Set<String> clearItems = PrefUtils.getStringSet(prefs, PREF, new HashSet<String>()); 27 ((ListCheckboxPreference) pref).setChecked(clearItems.size() > 0); 28 return true; 29 } 30 31 @Override 32 @SuppressWarnings("unchecked") onChange(Context context, Preference pref, Object newValue)33 public void onChange(Context context, Preference pref, Object newValue) { 34 final Set<String> vals = (Set<String>) newValue; 35 ((ListCheckboxPreference) pref).setChecked(vals.size() > 0); 36 } 37 } 38