diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2014-03-12 17:12:26 -0700 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2014-03-20 14:02:42 -0700 |
commit | 5135dce1429facfd764f4afffe69d60c19589750 (patch) | |
tree | 2bd90588e95515377e3f85daf360a2adf88d0e86 /src/com/android/settings | |
parent | b4f18b8d3bc8f104ba2c0913b1023883ebbcec66 (diff) | |
download | packages_apps_Settings-5135dce1429facfd764f4afffe69d60c19589750.tar.gz packages_apps_Settings-5135dce1429facfd764f4afffe69d60c19589750.tar.bz2 packages_apps_Settings-5135dce1429facfd764f4afffe69d60c19589750.zip |
Add indexing for cached Bluetooth (BT) paired devices
- comply to the SEARCH_INDEX_DATA_PROVIDER
- add to the Index the name of previously paired BT devices
(this will work for now only and only if BT has been on during
the indexing)
Change-Id: I00065db0f4e9657cca3578a2fafa0ec39cfaa432
Diffstat (limited to 'src/com/android/settings')
3 files changed, 56 insertions, 8 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java index acd9dada7..35c9d6c35 100755 --- a/src/com/android/settings/bluetooth/BluetoothSettings.java +++ b/src/com/android/settings/bluetooth/BluetoothSettings.java @@ -26,11 +26,13 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Resources; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceCategory; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; +import android.provider.SearchIndexableResource; import android.util.Log; import android.view.Gravity; import android.view.Menu; @@ -42,12 +44,19 @@ import android.widget.TextView; import com.android.settings.R; import com.android.settings.SettingsActivity; +import com.android.settings.search.Indexable; +import com.android.settings.search.SearchIndexableRaw; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; /** * BluetoothSettings is the Settings screen for Bluetooth configuration and * connection management. */ -public final class BluetoothSettings extends DeviceListPreferenceFragment { +public final class BluetoothSettings extends DeviceListPreferenceFragment implements Indexable { private static final String TAG = "BluetoothSettings"; private static final int MENU_ID_SCAN = Menu.FIRST; @@ -410,4 +419,42 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment { protected int getHelpResource() { return R.string.help_url_bluetooth; } + + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new SearchIndexProvider() { + + @Override + public List<SearchIndexableResource> getXmlResourcesToIndex(Context context) { + return null; + } + + @Override + public List<SearchIndexableRaw> getRawDataToIndex(Context context) { + + final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>(); + + final Resources res = context.getResources(); + + // Add fragment title + SearchIndexableRaw data = new SearchIndexableRaw(context); + data.title = res.getString(R.string.bluetooth_settings); + data.screenTitle = res.getString(R.string.bluetooth_settings); + result.add(data); + + // Add cached paired BT devices + LocalBluetoothManager lbtm = LocalBluetoothManager.getInstance(context); + Set<BluetoothDevice> bondedDevices = + lbtm.getBluetoothAdapter().getBondedDevices(); + + for (BluetoothDevice device : bondedDevices) { + data = new SearchIndexableRaw(context); + data.title = device.getName(); + data.screenTitle = res.getString(R.string.bluetooth_settings); + result.add(data); + } + + return result; + } + }; + } diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java index 312854705..bf7f71ffd 100644 --- a/src/com/android/settings/search/Index.java +++ b/src/com/android/settings/search/Index.java @@ -183,9 +183,9 @@ public class Index { SearchIndexablesContract.INDEXABLES_RAW_PATH); } - private void addIndexablesForXmlResourceUri(Context context, String packageName, Uri uri, + private void addIndexablesForXmlResourceUri(Context packageContext, String packageName, Uri uri, String[] projection) { - final ContentResolver resolver = context.getContentResolver(); + final ContentResolver resolver = packageContext.getContentResolver(); final Cursor cursor = resolver.query(uri, projection, null, null, null); @@ -209,7 +209,7 @@ public class Index { final String targetPackage = cursor.getString(5); final String targetClass = cursor.getString(6); - SearchIndexableResource sir = new SearchIndexableResource(context); + SearchIndexableResource sir = new SearchIndexableResource(packageContext); sir.rank = rank; sir.xmlResId = xmlResId; sir.className = className; @@ -227,9 +227,9 @@ public class Index { } } - private void addIndexablesForRawDataUri(Context context, String packageName, Uri uri, + private void addIndexablesForRawDataUri(Context packageContext, String packageName, Uri uri, String[] projection) { - final ContentResolver resolver = context.getContentResolver(); + final ContentResolver resolver = packageContext.getContentResolver(); final Cursor cursor = resolver.query(uri, projection, null, null, null); @@ -257,7 +257,7 @@ public class Index { final String targetPackage = cursor.getString(8); final String targetClass = cursor.getString(9); - SearchIndexableRaw data = new SearchIndexableRaw(context); + SearchIndexableRaw data = new SearchIndexableRaw(packageContext); data.rank = rank; data.title = title; data.summary = summary; @@ -472,6 +472,7 @@ public class Index { sir.xmlResId, sir.className, sir.iconResId, sir.rank, sir.intentAction, sir.intentTargetPackage, sir.intentTargetClass); } else if (!TextUtils.isEmpty(sir.className)) { + sir.context = mContext; indexFromLocalProvider(database, localeStr, sir); } } diff --git a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java index 467357286..56904922f 100644 --- a/src/com/android/settings/search/SettingsSearchIndexablesProvider.java +++ b/src/com/android/settings/search/SettingsSearchIndexablesProvider.java @@ -54,7 +54,7 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider { new SearchIndexableResource(1, NO_DATA_RES_ID, WifiSettings.class.getName(), R.drawable.ic_settings_wireless), - new SearchIndexableResource(2, R.xml.bluetooth_settings, + new SearchIndexableResource(2, NO_DATA_RES_ID, BluetoothSettings.class.getName(), R.drawable.ic_settings_bluetooth2), new SearchIndexableResource(3, R.xml.data_usage_metered_prefs, |