Added OSD Alarm state and refresh button to EditEventActivity
This commit is contained in:
@@ -171,6 +171,8 @@ public class EditEventActivity extends AppCompatActivity
|
|||||||
if (mEventObj != null) {
|
if (mEventObj != null) {
|
||||||
tv = (TextView) findViewById(R.id.eventIdTv);
|
tv = (TextView) findViewById(R.id.eventIdTv);
|
||||||
tv.setText(String.valueOf(mEventObj.getLong("id")));
|
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 = (TextView) findViewById(R.id.eventNotsTv);
|
||||||
tv.setText(mEventObj.getString("desc"));
|
tv.setText(mEventObj.getString("desc"));
|
||||||
|
|
||||||
|
|||||||
@@ -361,23 +361,7 @@ public class LogManager implements AuthCallbackInterface, EventCallbackInterface
|
|||||||
//event.put("id", cursor.getString(cursor.getColumnIndex("id")));
|
//event.put("id", cursor.getString(cursor.getColumnIndex("id")));
|
||||||
event.put("dataTime", cursor.getString(cursor.getColumnIndex("dataTime")));
|
event.put("dataTime", cursor.getString(cursor.getColumnIndex("dataTime")));
|
||||||
int status = cursor.getInt(cursor.getColumnIndex("Status"));
|
int status = cursor.getInt(cursor.getColumnIndex("Status"));
|
||||||
String statusStr = "Unknown";
|
String statusStr = mUtil.alarmStatusToString(status);
|
||||||
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";
|
|
||||||
}
|
|
||||||
event.put("status",statusStr);
|
event.put("status",statusStr);
|
||||||
event.put("uploaded", cursor.getString(cursor.getColumnIndex("uploaded")));
|
event.put("uploaded", cursor.getString(cursor.getColumnIndex("uploaded")));
|
||||||
//event.put("dataJSON", cursor.getString(cursor.getColumnIndex("dataJSON")));
|
//event.put("dataJSON", cursor.getString(cursor.getColumnIndex("dataJSON")));
|
||||||
@@ -611,33 +595,13 @@ public class LogManager implements AuthCallbackInterface, EventCallbackInterface
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
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 {
|
try {
|
||||||
eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(eventDateStr);
|
eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(eventDateStr);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
Log.e(TAG, "Error parsing date " + eventDateStr);
|
Log.e(TAG, "Error parsing date " + eventDateStr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mWac.createEvent(eventType, eventDate, "Uploaded by OpenSeizureDetector Android App");
|
mWac.createEvent(eventAlarmStatus, eventDate, "Uploaded by OpenSeizureDetector Android App");
|
||||||
} else{
|
} else{
|
||||||
Log.v(TAG,"UploadSdData - no data to upload");
|
Log.v(TAG,"UploadSdData - no data to upload");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
(Button) findViewById(R.id.reportSeizureBtn);
|
(Button) findViewById(R.id.reportSeizureBtn);
|
||||||
reportSeizureBtn.setOnClickListener(onReportSeizureBtn);
|
reportSeizureBtn.setOnClickListener(onReportSeizureBtn);
|
||||||
Button remoteDbBtn =
|
Button remoteDbBtn =
|
||||||
(Button) findViewById(R.id.view_remote_db_button);
|
(Button) findViewById(R.id.refresh_button);
|
||||||
remoteDbBtn.setOnClickListener(onRemoteDbBtn);
|
remoteDbBtn.setOnClickListener(onRefreshBtn);
|
||||||
|
|
||||||
ListView lv = (ListView) findViewById(R.id.eventLogListView);
|
ListView lv = (ListView) findViewById(R.id.eventLogListView);
|
||||||
lv.setOnItemClickListener(onEventListClick);
|
lv.setOnItemClickListener(onEventListClick);
|
||||||
@@ -129,6 +129,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void initialiseServiceConnection() {
|
private void initialiseServiceConnection() {
|
||||||
mLm = mConnection.mSdServer.mLm;
|
mLm = mConnection.mSdServer.mLm;
|
||||||
|
startUiTimer();
|
||||||
getRemoteEvents();
|
getRemoteEvents();
|
||||||
// Populate events list - we only do it once when the activity is created because the query might slow down the UI.
|
// 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.
|
// 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>();
|
HashMap<String, String> eventHashMap = new HashMap<String, String>();
|
||||||
eventHashMap.put("id", String.valueOf(id));
|
eventHashMap.put("id", String.valueOf(id));
|
||||||
eventHashMap.put("osdAlarmState", String.valueOf(osdAlarmState));
|
eventHashMap.put("osdAlarmState", String.valueOf(osdAlarmState));
|
||||||
|
eventHashMap.put("osdAlarmStateStr", mUtil.alarmStatusToString(osdAlarmState));
|
||||||
eventHashMap.put("dataTime", dataTime);
|
eventHashMap.put("dataTime", dataTime);
|
||||||
eventHashMap.put("type", typeStr);
|
eventHashMap.put("type", typeStr);
|
||||||
eventHashMap.put("subType", subType);
|
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 =
|
AdapterView.OnItemClickListener onEventListClick =
|
||||||
new AdapterView.OnItemClickListener() {
|
new AdapterView.OnItemClickListener() {
|
||||||
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
|
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
|
||||||
|
|||||||
@@ -541,4 +541,30 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac
|
|||||||
}, 100);
|
}, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package uk.org.openseizuredetector;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.icu.text.RelativeDateTimeFormatter;
|
import android.icu.text.RelativeDateTimeFormatter;
|
||||||
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ public class WebApiConnection {
|
|||||||
private DatapointCallbackInterface mDatapointCallback;
|
private DatapointCallbackInterface mDatapointCallback;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private String TOKEN_ID = "webApiAuthToken";
|
private String TOKEN_ID = "webApiAuthToken";
|
||||||
|
private OsdUtil mUtil;
|
||||||
RequestQueue mQueue;
|
RequestQueue mQueue;
|
||||||
|
|
||||||
public WebApiConnection(Context context, AuthCallbackInterface authCallback, EventCallbackInterface eventCallback,
|
public WebApiConnection(Context context, AuthCallbackInterface authCallback, EventCallbackInterface eventCallback,
|
||||||
@@ -51,6 +53,7 @@ public class WebApiConnection {
|
|||||||
mEventCallback = eventCallback;
|
mEventCallback = eventCallback;
|
||||||
mDatapointCallback = datapointCallback;
|
mDatapointCallback = datapointCallback;
|
||||||
mQueue = Volley.newRequestQueue(context);
|
mQueue = Volley.newRequestQueue(context);
|
||||||
|
mUtil = new OsdUtil(mContext, new Handler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean authenticate(final String uname, final String passwd) {
|
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.
|
// 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
|
// EventType is defined by the WebAPI in https://github.com/OpenSeizureDetector/webApi/blob/master/api/events/models.py
|
||||||
// We currently use:
|
// We currently use:
|
||||||
// 0: Unvalidated Alarm
|
// 0: Unvalidated Alarm
|
||||||
@@ -165,7 +169,6 @@ public class WebApiConnection {
|
|||||||
final String dataStr = jsonObject.toString();
|
final String dataStr = jsonObject.toString();
|
||||||
Log.v(TAG, "createEvent - data=" + dataStr);
|
Log.v(TAG, "createEvent - data=" + dataStr);
|
||||||
|
|
||||||
|
|
||||||
StringRequest req = new StringRequest(Request.Method.POST, urlStr,
|
StringRequest req = new StringRequest(Request.Method.POST, urlStr,
|
||||||
new Response.Listener<String>() {
|
new Response.Listener<String>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -190,9 +193,6 @@ public class WebApiConnection {
|
|||||||
String authToken = getStoredToken();
|
String authToken = getStoredToken();
|
||||||
params.put("Authorization: Token " + authToken, authToken);
|
params.put("Authorization: Token " + authToken, authToken);
|
||||||
Log.v(TAG, "getParams: params=" + params.toString());
|
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;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +238,7 @@ public class WebApiConnection {
|
|||||||
Log.v(TAG, "Response is: " + response);
|
Log.v(TAG, "Response is: " + response);
|
||||||
try {
|
try {
|
||||||
JSONObject retObj = new JSONObject(response);
|
JSONObject retObj = new JSONObject(response);
|
||||||
|
retObj.put("alarmStateStr",mUtil.alarmStatusToString(retObj.getInt("osdAlarmState")));
|
||||||
callback.accept(retObj);
|
callback.accept(retObj);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG,"getEventTypes.onRespons(): Error: "+e.getMessage()+","+e.toString());
|
Log.e(TAG,"getEventTypes.onRespons(): Error: "+e.getMessage()+","+e.toString());
|
||||||
|
|||||||
@@ -18,12 +18,10 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="EventId: " />
|
android:text="EventId: " />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/eventIdTv"
|
android:id="@+id/eventIdTv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -35,13 +33,11 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Event Date: "
|
android:text="Event Date: "
|
||||||
android:textSize="20sp"/>
|
android:textSize="20sp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/eventDateTv"
|
android:id="@+id/eventDateTv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -54,14 +50,29 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
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
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/event_type"
|
android:text="@string/event_type"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:id="@+id/eventTypeRg"
|
android:id="@+id/eventTypeRg"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -111,10 +111,10 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/view_remote_db_button"
|
android:id="@+id/refresh_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/view_remote_db_btn" />
|
android:text="@string/refreshBtn" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -324,4 +324,5 @@
|
|||||||
<string name="event_sub_type">"Event Sub-Type: "</string>
|
<string name="event_sub_type">"Event Sub-Type: "</string>
|
||||||
<string name="selectFromOptionselow">"-- select option --"</string>
|
<string name="selectFromOptionselow">"-- select option --"</string>
|
||||||
<string name="waitingForData">...waiting for data...</string>
|
<string name="waitingForData">...waiting for data...</string>
|
||||||
|
<string name="refreshBtn">Refresh</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user