Example usage for android.preference PreferenceCategory removePreference

List of usage examples for android.preference PreferenceCategory removePreference

Introduction

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

Prototype

public boolean removePreference(Preference preference) 

Source Link

Document

Removes a Preference from this group.

Usage

From source file:com.cyanogenmod.settings.device.GeneralFragment.java

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

    if (!isSupported())
        return;//  w w  w.ja va  2  s  . co m

    addPreferencesFromResource(R.xml.general);
    //setModePrefTitle(null);

    //

    mBlnPreference = findPreference("touch_blink_preference");

    if (!BlnActivity.isSupported()) {
        PreferenceCategory category = (PreferenceCategory) getPreferenceScreen()
                .findPreference("touch_lights_preference_category");
        category.removePreference(mBlnPreference);
        //getPreferenceScreen().removePreference(category);
    } else
        updateBlnSummary();

}

From source file:de.grobox.blitzmail.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

    // recreate send now preference
    PreferenceCategory cat = (PreferenceCategory) findPreference("pref_sending");
    if (cat.findPreference("pref_send_now") != null) {
        cat.removePreference(findPreference("pref_send_now"));
    }/* w  ww.  j a v  a2  s  .c  o  m*/
    addSendNowPref(this);
}

From source file:com.nghianh.giaitriviet.fragment.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.activity_settings);

    // open play store page
    Preference preferencerate = findPreference("rate");
    preferencerate.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override//from  w  w  w  .  j  a  v  a 2 s . c o m
        public boolean onPreferenceClick(Preference preference) {
            Uri uri = Uri.parse("market://details?id=" + getActivity().getPackageName());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getActivity(), "Could not open Play Store", Toast.LENGTH_SHORT).show();
                return true;
            }
            return true;
        }
    });

    final ServiceStarter alarm = new ServiceStarter();

    // open default page
    Preference preferenceservice = findPreference("switchRss");

    String push = getString(R.string.rss_push_url);
    if (null == push || push.equals("")) {
        PreferenceCategory general = (PreferenceCategory) findPreference("general");
        general.removePreference(preferenceservice);
    }

    preferenceservice.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @SuppressLint("CommitPrefEdits")
        @Override
        public boolean onPreferenceChange(Preference preference, Object newvalue) {
            boolean switched = ((SwitchPreference) preference).isChecked();

            if (switched == false) {
                alarm.setAlarm(getActivity());
            } else {
                alarm.cancelAlarm(getActivity());
            }
            return true;
        }

    });

    // open about dialog
    Preference preferenceabout = findPreference("about");
    preferenceabout.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AlertDialog.Builder ab = null;
            ab = new AlertDialog.Builder(getActivity());
            ab.setMessage(Html.fromHtml(getResources().getString(R.string.about_text)));
            ab.setPositiveButton(getResources().getString(R.string.ok), null);
            ab.setTitle(getResources().getString(R.string.about_header));
            ab.show();
            return true;
        }
    });

    // purchase
    preferencepurchase = findPreference("purchase");
    String license = getResources().getString(R.string.google_play_license);
    if (null != license && !license.equals("")) {
        bp = new BillingProcessor(getActivity(), license, this);
        bp.loadOwnedPurchasesFromGoogle();

        preferencepurchase.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                bp.purchase(getActivity(), PRODUCT_ID());
                return true;
            }
        });

        if (getIsPurchased(getActivity())) {
            preferencepurchase.setIcon(R.drawable.ic_action_action_done);
        }
    } else {
        PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preferenceScreen");
        PreferenceCategory billing = (PreferenceCategory) findPreference("billing");
        preferenceScreen.removePreference(billing);
    }

    String[] extra = getArguments().getStringArray(MainActivity.FRAGMENT_DATA);
    if (null != extra && extra.length != 0 && extra[0].equals(SHOW_DIALOG)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Add the buttons
        builder.setPositiveButton(R.string.settings_purchase, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                bp.purchase(getActivity(), PRODUCT_ID());
            }
        });
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });
        builder.setTitle(getResources().getString(R.string.dialog_purchase_title));
        builder.setMessage(getResources().getString(R.string.dialog_purchase));

        // Create the AlertDialog
        dialog = builder.create();
        dialog.show();
    }

    if (HIDE_RATE_MY_APP) {
        PreferenceCategory other = (PreferenceCategory) findPreference("other");
        Preference preference = findPreference("rate");
        other.removePreference(preference);
    }

}

From source file:com.alusorstroke.jjvm.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.activity_settings);

    // open play store page
    Preference preferencerate = findPreference("rate");
    preferencerate.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override/*from   ww  w .j av a 2s. co  m*/
        public boolean onPreferenceClick(Preference preference) {
            Uri uri = Uri.parse("market://details?id=" + getActivity().getPackageName());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getActivity(), "Could not open Play Store", Toast.LENGTH_SHORT).show();
                return true;
            }
            return true;
        }
    });

    final ServiceStarter alarm = new ServiceStarter();

    // open default page
    Preference preferenceservice = findPreference("switchRss");

    String push = getString(R.string.rss_push_url);
    if (null == push || push.equals("")) {
        PreferenceCategory general = (PreferenceCategory) findPreference("general");
        general.removePreference(preferenceservice);
    }

    preferenceservice.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @SuppressLint("CommitPrefEdits")
        @Override
        public boolean onPreferenceChange(Preference preference, Object newvalue) {
            boolean switched = ((SwitchPreference) preference).isChecked();

            if (switched == false) {
                alarm.setAlarm(getActivity());
            } else {
                alarm.cancelAlarm(getActivity());
            }
            return true;
        }

    });

    // open about dialog
    Preference preferenceabout = findPreference("about");
    preferenceabout.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AlertDialog.Builder ab = null;
            ab = new AlertDialog.Builder(getActivity());
            ab.setMessage(Html.fromHtml(getResources().getString(R.string.about_text)));
            ab.setPositiveButton(getResources().getString(R.string.ok), null);
            ab.setTitle(getResources().getString(R.string.about_header));
            ab.show();
            return true;
        }
    });

    // purchase
    preferencepurchase = findPreference("purchase");
    String license = getResources().getString(R.string.google_play_license);
    if (null != license && !license.equals("")) {
        bp = new BillingProcessor(getActivity(), license, this);
        bp.loadOwnedPurchasesFromGoogle();

        preferencepurchase.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                bp.purchase(getActivity(), PRODUCT_ID());
                return true;
            }
        });

        if (getIsPurchased(getActivity())) {
            preferencepurchase.setIcon(R.drawable.ic_action_action_done);
        }
    } else {
        PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preferenceScreen");
        PreferenceCategory billing = (PreferenceCategory) findPreference("billing");
        preferenceScreen.removePreference(billing);
    }

    String[] extra = getArguments().getStringArray(MainActivity.FRAGMENT_DATA);
    if (null != extra && extra.length != 0 && extra[0].equals(SHOW_DIALOG)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Add the buttons
        builder.setPositiveButton(R.string.settings_purchase, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                bp.purchase(getActivity(), PRODUCT_ID());
            }
        });
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });
        builder.setTitle(getResources().getString(R.string.dialog_purchase_title));
        builder.setMessage(getResources().getString(R.string.dialog_purchase));

        // Create the AlertDialog
        dialog = builder.create();
        dialog.show();
    }

    if (HIDE_RATE_MY_APP) {
        PreferenceCategory other = (PreferenceCategory) findPreference("other");
        Preference preference = (Preference) findPreference("rate");
        other.removePreference(preference);
    }

}

