auto import from //depot/cupcake/@137055

This commit is contained in:
The Android Open Source Project
2009-03-02 22:54:43 -08:00
parent 90e190609a
commit 8a156091ef
44 changed files with 1427 additions and 601 deletions

View File

@@ -23,6 +23,7 @@ import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
@@ -51,11 +52,13 @@ public class LocalBluetoothManager {
private Context mContext;
/** If a BT-related activity is in the foreground, this will be it. */
private Activity mForegroundActivity;
private AlertDialog mErrorDialog = null;
private BluetoothDevice mManager;
private LocalBluetoothDeviceManager mLocalDeviceManager;
private BluetoothEventRedirector mEventRedirector;
private BluetoothA2dp mBluetoothA2dp;
public static enum ExtendedBluetoothState { ENABLED, ENABLING, DISABLED, DISABLING, UNKNOWN }
private ExtendedBluetoothState mState = ExtendedBluetoothState.UNKNOWN;
@@ -95,7 +98,9 @@ public class LocalBluetoothManager {
mEventRedirector = new BluetoothEventRedirector(this);
mEventRedirector.start();
mBluetoothA2dp = new BluetoothA2dp(context);
return true;
}
@@ -112,6 +117,10 @@ public class LocalBluetoothManager {
}
public void setForegroundActivity(Activity activity) {
if (mErrorDialog != null) {
mErrorDialog.dismiss();
mErrorDialog = null;
}
mForegroundActivity = activity;
}
@@ -149,9 +158,23 @@ public class LocalBluetoothManager {
*/
dispatchScanningStateChanged(true);
} else {
// Don't scan more than frequently than SCAN_EXPIRATION_MS, unless forced
if (!force && mLastScan + SCAN_EXPIRATION_MS > System.currentTimeMillis()) return;
if (!force) {
// Don't scan more than frequently than SCAN_EXPIRATION_MS,
// unless forced
if (mLastScan + SCAN_EXPIRATION_MS > System.currentTimeMillis()) {
return;
}
// If we are playing music, don't scan unless forced.
List<String> sinks = mBluetoothA2dp.listConnectedSinks();
if (sinks != null) {
for (String address : sinks) {
if (mBluetoothA2dp.getSinkState(address) == BluetoothA2dp.STATE_PLAYING) {
return;
}
}
}
}
if (mManager.startDiscovery(true)) {
mLastScan = System.currentTimeMillis();
@@ -235,7 +258,7 @@ public class LocalBluetoothManager {
if (mForegroundActivity != null) {
// Need an activity context to show a dialog
AlertDialog ad = new AlertDialog.Builder(mForegroundActivity)
mErrorDialog = new AlertDialog.Builder(mForegroundActivity)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(titleResId)
.setMessage(message)