Search in sources :

Example 1 with LifecycleObserver

use of com.android.settingslib.core.lifecycle.LifecycleObserver in project android_packages_apps_Settings by LineageOS.

the class LanguageAndInputSettingsTest method testGetPreferenceControllers_shouldRegisterLifecycleObservers.

@Test
public void testGetPreferenceControllers_shouldRegisterLifecycleObservers() {
    final List<AbstractPreferenceController> controllers = mFragment.getPreferenceControllers(mActivity);
    int lifecycleObserverCount = 0;
    for (AbstractPreferenceController controller : controllers) {
        if (controller instanceof LifecycleObserver) {
            lifecycleObserverCount++;
        }
    }
    verify(mFragment.getLifecycle(), times(lifecycleObserverCount)).addObserver(any(LifecycleObserver.class));
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver) Test(org.junit.Test)

Example 2 with LifecycleObserver

use of com.android.settingslib.core.lifecycle.LifecycleObserver in project android_packages_apps_Settings by crdroidandroid.

the class LanguageAndInputSettingsTest method testGetPreferenceControllers_shouldRegisterLifecycleObservers.

@Test
public void testGetPreferenceControllers_shouldRegisterLifecycleObservers() {
    final List<AbstractPreferenceController> controllers = mFragment.getPreferenceControllers(mActivity);
    int lifecycleObserverCount = 0;
    for (AbstractPreferenceController controller : controllers) {
        if (controller instanceof LifecycleObserver) {
            lifecycleObserverCount++;
        }
    }
    verify(mFragment.getLifecycle(), times(lifecycleObserverCount)).addObserver(any(LifecycleObserver.class));
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver) Test(org.junit.Test)

Example 3 with LifecycleObserver

use of com.android.settingslib.core.lifecycle.LifecycleObserver in project platform_packages_apps_Settings by BlissRoms.

the class LanguageAndInputSettingsTest method testGetPreferenceControllers_shouldRegisterLifecycleObservers.

@Test
public void testGetPreferenceControllers_shouldRegisterLifecycleObservers() {
    final List<AbstractPreferenceController> controllers = mFragment.getPreferenceControllers(mActivity);
    int lifecycleObserverCount = 0;
    for (AbstractPreferenceController controller : controllers) {
        if (controller instanceof LifecycleObserver) {
            lifecycleObserverCount++;
        }
    }
    verify(mFragment.getLifecycle(), times(lifecycleObserverCount)).addObserver(any(LifecycleObserver.class));
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver) Test(org.junit.Test)

Example 4 with LifecycleObserver

use of com.android.settingslib.core.lifecycle.LifecycleObserver in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DashboardFragment method onAttach.

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    mSuppressInjectedTileKeys = Arrays.asList(context.getResources().getStringArray(R.array.config_suppress_injected_tile_keys));
    mDashboardFeatureProvider = FeatureFactory.getFactory(context).getDashboardFeatureProvider(context);
    final List<AbstractPreferenceController> controllers = new ArrayList<>();
    // Load preference controllers from code
    final List<AbstractPreferenceController> controllersFromCode = createPreferenceControllers(context);
    // Load preference controllers from xml definition
    final List<BasePreferenceController> controllersFromXml = PreferenceControllerListHelper.getPreferenceControllersFromXml(context, getPreferenceScreenResId());
    // Filter xml-based controllers in case a similar controller is created from code already.
    final List<BasePreferenceController> uniqueControllerFromXml = PreferenceControllerListHelper.filterControllers(controllersFromXml, controllersFromCode);
    // Add unique controllers to list.
    if (controllersFromCode != null) {
        controllers.addAll(controllersFromCode);
    }
    controllers.addAll(uniqueControllerFromXml);
    // And wire up with lifecycle.
    final Lifecycle lifecycle = getSettingsLifecycle();
    uniqueControllerFromXml.stream().filter(controller -> controller instanceof LifecycleObserver).forEach(controller -> lifecycle.addObserver((LifecycleObserver) controller));
    mPlaceholderPreferenceController = new DashboardTilePlaceholderPreferenceController(context);
    controllers.add(mPlaceholderPreferenceController);
    for (AbstractPreferenceController controller : controllers) {
        addPreferenceController(controller);
    }
    checkUiBlocker(controllers);
}
Also used : PreferenceGroup(androidx.preference.PreferenceGroup) SettingsPreferenceFragment(com.android.settings.SettingsPreferenceFragment) Context(android.content.Context) Arrays(java.util.Arrays) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Indexable(com.android.settings.search.Indexable) SettingsBaseActivity(com.android.settings.core.SettingsBaseActivity) Map(java.util.Map) BasePreferenceController(com.android.settings.core.BasePreferenceController) ArraySet(android.util.ArraySet) Log(android.util.Log) ArrayMap(android.util.ArrayMap) R(com.android.settings.R) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceControllerListHelper(com.android.settings.core.PreferenceControllerListHelper) Collection(java.util.Collection) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver) Set(java.util.Set) SettingsEnums(android.app.settings.SettingsEnums) TextUtils(android.text.TextUtils) FeatureFactory(com.android.settings.overlay.FeatureFactory) CallSuper(androidx.annotation.CallSuper) Preference(androidx.preference.Preference) List(java.util.List) DashboardCategory(com.android.settingslib.drawer.DashboardCategory) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Tile(com.android.settingslib.drawer.Tile) PreferenceManager(androidx.preference.PreferenceManager) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) BasePreferenceController(com.android.settings.core.BasePreferenceController) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) ArrayList(java.util.ArrayList) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver)

