diff --git a/app/build.gradle b/app/build.gradle
index 7008905..2ba54e6 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -32,6 +32,14 @@ dependencies {
implementation 'com.getpebble:pebblekit:3.1.0@aar'
// Unit testing dependencies
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
+ //implementation 'androidx.appcompat:appcompat:1.4.0'
+ //implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
+ //implementation 'androidx.appcompat:appcompat:1.2.0'
+ //implementation 'com.google.android.material:material:1.1.0'
+ //implementation 'androidx.annotation:annotation:1.1.0'
+ //implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
+ //implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
+ //implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
testImplementation 'junit:junit:4.12'
// Set this dependency if you want to use Mockito
testImplementation 'org.mockito:mockito-core:1.10.19'
@@ -47,6 +55,7 @@ dependencies {
implementation 'com.google.android.gms:play-services-location:10.0.0'
//implementation 'com.github.RohitSurwase.UCE-Handler:uce_handler:1.3'
testImplementation 'org.robolectric:robolectric:4.3'
+ implementation 'com.android.volley:volley:1.2.1'
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 20778d4..6fe8fcc 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -28,19 +28,19 @@
-
-
-
+
-
-
-
+ android:theme="@style/AppTheme">
+
+
+
+
@@ -79,4 +79,4 @@
android:required="false" />
-
+
\ No newline at end of file
diff --git a/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java
new file mode 100644
index 0000000..0781164
--- /dev/null
+++ b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java
@@ -0,0 +1,94 @@
+package uk.org.openseizuredetector;
+
+//import androidx.appcompat.app.AppCompatActivity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.support.v7.app.AppCompatActivity;
+
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+
+public class AuthenticateActivity extends AppCompatActivity {
+ private String TAG = "AuthenticateActivity";
+ private Context mContext;
+ private EditText mUnameEt;
+ private EditText mPasswdEt;
+ private boolean mIsLoggedIn;
+ private WebApiConnection mWac;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ Log.v(TAG, "onCreate()");
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_authenticate);
+ Button cancelBtn =
+ (Button) findViewById(R.id.cancelBtn);
+ cancelBtn.setOnClickListener(onCancel);
+ Button OKBtn = (Button) findViewById(R.id.OKBtn);
+ OKBtn.setOnClickListener(onOK);
+
+ mUnameEt = (EditText) findViewById(R.id.username);
+ mPasswdEt = (EditText) findViewById(R.id.password);
+ mWac = new WebApiConnection(this);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ switchUi();
+ }
+
+ private void switchUi() {
+ SharedPreferences prefs;
+ String storedAuthToken;
+ LinearLayout loginLl = (LinearLayout)findViewById(R.id.login_ui);
+ LinearLayout logoutLl = (LinearLayout)findViewById(R.id.logout_ui);
+ Log.i(TAG, "switchUi()");
+ prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ storedAuthToken = (prefs.getString("webApiAuthToken", null));
+ Log.v(TAG, "storedAuthToken=" + storedAuthToken);
+
+ // Check if we are already logged in
+ if (storedAuthToken == null || storedAuthToken.length() == 0) {
+ Log.v(TAG, "Not Logged in - showing log in UI");
+ loginLl.setVisibility(View.VISIBLE);
+ logoutLl.setVisibility(View.GONE);
+ } else {
+ Log.v(TAG, "Already Logged in - showing Log Out prompt");
+ loginLl.setVisibility(View.GONE);
+ logoutLl.setVisibility(View.VISIBLE);
+ }
+
+ }
+
+ View.OnClickListener onCancel =
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Log.v(TAG, "onCancel");
+ //m_status=false;
+ finish();
+ }
+ };
+
+ View.OnClickListener onOK =
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ //m_status=true;
+ Log.v(TAG, "onOK()");
+ String uname = mUnameEt.getText().toString();
+ String passwd = mPasswdEt.getText().toString();
+ Log.v(TAG,"onOK() - uname="+uname+", passwd="+passwd);
+ mWac.authenticate(uname,passwd);
+ //finish();
+ }
+ };
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java
index 548dca7..f21bb87 100644
--- a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java
+++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java
@@ -244,6 +244,17 @@ public class MainActivity extends AppCompatActivity {
mConnection.mSdServer.sendPhoneAlarm();
}
return true;
+ case R.id.action_authenticate_api:
+ Log.i(TAG, "action_autheticate_api");
+ try {
+ Intent i = new Intent(
+ MainActivity.this,
+ AuthenticateActivity.class);
+ this.startActivity(i);
+ } catch (Exception ex) {
+ Log.i(TAG, "exception starting export activity " + ex.toString());
+ }
+ return true;
case R.id.action_export:
Log.i(TAG, "action_export");
try {
diff --git a/app/src/main/java/uk/org/openseizuredetector/WebApiConnection.java b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection.java
new file mode 100644
index 0000000..f953f73
--- /dev/null
+++ b/app/src/main/java/uk/org/openseizuredetector/WebApiConnection.java
@@ -0,0 +1,66 @@
+package uk.org.openseizuredetector;
+
+import android.content.Context;
+import android.util.Log;
+
+
+import com.android.volley.Request;
+import com.android.volley.RequestQueue;
+import com.android.volley.Response;
+import com.android.volley.VolleyError;
+import com.android.volley.toolbox.JsonObjectRequest;
+import com.android.volley.toolbox.StringRequest;
+import com.android.volley.toolbox.Volley;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+// This class is intended to handle all interactions with the OSD WebAPI
+public class WebApiConnection {
+ public String retVal;
+ public int retCode;
+ private String mUrlBase = "https://osdApi.ddns.net";
+ private String TAG = "WebApiConnection";
+ RequestQueue mQueue;
+
+ public WebApiConnection(Context context) {
+ mQueue = Volley.newRequestQueue(context);
+ }
+
+ public boolean authenticate(String uname, String passwd) {
+ // We know that this command works, so we just need the Java equivalent:
+ // curl -X POST -d 'login=graham4&password=testpwd1' https://osdapi.ddns.net/api/accounts/login/
+ String urlStr = mUrlBase + "/api/accounts/login/";
+ Log.v(TAG, "urlStr=" + urlStr);
+
+ JSONObject postData = new JSONObject();
+ try {
+ postData.put("login", uname);
+ postData.put("password", passwd);
+
+ } catch (JSONException e) {
+ Log.e(TAG,e.getMessage());
+ }
+
+ Log.v(TAG,postData.toString());
+ JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, urlStr, postData,
+ new Response.Listener() {
+ @Override
+ public void onResponse(JSONObject response) {
+ // Display the first 500 characters of the response string.
+ Log.v(TAG, "Response is: " + response);
+ }
+ },
+ new Response.ErrorListener() {
+ @Override
+ public void onErrorResponse(VolleyError error) {
+ String responseBody = new String(error.networkResponse.data);
+ Log.v(TAG, "Login Error" + error.toString()+","+error.getMessage()+error.networkResponse.statusCode+","+responseBody);
+ }
+ }
+ );
+ mQueue.add(req);
+ return (true);
+ }
+
+}
diff --git a/app/src/main/res/layout/activity_authenticate.xml b/app/src/main/res/layout/activity_authenticate.xml
new file mode 100644
index 0000000..4d3f5fa
--- /dev/null
+++ b/app/src/main/res/layout/activity_authenticate.xml
@@ -0,0 +1,104 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/main_activity_actions.xml b/app/src/main/res/menu/main_activity_actions.xml
index 7afa63a..5537747 100644
--- a/app/src/main/res/menu/main_activity_actions.xml
+++ b/app/src/main/res/menu/main_activity_actions.xml
@@ -61,6 +61,14 @@
android:title="@string/data_log_manager"
/>
+
+
- Treat Null Value as Alarm
Oxygen Saturation Low Alarm Level (%)
O2 Saturation Low Alarm Level (%)
+ AuthenticateActivity
+ Log Out
+ Logged in with Token: