From 8c749fe33888cd2b2be0349ea9ac7770d15b2edf Mon Sep 17 00:00:00 2001 From: Islam Mustafa Date: Wed, 10 Sep 2014 12:00:56 +0300 Subject: [PATCH] Added time to the logged row --- .../shields/controller/DataLoggerShield.java | 26 +++++++++++-------- .../shields/fragments/DataLoggerFragment.java | 25 +++++++++--------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/OneSheeld/src/com/integreight/onesheeld/shields/controller/DataLoggerShield.java b/OneSheeld/src/com/integreight/onesheeld/shields/controller/DataLoggerShield.java index 03d6bb9f2..84e5ef8cf 100644 --- a/OneSheeld/src/com/integreight/onesheeld/shields/controller/DataLoggerShield.java +++ b/OneSheeld/src/com/integreight/onesheeld/shields/controller/DataLoggerShield.java @@ -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; @@ -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; @@ -42,6 +43,10 @@ public class DataLoggerShield extends ControllerParent { STOPPED_LOGGING = 2; public int currentStatus = READ_FOR_LOGGING; private DataLoggerListener eventHandler; + + public boolean isLoggingStarted(){ + return isStarted; + } public DataLoggerShield() { super(); @@ -72,7 +77,6 @@ public void onNewShieldFrameReceived(ShieldFrame frame) { else fileName = null; headerList = new CopyOnWriteArrayList(); - headerList.add("Time"); dataSet = new ArrayList>(); rowData = new HashMap(); currentStatus = LOGGING; @@ -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 @@ -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>( - dataSet), new HashMap(rowData)); + eventHandler.onLog(new HashMap(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(rowData)); rowData = new HashMap(); } @@ -222,8 +227,7 @@ public static interface DataLoggerListener { public void onAdd(String key, String value); - public void onLog(ArrayList> loggedValues, - Map rowData); + public void onLog(Map rowData); } } diff --git a/OneSheeld/src/com/integreight/onesheeld/shields/fragments/DataLoggerFragment.java b/OneSheeld/src/com/integreight/onesheeld/shields/fragments/DataLoggerFragment.java index abebfbb5f..4e79f4fbb 100644 --- a/OneSheeld/src/com/integreight/onesheeld/shields/fragments/DataLoggerFragment.java +++ b/OneSheeld/src/com/integreight/onesheeld/shields/fragments/DataLoggerFragment.java @@ -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() @@ -146,8 +147,7 @@ public void run() { } @Override - public void onLog(final ArrayList> loggedValues, - final Map rowData) { + public void onLog(final Map rowData) { uiHandler.post(new Runnable() { @Override @@ -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); @@ -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, @@ -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); } }