1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-03 17:02:13 +01:00

Pebble: add toggle to use last known location for sunrise and sunset

This adds the feature discussed in #415, the used location is the last recorded by the network location provider, if it's not available then the stored location is used.
This commit is contained in:
Daniele Gobbetti 2016-11-06 15:42:52 +01:00
parent 119c225ec4
commit 16c4f1a5ca
5 changed files with 35 additions and 0 deletions

View File

@ -1,5 +1,8 @@
###Changelog
####Version next
* Pebble: use the last known location for setting sunrise and sunset
####Version 0.13.8
* Mi Band2: attempt at fixing connection issues for users of Mi Fit (#408, #425)

View File

@ -1,11 +1,17 @@
package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.Manifest;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import net.e175.klaus.solarpositioning.DeltaT;
import net.e175.klaus.solarpositioning.SPA;
@ -64,6 +70,21 @@ public class AlarmReceiver extends BroadcastReceiver {
float latitude = prefs.getFloat("location_latitude", 0);
float longitude = prefs.getFloat("location_longitude", 0);
LOG.info("got longitude/latitude from preferences: " + latitude + "/" + longitude);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
prefs.getBoolean("use_updated_location_if_available", false)) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
if (provider != null) {
Location lastKnownLocation = locationManager.getLastKnownLocation(provider);
if (lastKnownLocation != null) {
latitude = (float) lastKnownLocation.getLatitude();
longitude = (float) lastKnownLocation.getLongitude();
LOG.info("got longitude/latitude from last known location: " + latitude + "/" + longitude);
}
}
}
GregorianCalendar[] sunriseTransitSetTomorrow = SPA.calculateSunriseTransitSet(dateTimeTomorrow, latitude, longitude, DeltaT.estimate(dateTimeTomorrow));
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();

View File

@ -106,6 +106,8 @@
<string name="pref_title_location_aquire">Acquire Location</string>
<string name="pref_title_location_latitude">Latitude</string>
<string name="pref_title_location_longitude">Longitude</string>
<string name="pref_title_location_keep_uptodate">Keep location updated</string>
<string name="pref_summary_location_keep_uptodate">Try to get the current location at runtime, use the stored location as fallback</string>
<string name="toast_enable_networklocationprovider">Please enable network location</string>
<string name="toast_aqurired_networklocation">location acquired</string>

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<changelog>
<release version="next">
<change>Pebble: use the last known location for setting sunrise and sunset</change>
</release>
<release version="0.13.8" versioncode="70">
<change>Mi Band 2: attempt at fixing connection issues for users of Mi Fit</change>
</release>

View File

@ -206,6 +206,12 @@
android:defaultValue="0"
android:key="location_longitude"
android:title="@string/pref_title_location_longitude" />
<CheckBoxPreference
android:defaultValue="true"
android:dependency="location_aquire"
android:key="use_updated_location_if_available"
android:summary="@string/pref_summary_location_keep_uptodate"
android:title="@string/pref_title_location_keep_uptodate" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_header_cannned_messages">