Search in sources :

Example 36 with AbstractPreferenceController

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

the class PowerUsageSummaryTest method testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen.

@Test
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
    final Context context = RuntimeEnvironment.application;
    final PowerUsageSummary fragment = new PowerUsageSummary();
    final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context, fragment.getPreferenceScreenResId());
    final List<String> preferenceKeys = new ArrayList<>();
    for (AbstractPreferenceController controller : fragment.getPreferenceControllers(context)) {
        preferenceKeys.add(controller.getPreferenceKey());
    }
    assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys);
}
Also used : Context(android.content.Context) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 37 with AbstractPreferenceController

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

the class StorageDashboardFragment method updateSecondaryUserControllers.

/**
 * Updates the secondary user controller sizes.
 */
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers, SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
    for (int i = 0, size = controllers.size(); i < size; i++) {
        AbstractPreferenceController controller = controllers.get(i);
        if (controller instanceof StorageAsyncLoader.ResultHandler) {
            StorageAsyncLoader.ResultHandler userController = (StorageAsyncLoader.ResultHandler) controller;
            userController.handleResult(stats);
        }
    }
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) StorageAsyncLoader(com.android.settings.deviceinfo.storage.StorageAsyncLoader)

Example 38 with AbstractPreferenceController

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

the class StorageDashboardFragment method onReceivedSizes.

private void onReceivedSizes() {
    if (mStorageInfo != null) {
        long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
        mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
        mPreferenceController.setVolume(mVolume);
        mPreferenceController.setUsedSize(privateUsedBytes);
        mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
        for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
            AbstractPreferenceController controller = mSecondaryUsers.get(i);
            if (controller instanceof SecondaryUserController) {
                SecondaryUserController userController = (SecondaryUserController) controller;
                userController.setTotalSize(mStorageInfo.totalBytes);
            }
        }
    }
    if (mAppsResult == null) {
        return;
    }
    mPreferenceController.onLoadFinished(mAppsResult, UserHandle.myUserId());
    updateSecondaryUserControllers(mSecondaryUsers, mAppsResult);
    // setLoading always causes a flicker, so let's avoid doing it.
    if (getView().findViewById(R.id.loading_container).getVisibility() == View.VISIBLE) {
        setLoading(false, true);
    }
}
Also used : AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) SecondaryUserController(com.android.settings.deviceinfo.storage.SecondaryUserController)

Example 39 with AbstractPreferenceController

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

the class ResetDashboardFragment method buildPreferenceControllers.

private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, Lifecycle lifecycle) {
    final List<AbstractPreferenceController> controllers = new ArrayList<>();
    controllers.add(new NetworkResetPreferenceController(context));
    controllers.add(new FactoryResetPreferenceController(context));
    controllers.add(new ResetAppPrefPreferenceController(context, lifecycle));
    return controllers;
}
Also used : NetworkResetPreferenceController(com.android.settings.network.NetworkResetPreferenceController) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) ArrayList(java.util.ArrayList) ResetAppPrefPreferenceController(com.android.settings.applications.ResetAppPrefPreferenceController)

Example 40 with AbstractPreferenceController

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

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).getPreferenceControllers(context);
    } 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) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Indexable(com.android.settings.search.Indexable) Fragment(android.app.Fragment)

Aggregations

AbstractPreferenceController (com.android.settingslib.core.AbstractPreferenceController)344 ArrayList (java.util.ArrayList)245 Test (org.junit.Test)86 UserInfo (android.content.pm.UserInfo)33 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)33 Context (android.content.Context)31 SettingsActivity (com.android.settings.SettingsActivity)18 StorageManager (android.os.storage.StorageManager)16 StorageItemPreferenceController (com.android.settings.deviceinfo.storage.StorageItemPreferenceController)16 StorageManagerVolumeProvider (com.android.settingslib.deviceinfo.StorageManagerVolumeProvider)16 AdditionalSystemUpdatePreferenceController (com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController)12 Activity (android.app.Activity)11 BasePreferenceController (com.android.settings.core.BasePreferenceController)11 PreferenceScreen (android.support.v7.preference.PreferenceScreen)10 UserManager (android.os.UserManager)9 PreferenceControllerMixin (com.android.settings.core.PreferenceControllerMixin)9 TimeoutPreferenceController (com.android.settings.display.TimeoutPreferenceController)9 Intent (android.content.Intent)8 AmbientDisplayConfiguration (com.android.internal.hardware.AmbientDisplayConfiguration)8 PreferenceScreen (androidx.preference.PreferenceScreen)7