Allows for system navigation settings to be added dynamically.
This allows for controller-backed preferences to be added or overridden via xml. Similarly, if the controllers cause all of the preferences for 2 or 3 button nav to be unavailable, we hide the settings button. Bug: 324036308 Test: Manual and unit tests Flag: NA Change-Id: I2371f3173076172489966728ac69c8767570cd56
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user