From source file:com.richard.dcc.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.activity_settings);

    // open play store page
    Preference preferencerate = findPreference("rate");
    preferencerate.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override/*from   ww w .  j  a  v  a2s .c o m*/
        public boolean onPreferenceClick(Preference preference) {
            Uri uri = Uri.parse("market://details?id=" + getActivity().getPackageName());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
                startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getActivity(), "Could not open Play Store", Toast.LENGTH_SHORT).show();
                return true;
            }
            return true;
        }
    });

    // open about dialog
    Preference preferenceabout = findPreference("about");
    preferenceabout.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AlertDialog.Builder ab = null;
            ab = new AlertDialog.Builder(getActivity());
            ab.setMessage(Html.fromHtml(getResources().getString(R.string.about_text)));
            ab.setPositiveButton(getResources().getString(R.string.ok), null);
            ab.setTitle(getResources().getString(R.string.about_header));
            ab.show();
            return true;
        }
    });

    // purchase
    preferencepurchase = findPreference("purchase");
    String license = getResources().getString(R.string.google_play_license);
    if (null != license && !license.equals("")) {
        bp = new BillingProcessor(getActivity(), license, this);
        bp.loadOwnedPurchasesFromGoogle();

        preferencepurchase.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                bp.purchase(getActivity(), PRODUCT_ID());
                return true;
            }
        });

        if (getIsPurchased(getActivity())) {
            preferencepurchase.setIcon(R.drawable.ic_action_action_done);
        }
    } else {
        PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preferenceScreen");
        PreferenceCategory billing = (PreferenceCategory) findPreference("billing");
        preferenceScreen.removePreference(billing);
    }

    String[] extra = getArguments().getStringArray(MainActivity.FRAGMENT_DATA);
    if (null != extra && extra.length != 0 && extra[0].equals(SHOW_DIALOG)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Add the buttons
        builder.setPositiveButton(R.string.settings_purchase, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                bp.purchase(getActivity(), PRODUCT_ID());
            }
        });
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                // User cancelled the dialog
            }
        });
        builder.setTitle(getResources().getString(R.string.dialog_purchase_title));
        builder.setMessage(getResources().getString(R.string.dialog_purchase));

        // Create the AlertDialog
        dialog = builder.create();
        dialog.show();
    }

    if (HIDE_RATE_MY_APP) {
        PreferenceCategory other = (PreferenceCategory) findPreference("other");
        Preference preference = (Preference) findPreference("rate");
        other.removePreference(preference);
    }

}

From source file:org.runnerup.view.SettingsActivity.java

public void onCreate(Bundle savedInstanceState) {
    Resources res = getResources();
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
    setContentView(R.layout.settings_wrapper);
    {/*from   ww  w. ja  v a  2 s  .c o  m*/
        Preference btn = findPreference(res.getString(R.string.pref_exportdb));
        btn.setOnPreferenceClickListener(onExportClick);
    }
    {
        Preference btn = findPreference(res.getString(R.string.pref_importdb));
        btn.setOnPreferenceClickListener(onImportClick);
    }
    {
        Preference btn = findPreference(res.getString(R.string.pref_prunedb));
        btn.setOnPreferenceClickListener(onPruneClick);
    }
    {
        //Currently unused, should maybe be removed?
        getPreferenceManager().findPreference(res.getString(R.string.pref_experimental_features))
                .setEnabled(false);
    }

    //remove google play notices from froyo since we do not use it
    if (BuildConfig.FLAVOR.equals("froyo") || !AboutPreference.isGooglePlayServicesAvailable(this)) {
        Preference pref = findPreference(res.getString(R.string.pref_googleplayserviceslegalnotices));
        PreferenceCategory category = (PreferenceCategory) findPreference(
                res.getString(R.string.pref_aboutcategory));
        category.removePreference(pref);
    }

    //Geoid correction is not included in Froyo
    if (BuildConfig.FLAVOR.equals("froyo")) {
        getPreferenceManager().findPreference(res.getString(R.string.pref_altitude_adjust)).setEnabled(false);
        getPreferenceScreen().removePreference(getPreferenceManager().findPreference("map_preferencescreen"));
        getPreferenceScreen().removePreference(getPreferenceManager().findPreference("graph_preferencescreen"));
    }

    if (!hasHR(this)) {
        getPreferenceManager().findPreference(res.getString(R.string.cue_configure_hrzones)).setEnabled(false);
        getPreferenceManager().findPreference(res.getString(R.string.pref_battery_level_low_threshold))
                .setEnabled(false);
        getPreferenceManager().findPreference(res.getString(R.string.pref_battery_level_high_threshold))
                .setEnabled(false);
    }

}

