Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions app/src/main/java/io/pslab/activity/LuxMeterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class LuxMeterActivity extends AppCompatActivity {
public boolean exportData = false;
public boolean recordingStarted = false;
public GPSLogger gpsLogger;
public boolean locationPref;
public CSVLogger luxLogger;
private Menu menu;

Expand Down Expand Up @@ -84,6 +83,8 @@ public class LuxMeterActivity extends AppCompatActivity {
@BindView(R.id.custom_dialog_desc)
TextView bottomSheetDesc;
private boolean checkGpsOnResume = false;
public boolean locationPref;
private LuxMeterFragmentData selectedFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -121,7 +122,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
});
try {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment selectedFragment = LuxMeterFragmentData.newInstance();
selectedFragment = LuxMeterFragmentData.newInstance();
transaction.replace(R.id.frame_layout_lux_meter, selectedFragment, selectedFragment.getTag());
transaction.commit();
} catch (Exception e) {
Expand Down Expand Up @@ -198,15 +199,22 @@ public boolean onTouchEvent(MotionEvent event) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.data_log_menu, menu);
inflater.inflate(R.menu.lux_data_log_menu, menu);
this.menu = menu;
return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem item = menu.findItem(R.id.record_data);
item.setIcon(recordData? R.drawable.ic_record_stop_white: R.drawable.ic_record_white);
return super.onPrepareOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.record_pause_data:
case R.id.record_data:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
Expand All @@ -215,16 +223,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}
if (recordData) {
item.setIcon(R.drawable.record_icon);
((LuxMeterFragmentData)selectedFragment).stopSensorFetching();
invalidateOptionsMenu();
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;
}
luxLogger = new CSVLogger(getString(R.string.lux_meter));
luxLogger.writeCSVFile("Timestamp,X,Y,Z\n");
recordData = true;
((LuxMeterFragmentData)selectedFragment).startSensorFetching();
invalidateOptionsMenu();
if (locationPref) {
gpsLogger = new GPSLogger(this, (LocationManager) getSystemService(Context.LOCATION_SERVICE));
if (gpsLogger.isGPSEnabled()) {
Expand All @@ -240,28 +247,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}
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,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
Expand Down
34 changes: 29 additions & 5 deletions app/src/main/java/io/pslab/fragment/LuxMeterFragmentData.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class LuxMeterFragmentData extends Fragment {
private Unbinder unbinder;
private long previousTimeElapsed = (System.currentTimeMillis() - startTime) / 1000;
private GPSLogger gpsLogger;
private Runnable runnable;

public static LuxMeterFragmentData newInstance() {
return new LuxMeterFragmentData();
Expand All @@ -98,6 +100,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
currentMin = 10000;
currentMax = 30;
entries = new ArrayList<>();
switch (sensorType) {
case 0:
Expand Down Expand Up @@ -135,7 +138,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_lux_meter_data, container, false);
unbinder = ButterKnife.bind(this, view);
Runnable runnable = new Runnable() {
runnable = new Runnable() {
@Override
public void run() {
if (flag == 0) {
Expand Down Expand Up @@ -189,8 +192,6 @@ public void run() {
}
}
};
Thread dataThread = new Thread(runnable);
dataThread.start();

lightMeter.setMaxSpeed(10000);

Expand Down Expand Up @@ -304,7 +305,7 @@ private void visualizeData() {
else
lightMeter.setPointerColor(Color.WHITE);

timeElapsed = (System.currentTimeMillis() - startTime) / 1000;
timeElapsed = ((System.currentTimeMillis() - startTime) / 1000);
if (timeElapsed != previousTimeElapsed) {
previousTimeElapsed = timeElapsed;
entries.add(new Entry((float) timeElapsed, data));
Expand Down Expand Up @@ -370,7 +371,7 @@ public void onClick(DialogInterface dialogInterface, int i) {

mChart.setData(data);
mChart.notifyDataSetChanged();
mChart.setVisibleXRangeMaximum(20);
mChart.setVisibleXRangeMaximum(80);
mChart.moveViewToX(data.getEntryCount());
mChart.invalidate();
}
Expand All @@ -386,4 +387,27 @@ private void unRegisterListener() {
sensorManager.unregisterListener(this);
}
}

public void startSensorFetching() {
entries.clear();
mChart.invalidate();
mChart.clear();
monitor = true;
flag = 0;
lightMeter.setWithTremble(true);
Thread dataThread = new Thread(runnable);
dataThread.start();
}

public void stopSensorFetching() {
monitor = false;
if (sensor != null && sensorDataFetch != null) {
sensorManager.unregisterListener(sensorDataFetch);
sensorDataFetch.cancel(true);
lightMeter.setWithTremble(false);
lightMeter.speedTo(0f, 500);
lightMeter.setPointerColor(ContextCompat.getColor(getActivity(), R.color.white));
}
}

}
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/ic_play_arrow_black_24dp.xml

This file was deleted.

21 changes: 21 additions & 0 deletions app/src/main/res/drawable/ic_record_stop_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<vector android:height="34dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="34dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#00000000"
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"
android:strokeAlpha="1" android:strokeColor="#e6e6e6" android:strokeWidth="8.94158649"/>
<path android:fillAlpha="0.09" android:fillColor="#00000000"
android:pathData="m-159.098,179.636a329,310 0,0 1,0.204 1.092"
android:strokeAlpha="0.09" android:strokeColor="#e635e6" android:strokeWidth="10"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
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"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
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"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
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"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
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"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
android:pathData="M179,99h168v142h-168z" android:strokeAlpha="1"
android:strokeColor="#e6e6e6" android:strokeWidth="10"/>
</vector>
19 changes: 19 additions & 0 deletions app/src/main/res/drawable/ic_record_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<vector android:height="34dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="34dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#00000000"
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"
android:strokeAlpha="1" android:strokeColor="#e6e6e6" android:strokeWidth="8.94158649"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
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"
android:strokeAlpha="1" android:strokeColor="#e6e6e6" android:strokeWidth="12.34022903"/>
<path android:fillAlpha="0.09" android:fillColor="#00000000"
android:pathData="m-159.098,179.636a329,310 0,0 1,0.204 1.092"
android:strokeAlpha="0.09" android:strokeColor="#e635e6" android:strokeWidth="10"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
android:pathData="m198.232,484.162l-25.098,0l-48.634,-50.268l-27.247,0l0,50.268l-19.336,0l0,-126.435l40.724,0q13.184,0 21.973,1.528 8.789,1.444 15.821,5.265 7.91,4.331 12.305,10.954 4.492,6.538 4.492,16.643 0,13.671 -7.91,22.926 -7.91,9.171 -21.778,13.841zM153.016,393.306q0,-5.434 -2.246,-9.595 -2.148,-4.246 -7.227,-7.133 -4.199,-2.462 -9.961,-3.397 -5.762,-1.019 -13.575,-1.019l-22.754,0l0,47.721l19.532,0q9.18,0 16.016,-1.359 6.836,-1.444 11.621,-5.265 4.395,-3.566 6.445,-8.152 2.148,-4.67 2.148,-11.803z" android:strokeColor="#00000000"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
android:pathData="m312.785,484.162l-95.803,0l0,-126.435l95.803,0l0,14.945l-76.467,0l0,34.644l76.467,0l0,14.945l-76.467,0l0,46.957l76.467,0z" android:strokeColor="#00000000"/>
<path android:fillAlpha="1" android:fillColor="#e6e6e6"
android:pathData="m455.855,474.991q-5.371,2.038 -9.766,3.821 -4.297,1.783 -11.328,3.736 -5.957,1.613 -12.989,2.717 -6.934,1.189 -15.332,1.189 -15.821,0 -28.809,-3.821 -12.891,-3.906 -22.461,-12.142 -9.375,-8.067 -14.649,-20.464 -5.274,-12.482 -5.274,-28.955 0,-15.624 5.078,-27.936 5.078,-12.312 14.649,-20.804 9.278,-8.237 22.364,-12.567 13.184,-4.331 29.2,-4.331 11.719,0 23.34,2.462 11.719,2.462 25.977,8.661l0,19.954l-1.465,0q-12.012,-8.746 -23.829,-12.737 -11.817,-3.991 -25.294,-3.991 -11.035,0 -19.922,3.142 -8.789,3.057 -15.723,9.595 -6.738,6.368 -10.547,16.133 -3.711,9.68 -3.711,22.417 0,13.331 4.102,22.926 4.199,9.595 10.742,15.624 6.836,6.284 15.918,9.34 9.18,2.972 19.336,2.972 13.965,0 26.173,-4.161 12.207,-4.161 22.852,-12.482l1.367,0z" android:strokeColor="#00000000"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/rounded_custom_border.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dip" android:color="#B1BCBE" />
<stroke android:width="1dip" android:color="@color/colorPrimary" />
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/fragment_lux_meter_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin"
android:layout_weight="@dimen/weight_1"
android:background="@drawable/rounded_custom_border"
android:background="@drawable/control_edittext"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="@color/black"
Expand All @@ -190,7 +190,7 @@
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin"
android:layout_weight="@dimen/weight_1"
android:background="@drawable/rounded_custom_border"
android:background="@drawable/control_edittext"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="@color/black"
Expand All @@ -204,7 +204,7 @@
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin"
android:layout_weight="@dimen/weight_1"
android:background="@drawable/rounded_custom_border"
android:background="@drawable/control_edittext"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="@color/black"
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/menu/lux_data_log_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/record_data"
android:icon="@drawable/ic_record_white"
android:title="@string/record_csv_data"
app:showAsAction="always" />
<item
android:id="@+id/show_map"
android:icon="@drawable/menu_icon_map"
android:title="@string/view_map"
app:showAsAction="never" />
<item
android:id="@+id/settings"
android:title="@string/nav_settings"
app:showAsAction="never" />
</menu>