diff --git a/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/guiUtilities/ShimmerBluetoothDialog.java b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/guiUtilities/ShimmerBluetoothDialog.java index 9beaaa49..90413522 100644 --- a/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/guiUtilities/ShimmerBluetoothDialog.java +++ b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/guiUtilities/ShimmerBluetoothDialog.java @@ -124,6 +124,7 @@ public void onClick(View v) { // If there are paired devices, add each one to the ArrayAdapter if (pairedDevices.size() > 0) { + pairedListView.setEnabled(true); findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE); for (BluetoothDevice device : pairedDevices) { mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); @@ -131,6 +132,7 @@ public void onClick(View v) { } else { String noDevices = getResources().getText(R.string.none_paired).toString(); mPairedDevicesArrayAdapter.add(noDevices); + pairedListView.setEnabled(false); } } @@ -187,7 +189,7 @@ public void onItemClick(AdapterView av, View v, int arg2, long arg3) { Toast.makeText(getApplicationContext(),"Device Selected " + "-> "+ address, Toast.LENGTH_SHORT).show(); setResult(Activity.RESULT_OK, intent); // Set result and finish this Activity - finish(); + finish(); } }; diff --git a/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/manager/ShimmerBluetoothManagerAndroid.java b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/manager/ShimmerBluetoothManagerAndroid.java index 3016d182..71131238 100644 --- a/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/manager/ShimmerBluetoothManagerAndroid.java +++ b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/manager/ShimmerBluetoothManagerAndroid.java @@ -23,7 +23,6 @@ import com.shimmerresearch.driver.Configuration; import com.shimmerresearch.driver.ObjectCluster; import com.shimmerresearch.driver.ShimmerDevice; -import com.shimmerresearch.driver.ShimmerObject; import com.shimmerresearch.driver.shimmer4sdk.Shimmer4sdk; import com.shimmerresearch.driverUtilities.BluetoothDeviceDetails; import com.shimmerresearch.driverUtilities.ChannelDetails; @@ -35,7 +34,6 @@ import com.shimmerresearch.exceptions.ConnectionExceptionListener; import com.shimmerresearch.exceptions.ShimmerException; -import com.shimmerresearch.exgConfig.ExGConfigOptionDetails; import com.shimmerresearch.managers.bluetoothManager.ShimmerBluetoothManager; import java.util.ArrayList; @@ -46,8 +44,6 @@ import java.util.Set; import java.util.TreeMap; -import static android.R.id.list; - /** * Created by ASaez on 10-Aug-16. */ @@ -89,8 +85,19 @@ public void connectBluetoothDevice(BluetoothDevice device){ } /** - * @param bluetoothAddress + * When true, will attempt to pair the device if the device is not paired. User will have to manually key in the pairing key. + * @param enable + */ + public void enablePairingOnConnect(boolean enable){ + AllowAutoPairing = enable; + } + + /** + * See also {@link #connectShimmerThroughBTAddress(String)}. + * @param bluetoothAddress in the form of XX:XX:XX:XX:XX:XX * @param context if the context is set, a progress dialog will show, otherwise a toast msg will show + * @exception IllegalArgumentException if bluetoothAddress is invalid, note this will only occur when {@link #enablePairingOnConnect(boolean)} is enabled + * @exception DeviceNotPairedException if the device is not paired */ public void connectShimmerThroughBTAddress(final String bluetoothAddress,Context context) { @@ -143,12 +150,23 @@ public void onConnectStartException(String connectionHandle) { } } + /** + * See also {@link #connectShimmerThroughBTAddress(String,Context)}. + * @param bluetoothAddress in the form of XX:XX:XX:XX:XX:XX + * @exception IllegalArgumentException if bluetoothAddress is invalid, note this will only occur when {@link #enablePairingOnConnect(boolean)} is enabled + * @exception DeviceNotPairedException if the device is not paired + */ @Override public void connectShimmerThroughBTAddress(final String bluetoothAddress) { connectShimmerThroughBTAddress(bluetoothAddress,null); } - private boolean isDevicePaired(String bluetoothAddress){ + /** + * Using the specified bluetooth address in the form of XX:XX:XX:XX:XX:XX check if the device is currently paired to the android device + * @param bluetoothAddress + * @return true if the device is paired + */ + public boolean isDevicePaired(String bluetoothAddress){ Set pairedDevices = mBluetoothAdapter.getBondedDevices(); for(BluetoothDevice device: pairedDevices){ if(device.getAddress().equals(bluetoothAddress)){ diff --git a/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/AndroidManifest.xml b/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/AndroidManifest.xml index 77473584..b6a7d2db 100644 --- a/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/AndroidManifest.xml +++ b/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/AndroidManifest.xml @@ -21,5 +21,9 @@ + + + + \ No newline at end of file diff --git a/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/java/shimmerresearch/com/shimmerbasicexample/MainActivity.java b/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/java/shimmerresearch/com/shimmerbasicexample/MainActivity.java index e753e065..5209ef2d 100644 --- a/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/java/shimmerresearch/com/shimmerbasicexample/MainActivity.java +++ b/ShimmerAndroidInstrumentDriver/shimmerBasicExample/src/main/java/shimmerresearch/com/shimmerbasicexample/MainActivity.java @@ -1,10 +1,12 @@ package shimmerresearch.com.shimmerbasicexample; +import android.Manifest; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.support.v4.app.ActivityCompat; import android.util.Log; import android.view.View; import android.widget.Toast; @@ -36,7 +38,9 @@ public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION}, + 0); shimmer = new Shimmer(mHandler); } diff --git a/ShimmerAndroidInstrumentDriver/shimmerConnectionTest/README.md b/ShimmerAndroidInstrumentDriver/shimmerConnectionTest/README.md index b1905f75..0b58d32b 100644 --- a/ShimmerAndroidInstrumentDriver/shimmerConnectionTest/README.md +++ b/ShimmerAndroidInstrumentDriver/shimmerConnectionTest/README.md @@ -1,22 +1,9 @@ -# Shimmer Basic Example -This example is only applicable for Shimmer3 devices onwards. For Shimmer2 devices, please see the Legacy Example +# Shimmer Connection Test Example +This example is only applicable for Shimmer3 devices onwards. -- This example demonstrates connecting and streaming data from a Shimmer directly, without the use of the Bluetooth Manager -- The build.gradle file shows how to retrieve the library from bintray. Take note of the following:- - -``` -compile 'ShimmerAndroidInstrumentDriver:ShimmerAndroidInstrumentDriver:3.0.65Beta' -``` - -- Note you will need to specify the url for the shimmer bintray repository, this is done in the build.gradle file (root projects folder) +This shows how to implement the retry logic for a successful connection on the first try. Note the important part are that a new shimmer instance be created everytime an attempt to connect is made (_this also applies if you aren't using the Bluetooth Manager_). Also note that the method setMacIdFromUart is called in order to maintain functionality of the BluetoothManager (_e.g. public void startStreaming(String bluetoothAddress)_) ``` -allprojects { - repositories { - google() - jcenter() - maven { - url "http://dl.bintray.com/shimmerengineering/Shimmer" - } - } -} -``` \ No newline at end of file +Shimmer shimmer = new Shimmer(mHandler); +shimmer.setMacIdFromUart(macAdd); +btManager.removeShimmerDeviceBtConnected(macAdd); +btManager.putShimmerGlobalMap(macAdd, shimmer);