Animated markers, need to customize behavior on newTimeStamp

This commit is contained in:
Adam Domagalski 2018-10-31 01:13:05 +01:00
parent ca26b03d49
commit c67d4ba4c8

View File

@ -25,6 +25,7 @@ import com.uam.wmi.findmytutor.network.RetrofitClientInstance;
import com.uam.wmi.findmytutor.service.CoordinateService;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -39,8 +40,8 @@ import io.reactivex.schedulers.Schedulers;
public class MapActivity extends BaseActivity
implements OnMapReadyCallback {
String tag = getClass().getName();
String tag = "LifeCycleEvents";
private MapView mapView;
@ -48,7 +49,9 @@ public class MapActivity extends BaseActivity
private int mInterval = 10000;
private Handler mHandler;
private Map<String,Coordinate> coordsMap = new HashMap<>();
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
private HashMap<String, Marker> markerHash = new HashMap<>();
private CoordinateService coordinateService;
private CompositeDisposable disposable = new CompositeDisposable();
@ -56,9 +59,6 @@ public class MapActivity extends BaseActivity
private Runnable mStatusChecker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -136,42 +136,48 @@ public class MapActivity extends BaseActivity
@Override
public void onSuccess(List<Coordinate> coordsList) {
Log.e(tag, "");
for (Coordinate element : coordsList) {
String id = element.getUserId();
Coordinate cord = coordsMap.get(id);
Coordinate coordinate = coordsMap.get(id);
Log.e(tag, "hashMapSize: "+ coordsMap.size());
Log.e(tag, "markerMapSize: "+ coordsMap.size());
Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
Log.d("mapper", "b " + coordsMap.size());
if (cord != null) {
if (!cord.getLongitude().equals(element.getLongitude())
) {
Log.d("mapper", " cos sie zienilo ");
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
.title(cord.getUserId())
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
if (coordinate != null) {
Log.e(tag, "Coordin: " + coordinate.getLatitude()+" | " + coordinate.getLongitude());
// Log.e(tag, "Element: " + element.getLatitude()+" | " + element.getLongitude());
// Log.e(tag, "isEqual: " + coordinate.getLatitude().equals(element.getLatitude()));
// Log.e(tag, "isEqual: " + coordinate.getLongitude().equals(element.getLongitude()));
boolean statement = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
Log.e(tag, "diff || diff: " + !statement);
if (!statement) {
Log.e(tag, "replace and animate");
ValueAnimator markerAnimator = ObjectAnimator.ofObject(markerHash.get(id), "position",
new LatLngEvaluator(), markerHash.get(id).getPosition(),
new LatLng(element.getLatitude(), element.getLongitude()));
markerAnimator.setDuration(2000);
markerAnimator.start();
coordsMap.put(id, element);
markerHash.get(id).setPosition(new LatLng(element.getLatitude(), element.getLongitude()));
} else if(!coordinate.getTimeStamp().equals(element.getTimeStamp())) {
Log.e(tag, "timestamp changed");
// coordsMap.replace(id,element);
coordsMap.remove(id);
coordsMap.put(id,element);
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
Log.d("mapper", "update");
Log.d("mapper", " "+cord.getTimeStamp());
Log.d("mapper", " " + element.getTimeStamp());
// coordsMap.replace(id,element);
coordsMap.remove(id);
coordsMap.put(id,element);
}
} else {
Log.e(tag, "Marker Added: " + id);
coordsMap.put(id, element);
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
Marker marker = mapboxMap.addMarker(new MarkerOptions()
.title(element.getLabel())
.position(new LatLng(element.getLatitude(), element.getLongitude())));
markerHash.put(id, marker);
}
}
}
@ -203,7 +209,6 @@ public class MapActivity extends BaseActivity
}
// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {