Example usage for android.preference PreferenceScreen removePreference

List of usage examples for android.preference PreferenceScreen removePreference

Introduction

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

Prototype

public boolean removePreference(Preference preference) 

Source Link

Document

Removes a Preference from this group.

Usage

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);
    ps.addPreference(preference);//w  w  w  . jav  a  2  s  . c o  m
}

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

public void removeIfEmpty(final PreferenceScreen root, final PreferenceGroup preferenceGroup) {
    if (root != null && preferenceGroup.getPreferenceCount() == 0) {
        root.removePreference(preferenceGroup);
    }/*from ww w. j  a va2 s.  co m*/
}

From source file:org.adblockplus.android.AdvancedPreferences.java

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

    addPreferencesFromResource(R.xml.preferences_advanced);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    this.serviceBinder = new ServiceBinder(this);

    final PreferenceScreen screen = getPreferenceScreen();
    if (ProxyService.GLOBAL_PROXY_USER_CONFIGURABLE) {
        screen.removePreference(findPreference(getString(R.string.pref_proxy)));
        if (prefs.getBoolean(getString(R.string.pref_proxyautoconfigured), false)) {
            screen.removePreference(findPreference(getString(R.string.pref_proxyenabled)));
        }//from  ww  w. j  a  v a 2s. c  o  m
    }
    if (getResources().getBoolean(R.bool.def_release)) {
        screen.removePreference(findPreference(getString(R.string.pref_support)));
    } else {
        final Preference prefUpdate = findPreference(getString(R.string.pref_checkupdate));
        prefUpdate.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(final Preference preference) {
                final AdblockPlus application = AdblockPlus.getApplication();
                application.checkUpdates();
                return true;
            }
        });

        final Preference prefConfiguration = findPreference(getString(R.string.pref_configuration));
        prefConfiguration.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(final Preference preference) {
                showDialog(CONFIGURATION_DIALOG);
                return true;
            }
        });
    }
}

From source file:com.android.switchaccess.SwitchAccessPreferenceActivity.java

/**
 * @return {@code true} if preference was empty and has been removed
 *///w  w w. j  a  va  2s.  c  om
private void removeKeyAssignmentPressIfEmpty(PreferenceScreen keyAssignmentScreen, int prefKeyStringId) {
    if (!prefHasKeyAssigned(prefKeyStringId)) {
        keyAssignmentScreen.removePreference(findPreference(getString(prefKeyStringId)));
    }
}

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 w  w w . j a  v a 2 s . 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;
        }
    });

    // 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.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/*ww w. j  av a2 s .c  om*/
        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   www  .ja  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 = (Preference) findPreference("rate");
        other.removePreference(preference);
    }

}

From source file:com.android.switchaccess.SwitchAccessPreferenceActivity.java

private void adjustAutoscanPrefs() {
    if (isAutoScanEnabled(this)) {
        ListPreference scanMethodsPref = (ListPreference) findPreference(
                getString(R.string.pref_scanning_methods_key));
        String optionScanKey = getString(R.string.option_scanning_key);
        if (isOptionScanningEnabled(this)) {
            /* If somehow both autoscan and option scan are enabled, turn off option scan */
            scanMethodsPref.setValue(getString(R.string.row_col_scanning_key));
            SharedPreferencesUtils.getSharedPreferences(this).edit()
                    .putString(getString(R.string.pref_scanning_methods_key),
                            getString(R.string.row_col_scanning_key))
                    .commit();/*from w w  w  . jav a 2s. c o  m*/
        }
        ArrayList<String> entries = new ArrayList<>(
                Arrays.asList(getResources().getStringArray(R.array.switch_access_scanning_methods_entries)));
        ArrayList<String> entryValues = new ArrayList<>(
                Arrays.asList(getResources().getStringArray(R.array.switch_access_scanning_methods_values)));
        int optionScanIndex = entryValues.indexOf(optionScanKey);
        entries.remove(optionScanIndex);
        entryValues.remove(optionScanIndex);
        scanMethodsPref.setEntries(entries.toArray(new String[entries.size()]));
        scanMethodsPref.setEntryValues(entryValues.toArray(new String[entries.size()]));
    } else {
        PreferenceScreen mainPrefScreen = (PreferenceScreen) findPreference(
                getString(R.string.main_pref_screen_key));
        PreferenceScreen keyAssignmentScreen = (PreferenceScreen) findPreference(
                getString(R.string.pref_category_scan_mappings_key));
        mainPrefScreen.removePreference(findPreference(getString(R.string.pref_key_auto_scan_time_delay)));
        removeKeyAssignmentPressIfEmpty(keyAssignmentScreen, R.string.pref_key_mapped_to_auto_scan_key);
        removeKeyAssignmentPressIfEmpty(keyAssignmentScreen, R.string.pref_key_mapped_to_reverse_auto_scan_key);
        if (isOptionScanningEnabled(this)) {
            mainPrefScreen.removePreference(findPreference(getString(R.string.pref_key_auto_scan_enabled)));
        }
    }
}

