Skip to content

Commit 5d99ff7

Browse files
authored
Merge pull request #1409 from fossasia/development
chore: merge dev into master
2 parents 22557e6 + 62ff44b commit 5d99ff7

21 files changed

+444
-726
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# PSLab Android App
22

33
<a href="https://play.google.com/store/apps/details?id=io.pslab"><img alt="Get it on Google Play" height="80" src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png"></a>
4+
<a href="https://f-droid.org/app/io.pslab"><img alt="Get it on F-Droid" height="80" src="https://f-droid.org/badge/get-it-on.png"></a>
45

56
[![Build Status](https://travis-ci.org/fossasia/pslab-android.svg?branch=development)](https://travis-ci.org/fossasia/pslab-android)
67
[![Gitter](https://badges.gitter.im/fossasia/pslab.svg)](https://gitter.im/fossasia/pslab?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "io.pslab"
99
minSdkVersion rootProject.ext.minSdkVersion
1010
targetSdkVersion rootProject.ext.targetSdkVersion
11-
versionCode 4
12-
versionName "2.0.3"
11+
versionCode 5
12+
versionName "2.0.4"
1313
multiDexEnabled true
1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1515
}

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

+32-44
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
import android.os.Bundle;
1010
import android.os.Handler;
1111
import android.support.annotation.NonNull;
12-
import android.support.design.widget.BottomNavigationView;
1312
import android.support.design.widget.BottomSheetBehavior;
1413
import android.support.design.widget.CoordinatorLayout;
1514
import android.support.v4.app.ActivityCompat;
16-
import android.support.v4.app.Fragment;
1715
import android.support.v4.app.FragmentTransaction;
1816
import android.support.v4.content.ContextCompat;
1917
import android.support.v7.app.AppCompatActivity;
@@ -33,9 +31,8 @@
3331
import butterknife.BindView;
3432
import butterknife.ButterKnife;
3533
import io.pslab.R;
36-
import io.pslab.fragment.LuxMeterFragmentConfig;
3734
import io.pslab.fragment.LuxMeterFragmentData;
38-
import io.pslab.fragment.SettingsFragment;
35+
import io.pslab.fragment.LuxMeterSettingFragment;
3936
import io.pslab.others.CSVLogger;
4037
import io.pslab.others.CustomSnackBar;
4138
import io.pslab.others.GPSLogger;
@@ -58,8 +55,6 @@ public class LuxMeterActivity extends AppCompatActivity {
5855
BottomSheetBehavior bottomSheetBehavior;
5956
GestureDetector gestureDetector;
6057

61-
@BindView(R.id.navigation_lux_meter)
62-
BottomNavigationView bottomNavigationView;
6358
@BindView(R.id.toolbar)
6459
Toolbar toolbar;
6560
@BindView(R.id.cl)
@@ -99,39 +94,11 @@ protected void onCreate(Bundle savedInstanceState) {
9994
tvShadow.setOnClickListener(new View.OnClickListener() {
10095
@Override
10196
public void onClick(View v) {
102-
if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED)
97+
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
10398
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
10499
tvShadow.setVisibility(View.GONE);
105100
}
106101
});
107-
108-
bottomNavigationView.setOnNavigationItemSelectedListener
109-
(new BottomNavigationView.OnNavigationItemSelectedListener() {
110-
@Override
111-
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
112-
Fragment selectedFragment = null;
113-
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.frame_layout_lux_meter);
114-
115-
switch (item.getItemId()) {
116-
case R.id.action_data:
117-
if (!(fragment instanceof LuxMeterFragmentData))
118-
selectedFragment = LuxMeterFragmentData.newInstance();
119-
break;
120-
case R.id.action_config:
121-
if (!(fragment instanceof LuxMeterFragmentConfig))
122-
selectedFragment = LuxMeterFragmentConfig.newInstance();
123-
break;
124-
default:
125-
break;
126-
}
127-
if (selectedFragment != null) {
128-
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
129-
transaction.replace(R.id.frame_layout_lux_meter, selectedFragment, selectedFragment.getTag());
130-
transaction.commit();
131-
}
132-
return true;
133-
}
134-
});
135102
try {
136103
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
137104
selectedFragment = LuxMeterFragmentData.newInstance();
@@ -222,7 +189,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
222189
@Override
223190
public boolean onPrepareOptionsMenu(Menu menu) {
224191
MenuItem item = menu.findItem(R.id.record_data);
225-
item.setIcon(recordData? R.drawable.ic_record_stop_white: R.drawable.ic_record_white);
192+
item.setIcon(recordData ? R.drawable.ic_record_stop_white : R.drawable.ic_record_white);
226193
return super.onPrepareOptionsMenu(menu);
227194
}
228195

@@ -234,7 +201,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
234201
((LuxMeterFragmentData) selectedFragment).stopSensorFetching();
235202
invalidateOptionsMenu();
236203
Long uniqueRef = realmPreferences.getLong("uniqueCount", 0);
237-
selectedFragment.saveDataInRealm(uniqueRef,locationPref,gpsLogger);
204+
selectedFragment.saveDataInRealm(uniqueRef, locationPref, gpsLogger);
238205
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.exp_data_saved), null, null);
239206
SharedPreferences.Editor editor = realmPreferences.edit();
240207
editor.putLong("uniqueCount", uniqueRef + 1);
@@ -246,7 +213,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
246213
if (gpsLogger.isGPSEnabled()) {
247214
recordData = true;
248215
((LuxMeterFragmentData) selectedFragment).startSensorFetching();
249-
CustomSnackBar.showSnackBar(coordinatorLayout,getString(R.string.data_recording_start)+"\n"+getString(R.string.location_enabled) , null, null);
216+
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_enabled), null, null);
250217
invalidateOptionsMenu();
251218
} else {
252219
checkGpsOnResume = true;
@@ -255,7 +222,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
255222
} else {
256223
recordData = true;
257224
((LuxMeterFragmentData) selectedFragment).startSensorFetching();
258-
CustomSnackBar.showSnackBar(coordinatorLayout,getString(R.string.data_recording_start)+"\n"+getString(R.string.location_disabled) , null, null);
225+
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_disabled), null, null);
259226
invalidateOptionsMenu();
260227
}
261228
}
@@ -272,13 +239,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
272239
startActivity(MAP);
273240
break;
274241
case R.id.settings:
275-
startActivity(new Intent(this, SettingsActivity.class));
242+
Intent settingIntent = new Intent(this, SettingsActivity.class);
243+
settingIntent.putExtra("title", "Lux Meter Settings");
244+
startActivity(settingIntent);
276245
break;
277246
case R.id.show_logged_data:
278247
Intent intent = new Intent(this, DataLoggerActivity.class);
279248
intent.putExtra(DataLoggerActivity.CALLER_ACTIVITY, "Lux Meter");
280249
startActivity(intent);
281-
250+
break;
251+
case R.id.show_guide:
252+
bottomSheetBehavior.setState(bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN ?
253+
BottomSheetBehavior.STATE_EXPANDED : BottomSheetBehavior.STATE_HIDDEN);
282254
break;
283255
default:
284256
break;
@@ -289,13 +261,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
289261
@Override
290262
protected void onResume() {
291263
super.onResume();
264+
SharedPreferences sharedPref;
265+
sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
292266
if (checkGpsOnResume) {
293267
if (gpsLogger.isGPSEnabled()) {
294268
recordData = true;
295269
gpsLogger.startFetchingLocation();
296270
((LuxMeterFragmentData) selectedFragment).startSensorFetching();
297271
invalidateOptionsMenu();
298-
CustomSnackBar.showSnackBar(coordinatorLayout,getString(R.string.data_recording_start)+"\n"+getString(R.string.location_enabled) , null, null);
272+
CustomSnackBar.showSnackBar(coordinatorLayout, getString(R.string.data_recording_start) + "\n" + getString(R.string.location_enabled), null, null);
299273
} else {
300274
recordData = false;
301275
Toast.makeText(getApplicationContext(), getString(R.string.gps_not_enabled),
@@ -304,10 +278,13 @@ protected void onResume() {
304278
}
305279
checkGpsOnResume = false;
306280
}
307-
locationPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getBoolean(SettingsFragment.KEY_INCLUDE_LOCATION, false);
308-
if(!locationPref && gpsLogger!=null){
281+
locationPref = sharedPref.getBoolean(LuxMeterSettingFragment.KEY_INCLUDE_LOCATION, false);
282+
if (!locationPref && gpsLogger != null) {
309283
gpsLogger = null;
310284
}
285+
String highLimit = sharedPref.getString(LuxMeterSettingFragment.KEY_HIGH_LIMIT, "2000");
286+
String updatePeriod = sharedPref.getString(LuxMeterSettingFragment.KEY_UPDATE_PERIOD, "1000");
287+
LuxMeterFragmentData.setParameters(getValueFromText(highLimit, 10, 10000), getValueFromText(updatePeriod, 100, 1000));
311288
}
312289

313290
@Override
@@ -318,4 +295,15 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
318295
startActivity(MAP);
319296
}
320297
}
298+
299+
public int getValueFromText(String strValue, int lowerBound, int upperBound) {
300+
301+
if ("".equals(strValue)) {
302+
return lowerBound;
303+
}
304+
int value = Integer.parseInt(strValue);
305+
if (value > upperBound) return upperBound;
306+
else if (value < lowerBound) return lowerBound;
307+
else return value;
308+
}
321309
}

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
import android.widget.TextView;
3030
import android.widget.Toast;
3131

