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
This commit is contained in:
@@ -26,11 +26,13 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.provider.SearchIndexableResource;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -42,12 +44,19 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
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
|
* BluetoothSettings is the Settings screen for Bluetooth configuration and
|
||||||
* connection management.
|
* 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 String TAG = "BluetoothSettings";
|
||||||
|
|
||||||
private static final int MENU_ID_SCAN = Menu.FIRST;
|
private static final int MENU_ID_SCAN = Menu.FIRST;
|
||||||
@@ -410,4 +419,42 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
|||||||
protected int getHelpResource() {
|
protected int getHelpResource() {
|
||||||
return R.string.help_url_bluetooth;
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -183,9 +183,9 @@ public class Index {
|
|||||||
SearchIndexablesContract.INDEXABLES_RAW_PATH);
|
SearchIndexablesContract.INDEXABLES_RAW_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addIndexablesForXmlResourceUri(Context context, String packageName, Uri uri,
|
private void addIndexablesForXmlResourceUri(Context packageContext, String packageName, Uri uri,
|
||||||
String[] projection) {
|
String[] projection) {
|
||||||
final ContentResolver resolver = context.getContentResolver();
|
final ContentResolver resolver = packageContext.getContentResolver();
|
||||||
|
|
||||||
final Cursor cursor = resolver.query(uri, projection,
|
final Cursor cursor = resolver.query(uri, projection,
|
||||||
null, null, null);
|
null, null, null);
|
||||||
@@ -209,7 +209,7 @@ public class Index {
|
|||||||
final String targetPackage = cursor.getString(5);
|
final String targetPackage = cursor.getString(5);
|
||||||
final String targetClass = cursor.getString(6);
|
final String targetClass = cursor.getString(6);
|
||||||
|
|
||||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
SearchIndexableResource sir = new SearchIndexableResource(packageContext);
|
||||||
sir.rank = rank;
|
sir.rank = rank;
|
||||||
sir.xmlResId = xmlResId;
|
sir.xmlResId = xmlResId;
|
||||||
sir.className = className;
|
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) {
|
String[] projection) {
|
||||||
final ContentResolver resolver = context.getContentResolver();
|
final ContentResolver resolver = packageContext.getContentResolver();
|
||||||
|
|
||||||
final Cursor cursor = resolver.query(uri, projection,
|
final Cursor cursor = resolver.query(uri, projection,
|
||||||
null, null, null);
|
null, null, null);
|
||||||
@@ -257,7 +257,7 @@ public class Index {
|
|||||||
final String targetPackage = cursor.getString(8);
|
final String targetPackage = cursor.getString(8);
|
||||||
final String targetClass = cursor.getString(9);
|
final String targetClass = cursor.getString(9);
|
||||||
|
|
||||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
SearchIndexableRaw data = new SearchIndexableRaw(packageContext);
|
||||||
data.rank = rank;
|
data.rank = rank;
|
||||||
data.title = title;
|
data.title = title;
|
||||||
data.summary = summary;
|
data.summary = summary;
|
||||||
@@ -472,6 +472,7 @@ public class Index {
|
|||||||
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);
|
||||||
} else if (!TextUtils.isEmpty(sir.className)) {
|
} else if (!TextUtils.isEmpty(sir.className)) {
|
||||||
|
sir.context = mContext;
|
||||||
indexFromLocalProvider(database, localeStr, sir);
|
indexFromLocalProvider(database, localeStr, sir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
|||||||
new SearchIndexableResource(1, NO_DATA_RES_ID,
|
new SearchIndexableResource(1, NO_DATA_RES_ID,
|
||||||
WifiSettings.class.getName(),
|
WifiSettings.class.getName(),
|
||||||
R.drawable.ic_settings_wireless),
|
R.drawable.ic_settings_wireless),
|
||||||
new SearchIndexableResource(2, R.xml.bluetooth_settings,
|
new SearchIndexableResource(2, NO_DATA_RES_ID,
|
||||||
BluetoothSettings.class.getName(),
|
BluetoothSettings.class.getName(),
|
||||||
R.drawable.ic_settings_bluetooth2),
|
R.drawable.ic_settings_bluetooth2),
|
||||||
new SearchIndexableResource(3, R.xml.data_usage_metered_prefs,
|
new SearchIndexableResource(3, R.xml.data_usage_metered_prefs,
|
||||||
|
Reference in New Issue
Block a user