From source file:org.wordpress.android.ui.prefs.SettingsFragment.java

private void hideNotificationBlogsCategory() {
    PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference(
            getActivity().getString(R.string.pref_key_settings_root));
    PreferenceCategory blogs = (PreferenceCategory) findPreference(
            getActivity().getString(R.string.pref_notification_blogs));
    if (preferenceScreen != null && blogs != null) {
        preferenceScreen.removePreference(blogs);
    }/*  ww  w.  ja v  a2  s.c  o m*/
}

From source file:org.wordpress.android.ui.prefs.SettingsFragment.java

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

    Resources resources = getResources();

    if (savedInstanceState == null) {
        AnalyticsTracker.track(AnalyticsTracker.Stat.OPENED_SETTINGS);
    }/*from   w  w  w . j  a  v a2s. c o m*/

    addPreferencesFromResource(R.xml.settings);
    OnPreferenceChangeListener preferenceChangeListener = new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue != null) { // cancelled dismiss keyboard
                preference.setSummary(newValue.toString());
            }
            ActivityUtils.hideKeyboard(getActivity());
            return true;
        }
    };

    mTaglineTextPreference = (WPEditTextPreference) findPreference(
            resources.getString(R.string.pref_key_post_sig));
    if (mTaglineTextPreference != null) {
        mTaglineTextPreference.setOnPreferenceChangeListener(preferenceChangeListener);
    }
    findPreference(resources.getString(R.string.pref_key_notifications))
            .setOnPreferenceClickListener(notificationPreferenceClickListener);
    findPreference(resources.getString(R.string.pref_key_language))
            .setOnPreferenceClickListener(languagePreferenceClickListener);
    findPreference(resources.getString(R.string.pref_key_app_about))
            .setOnPreferenceClickListener(launchActivitiyClickListener);
    findPreference(resources.getString(R.string.pref_key_oss_licenses))
            .setOnPreferenceClickListener(launchActivitiyClickListener);
    findPreference(resources.getString(R.string.pref_key_help_and_support))
            .setOnPreferenceClickListener(launchActivitiyClickListener);
    findPreference(resources.getString(R.string.pref_key_passlock))
            .setOnPreferenceChangeListener(passcodeCheckboxChangeListener);
    findPreference(resources.getString(R.string.pref_key_signout))
            .setOnPreferenceClickListener(signOutPreferenceClickListener);
    findPreference(resources.getString(R.string.pref_key_reset_shared_pref))
            .setOnPreferenceClickListener(resetAUtoSharePreferenceClickListener);

    mSettings = PreferenceManager.getDefaultSharedPreferences(getActivity());

    initNotifications();

    // Passcode Lock not supported
    if (AppLockManager.getInstance().isAppLockFeatureEnabled()) {
        final CheckBoxPreference passcodeEnabledCheckBoxPreference = (CheckBoxPreference) findPreference(
                resources.getString(R.string.pref_key_passlock));
        // disable on-click changes on the property
        passcodeEnabledCheckBoxPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                passcodeEnabledCheckBoxPreference
                        .setChecked(AppLockManager.getInstance().getCurrentAppLock().isPasswordLocked());
                return false;
            }
        });
    } else {
        PreferenceScreen rootScreen = (PreferenceScreen) findPreference(
                resources.getString(R.string.pref_key_settings_root));
        PreferenceGroup passcodeGroup = (PreferenceGroup) findPreference(
                resources.getString(R.string.pref_key_passlock_section));
        rootScreen.removePreference(passcodeGroup);
    }
    displayPreferences();
}