Skip to content

Commit

Permalink
Merge pull request #1990 from fossasia/development
Browse files Browse the repository at this point in the history
chore: merge dev into master
  • Loading branch information
CloudyPadmal authored Oct 18, 2019
2 parents 281b294 + 88d8fdb commit 8bd5fdf
Show file tree
Hide file tree
Showing 41 changed files with 1,579 additions and 187 deletions.
30 changes: 11 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ This repository holds the Android App for performing experiments with [PSLab](ht

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


### Application Flavors

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

We have the following branches
* **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.

* **master**
This contains the stable code. After significant features/bugfixes are accumulated on development, we move it to master.

* **apk**
This branch contains automatically generated apk file for testing.

* **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.
* **master** This contains the stable code. After significant features/bugfixes are accumulated on development, we move it to master.
* **apk** This branch contains automatically generated apk file for testing.

### Code style

Expand All @@ -239,25 +230,26 @@ Please try to follow the mentioned guidelines while writing and submitting your
* 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``` .
* 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``` .

## License

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.
## Developers

## Maintainers
### Maintainers
The project is maintained by
- Padmal ([@CloudyPadmal](https://github.com/CloudyPadmal))
- Mario Behling ([@mariobehling](http://github.com/mariobehling))
- Lorenz Gerber ([@lorenzgerber](https://github.com/lorenzgerber))
- Wei Tat ([@cweitat](https://github.com/cweitat))
- Wai Gie ([@woshikie](https://github.com/woshikie))
- Neel Trivedi ([@neel1998](https://github.com/neel1998))
## Alumni
- Praveen Patil ([@wavicles](https://github.com/wavicles))
- Jithin ([@jithinbp](https://github.com/jithinbp))

### Alumni
- Akarshan Gandotra ([@akarshan96](https://github.com/akarshan96))
- Asitava Sarkar ([@asitava1998](https://github.com/asitava1998))
- Vivek Singh Bhadauria ([@viveksb007](https://github.com/viveksb007))
- Avjeet ([@Avjeet](https://github.com/Avjeet))
- Abhinav ([@abhinavraj23](https://github.com/abhinavraj23))
- Harsh ([@harsh-2711](https://github.com/harsh-2711))
- Yatri ([@yatri1609](https://github.com/yatri1609))

## License

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.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "io.pslab"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 20
versionName "2.0.19"
versionCode 21
versionName "2.0.20"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
android:name=".activity.GasSensorActivity"
android:screenOrientation="portrait" />
<activity android:name=".activity.MapsActivity" />
<activity
android:name=".activity.DustSensorActivity"
android:screenOrientation="portrait"/>

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

Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/io/pslab/CheckBoxGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.pslab;

import java.io.Serializable;

public class CheckBoxGetter implements Serializable {

private String name;
private boolean isSelected;

public CheckBoxGetter(String name, boolean isSelected) {
this.name = name;
this.isSelected = isSelected;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isSelected() {
return isSelected;
}

public void setSelected(boolean selected) {
isSelected = selected;
}
}
35 changes: 19 additions & 16 deletions app/src/main/java/io/pslab/activity/CreateConfigActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
import android.os.Environment;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import io.pslab.CheckBoxGetter;
import io.pslab.R;
import io.pslab.adapters.CheckBoxAdapter;
import io.pslab.others.CSVLogger;
import io.pslab.others.CustomSnackBar;

Expand All @@ -36,7 +38,8 @@ public class CreateConfigActivity extends AppCompatActivity {
private EditText intervalEditText;
private String interval;
private View rootView;
private LinearLayout paramsListContainer;
private RecyclerView paramsListContainer;
private List<CheckBoxGetter> list;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -58,6 +61,8 @@ protected void onCreate(Bundle savedInstanceState) {
instrumentsList = new ArrayList<>();
instrumentParamsList = new ArrayList<>();
instrumentParamsListTitles = new ArrayList<>();
paramsListContainer.setLayoutManager(new LinearLayoutManager(this));
list = new ArrayList<>();
createArrayLists();
selectInstrumentSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, instrumentsList));
selectInstrumentSpinner.setSelection(0, true);
Expand Down Expand Up @@ -97,9 +102,9 @@ public void onClick(View v) {
Toast.makeText(CreateConfigActivity.this, getResources().getString(R.string.no_interval_message), Toast.LENGTH_SHORT).show();
} else {
ArrayList<String> selectedParamsList = new ArrayList<>();
for (int i = 0; i < paramsListContainer.getChildCount(); i ++) {
CheckBox checkBox = (CheckBox) paramsListContainer.getChildAt(i);
if (checkBox.isChecked()) {
for (int i = 0; i < paramsListContainer.getChildCount(); i++) {
boolean checkBox = list.get(i).isSelected();
if (checkBox) {
selectedParamsList.add(instrumentParamsList.get(selectedItem)[i]);
}
}
Expand Down Expand Up @@ -134,17 +139,15 @@ private void createArrayLists() {
}

private void createCheckboxList() {
paramsListContainer.removeAllViews();
list.clear();
String[] params = instrumentParamsListTitles.get(selectedItem);
for (int i = 0; i < params.length; i++){
CheckBox checkBox = new CheckBox(CreateConfigActivity.this);
checkBox.setText(params[i]);
LinearLayout.LayoutParams checkBoxParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
checkBoxParams.gravity = Gravity.CENTER_HORIZONTAL;
checkBoxParams.setMargins(0,(int)getResources().getDimension(R.dimen.create_config_margin1),0,0);
checkBox.setLayoutParams(checkBoxParams);
paramsListContainer.addView(checkBox, i);
for (int i = 0; i < params.length; i++) {
CheckBoxGetter check = new CheckBoxGetter(params[i], false);
list.add(check);
}
CheckBoxAdapter box;
box = new CheckBoxAdapter(CreateConfigActivity.this, list);
paramsListContainer.setAdapter(box);
}

@Override
Expand Down
135 changes: 135 additions & 0 deletions app/src/main/java/io/pslab/activity/DustSensorActivity.java
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);
}
}
}
Loading

0 comments on commit 8bd5fdf

Please sign in to comment.