Search in sources :

Example 1 with BasePreferenceController

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

the class BaseSearchIndexProviderTest method getAllPreferenceControllers_shouldCreateControllerFromCodeAndXml.

@Test
@Config(qualifiers = "mcc999")
public void getAllPreferenceControllers_shouldCreateControllerFromCodeAndXml() {
    final BaseSearchIndexProvider provider = new BaseSearchIndexProvider() {

        @Override
        public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, boolean enabled) {
            final SearchIndexableResource sir = new SearchIndexableResource(context);
            sir.xmlResId = R.xml.location_settings;
            return Collections.singletonList(sir);
        }

        @Override
        public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
            final List<AbstractPreferenceController> controllersFromCode = new ArrayList<>();
            controllersFromCode.add(new BasePreferenceController(mContext, "TEST_KEY") {

                @Override
                public int getAvailabilityStatus() {
                    return AVAILABLE;
                }
            });
            return controllersFromCode;
        }
    };
    final List<AbstractPreferenceController> controllers = provider.getPreferenceControllers(mContext);
    assertThat(controllers).hasSize(2);
}
Also used : Context(android.content.Context) BasePreferenceController(com.android.settings.core.BasePreferenceController) SearchIndexableResource(android.provider.SearchIndexableResource) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) ArrayList(java.util.ArrayList) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 2 with BasePreferenceController

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

the class SliceBuilderUtilsTest method testGetPreferenceController_buildsMatchingController.

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

Example 3 with BasePreferenceController

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

the class SliceBroadcastReceiver method handleSliderAction.

private void handleSliderAction(Context context, String key, int newPosition, boolean isPlatformSlice) {
    if (TextUtils.isEmpty(key)) {
        throw new IllegalArgumentException("No key passed to Intent for slider controller. Use extra: " + EXTRA_SLICE_KEY);
    }
    if (newPosition == -1) {
        throw new IllegalArgumentException("Invalid position passed to Slider controller");
    }
    final BasePreferenceController controller = getPreferenceController(context, key);
    if (!(controller instanceof SliderPreferenceController)) {
        throw new IllegalArgumentException("Slider action passed for a non-slider key: " + key);
    }
    if (!controller.isAvailable()) {
        Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
        updateUri(context, key, isPlatformSlice);
        return;
    }
    final SliderPreferenceController sliderController = (SliderPreferenceController) controller;
    final int minValue = sliderController.getMin();
    final int maxValue = sliderController.getMax();
    if (newPosition < minValue || newPosition > maxValue) {
        throw new IllegalArgumentException("Invalid position passed to Slider controller. Expected between " + minValue + " and " + maxValue + " but found " + newPosition);
    }
    sliderController.setSliderPosition(newPosition);
    logSliceValueChange(context, key, newPosition);
    updateUri(context, key, isPlatformSlice);
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) SliderPreferenceController(com.android.settings.core.SliderPreferenceController)

Example 4 with BasePreferenceController

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

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

the class SliceBuilderUtils method buildSlice.

/**
 * Build a Slice from {@link SliceData}.
 *
 * @return a {@link Slice} based on the data provided by {@param sliceData}.
 * Will build an {@link Intent} based Slice unless the Preference Controller name in
 * {@param sliceData} is an inline controller.
 */
public static Slice buildSlice(Context context, SliceData sliceData) {
    // Reload theme for switching dark mode on/off
    context.getTheme().applyStyle(R.style.Theme_Settings_Home, true);
    Log.d(TAG, "Creating slice for: " + sliceData.getPreferenceController());
    final BasePreferenceController controller = getPreferenceController(context, sliceData);
    FeatureFactory.getFactory(context).getMetricsFeatureProvider().action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_SETTINGS_SLICE_REQUESTED, SettingsEnums.PAGE_UNKNOWN, sliceData.getKey(), 0);
    if (!controller.isAvailable()) {
        // Cannot guarantee setting page is accessible, let the presenter handle error case.
        return null;
    }
    if (controller.getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
        return buildUnavailableSlice(context, sliceData);
    }
    if (controller.isCopyableSlice()) {
        return buildCopyableSlice(context, sliceData, controller);
    }
    switch(sliceData.getSliceType()) {
        case SliceData.SliceType.INTENT:
            return buildIntentSlice(context, sliceData, controller);
        case SliceData.SliceType.SWITCH:
            return buildToggleSlice(context, sliceData, controller);
        case SliceData.SliceType.SLIDER:
            return buildSliderSlice(context, sliceData, controller);
        default:
            throw new IllegalArgumentException("Slice type passed was invalid: " + sliceData.getSliceType());
    }
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController)

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