Issue
In my application I would like to have parts of my preferences password protected. There's not really the need to have them "really" secured - it's just that some settings should be only changed "if you know what you do" (it's an enterprise app).
So my preference hierarchy looks something like this:
PreferenceScreen
+-- PreferenceScreen
+-- SettingA
+-- SettingB
+-- PreferenceScreen (this one should be password protected)
+-- SettingC
+-- SettingD
The problem is, I can't find any way to intercept the clicking of the preferencescreen - I tried to override the onPreferenceTreeClicked
method, but that didn't work:
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if(userHasEnteredCorrectPassword) {
return super.onPreferenceTreeClick(preferenceScreen, preference);
} else {
return false;
}
}
Obviously because super.onPreferenceTreeClick(...)
just start's an fragment in case the preference has set it.
I also tried to set the onClickListener
of the preference in the onCreate
of the PreferenceFragment - like this:
findPreference("secure_preference_screen").setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if(userHasEnteredCorrectPassword) {
return true;
} else {
return false;
}
}
});
But that won't intercept the click as well.
Is there anyone out there who could possibly know how to implement such a feature?
Solution
So just close the fragment if the user don't have the password. Catch it in where you can. It doesn't really matters
Answered By - Ilya Gazman
Answer Checked By - David Marino (JavaFixing Volunteer)