@@ -53,7 +53,6 @@ public class LuxMeterActivity extends AppCompatActivity {
5353 public boolean exportData = false ;
5454 public boolean recordingStarted = false ;
5555 public GPSLogger gpsLogger ;
56- public boolean locationPref ;
5756 public CSVLogger luxLogger ;
5857 private Menu menu ;
5958
@@ -84,6 +83,8 @@ public class LuxMeterActivity extends AppCompatActivity {
8483 @ BindView (R .id .custom_dialog_desc )
8584 TextView bottomSheetDesc ;
8685 private boolean checkGpsOnResume = false ;
86+ public boolean locationPref ;
87+ private LuxMeterFragmentData selectedFragment ;
8788
8889 @ Override
8990 protected void onCreate (Bundle savedInstanceState ) {
@@ -121,7 +122,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
121122 });
122123 try {
123124 FragmentTransaction transaction = getSupportFragmentManager ().beginTransaction ();
124- Fragment selectedFragment = LuxMeterFragmentData .newInstance ();
125+ selectedFragment = LuxMeterFragmentData .newInstance ();
125126 transaction .replace (R .id .frame_layout_lux_meter , selectedFragment , selectedFragment .getTag ());
126127 transaction .commit ();
127128 } catch (Exception e ) {
@@ -198,15 +199,22 @@ public boolean onTouchEvent(MotionEvent event) {
198199 @ Override
199200 public boolean onCreateOptionsMenu (Menu menu ) {
200201 MenuInflater inflater = getMenuInflater ();
201- inflater .inflate (R .menu .data_log_menu , menu );
202+ inflater .inflate (R .menu .lux_data_log_menu , menu );
202203 this .menu = menu ;
203204 return true ;
204205 }
205206
207+ @ Override
208+ public boolean onPrepareOptionsMenu (Menu menu ) {
209+ MenuItem item = menu .findItem (R .id .record_data );
210+ item .setIcon (recordData ? R .drawable .ic_record_stop : R .drawable .ic_record );
211+ return super .onPrepareOptionsMenu (menu );
212+ }
213+
206214 @ Override
207215 public boolean onOptionsItemSelected (MenuItem item ) {
208216 switch (item .getItemId ()) {
209- case R .id .record_pause_data :
217+ case R .id .record_data :
210218 if (ContextCompat .checkSelfPermission (this ,
211219 Manifest .permission .WRITE_EXTERNAL_STORAGE )
212220 != PackageManager .PERMISSION_GRANTED ) {
@@ -215,16 +223,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
215223 return true ;
216224 }
217225 if (recordData ) {
218- item .setIcon (R .drawable .record_icon );
226+ ((LuxMeterFragmentData )selectedFragment ).stopSensorFetching ();
227+ invalidateOptionsMenu ();
219228 recordData = false ;
220- CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .data_recording_paused ), null , null );
221229 } else {
222- item .setIcon (R .drawable .pause_icon );
223- if (!recordingStarted ) {
224- luxLogger = new CSVLogger (getString (R .string .lux_meter ));
225- luxLogger .writeCSVFile ("Timestamp,X,Y\n " );
226- recordingStarted = true ;
227- }
230+ luxLogger = new CSVLogger (getString (R .string .lux_meter ));
231+ luxLogger .writeCSVFile ("Timestamp,X,Y,Z\n " );
232+ recordData = true ;
233+ ((LuxMeterFragmentData )selectedFragment ).startSensorFetching ();
234+ invalidateOptionsMenu ();
228235 if (locationPref ) {
229236 gpsLogger = new GPSLogger (this , (LocationManager ) getSystemService (Context .LOCATION_SERVICE ));
230237 if (gpsLogger .isGPSEnabled ()) {
@@ -240,28 +247,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
240247 }
241248 }
242249 break ;
243- case R .id .record_csv_data :
244- if (recordingStarted ) {
245- MenuItem item1 = menu .findItem (R .id .record_pause_data );
246- item1 .setIcon (R .drawable .record_icon );
247- exportData = true ;
248- recordingStarted = false ;
249- recordData = false ;
250- } else {
251- CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .nothing_to_export ), null , null );
252- }
253- break ;
254- case R .id .delete_csv_data :
255- if (recordingStarted ) {
256- MenuItem item1 = menu .findItem (R .id .record_pause_data );
257- item1 .setIcon (R .drawable .record_icon );
258- luxLogger .deleteFile ();
259- recordingStarted = false ;
260- recordData = false ;
261- CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .data_deleted ), null , null );
262- } else
263- CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .nothing_to_delete ), null , null );
264- break ;
265250 case R .id .show_map :
266251 if (ContextCompat .checkSelfPermission (this ,
267252 Manifest .permission .WRITE_EXTERNAL_STORAGE )
0 commit comments