Skip to content

Commit 8bd5fdf

Browse files
authored
Merge pull request #1990 from fossasia/development
chore: merge dev into master
2 parents 281b294 + 88d8fdb commit 8bd5fdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1579
-187
lines changed

README.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ This repository holds the Android App for performing experiments with [PSLab](ht
119119

120120
## How to set up the Android app in your development environment
121121

122-
123122
### Application Flavors
124123

125124
There are 2 flavors (build variants) of PSLab Android application.
@@ -218,17 +217,9 @@ Despite any reason, follow the steps given below to squash all commits into one
218217
### Branch Policy
219218

220219
We have the following branches
221-
* **development**
222-
All development goes on in this branch. If you're making a contribution,
223-
you are supposed to make a pull request to _development_.
224-
Make sure it passes a build check on Travis.
225-
226-
* **master**
227-
This contains the stable code. After significant features/bugfixes are accumulated on development, we move it to master.
228-
229-
* **apk**
230-
This branch contains automatically generated apk file for testing.
231-
220+
* **development** All development goes on in this branch. If you're making a contribution, you are supposed to make a pull request to _development_. Make sure it passes a build check on Travis.
221+
* **master** This contains the stable code. After significant features/bugfixes are accumulated on development, we move it to master.
222+
* **apk** This branch contains automatically generated apk file for testing.
232223

233224
### Code style
234225

@@ -239,25 +230,26 @@ Please try to follow the mentioned guidelines while writing and submitting your
239230
* The activity/fragment file name corresponding to the layout files should be named as (activity/fragment name)(activity/fragment).java like ```ChannelsParameterFragment.java``` corresponding to the layout file ```fragment_channels_parameter.xml``` .
240231
* The corresponding widgets for buttons, textboxes, checkboxes etc. in activity files should be named as (viewtype/widget)(fragment/activity name)(no. in the file) like ```spinnerChannelSelect1``` corresponding to ```spinner_channel_select1``` .
241232

242-
## License
243-
244-
This project is currently licensed under the Apache License 2.0. A copy of [LICENSE](LICENSE) is to be present along with the source code. To obtain the software under a different license, please contact FOSSASIA.
233+
## Developers
245234

246-
## Maintainers
235+
### Maintainers
247236
The project is maintained by
248237
- Padmal ([@CloudyPadmal](https://github.com/CloudyPadmal))
249238
- Mario Behling ([@mariobehling](http://github.com/mariobehling))
250239
- Lorenz Gerber ([@lorenzgerber](https://github.com/lorenzgerber))
251240
- Wei Tat ([@cweitat](https://github.com/cweitat))
252241
- Wai Gie ([@woshikie](https://github.com/woshikie))
253242
- Neel Trivedi ([@neel1998](https://github.com/neel1998))
254-
## Alumni
255-
- Praveen Patil ([@wavicles](https://github.com/wavicles))
256-
- Jithin ([@jithinbp](https://github.com/jithinbp))
243+
244+
### Alumni
257245
- Akarshan Gandotra ([@akarshan96](https://github.com/akarshan96))
258246
- Asitava Sarkar ([@asitava1998](https://github.com/asitava1998))
259247
- Vivek Singh Bhadauria ([@viveksb007](https://github.com/viveksb007))
260248
- Avjeet ([@Avjeet](https://github.com/Avjeet))
261249
- Abhinav ([@abhinavraj23](https://github.com/abhinavraj23))
262250
- Harsh ([@harsh-2711](https://github.com/harsh-2711))
263251
- Yatri ([@yatri1609](https://github.com/yatri1609))
252+
253+
## License
254+
255+
This project is currently licensed under the Apache License 2.0. A copy of [LICENSE](LICENSE) is to be present along with the source code. To obtain the software under a different license, please contact FOSSASIA.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId "io.pslab"
1414
minSdkVersion rootProject.ext.minSdkVersion
1515
targetSdkVersion rootProject.ext.targetSdkVersion
16-
versionCode 20
17-
versionName "2.0.19"
16+
versionCode 21
17+
versionName "2.0.20"
1818
multiDexEnabled true
1919
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2020
}

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
android:name=".activity.GasSensorActivity"
104104
android:screenOrientation="portrait" />
105105
<activity android:name=".activity.MapsActivity" />
106+
<activity
107+
android:name=".activity.DustSensorActivity"
108+
android:screenOrientation="portrait"/>
106109

107110
<receiver android:name=".receivers.USBDetachReceiver" />
108111

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.pslab;
2+
3+
import java.io.Serializable;
4+
5+
public class CheckBoxGetter implements Serializable {
6+
7+
private String name;
8+
private boolean isSelected;
9+
10+
public CheckBoxGetter(String name, boolean isSelected) {
11+
this.name = name;
12+
this.isSelected = isSelected;
13+
}
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
23+
public boolean isSelected() {
24+
return isSelected;
25+
}
26+
27+
public void setSelected(boolean selected) {
28+
isSelected = selected;
29+
}
30+
}

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@
44
import android.os.Environment;
55
import android.support.design.widget.Snackbar;
66
import android.support.v7.app.AppCompatActivity;
7+
import android.support.v7.widget.LinearLayoutManager;
8+
import android.support.v7.widget.RecyclerView;
79
import android.support.v7.widget.Toolbar;
8-
import android.view.Gravity;
910
import android.view.MenuItem;
1011
import android.view.View;
1112
import android.widget.AdapterView;
1213
import android.widget.ArrayAdapter;
1314
import android.widget.Button;
14-
import android.widget.CheckBox;
1515
import android.widget.EditText;
16-
import android.widget.LinearLayout;
1716
import android.widget.Spinner;
1817
import android.widget.Toast;
1918

2019
import java.io.File;
2120
import java.io.FileWriter;
2221
import java.io.IOException;
2322
import java.util.ArrayList;
23+
import java.util.List;
2424

25+
import io.pslab.CheckBoxGetter;
2526
import io.pslab.R;
27+
import io.pslab.adapters.CheckBoxAdapter;
2628
import io.pslab.others.CSVLogger;
2729
import io.pslab.others.CustomSnackBar;
2830

@@ -36,7 +38,8 @@ public class CreateConfigActivity extends AppCompatActivity {
3638
private EditText intervalEditText;
3739
private String interval;
3840
private View rootView;
39-
private LinearLayout paramsListContainer;
41+
private RecyclerView paramsListContainer;
42+
private List<CheckBoxGetter> list;
4043

4144
@Override
4245
protected void onCreate(Bundle savedInstanceState) {
@@ -58,6 +61,8 @@ protected void onCreate(Bundle savedInstanceState) {
5861
instrumentsList = new ArrayList<>();
5962
instrumentParamsList = new ArrayList<>();
6063
instrumentParamsListTitles = new ArrayList<>();
64+
paramsListContainer.setLayoutManager(new LinearLayoutManager(this));
65+
list = new ArrayList<>();
6166
createArrayLists();
6267
selectInstrumentSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, instrumentsList));
6368
selectInstrumentSpinner.setSelection(0, true);
@@ -97,9 +102,9 @@ public void onClick(View v) {
97102
Toast.makeText(CreateConfigActivity.this, getResources().getString(R.string.no_interval_message), Toast.LENGTH_SHORT).show();
98103
} else {
99104
ArrayList<String> selectedParamsList = new ArrayList<>();
100-
for (int i = 0; i < paramsListContainer.getChildCount(); i ++) {
101-
CheckBox checkBox = (CheckBox) paramsListContainer.getChildAt(i);
102-
if (checkBox.isChecked()) {
105+
for (int i = 0; i < paramsListContainer.getChildCount(); i++) {
106+
boolean checkBox = list.get(i).isSelected();
107+
if (checkBox) {
103108
selectedParamsList.add(instrumentParamsList.get(selectedItem)[i]);
104109
}
105110
}
@@ -134,17 +139,15 @@ private void createArrayLists() {
134139
}
135140

136141
private void createCheckboxList() {
137-
paramsListContainer.removeAllViews();
142+
list.clear();
138143
String[] params = instrumentParamsListTitles.get(selectedItem);
139-
for (int i = 0; i < params.length; i++){
140-
CheckBox checkBox = new CheckBox(CreateConfigActivity.this);
141-
checkBox.setText(params[i]);
142-
LinearLayout.LayoutParams checkBoxParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
143-
checkBoxParams.gravity = Gravity.CENTER_HORIZONTAL;
144-
checkBoxParams.setMargins(0,(int)getResources().getDimension(R.dimen.create_config_margin1),0,0);
145-
checkBox.setLayoutParams(checkBoxParams);
146-
paramsListContainer.addView(checkBox, i);
144+
for (int i = 0; i < params.length; i++) {
145+
CheckBoxGetter check = new CheckBoxGetter(params[i], false);
146+
list.add(check);
147147
}
148+
CheckBoxAdapter box;
149+
box = new CheckBoxAdapter(CreateConfigActivity.this, list);
150+
paramsListContainer.setAdapter(box);
148151
}
149152

150153
@Override
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package io.pslab.activity;
2+
3+
import android.content.SharedPreferences;
4+
import android.preference.PreferenceManager;
5+
import android.support.v4.app.Fragment;
6+
7+
import io.pslab.R;
8+
import io.pslab.fragment.DustSensorDataFragment;
9+
import io.pslab.fragment.DustSensorSettingsFragment;
10+
import io.pslab.models.DustSensorData;
11+
import io.pslab.models.PSLabSensor;
12+
import io.pslab.models.SensorDataBlock;
13+
import io.pslab.others.LocalDataLog;
14+
import io.realm.RealmObject;
15+
import io.realm.RealmResults;
16+
17+
public class DustSensorActivity extends PSLabSensor {
18+
19+
private static final String PREF_NAME = "customDialogPreference";
20+
public RealmResults<DustSensorData> recordedDustSensorData;
21+
22+
@Override
23+
public int getMenu() {
24+
return R.menu.sensor_data_log_menu;
25+
}
26+
27+
@Override
28+
public SharedPreferences getStateSettings() {
29+
return this.getSharedPreferences(PREF_NAME, MODE_PRIVATE);
30+
}
31+
32+
@Override
33+
public String getFirstTimeSettingID() {
34+
return "DustSensorFirstTime";
35+
}
36+
37+
@Override
38+
public String getSensorName() {
39+
return getResources().getString(R.string.dust_sensor);
40+
}
41+
42+
@Override
43+
public int getGuideTitle() {
44+
return R.string.dust_sensor;
45+
}
46+
47+
@Override
48+
public int getGuideAbstract() {
49+
return R.string.dust_sensor_intro;
50+
}
51+
52+
@Override
53+
public int getGuideSchematics() {
54+
return 0;
55+
}
56+
57+
@Override
58+
public int getGuideDescription() {
59+
return R.string.dust_sensor_desc;
60+
}
61+
62+
@Override
63+
public int getGuideExtraContent() {
64+
return 0;
65+
}
66+
67+
@Override
68+
public void recordSensorDataBlockID(SensorDataBlock block) {
69+
realm.beginTransaction();
70+
realm.copyToRealm(block);
71+
realm.commitTransaction();
72+
}
73+
74+
@Override
75+
public void recordSensorData(RealmObject sensorData) {
76+
realm.beginTransaction();
77+
realm.copyToRealm((DustSensorData) sensorData);
78+
realm.commitTransaction();
79+
}
80+
81+
@Override
82+
public void stopRecordSensorData() {
83+
LocalDataLog.with().refresh();
84+
}
85+
86+
@Override
87+
public Fragment getSensorFragment() {
88+
return DustSensorDataFragment.newInstance();
89+
}
90+
91+
@Override
92+
protected void onResume() {
93+
super.onResume();
94+
reinstateConfigurations();
95+
}
96+
97+
private void reinstateConfigurations() {
98+
SharedPreferences luxMeterConfigurations;
99+
luxMeterConfigurations = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
100+
locationEnabled = luxMeterConfigurations.getBoolean(DustSensorSettingsFragment.KEY_INCLUDE_LOCATION, true);
101+
DustSensorDataFragment.setParameters(
102+
getValueFromText(luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_HIGH_LIMIT, "4.0"),
103+
0.0, 5.0),
104+
getValueFromText(luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_UPDATE_PERIOD, "1000"),
105+
100, 1000),
106+
luxMeterConfigurations.getString(DustSensorSettingsFragment.KEY_DUST_SENSOR_TYPE, "0"));
107+
}
108+
109+
private int getValueFromText(String strValue, int lowerBound, int upperBound) {
110+
if (strValue.isEmpty()) return lowerBound;
111+
int value = Integer.parseInt(strValue);
112+
if (value > upperBound) return upperBound;
113+
else if (value < lowerBound) return lowerBound;
114+
else return value;
115+
}
116+
117+
private double getValueFromText(String strValue, double lowerBound, double upperBound) {
118+
if (strValue.isEmpty()) return lowerBound;
119+
double value = Double.parseDouble(strValue);
120+
if (value > upperBound) return upperBound;
121+
else if (value < lowerBound) return lowerBound;
122+
else return value;
123+
}
124+
125+
@Override
126+
public void getDataFromDataLogger() {
127+
if (getIntent().getExtras() != null && getIntent().getExtras().getBoolean(KEY_LOG)) {
128+
viewingData = true;
129+
recordedDustSensorData = LocalDataLog.with()
130+
.getBlockOfDustSensorRecords(getIntent().getExtras().getLong(DATA_BLOCK));
131+
String title = titleFormat.format(recordedDustSensorData.get(0).getTime());
132+
getSupportActionBar().setTitle(title);
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)