Example 5 with LifecycleObserver

use of com.android.settingslib.core.lifecycle.LifecycleObserver in project android_packages_apps_Settings by omnirom.

the class DashboardFragment method onAttach.

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    mSuppressInjectedTileKeys = Arrays.asList(context.getResources().getStringArray(R.array.config_suppress_injected_tile_keys));
    mDashboardFeatureProvider = FeatureFactory.getFactory(context).getDashboardFeatureProvider(context);
    // Load preference controllers from code
    final List<AbstractPreferenceController> controllersFromCode = createPreferenceControllers(context);
    // Load preference controllers from xml definition
    final List<BasePreferenceController> controllersFromXml = PreferenceControllerListHelper.getPreferenceControllersFromXml(context, getPreferenceScreenResId());
    // Filter xml-based controllers in case a similar controller is created from code already.
    final List<BasePreferenceController> uniqueControllerFromXml = PreferenceControllerListHelper.filterControllers(controllersFromXml, controllersFromCode);
    // Add unique controllers to list.
    if (controllersFromCode != null) {
        mControllers.addAll(controllersFromCode);
    }
    mControllers.addAll(uniqueControllerFromXml);
    // And wire up with lifecycle.
    final Lifecycle lifecycle = getSettingsLifecycle();
    uniqueControllerFromXml.forEach(controller -> {
        if (controller instanceof LifecycleObserver) {
            lifecycle.addObserver((LifecycleObserver) controller);
        }
    });
    // Set metrics category for BasePreferenceController.
    final int metricCategory = getMetricsCategory();
    mControllers.forEach(controller -> {
        if (controller instanceof BasePreferenceController) {
            ((BasePreferenceController) controller).setMetricsCategory(metricCategory);
        }
    });
    mPlaceholderPreferenceController = new DashboardTilePlaceholderPreferenceController(context);
    mControllers.add(mPlaceholderPreferenceController);
    for (AbstractPreferenceController controller : mControllers) {
        addPreferenceController(controller);
    }
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) LifecycleObserver(com.android.settingslib.core.lifecycle.LifecycleObserver)

Aggregations

AbstractPreferenceController (com.android.settingslib.core.AbstractPreferenceController)7 LifecycleObserver (com.android.settingslib.core.lifecycle.LifecycleObserver)7 Test (org.junit.Test)5 BasePreferenceController (com.android.settings.core.BasePreferenceController)2 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)2 Activity (android.app.Activity)1 SettingsEnums (android.app.settings.SettingsEnums)1 Context (android.content.Context)1 Bundle (android.os.Bundle)1 TextUtils (android.text.TextUtils)1 ArrayMap (android.util.ArrayMap)1 ArraySet (android.util.ArraySet)1 Log (android.util.Log)1 CallSuper (androidx.annotation.CallSuper)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 Preference (androidx.preference.Preference)1 PreferenceGroup (androidx.preference.PreferenceGroup)1 PreferenceManager (androidx.preference.PreferenceManager)1 PreferenceScreen (androidx.preference.PreferenceScreen)1 R (com.android.settings.R)1