From source file:com.amaze.carbonfilemanager.fragments.preference_fragments.Preffrag.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    utilsProvider = (UtilitiesProviderInterface) getActivity();

    PreferenceUtils.reset();//from  w  ww  . j a  v  a2s .c o  m
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    for (String PREFERENCE_KEY : PREFERENCE_KEYS) {
        findPreference(PREFERENCE_KEY).setOnPreferenceClickListener(this);
    }

    gplus = (CheckBox) findPreference("plus_pic");

    if (BuildConfig.IS_VERSION_FDROID)
        gplus.setEnabled(false);

    // crypt master password
    final EditTextPreference masterPasswordPreference = (EditTextPreference) findPreference(
            PREFERENCE_CRYPT_MASTER_PASSWORD);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        // encryption feature not available
        masterPasswordPreference.setEnabled(false);
    }

    if (sharedPref.getBoolean(PREFERENCE_CRYPT_FINGERPRINT, false)) {
        masterPasswordPreference.setEnabled(false);
    }

    CheckBox checkBoxFingerprint = (CheckBox) findPreference(PREFERENCE_CRYPT_FINGERPRINT);

    try {

        // finger print sensor
        final FingerprintManager fingerprintManager = (FingerprintManager) getActivity()
                .getSystemService(Context.FINGERPRINT_SERVICE);

        final KeyguardManager keyguardManager = (KeyguardManager) getActivity()
                .getSystemService(Context.KEYGUARD_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager.isHardwareDetected()) {

            checkBoxFingerprint.setEnabled(true);
        }

        checkBoxFingerprint.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {

                if (ActivityCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_no_permission),
                            Toast.LENGTH_LONG).show();
                    return false;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                        && !fingerprintManager.hasEnrolledFingerprints()) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_not_enrolled),
                            Toast.LENGTH_LONG).show();
                    return false;
                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                        && !keyguardManager.isKeyguardSecure()) {
                    Toast.makeText(getActivity(),
                            getResources().getString(R.string.crypt_fingerprint_no_security), Toast.LENGTH_LONG)
                            .show();
                    return false;
                }

                masterPasswordPreference.setEnabled(false);
                return true;
            }
        });
    } catch (NoClassDefFoundError error) {
        error.printStackTrace();

        // fingerprint manager class not defined in the framework
        checkBoxFingerprint.setEnabled(false);
    }

    // Hide root preference
    Preference mRootMode = findPreference("rootmode");
    PreferenceCategory mMisc = (PreferenceCategory) findPreference("misc");
    mMisc.removePreference(mRootMode);

}

From source file:com.todoroo.astrid.sync.SyncProviderPreferences.java

/**
 *
 * @param resource/*ww w  . ja  va 2  s. co  m*/
 *            if null, updates all resources
 */
