Example usage for android.preference PreferenceScreen addPreference

List of usage examples for android.preference PreferenceScreen addPreference

Introduction

In this page you can find the example usage for android.preference PreferenceScreen addPreference.

Prototype

public boolean addPreference(Preference preference) 

Source Link

Document

Adds a Preference at the correct position based on the preference's order.

Usage

From source file:de.azapps.mirakel.settings.custom_views.Settings.java

public static PreferenceScreen inflateHeaders(final @NonNull PreferenceScreen screen,
        final @NonNull OnItemClickedListener<Settings> onClick) {
    for (final Map.Entry<Integer, List<Settings>> id : all.entrySet()) {
        final PreferenceCategory cat = new PreferenceCategory(ctx);
        screen.addPreference(cat);
        cat.setTitle(id.getKey());/*from w w  w  . j ava 2s .c o  m*/
        for (final Settings setting : id.getValue()) {
            if (setting == DEV && !MirakelCommonPreferences.isEnabledDebugMenu()) {
                continue;
            }
            cat.addItemFromInflater(setting.getPreference(onClick));
        }
    }
    return screen;

}

From source file:be.deadba.ampd.SettingsActivity.java

private static void setupDefaultDirectoryPreference(Preference preference, PreferenceScreen ps) {
    preference.setDefaultValue(MPDConf.DEFAULT_MUSIC_DIRECTORY);
    ps.removePreference(preference);/* w  w  w.j  a v  a 2  s  . c o  m*/
    ps.addPreference(preference);
}

From source file:org.namelessrom.devicecontrol.ui.views.CustomPreferenceFragment.java

protected void isSupported(final PreferenceScreen preferenceScreen, final Context context, final int sId) {
    if (preferenceScreen.getPreferenceCount() == 0) {
        preferenceScreen.addPreference(createPreference(context, sId));
    }//w ww .  j a  v  a  2  s.c om
}

From source file:com.colossaldb.dnd.ui.DebugFragment.java

/**
 * Add the events to the preference screen
 *//*from   ww w. j  a va  2  s . c  o m*/
private void addEventsToPreferenceScreen(PreferenceScreen screen, JSONArray events) {
    if (events == null || events.length() == 0) {
        screen.addPreference(failedPreference("No events"));
        return;
    }

    for (int i = events.length() - 1; i >= 0; i--) {
        try {
            JSONObject object = events.getJSONObject(i);
            Preference eventPreference = new Preference(getActivity());
            eventPreference.setTitle(object.getString(AppPreferences.TITLE_KEY));
            eventPreference.setSummary(object.getString(AppPreferences.TIMESTAMP_KEY) + " : "
                    + object.getString(AppPreferences.DETAIL_KEY));
            screen.addPreference(eventPreference);
        } catch (JSONException ignored) {
            Log.e("DebugFragment", "Failed get object", ignored);
        }
    }
}

From source file:com.colossaldb.dnd.ui.DebugFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getPreferenceManager() == null)
        return;//from   ww w . j ava2s .  co m

    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(getActivity());
    if (root == null)
        return;

    root.setTitle("Debug Information");

    root.addPreference(getPast(getPreferenceManager()));
    root.addPreference(getPresent(getPreferenceManager()));
    root.addPreference(getFuture(getPreferenceManager()));
    root.addPreference(getErrors(getPreferenceManager()));
    setPreferenceScreen(root);
}

