9
9
import android .os .Bundle ;
10
10
import android .os .Handler ;
11
11
import android .support .annotation .NonNull ;
12
- import android .support .design .widget .BottomNavigationView ;
13
12
import android .support .design .widget .BottomSheetBehavior ;
14
13
import android .support .design .widget .CoordinatorLayout ;
15
14
import android .support .v4 .app .ActivityCompat ;
16
- import android .support .v4 .app .Fragment ;
17
15
import android .support .v4 .app .FragmentTransaction ;
18
16
import android .support .v4 .content .ContextCompat ;
19
17
import android .support .v7 .app .AppCompatActivity ;
33
31
import butterknife .BindView ;
34
32
import butterknife .ButterKnife ;
35
33
import io .pslab .R ;
36
- import io .pslab .fragment .LuxMeterFragmentConfig ;
37
34
import io .pslab .fragment .LuxMeterFragmentData ;
38
- import io .pslab .fragment .SettingsFragment ;
35
+ import io .pslab .fragment .LuxMeterSettingFragment ;
39
36
import io .pslab .others .CSVLogger ;
40
37
import io .pslab .others .CustomSnackBar ;
41
38
import io .pslab .others .GPSLogger ;
@@ -58,8 +55,6 @@ public class LuxMeterActivity extends AppCompatActivity {
58
55
BottomSheetBehavior bottomSheetBehavior ;
59
56
GestureDetector gestureDetector ;
60
57
61
- @ BindView (R .id .navigation_lux_meter )
62
- BottomNavigationView bottomNavigationView ;
63
58
@ BindView (R .id .toolbar )
64
59
Toolbar toolbar ;
65
60
@ BindView (R .id .cl )
@@ -99,39 +94,11 @@ protected void onCreate(Bundle savedInstanceState) {
99
94
tvShadow .setOnClickListener (new View .OnClickListener () {
100
95
@ Override
101
96
public void onClick (View v ) {
102
- if (bottomSheetBehavior .getState ()== BottomSheetBehavior .STATE_EXPANDED )
97
+ if (bottomSheetBehavior .getState () == BottomSheetBehavior .STATE_EXPANDED )
103
98
bottomSheetBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
104
99
tvShadow .setVisibility (View .GONE );
105
100
}
106
101
});
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
- });
135
102
try {
136
103
FragmentTransaction transaction = getSupportFragmentManager ().beginTransaction ();
137
104
selectedFragment = LuxMeterFragmentData .newInstance ();
@@ -222,7 +189,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
222
189
@ Override
223
190
public boolean onPrepareOptionsMenu (Menu menu ) {
224
191
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 );
226
193
return super .onPrepareOptionsMenu (menu );
227
194
}
228
195
@@ -234,7 +201,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
234
201
((LuxMeterFragmentData ) selectedFragment ).stopSensorFetching ();
235
202
invalidateOptionsMenu ();
236
203
Long uniqueRef = realmPreferences .getLong ("uniqueCount" , 0 );
237
- selectedFragment .saveDataInRealm (uniqueRef ,locationPref ,gpsLogger );
204
+ selectedFragment .saveDataInRealm (uniqueRef , locationPref , gpsLogger );
238
205
CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .exp_data_saved ), null , null );
239
206
SharedPreferences .Editor editor = realmPreferences .edit ();
240
207
editor .putLong ("uniqueCount" , uniqueRef + 1 );
@@ -246,7 +213,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
246
213
if (gpsLogger .isGPSEnabled ()) {
247
214
recordData = true ;
248
215
((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 );
250
217
invalidateOptionsMenu ();
251
218
} else {
252
219
checkGpsOnResume = true ;
@@ -255,7 +222,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
255
222
} else {
256
223
recordData = true ;
257
224
((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 );
259
226
invalidateOptionsMenu ();
260
227
}
261
228
}
@@ -272,13 +239,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
272
239
startActivity (MAP );
273
240
break ;
274
241
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 );
276
245
break ;
277
246
case R .id .show_logged_data :
278
247
Intent intent = new Intent (this , DataLoggerActivity .class );
279
248
intent .putExtra (DataLoggerActivity .CALLER_ACTIVITY , "Lux Meter" );
280
249
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 );
282
254
break ;
283
255
default :
284
256
break ;
@@ -289,13 +261,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
289
261
@ Override
290
262
protected void onResume () {
291
263
super .onResume ();
264
+ SharedPreferences sharedPref ;
265
+ sharedPref = PreferenceManager .getDefaultSharedPreferences (getBaseContext ());
292
266
if (checkGpsOnResume ) {
293
267
if (gpsLogger .isGPSEnabled ()) {
294
268
recordData = true ;
295
269
gpsLogger .startFetchingLocation ();
296
270
((LuxMeterFragmentData ) selectedFragment ).startSensorFetching ();
297
271
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 );
299
273
} else {
300
274
recordData = false ;
301
275
Toast .makeText (getApplicationContext (), getString (R .string .gps_not_enabled ),
@@ -304,10 +278,13 @@ protected void onResume() {
304
278
}
305
279
checkGpsOnResume = false ;
306
280
}
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 ) {
309
283
gpsLogger = null ;
310
284
}
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 ));
311
288
}
312
289
313
290
@ Override
@@ -318,4 +295,15 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
318
295
startActivity (MAP );
319
296
}
320
297
}
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
+ }
321
309
}
0 commit comments