Merge "Some code refactoring"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2f1b4e2fd9
@@ -530,7 +530,7 @@ public class Index {
|
|||||||
|
|
||||||
private void indexOneResource(SQLiteDatabase database, String localeStr,
|
private void indexOneResource(SQLiteDatabase database, String localeStr,
|
||||||
SearchIndexableResource sir) {
|
SearchIndexableResource sir) {
|
||||||
if (sir.xmlResId > 0) {
|
if (sir.xmlResId > SearchIndexableResources.NO_DATA_RES_ID) {
|
||||||
indexFromResource(sir.context, database, localeStr,
|
indexFromResource(sir.context, database, localeStr,
|
||||||
sir.xmlResId, sir.className, sir.iconResId, sir.rank,
|
sir.xmlResId, sir.className, sir.iconResId, sir.rank,
|
||||||
sir.intentAction, sir.intentTargetPackage, sir.intentTargetClass);
|
sir.intentAction, sir.intentTargetPackage, sir.intentTargetClass);
|
||||||
@@ -646,72 +646,80 @@ public class Index {
|
|||||||
raw.key);
|
raw.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indexFromLocalProvider(SQLiteDatabase database, String localeStr,
|
private Indexable.SearchIndexProvider getSearchIndexProvider(String className) {
|
||||||
SearchIndexableResource sir) {
|
|
||||||
try {
|
try {
|
||||||
final Class<?> clazz = Class.forName(sir.className);
|
final Class<?> clazz = Class.forName(className);
|
||||||
if (Indexable.class.isAssignableFrom(clazz)) {
|
if (Indexable.class.isAssignableFrom(clazz)) {
|
||||||
final Field f = clazz.getField(FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER);
|
final Field f = clazz.getField(FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER);
|
||||||
final Indexable.SearchIndexProvider provider =
|
return (Indexable.SearchIndexProvider) f.get(null);
|
||||||
(Indexable.SearchIndexProvider) f.get(null);
|
|
||||||
|
|
||||||
final List<SearchIndexableRaw> rawList =
|
|
||||||
provider.getRawDataToIndex(sir.context, sir.enabled);
|
|
||||||
if (rawList != null) {
|
|
||||||
final int rawSize = rawList.size();
|
|
||||||
for (int i = 0; i < rawSize; i++) {
|
|
||||||
SearchIndexableRaw raw = rawList.get(i);
|
|
||||||
|
|
||||||
// Should be the same locale as the one we are processing
|
|
||||||
if (!raw.locale.toString().equalsIgnoreCase(localeStr)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateOneRowWithFilteredData(database, localeStr,
|
|
||||||
raw.title,
|
|
||||||
raw.summaryOn,
|
|
||||||
raw.summaryOff,
|
|
||||||
raw.entries,
|
|
||||||
sir.className,
|
|
||||||
raw.screenTitle,
|
|
||||||
sir.iconResId,
|
|
||||||
sir.rank,
|
|
||||||
raw.keywords,
|
|
||||||
raw.intentAction,
|
|
||||||
raw.intentTargetPackage,
|
|
||||||
raw.intentTargetClass,
|
|
||||||
raw.enabled,
|
|
||||||
raw.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<SearchIndexableResource> resList =
|
|
||||||
provider.getXmlResourcesToIndex(sir.context, sir.enabled);
|
|
||||||
if (resList != null) {
|
|
||||||
final int resSize = resList.size();
|
|
||||||
for (int i = 0; i < resSize; i++) {
|
|
||||||
SearchIndexableResource item = resList.get(i);
|
|
||||||
|
|
||||||
// Should be the same locale as the one we are processing
|
|
||||||
if (!item.locale.toString().equalsIgnoreCase(localeStr)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
indexFromResource(sir.context, database, localeStr,
|
|
||||||
item.xmlResId, item.className, item.iconResId, item.rank,
|
|
||||||
item.intentAction, item.intentTargetPackage,
|
|
||||||
item.intentTargetClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
Log.e(LOG_TAG, "Cannot find class: " + sir.className, e);
|
Log.e(LOG_TAG, "Cannot find class: " + className, e);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
Log.e(LOG_TAG, "Cannot find field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'", e);
|
Log.e(LOG_TAG, "Cannot find field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'", e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Log.e(LOG_TAG,
|
Log.e(LOG_TAG,
|
||||||
"Illegal access to field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'", e);
|
"Illegal access to field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'", e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void indexFromLocalProvider(SQLiteDatabase database, String localeStr,
|
||||||
|
SearchIndexableResource sir) {
|
||||||
|
final Indexable.SearchIndexProvider provider = getSearchIndexProvider(sir.className);
|
||||||
|
if (provider == null) {
|
||||||
|
Log.w(LOG_TAG, "Cannot find provider: " + sir.className);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<SearchIndexableRaw> rawList =
|
||||||
|
provider.getRawDataToIndex(sir.context, sir.enabled);
|
||||||
|
if (rawList != null) {
|
||||||
|
final int rawSize = rawList.size();
|
||||||
|
for (int i = 0; i < rawSize; i++) {
|
||||||
|
SearchIndexableRaw raw = rawList.get(i);
|
||||||
|
|
||||||
|
// Should be the same locale as the one we are processing
|
||||||
|
if (!raw.locale.toString().equalsIgnoreCase(localeStr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateOneRowWithFilteredData(database, localeStr,
|
||||||
|
raw.title,
|
||||||
|
raw.summaryOn,
|
||||||
|
raw.summaryOff,
|
||||||
|
raw.entries,
|
||||||
|
sir.className,
|
||||||
|
raw.screenTitle,
|
||||||
|
sir.iconResId,
|
||||||
|
sir.rank,
|
||||||
|
raw.keywords,
|
||||||
|
raw.intentAction,
|
||||||
|
raw.intentTargetPackage,
|
||||||
|
raw.intentTargetClass,
|
||||||
|
raw.enabled,
|
||||||
|
raw.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<SearchIndexableResource> resList =
|
||||||
|
provider.getXmlResourcesToIndex(sir.context, sir.enabled);
|
||||||
|
if (resList != null) {
|
||||||
|
final int resSize = resList.size();
|
||||||
|
for (int i = 0; i < resSize; i++) {
|
||||||
|
SearchIndexableResource item = resList.get(i);
|
||||||
|
|
||||||
|
// Should be the same locale as the one we are processing
|
||||||
|
if (!item.locale.toString().equalsIgnoreCase(localeStr)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
indexFromResource(sir.context, database, localeStr,
|
||||||
|
item.xmlResId, item.className, item.iconResId, item.rank,
|
||||||
|
item.intentAction, item.intentTargetPackage,
|
||||||
|
item.intentTargetClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateOneRowWithFilteredData(SQLiteDatabase database, String locale,
|
private void updateOneRowWithFilteredData(SQLiteDatabase database, String locale,
|
||||||
|
@@ -47,7 +47,7 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public final class SearchIndexableResources {
|
public final class SearchIndexableResources {
|
||||||
|
|
||||||
private static int NO_DATA_RES_ID = 0;
|
public static int NO_DATA_RES_ID = 0;
|
||||||
|
|
||||||
private static final int RANK_WIFI = 1;
|
private static final int RANK_WIFI = 1;
|
||||||
private static final int RANK_BT = 2;
|
private static final int RANK_BT = 2;
|
||||||
|
Reference in New Issue
Block a user