Add Indexable.SearchIndexProvider.getNonIndexableKeys(Context)
- getNonIndexableKeys(Context) allow a SearchIndexProvider to tell which data he does not want to index by providing a list of the data keys - use this new API for SoundSettings and removing KEY_EMERGENCY_TONE related settings if the device is not CDMA - add a BaseSearchIndexProvider for code simplification Change-Id: I23633ace1d7e390ee05fac0a5458a33e04e72d8d
This commit is contained in:
49
src/com/android/settings/search/BaseSearchIndexProvider.java
Normal file
49
src/com/android/settings/search/BaseSearchIndexProvider.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A basic SearchIndexProvider that returns no data to index.
|
||||
*/
|
||||
public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
|
||||
private static final List<String> EMPTY_LIST = Collections.<String>emptyList();
|
||||
|
||||
public BaseSearchIndexProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, boolean enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
return EMPTY_LIST;
|
||||
}
|
||||
}
|
@@ -46,6 +46,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -136,6 +137,8 @@ public class Index {
|
||||
private static final String NODE_NAME_CHECK_BOX_PREFERENCE = "CheckBoxPreference";
|
||||
private static final String NODE_NAME_LIST_PREFERENCE = "ListPreference";
|
||||
|
||||
private static final List<String> EMPTY_LIST = Collections.<String>emptyList();
|
||||
|
||||
private static Index sInstance;
|
||||
private final AtomicBoolean mIsAvailable = new AtomicBoolean(false);
|
||||
private final UpdateData mDataToProcess = new UpdateData();
|
||||
@@ -530,19 +533,35 @@ public class Index {
|
||||
|
||||
private void indexOneResource(SQLiteDatabase database, String localeStr,
|
||||
SearchIndexableResource sir) {
|
||||
|
||||
if (sir == null) {
|
||||
Log.e(LOG_TAG, "Cannot index a null resource!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Will be non null only for a Local provider
|
||||
final Indexable.SearchIndexProvider provider =
|
||||
TextUtils.isEmpty(sir.className) ? null : getSearchIndexProvider(sir.className);
|
||||
|
||||
if (sir.xmlResId > SearchIndexableResources.NO_DATA_RES_ID) {
|
||||
List<String> doNotIndexKeys = EMPTY_LIST;
|
||||
if (provider != null) {
|
||||
doNotIndexKeys = provider.getNonIndexableKeys(sir.context);
|
||||
}
|
||||
indexFromResource(sir.context, database, localeStr,
|
||||
sir.xmlResId, sir.className, sir.iconResId, sir.rank,
|
||||
sir.intentAction, sir.intentTargetPackage, sir.intentTargetClass);
|
||||
sir.intentAction, sir.intentTargetPackage, sir.intentTargetClass,
|
||||
doNotIndexKeys);
|
||||
} else if (!TextUtils.isEmpty(sir.className)) {
|
||||
sir.context = mContext;
|
||||
indexFromLocalProvider(database, localeStr, sir);
|
||||
indexFromLocalProvider(mContext, database, localeStr, provider, sir.className,
|
||||
sir.iconResId, sir.rank, sir.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
private void indexFromResource(Context context, SQLiteDatabase database, String localeStr,
|
||||
int xmlResId, String fragmentName, int iconResId, int rank,
|
||||
String intentAction, String intentTargetPackage, String intentTargetClass) {
|
||||
int xmlResId, String fragmentName, int iconResId, int rank,
|
||||
String intentAction, String intentTargetPackage, String intentTargetClass,
|
||||
List<String> doNotIndexKeys) {
|
||||
|
||||
XmlResourceParser parser = null;
|
||||
try {
|
||||
@@ -563,18 +582,26 @@ public class Index {
|
||||
|
||||
final int outerDepth = parser.getDepth();
|
||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
|
||||
final String screenTitle = getDataTitle(context, attrs);
|
||||
|
||||
String title = getDataTitle(context, attrs);
|
||||
String summary = getDataSummary(context, attrs);
|
||||
String keywords = getDataKeywords(context, attrs);
|
||||
String key = getDataKey(context, attrs);
|
||||
|
||||
String title;
|
||||
String summary;
|
||||
String keywords;
|
||||
|
||||
// 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, intentAction, intentTargetPackage, intentTargetClass, true, key);
|
||||
if (!doNotIndexKeys.contains(key)) {
|
||||
title = getDataTitle(context, attrs);
|
||||
summary = getDataSummary(context, attrs);
|
||||
keywords = getDataKeywords(context, attrs);
|
||||
|
||||
updateOneRowWithFilteredData(database, localeStr, title, summary, null, null,
|
||||
fragmentName, screenTitle, iconResId, rank,
|
||||
keywords, intentAction, intentTargetPackage, intentTargetClass, true, key);
|
||||
}
|
||||
|
||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
|
||||
@@ -584,9 +611,13 @@ public class Index {
|
||||
|
||||
nodeName = parser.getName();
|
||||
|
||||
key = getDataKey(context, attrs);
|
||||
if (doNotIndexKeys.contains(key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
title = getDataTitle(context, attrs);
|
||||
keywords = getDataKeywords(context, attrs);
|
||||
key = getDataKey(context, attrs);
|
||||
|
||||
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
|
||||
summary = getDataSummary(context, attrs);
|
||||
@@ -664,16 +695,18 @@ public class Index {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void indexFromLocalProvider(SQLiteDatabase database, String localeStr,
|
||||
SearchIndexableResource sir) {
|
||||
final Indexable.SearchIndexProvider provider = getSearchIndexProvider(sir.className);
|
||||
private void indexFromLocalProvider(Context context, SQLiteDatabase database, String localeStr,
|
||||
Indexable.SearchIndexProvider provider, String className, int iconResId, int rank,
|
||||
boolean enabled) {
|
||||
|
||||
if (provider == null) {
|
||||
Log.w(LOG_TAG, "Cannot find provider: " + sir.className);
|
||||
Log.w(LOG_TAG, "Cannot find provider: " + className);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<SearchIndexableRaw> rawList =
|
||||
provider.getRawDataToIndex(sir.context, sir.enabled);
|
||||
final List<String> doNotIndexKeys = provider.getNonIndexableKeys(context);
|
||||
final List<SearchIndexableRaw> rawList = provider.getRawDataToIndex(context, enabled);
|
||||
|
||||
if (rawList != null) {
|
||||
final int rawSize = rawList.size();
|
||||
for (int i = 0; i < rawSize; i++) {
|
||||
@@ -684,15 +717,19 @@ public class Index {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (doNotIndexKeys.contains(raw.key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
updateOneRowWithFilteredData(database, localeStr,
|
||||
raw.title,
|
||||
raw.summaryOn,
|
||||
raw.summaryOff,
|
||||
raw.entries,
|
||||
sir.className,
|
||||
className,
|
||||
raw.screenTitle,
|
||||
sir.iconResId,
|
||||
sir.rank,
|
||||
iconResId,
|
||||
rank,
|
||||
raw.keywords,
|
||||
raw.intentAction,
|
||||
raw.intentTargetPackage,
|
||||
@@ -703,7 +740,7 @@ public class Index {
|
||||
}
|
||||
|
||||
final List<SearchIndexableResource> resList =
|
||||
provider.getXmlResourcesToIndex(sir.context, sir.enabled);
|
||||
provider.getXmlResourcesToIndex(context, enabled);
|
||||
if (resList != null) {
|
||||
final int resSize = resList.size();
|
||||
for (int i = 0; i < resSize; i++) {
|
||||
@@ -714,10 +751,10 @@ public class Index {
|
||||
continue;
|
||||
}
|
||||
|
||||
indexFromResource(sir.context, database, localeStr,
|
||||
indexFromResource(context, database, localeStr,
|
||||
item.xmlResId, item.className, item.iconResId, item.rank,
|
||||
item.intentAction, item.intentTargetPackage,
|
||||
item.intentTargetClass);
|
||||
item.intentTargetClass, doNotIndexKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -57,5 +57,13 @@ public interface Indexable {
|
||||
* @return a list of {@link SearchIndexableRaw} references. Can be null.
|
||||
*/
|
||||
List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled);
|
||||
|
||||
/**
|
||||
* Return a list of data keys that cannot be indexed. See {@link SearchIndexableRaw}
|
||||
*
|
||||
* @param context the context.
|
||||
* @return a list of {@link SearchIndexableRaw} references. Can be null.
|
||||
*/
|
||||
List<String> getNonIndexableKeys(Context context);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user