Search in sources :

Example 16 with PreferenceControllerMixin

use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by crdroidandroid.

the class DatabaseIndexingUtils method getPreferenceControllerUriMap.

/**
 * @param className which wil provide the map between from {@link Uri}s to
 * {@link PreferenceControllerMixin}
 * @param context
 * @return A map between {@link Uri}s and {@link PreferenceControllerMixin}s to get the payload
 * types for Settings.
 */
public static Map<String, PreferenceControllerMixin> getPreferenceControllerUriMap(String className, Context context) {
    if (context == null) {
        return null;
    }
    final Class<?> clazz = getIndexableClass(className);
    if (clazz == null) {
        Log.d(TAG, "SearchIndexableResource '" + className + "' should implement the " + Indexable.class.getName() + " interface!");
        return null;
    }
    // Will be non null only for a Local provider implementing a
    // SEARCH_INDEX_DATA_PROVIDER field
    final Indexable.SearchIndexProvider provider = getSearchIndexProvider(clazz);
    List<AbstractPreferenceController> controllers = provider.getPreferenceControllers(context);
    if (controllers == null) {
        return null;
    }
    ArrayMap<String, PreferenceControllerMixin> map = new ArrayMap<>();
    for (AbstractPreferenceController controller : controllers) {
        if (controller instanceof PreferenceControllerMixin) {
            map.put(controller.getPreferenceKey(), (PreferenceControllerMixin) controller);
        } else {
            throw new IllegalStateException(controller.getClass().getName() + " must implement " + PreferenceControllerMixin.class.getName());
        }
    }
    return map;
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) ArrayMap(android.util.ArrayMap)

Example 17 with PreferenceControllerMixin

use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by SudaMod.

the class DatabaseIndexingUtils method getPreferenceControllerUriMap.

/**
 * @param className which wil provide the map between from {@link Uri}s to
 * {@link PreferenceControllerMixin}
 * @param context
 * @return A map between {@link Uri}s and {@link PreferenceControllerMixin}s to get the payload
 * types for Settings.
 */
public static Map<String, PreferenceControllerMixin> getPreferenceControllerUriMap(String className, Context context) {
    if (context == null) {
        return null;
    }
    final Class<?> clazz = getIndexableClass(className);
    if (clazz == null) {
        Log.d(TAG, "SearchIndexableResource '" + className + "' should implement the " + Indexable.class.getName() + " interface!");
        return null;
    }
    // Will be non null only for a Local provider implementing a
    // SEARCH_INDEX_DATA_PROVIDER field
    final Indexable.SearchIndexProvider provider = getSearchIndexProvider(clazz);
    List<AbstractPreferenceController> controllers = provider.getPreferenceControllers(context);
    if (controllers == null) {
        return null;
    }
    ArrayMap<String, PreferenceControllerMixin> map = new ArrayMap<>();
    for (AbstractPreferenceController controller : controllers) {
        if (controller instanceof PreferenceControllerMixin) {
            map.put(controller.getPreferenceKey(), (PreferenceControllerMixin) controller);
        } else {
            throw new IllegalStateException(controller.getClass().getName() + " must implement " + PreferenceControllerMixin.class.getName());
        }
    }
    return map;
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) ArrayMap(android.util.ArrayMap)

Example 18 with PreferenceControllerMixin

use of com.android.settings.core.PreferenceControllerMixin in project android_packages_apps_Settings by SudaMod.

the class DatabaseIndexingUtilsTest method testGetPayloadFromMap_MatchingKey_ReturnsPayload.

@Test
public void testGetPayloadFromMap_MatchingKey_ReturnsPayload() {
    final String key = "key";
    PreferenceControllerMixin prefController = new PreferenceControllerMixin() {

        @Override
        public ResultPayload getResultPayload() {
            return new ResultPayload(null);
        }
    };
    ArrayMap<String, PreferenceControllerMixin> map = new ArrayMap<>();
    map.put(key, prefController);
    ResultPayload payload = DatabaseIndexingUtils.getPayloadFromUriMap(map, key);
    assertThat(payload).isInstanceOf(ResultPayload.class);
}
Also used : PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) ArrayMap(android.util.ArrayMap) Test(org.junit.Test)

Example 19 with PreferenceControllerMixin

use of com.android.settings.core.PreferenceControllerMixin in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BaseSearchIndexProvider method getNonIndexableKeys.

@Override
@CallSuper
public List<String> getNonIndexableKeys(Context context) {
    if (!isPageSearchEnabled(context)) {
        // Entire page should be suppressed, mark all keys from this page as non-indexable.
        return getNonIndexableKeysFromXml(context, true);
    }
    final List<String> nonIndexableKeys = new ArrayList<>();
    nonIndexableKeys.addAll(getNonIndexableKeysFromXml(context, false));
    final List<AbstractPreferenceController> controllers = getPreferenceControllers(context);
    if (controllers != null && !controllers.isEmpty()) {
        for (AbstractPreferenceController controller : controllers) {
            if (controller instanceof PreferenceControllerMixin) {
                ((PreferenceControllerMixin) controller).updateNonIndexableKeys(nonIndexableKeys);
            } else if (controller instanceof BasePreferenceController) {
                ((BasePreferenceController) controller).updateNonIndexableKeys(nonIndexableKeys);
            } else {
                Log.e(TAG, controller.getClass().getName() + " must implement " + PreferenceControllerMixin.class.getName() + " treating the key non-indexable");
                nonIndexableKeys.add(controller.getPreferenceKey());
            }
        }
    }
    return nonIndexableKeys;
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) ArrayList(java.util.ArrayList) CallSuper(androidx.annotation.CallSuper)

Aggregations

PreferenceControllerMixin (com.android.settings.core.PreferenceControllerMixin)19 ArrayMap (android.util.ArrayMap)12 AbstractPreferenceController (com.android.settingslib.core.AbstractPreferenceController)7 Context (android.content.Context)6 XmlResourceParser (android.content.res.XmlResourceParser)6 DrawableRes (android.support.annotation.DrawableRes)6 VisibleForTesting (android.support.annotation.VisibleForTesting)6 AttributeSet (android.util.AttributeSet)6 IOException (java.io.IOException)6 Test (org.junit.Test)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 CallSuper (androidx.annotation.CallSuper)1 BasePreferenceController (com.android.settings.core.BasePreferenceController)1 ArrayList (java.util.ArrayList)1