@Override
public void updatePreferences(Preference preference, Object value) {
    final Resources r = getResources();

    // interval
    if (r.getString(getUtilities().getSyncIntervalKey()).equals(preference.getKey())) {
        int index = AndroidUtilities.indexOf(r.getStringArray(R.array.sync_SPr_interval_values),
                (String) value);
        if (index <= 0)
            preference.setSummary(R.string.sync_SPr_interval_desc_disabled);
        else
            preference.setSummary(r.getString(R.string.sync_SPr_interval_desc,
                    r.getStringArray(R.array.sync_SPr_interval_entries)[index]));
    }

    // status
    else if (r.getString(R.string.sync_SPr_status_key).equals(preference.getKey())) {
        boolean loggedIn = getUtilities().isLoggedIn();
        String status;
        //String subtitle = ""; //$NON-NLS-1$

        // ! logged in - display message, click -> sync
        if (!loggedIn) {
            status = r.getString(R.string.sync_status_loggedout);
            statusColor = Color.rgb(19, 132, 165);
        }
        // sync is occurring
        else if (getUtilities().isOngoing()) {
            status = r.getString(R.string.sync_status_ongoing);
            statusColor = Color.rgb(0, 0, 100);
        }
        // last sync had errors
        else if (getUtilities().getLastError() != null || getUtilities().getLastAttemptedSyncDate() != 0) {
            // last sync was failure
            if (getUtilities().getLastAttemptedSyncDate() != 0) {
                status = r.getString(R.string.sync_status_failed, DateUtilities.getDateStringWithTime(
                        SyncProviderPreferences.this, new Date(getUtilities().getLastAttemptedSyncDate())));
                statusColor = Color.rgb(100, 0, 0);

                if (getUtilities().getLastSyncDate() > 0) {
                    //                        subtitle = r.getString(R.string.sync_status_failed_subtitle,
                    //                                DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
                    //                                        new Date(getUtilities().getLastSyncDate())));
                }
            } else {
                long lastSyncDate = getUtilities().getLastSyncDate();
                String dateString = lastSyncDate > 0
                        ? DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
                                new Date(lastSyncDate))
                        : ""; //$NON-NLS-1$
                status = r.getString(R.string.sync_status_errors, dateString);
                statusColor = Color.rgb(100, 100, 0);
            }
        } else if (getUtilities().getLastSyncDate() > 0) {
            status = r.getString(R.string.sync_status_success, DateUtilities.getDateStringWithTime(
                    SyncProviderPreferences.this, new Date(getUtilities().getLastSyncDate())));
            statusColor = Color.rgb(0, 100, 0);
        } else {
            status = r.getString(R.string.sync_status_never);
            statusColor = Color.rgb(0, 0, 100);
        }
        preference.setTitle(R.string.sync_SPr_sync);
        preference.setSummary(r.getString(R.string.sync_SPr_status_subtitle, status));

        preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference p) {
                startSync();
                return true;
            }
        });

        View view = findViewById(R.id.status);
        if (view != null)
            view.setBackgroundColor(statusColor);
    } else if (r.getString(R.string.sync_SPr_key_last_error).equals(preference.getKey())) {
        if (getUtilities().getLastError() != null) {
            // Display error
            final String service = getTitle().toString();
            final String lastErrorFull = getUtilities().getLastError();
            final String lastErrorDisplay = adjustErrorForDisplay(r, lastErrorFull, service);
            preference.setTitle(R.string.sync_SPr_last_error);
            preference.setSummary(R.string.sync_SPr_last_error_subtitle);

            preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                @SuppressWarnings("nls")
                public boolean onPreferenceClick(Preference pref) {
                    // Show last error
                    new AlertDialog.Builder(SyncProviderPreferences.this).setTitle(R.string.sync_SPr_last_error)
                            .setMessage(lastErrorDisplay)
                            .setPositiveButton(R.string.sync_SPr_send_report, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                                    emailIntent.setType("plain/text")
                                            .putExtra(Intent.EXTRA_EMAIL,
                                                    new String[] { "android-bugs@astrid.com" })
                                            .putExtra(Intent.EXTRA_SUBJECT, service + " Sync Error")
                                            .putExtra(Intent.EXTRA_TEXT, lastErrorFull);
                                    startActivity(Intent.createChooser(emailIntent,
                                            r.getString(R.string.sync_SPr_send_report)));
                                }
                            }).setNegativeButton(R.string.DLG_close, null).create().show();
                    return true;
                }
            });

        } else {
            PreferenceCategory statusCategory = (PreferenceCategory) findPreference(
                    r.getString(R.string.sync_SPr_group_status));
            statusCategory.removePreference(findPreference(r.getString(R.string.sync_SPr_key_last_error)));
        }
    }
    // log out button
    else if (r.getString(R.string.sync_SPr_forget_key).equals(preference.getKey())) {
        boolean loggedIn = getUtilities().isLoggedIn();
        preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference p) {
                DialogUtilities.okCancelDialog(SyncProviderPreferences.this,
                        r.getString(R.string.sync_forget_confirm), new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                logOut();
                                initializePreference(getPreferenceScreen());
                            }
                        }, null);
                return true;
            }
        });
        if (!loggedIn) {
            PreferenceCategory category = (PreferenceCategory) findPreference(
                    r.getString(R.string.sync_SPr_key_options));
            category.removePreference(preference);
        }

    }
}

From source file:org.namelessrom.devicecontrol.ui.fragments.preferences.MainPreferencesFragment.java

