Example usage for android.preference PreferenceCategory getPreferenceCount

List of usage examples for android.preference PreferenceCategory getPreferenceCount

Introduction

In this page you can find the example usage for android.preference PreferenceCategory getPreferenceCount.

Prototype

public int getPreferenceCount() 

Source Link

Document

Returns the number of children Preference s.

Usage

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

protected void isSupported(final PreferenceCategory preferenceCategory, final Context context, final int sId) {
    if (preferenceCategory.getPreferenceCount() == 0) {
        preferenceCategory.addPreference(createPreference(context, sId));
    }/*  w w  w .j  a va2 s .c o  m*/
}

From source file:de.wolfgang_popp.shoppinglist.activity.SettingsFragment.java

private void initSummary(Preference p) {
    if (p instanceof PreferenceCategory) {
        PreferenceCategory cat = (PreferenceCategory) p;
        for (int i = 0; i < cat.getPreferenceCount(); i++) {
            initSummary(cat.getPreference(i));
        }/*from   w  w w .  j  ava2  s .  co  m*/
    } else {
        updatePreferences(p);
    }
}

From source file:org.namelessrom.devicecontrol.device.DeviceInformationSensorFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    addPreferencesFromResource(R.xml.device_information_sensor);

    final SensorManager sensorManager = (SensorManager) Application.get()
            .getSystemService(Context.SENSOR_SERVICE);

    // Sensors/*  www. j  a  v  a2 s.  c om*/
    PreferenceCategory category = (PreferenceCategory) findPreference("sensors");

    // we need an array list to be able to sort it, a normal list throws
    // java.lang.UnsupportedOperationException when sorting
    final ArrayList<Sensor> sensorList = new ArrayList<>(sensorManager.getSensorList(Sensor.TYPE_ALL));

    Collections.sort(sensorList, new SortIgnoreCase());

    for (final Sensor s : sensorList) {
        addPreference(category, "", s.getName(), s.getVendor());
    }

    if (category.getPreferenceCount() == 0) {
        getPreferenceScreen().removePreference(category);
    }
}

From source file:com.almalence.opencam.Fragment.java

private void initSummary(Preference p) {
    if (p instanceof PreferenceCategory) {
        PreferenceCategory pCat = (PreferenceCategory) p;
        for (int i = 0; i < pCat.getPreferenceCount(); i++) {
            initSummary(pCat.getPreference(i));
        }//from ww  w  .ja  v a  2s. co m
    } else {
        updatePrefSummary(p);
    }
}

From source file:org.mozilla.gecko.fxa.activities.FxAccountStatusFragment.java

/**
 * Iterate through debug buttons, adding a special debug preference click
 * listener to each of them.//from w  w w  . ja  v a2s.c  o m
 */
protected void connectDebugButtons() {
    // Separate listener to really separate debug logic from main code paths.
    final OnPreferenceClickListener listener = new DebugPreferenceClickListener();

    // We don't want to use Android resource strings for debug UI, so we just
    // use the keys throughout.
    final PreferenceCategory debugCategory = (PreferenceCategory) ensureFindPreference("debug_category");
    debugCategory.setTitle(debugCategory.getKey());

    for (int i = 0; i < debugCategory.getPreferenceCount(); i++) {
        final Preference button = debugCategory.getPreference(i);
        button.setTitle(button.getKey()); // Not very friendly, but this is for debugging only!
        button.setOnPreferenceClickListener(listener);
    }
}

From source file:org.namelessrom.devicecontrol.device.DeviceInformationGeneralFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    addPreferencesFromResource(R.xml.device_information_general);

    final Device device = Device.get();

    // Platform//from  w  w  w. ja  va 2 s  .  com
    PreferenceCategory category = (PreferenceCategory) findPreference("platform");

    addPreference(category, KEY_PLATFORM_VERSION, R.string.version, device.platformVersion).setSelectable(true); // selectable because of the easter egg
    addPreference(category, "platform_id", R.string.build_id, device.platformId);
    addPreference(category, "platform_type", R.string.type, device.platformType);
    addPreference(category, "platform_tags", R.string.tags, device.platformTags);
    addPreference(category, "platform_build_date", R.string.build_date, device.platformBuildType);

    // Runtime
    category = (PreferenceCategory) findPreference("runtime");

    addPreference(category, "vm_library", R.string.type, device.vmLibrary);
    addPreference(category, "vm_version", R.string.version, device.vmVersion);

    // Device
    category = (PreferenceCategory) findPreference("device_information");

    // TODO: save / restore / check --> ANDROID ID
    addPreference(category, KEY_ANDROID_ID, R.string.android_id, device.androidId);
    addPreference(category, "device_manufacturer", R.string.manufacturer, device.manufacturer);
    addPreference(category, "device_model", R.string.model, device.model);
    addPreference(category, "device_product", R.string.product, device.product);
    addPreference(category, "device_board", R.string.board, device.board);
    addPreference(category, "device_bootloader", R.string.bootloader, device.bootloader);
    addPreference(category, "device_radio_version", R.string.radio_version, device.radio);

    // eMMC
    category = (PreferenceCategory) findPreference("emmc");
    addPreference(category, "emmc_name", R.string.name, Emmc.get().getName());
    addPreference(category, "emmc_cid", R.string.emmc_cid, Emmc.get().getCid());
    addPreference(category, "emmc_mid", R.string.emmc_mid, Emmc.get().getMid());
    addPreference(category, "emmc_rev", R.string.emmc_rev, Emmc.get().getRev());
    addPreference(category, "emmc_date", R.string.emmc_date, Emmc.get().getDate());
    String tmp = Emmc.get().canBrick() ? getString(R.string.emmc_can_brick_true)
            : getString(R.string.emmc_can_brick_false);
    tmp = String.format("%s\n%s", tmp, getString(R.string.press_learn_more));
    addPreference(category, "emmc_can_brick", R.string.emmc_can_brick, tmp).setSelectable(true);

    // Processor
    category = (PreferenceCategory) findPreference("processor");

    final String cpuAbi = getString(R.string.cpu_abi);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final int bitResId = Build.SUPPORTED_64_BIT_ABIS.length == 0 ? R.string.bit_32 : R.string.bit_64;
        addPreference(category, "cpu_bit", R.string.arch, getString(bitResId));
        for (int i = 0; i < Build.SUPPORTED_ABIS.length; i++) {
            addPreference(category, String.format("cpu_abi%s", i + 1), cpuAbi + String.valueOf(i + 1),
                    Build.SUPPORTED_ABIS[i]);
        }
    } else {
        //noinspection deprecation
        addPreference(category, "cpu_abi", cpuAbi, Build.CPU_ABI);
        //noinspection deprecation
        addPreference(category, "cpu_abi2", cpuAbi + "2", Build.CPU_ABI2);
    }
    new CpuInfoTask(category).execute();

    // Kernel
    category = (PreferenceCategory) findPreference("kernel");
    new KernelInfoTask(category).execute();

    // Memory
    category = (PreferenceCategory) findPreference("memory");
    new MemoryInfoTask(category).execute();

    if (category.getPreferenceCount() == 0) {
        getPreferenceScreen().removePreference(category);
    }
}