Skip to content

Commit

Permalink
Added time to the logged row
Browse files Browse the repository at this point in the history
  • Loading branch information
isso committed Sep 10, 2014
1 parent a557a1c commit 8c749fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

Expand All @@ -17,7 +19,6 @@

import android.app.Activity;
import android.os.Environment;
import android.text.format.DateFormat;

import com.integreight.firmatabluetooth.ShieldFrame;
import com.integreight.onesheeld.enums.UIShield;
Expand All @@ -42,6 +43,10 @@ public class DataLoggerShield extends ControllerParent<DataLoggerShield> {
STOPPED_LOGGING = 2;
public int currentStatus = READ_FOR_LOGGING;
private DataLoggerListener eventHandler;

public boolean isLoggingStarted(){
return isStarted;
}

public DataLoggerShield() {
super();
Expand Down Expand Up @@ -72,7 +77,6 @@ public void onNewShieldFrameReceived(ShieldFrame frame) {
else
fileName = null;
headerList = new CopyOnWriteArrayList<String>();
headerList.add("Time");
dataSet = new ArrayList<Map<String, String>>();
rowData = new HashMap<String, String>();
currentStatus = LOGGING;
Expand Down Expand Up @@ -110,7 +114,8 @@ public void onNewShieldFrameReceived(ShieldFrame frame) {
+ (fileName == null
|| fileName.length() == 0 ? new Date()
.getTime() + ""
: fileName) + ".csv"),
: fileName+" - "+new Date()
.getTime()) + ".csv"),
CsvPreference.STANDARD_PREFERENCE);

// assign a default value for married (if null), and
Expand Down Expand Up @@ -180,14 +185,14 @@ public void onNewShieldFrameReceived(ShieldFrame frame) {
case LOG:
if (isStarted) {
currentStatus = LOGGING;
rowData.put("Time",
DateFormat.format("hh:mm:ss", new java.util.Date())
.toString());
if (eventHandler != null) {
eventHandler.onLog(new ArrayList<Map<String, String>>(
dataSet), new HashMap<String, String>(rowData));
eventHandler.onLog(new HashMap<String, String>(rowData));
}
// rowData.remove("Time");
if(!headerList.contains("Time"))headerList.add("Time");
rowData.put("Time",
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS",Locale.US).format(new Date())
.toString());
//rowData.remove("Time");
dataSet.add(new HashMap<String, String>(rowData));
rowData = new HashMap<String, String>();
}
Expand Down Expand Up @@ -222,8 +227,7 @@ public static interface DataLoggerListener {

public void onAdd(String key, String value);

public void onLog(ArrayList<Map<String, String>> loggedValues,
Map<String, String> rowData);
public void onLog(Map<String, String> rowData);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public void run() {

@Override
public void run() {
if (canChangeUI()) {
if (canChangeUI() && !((DataLoggerShield) getApplication().getRunningShields().get(
getControllerTag())).isLoggingStarted()) {
keysContainer.removeAllViews();
valuesContainer.removeAllViews();
((DataLoggerShield) getApplication()
Expand Down Expand Up @@ -146,8 +147,7 @@ public void run() {
}

@Override
public void onLog(final ArrayList<Map<String, String>> loggedValues,
final Map<String, String> rowData) {
public void onLog(final Map<String, String> rowData) {
uiHandler.post(new Runnable() {

@Override
Expand All @@ -156,16 +156,15 @@ public void run() {
loggerStatus
.setBackgroundResource(R.drawable.large_green_circle);
loggerStatus.setText(R.string.logging);
for (String header : ((DataLoggerShield) getApplication()
.getRunningShields().get(getControllerTag())).headerList) {
for (String header : rowData.keySet()) {
if (keysContainer.findViewWithTag(header) != null) {
((OneSheeldTextView) valuesContainer
.findViewWithTag(header + "Value"))
.setText("");
((OneSheeldTextView) valuesContainer
.findViewWithTag(header + "Value")).setText(header
.equals("Time") ? rowData.get(header)
: "");
// ((OneSheeldTextView) valuesContainer
// .findViewWithTag(header + "Value")).setText(header
// .equals("Time") ? rowData.get(header)
// : "");
} else {
OneSheeldTextView key = new OneSheeldTextView(
activity);
Expand All @@ -182,8 +181,8 @@ public void run() {
activity);
value.setLayoutParams(cellParams);
value.setSingleLine(true);
value.setText(header.equals("Time") ? rowData
.get(header) : "");
// value.setText(header.equals("Time") ? rowData
// .get(header) : "");
value.setTextColor(getResources().getColor(
R.color.offWhite));
value.setTextSize(TypedValue.COMPLEX_UNIT_DIP,
Expand Down Expand Up @@ -236,8 +235,8 @@ public void onAdd(final String header, final String valueT) {
@Override
public void run() {
if (canChangeUI()) {
if (keysContainer.findViewWithTag("Time") == null)
add("Time", "");
// if (keysContainer.findViewWithTag("Time") == null)
// add("Time", "");
add(header, valueT);
}
}
Expand Down

0 comments on commit 8c749fe

Please sign in to comment.