Skip to content

Commit 36be008

Browse files
author
Kunal
committed
Accelerometer code refactored
1 parent 9f15fe2 commit 36be008

File tree

9 files changed

+580
-1123
lines changed

9 files changed

+580
-1123
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Fragment getSensorFragment() {
9292
@Override
9393
public void getDataFromDataLogger() {
9494
if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) {
95-
//playingData = true;
95+
playingData = true;
9696
viewingData = true;
9797
recordedAccelerometerData = LocalDataLog.with()
9898
.getBlockOfAccelerometerRecords(getIntent().getExtras().getLong(DATA_BLOCK));
@@ -115,19 +115,8 @@ private void reinstateConfigurations() {
115115
accelerometerConfigurations = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
116116
locationEnabled = accelerometerConfigurations.getBoolean(AccelerometerSettingsFragment.KEY_INCLUDE_LOCATION, true);
117117
AccelerometerDataFragment.setParameters(
118-
getValueFromText(accelerometerConfigurations.getString(AccelerometerSettingsFragment.KEY_HIGH_LIMIT, "2000"),
119-
10, 10000),
120-
getValueFromText(accelerometerConfigurations.getString(AccelerometerSettingsFragment.KEY_UPDATE_PERIOD, "1000"),
121-
100, 1000),
122-
accelerometerConfigurations.getString(AccelerometerSettingsFragment.KEY_ACCELEROMETER_SENSOR_TYPE, "0"),
118+
Float.valueOf(accelerometerConfigurations.getString(AccelerometerSettingsFragment.KEY_HIGH_LIMIT, "20")),
119+
Integer.valueOf(accelerometerConfigurations.getString(AccelerometerSettingsFragment.KEY_UPDATE_PERIOD, "1000")),
123120
accelerometerConfigurations.getString(AccelerometerSettingsFragment.KEY_ACCELEROMETER_SENSOR_GAIN, "1"));
124121
}
125-
126-
private int getValueFromText(String strValue, int lowerBound, int upperBound) {
127-
if (strValue.isEmpty()) return lowerBound;
128-
int value = Integer.parseInt(strValue);
129-
if (value > upperBound) return upperBound;
130-
else if (value < lowerBound) return lowerBound;
131-
else return value;
132-
}
133122
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ protected void onResume() {
107107
}
108108

109109
private void reinstateConfigurations() {
110-
SharedPreferences accelerometerConfigurations;
111-
accelerometerConfigurations = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
112-
locationEnabled = accelerometerConfigurations.getBoolean(GyroscopeSettingsFragment.KEY_INCLUDE_LOCATION, true);
110+
SharedPreferences gyroscopeConfigurations;
111+
gyroscopeConfigurations = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
112+
locationEnabled = gyroscopeConfigurations.getBoolean(GyroscopeSettingsFragment.KEY_INCLUDE_LOCATION, true);
113113
GyroscopeDataFragment.setParameters(
114-
Float.valueOf(accelerometerConfigurations.getString(GyroscopeSettingsFragment.KEY_HIGH_LIMIT, "20")),
115-
Integer.valueOf(accelerometerConfigurations.getString(GyroscopeSettingsFragment.KEY_UPDATE_PERIOD, "1000")),
116-
accelerometerConfigurations.getString(GyroscopeSettingsFragment.KEY_GYROSCOPE_SENSOR_GAIN, "1"));
114+
Float.valueOf(gyroscopeConfigurations.getString(GyroscopeSettingsFragment.KEY_HIGH_LIMIT, "20")),
115+
Integer.valueOf(gyroscopeConfigurations.getString(GyroscopeSettingsFragment.KEY_UPDATE_PERIOD, "1000")),
116+
gyroscopeConfigurations.getString(GyroscopeSettingsFragment.KEY_GYROSCOPE_SENSOR_GAIN, "1"));
117117
}
118118
}

0 commit comments

Comments
 (0)