Move xmlParserUtils to core
This class is currently used by both search and slice, in the future will be used by DashboardFragment to build controller list. So the scope of this class is beyond search now. Test: rerun robotests Change-Id: If43ebca065aac31ad24f95a94bfe5be784109605
This commit is contained in:
@@ -29,6 +29,7 @@ import android.util.Xml;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.PreferenceXmlParserUtils;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
@@ -119,7 +120,7 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
try {
|
||||
while (parser.next() != XmlPullParser.END_DOCUMENT) {
|
||||
final String key = XmlParserUtils.getDataKey(context, attrs);
|
||||
final String key = PreferenceXmlParserUtils.getDataKey(context, attrs);
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
nonIndexableKeys.add(key);
|
||||
}
|
||||
|
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Utility class to parse elements of XML preferences
|
||||
*/
|
||||
public class XmlParserUtils {
|
||||
|
||||
private static final String ENTRIES_SEPARATOR = "|";
|
||||
|
||||
public static String getDataKey(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs,
|
||||
com.android.internal.R.styleable.Preference,
|
||||
com.android.internal.R.styleable.Preference_key);
|
||||
}
|
||||
|
||||
public static String getDataTitle(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs,
|
||||
com.android.internal.R.styleable.Preference,
|
||||
com.android.internal.R.styleable.Preference_title);
|
||||
}
|
||||
|
||||
public static String getDataSummary(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs,
|
||||
com.android.internal.R.styleable.Preference,
|
||||
com.android.internal.R.styleable.Preference_summary);
|
||||
}
|
||||
|
||||
public static String getDataSummaryOn(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs,
|
||||
com.android.internal.R.styleable.CheckBoxPreference,
|
||||
com.android.internal.R.styleable.CheckBoxPreference_summaryOn);
|
||||
}
|
||||
|
||||
public static String getDataSummaryOff(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs,
|
||||
com.android.internal.R.styleable.CheckBoxPreference,
|
||||
com.android.internal.R.styleable.CheckBoxPreference_summaryOff);
|
||||
}
|
||||
|
||||
public static String getDataEntries(Context context, AttributeSet attrs) {
|
||||
return getDataEntries(context, attrs,
|
||||
com.android.internal.R.styleable.ListPreference,
|
||||
com.android.internal.R.styleable.ListPreference_entries);
|
||||
}
|
||||
|
||||
public static String getDataKeywords(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs, R.styleable.Preference, R.styleable.Preference_keywords);
|
||||
}
|
||||
|
||||
public static String getController(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs, R.styleable.Preference, R.styleable.Preference_controller);
|
||||
}
|
||||
|
||||
public static int getDataIcon(Context context, AttributeSet attrs) {
|
||||
final TypedArray ta = context.obtainStyledAttributes(attrs,
|
||||
com.android.internal.R.styleable.Preference);
|
||||
final int dataIcon = ta.getResourceId(com.android.internal.R.styleable.Icon_icon, 0);
|
||||
ta.recycle();
|
||||
return dataIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fragment name if this preference launches a child fragment.
|
||||
*/
|
||||
public static String getDataChildFragment(Context context, AttributeSet attrs) {
|
||||
return getData(context, attrs, R.styleable.Preference,
|
||||
R.styleable.Preference_android_fragment);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getData(Context context, AttributeSet set, int[] attrs, int resId) {
|
||||
final TypedArray ta = context.obtainStyledAttributes(set, attrs);
|
||||
String data = ta.getString(resId);
|
||||
ta.recycle();
|
||||
return data;
|
||||
}
|
||||
|
||||
private static String getDataEntries(Context context, AttributeSet set, int[] attrs, int resId) {
|
||||
final TypedArray sa = context.obtainStyledAttributes(set, attrs);
|
||||
final TypedValue tv = sa.peekValue(resId);
|
||||
sa.recycle();
|
||||
String[] data = null;
|
||||
if (tv != null && tv.type == TypedValue.TYPE_REFERENCE) {
|
||||
if (tv.resourceId != 0) {
|
||||
data = context.getResources().getStringArray(tv.resourceId);
|
||||
}
|
||||
}
|
||||
final int count = (data == null ) ? 0 : data.length;
|
||||
if (count == 0) {
|
||||
return null;
|
||||
}
|
||||
final StringBuilder result = new StringBuilder();
|
||||
for (int n = 0; n < count; n++) {
|
||||
result.append(data[n]);
|
||||
result.append(ENTRIES_SEPARATOR);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
@@ -29,11 +29,10 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.search.DatabaseIndexingUtils;
|
||||
import com.android.settings.core.PreferenceXmlParserUtils;
|
||||
import com.android.settings.search.ResultPayload;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.search.XmlParserUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
@@ -161,8 +160,8 @@ public class IndexDataConverter {
|
||||
final int outerDepth = parser.getDepth();
|
||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
|
||||
final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
|
||||
String key = XmlParserUtils.getDataKey(context, attrs);
|
||||
final String screenTitle = PreferenceXmlParserUtils.getDataTitle(context, attrs);
|
||||
String key = PreferenceXmlParserUtils.getDataKey(context, attrs);
|
||||
|
||||
String title;
|
||||
String headerTitle;
|
||||
@@ -186,9 +185,9 @@ public class IndexDataConverter {
|
||||
.getPayloadKeyMap(fragmentName, context);
|
||||
}
|
||||
|
||||
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
|
||||
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
|
||||
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
|
||||
headerTitle = PreferenceXmlParserUtils.getDataTitle(context, attrs);
|
||||
headerSummary = PreferenceXmlParserUtils.getDataSummary(context, attrs);
|
||||
headerKeywords = PreferenceXmlParserUtils.getDataKeywords(context, attrs);
|
||||
enabled = !nonIndexableKeys.contains(key);
|
||||
|
||||
// TODO: Set payload type for header results
|
||||
@@ -217,11 +216,11 @@ public class IndexDataConverter {
|
||||
|
||||
nodeName = parser.getName();
|
||||
|
||||
title = XmlParserUtils.getDataTitle(context, attrs);
|
||||
key = XmlParserUtils.getDataKey(context, attrs);
|
||||
title = PreferenceXmlParserUtils.getDataTitle(context, attrs);
|
||||
key = PreferenceXmlParserUtils.getDataKey(context, attrs);
|
||||
enabled = !nonIndexableKeys.contains(key);
|
||||
keywords = XmlParserUtils.getDataKeywords(context, attrs);
|
||||
iconResId = XmlParserUtils.getDataIcon(context, attrs);
|
||||
keywords = PreferenceXmlParserUtils.getDataKeywords(context, attrs);
|
||||
iconResId = PreferenceXmlParserUtils.getDataIcon(context, attrs);
|
||||
|
||||
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
|
||||
isHeaderUnique = false;
|
||||
@@ -241,17 +240,17 @@ public class IndexDataConverter {
|
||||
.setUserId(-1 /* default user id */);
|
||||
|
||||
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
|
||||
summary = XmlParserUtils.getDataSummary(context, attrs);
|
||||
summary = PreferenceXmlParserUtils.getDataSummary(context, attrs);
|
||||
|
||||
String entries = null;
|
||||
|
||||
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
|
||||
entries = XmlParserUtils.getDataEntries(context, attrs);
|
||||
entries = PreferenceXmlParserUtils.getDataEntries(context, attrs);
|
||||
}
|
||||
|
||||
// TODO (b/62254931) index primitives instead of payload
|
||||
payload = controllerUriMap.get(key);
|
||||
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
|
||||
childFragment = PreferenceXmlParserUtils.getDataChildFragment(context, attrs);
|
||||
|
||||
builder.setSummaryOn(summary)
|
||||
.setEntries(entries)
|
||||
@@ -263,11 +262,11 @@ public class IndexDataConverter {
|
||||
// TODO (b/33577327) We removed summary off here. We should check if we can
|
||||
// merge this 'else' section with the one above. Put a break point to
|
||||
// investigate.
|
||||
String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
|
||||
String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
|
||||
String summaryOn = PreferenceXmlParserUtils.getDataSummaryOn(context, attrs);
|
||||
String summaryOff = PreferenceXmlParserUtils.getDataSummaryOff(context, attrs);
|
||||
|
||||
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
|
||||
summaryOn = XmlParserUtils.getDataSummary(context, attrs);
|
||||
summaryOn = PreferenceXmlParserUtils.getDataSummary(context, attrs);
|
||||
}
|
||||
|
||||
builder.setSummaryOn(summaryOn);
|
||||
|
Reference in New Issue
Block a user