Add dynamic Preferences indexing (part 2)

- change the Index SQL model. Add a new "enabled" column.
- use that column for issuing a more restrictive search query
- change the SearchIndexProvider API to pass the "enable" state
- apply it to Bluetooth settings
- refactor the list of indexable resources (SearchIndexableResources)

Change-Id: Ic900fb27cb12a285a80d953aa1aa88f0070cd986
This commit is contained in:
Fabrice Di Meglio
2014-03-20 19:52:29 -07:00
parent 30eb2d3dd1
commit 51bfee595c
9 changed files with 641 additions and 464 deletions

View File

@@ -28,6 +28,7 @@ import android.widget.Toast;
import com.android.settings.R;
import com.android.settings.WirelessSettings;
import com.android.settings.search.Index;
/**
* BluetoothEnabler is a helper to manage the Bluetooth on/off checkbox
@@ -132,6 +133,7 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
case BluetoothAdapter.STATE_ON:
setChecked(true);
mSwitch.setEnabled(true);
updateSearchIndex(true);
break;
case BluetoothAdapter.STATE_TURNING_OFF:
mSwitch.setEnabled(false);
@@ -139,10 +141,12 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
case BluetoothAdapter.STATE_OFF:
setChecked(false);
mSwitch.setEnabled(true);
updateSearchIndex(false);
break;
default:
setChecked(false);
mSwitch.setEnabled(true);
updateSearchIndex(false);
}
}
@@ -159,4 +163,9 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
}
}
}
private void updateSearchIndex(boolean isBluetoothOn) {
Index.getInstance(mContext).updateFromClassNameResource(
BluetoothSettings.class.getName(), isBluetoothOn);
}
}

View File

@@ -48,7 +48,6 @@ 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;
@@ -421,40 +420,42 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new SearchIndexProvider() {
new SearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context) {
return null;
}
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
return null;
}
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context) {
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
final Resources res = context.getResources();
final Resources res = context.getResources();
// Add fragment title
SearchIndexableRaw data = new SearchIndexableRaw(context);
data.title = res.getString(R.string.bluetooth_settings);
// 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);
data.enabled = enabled;
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;
}
};
return result;
}
};
}