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);
}
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);
}
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);
}
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);
}
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());
}
}
Aggregations