@Override
public void onCreate(final Bundle bundle) {
    super.onCreate(bundle);
    addPreferencesFromResource(R.xml._device_control);

    final DeviceConfiguration configuration = DeviceConfiguration.get(getActivity());

    mExtensiveLogging = (CustomTogglePreference) findPreference(DeviceConfiguration.EXTENSIVE_LOGGING);
    if (mExtensiveLogging != null) {
        mExtensiveLogging.setChecked(configuration.extensiveLogging);
        mExtensiveLogging.setOnPreferenceChangeListener(this);
    }/*from   ww w .ja  v a  2s . com*/

    PreferenceCategory category = (PreferenceCategory) findPreference("prefs_general");
    mSetOnBoot = (CustomPreference) findPreference("prefs_set_on_boot");

    mShowLauncher = (CustomTogglePreference) findPreference(DeviceConfiguration.SHOW_LAUNCHER);
    if (mShowLauncher != null) {
        if (Application.IS_NAMELESS) {
            mShowLauncher.setChecked(configuration.showLauncher);
            mShowLauncher.setOnPreferenceChangeListener(this);
        } else {
            category.removePreference(mShowLauncher);
        }
    }

    mSkipChecks = (CustomTogglePreference) findPreference(DeviceConfiguration.SKIP_CHECKS);
    if (mSkipChecks != null) {
        mSkipChecks.setChecked(configuration.skipChecks);
        mSkipChecks.setOnPreferenceChangeListener(this);
    }

    category = (PreferenceCategory) findPreference("prefs_app");

    if (Utils.existsInFile(Scripts.BUILD_PROP, "ro.nameless.secret=1")) {
        mMonkeyPref = new CustomTogglePreference(getActivity());
        mMonkeyPref.setKey(DeviceConfiguration.MONKEY);
        mMonkeyPref.setTitle(R.string.become_a_monkey);
        mMonkeyPref.setSummaryOn(R.string.is_monkey);
        mMonkeyPref.setSummaryOff(R.string.no_monkey);
        mMonkeyPref.setChecked(DeviceConfiguration.get(getActivity()).monkey);
        mMonkeyPref.setOnPreferenceChangeListener(this);
        category.addPreference(mMonkeyPref);
    }

    mDarkTheme = (CustomTogglePreference) findPreference(DeviceConfiguration.DARK_THEME);
    mDarkTheme.setChecked(Application.get().isDarkTheme());
    mDarkTheme.setOnPreferenceChangeListener(this);

    mSwipeOnContent = (CustomTogglePreference) findPreference(DeviceConfiguration.SWIPE_ON_CONTENT);
    mSwipeOnContent.setChecked(configuration.swipeOnContent);
    mSwipeOnContent.setOnPreferenceChangeListener(this);

    mShowPollfish = (CustomTogglePreference) findPreference(DeviceConfiguration.SHOW_POLLFISH);
    mShowPollfish.setChecked(configuration.showPollfish);
    mShowPollfish.setOnPreferenceChangeListener(this);

    setupVersionPreference();
}

