Added OSD Alarm state and refresh button to EditEventActivity

This commit is contained in:
Graham Jones
2022-01-21 10:40:16 +00:00
parent c052178082
commit 13200e95b5
8 changed files with 68 additions and 51 deletions

View File

@@ -171,6 +171,8 @@ public class EditEventActivity extends AppCompatActivity
if (mEventObj != null) {
tv = (TextView) findViewById(R.id.eventIdTv);
tv.setText(String.valueOf(mEventObj.getLong("id")));
tv = (TextView) findViewById(R.id.eventAlarmStateTv);
tv.setText(mEventObj.getString("alarmStateStr"));
tv = (TextView) findViewById(R.id.eventNotsTv);
tv.setText(mEventObj.getString("desc"));

View File

@@ -361,23 +361,7 @@ public class LogManager implements AuthCallbackInterface, EventCallbackInterface
//event.put("id", cursor.getString(cursor.getColumnIndex("id")));
event.put("dataTime", cursor.getString(cursor.getColumnIndex("dataTime")));
int status = cursor.getInt(cursor.getColumnIndex("Status"));
String statusStr = "Unknown";
switch (status) {
case 1:
statusStr = "WARNING";
break;
case 2:
statusStr = "ALARM";
break;
case 3:
statusStr = "FALL";
break;
case 5:
statusStr = "MANUAL ALARM";
break;
default:
statusStr = "Unknown";
}
String statusStr = mUtil.alarmStatusToString(status);
event.put("status",statusStr);
event.put("uploaded", cursor.getString(cursor.getColumnIndex("uploaded")));
//event.put("dataJSON", cursor.getString(cursor.getColumnIndex("dataJSON")));
@@ -611,33 +595,13 @@ public class LogManager implements AuthCallbackInterface, EventCallbackInterface
e.printStackTrace();
return;
}
// FIXME - this should really not be hard coded but based on a file on the API server.
// GJ 03jan22
switch (eventAlarmStatus) {
case 1: // Warning
eventType = 1;
break;
case 2: // alarm
eventType = 0;
break;
case 3: // fall
eventType = 2;
break;
case 5: // Manual alarm
eventType = 3;
break;
default:
eventType = -1;
Log.e(TAG, "UploadSdData - alarmStatus " + eventAlarmStatus + " unrecognised");
return;
}
try {
eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(eventDateStr);
} catch (ParseException e) {
Log.e(TAG, "Error parsing date " + eventDateStr);
return;
}
mWac.createEvent(eventType, eventDate, "Uploaded by OpenSeizureDetector Android App");
mWac.createEvent(eventAlarmStatus, eventDate, "Uploaded by OpenSeizureDetector Android App");
} else{
Log.v(TAG,"UploadSdData - no data to upload");
}

View File

@@ -61,8 +61,8 @@ public class LogManagerControlActivity extends AppCompatActivity {
(Button) findViewById(R.id.reportSeizureBtn);
reportSeizureBtn.setOnClickListener(onReportSeizureBtn);
Button remoteDbBtn =
(Button) findViewById(R.id.view_remote_db_button);
remoteDbBtn.setOnClickListener(onRemoteDbBtn);
(Button) findViewById(R.id.refresh_button);
remoteDbBtn.setOnClickListener(onRefreshBtn);
ListView lv = (ListView) findViewById(R.id.eventLogListView);
lv.setOnItemClickListener(onEventListClick);
@@ -129,6 +129,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
private void initialiseServiceConnection() {
mLm = mConnection.mSdServer.mLm;
startUiTimer();
getRemoteEvents();
// Populate events list - we only do it once when the activity is created because the query might slow down the UI.
// We could try this code in updateUI() and see though.
@@ -162,6 +163,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
HashMap<String, String> eventHashMap = new HashMap<String, String>();
eventHashMap.put("id", String.valueOf(id));
eventHashMap.put("osdAlarmState", String.valueOf(osdAlarmState));
eventHashMap.put("osdAlarmStateStr", mUtil.alarmStatusToString(osdAlarmState));
eventHashMap.put("dataTime", dataTime);
eventHashMap.put("type", typeStr);
eventHashMap.put("subType", subType);
@@ -299,6 +301,16 @@ public class LogManagerControlActivity extends AppCompatActivity {
}
};
View.OnClickListener onRefreshBtn =
new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.v(TAG, "onRefreshBtn");
initialiseServiceConnection();
}
};
AdapterView.OnItemClickListener onEventListClick =
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {

View File

@@ -541,4 +541,30 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac
}, 100);
}
public final int ALARM_STATUS_WARNING = 1;
public final int ALARM_STATUS_ALARM = 2;
public final int ALARM_STATUS_FALL = 3;
public final int ALARM_STATUS_MANUAL = 5;
public String alarmStatusToString(int eventAlarmStatus) {
String retVal = "Unknown";
switch (eventAlarmStatus) {
case ALARM_STATUS_WARNING: // Warning
retVal = "WARNING";
break;
case ALARM_STATUS_ALARM: // alarm
retVal = "ALARM";
break;
case ALARM_STATUS_FALL: // fall
retVal = "FALL";
break;
case ALARM_STATUS_MANUAL: // Manual alarm
retVal = "MANUAL ALARM";
break;
}
return(retVal);
}
}

