Skip to content

Commit

Permalink
Fixed timestamp bug in TimeOfDay generator.
Browse files Browse the repository at this point in the history
* Removed latitude distance adjustment for randomized location.
  • Loading branch information
audaciouscode committed Aug 13, 2017
1 parent c743936 commit c185eb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Expand Up @@ -355,7 +355,7 @@ public void onLocationChanged(android.location.Location location) {

double radius = prefs.getLong(Location.ACCURACY_MODE_RANDOMIZED_RANGE, Location.ACCURACY_MODE_RANDOMIZED_RANGE_DEFAULT);

double radiusInDegrees = radius / 111000;
double radiusInDegrees = radius / 111300;

double u = (double) Location.ACCURACY_MODE_RANDOMIZED_VECTOR_DISTANCE_DEFAULT;
double v = (double) Location.ACCURACY_MODE_RANDOMIZED_VECTOR_ANGLE_DEFAULT;
Expand Down Expand Up @@ -388,7 +388,7 @@ public void onLocationChanged(android.location.Location location) {
double y = w * Math.sin(t);

// Adjust the x-coordinate for the shrinking of the east-west distances
longitude = longitude + (x / Math.cos(latitude));
longitude = x + longitude; // + (x / Math.cos(latitude));
latitude = y + latitude;

location.setLongitude(longitude);
Expand Down
Expand Up @@ -294,6 +294,10 @@ public void onLocationChanged(android.location.Location location) {
Calendar sunrise = calculator.getOfficialSunriseCalendarForDate(now);
Calendar sunset = calculator.getOfficialSunsetCalendarForDate(now);

if (sunrise.getTimeInMillis() > sunset.getTimeInMillis()) {
sunset.add(Calendar.DATE, 1);
}

ContentValues values = new ContentValues();
values.put(TimeOfDay.HISTORY_OBSERVED, System.currentTimeMillis());
values.put(TimeOfDay.HISTORY_LATITUDE, location.getLatitude());
Expand Down Expand Up @@ -384,9 +388,9 @@ public int getTimeOfDay() {
return TimeOfDay.TIME_OF_DAY_NIGHT;
} else if (now < noon.getTimeInMillis()) {
return TimeOfDay.TIME_OF_DAY_MORNING;
} else if (now < this.mSunrise - (60 * 60 * 1000)) {
} else if (now < this.mSunset - (60 * 60 * 1000)) {
return TimeOfDay.TIME_OF_DAY_AFTERNOON;
} else if (now < this.mSunrise + (60 * 60 * 1000)) {
} else if (now < this.mSunset + (60 * 60 * 1000)) {
return TimeOfDay.TIME_OF_DAY_EVENING;
}

Expand Down

0 comments on commit c185eb1

Please sign in to comment.