32+
import java.io.IOException;
33+
34+
import butterknife.BindView;
35+
import butterknife.ButterKnife;
3236
import io.pslab.R;
3337
import io.pslab.communication.CommunicationHandler;
3438
import io.pslab.fragment.AboutUsFragment;
@@ -41,11 +45,6 @@
4145
import io.pslab.others.ScienceLabCommon;
4246
import io.pslab.receivers.USBDetachReceiver;
4347

44-
import java.io.IOException;
45-
46-
import butterknife.BindView;
47-
import butterknife.ButterKnife;
48-
4948
import static io.pslab.others.ScienceLabCommon.scienceLab;
5049

5150
public class MainActivity extends AppCompatActivity {
@@ -251,7 +250,9 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
251250
if (drawer != null) {
252251
drawer.closeDrawers();
253252
}
254-
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
253+
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
254+
intent.putExtra("title", "Settings");
255+
startActivity(intent);
255256
return true;
256257
case R.id.nav_about_us:
257258
navItemIndex = 3;

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package io.pslab.activity;
22

3+
import android.content.Intent;
34
import android.content.SharedPreferences;
45
import android.content.pm.PackageManager;
56
import android.os.Bundle;
67
import android.support.annotation.NonNull;
8+
import android.support.v4.app.Fragment;
79
import android.support.v7.app.ActionBar;
810
import android.support.v7.app.AppCompatActivity;
911
import android.support.v7.preference.PreferenceManager;
1012
import android.support.v7.widget.Toolbar;
1113
import android.view.MenuItem;
1214
import android.widget.FrameLayout;
1315

14-
import io.pslab.R;
15-
import io.pslab.fragment.SettingsFragment;
16-
import io.pslab.others.GPSLogger;
17-
1816
import butterknife.BindView;
1917
import butterknife.ButterKnife;
2018
import butterknife.Unbinder;
19+
import io.pslab.R;
20+
import io.pslab.fragment.LuxMeterSettingFragment;
21+
import io.pslab.fragment.SettingsFragment;
22+
import io.pslab.others.GPSLogger;
2123

2224
/**
2325
* Created by Avjeet on 7/7/18.
@@ -37,15 +39,29 @@ protected void onCreate(Bundle savedInstanceState) {
3739
setContentView(R.layout.activity_settings);
3840
unBinder = ButterKnife.bind(this);
3941

42+
Intent intent = getIntent();
43+
String title = intent.getStringExtra("title");
44+
4045
setSupportActionBar(toolbar);
4146
ActionBar actionBar = getSupportActionBar();
4247
if (actionBar != null) {
4348
actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp);
4449
actionBar.setDisplayHomeAsUpEnabled(true);
45-
actionBar.setTitle(R.string.nav_settings);
50+
actionBar.setTitle(title);
4651
}
52+
53+
Fragment fragment;
54+
switch (title) {
55+
case "Lux Meter Settings":
56+
fragment = new LuxMeterSettingFragment();
57+
break;
58+
default:
59+
fragment = new SettingsFragment();
60+
break;
61+
}
62+
4763
if (savedInstanceState == null) {
48-
getSupportFragmentManager().beginTransaction().add(R.id.content, new SettingsFragment()).commit();
64+
getSupportFragmentManager().beginTransaction().add(R.id.content, fragment).commit();
4965
}
5066
}
5167

@@ -70,7 +86,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
7086
if (grantResults.length <= 0
7187
|| grantResults[0] != PackageManager.PERMISSION_GRANTED) {
7288
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).edit();
73-
editor.putBoolean(SettingsFragment.KEY_INCLUDE_LOCATION, false);
89+
editor.putBoolean(LuxMeterSettingFragment.KEY_INCLUDE_LOCATION, false);
7490
editor.commit();
7591
}
7692
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -877,13 +877,15 @@ public void onClick(DialogInterface dialogInterface, int i) {
877877
@Override
878878
public void onClick(View view) {
879879
startActivity(new Intent(WaveGeneratorActivity.this, OscilloscopeActivity.class));
880+
waveDialog.cancel();
880881
}
881882
});
882883

883884
dialogView.findViewById(R.id.la_btn).setOnClickListener(new View.OnClickListener() {
884885
@Override
885886
public void onClick(View view) {
886887
startActivity(new Intent(WaveGeneratorActivity.this, LogicalAnalyzerActivity.class));
888+
waveDialog.cancel();
887889
}
888890
});
889891

0 commit comments

Comments
 (0)