From source file:com.guipenedo.pokeradar.activities.settings.PokemonFilterSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();//from w  w w .  j ava2 s  . c o m
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(this);
    PreferenceCategory category = new PreferenceCategory(this);
    category.setTitle(R.string.filter_pokemons);
    screen.addPreference(category);
    try {
        JSONArray pokemonList = new JSONArray(Utils.loadJSONFromFile(this, "pokemon.json"));
        for (int i = 0; i < pokemonList.length(); i++) {
            JSONObject pokemon = pokemonList.getJSONObject(i);
            CheckBoxPreference checkBox = new CheckBoxPreference(this);
            checkBox.setTitle(pokemon.getString("Name"));
            checkBox.setIcon(new BitmapDrawable(getResources(),
                    Utils.bitmapForPokemon(this, Integer.parseInt(pokemon.getString("Number")))));
            checkBox.setDefaultValue(true);
            checkBox.setSummary(String.format(getString(R.string.setting_filter_pokemon_summary),
                    pokemon.getString("Name")));
            checkBox.setKey("pref_key_show_pokemon_" + Integer.parseInt(pokemon.getString("Number")));
            category.addPreference(checkBox);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    setPreferenceScreen(screen);
}

From source file:com.colossaldb.dnd.ui.DebugFragment.java

/**
 * Future scheduled events (and related information - if available)
 *//*from www . j ava 2  s .c  o  m*/
Preference getFuture(PreferenceManager preferenceManager) {
    PreferenceScreen future = preferenceManager.createPreferenceScreen(getActivity());
    if (future == null)
        return failedPreference("Failed to create future");
    future.setTitle(R.string.future);

    Preference nextEvent = new Preference(getActivity());
    nextEvent.setTitle("Next Schedule Run");
    nextEvent.setSummary(AppPreferences.getInstance().getNextScheduleRun());
    future.addPreference(nextEvent);
    return future;
}

From source file:com.colossaldb.dnd.ui.DebugFragment.java

/**
 * Current debug information for display
 *///from   w  w  w. ja  v a  2  s .co  m
Preference getPresent(PreferenceManager preferenceManager) {
    PreferenceScreen present = preferenceManager.createPreferenceScreen(getActivity());
    if (present == null)
        return failedPreference("Failed to create present");

    present.setTitle(R.string.present);

    AppPreferences pref = AppPreferences.getInstance();

    Preference enabled = new Preference(getActivity());
    enabled.setTitle(R.string.enabled);
    enabled.setSummary("" + pref.isEnabled());
    present.addPreference(enabled);

    Preference startTime = new Preference(getActivity());
    startTime.setTitle(R.string.start);
    startTime.setSummary(pref.getFormattedStartTime());
    present.addPreference(startTime);

    Preference endTime = new Preference(getActivity());
    endTime.setTitle(R.string.end);
    endTime.setSummary(pref.getFormattedEndTime());
    present.addPreference(endTime);

    Preference ringForContacts = new Preference(getActivity());
    ringForContacts.setTitle(R.string.contacts);
    ringForContacts.setSummary("" + pref.ringForContacts());
    present.addPreference(ringForContacts);

    Preference ringOnRepeat = new Preference(getActivity());
    ringOnRepeat.setTitle(R.string.repeat_on_ring);
    ringOnRepeat.setSummary("" + pref.ringOnRepeatCall());
    present.addPreference(ringOnRepeat);

    // Add the current state
    // Did the user change volume?
    // Did we sent the ringer volume?

    return present;
}

From source file:com.esminis.server.library.activity.DrawerFragment.java

protected void setupPreferences(PreferenceScreen screen, Context context) {
    final CheckBoxPreference preference = createPreferenceCheckbox(context, Preferences.START_ON_BOOT, false,
            R.string.server_start_on_boot_title, R.string.server_start_on_boot_summary);
    preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override/* w w  w .j  a v a 2 s  .  c  om*/
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            onPreferenceChanged(preference, newValue);
            return true;
        }
    });
    screen.addPreference(preference);
    screen.addPreference(
            requestStatusOnChange(createPreferenceCheckbox(context, Preferences.SHOW_NOTIFICATION_SERVER, true,
                    R.string.show_notification_server, R.string.show_notification_server_summary)));
}

From source file:org.chromium.chrome.browser.preferences.website.UsbDevicePreferences.java

private void resetList() {
    getPreferenceScreen().removeAll();/*from  w ww.ja  v a  2  s. co m*/
    addPreferencesFromResource(R.xml.usb_device_preferences);

    PreferenceScreen preferenceScreen = getPreferenceScreen();
    Preference header = preferenceScreen.findPreference(PREF_OBJECT_NAME);
    header.setTitle(mUsbInfo.getName());
    header.setOnPreferenceClickListener(this);

    for (int i = 0; i < mSites.size(); ++i) {
        Website site = mSites.get(i);
        Preference preference = new WebsitePreference(getActivity(), site, mCategory);
        preference.getExtras().putSerializable(SingleWebsitePreferences.EXTRA_SITE, site);
        preference.setFragment(SingleWebsitePreferences.class.getCanonicalName());
        preferenceScreen.addPreference(preference);
    }

    // Force this list to be reloaded if the activity is resumed.
    mSites = null;
}