use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BaseSearchIndexProvider method getPreferenceControllers.
@Override
public List<AbstractPreferenceController> getPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllersFromCode = createPreferenceControllers(context);
final List<SearchIndexableResource> res = getXmlResourcesToIndex(context, true);
if (res == null || res.isEmpty()) {
return controllersFromCode;
}
List<BasePreferenceController> controllersFromXml = new ArrayList<>();
for (SearchIndexableResource sir : res) {
controllersFromXml.addAll(PreferenceControllerListHelper.getPreferenceControllersFromXml(context, sir.xmlResId));
}
controllersFromXml = PreferenceControllerListHelper.filterControllers(controllersFromXml, controllersFromCode);
final List<AbstractPreferenceController> allControllers = new ArrayList<>();
if (controllersFromCode != null) {
allControllers.addAll(controllersFromCode);
}
allControllers.addAll(controllersFromXml);
return allControllers;
}
use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SliceDataConverter method getSliceDataFromXML.
private List<SliceData> getSliceDataFromXML(int xmlResId, String fragmentName) {
XmlResourceParser parser = null;
final List<SliceData> xmlSliceData = new ArrayList<>();
String controllerClassName = "";
try {
parser = mContext.getResources().getXml(xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
String nodeName = parser.getName();
if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
}
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = PreferenceXmlParserUtils.getDataTitle(mContext, attrs);
// TODO (b/67996923) Investigate if we need headers for Slices, since they never
// correspond to an actual setting.
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext, xmlResId, MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER | MetadataFlag.FLAG_NEED_PREF_TYPE | MetadataFlag.FLAG_NEED_PREF_TITLE | MetadataFlag.FLAG_NEED_PREF_ICON | MetadataFlag.FLAG_NEED_PREF_SUMMARY | MetadataFlag.FLAG_NEED_PLATFORM_SLICE_FLAG | MetadataFlag.FLAG_UNAVAILABLE_SLICE_SUBTITLE);
for (Bundle bundle : metadata) {
// TODO (b/67996923) Non-controller Slices should become intent-only slices.
// Note that without a controller, dynamic summaries are impossible.
controllerClassName = bundle.getString(METADATA_CONTROLLER);
if (TextUtils.isEmpty(controllerClassName)) {
continue;
}
final String key = bundle.getString(METADATA_KEY);
final String title = bundle.getString(METADATA_TITLE);
final String summary = bundle.getString(METADATA_SUMMARY);
final int iconResId = bundle.getInt(METADATA_ICON);
final int sliceType = SliceBuilderUtils.getSliceType(mContext, controllerClassName, key);
final boolean isPlatformSlice = bundle.getBoolean(METADATA_PLATFORM_SLICE_FLAG);
final String unavailableSliceSubtitle = bundle.getString(METADATA_UNAVAILABLE_SLICE_SUBTITLE);
final SliceData xmlSlice = new SliceData.Builder().setKey(key).setTitle(title).setSummary(summary).setIcon(iconResId).setScreenTitle(screenTitle).setPreferenceControllerClassName(controllerClassName).setFragmentName(fragmentName).setSliceType(sliceType).setPlatformDefined(isPlatformSlice).setUnavailableSliceSubtitle(unavailableSliceSubtitle).build();
final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(mContext, xmlSlice);
// Only add pre-approved Slices available on the device.
if (controller.isSliceable() && controller.isAvailable()) {
xmlSliceData.add(xmlSlice);
}
}
} catch (SliceData.InvalidSliceDataException e) {
Log.w(TAG, "Invalid data when building SliceData for " + fragmentName, e);
mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_VERIFY_SLICE_ERROR_INVALID_DATA, SettingsEnums.PAGE_UNKNOWN, controllerClassName, 1);
} catch (XmlPullParserException | IOException | Resources.NotFoundException e) {
Log.w(TAG, "Error parsing PreferenceScreen: ", e);
mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_VERIFY_SLICE_PARSING_ERROR, SettingsEnums.PAGE_UNKNOWN, fragmentName, 1);
} catch (Exception e) {
Log.w(TAG, "Get slice data from XML failed ", e);
mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_VERIFY_SLICE_OTHER_EXCEPTION, SettingsEnums.PAGE_UNKNOWN, fragmentName + "_" + controllerClassName, 1);
} finally {
if (parser != null)
parser.close();
}
return xmlSliceData;
}
use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SettingsSliceProvider method loadSlice.
@VisibleForTesting
void loadSlice(Uri uri) {
long startBuildTime = System.currentTimeMillis();
final SliceData sliceData;
try {
sliceData = mSlicesDatabaseAccessor.getSliceDataFromUri(uri);
} catch (IllegalStateException e) {
Log.d(TAG, "Could not create slicedata for uri: " + uri, e);
return;
}
final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(getContext(), sliceData);
final IntentFilter filter = controller.getIntentFilter();
if (filter != null) {
registerIntentToUri(filter, uri);
}
ThreadUtils.postOnMainThread(() -> startBackgroundWorker(controller, uri));
mSliceWeakDataCache.put(uri, sliceData);
getContext().getContentResolver().notifyChange(uri, null);
Log.d(TAG, "Built slice (" + uri + ") in: " + (System.currentTimeMillis() - startBuildTime));
}
use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SliceBroadcastReceiver method handleCopyAction.
private void handleCopyAction(Context context, String key, boolean isPlatformSlice) {
if (TextUtils.isEmpty(key)) {
throw new IllegalArgumentException("No key passed to Intent for controller");
}
final BasePreferenceController controller = getPreferenceController(context, key);
if (!(controller instanceof Sliceable)) {
throw new IllegalArgumentException("Copyable action passed for a non-copyable key:" + key);
}
if (!controller.isAvailable()) {
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
if (!controller.hasAsyncUpdate()) {
updateUri(context, key, isPlatformSlice);
}
return;
}
controller.copy();
}
use of com.android.settings.core.BasePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SliceBroadcastReceiver method handleToggleAction.
private void handleToggleAction(Context context, String key, boolean isChecked, boolean isPlatformSlice) {
if (TextUtils.isEmpty(key)) {
throw new IllegalStateException("No key passed to Intent for toggle controller");
}
final BasePreferenceController controller = getPreferenceController(context, key);
if (!(controller instanceof TogglePreferenceController)) {
throw new IllegalStateException("Toggle action passed for a non-toggle key: " + key);
}
if (!controller.isAvailable()) {
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
if (!controller.hasAsyncUpdate()) {
updateUri(context, key, isPlatformSlice);
}
return;
}
// TODO post context.getContentResolver().notifyChanged(uri, null) in the Toggle controller
// so that it's automatically broadcast to any slice.
final TogglePreferenceController toggleController = (TogglePreferenceController) controller;
toggleController.setChecked(isChecked);
logSliceValueChange(context, key, isChecked ? 1 : 0);
if (!controller.hasAsyncUpdate()) {
updateUri(context, key, isPlatformSlice);
}
}
Aggregations