X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FDeviceListActivity.java;h=f36ef267c9c5c2660c5431e72638a388aa85125f;hp=7b9cbde74a84f0f4721231b37252e7846d1ee872;hb=4a257455b2dc57069c41e1845daf66239c5cbe1d;hpb=583458772746317b98fced907ec780edff465888 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/DeviceListActivity.java b/altosdroid/src/org/altusmetrum/AltosDroid/DeviceListActivity.java index 7b9cbde7..f36ef267 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/DeviceListActivity.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/DeviceListActivity.java @@ -27,7 +27,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; -import android.util.Log; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; @@ -45,12 +44,10 @@ import android.widget.AdapterView.OnItemClickListener; * Activity in the result Intent. */ public class DeviceListActivity extends Activity { - // Debugging - private static final String TAG = "DeviceListActivity"; - private static final boolean D = true; // Return Intent extra - public static String EXTRA_DEVICE_ADDRESS = "device_address"; + public static final String EXTRA_DEVICE_ADDRESS = "device_address"; + public static final String EXTRA_DEVICE_NAME = "device_name"; // Member fields private BluetoothAdapter mBtAdapter; @@ -109,9 +106,10 @@ public class DeviceListActivity extends Activity { // If there are paired devices, add each one to the ArrayAdapter if (pairedDevices.size() > 0) { findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); - for (BluetoothDevice device : pairedDevices) { - mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); - } + for (BluetoothDevice device : pairedDevices) + if (device.getName().startsWith("TeleBT")) + mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); + } else { String noDevices = getResources().getText(R.string.none_paired).toString(); mPairedDevicesArrayAdapter.add(noDevices); @@ -135,7 +133,7 @@ public class DeviceListActivity extends Activity { * Start device discover with the BluetoothAdapter */ private void doDiscovery() { - if (D) Log.d(TAG, "doDiscovery()"); + AltosDebug.debug("doDiscovery()"); // Indicate scanning in the title setProgressBarIndeterminateVisibility(true); @@ -163,9 +161,20 @@ public class DeviceListActivity extends Activity { String info = ((TextView) v).getText().toString(); String address = info.substring(info.length() - 17); + int newline = info.indexOf('\n'); + + String name = null; + if (newline > 0) + name = info.substring(0, newline); + else + name = info; + + AltosDebug.debug("******* selected item '%s'", info); + // Create the result Intent and include the MAC address Intent intent = new Intent(); intent.putExtra(EXTRA_DEVICE_ADDRESS, address); + intent.putExtra(EXTRA_DEVICE_NAME, name); // Set result and finish this Activity setResult(Activity.RESULT_OK, intent); @@ -182,13 +191,22 @@ public class DeviceListActivity extends Activity { // When discovery finds a device if (BluetoothDevice.ACTION_FOUND.equals(action)) { - // Get the BluetoothDevice object from the Intent + + /* Get the BluetoothDevice object from the Intent + */ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - // If it's already paired, skip it, because it's been listed already - if (device.getBondState() != BluetoothDevice.BOND_BONDED) { - mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); + + /* If it's already paired, skip it, because it's been listed already + */ + if (device != null && device.getBondState() != BluetoothDevice.BOND_BONDED) + { + String name = device.getName(); + if (name != null && name.startsWith("TeleBT")) + mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } - // When discovery is finished, change the Activity title + + /* When discovery is finished, change the Activity title + */ } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { setProgressBarIndeterminateVisibility(false); setTitle(R.string.select_device);