Skip to content

Commit 7a18caa

Browse files
ZahnstocherBinnette
authored andcommitted
display number of satellites (Fix #442)
1 parent 211580a commit 7a18caa

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

app/src/main/java/net/osmtracker/layout/GpsStatusRecord.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.Manifest;
1010
import android.content.Context;
1111
import android.content.pm.PackageManager;
12+
import android.location.GnssStatus;
1213
import android.location.Location;
1314
import android.location.LocationListener;
1415
import android.location.LocationManager;
@@ -114,15 +115,42 @@ public void requestLocationUpdates(boolean request) {
114115
if (request) {
115116
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
116117
lmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
118+
lmgr.registerGnssStatusCallback(mStatusCallback);
117119
} else {
118120
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
119121
REQUEST_CODE_GPS_PERMISSIONS);
120122
}
121123
} else {
122124
lmgr.removeUpdates(this);
125+
lmgr.unregisterGnssStatusCallback(mStatusCallback);
123126
}
124127
}
125128

129+
private GnssStatus.Callback mStatusCallback = new GnssStatus.Callback() {
130+
@Override
131+
public void onSatelliteStatusChanged(GnssStatus status) {
132+
satCount = status.getSatelliteCount();
133+
fixCount = 0;
134+
135+
for (int i = 0; i < satCount; i++) {
136+
if (status.usedInFix(i)) {
137+
fixCount++;
138+
}
139+
}
140+
141+
if (fixCount == 0) {
142+
TextView tvAccuracy = findViewById(R.id.gpsstatus_record_tvAccuracy);
143+
tvAccuracy.setText(getResources().getString(R.string.various_waiting_gps_fix)
144+
.replace("{0}", Long.toString(fixCount))
145+
.replace("{1}", Long.toString(satCount)));
146+
147+
((ImageView) findViewById(R.id.gpsstatus_record_imgSatIndicator)).setImageResource(R.drawable.sat_indicator_unknown);
148+
}
149+
150+
Log.v(TAG, "Found " + satCount + " satellites. " + fixCount + " used in fix.");
151+
}
152+
};
153+
126154
@Override
127155
public void onLocationChanged(Location location) {
128156
// first of all we check if the time from the last used fix to the current fix is greater than the logging interval
@@ -136,20 +164,14 @@ public void onLocationChanged(Location location) {
136164
manageRecordingIndicator(true);
137165
}
138166

139-
//TODO: get number of satellites used and visible.
140-
//Log.v(TAG, "Found " + satCount + " satellites. " + fixCount + " used in fix.
141-
142167
TextView tvAccuracy = findViewById(R.id.gpsstatus_record_tvAccuracy);
143168
if (location.hasAccuracy()) {
144169
Log.d(TAG, "location accuracy: "+ ACCURACY_FORMAT.format(location.getAccuracy()));
145170
tvAccuracy.setText(getResources().getString(R.string.various_accuracy_with_sats)
146171
.replace("{0}", ACCURACY_FORMAT.format(location.getAccuracy()))
147172
.replace("{1}", getResources().getString(R.string.various_unit_meters))
148-
//TODO: use the number of satellites used and visible
149-
//.replace("{2}", Long.toString(fixCount))
150-
//.replace("{3}", Long.toString(satCount)));
151-
.replace("{2}", "?")
152-
.replace("{3}", "?"));
173+
.replace("{2}", Long.toString(fixCount))
174+
.replace("{3}", Long.toString(satCount)));
153175

154176
manageSatelliteStatusIndicator((int) location.getAccuracy());
155177

0 commit comments

Comments
 (0)