Merge "Add SettingsPrefController for Slices"
This commit is contained in:
committed by
Android (Google) Code Review
commit
96c1ecd50f
@@ -27,6 +27,7 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -71,6 +72,9 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
if (controller instanceof PreferenceControllerMixin) {
|
||||
((PreferenceControllerMixin) controller)
|
||||
.updateNonIndexableKeys(nonIndexableKeys);
|
||||
} else if (controller instanceof BasePreferenceController) {
|
||||
((BasePreferenceController) controller).updateNonIndexableKeys(
|
||||
nonIndexableKeys);
|
||||
} else {
|
||||
throw new IllegalStateException(controller.getClass().getName()
|
||||
+ " must implement " + PreferenceControllerMixin.class.getName());
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.util.Log;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
@@ -72,10 +73,11 @@ public class DatabaseIndexingUtils {
|
||||
* @return A map between {@link Uri}s and {@link PreferenceControllerMixin}s to get the payload
|
||||
* types for Settings.
|
||||
*/
|
||||
public static Map<String, PreferenceControllerMixin> getPreferenceControllerUriMap(
|
||||
public static Map<String, ResultPayload> getPayloadKeyMap(
|
||||
String className, Context context) {
|
||||
ArrayMap<String, ResultPayload> map = new ArrayMap<>();
|
||||
if (context == null) {
|
||||
return null;
|
||||
return map;
|
||||
}
|
||||
|
||||
final Class<?> clazz = getIndexableClass(className);
|
||||
@@ -83,7 +85,7 @@ public class DatabaseIndexingUtils {
|
||||
if (clazz == null) {
|
||||
Log.d(TAG, "SearchIndexableResource '" + className +
|
||||
"' should implement the " + Indexable.class.getName() + " interface!");
|
||||
return null;
|
||||
return map;
|
||||
}
|
||||
|
||||
// Will be non null only for a Local provider implementing a
|
||||
@@ -94,44 +96,28 @@ public class DatabaseIndexingUtils {
|
||||
provider.getPreferenceControllers(context);
|
||||
|
||||
if (controllers == null) {
|
||||
return null;
|
||||
return map;
|
||||
}
|
||||
|
||||
ArrayMap<String, PreferenceControllerMixin> map = new ArrayMap<>();
|
||||
|
||||
for (AbstractPreferenceController controller : controllers) {
|
||||
ResultPayload payload;
|
||||
if (controller instanceof PreferenceControllerMixin) {
|
||||
map.put(controller.getPreferenceKey(), (PreferenceControllerMixin) controller);
|
||||
payload = ((PreferenceControllerMixin) controller).getResultPayload();
|
||||
|
||||
} else if (controller instanceof BasePreferenceController) {
|
||||
payload = ((BasePreferenceController) controller).getResultPayload();
|
||||
} else {
|
||||
throw new IllegalStateException(controller.getClass().getName()
|
||||
+ " must implement " + PreferenceControllerMixin.class.getName());
|
||||
}
|
||||
if (payload != null) {
|
||||
map.put(controller.getPreferenceKey(), payload);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uriMap Map between the {@link PreferenceControllerMixin} keys
|
||||
* and the controllers themselves.
|
||||
* @param key The look-up key
|
||||
* @return The Payload from the {@link PreferenceControllerMixin} specified by the key,
|
||||
* if it exists. Otherwise null.
|
||||
*/
|
||||
public static ResultPayload getPayloadFromUriMap(Map<String, PreferenceControllerMixin> uriMap,
|
||||
String key) {
|
||||
if (uriMap == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PreferenceControllerMixin controller = uriMap.get(key);
|
||||
if (controller == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return controller.getResultPayload();
|
||||
}
|
||||
|
||||
public static Class<?> getIndexableClass(String className) {
|
||||
final Class<?> clazz;
|
||||
try {
|
||||
@@ -164,4 +150,4 @@ public class DatabaseIndexingUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -178,11 +179,11 @@ public class IndexDataConverter {
|
||||
final String intentTargetPackage = sir.intentTargetPackage;
|
||||
final String intentTargetClass = sir.intentTargetClass;
|
||||
|
||||
Map<String, PreferenceControllerMixin> controllerUriMap = null;
|
||||
Map<String, ResultPayload> controllerUriMap = new HashMap<>();
|
||||
|
||||
if (fragmentName != null) {
|
||||
controllerUriMap = DatabaseIndexingUtils
|
||||
.getPreferenceControllerUriMap(fragmentName, context);
|
||||
.getPayloadKeyMap(fragmentName, context);
|
||||
}
|
||||
|
||||
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
|
||||
@@ -249,7 +250,7 @@ public class IndexDataConverter {
|
||||
}
|
||||
|
||||
// TODO (b/62254931) index primitives instead of payload
|
||||
payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
|
||||
payload = controllerUriMap.get(key);
|
||||
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
|
||||
|
||||
builder.setSummaryOn(summary)
|
||||
|
||||
Reference in New Issue
Block a user