use of org.eyeseetea.malariacare.layout.listeners.SurveyLocationListener in project pictureapp by EyeSeeTea.
the class ADashboardActivityStrategy method prepareLocationListener.
public void prepareLocationListener(Activity activity, Survey survey) {
SurveyLocationListener locationListener = new SurveyLocationListener(survey.getId_survey());
LocationManager locationManager = (LocationManager) LocationMemory.getContext().getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
Log.d(TAG, "requestLocationUpdates via NETWORK");
if (ActivityCompat.checkSelfPermission(activity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(activity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
} else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.d(TAG, "requestLocationUpdates via GPS");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
} else {
Location lastLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (lastLocation != null) {
Log.d(TAG, "location not available via GPS|NETWORK, last know: " + lastLocation);
locationListener.saveLocation(lastLocation);
} else {
String defaultLatitude = activity.getString(R.string.GPS_LATITUDE_DEFAULT);
String defaultLongitude = activity.getString(R.string.GPS_LONGITUDE_DEFAULT);
Location defaultLocation = new Location(activity.getString(R.string.GPS_PROVIDER_DEFAULT));
defaultLocation.setLatitude(Double.parseDouble(defaultLatitude));
defaultLocation.setLongitude(Double.parseDouble(defaultLongitude));
Log.d(TAG, "location not available via GPS|NETWORK, default: " + defaultLocation);
locationListener.saveLocation(defaultLocation);
}
}
}
Aggregations