Search in sources :

Example 11 with BasePreferenceController

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

the class DashboardFragmentSearchIndexProviderInspector method isSharingPreferenceControllers.

public static boolean isSharingPreferenceControllers(Class clazz) {
    final Context context = RuntimeEnvironment.application;
    final Fragment fragment;
    try {
        fragment = Fragment.instantiate(context, clazz.getName());
    } catch (Throwable e) {
        // Can't do much with exception, assume the test passed.
        return true;
    }
    if (!(fragment instanceof DashboardFragment)) {
        return true;
    }
    final Indexable.SearchIndexProvider provider = DatabaseIndexingUtils.getSearchIndexProvider(clazz);
    if (provider == null) {
        return true;
    }
    final List<AbstractPreferenceController> controllersFromSearchIndexProvider;
    final List<AbstractPreferenceController> controllersFromFragment;
    try {
        controllersFromSearchIndexProvider = provider.getPreferenceControllers(context);
    } catch (Throwable e) {
        // Can't do much with exception, assume the test passed.
        return true;
    }
    try {
        controllersFromFragment = ((DashboardFragment) fragment).createPreferenceControllers(context);
        List<BasePreferenceController> controllersFromXml = PreferenceControllerListHelper.getPreferenceControllersFromXml(context, ((DashboardFragment) fragment).getPreferenceScreenResId());
        final List<BasePreferenceController> uniqueControllerFromXml = PreferenceControllerListHelper.filterControllers(controllersFromXml, controllersFromFragment);
        controllersFromFragment.addAll(uniqueControllerFromXml);
    } catch (Throwable e) {
        // Can't do much with exception, assume the test passed.
        return true;
    }
    if (controllersFromFragment == controllersFromSearchIndexProvider) {
        return true;
    } else if (controllersFromFragment != null && controllersFromSearchIndexProvider != null) {
        return controllersFromFragment.size() == controllersFromSearchIndexProvider.size();
    } else {
        return false;
    }
}
Also used : Context(android.content.Context) BasePreferenceController(com.android.settings.core.BasePreferenceController) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Indexable(com.android.settings.search.Indexable) Fragment(androidx.fragment.app.Fragment)

Example 12 with BasePreferenceController

use of com.android.settings.core.BasePreferenceController 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)

Example 13 with BasePreferenceController

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

the class SliceBuilderUtilsTest method testGetPreferenceController_contextOnly_buildsMatchingController.

@Test
public void testGetPreferenceController_contextOnly_buildsMatchingController() {
    final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(mContext, getDummyData(CONTEXT_CONTROLLER, 0));
    assertThat(controller).isInstanceOf(FakeContextOnlyPreferenceController.class);
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) Test(org.junit.Test)

Aggregations

BasePreferenceController (com.android.settings.core.BasePreferenceController)13 AbstractPreferenceController (com.android.settingslib.core.AbstractPreferenceController)5 ArrayList (java.util.ArrayList)5 Context (android.content.Context)3 Test (org.junit.Test)3 Bundle (android.os.Bundle)2 SearchIndexableResource (android.provider.SearchIndexableResource)2 CallSuper (androidx.annotation.CallSuper)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 Indexable (com.android.settings.search.Indexable)2 Activity (android.app.Activity)1 SettingsEnums (android.app.settings.SettingsEnums)1 IntentFilter (android.content.IntentFilter)1 XmlResourceParser (android.content.res.XmlResourceParser)1 TextUtils (android.text.TextUtils)1 ArrayMap (android.util.ArrayMap)1 ArraySet (android.util.ArraySet)1 AttributeSet (android.util.AttributeSet)1 Log (android.util.Log)1 Fragment (androidx.fragment.app.Fragment)1