Java Code Examples for androidx.preference.PreferenceScreen#addPreference()

The following examples show how to use androidx.preference.PreferenceScreen#addPreference() . 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: UserRestrictionsParentDisplayFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
@RequiresApi(api = Util.R_VERSION_CODE)
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
            getPreferenceManager().getContext());
    setPreferenceScreen(preferenceScreen);

    final Context preferenceContext = getPreferenceManager().getContext();
    for (UserRestriction restriction : UserRestriction.PROFILE_OWNER_ORG_DEVICE_RESTRICTIONS) {
        DpcSwitchPreference preference = new DpcSwitchPreference(preferenceContext);
        preference.setTitle(restriction.titleResId);
        preference.setKey(restriction.key);
        preference.setOnPreferenceChangeListener(this);
        preferenceScreen.addPreference(preference);
    }

    updateAllUserRestrictions();
    constrainPreferences();
}
 
Example 2
Source File: UserRestrictionsDisplayFragment.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle bundle, String rootkey) {
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
            getPreferenceManager().getContext());
    setPreferenceScreen(preferenceScreen);

    final Context preferenceContext = getPreferenceManager().getContext();
    for (UserRestriction restriction : UserRestriction.ALL_USER_RESTRICTIONS) {
        DpcSwitchPreference preference = new DpcSwitchPreference(preferenceContext);
        preference.setTitle(restriction.titleResId);
        preference.setKey(restriction.key);
        preference.setOnPreferenceChangeListener(this);
        preferenceScreen.addPreference(preference);
    }

    updateAllUserRestrictions();
    constrainPreferences();
}
 
Example 3
Source File: ScheduleFragment.java    From PresencePublisher with MIT License 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    Context context = getPreferenceManager().getContext();
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(listener);

    Preference messageSchedule = new MessageSchedulePreference(context);
    Preference presenceTopic = new PresenceTopicPreference(context);

    Preference sendBatteryMessage = new SendBatteryMessagePreference(context);
    Preference batteryTopic = new BatteryTopicPreference(context);

    Preference autostart = new AutostartPreference(context);

    lastSuccess = new LastSuccessTimestampPreference(context);
    nextSchedule = new NextScheduleTimestampPreference(context);

    screen.addPreference(messageSchedule);
    screen.addPreference(presenceTopic);
    screen.addPreference(sendBatteryMessage);
    screen.addPreference(batteryTopic);
    screen.addPreference(autostart);
    screen.addPreference(lastSuccess);
    screen.addPreference(nextSchedule);

    setPreferenceScreen(screen);

    batteryTopic.setDependency(SEND_BATTERY_MESSAGE);
}
 
Example 4
Source File: ConnectionFragment.java    From PresencePublisher with MIT License 5 votes vote down vote up
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
    Context context = getPreferenceManager().getContext();
    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);

    Preference host = new HostPreference(context);
    Preference port = new PortPreference(context);

    Preference username = new UsernamePreference(context);
    Preference password = new PasswordPreference(context);

    Preference useTls = new UseTlsPreference(context);
    Preference clientCertificate = new ClientCertificatePreference(context, this);

    Preference checkConnection = new CheckConnectionDummy(context, this);

    screen.addPreference(host);
    screen.addPreference(port);
    screen.addPreference(username);
    screen.addPreference(password);
    screen.addPreference(useTls);
    screen.addPreference(clientCertificate);
    screen.addPreference(checkConnection);

    setPreferenceScreen(screen);

    checkConnection.setDependency(HOST);
    clientCertificate.setDependency(USE_TLS);
}
 
Example 5
Source File: TalkBackDumpAccessibilityEventActivity.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
  Context context = getActivity();

  PreferenceSettingsUtils.addPreferencesFromResource(this, R.xml.dump_events_preferences);

  PreferenceScreen screen = getPreferenceScreen();

  for (int eventType : AccessibilityEventUtils.getAllEventTypes()) {
    EventDumperSwitchPreference preference =
        new EventDumperSwitchPreference(context, eventType);
    switchPreferences.add(preference);
    screen.addPreference(preference);
  }
}
 
Example 6
Source File: ConditionFragment.java    From PresencePublisher with MIT License 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    context = getPreferenceManager().getContext();
    beaconsSupported = ((Application) context.getApplicationContext()).supportsBeacons();
    SharedPreferences preference = getPreferenceManager().getSharedPreferences();
    currentNetworks = Collections.unmodifiableSet(preference.getStringSet(SSID_LIST, Collections.emptySet()));
    currentBeacons = Collections.unmodifiableSet(preference.getStringSet(BEACON_LIST, Collections.emptySet()));

    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);

    Preference contentHelp = new ContentHelpDummy(context, R.string.condition_help_summary);
    Preference sendViaMobileNetwork = new SendViaMobileNetworkPreference(context);
    wifiCategory = new MyPreferenceCategory(context, R.string.category_wifi);
    beaconCategory = new MyPreferenceCategory(context, R.string.category_beacon_regions);
    PreferenceCategory offlineCategory = new MyPreferenceCategory(context, R.string.category_offline);

    screen.addPreference(contentHelp);
    screen.addPreference(sendViaMobileNetwork);
    screen.addPreference(wifiCategory);
    screen.addPreference(beaconCategory);
    screen.addPreference(offlineCategory);

    wifiCategory.setOrderingAsAdded(false);
    addNetworkChoice = new AddNetworkChoicePreferenceDummy(context, preference, this);
    for (String ssid : currentNetworks) {
        wifiCategory.addPreference(new WifiNetworkPreference(context, ssid, preference, this));
    }
    wifiCategory.addPreference(addNetworkChoice);

    beaconCategory.setOrderingAsAdded(false);
    // to make linter happy
    if (beaconsSupported && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        addBeaconChoice = new AddBeaconChoicePreferenceDummy(context, this);
        for (String beaconId : currentBeacons) {
            beaconCategory.addPreference(new BeaconPreference(context, beaconId, this));
        }
        beaconCategory.addPreference(addBeaconChoice);
    } else {
        beaconCategory.addPreference(new ContentHelpDummy(context, R.string.no_bluetooth_explanation));
    }

    Preference offlineContent = new OfflineContentPreference(context);
    offlineCategory.addPreference(new SendOfflineMessagePreference(context));
    offlineCategory.addPreference(offlineContent);

    setPreferenceScreen(screen);

    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(listener);

    offlineContent.setDependency(SEND_OFFLINE_MESSAGE);
}