Merge "Fixing crash in emulator due to missing bluetooth." into jb-mr1-dev

This commit is contained in:
Winson Chung
2012-09-11 17:10:43 -07:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 19 deletions

View File

@@ -167,10 +167,9 @@ class QuickSettings {
startSettingsActivity(intent);
}
private void startSettingsActivity(Intent intent) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
mBar.collapseAllPanels(true);
mContext.startActivity(intent);
}
private void addUserTiles(ViewGroup parent, LayoutInflater inflater) {
@@ -310,23 +309,25 @@ class QuickSettings {
parent.addView(airplaneTile);
// Bluetooth
QuickSettingsTileView bluetoothTile = (QuickSettingsTileView)
inflater.inflate(R.layout.quick_settings_tile, parent, false);
bluetoothTile.setContent(R.layout.quick_settings_tile_bluetooth, inflater);
bluetoothTile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
}
});
mModel.addBluetoothTile(bluetoothTile, new QuickSettingsModel.RefreshCallback() {
@Override
public void refreshView(QuickSettingsTileView view, State state) {
TextView tv = (TextView) view.findViewById(R.id.bluetooth_textview);
tv.setCompoundDrawablesRelativeWithIntrinsicBounds(0, state.iconId, 0, 0);
}
});
parent.addView(bluetoothTile);
if (mModel.deviceSupportsBluetooth()) {
QuickSettingsTileView bluetoothTile = (QuickSettingsTileView)
inflater.inflate(R.layout.quick_settings_tile, parent, false);
bluetoothTile.setContent(R.layout.quick_settings_tile_bluetooth, inflater);
bluetoothTile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startSettingsActivity(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
}
});
mModel.addBluetoothTile(bluetoothTile, new QuickSettingsModel.RefreshCallback() {
@Override
public void refreshView(QuickSettingsTileView view, State state) {
TextView tv = (TextView) view.findViewById(R.id.bluetooth_textview);
tv.setCompoundDrawablesRelativeWithIntrinsicBounds(0, state.iconId, 0, 0);
}
});
parent.addView(bluetoothTile);
}
// Brightness
QuickSettingsTileView brightnessTile = (QuickSettingsTileView)

View File

@@ -258,6 +258,9 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
onBluetoothStateChange(adapter.isEnabled());
}
boolean deviceSupportsBluetooth() {
return (BluetoothAdapter.getDefaultAdapter() != null);
}
// BluetoothController callback
@Override
public void onBluetoothStateChange(boolean on) {