So I am getting started with Androidx, writing for API release 32.
One thing I can't wrap my mind around is why Googly, decided to implement the Settings Screen the way they did.
In my case, I am building an app that is to communicate with a Bluetooth device, but only one specific Bluetooth device is supported by the app.
I have the settings screen presenting the list of bonded devices in a DropDownPreference.
What I am stumped about, is how to interrupt the selection of an item in the list, before it's written to shared preferences.
It looks like all the methods both onPreferenceTreeClick, and OnPreferenceClickListener fires, when the dropdown list is opened, not when an item is selected.
What I have so far (not yet checking the fingerprint of the bonded device) is:
DropDownPreference db = findPreference( "Prefs_Bonded_Device" );
if ( db != null )
db.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick( Preference preference ) {
if (Objects.equals(preference.getKey(), "Prefs_Bonded_Device" )) {
SwitchPreference s = findPreference("Prefs_Bluetooth" );
DropDownPreference d = (DropDownPreference) preference;
if (s != null && s.isChecked())
broadCastPreferenceChange( CustomIntent.PREFERENCES_CHANGED_BONDED_DEVICE, d.getValue() );
}
return true;
}
});
So long story short, what is the best strategy to inject business logic into the Settings Screen, before changes are written to Shared Preference, and rest of the Activities in the app pick up and run with the preference change through the Shared Preference listener?
Do I really have to build my own widget that inherit from DropDownPreference to make that possible?