diff --git a/app/src/main/java/io/pslab/activity/LuxMeterActivity.java b/app/src/main/java/io/pslab/activity/LuxMeterActivity.java
index 750ceff7b..50bd423c8 100644
--- a/app/src/main/java/io/pslab/activity/LuxMeterActivity.java
+++ b/app/src/main/java/io/pslab/activity/LuxMeterActivity.java
@@ -33,6 +33,7 @@
import io.pslab.R;
import io.pslab.fragment.LuxMeterFragmentConfig;
import io.pslab.fragment.LuxMeterFragmentData;
+import io.pslab.others.CSVLogger;
import io.pslab.others.CustomSnackBar;
import io.pslab.others.GPSLogger;
import io.pslab.others.MathUtils;
@@ -43,19 +44,28 @@
import butterknife.ButterKnife;
public class LuxMeterActivity extends AppCompatActivity {
- BottomSheetBehavior bottomSheetBehavior;
- GestureDetector gestureDetector;
+
private static final String PREF_NAME = "customDialogPreference";
private static final int MY_PERMISSIONS_REQUEST_STORAGE_FOR_DATA = 101;
private static final int MY_PERMISSIONS_REQUEST_STORAGE_FOR_MAPS = 102;
+ public boolean recordData = false;
+ public boolean exportData = false;
+ public boolean recordingStarted = false;
+ public GPSLogger gpsLogger;
+ public boolean locationPref;
+ public CSVLogger luxLogger;
+ private Menu menu;
+
+ BottomSheetBehavior bottomSheetBehavior;
+ GestureDetector gestureDetector;
+
@BindView(R.id.navigation_lux_meter)
BottomNavigationView bottomNavigationView;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.cl)
CoordinatorLayout coordinatorLayout;
-
//bottomSheet
@BindView(R.id.bottom_sheet)
LinearLayout bottomSheet;
@@ -73,11 +83,7 @@ public class LuxMeterActivity extends AppCompatActivity {
ImageView bottomSheetSchematic;
@BindView(R.id.custom_dialog_desc)
TextView bottomSheetDesc;
-
- public boolean saveData = false;
- public GPSLogger gpsLogger;
private boolean checkGpsOnResume = false;
- public boolean locationPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -193,13 +199,14 @@ public boolean onTouchEvent(MotionEvent event) {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.data_log_menu, menu);
+ this.menu = menu;
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.save_csv_data:
+ case R.id.record_pause_data:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
@@ -207,24 +214,53 @@ public boolean onOptionsItemSelected(MenuItem item) {
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_STORAGE_FOR_DATA);
return true;
}
- if (saveData) {
- saveData = false;
+ if (recordData) {
+ item.setIcon(R.drawable.record_icon);
+ recordData = false;
+ CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_paused), null, null);
} else {
+ item.setIcon(R.drawable.pause_icon);
+ if (!recordingStarted) {
+ luxLogger = new CSVLogger(getString(R.string.lux_meter));
+ luxLogger.writeCSVFile("Timestamp,X,Y\n");
+ recordingStarted = true;
+ }
if (locationPref) {
gpsLogger = new GPSLogger(this, (LocationManager) getSystemService(Context.LOCATION_SERVICE));
if (gpsLogger.isGPSEnabled()) {
- saveData = true;
+ recordData = true;
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_enabled), null, null);
} else {
checkGpsOnResume = true;
}
gpsLogger.startFetchingLocation();
} else {
- saveData = true;
+ recordData = true;
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_disabled), null, null);
}
}
- invalidateOptionsMenu();
+ break;
+ case R.id.record_csv_data:
+ if (recordingStarted) {
+ MenuItem item1 = menu.findItem(R.id.record_pause_data);
+ item1.setIcon(R.drawable.record_icon);
+ exportData = true;
+ recordingStarted = false;
+ recordData = false;
+ } else {
+ CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.nothing_to_export), null, null);
+ }
+ break;
+ case R.id.delete_csv_data:
+ if (recordingStarted) {
+ MenuItem item1 = menu.findItem(R.id.record_pause_data);
+ item1.setIcon(R.drawable.record_icon);
+ luxLogger.deleteFile();
+ recordingStarted = false;
+ recordData = false;
+ CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_deleted), null, null);
+ } else
+ CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.nothing_to_delete), null, null);
break;
case R.id.show_map:
if (ContextCompat.checkSelfPermission(this,
@@ -251,10 +287,10 @@ protected void onResume() {
super.onResume();
if (checkGpsOnResume) {
if (gpsLogger.isGPSEnabled()) {
- saveData = true;
+ recordData = true;
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start), null, null);
} else {
- saveData = false;
+ recordData = false;
Toast.makeText(getApplicationContext(), getString(R.string.gps_not_enabled),
Toast.LENGTH_SHORT).show();
}
@@ -270,14 +306,14 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
if (locationPref) {
gpsLogger = new GPSLogger(this, (LocationManager) getSystemService(Context.LOCATION_SERVICE));
if (gpsLogger.isGPSEnabled()) {
- saveData = true;
+ recordData = true;
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_enabled), null, null);
} else {
checkGpsOnResume = true;
}
gpsLogger.startFetchingLocation();
} else {
- saveData = true;
+ recordData = true;
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_disabled), null, null);
}
} else {
@@ -289,4 +325,13 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
startActivity(MAP);
}
}
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if(recordingStarted) {
+ luxLogger.deleteFile();
+ recordingStarted = false;
+ }
+ }
}
diff --git a/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java b/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java
index 7867fc6a0..f33296488 100644
--- a/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java
+++ b/app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java
@@ -54,7 +54,6 @@ public class LuxMeterFragmentData extends Fragment {
private static int highLimit = 2000;
private static int updatePeriod = 100;
private final Object lock = new Object();
- public CSVLogger lux_logger;
@BindView(R.id.lux_stat_max)
TextView statMax;
@@ -81,7 +80,6 @@ public class LuxMeterFragmentData extends Fragment {
private YAxis y;
private volatile boolean monitor = true;
private Unbinder unbinder;
- private boolean logged = false, writeHeader = false;
private long previousTimeElapsed = (System.currentTimeMillis() - startTime) / 1000;
private GPSLogger gpsLogger;
@@ -313,53 +311,48 @@ private void visualizeData() {
final LuxMeterActivity parent = (LuxMeterActivity) getActivity();
for (Entry item : entries) {
assert parent != null;
- if (parent.saveData) {
- if (!writeHeader) {
- gpsLogger = parent.gpsLogger;
- lux_logger = new CSVLogger(getString(R.string.lux_meter));
- lux_logger.writeCSVFile("Timestamp,X,Y\n");
- writeHeader = true;
- }
+
+ if (parent.recordData) {
+ gpsLogger = parent.gpsLogger;
String data = String.valueOf(System.currentTimeMillis()) + "," +
item.getX() + "," + item.getY() + "\n";
- lux_logger.writeCSVFile(data);
- logged = true;
- } else {
- if (logged) {
- writeHeader = false;
- logged = false;
- if (parent.locationPref && gpsLogger != null) {
- String data;
- Location location = gpsLogger.getBestLocation();
- if (location != null) {
- data = "\nLocation" + "," + String.valueOf(location.getLatitude()) + "," + String.valueOf(location.getLongitude() + "\n");
- } else {
- data = "\nLocation" + "," + "null" + "," + "null";
- }
- lux_logger.writeCSVFile(data);
- gpsLogger.removeUpdate();
+ parent.luxLogger.writeCSVFile(data);
+ }
+
+ if (parent.exportData) {
+ parent.exportData = false;
+ if (parent.locationPref && gpsLogger != null) {
+ String data;
+ Location location = gpsLogger.getBestLocation();
+ if (location != null) {
+ data = "\nLocation" + "," + String.valueOf(location.getLatitude()) + "," + String.valueOf(location.getLongitude() + "\n");
+ } else {
+ data = "\nLocation" + "," + "null" + "," + "null";
}
- CustomSnackBar.showSnackBar((CoordinatorLayout) parent.findViewById(R.id.cl),
- getString(R.string.csv_store_text) + " " + lux_logger.getCurrentFilePath()
- , getString(R.string.delete_capital), new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- new AlertDialog.Builder(parent, R.style.AlertDialogStyle)
- .setTitle(R.string.delete_file)
- .setMessage(R.string.delete_warning)
- .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- lux_logger.deleteFile();
- }
- })
- .setNegativeButton(R.string.cancel, null)
- .create()
- .show();
- }
- });
+ parent.luxLogger.writeCSVFile(data);
+ gpsLogger.removeUpdate();
}
+ CustomSnackBar.showSnackBar((CoordinatorLayout) parent.findViewById(R.id.cl),
+ getString(R.string.csv_store_text) + " " + parent.luxLogger.getCurrentFilePath()
+ , getString(R.string.delete_capital), new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ new AlertDialog.Builder(parent, R.style.AlertDialogStyle)
+ .setTitle(R.string.delete_file)
+ .setMessage(R.string.delete_warning)
+ .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ parent.luxLogger.deleteFile();
+ }
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .create()
+ .show();
+ }
+ });
}
+
count++;
sum += item.getY();
}
diff --git a/app/src/main/java/io/pslab/others/GPSLogger.java b/app/src/main/java/io/pslab/others/GPSLogger.java
index d6dbead31..4280b3119 100644
--- a/app/src/main/java/io/pslab/others/GPSLogger.java
+++ b/app/src/main/java/io/pslab/others/GPSLogger.java
@@ -59,7 +59,7 @@ public void onProviderEnabled(String s) { /**/}
@Override
public void onProviderDisabled(String s) {
- callerActivity.saveData = false;
+ callerActivity.recordData = false;
new AlertDialog.Builder(callerActivity, R.style.AlertDialogStyle)
.setTitle(R.string.allow_gps)
.setMessage(R.string.allow_gps_info)
diff --git a/app/src/main/res/drawable/delete_icon.xml b/app/src/main/res/drawable/delete_icon.xml
new file mode 100755
index 000000000..8a3e56298
--- /dev/null
+++ b/app/src/main/res/drawable/delete_icon.xml
@@ -0,0 +1,9 @@
+