From source file:jackpal.androidterm.TermPreferences.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    final TermSettings settings = new TermSettings(getResources(), mPrefs);
    if (mFirst && settings.getColorTheme() == 0)
        setTheme(R.style.Theme_AppCompat);
    mFirst = false;//from ww w.  j a v  a2  s  .  co  m
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
    if (FLAVOR_VIM) {
        addPreferencesFromResource(R.xml.preferences_apps);

        Resources res = getResources();
        String[] array = res.getStringArray(R.array.entries_app_filepicker_preference);

        OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Resources res = getResources();
                String[] array = res.getStringArray(R.array.entries_app_filepicker_preference);
                int value = Integer.valueOf((String) newValue);
                String summary = array[value];
                preference.setSummary(summary);
                return true;
            }
        };

        String id = "cloud_dropbox_filepicker";
        Preference filePicker = findPreference(id);
        String summary = array[settings.getDropboxFilePicker()];
        filePicker.setSummary(summary);
        filePicker.setOnPreferenceChangeListener(listener);

        id = "cloud_googledrive_filepicker";
        filePicker = findPreference(id);
        summary = array[settings.getGoogleDriveFilePicker()];
        filePicker.setSummary(summary);
        filePicker.setOnPreferenceChangeListener(listener);

        id = "cloud_onedrive_filepicker";
        filePicker = findPreference(id);
        summary = array[settings.getOneDriveFilePicker()];
        filePicker.setSummary(summary);
        filePicker.setOnPreferenceChangeListener(listener);

        id = "external_app_button";
        filePicker = findPreference(id);
        final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        OnPreferenceChangeListener AppButtonListener = new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                sp.edit().putBoolean(EXTERNAL_APP_BUTTON, (Boolean) newValue).apply();
                return true;
            }
        };
        filePicker.setOnPreferenceChangeListener(AppButtonListener);

        id = "external_app_package_name";
        Preference pref = getPreferenceScreen().findPreference(id);
        String appId = mPrefs.getString(id, "");
        setAppPickerLabel(pref, appId);
        new Thread() {
            @Override
            public void run() {
                setAppPickerList();
            }
        }.start();
        pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                setAppPickerLabel(preference, (String) newValue);
                return true;
            }
        });

    }

    if (AndroidCompat.SDK >= 19) {
        addPreferencesFromResource(R.xml.preferences_prefs);
        final String PREFS_KEY = "prefs_rw";
        Preference prefsPicker = getPreferenceScreen().findPreference(PREFS_KEY);
        prefsPicker.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                prefsPicker();
                return true;
            }
        });

        final String LICENSE_KEY = "license";
        Preference licensePrefs = getPreferenceScreen().findPreference(LICENSE_KEY);
        licensePrefs.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                licensePrefs();
                return true;
            }
        });
    }

    // Remove the action bar pref on older platforms without an action bar
    Preference actionBarPref = findPreference(ACTIONBAR_KEY);
    PreferenceCategory screenCategory = (PreferenceCategory) findPreference(CATEGORY_SCREEN_KEY);
    if ((actionBarPref != null) && (screenCategory != null)) {
        screenCategory.removePreference(actionBarPref);
    }

    Preference statusBarPref = findPreference(STATUSBAR_KEY);
    if ((statusBarPref != null) && (screenCategory != null)) {
        screenCategory.removePreference(statusBarPref);
    }

    PreferenceCategory keyboardCategory = (PreferenceCategory) findPreference("categoryKeyboard");
    Preference controlKeyPref = findPreference("controlkey");
    if ((controlKeyPref != null) && (keyboardCategory != null)) {
        keyboardCategory.removePreference(controlKeyPref);
    }
    Preference fnKeyPref = findPreference("fnkey");
    if ((fnKeyPref != null) && (keyboardCategory != null)) {
        keyboardCategory.removePreference(fnKeyPref);
    }

    if (FLAVOR_VIM) {
        findPreference("functionbar_vim_paste").setDefaultValue(true);
    }

    // FIXME:
    if (AndroidCompat.SDK < 19 && !new File(FONTPATH).exists())
        new File(FONTPATH).mkdirs();
    Preference fontPicker = getPreferenceScreen().findPreference("fontfile_picker");
    fontPicker.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            filePicker();
            return true;
        }
    });

    ListPreference fontFileList = (ListPreference) getPreferenceScreen().findPreference("fontfile");
    setFontList(fontFileList);

    Preference fontSelect = findPreference("fontfile");
    Resources res = getResources();
    fontSelect
            .setSummary(res.getString(R.string.summary_fontfile_preference) + String.format(" (%s)", FONTPATH));
    fontSelect.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            ListPreference fontFileList = (ListPreference) preference;
            setFontList(fontFileList);
            return true;
        }
    });

    fontSelect.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            ListPreference fontFileList = (ListPreference) preference;
            setFontList(fontFileList);
            fontFileList.setDefaultValue(newValue);
            return true;
        }
    });

    PreferenceCategory textCategory = (PreferenceCategory) findPreference(CATEGORY_TEXT_KEY);
    Preference fontPref;
    if (AndroidCompat.SDK >= 19) {
        fontPref = findPreference("fontfile");
    } else {
        fontPref = findPreference("fontfile_picker");
    }
    if ((fontPref != null) && (textCategory != null)) {
        textCategory.removePreference(fontPref);
    }

}