Example usage for android.preference PreferenceScreen getPreference

List of usage examples for android.preference PreferenceScreen getPreference

Introduction

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

Prototype

public Preference getPreference(int index) 

Source Link

Document

Returns the Preference at a particular index.

Usage

From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    PreferenceScreen screen = getPreferenceScreen();
    int count = screen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        Preference pref = screen.getPreference(i);
        setSummary(pref);//from  w w w  .j av  a  2 s  . c  o m
        pref.setOnPreferenceChangeListener(this);
    }
    getPreferenceManager().getSharedPreferences()
            .registerOnSharedPreferenceChangeListener(mGlobalChangeListener);
}

From source file:com.jmstudios.redmoon.fragment.ShadesFragment.java

private void setAllPreferencesEnabled(boolean enabled) {
    PreferenceScreen root = getPreferenceScreen();
    for (int i = 0; i < root.getPreferenceCount(); i++) {
        root.getPreference(i).setEnabled(enabled);
    }/*from   w  w  w  .j  av  a2s . c o  m*/
}

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

protected void setupPreferencesValues(PreferenceScreen screen, Context context) {
    final Map<String, Boolean> values = preferences.getBooleans(context);
    final Map<String, Boolean> valuesSave = new HashMap<>();
    for (int i = 0; i < screen.getPreferenceCount(); i++) {
        Preference preference = screen.getPreference(i);
        if (preference instanceof CheckBoxPreference) {
            if (values.containsKey(preference.getKey())) {
                ((CheckBoxPreference) preference).setChecked(values.get(preference.getKey()));
            } else {
                valuesSave.put(preference.getKey(), ((CheckBoxPreference) preference).isChecked());
            }// www .j a v a  2 s  .  c o  m
        }
    }
    preferences.setBooleans(context, valuesSave);
}

From source file:com.rareventure.gps2.reviewer.SettingsActivity.java

@Override
public void doOnResume() {
    super.doOnResume();
    enablePassword.setChecked(!GpsTrailerCrypt.prefs.isNoPassword);
    isCollectData.setChecked(GTG.prefs.isCollectData);
    percTimeGpsOn.setValue(GpsTrailerGpsStrategy.prefs.batteryGpsOnTimePercentage * 100);
    minBatteryLife.setValue(GTG.prefs.minBatteryPerc * 100);
    enableToolTips.setChecked(OsmMapGpsTrailerReviewerMapActivity.prefs.enableToolTips);
    mapFontSize.setValue(OsmMapGpsTrailerReviewerMapActivity.prefs.panelScale);
    passwordTimeout.setValue(getPasswordTimeoutFromMS(GTG.prefs.passwordTimeoutMS));

    passwordTimeout.setEnabled(enablePassword.isChecked());

    //co: we no longer allow access to application after expiry (so we can justify not
    // serving tiles without a valid license)
    //        if(GTG.isTrialPeriodExpired())
    //        {//from  w  w  w .j a  v a2s  .c  o  m
    //           isCollectData.setEnabled(false);
    //           isCollectData.setChecked(false);
    //        }

    if (GTG.lastSuccessfulAction == GTGAction.TOOL_TIP_CLICKED) {
        GTG.lastSuccessfulAction = null;

        //scroll done to tool tip option
        ViewTreeObserver vto = getListView().getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {

                PreferenceScreen screen = getPreferenceScreen();
                int i;
                for (i = 0; i < screen.getPreferenceCount(); i++) {
                    Preference p = screen.getPreference(i);

                    if (p == enableToolTips)
                        break;
                }

                getListView().setSelection(i);

                getListView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });

    }

}

From source file:de.j4velin.wifiAutoOff.Preferences.java

@SuppressLint("NewApi")
@Override/*from w ww . j ava 2  s  . c  o m*/
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        CompoundButton enable = (CompoundButton) menu.findItem(R.id.enable).getActionView();
        if (android.os.Build.VERSION.SDK_INT < 14) {
            enable.setText("Enable");
        }
        enable.setChecked(getPackageManager().getComponentEnabledSetting(
                new ComponentName(this, Receiver.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
        // disable initially if not checked
        if (!enable.isChecked()) {
            @SuppressWarnings("deprecation")
            PreferenceScreen ps = getPreferenceScreen();
            for (int i = 0; i < ps.getPreferenceCount(); i++) {
                ps.getPreference(i).setEnabled(false);
            }
        }
        enable.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                @SuppressWarnings("deprecation")
                PreferenceScreen ps = getPreferenceScreen();
                // start at 1 to skip "status" preference
                for (int i = 1; i < ps.getPreferenceCount(); i++) {
                    ps.getPreference(i).setEnabled(isChecked);
                }
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, Receiver.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
                if (!isChecked)
                    stopService(new Intent(Preferences.this, ScreenChangeDetector.class));
                getPackageManager().setComponentEnabledSetting(
                        new ComponentName(Preferences.this, ScreenChangeDetector.class),
                        isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
        });
    }
    return true;
}

From source file:com.ichi2.anki.PreferenceContext.java

/**
 * Loop over every preference in the list and set the summary text
 *///  w  w w  .  ja  v a 2s .c om
private void initAllPreferences(PreferenceScreen screen) {
    for (int i = 0; i < screen.getPreferenceCount(); ++i) {
        Preference preference = screen.getPreference(i);
        if (preference instanceof PreferenceGroup) {
            PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
            for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                Preference nestedPreference = preferenceGroup.getPreference(j);
                if (nestedPreference instanceof PreferenceGroup) {
                    PreferenceGroup nestedPreferenceGroup = (PreferenceGroup) nestedPreference;
                    for (int k = 0; k < nestedPreferenceGroup.getPreferenceCount(); ++k) {
                        initPreference(nestedPreferenceGroup.getPreference(k));
                    }
                } else {
                    initPreference(preferenceGroup.getPreference(j));
                }
            }
        } else {
            initPreference(preference);
        }
    }
}

From source file:at.jclehner.rxdroid.DrugEditFragment.java

private void performPreferenceClick(String key) {
    final PreferenceScreen ps = getPreferenceScreen();
    for (int i = 0; i != ps.getPreferenceCount(); ++i) {
        if (key.equals(ps.getPreference(i).getKey())) {
            ps.onItemClick(getListView(), null, i, 0);
            break;
        }/*  w w w.j  a v a  2 s  .com*/
    }
}