Create handlers for coming in and out from building

This commit is contained in:
Mieszko Wrzeszczyński 2018-12-06 21:32:13 +01:00
parent 5e51be5d0b
commit 0cec17dd16
4 changed files with 23 additions and 29 deletions

View File

@ -3,6 +3,7 @@ package com.uam.wmi.findmytutor.model;
import android.util.Range;
import com.google.gson.annotations.SerializedName;
import com.uam.wmi.findmytutor.utils.Consts;
import java.util.Objects;
import java.util.UUID;
@ -14,8 +15,8 @@ import io.swagger.annotations.ApiModelProperty;
*/
public class Coordinate extends BaseResponse {
Range<Double> latitudeRange = Range.create(52.46598, 52.467545);
Range<Double> longtitudeRange = Range.create(16.926099, 16.927794);
private Range<Double> latitudeRange = Consts.latitudeRange;
private Range<Double> longtitudeRange = Consts.longitudeRange;
@SerializedName("coordinateId")
private UUID coordinateId = null;

View File

@ -63,15 +63,15 @@ public class BackgroundLocalizationService extends Service {
private static final String TAG = "MyLocationService";
private static final int LOCATION_INTERVAL = 1000;
private static final float LOCATION_DISTANCE = 5f;
public static String str_receiver = "background.location.broadcast";
private static long notify_interval = 10000;
private static long notify_interval_inside_building = 10000;
private static long notify_interval_outside_building = 20000;
private static long notify_interval_outside_building = 360000;
//private static long notify_interval_outside_building = 900000;
private CircularFifoQueue<Location> coordinatesHistory = new CircularFifoQueue<Location>(5);
private static int coordinatesHistoryLength = 10;
private CircularFifoQueue<Location> coordinatesHistory = new CircularFifoQueue<Location>(coordinatesHistoryLength);
Location mLastLocation;
Boolean stopService = false;
Intent intent;
ArrayList<String> providers = new ArrayList<String>();
LocationListener[] mLocationListeners;
@ -171,22 +171,27 @@ public class BackgroundLocalizationService extends Service {
private void changeBackgroundMode() {
Predicate<Boolean> p2 = v -> !v;
if(coordinatesHistory.size() > 4){
Boolean shouldExtendTimeInterval = Stream.of(coordinatesHistory)
.map(MapUtils::checkIfCoordinateIsValid).takeWhile( s-> !s).toList().size() == 5;
.map(MapUtils::checkIfCoordinateIsValid).takeWhile( s-> !s).toList().size() == coordinatesHistory.size();
Boolean shouldAbbreviateTimeInterval = Stream.of(coordinatesHistory).
map(MapUtils::checkIfCoordinateIsValid).toList().get(coordinatesHistory.size() -1);
if(shouldExtendTimeInterval){
notify_interval = notify_interval_outside_building;
}else{
}else if (shouldAbbreviateTimeInterval){
notify_interval = notify_interval_inside_building;
}
}
Log.e("COORD_HISTORY", String.valueOf(Stream.of(coordinatesHistory)
.map(MapUtils::checkIfCoordinateIsValid).toList()));
Log.e("COORD_HISTORY", String.valueOf(coordinatesHistory));
Log.e("NEW INTERVAL", String.valueOf(notify_interval));
Log.e("COORD_HISTORY", String.valueOf(Stream.of(coordinatesHistory)
.map(x -> x.getLatitude() + " " + x.getLongitude()).toList()));
Log.e("COORD_NEW INTERVAL", String.valueOf(notify_interval));
}
@ -255,9 +260,6 @@ public class BackgroundLocalizationService extends Service {
Log.e("Best localization:", String.valueOf(bestLocation));
}
}
private void fn_update(Location location) {

View File

@ -7,8 +7,8 @@ public class Consts {
public final static Integer searchMapZoom = 13;
public final static Double presenceLatitude = 52.466365;
public final static Double presenceLongitude = 16.926792;
public final static String presenceApproximatedName = "unknown";
public final static Range<Double> latitudeRange = Range.create(52.466709, 52.467007);
public final static Range<Double> longtitudeRange = Range.create(16.926159, 16.926976);
public final static String presenceApproximatedName = "Unknown";
public final static Range<Double> latitudeRange = Range.create(52.466092, 52.467529);
public final static Range<Double> longitudeRange = Range.create(16.926159, 16.927759);
}

View File

@ -2,30 +2,21 @@ package com.uam.wmi.findmytutor.utils;
import android.animation.TypeEvaluator;
import android.content.Context;
import android.graphics.Color;
import android.location.Location;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.content.res.AssetManager;
import android.util.Log;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.layers.FillLayer;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.uam.wmi.findmytutor.model.Coordinate;
import java.io.IOException;
import java.io.InputStream;
import static com.uam.wmi.findmytutor.utils.Consts.latitudeRange;
import static com.uam.wmi.findmytutor.utils.Consts.longtitudeRange;
import static com.uam.wmi.findmytutor.utils.Consts.longitudeRange;
public class MapUtils {
@ -85,7 +76,7 @@ public class MapUtils {
}
public static Boolean checkIfCoordinateIsValid(Location coordinate){
return (!latitudeRange.contains(coordinate.getLatitude()) && !longtitudeRange.contains(coordinate.getLongitude()));
return latitudeRange.contains(coordinate.getLatitude()) && longitudeRange.contains(coordinate.getLongitude());
}
// Function for marker animation