private void restoreDefaults ( @ NonNull final PreferenceGroup preferenceGroup , @ NonNull final SharedPreferences sharedPreferences ) { for ( int i = 0 ; i < preferenceGroup . getPreferenceCount ( ) ; i ++ ) { Preference preference = preferenceGroup . getPreference ( i ) ; if ( preference instanceof PreferenceGroup ) { restoreDefaults ( ( PreferenceGroup ) preference , sharedPreferences ) ; } else if ( preference . getKey ( ) != null && ! preference . getKey ( ) . isEmpty ( ) ) { Object oldValue = sharedPreferences . getAll ( ) . get ( preference . getKey ( ) ) ; if ( notifyOnRestoreDefaultValueRequested ( preference , oldValue ) ) { sharedPreferences . edit ( ) . remove ( preference . getKey ( ) ) . apply ( ) ; preferenceGroup . removePreference ( preference ) ; preferenceGroup . addPreference ( preference ) ; Object newValue = sharedPreferences . getAll ( ) . get ( preference . getKey ( ) ) ; notifyOnRestoredDefaultValue ( preference , oldValue , newValue ) ; } else { preferenceGroup . removePreference ( preference ) ; preferenceGroup . addPreference ( preference ) ; } } } }
Restores the default preferences which are contained by a specific preference group .