Skip to content

Commit 53f62ee

Browse files
committed
added record functionality in lux meter
changed icons Increased icon text size increased rec text size
1 parent 4de3a46 commit 53f62ee

File tree

8 files changed

+111
-52
lines changed

8 files changed

+111
-52
lines changed

app/src/main/java/io/pslab/activity/LuxMeterActivity.java

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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_white: R.drawable.ic_record_white);
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)

app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.os.Bundle;
1414
import android.support.design.widget.CoordinatorLayout;
1515
import android.support.v4.app.Fragment;
16+
import android.support.v4.content.ContextCompat;
1617
import android.view.LayoutInflater;
1718
import android.view.View;
1819
import android.view.ViewGroup;
@@ -82,6 +83,7 @@ public class LuxMeterFragmentData extends Fragment {
8283
private Unbinder unbinder;
8384
private long previousTimeElapsed = (System.currentTimeMillis() - startTime) / 1000;
8485
private GPSLogger gpsLogger;
86+
private Runnable runnable;
8587

8688
public static LuxMeterFragmentData newInstance() {
8789
return new LuxMeterFragmentData();
@@ -98,6 +100,7 @@ public void onCreate(Bundle savedInstanceState) {
98100
super.onCreate(savedInstanceState);
99101
setRetainInstance(true);
100102
currentMin = 10000;
103+
currentMax = 30;
101104
entries = new ArrayList<>();
102105
switch (sensorType) {
103106
case 0:
@@ -135,7 +138,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
135138
Bundle savedInstanceState) {
136139
View view = inflater.inflate(R.layout.fragment_lux_meter_data, container, false);
137140
unbinder = ButterKnife.bind(this, view);
138-
Runnable runnable = new Runnable() {
141+
runnable = new Runnable() {
139142
@Override
140143
public void run() {
141144
if (flag == 0) {
@@ -189,8 +192,6 @@ public void run() {
189192
}
190193
}
191194
};
192-
Thread dataThread = new Thread(runnable);
193-
dataThread.start();
194195

195196
lightMeter.setMaxSpeed(10000);
196197

@@ -304,7 +305,7 @@ private void visualizeData() {
304305
else
305306
lightMeter.setPointerColor(Color.WHITE);
306307

307-
timeElapsed = (System.currentTimeMillis() - startTime) / 1000;
308+
timeElapsed = ((System.currentTimeMillis() - startTime) / 1000);
308309
if (timeElapsed != previousTimeElapsed) {
309310
previousTimeElapsed = timeElapsed;
310311
entries.add(new Entry((float) timeElapsed, data));
@@ -370,7 +371,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
370371

371372
mChart.setData(data);
372373
mChart.notifyDataSetChanged();
373-
mChart.setVisibleXRangeMaximum(20);
374+
mChart.setVisibleXRangeMaximum(80);
374375
mChart.moveViewToX(data.getEntryCount());
375376
mChart.invalidate();
376377
}
@@ -386,4 +387,27 @@ private void unRegisterListener() {
386387
sensorManager.unregisterListener(this);
387388
}
388389
}
390+
391+
public void startSensorFetching() {
392+
entries.clear();
393+
mChart.invalidate();
394+
mChart.clear();
395+
monitor = true;
396+
flag = 0;
397+
lightMeter.setWithTremble(true);
398+
Thread dataThread = new Thread(runnable);
399+
dataThread.start();
400+
}
401+
402+
public void stopSensorFetching() {
403+
monitor = false;
404+
if (sensor != null && sensorDataFetch != null) {
405+
sensorManager.unregisterListener(sensorDataFetch);
406+
sensorDataFetch.cancel(true);
407+
lightMeter.setWithTremble(false);
408+
lightMeter.speedTo(0f, 500);
409+
lightMeter.setPointerColor(ContextCompat.getColor(getActivity(), R.color.white));
410+
}
411+
}
412+
389413
}

app/src/main/res/drawable/ic_play_arrow_black_24dp.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<vector android:height="34dp" android:viewportHeight="512"
2+
android:viewportWidth="512" android:width="34dp"
3+
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#00000000"
5+
android:pathData="m262.868,323.778c-87.965,0 -159.529,-69.994 -159.529,-156.029 0,-86.035 71.564,-156.029 159.529,-156.029 87.965,0 159.529,69.994 159.529,156.029 0,86.035 -71.564,156.029 -159.529,156.029z"
6+
android:strokeAlpha="1" android:strokeColor="#e6e6e6" android:strokeWidth="8.94158649"/>
7+
<path android:fillAlpha="0.09" android:fillColor="#00000000"
8+
android:pathData="m-159.098,179.636a329,310 0,0 1,0.204 1.092"
9+
android:strokeAlpha="0.09" android:strokeColor="#e635e6" android:strokeWidth="10"/>
10+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
11+
android:pathData="m149.158,450.778q0,7.228 -3.198,14.29 -3.12,7.062 -8.814,11.963 -6.24,5.317 -14.586,8.308 -8.268,2.991 -19.967,2.991 -12.558,0 -22.619,-2.492 -9.984,-2.492 -20.357,-7.394l0,-20.604l1.092,0q8.814,7.81 20.357,12.047 11.544,4.237 21.683,4.237 14.352,0 22.307,-5.732 8.034,-5.733 8.034,-15.287 0,-8.225 -3.822,-12.13 -3.744,-3.905 -11.466,-6.065 -5.85,-1.662 -12.714,-2.742 -6.786,-1.08 -14.43,-2.742 -15.443,-3.489 -22.931,-11.88 -7.41,-8.474 -7.41,-22.016 0,-15.536 12.324,-25.422 12.324,-9.97 31.277,-9.97 12.246,0 22.463,2.492 10.218,2.492 18.095,6.148l0,19.441L143.386,388.219q-6.63,-5.982 -17.471,-9.886 -10.764,-3.988 -22.073,-3.988 -12.402,0 -19.967,5.483 -7.488,5.483 -7.488,14.124 0,7.726 3.744,12.13 3.744,4.403 13.182,6.729 4.992,1.163 14.196,2.825 9.204,1.662 15.599,3.406 12.948,3.656 19.499,11.05 6.552,7.394 6.552,20.687z" android:strokeColor="#00000000"/>
12+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
13+
android:pathData="M256.795,377.003L215.3,377.003l0,109.084L199.857,486.087L199.857,377.003L158.362,377.003l0,-14.622l98.433,0z" android:strokeColor="#00000000"/>
14+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
15+
android:pathData="m355.384,376.588q7.098,8.308 10.842,20.355 3.822,12.047 3.822,27.333 0,15.287 -3.9,27.416 -3.822,12.047 -10.764,20.105 -7.176,8.391 -17.003,12.628 -9.75,4.237 -22.307,4.237 -12.246,0 -22.307,-4.32 -9.984,-4.32 -17.003,-12.545 -7.02,-8.225 -10.842,-20.188 -3.744,-11.963 -3.744,-27.333 0,-15.12 3.744,-27.084 3.744,-12.047 10.92,-20.604 6.864,-8.142 17.003,-12.462 10.218,-4.32 22.229,-4.32 12.48,0 22.385,4.403 9.984,4.32 16.925,12.379zM353.98,424.276q0,-24.093 -10.14,-37.137 -10.14,-13.127 -27.689,-13.127 -17.705,0 -27.845,13.127 -10.062,13.044 -10.062,37.137 0,24.342 10.296,37.303 10.296,12.877 27.611,12.877 17.315,0 27.533,-12.877 10.296,-12.96 10.296,-37.303z" android:strokeColor="#00000000"/>
16+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
17+
android:pathData="m470.508,399.767q0,8.225 -2.73,15.287 -2.652,6.979 -7.488,12.13 -6.006,6.397 -14.196,9.637 -8.19,3.157 -20.669,3.157l-15.444,0l0,46.109l-15.443,0l0,-123.706l31.511,0q10.452,0 17.705,1.911 7.254,1.828 12.87,5.816 6.63,4.736 10.218,11.797 3.666,7.062 3.666,17.862zM454.44,400.182q0,-6.397 -2.106,-11.133 -2.106,-4.736 -6.396,-7.726 -3.744,-2.575 -8.58,-3.656 -4.758,-1.163 -12.09,-1.163l-15.288,0l0,49.432l13.026,0q9.36,0 15.21,-1.745 5.85,-1.828 9.516,-5.732 3.666,-3.988 5.148,-8.391 1.56,-4.403 1.56,-9.886z" android:strokeColor="#00000000"/>
18+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
19+
android:pathData="M179,99h168v142h-168z" android:strokeAlpha="1"
20+
android:strokeColor="#e6e6e6" android:strokeWidth="10"/>
21+
</vector>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<vector android:height="34dp" android:viewportHeight="512"
2+
android:viewportWidth="512" android:width="34dp"
3+
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#00000000"
5+
android:pathData="m262.868,323.778c-87.965,0 -159.529,-69.994 -159.529,-156.029 0,-86.035 71.564,-156.029 159.529,-156.029 87.965,0 159.529,69.994 159.529,156.029 0,86.035 -71.564,156.029 -159.529,156.029z"
6+
android:strokeAlpha="1" android:strokeColor="#e6e6e6" android:strokeWidth="8.94158649"/>
7+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
8+
android:pathData="m333.739,157.166a70.328,70.328 0,0 1,-56.625 81.522,70.328 70.328,0 0,1 -81.75,-56.295 70.328,70.328 0,0 1,55.965 -81.977,70.328 70.328,0 0,1 82.202,55.633"
9+
android:strokeAlpha="1" android:strokeColor="#e6e6e6" android:strokeWidth="12.34022903"/>
10+
<path android:fillAlpha="0.09" android:fillColor="#00000000"
11+
android:pathData="m-159.098,179.636a329,310 0,0 1,0.204 1.092"
12+
android:strokeAlpha="0.09" android:strokeColor="#e635e6" android:strokeWidth="10"/>
13+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
14+
android:pathData="m207.996,484.162l-21.711,0l-42.071,-50.268l-23.57,0l0,50.268l-16.727,0l0,-126.435l35.228,0q11.405,0 19.008,1.528 7.603,1.444 13.686,5.265 6.843,4.331 10.645,10.954 3.886,6.538 3.886,16.643 0,13.671 -6.843,22.926 -6.843,9.171 -18.839,13.841zM168.882,393.306q0,-5.434 -1.943,-9.595 -1.859,-4.246 -6.252,-7.133 -3.633,-2.462 -8.617,-3.397 -4.984,-1.019 -11.743,-1.019l-19.684,0l0,47.721l16.896,0q7.941,0 13.855,-1.359 5.914,-1.444 10.053,-5.265 3.802,-3.566 5.576,-8.152 1.859,-4.67 1.859,-11.803z" android:strokeColor="#00000000"/>
15+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
16+
android:pathData="m307.091,484.162l-82.875,0l0,-126.435l82.875,0l0,14.945l-66.148,0l0,34.644l66.148,0l0,14.945l-66.148,0l0,46.957l66.148,0z" android:strokeColor="#00000000"/>
17+
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
18+
android:pathData="m430.855,474.991q-4.646,2.038 -8.448,3.821 -3.717,1.783 -9.8,3.736 -5.153,1.613 -11.236,2.717 -5.998,1.189 -13.263,1.189 -13.686,0 -24.922,-3.821 -11.151,-3.906 -19.43,-12.142 -8.11,-8.067 -12.672,-20.464 -4.562,-12.482 -4.562,-28.955 0,-15.624 4.393,-27.936 4.393,-12.312 12.672,-20.804 8.026,-8.237 19.346,-12.567 11.405,-4.331 25.26,-4.331 10.138,0 20.191,2.462 10.138,2.462 22.472,8.661l0,19.954l-1.267,0q-10.391,-8.746 -20.613,-12.737 -10.222,-3.991 -21.88,-3.991 -9.546,0 -17.234,3.142 -7.603,3.057 -13.601,9.595 -5.829,6.368 -9.124,16.133 -3.21,9.68 -3.21,22.417 0,13.331 3.548,22.926 3.633,9.595 9.293,15.624 5.914,6.284 13.77,9.34 7.941,2.972 16.727,2.972 12.081,0 22.641,-4.161 10.56,-4.161 19.768,-12.482l1.183,0z" android:strokeColor="#00000000"/>
19+
</vector>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<shape xmlns:android="http://schemas.android.com/apk/res/android">
33
<solid android:color="#FFFFFF"/>
4-
<stroke android:width="3dip" android:color="#B1BCBE" />
4+
<stroke android:width="1dip" android:color="@color/colorPrimary" />
55
<corners android:radius="10dip"/>
66
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
77
</shape>

app/src/main/res/layout/fragment_lux_meter_data.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
android:layout_marginLeft="@dimen/card_margin"
177177
android:layout_marginRight="@dimen/card_margin"
178178
android:layout_weight="@dimen/weight_1"
179-
android:background="@drawable/rounded_custom_border"
179+
android:background="@drawable/control_edittext"
180180
android:gravity="center_vertical"
181181
android:textAlignment="center"
182182
android:textColor="@color/black"
@@ -190,7 +190,7 @@
190190
android:layout_marginLeft="@dimen/card_margin"
191191
android:layout_marginRight="@dimen/card_margin"
192192
android:layout_weight="@dimen/weight_1"
193-
android:background="@drawable/rounded_custom_border"
193+
android:background="@drawable/control_edittext"
194194
android:gravity="center_vertical"
195195
android:textAlignment="center"
196196
android:textColor="@color/black"
@@ -204,7 +204,7 @@
204204
android:layout_marginLeft="@dimen/card_margin"
205205
android:layout_marginRight="@dimen/card_margin"
206206
android:layout_weight="@dimen/weight_1"
207-
android:background="@drawable/rounded_custom_border"
207+
android:background="@drawable/control_edittext"
208208
android:gravity="center_vertical"
209209
android:textAlignment="center"
210210
android:textColor="@color/black"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
android:id="@+id/record_data"
6+
android:icon="@drawable/ic_record_white"
7+
android:title="@string/record_csv_data"
8+
app:showAsAction="always" />
9+
<item
10+
android:id="@+id/show_map"
11+
android:icon="@drawable/menu_icon_map"
12+
android:title="@string/view_map"
13+
app:showAsAction="never" />
14+
<item
15+
android:id="@+id/settings"
16+
android:title="@string/nav_settings"
17+
app:showAsAction="never" />
18+
</menu>
19+

0 commit comments

Comments
 (0)