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
diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java
index 246e8a0..987539b 100644
--- a/src/com/android/settings/search/Index.java
+++ b/src/com/android/settings/search/Index.java
@@ -61,14 +61,16 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
raw.summaryOn,
raw.summaryOff,
raw.entries,
+ raw.switchOn,
+ raw.switchOff,
raw.className,
raw.screenTitle,
raw.iconResId,
@@ -588,6 +609,8 @@
raw.summaryOn,
raw.summaryOff,
raw.entries,
+ raw.switchOn,
+ raw.switchOff,
sir.className,
raw.screenTitle,
sir.iconResId,
@@ -630,7 +653,8 @@
}
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 @@
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 @@
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 @@
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);
}
diff --git a/src/com/android/settings/search/IndexDatabaseHelper.java b/src/com/android/settings/search/IndexDatabaseHelper.java
index 65db6b4..bd035c3 100644
--- a/src/com/android/settings/search/IndexDatabaseHelper.java
+++ b/src/com/android/settings/search/IndexDatabaseHelper.java
@@ -28,7 +28,7 @@
private static final String TAG = "IndexDatabaseHelper";
private static final String DATABASE_NAME = "search_index.db";
- private static final int DATABASE_VERSION = 105;
+ private static final int DATABASE_VERSION = 106;
public interface Tables {
public static final String TABLE_PREFS_INDEX = "prefs_index";
@@ -46,6 +46,10 @@
public static final String DATA_SUMMARY_OFF = "data_summary_off";
public static final String DATA_SUMMARY_OFF_NORMALIZED = "data_summary_off_normalized";
public static final String DATA_ENTRIES = "data_entries";
+ public static final String DATA_SWITCH_ON = "data_switch_on";
+ public static final String DATA_SWITCH_ON_NORMALIZED = "data_switch_on_normalized";
+ public static final String DATA_SWITCH_OFF = "data_switch_off";
+ public static final String DATA_SWITCH_OFF_NORMALIZED = "data_switch_off_normalized";
public static final String DATA_KEYWORDS = "data_keywords";
public static final String CLASS_NAME = "class_name";
public static final String SCREEN_TITLE = "screen_title";
@@ -81,6 +85,14 @@
", " +
IndexColumns.DATA_ENTRIES +
", " +
+ IndexColumns.DATA_SWITCH_ON +
+ ", " +
+ IndexColumns.DATA_SWITCH_ON_NORMALIZED +
+ ", " +
+ IndexColumns.DATA_SWITCH_OFF +
+ ", " +
+ IndexColumns.DATA_SWITCH_OFF_NORMALIZED +
+ ", " +
IndexColumns.DATA_KEYWORDS +
", " +
IndexColumns.SCREEN_TITLE +
@@ -153,7 +165,7 @@
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- if (oldVersion == 100 || oldVersion == 101 || oldVersion == 102 || oldVersion == 103) {
+ if (oldVersion < DATABASE_VERSION) {
Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
// We need to drop the tables and recreate them
diff --git a/src/com/android/settings/search/SearchIndexableRaw.java b/src/com/android/settings/search/SearchIndexableRaw.java
index c4d187e..e661c87 100644
--- a/src/com/android/settings/search/SearchIndexableRaw.java
+++ b/src/com/android/settings/search/SearchIndexableRaw.java
@@ -32,6 +32,8 @@
public String summaryOn;
public String summaryOff;
public String entries;
+ public String switchOn;
+ public String switchOff;
public String keywords;
public String screenTitle;