altosdroid: Add BLUETOOTH_CONNECT permission, handle its lack
[fw/altos] / altosdroid / app / src / main / java / org / altusmetrum / AltosDroid / DeviceListActivity.java
index f36ef267c9c5c2660c5431e72638a388aa85125f..a3aef896c1f4718be190509239959c715e02d056 100644 (file)
@@ -17,7 +17,6 @@
 package org.altusmetrum.AltosDroid;
 
 import java.util.Set;
-import org.altusmetrum.AltosDroid.R;
 
 import android.app.Activity;
 import android.bluetooth.BluetoothAdapter;
@@ -56,10 +55,10 @@ public class DeviceListActivity extends Activity {
 
        @Override
        protected void onCreate(Bundle savedInstanceState) {
+               setTheme(AltosDroid.dialog_themes[AltosDroidPreferences.font_size()]);
                super.onCreate(savedInstanceState);
 
                // Setup the window
-               requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
                setContentView(R.layout.device_list);
 
                // Set result CANCELED incase the user backs out
@@ -106,10 +105,11 @@ 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)
-                               if (device.getName().startsWith("TeleBT"))
-                                       mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
-
+                       for (BluetoothDevice device : pairedDevices) {
+                               String name = device.getName();
+                               if (name != null && name.startsWith("TeleBT"))
+                                       mPairedDevicesArrayAdapter.add(name + "\n" + device.getAddress());
+                       }
                } else {
                        String noDevices = getResources().getText(R.string.none_paired).toString();
                        mPairedDevicesArrayAdapter.add(noDevices);
@@ -136,7 +136,6 @@ public class DeviceListActivity extends Activity {
                AltosDebug.debug("doDiscovery()");
 
                // Indicate scanning in the title
-               setProgressBarIndeterminateVisibility(true);
                setTitle(R.string.scanning);
 
                // Turn on sub-title for new devices
@@ -154,11 +153,16 @@ public class DeviceListActivity extends Activity {
        // The on-click listener for all devices in the ListViews
        private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
                public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {
+                       // Get the device MAC address, which is the last 17 chars in the View
+                       String info = ((TextView) v).getText().toString();
+
+                       /* Ignore clicks on items that are too short */
+                       if (info.length() <= 17)
+                               return;
+
                        // Cancel discovery because it's costly and we're about to connect
                        mBtAdapter.cancelDiscovery();
 
-                       // Get the device MAC address, which is the last 17 chars in the View
-                       String info = ((TextView) v).getText().toString();
                        String address = info.substring(info.length() - 17);
 
                        int newline = info.indexOf('\n');
@@ -202,13 +206,12 @@ public class DeviceListActivity extends Activity {
                                {
                                        String  name = device.getName();
                                        if (name != null && name.startsWith("TeleBT"))
-                                               mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
+                                               mNewDevicesArrayAdapter.add(name + "\n" + device.getAddress());
                                }
 
                        /* When discovery is finished, change the Activity title
                         */
                        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
-                               setProgressBarIndeterminateVisibility(false);
                                setTitle(R.string.select_device);
                                if (mNewDevicesArrayAdapter.getCount() == 0) {
                                        String noDevices = getResources().getText(R.string.none_found).toString();