Update application for Bluetooth API change.
This commit is contained in:
@@ -55,8 +55,8 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (BluetoothIntent.SCAN_MODE_CHANGED_ACTION.equals(intent.getAction())) {
|
if (BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(intent.getAction())) {
|
||||||
int mode = intent.getIntExtra(BluetoothIntent.SCAN_MODE, BluetoothError.ERROR);
|
int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothError.ERROR);
|
||||||
if (mode != BluetoothError.ERROR) {
|
if (mode != BluetoothError.ERROR) {
|
||||||
handleModeChanged(mode);
|
handleModeChanged(mode);
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntentFilter filter = new IntentFilter(BluetoothIntent.SCAN_MODE_CHANGED_ACTION);
|
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
|
||||||
mContext.registerReceiver(mReceiver, filter);
|
mContext.registerReceiver(mReceiver, filter);
|
||||||
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
@@ -49,7 +49,7 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
|
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
|
||||||
BluetoothError.ERROR);
|
BluetoothError.ERROR);
|
||||||
handleStateChanged(state);
|
handleStateChanged(state);
|
||||||
}
|
}
|
||||||
@@ -76,13 +76,13 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
|
|
||||||
int state = mLocalManager.getBluetoothState();
|
int state = mLocalManager.getBluetoothState();
|
||||||
// This is the widget enabled state, not the preference toggled state
|
// This is the widget enabled state, not the preference toggled state
|
||||||
mCheckBoxPreference.setEnabled(state == BluetoothAdapter.BLUETOOTH_STATE_ON ||
|
mCheckBoxPreference.setEnabled(state == BluetoothAdapter.STATE_ON ||
|
||||||
state == BluetoothAdapter.BLUETOOTH_STATE_OFF);
|
state == BluetoothAdapter.STATE_OFF);
|
||||||
// BT state is not a sticky broadcast, so set it manually
|
// BT state is not a sticky broadcast, so set it manually
|
||||||
handleStateChanged(state);
|
handleStateChanged(state);
|
||||||
|
|
||||||
mContext.registerReceiver(mReceiver,
|
mContext.registerReceiver(mReceiver,
|
||||||
new IntentFilter(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION));
|
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
||||||
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,18 +112,18 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
|
|
||||||
private void handleStateChanged(int state) {
|
private void handleStateChanged(int state) {
|
||||||
|
|
||||||
if (state == BluetoothAdapter.BLUETOOTH_STATE_OFF ||
|
if (state == BluetoothAdapter.STATE_OFF ||
|
||||||
state == BluetoothAdapter.BLUETOOTH_STATE_ON) {
|
state == BluetoothAdapter.STATE_ON) {
|
||||||
mCheckBoxPreference.setChecked(state == BluetoothAdapter.BLUETOOTH_STATE_ON);
|
mCheckBoxPreference.setChecked(state == BluetoothAdapter.STATE_ON);
|
||||||
mCheckBoxPreference.setSummary(state == BluetoothAdapter.BLUETOOTH_STATE_OFF ?
|
mCheckBoxPreference.setSummary(state == BluetoothAdapter.STATE_OFF ?
|
||||||
mOriginalSummary :
|
mOriginalSummary :
|
||||||
null);
|
null);
|
||||||
|
|
||||||
mCheckBoxPreference.setEnabled(isEnabledByDependency());
|
mCheckBoxPreference.setEnabled(isEnabledByDependency());
|
||||||
|
|
||||||
} else if (state == BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON ||
|
} else if (state == BluetoothAdapter.STATE_TURNING_ON ||
|
||||||
state == BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF) {
|
state == BluetoothAdapter.STATE_TURNING_OFF) {
|
||||||
mCheckBoxPreference.setSummary(state == BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON
|
mCheckBoxPreference.setSummary(state == BluetoothAdapter.STATE_TURNING_ON
|
||||||
? R.string.wifi_starting
|
? R.string.wifi_starting
|
||||||
: R.string.wifi_stopping);
|
: R.string.wifi_stopping);
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothA2dp;
|
import android.bluetooth.BluetoothA2dp;
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothError;
|
import android.bluetooth.BluetoothError;
|
||||||
@@ -51,8 +52,8 @@ public class BluetoothEventRedirector {
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothIntent.DEVICE);
|
BluetoothDevice device = intent.getParcelableExtra(BluetoothIntent.DEVICE);
|
||||||
|
|
||||||
if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
|
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
||||||
int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
|
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
|
||||||
BluetoothError.ERROR);
|
BluetoothError.ERROR);
|
||||||
mManager.setBluetoothStateInt(state);
|
mManager.setBluetoothStateInt(state);
|
||||||
} else if (action.equals(BluetoothIntent.DISCOVERY_STARTED_ACTION)) {
|
} else if (action.equals(BluetoothIntent.DISCOVERY_STARTED_ACTION)) {
|
||||||
@@ -123,7 +124,7 @@ public class BluetoothEventRedirector {
|
|||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
|
|
||||||
// Bluetooth on/off broadcasts
|
// Bluetooth on/off broadcasts
|
||||||
filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
|
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
|
|
||||||
// Discovery broadcasts
|
// Discovery broadcasts
|
||||||
filter.addAction(BluetoothIntent.DISCOVERY_STARTED_ACTION);
|
filter.addAction(BluetoothIntent.DISCOVERY_STARTED_ACTION);
|
||||||
|
@@ -49,9 +49,9 @@ public class BluetoothNamePreference extends EditTextPreference implements TextW
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (action.equals(BluetoothIntent.NAME_CHANGED_ACTION)) {
|
if (action.equals(BluetoothIntent.NAME_CHANGED_ACTION)) {
|
||||||
setSummaryToName();
|
setSummaryToName();
|
||||||
} else if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION) &&
|
} else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) &&
|
||||||
(intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
|
(intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
|
||||||
BluetoothError.ERROR) == BluetoothAdapter.BLUETOOTH_STATE_ON)) {
|
BluetoothError.ERROR) == BluetoothAdapter.STATE_ON)) {
|
||||||
setSummaryToName();
|
setSummaryToName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ public class BluetoothNamePreference extends EditTextPreference implements TextW
|
|||||||
|
|
||||||
public void resume() {
|
public void resume() {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
|
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
filter.addAction(BluetoothIntent.NAME_CHANGED_ACTION);
|
filter.addAction(BluetoothIntent.NAME_CHANGED_ACTION);
|
||||||
getContext().registerReceiver(mReceiver, filter);
|
getContext().registerReceiver(mReceiver, filter);
|
||||||
|
|
||||||
|
@@ -87,7 +87,7 @@ public class BluetoothSettings extends PreferenceActivity
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
// TODO: put this in callback instead of receiving
|
// TODO: put this in callback instead of receiving
|
||||||
|
|
||||||
if (intent.getAction().equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) {
|
if (intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
||||||
onBluetoothStateChanged(mLocalManager.getBluetoothState());
|
onBluetoothStateChanged(mLocalManager.getBluetoothState());
|
||||||
} else if (intent.getAction().equals(BluetoothIntent.BOND_STATE_CHANGED_ACTION)
|
} else if (intent.getAction().equals(BluetoothIntent.BOND_STATE_CHANGED_ACTION)
|
||||||
&& mScreenType == SCREEN_TYPE_DEVICEPICKER) {
|
&& mScreenType == SCREEN_TYPE_DEVICEPICKER) {
|
||||||
@@ -175,7 +175,7 @@ public class BluetoothSettings extends PreferenceActivity
|
|||||||
mLocalManager.startScanning(false);
|
mLocalManager.startScanning(false);
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION);
|
intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
|
||||||
intentFilter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION);
|
intentFilter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION);
|
||||||
registerReceiver(mReceiver, intentFilter);
|
registerReceiver(mReceiver, intentFilter);
|
||||||
mLocalManager.setForegroundActivity(this);
|
mLocalManager.setForegroundActivity(this);
|
||||||
@@ -339,9 +339,9 @@ public class BluetoothSettings extends PreferenceActivity
|
|||||||
private void onBluetoothStateChanged(int bluetoothState) {
|
private void onBluetoothStateChanged(int bluetoothState) {
|
||||||
// When bluetooth is enabled (and we are in the activity, which we are),
|
// When bluetooth is enabled (and we are in the activity, which we are),
|
||||||
// we should start a scan
|
// we should start a scan
|
||||||
if (bluetoothState == BluetoothAdapter.BLUETOOTH_STATE_ON) {
|
if (bluetoothState == BluetoothAdapter.STATE_ON) {
|
||||||
mLocalManager.startScanning(false);
|
mLocalManager.startScanning(false);
|
||||||
} else if (bluetoothState == BluetoothAdapter.BLUETOOTH_STATE_OFF) {
|
} else if (bluetoothState == BluetoothAdapter.STATE_OFF) {
|
||||||
mDeviceList.setProgress(false);
|
mDeviceList.setProgress(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@ import android.app.AlertDialog;
|
|||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothError;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -322,7 +323,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
int status = profileManager.getConnectionStatus(cachedDevice.mDevice);
|
int status = profileManager.getConnectionStatus(cachedDevice.mDevice);
|
||||||
if (SettingsBtStatus.isConnectionStatusConnected(status)) {
|
if (SettingsBtStatus.isConnectionStatusConnected(status)) {
|
||||||
if (profileManager.disconnect(cachedDevice.mDevice) ==
|
if (profileManager.disconnect(cachedDevice.mDevice) ==
|
||||||
BluetoothAdapter.RESULT_SUCCESS) {
|
BluetoothError.SUCCESS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,7 +408,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
|
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
|
||||||
int status = profileManager.getConnectionStatus(cachedDevice.mDevice);
|
int status = profileManager.getConnectionStatus(cachedDevice.mDevice);
|
||||||
if (!SettingsBtStatus.isConnectionStatusConnected(status)) {
|
if (!SettingsBtStatus.isConnectionStatusConnected(status)) {
|
||||||
if (profileManager.connect(cachedDevice.mDevice) == BluetoothAdapter.RESULT_SUCCESS) {
|
if (profileManager.connect(cachedDevice.mDevice) == BluetoothError.SUCCESS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "Failed to connect " + profile.toString() + " to " + cachedDevice.mName);
|
Log.i(TAG, "Failed to connect " + profile.toString() + " to " + cachedDevice.mName);
|
||||||
@@ -690,7 +691,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
|
|
||||||
public void onCreateContextMenu(ContextMenu menu) {
|
public void onCreateContextMenu(ContextMenu menu) {
|
||||||
// No context menu if it is busy (none of these items are applicable if busy)
|
// No context menu if it is busy (none of these items are applicable if busy)
|
||||||
if (mLocalManager.getBluetoothState() != BluetoothAdapter.BLUETOOTH_STATE_ON || isBusy()) {
|
if (mLocalManager.getBluetoothState() != BluetoothAdapter.STATE_ON || isBusy()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -196,10 +196,10 @@ public class LocalBluetoothManager {
|
|||||||
|
|
||||||
void setBluetoothStateInt(int state) {
|
void setBluetoothStateInt(int state) {
|
||||||
mState = state;
|
mState = state;
|
||||||
if (state == BluetoothAdapter.BLUETOOTH_STATE_ON ||
|
if (state == BluetoothAdapter.STATE_ON ||
|
||||||
state == BluetoothAdapter.BLUETOOTH_STATE_OFF) {
|
state == BluetoothAdapter.STATE_OFF) {
|
||||||
mCachedDeviceManager.onBluetoothStateChanged(state ==
|
mCachedDeviceManager.onBluetoothStateChanged(state ==
|
||||||
BluetoothAdapter.BLUETOOTH_STATE_ON);
|
BluetoothAdapter.STATE_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,8 +208,8 @@ public class LocalBluetoothManager {
|
|||||||
|
|
||||||
if (mAdapter != null) {
|
if (mAdapter != null) {
|
||||||
bluetoothState = mAdapter.isEnabled()
|
bluetoothState = mAdapter.isEnabled()
|
||||||
? BluetoothAdapter.BLUETOOTH_STATE_ON
|
? BluetoothAdapter.STATE_ON
|
||||||
: BluetoothAdapter.BLUETOOTH_STATE_OFF;
|
: BluetoothAdapter.STATE_OFF;
|
||||||
} else {
|
} else {
|
||||||
bluetoothState = BluetoothError.ERROR;
|
bluetoothState = BluetoothError.ERROR;
|
||||||
}
|
}
|
||||||
@@ -224,8 +224,8 @@ public class LocalBluetoothManager {
|
|||||||
|
|
||||||
if (wasSetStateSuccessful) {
|
if (wasSetStateSuccessful) {
|
||||||
setBluetoothStateInt(enabled
|
setBluetoothStateInt(enabled
|
||||||
? BluetoothAdapter.BLUETOOTH_STATE_TURNING_ON
|
? BluetoothAdapter.STATE_TURNING_ON
|
||||||
: BluetoothAdapter.BLUETOOTH_STATE_TURNING_OFF);
|
: BluetoothAdapter.STATE_TURNING_OFF);
|
||||||
} else {
|
} else {
|
||||||
if (V) {
|
if (V) {
|
||||||
Log.v(TAG,
|
Log.v(TAG,
|
||||||
|
@@ -379,9 +379,9 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int state = mLocalBluetoothManager.getBluetoothState();
|
int state = mLocalBluetoothManager.getBluetoothState();
|
||||||
if (state == BluetoothAdapter.BLUETOOTH_STATE_OFF) {
|
if (state == BluetoothAdapter.STATE_OFF) {
|
||||||
return STATE_DISABLED;
|
return STATE_DISABLED;
|
||||||
} else if (state == BluetoothAdapter.BLUETOOTH_STATE_ON) {
|
} else if (state == BluetoothAdapter.STATE_ON) {
|
||||||
return STATE_ENABLED;
|
return STATE_ENABLED;
|
||||||
} else {
|
} else {
|
||||||
return STATE_INTERMEDIATE;
|
return STATE_INTERMEDIATE;
|
||||||
|
Reference in New Issue
Block a user