Merge "Allows for system navigation settings to be added dynamically." into main

This commit is contained in:
Andy Wickham
2024-03-20 03:00:10 +00:00
committed by Android (Google) Code Review
6 changed files with 133 additions and 5 deletions

View File

@@ -27,6 +27,8 @@ import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.PreferenceXmlParserUtils.MetadataFlag;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -93,6 +95,25 @@ public class PreferenceControllerListHelper {
return controllers;
}
/**
* Checks if the given PreferenceScreen will be empty due to all preferences being unavailable.
*
* @param xmlResId resource id of the PreferenceScreen to check
* @return {@code true} if none of the preferences in the given screen will appear
*/
public static boolean areAllPreferencesUnavailable(@NonNull Context context,
@NonNull PreferenceManager preferenceManager, @XmlRes int xmlResId) {
PreferenceScreen screen = preferenceManager.inflateFromResource(context, xmlResId,
/* rootPreferences= */ null);
List<BasePreferenceController> preferenceControllers =
getPreferenceControllersFromXml(context, xmlResId);
if (screen.getPreferenceCount() != preferenceControllers.size()) {
// There are some preferences without controllers, which will show regardless.
return false;
}
return preferenceControllers.stream().noneMatch(BasePreferenceController::isAvailable);
}
/**
* Return a sub list of {@link AbstractPreferenceController} to only contain controller that
* doesn't exist in filter.