View File

@@ -3,6 +3,7 @@ package uk.org.openseizuredetector;
import android.content.Context;
import android.content.SharedPreferences;
import android.icu.text.RelativeDateTimeFormatter;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -42,6 +43,7 @@ public class WebApiConnection {
private DatapointCallbackInterface mDatapointCallback;
private Context mContext;
private String TOKEN_ID = "webApiAuthToken";
private OsdUtil mUtil;
RequestQueue mQueue;
public WebApiConnection(Context context, AuthCallbackInterface authCallback, EventCallbackInterface eventCallback,
@@ -51,6 +53,7 @@ public class WebApiConnection {
mEventCallback = eventCallback;
mDatapointCallback = datapointCallback;
mQueue = Volley.newRequestQueue(context);
mUtil = new OsdUtil(mContext, new Handler());
}
public boolean authenticate(final String uname, final String passwd) {
@@ -135,6 +138,7 @@ public class WebApiConnection {
// Create a new event in the remote database, based on the provided parameters.
// FIXME - eventType info below is wrong!
// EventType is defined by the WebAPI in https://github.com/OpenSeizureDetector/webApi/blob/master/api/events/models.py
// We currently use:
// 0: Unvalidated Alarm
@@ -165,7 +169,6 @@ public class WebApiConnection {
final String dataStr = jsonObject.toString();
Log.v(TAG, "createEvent - data=" + dataStr);
StringRequest req = new StringRequest(Request.Method.POST, urlStr,
new Response.Listener<String>() {
@Override
@@ -190,9 +193,6 @@ public class WebApiConnection {
String authToken = getStoredToken();
params.put("Authorization: Token " + authToken, authToken);
Log.v(TAG, "getParams: params=" + params.toString());
//params.put("eventType", String.valueOf(eventType));
//params.put("dataTime", dateFormat.format(eventDate));
//params.put("desc", eventDesc);
return params;
}
@@ -238,6 +238,7 @@ public class WebApiConnection {
Log.v(TAG, "Response is: " + response);
try {
JSONObject retObj = new JSONObject(response);
retObj.put("alarmStateStr",mUtil.alarmStatusToString(retObj.getInt("osdAlarmState")));
callback.accept(retObj);
} catch (JSONException e) {
Log.e(TAG,"getEventTypes.onRespons(): Error: "+e.getMessage()+","+e.toString());

View File

@@ -18,12 +18,10 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EventId: " />
<TextView
android:id="@+id/eventIdTv"
android:layout_width="wrap_content"
@@ -35,13 +33,11 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Date: "
android:textSize="20sp"/>
<TextView
android:id="@+id/eventDateTv"
android:layout_width="wrap_content"
@@ -54,14 +50,29 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alarm State: "
android:textSize="20sp"/>
<TextView
android:id="@+id/eventAlarmStateTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="..."
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/event_type"
android:textSize="20sp" />
<RadioGroup
android:id="@+id/eventTypeRg"
android:layout_width="wrap_content"

View File

@@ -111,10 +111,10 @@
</LinearLayout>
<Button
android:id="@+id/view_remote_db_button"
android:id="@+id/refresh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/view_remote_db_btn" />
android:text="@string/refreshBtn" />

View File

@@ -324,4 +324,5 @@
<string name="event_sub_type">"Event Sub-Type: "</string>
<string name="selectFromOptionselow">"-- select option --"</string>
<string name="waitingForData">...waiting for data...</string>
<string name="refreshBtn">Refresh</string>
</resources>