Java Code Examples for androidx.preference.Preference#setDependency()

The following examples show how to use androidx.preference.Preference#setDependency() . 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: 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 2
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 3
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);
}