Java Code Examples for android.support.v7.preference.PreferenceScreen#removePreference()

The following examples show how to use android.support.v7.preference.PreferenceScreen#removePreference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsActivity.java    From bitcoinpos with MIT License 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String s) {
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

    // Set preferences' values to summaries by reusing onSharedPreferenceChanged
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    onSharedPreferenceChanged(mSharedPreferences, getString(R.string.merchant_name_key));
    onSharedPreferenceChanged(mSharedPreferences, getString(R.string.btc_payment_address_key));
    onSharedPreferenceChanged(mSharedPreferences, getString(R.string.bch_payment_address_key));
    onSharedPreferenceChanged(mSharedPreferences, getString(R.string.ltc_payment_address_key));
    onSharedPreferenceChanged(mSharedPreferences, getString(R.string.local_currency_key));
    onSharedPreferenceChanged(mSharedPreferences, getString(R.string.accept_testnet_key));

    testnetStatus = mSharedPreferences.getBoolean(getString(R.string.accept_testnet_key), false);

    if(testnetStatus){
        onSharedPreferenceChanged(mSharedPreferences, getString(R.string.btc_test_payment_address_key));
    }
    else {
        PreferenceScreen screen = getPreferenceScreen();
        Preference pref = getPreferenceManager().findPreference(getString(R.string.btc_test_payment_address_key));
        if(pref!=null){
        screen.removePreference(pref);
        }
    }

}
 
Example 2
Source File: SmsMmsPreferenceFragment.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private void initializePlatformSpecificOptions() {
  PreferenceScreen preferenceScreen    = getPreferenceScreen();
  Preference       defaultPreference   = findPreference(KITKAT_DEFAULT_PREF);
  Preference       allSmsPreference    = findPreference(SilencePreferences.ALL_SMS_PREF);
  Preference       allMmsPreference    = findPreference(SilencePreferences.ALL_MMS_PREF);
  Preference       manualMmsPreference = findPreference(MMS_PREF);

  if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
    if (allSmsPreference != null) preferenceScreen.removePreference(allSmsPreference);
    if (allMmsPreference != null) preferenceScreen.removePreference(allMmsPreference);

    if (Util.isDefaultSmsProvider(getActivity())) {
      defaultPreference.setIntent(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
      defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_enabled));
      defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_tap_to_change_your_default_sms_app));
    } else {
      Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
      intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getActivity().getPackageName());
      defaultPreference.setIntent(intent);
      defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_disabled));
      defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_tap_to_make_silence_your_default_sms_app));
    }
  } else if (defaultPreference != null) {
    preferenceScreen.removePreference(defaultPreference);
  }

  if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && manualMmsPreference != null) {
    preferenceScreen.removePreference(manualMmsPreference);
  }
}
 
Example 3
Source File: AppProtectionPreferenceFragment.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private void initializePlatformSpecificOptions() {
  PreferenceScreen preferenceScreen         = getPreferenceScreen();
  Preference       screenSecurityPreference = findPreference(SilencePreferences.SCREEN_SECURITY_PREF);

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
      screenSecurityPreference != null) {
    preferenceScreen.removePreference(screenSecurityPreference);
  }
}
 
Example 4
Source File: SettingsFragment.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
private void initPreferenceForConsent() {
    boolean isSignedInAndConsented = DataProvider.getInstance().isSignedIn(getActivity()) &&
            DataProvider.getInstance().isConsented(getActivity());

    PreferenceScreen screen = getPreferenceScreen();

    if (!isSignedInAndConsented) {
        screen.removePreference(profileCategory);
        privacyCategory.removePreference(sharingScope);
        generalCategory.removePreference(leaveStudy);

        // This method will be called if we leave the study. This means we need to add
        // "join study" back into the general-category as it was removed on the initial call of
        // this method
        if (generalCategory.findPreference(KEY_JOIN_STUDY) == null) {
            generalCategory.addPreference(joinStudy);
        }
    } else {
        generalCategory.removePreference(joinStudy);

        Observable.defer(() -> Observable.just(DataProvider.getInstance()
                .getUser(getActivity())))
                .compose(ObservableUtils.applyDefault())
                .subscribe(profile -> {
                    if (profile == null) {
                        getPreferenceScreen().removePreference(profileCategory);
                        return;

                    }

                    Preference namePref = profileCategory.findPreference(KEY_PROFILE_NAME);
                    if (profile.getName() != null) {
                        namePref.setSummary(profile.getName());
                    } else {
                        profileCategory.removePreference(namePref);
                    }

                    Preference birthdatePref = profileCategory.findPreference(
                            KEY_PROFILE_BIRTHDATE);
                    if (profile.getBirthDate() != null) {
                        try {
                            // The incoming date is formated in "yyyy-MM-dd", clean it up to "MMM dd, yyyy"
                            Date birthdate = FormatHelper.SIMPLE_FORMAT_DATE.parse(profile.getBirthDate());
                            DateFormat format = FormatHelper.getFormat(DateFormat.LONG,
                                    FormatHelper.NONE);
                            birthdatePref.setSummary(format.format(birthdate));
                        } catch (ParseException e) {
                            LogExt.e(SettingsFragment.class, e);
                            birthdatePref.setSummary(profile.getBirthDate());
                        }
                    } else {
                        profileCategory.removePreference(birthdatePref);
                    }
                });

        // Load Consent Data and set sharing scope
        Observable.defer(() -> Observable.just(ResourceManager.getInstance()
                .getConsentSections()
                .create(getActivity()))).flatMap((consentData) -> {
            this.data = (ConsentSectionModel) consentData;

            // Load and set sharing scope
            return Observable.just(DataProvider.getInstance()
                    .getUserSharingScope(getContext()));
        }).compose(ObservableUtils.applyDefault()).subscribe(scope -> {
            sharingScope.setSummary(formatSharingOption(scope));
        });
    }

    isInitializedForConsent = true;
}