Add indexing for SwitchPreferences

- now support the SwitchPreferences and save the "switchOn" and "switchOff"
attributes
- update Index database schema (and increment its version)
- fix an issue with some previous schema not rebuilt

Change-Id: I9cd48c666525f19474ef9bd5746d61b589058063
This commit is contained in:
Fabrice Di Meglio
2014-04-02 19:37:39 -07:00
parent a41707200b
commit dd41dfc483
3 changed files with 105 additions and 31 deletions

View File

@@ -61,14 +61,16 @@ public class Index {
public static final int COLUMN_INDEX_SUMMARY_ON = 2;
public static final int COLUMN_INDEX_SUMMARY_OFF = 3;
public static final int COLUMN_INDEX_ENTRIES = 4;
public static final int COLUMN_INDEX_KEYWORDS = 5;
public static final int COLUMN_INDEX_CLASS_NAME = 6;
public static final int COLUMN_INDEX_SCREEN_TITLE = 7;
public static final int COLUMN_INDEX_ICON = 8;
public static final int COLUMN_INDEX_INTENT_ACTION = 9;
public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE = 10;
public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS = 11;
public static final int COLUMN_INDEX_ENABLED = 12;
public static final int COLUMN_INDEX_SWITCH_ON = 5;
public static final int COLUMN_INDEX_SWITCH_OFF = 6;
public static final int COLUMN_INDEX_KEYWORDS = 7;
public static final int COLUMN_INDEX_CLASS_NAME = 8;
public static final int COLUMN_INDEX_SCREEN_TITLE = 9;
public static final int COLUMN_INDEX_ICON = 10;
public static final int COLUMN_INDEX_INTENT_ACTION = 11;
public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE = 12;
public static final int COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS = 13;
public static final int COLUMN_INDEX_ENABLED = 14;
// If you change the order of columns here, you SHOULD change the COLUMN_INDEX_XXX values
private static final String[] SELECT_COLUMNS = new String[] {
@@ -77,13 +79,15 @@ public class Index {
IndexColumns.DATA_SUMMARY_ON, // 2
IndexColumns.DATA_SUMMARY_OFF, // 3
IndexColumns.DATA_ENTRIES, // 4
IndexColumns.DATA_KEYWORDS, // 5
IndexColumns.CLASS_NAME, // 6
IndexColumns.SCREEN_TITLE, // 7
IndexColumns.ICON, // 8
IndexColumns.INTENT_ACTION, // 9
IndexColumns.INTENT_TARGET_PACKAGE, // 10
IndexColumns.INTENT_TARGET_CLASS // 11
IndexColumns.DATA_SWITCH_ON, // 5
IndexColumns.DATA_SWITCH_OFF, // 6
IndexColumns.DATA_KEYWORDS, // 7
IndexColumns.CLASS_NAME, // 8
IndexColumns.SCREEN_TITLE, // 9
IndexColumns.ICON, // 10
IndexColumns.INTENT_ACTION, // 11
IndexColumns.INTENT_TARGET_PACKAGE, // 12
IndexColumns.INTENT_TARGET_CLASS // 13
};
private static final String[] MATCH_COLUMNS = {
@@ -93,6 +97,10 @@ public class Index {
IndexColumns.DATA_SUMMARY_ON_NORMALIZED,
IndexColumns.DATA_SUMMARY_OFF,
IndexColumns.DATA_SUMMARY_OFF_NORMALIZED,
IndexColumns.DATA_SWITCH_ON,
IndexColumns.DATA_SWITCH_ON_NORMALIZED,
IndexColumns.DATA_SWITCH_OFF,
IndexColumns.DATA_SWITCH_OFF_NORMALIZED,
IndexColumns.DATA_ENTRIES,
IndexColumns.DATA_KEYWORDS
};
@@ -107,6 +115,7 @@ public class Index {
private static final String NODE_NAME_PREFERENCE_SCREEN = "PreferenceScreen";
private static final String NODE_NAME_CHECK_BOX_PREFERENCE = "CheckBoxPreference";
private static final String NODE_NAME_LIST_PREFERENCE = "ListPreference";
private static final String NODE_NAME_SWITCH_PREFERENCE = "SwitchPreference";
private static Index sInstance;
private final AtomicBoolean mIsAvailable = new AtomicBoolean(false);
@@ -353,16 +362,18 @@ public class Index {
final String summaryOn = cursor.getString(2);
final String summaryOff = cursor.getString(3);
final String entries = cursor.getString(4);
final String keywords = cursor.getString(5);
final String switchOn = cursor.getString(5);
final String switchOff = cursor.getString(6);
final String keywords = cursor.getString(7);
final String screenTitle = cursor.getString(6);
final String screenTitle = cursor.getString(8);
final String className = cursor.getString(7);
final int iconResId = cursor.getInt(8);
final String className = cursor.getString(9);
final int iconResId = cursor.getInt(10);
final String action = cursor.getString(9);
final String targetPackage = cursor.getString(10);
final String targetClass = cursor.getString(11);
final String action = cursor.getString(11);
final String targetPackage = cursor.getString(12);
final String targetClass = cursor.getString(13);
SearchIndexableRaw data = new SearchIndexableRaw(packageContext);
data.rank = rank;
@@ -370,6 +381,8 @@ public class Index {
data.summaryOn = summaryOn;
data.summaryOff = summaryOff;
data.entries = entries;
data.switchOn = switchOn;
data.switchOff = switchOff;
data.keywords = keywords;
data.screenTitle = screenTitle;
data.className = className;
@@ -494,7 +507,7 @@ public class Index {
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
updateOneRowWithFilteredData(database, localeStr, title, summary, null, null,
fragmentName, screenTitle, iconResId, rank, keywords,
null, null, fragmentName, screenTitle, iconResId, rank, keywords,
intentAction, intentTargetPackage, intentTargetClass, true);
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
@@ -512,20 +525,26 @@ public class Index {
summary = getDataSummary(context, attrs);
String entries = null;
String switchOn = null;
String switchOff = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
entries = getDataEntries(context, attrs);
} else if (nodeName.endsWith(NODE_NAME_SWITCH_PREFERENCE)) {
switchOn = getDataSwitchOn(context, attrs);
switchOff = getDataSwitchOff(context, attrs);
}
// Insert rows for the child nodes of PreferenceScreen
updateOneRowWithFilteredData(database, localeStr, title, summary, null, entries,
fragmentName, screenTitle, iconResId, rank, keywords,
switchOn, switchOff, fragmentName, screenTitle, iconResId, rank, keywords,
intentAction, intentTargetPackage, intentTargetClass, true);
} else if (nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
final String summaryOn = getDataSummaryOn(context, attrs);
final String summaryOff = getDataSummaryOff(context, attrs);
updateOneRowWithFilteredData(database, localeStr, title, summaryOn, summaryOff,
null, fragmentName, screenTitle, iconResId, rank, keywords,
null, null, null, fragmentName, screenTitle, iconResId, rank, keywords,
intentAction, intentTargetPackage, intentTargetClass, true);
}
}
@@ -551,6 +570,8 @@ public class Index {
raw.summaryOn,
raw.summaryOff,
raw.entries,
raw.switchOn,
raw.switchOff,
raw.className,
raw.screenTitle,
raw.iconResId,
@@ -588,6 +609,8 @@ public class Index {
raw.summaryOn,
raw.summaryOff,
raw.entries,
raw.switchOn,
raw.switchOff,
sir.className,
raw.screenTitle,
sir.iconResId,
@@ -630,7 +653,8 @@ public class Index {
}
private void updateOneRowWithFilteredData(SQLiteDatabase database, String locale,
String title, String summaryOn, String summaryOff, String entries, String className,
String title, String summaryOn, String summaryOff, String entries,
String switchOn, String switchOff, String className,
String screenTitle, int iconResId, int rank, String keywords,
String intentAction, String intentTargetPackage, String intentTargetClass,
boolean enabled) {
@@ -657,21 +681,41 @@ public class Index {
updatedSummaryOff = EMPTY;
}
String updatedSwitchOn;
if (switchOn != null) {
updatedSwitchOn = switchOn.replaceAll(NON_BREAKING_HYPHEN, HYPHEN);
} else {
updatedSwitchOn = EMPTY;
}
String updatedSwitchOff;
if (switchOff != null) {
updatedSwitchOff = switchOff.replaceAll(NON_BREAKING_HYPHEN, HYPHEN);
} else {
updatedSwitchOff = EMPTY;
}
String normalizedTitle = updatedTitle.replaceAll(HYPHEN, EMPTY);
String normalizedSummaryOn = updatedSummaryOn.replaceAll(HYPHEN, EMPTY);
String normalizedSummaryOff = updatedSummaryOff.replaceAll(HYPHEN, EMPTY);
String normalizedSwitchOn = updatedSwitchOn.replaceAll(HYPHEN, EMPTY);
String normalizedSwitchOff = updatedSwitchOff.replaceAll(HYPHEN, EMPTY);
updateOneRow(database, locale,
updatedTitle, normalizedTitle, updatedSummaryOn, normalizedSummaryOn,
updatedSummaryOff, normalizedSummaryOff, entries, className, screenTitle, iconResId,
updatedSummaryOff, normalizedSummaryOff, entries,
updatedSwitchOn, normalizedSwitchOn, updatedSwitchOff, normalizedSwitchOff,
className, screenTitle, iconResId,
rank, keywords, intentAction, intentTargetPackage, intentTargetClass, enabled);
}
private void updateOneRow(SQLiteDatabase database, String locale,
String updatedTitle, String normalizedTitle,
String updatedSummaryOn, String normalizedSummaryOn,
String updatedSummaryOff, String normalizedSummaryOff, String entries, String className,
String screenTitle, int iconResId, int rank, String keywords,
String updatedSummaryOff, String normalizedSummaryOff, String entries,
String updatedSwitchOn, String normalizedSwitchOn,
String updatedSwitchOff, String normalizedSwitchOff,
String className, String screenTitle, int iconResId, int rank, String keywords,
String intentAction, String intentTargetPackage, String intentTargetClass,
boolean enabled) {
@@ -690,6 +734,10 @@ public class Index {
values.put(IndexColumns.DATA_SUMMARY_OFF, updatedSummaryOff);
values.put(IndexColumns.DATA_SUMMARY_OFF_NORMALIZED, normalizedSummaryOff);
values.put(IndexColumns.DATA_ENTRIES, entries);
values.put(IndexColumns.DATA_SWITCH_ON, updatedSwitchOn);
values.put(IndexColumns.DATA_SWITCH_ON_NORMALIZED, normalizedSwitchOn);
values.put(IndexColumns.DATA_SWITCH_OFF, updatedSwitchOff);
values.put(IndexColumns.DATA_SWITCH_OFF_NORMALIZED, normalizedSwitchOff);
values.put(IndexColumns.DATA_KEYWORDS, keywords);
values.put(IndexColumns.CLASS_NAME, className);
values.put(IndexColumns.SCREEN_TITLE, screenTitle);
@@ -732,6 +780,18 @@ public class Index {
com.android.internal.R.styleable.ListPreference_entries);
}
private String getDataSwitchOn(Context context, AttributeSet attrs) {
return getData(context, attrs,
com.android.internal.R.styleable.SwitchPreference,
com.android.internal.R.styleable.SwitchPreference_switchTextOn);
}
private String getDataSwitchOff(Context context, AttributeSet attrs) {
return getData(context, attrs,
com.android.internal.R.styleable.SwitchPreference,
com.android.internal.R.styleable.SwitchPreference_switchTextOff);
}
private String getDataKeywords(Context context, AttributeSet attrs) {
return getData(context, attrs, R.styleable.Preference, R.styleable.Preference_keywords);
}