Skip to content

Commit a5f06b5

Browse files
authored
Merge pull request #106 from svvashishtha/fused_location_provider
Use FusedLocationProvider to get gps location.
2 parents bd40a8c + c513510 commit a5f06b5

File tree

11 files changed

+501
-156
lines changed

11 files changed

+501
-156
lines changed

app/src/main/java/com/example/lezh1k/sensordatacollector/MainActivity.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import mad.location.manager.lib.SensorAux.SensorCalibrator;
4444
import mad.location.manager.lib.Services.KalmanLocationService;
4545
import mad.location.manager.lib.Services.ServicesHelper;
46+
import mad.location.manager.lib.Services.Settings;
47+
4648
import com.example.lezh1k.sensordatacollector.Interfaces.MapInterface;
4749
import com.example.lezh1k.sensordatacollector.Presenters.MapPresenter;
4850
import com.mapbox.mapboxsdk.Mapbox;
@@ -179,6 +181,8 @@ private void set_isLogging(boolean isLogging) {
179181
Button btnStartStop = (Button) findViewById(R.id.btnStartStop);
180182
TextView tvStatus = (TextView) findViewById(R.id.tvStatus);
181183
Button btnCalibrate = (Button) findViewById(R.id.btnCalibrate);
184+
Button gpsProvider = (Button) findViewById(R.id.button_gps);
185+
Button fusedProvider = (Button) findViewById(R.id.button_fused);
182186
String btnStartStopText;
183187
String btnTvStatusText;
184188

@@ -188,27 +192,38 @@ private void set_isLogging(boolean isLogging) {
188192
m_presenter.start();
189193
m_geoHashRTFilter.stop();
190194
m_geoHashRTFilter.reset(this);
195+
Settings.LocationProvider provider = Settings.LocationProvider.GPS;
196+
if (gpsProvider.isSelected())
197+
{
198+
provider = Settings.LocationProvider.GPS;
199+
}
200+
else if (fusedProvider.isSelected())
201+
{
202+
provider = Settings.LocationProvider.FUSED;
203+
}
204+
Settings.LocationProvider finalProvider = provider;
191205
ServicesHelper.getLocationService(this, value -> {
192206
if (value.IsRunning()) {
193207
return;
194208
}
195209
value.stop();
196210
initXlogPrintersFileName();
197-
KalmanLocationService.Settings settings =
198-
new KalmanLocationService.Settings(
211+
Settings settings =
212+
new Settings(
199213
Utils.ACCELEROMETER_DEFAULT_DEVIATION,
200-
Integer.parseInt(mSharedPref.getString("pref_gps_min_distance", "")),
201-
Integer.parseInt(mSharedPref.getString("pref_gps_min_time", "")),
202-
Integer.parseInt(mSharedPref.getString("pref_position_min_time", "")),
203-
Integer.parseInt(mSharedPref.getString("pref_geohash_precision", "")),
204-
Integer.parseInt(mSharedPref.getString("pref_geohash_min_point", "")),
205-
Double.parseDouble(mSharedPref.getString("pref_sensor_frequency", "")),
214+
Integer.parseInt(mSharedPref.getString("pref_gps_min_distance", "10")),
215+
Integer.parseInt(mSharedPref.getString("pref_gps_min_time", "2000")),
216+
Integer.parseInt(mSharedPref.getString("pref_position_min_time", "500")),
217+
Integer.parseInt(mSharedPref.getString("pref_geohash_precision", "6")),
218+
Integer.parseInt(mSharedPref.getString("pref_geohash_min_point", "2")),
219+
Double.parseDouble(mSharedPref.getString("pref_sensor_frequency", "10")),
206220
this,
207-
false,
208221
true,
222+
false,
209223
true,
210224
Utils.DEFAULT_VEL_FACTOR,
211-
Utils.DEFAULT_POS_FACTOR
225+
Utils.DEFAULT_POS_FACTOR,
226+
finalProvider
212227
);
213228
value.reset(settings); //warning!! here you can adjust your filter behavior
214229
value.start();
@@ -465,6 +480,23 @@ protected void onCreate(Bundle savedInstanceState) {
465480
} else {
466481
//todo set some status
467482
}
483+
Button gpsProvider = (Button) findViewById(R.id.button_gps);
484+
Button fusedProvider = (Button) findViewById(R.id.button_fused);
485+
gpsProvider.setSelected(true);
486+
gpsProvider.setOnClickListener(new View.OnClickListener() {
487+
@Override
488+
public void onClick(View v) {
489+
fusedProvider.setSelected(false);
490+
gpsProvider.setSelected(true);
491+
}
492+
});
493+
fusedProvider.setOnClickListener(new View.OnClickListener() {
494+
@Override
495+
public void onClick(View v) {
496+
gpsProvider.setSelected(false);
497+
fusedProvider.setSelected(true);
498+
}
499+
});
468500
}
469501

470502
@Override
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:state_checked="true" android:state_pressed="true" android:drawable="@color/colorAccent" />
5+
<item android:state_pressed="true" android:drawable="@color/orange"/>
6+
<item android:state_selected="true" android:drawable="@color/orange"/>
7+
<item android:state_checked="true" android:drawable="@color/green"/>
8+
<item android:drawable="@color/light_grey"/>
9+
</selector>

app/src/main/res/layout/activity_main.xml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,46 @@
3131
app:layout_constraintEnd_toEndOf="parent"
3232
app:layout_constraintStart_toStartOf="parent" />
3333

34+
<TextView
35+
android:layout_width="wrap_content"
36+
app:layout_constraintBottom_toTopOf="@id/button_fused"
37+
app:layout_constraintStart_toStartOf="parent"
38+
android:layout_marginBottom="8dp"
39+
android:layout_marginEnd="8dp"
40+
android:text="@string/location_provider"
41+
android:layout_marginStart="8dp"
42+
android:id="@+id/location_provider_title"
43+
android:textColor="@color/black"
44+
android:layout_marginTop="8dp"
45+
android:layout_height="wrap_content"/>
46+
<Button
47+
android:id="@+id/button_gps"
48+
android:layout_width="0dp"
49+
android:layout_height="wrap_content"
50+
android:layout_marginStart="8dp"
51+
android:layout_marginTop="8dp"
52+
android:layout_marginEnd="8dp"
53+
android:layout_marginBottom="8dp"
54+
android:background="@drawable/button_backgorund"
55+
android:text="@string/gps_provider"
56+
app:layout_constraintBottom_toTopOf="@id/btnStartStop"
57+
app:layout_constraintEnd_toStartOf="@id/button_fused"
58+
app:layout_constraintStart_toStartOf="parent" />
59+
60+
<Button
61+
android:id="@+id/button_fused"
62+
android:layout_width="0dp"
63+
android:background="@drawable/button_backgorund"
64+
android:layout_height="wrap_content"
65+
android:layout_marginStart="8dp"
66+
android:layout_marginTop="8dp"
67+
android:layout_marginEnd="8dp"
68+
android:layout_marginBottom="8dp"
69+
android:text="@string/fused_provider"
70+
app:layout_constraintBottom_toTopOf="@id/btnStartStop"
71+
app:layout_constraintEnd_toEndOf="parent"
72+
app:layout_constraintStart_toEndOf="@id/button_gps" />
73+
3474
<Button
3575
android:id="@+id/btnCalibrate"
3676
android:layout_width="348dp"
@@ -42,7 +82,7 @@
4282
android:onClick="btnCalibrate_click"
4383
android:text="@string/calibrate"
4484
android:visibility="visible"
45-
app:layout_constraintBottom_toTopOf="@+id/btnStartStop"
85+
app:layout_constraintBottom_toTopOf="@+id/location_provider_title"
4686
app:layout_constraintEnd_toEndOf="parent"
4787
app:layout_constraintStart_toStartOf="parent"
4888
app:layout_constraintTop_toBottomOf="@+id/cbFilteredKalman" />

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
<string name="pref_geohash_precision_summ">The length of geohash string (and precision)</string>
2323
<string name="pref_geohash_min_point">GeoHash min point</string>
2424
<string name="pref_geohash_min_point_summ">Count of points with same geohash. GPS point becomes valid only when count greater then this value.</string>
25+
<string name="gps_provider">GPS </string>
26+
<string name="fused_provider">Fused</string>
27+
<string name="location_provider">Location provider</string>
2528
</resources>

madlocationmanager/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies {
4040
api 'androidx.legacy:legacy-support-v4:1.0.0'
4141
api 'com.google.android.material:material:1.2.1'
4242
api 'androidx.recyclerview:recyclerview:1.1.0'
43-
43+
implementation "com.google.android.gms:play-services-location:17.1.0"
4444
testImplementation 'junit:junit:4.13'
4545
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4646
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

0 commit comments

Comments
 (0)