Loading packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceStateProviders.kt +9 −6 Original line number Diff line number Diff line Loading @@ -60,14 +60,17 @@ interface PreferenceIconProvider { fun getIcon(context: Context): Int } /** Interface to provide the state of preference availability. */ interface PreferenceAvailabilityProvider { /** * Interface to provide the state of preference availability. * Returns if the preference is available. * * UI framework normally does not show the preference widget if it is unavailable. * When unavailable (i.e. `false` returned), * - UI framework normally does not show the preference widget. * - If it is a preference screen, all children may be disabled (depends on UI framework * implementation). */ interface PreferenceAvailabilityProvider { /** Returns if the preference is available. */ fun isAvailable(context: Context): Boolean } Loading packages/SettingsLib/Preference/src/com/android/settingslib/preference/PreferenceBinding.kt +7 −1 Original line number Diff line number Diff line Loading @@ -97,9 +97,15 @@ interface PreferenceBinding { if (!isPreferenceScreen) { preference.summary = getPreferenceSummary(context) } preference.isEnabled = isEnabled(context) preference.isVisible = (this as? PreferenceAvailabilityProvider)?.isAvailable(context) != false // PreferenceScreen.isVisible=false has no effect on UI, while isEnable=false will // apply recursively. As a workaround, disable all children when screen is unavailable. preference.isEnabled = when { isPreferenceScreen && !preference.isVisible -> false else -> isEnabled(context) } preference.isPersistent = isPersistent(context) // PreferenceScreenBindingHelper will notify dependency change, so we do not need to set // dependency here. This simplifies dependency management and avoid the Loading Loading
packages/SettingsLib/Metadata/src/com/android/settingslib/metadata/PreferenceStateProviders.kt +9 −6 Original line number Diff line number Diff line Loading @@ -60,14 +60,17 @@ interface PreferenceIconProvider { fun getIcon(context: Context): Int } /** Interface to provide the state of preference availability. */ interface PreferenceAvailabilityProvider { /** * Interface to provide the state of preference availability. * Returns if the preference is available. * * UI framework normally does not show the preference widget if it is unavailable. * When unavailable (i.e. `false` returned), * - UI framework normally does not show the preference widget. * - If it is a preference screen, all children may be disabled (depends on UI framework * implementation). */ interface PreferenceAvailabilityProvider { /** Returns if the preference is available. */ fun isAvailable(context: Context): Boolean } Loading
packages/SettingsLib/Preference/src/com/android/settingslib/preference/PreferenceBinding.kt +7 −1 Original line number Diff line number Diff line Loading @@ -97,9 +97,15 @@ interface PreferenceBinding { if (!isPreferenceScreen) { preference.summary = getPreferenceSummary(context) } preference.isEnabled = isEnabled(context) preference.isVisible = (this as? PreferenceAvailabilityProvider)?.isAvailable(context) != false // PreferenceScreen.isVisible=false has no effect on UI, while isEnable=false will // apply recursively. As a workaround, disable all children when screen is unavailable. preference.isEnabled = when { isPreferenceScreen && !preference.isVisible -> false else -> isEnabled(context) } preference.isPersistent = isPersistent(context) // PreferenceScreenBindingHelper will notify dependency change, so we do not need to set // dependency here. This simplifies dependency management and avoid the Loading