Animated markers, need to customize behavior on newTimeStamp
This commit is contained in:
parent
ca26b03d49
commit
c67d4ba4c8
@ -25,6 +25,7 @@ import com.uam.wmi.findmytutor.network.RetrofitClientInstance;
|
|||||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -39,8 +40,8 @@ import io.reactivex.schedulers.Schedulers;
|
|||||||
public class MapActivity extends BaseActivity
|
public class MapActivity extends BaseActivity
|
||||||
implements OnMapReadyCallback {
|
implements OnMapReadyCallback {
|
||||||
|
|
||||||
|
String tag = getClass().getName();
|
||||||
|
|
||||||
String tag = "LifeCycleEvents";
|
|
||||||
|
|
||||||
|
|
||||||
private MapView mapView;
|
private MapView mapView;
|
||||||
@ -48,7 +49,9 @@ public class MapActivity extends BaseActivity
|
|||||||
private int mInterval = 10000;
|
private int mInterval = 10000;
|
||||||
private Handler mHandler;
|
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 CoordinateService coordinateService;
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
@ -56,9 +59,6 @@ public class MapActivity extends BaseActivity
|
|||||||
private Runnable mStatusChecker;
|
private Runnable mStatusChecker;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -136,42 +136,48 @@ public class MapActivity extends BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<Coordinate> coordsList) {
|
public void onSuccess(List<Coordinate> coordsList) {
|
||||||
|
|
||||||
|
Log.e(tag, "");
|
||||||
|
|
||||||
for (Coordinate element : coordsList) {
|
for (Coordinate element : coordsList) {
|
||||||
String id = element.getUserId();
|
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());
|
if (coordinate != null) {
|
||||||
Log.d("mapper", "b " + coordsMap.size());
|
Log.e(tag, "Coordin: " + coordinate.getLatitude()+" | " + coordinate.getLongitude());
|
||||||
if (cord != null) {
|
// Log.e(tag, "Element: " + element.getLatitude()+" | " + element.getLongitude());
|
||||||
if (!cord.getLongitude().equals(element.getLongitude())
|
// Log.e(tag, "isEqual: " + coordinate.getLatitude().equals(element.getLatitude()));
|
||||||
) {
|
// Log.e(tag, "isEqual: " + coordinate.getLongitude().equals(element.getLongitude()));
|
||||||
Log.d("mapper", " cos sie zienilo ");
|
boolean statement = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
|
||||||
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
|
||||||
.title(cord.getUserId())
|
|
||||||
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
|
|
||||||
|
|
||||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
Log.e(tag, "diff || diff: " + !statement);
|
||||||
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
|
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.setDuration(2000);
|
||||||
markerAnimator.start();
|
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 {
|
} else {
|
||||||
|
Log.e(tag, "Marker Added: " + id);
|
||||||
coordsMap.put(id, element);
|
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
|
// Add the mapView lifecycle to the activity's lifecycle methods
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
Loading…
Reference in New Issue
Block a user