-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
1,112 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
app/src/main/java/io/pslab/activity/DustSensorActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package io.pslab.activity; | ||
|
||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
import android.support.v4.app.Fragment; | ||
|
||
import io.pslab.R; | ||
import io.pslab.fragment.DustSensorDataFragment; | ||
import io.pslab.fragment.DustSensorSettingsFragment; | ||
import io.pslab.models.DustSensorData; | ||
import io.pslab.models.PSLabSensor; | ||
import io.pslab.models.SensorDataBlock; | ||
import io.pslab.others.LocalDataLog; | ||
import io.realm.RealmObject; | ||
import io.realm.RealmResults; | ||
|
||
public class DustSensorActivity extends PSLabSensor { | ||
|
||
private static final String PREF_NAME = "customDialogPreference"; | ||
public RealmResults<DustSensorData> recordedDustSensorData; | ||
|
||
@Override | ||
public int getMenu() { | ||
return R.menu.sensor_data_log_menu; | ||
} | ||
|
||
@Override | ||
public SharedPreferences getStateSettings() { | ||
return this.getSharedPreferences(PREF_NAME, MODE_PRIVATE); | ||
} | ||
|
||
@Override | ||
public String getFirstTimeSettingID() { | ||
return "DustSensorFirstTime"; | ||
} | ||
|
||
@Override | ||
public String getSensorName() { | ||
return getResources().getString(R.string.dust_sensor); | ||
} | ||
|
||
@Override | ||
public int getGuideTitle() { | ||
return R.string.dust_sensor; | ||
} | ||
|
||
@Override | ||
public int getGuideAbstract() { | ||
return R.string.dust_sensor_intro; | ||
} | ||
|
||
@Override | ||
public int getGuideSchematics() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getGuideDescription() { | ||
return R.string.dust_sensor_desc; | ||
} | ||
|
||
@Override | ||
public int getGuideExtraContent() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void recordSensorDataBlockID(SensorDataBlock block) { | ||
realm.beginTransaction(); | ||
realm.copyToRealm(block); | ||
realm.commitTransaction(); | ||
} | ||
|
||
@Override | ||
public void recordSensorData(RealmObject sensorData) { | ||
realm.beginTransaction(); | ||
realm.copyToRealm((DustSensorData) sensorData); | ||
realm.commitTransaction(); | ||
} | ||
|
||
@Override | ||
public void stopRecordSensorData() { | ||
LocalDataLog.with().refresh(); | ||
} | ||
|
||
@Override | ||
public Fragment getSensorFragment() { | ||
return DustSensorDataFragment.newInstance(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
reinstateConfigurations(); | ||
} | ||
|
||
private void reinstateConfigurations() { | ||
SharedPreferences luxMeterConfigurations; | ||
luxMeterConfigurations = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); | ||
locationEnabled = luxMeterConfigurations.getBoolean(DustSensorSettingsFragment.KEY_INCLUDE_LOCATION, true); | ||
DustSensorDataFragment.setParameters( | ||
getValueFromText(luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_HIGH_LIMIT, "4.0"), | ||
0.0, 5.0), | ||
getValueFromText(luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_UPDATE_PERIOD, "1000"), | ||
100, 1000), | ||
luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_DUST_SENSOR_TYPE, "0")); | ||
} | ||
|
||
private int getValueFromText(String strValue, int lowerBound, int upperBound) { | ||
if (strValue.isEmpty()) return lowerBound; | ||
int value = Integer.parseInt(strValue); | ||
if (value > upperBound) return upperBound; | ||
else if (value < lowerBound) return lowerBound; | ||
else return value; | ||
} | ||
|
||
private double getValueFromText(String strValue, double lowerBound, double upperBound) { | ||
if (strValue.isEmpty()) return lowerBound; | ||
double value = Double.parseDouble(strValue); | ||
if (value > upperBound) return upperBound; | ||
else if (value < lowerBound) return lowerBound; | ||
else return value; | ||
} | ||
|
||
@Override | ||
public void getDataFromDataLogger() { | ||
if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) { | ||
viewingData = true; | ||
recordedDustSensorData = LocalDataLog.with() | ||
.getBlockOfDustSensorRecords(getIntent().getExtras().getLong(DATA_BLOCK)); | ||
String title = titleFormat.format(recordedDustSensorData.get(0).getTime()); | ||
getSupportActionBar().setTitle(title); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.