Merge branch 'BLE' into O2SAT
This commit is contained in:
BIN
app/release/app-release-3.6.3c.apk
Normal file
BIN
app/release/app-release-3.6.3c.apk
Normal file
Binary file not shown.
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 2,
|
|
||||||
"artifactType": {
|
|
||||||
"type": "APK",
|
|
||||||
"kind": "Directory"
|
|
||||||
},
|
|
||||||
"applicationId": "uk.org.openseizuredetector",
|
|
||||||
"variantName": "processReleaseResources",
|
|
||||||
"elements": [
|
|
||||||
{
|
|
||||||
"type": "SINGLE",
|
|
||||||
"filters": [],
|
|
||||||
"versionCode": 90,
|
|
||||||
"versionName": "3.7.0a",
|
|
||||||
"outputFile": "app-release.apk"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -39,6 +39,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -53,6 +54,7 @@ public class BLEScanActivity extends ListActivity {
|
|||||||
private BluetoothAdapter mBluetoothAdapter;
|
private BluetoothAdapter mBluetoothAdapter;
|
||||||
private boolean mScanning;
|
private boolean mScanning;
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
private boolean bleAvailable = false;
|
||||||
|
|
||||||
private boolean mPermissionsRequested = false;
|
private boolean mPermissionsRequested = false;
|
||||||
private final String TAG = "BLEScanActivity";
|
private final String TAG = "BLEScanActivity";
|
||||||
@@ -70,6 +72,7 @@ public class BLEScanActivity extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.ble_scan_activity);
|
||||||
//this.getActionBar().setTitle(R.string.title_devices);
|
//this.getActionBar().setTitle(R.string.title_devices);
|
||||||
this.setTitle(R.string.title_devices);
|
this.setTitle(R.string.title_devices);
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
@@ -79,6 +82,8 @@ public class BLEScanActivity extends ListActivity {
|
|||||||
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
|
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
|
||||||
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
|
||||||
finish();
|
finish();
|
||||||
|
} else {
|
||||||
|
bleAvailable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes a Bluetooth adapter. For API level 18 and above, get a reference to
|
// Initializes a Bluetooth adapter. For API level 18 and above, get a reference to
|
||||||
@@ -125,15 +130,40 @@ public class BLEScanActivity extends ListActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void onScanButtonClick(View v) {
|
||||||
|
scanLeDevice(true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
SharedPreferences SP = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(this);
|
||||||
|
TextView tv = (TextView) findViewById(R.id.current_ble_device_tv);
|
||||||
|
try {
|
||||||
|
String bleAddr = SP.getString("BLE_Device_Addr", "none");
|
||||||
|
String bleName = SP.getString("BLE_Device_Name", "none");
|
||||||
|
tv.setText("Current Device=" + bleName + " (" + bleAddr + ")");
|
||||||
|
} catch(Exception e) {
|
||||||
|
tv.setText("Current Device=" + "none" + " (" + "none" + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
tv = (TextView)findViewById(R.id.ble_present_tv);
|
||||||
|
if (mBluetoothAdapter == null) {
|
||||||
|
tv.setText("ERROR - Bluetooth Adapter Not Present");
|
||||||
|
} else {
|
||||||
|
tv.setText("Bluetooth Adapter Present - OK");
|
||||||
|
}
|
||||||
// Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled,
|
// Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled,
|
||||||
// fire an intent to display a dialog asking the user to grant permission to enable it.
|
// fire an intent to display a dialog asking the user to grant permission to enable it.
|
||||||
|
tv = (TextView)findViewById(R.id.ble_adapter_tv);
|
||||||
if (!mBluetoothAdapter.isEnabled()) {
|
if (!mBluetoothAdapter.isEnabled()) {
|
||||||
|
tv.setText("ERROR - Bluetoot NOT Enabled");
|
||||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||||
|
} else {
|
||||||
|
tv.setText("Bluetooth Adapter Enabled OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes list view adapter.
|
// Initializes list view adapter.
|
||||||
@@ -191,6 +221,7 @@ public class BLEScanActivity extends ListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void scanLeDevice(final boolean enable) {
|
private void scanLeDevice(final boolean enable) {
|
||||||
|
TextView tv;
|
||||||
requestPermissions(this);
|
requestPermissions(this);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
// Stops scanning after a pre-defined scan period.
|
// Stops scanning after a pre-defined scan period.
|
||||||
@@ -200,14 +231,28 @@ public class BLEScanActivity extends ListActivity {
|
|||||||
mScanning = false;
|
mScanning = false;
|
||||||
mBluetoothAdapter.stopLeScan(mLeScanCallback);
|
mBluetoothAdapter.stopLeScan(mLeScanCallback);
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
|
TextView tv = (TextView)(findViewById(R.id.ble_scan_status_tv));
|
||||||
|
tv.setText("Stopped");
|
||||||
|
Button b = (Button)findViewById(R.id.startScanButton);
|
||||||
|
b.setEnabled(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}, SCAN_PERIOD);
|
}, SCAN_PERIOD);
|
||||||
|
|
||||||
mScanning = true;
|
mScanning = true;
|
||||||
mBluetoothAdapter.startLeScan(mLeScanCallback);
|
mBluetoothAdapter.startLeScan(mLeScanCallback);
|
||||||
|
tv = (TextView)(findViewById(R.id.ble_scan_status_tv));
|
||||||
|
tv.setText("Scanning");
|
||||||
|
Button b = (Button)findViewById(R.id.startScanButton);
|
||||||
|
b.setEnabled(false);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mScanning = false;
|
mScanning = false;
|
||||||
mBluetoothAdapter.stopLeScan(mLeScanCallback);
|
mBluetoothAdapter.stopLeScan(mLeScanCallback);
|
||||||
|
tv = (TextView)(findViewById(R.id.ble_scan_status_tv));
|
||||||
|
tv.setText("Stopped");
|
||||||
|
Button b = (Button)findViewById(R.id.startScanButton);
|
||||||
|
b.setEnabled(true);
|
||||||
}
|
}
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|||||||
66
app/src/main/res/layout/ble_scan_activity.xml
Normal file
66
app/src/main/res/layout/ble_scan_activity.xml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ble_scan_status_tv"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16pt"
|
||||||
|
android:text="ble_scan_status_tv" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/startScanButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="onScanButtonClick"
|
||||||
|
android:text="Start Scan"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ble_present_tv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="ble_present_tv" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ble_adapter_tv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="ble_adapter_tv" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/current_ble_device_tv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="current_ble_device_tv" />
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@android:id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="#00FF00"
|
||||||
|
android:drawSelectorOnTop="false" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/empty"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="#FF0000"
|
||||||
|
android:text="No data" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
Reference in New Issue
Block a user