mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Add animation of current location marker on slight move
This commit is contained in:
parent
93eba0e0d5
commit
64503aaa63
2 changed files with 47 additions and 5 deletions
|
|
@ -388,7 +388,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
|||
|
||||
private void updateMapFragment() {
|
||||
getMapFragment().setArguments(bundle);
|
||||
getMapFragment().updateMapViewWithLocationChanges();
|
||||
getMapFragment().updateMapWithLocationChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -415,12 +415,14 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
|
|||
|
||||
@Override
|
||||
public void onLocationChangedSignificantly(LatLng latLng) {
|
||||
refreshView(false, LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED);
|
||||
refreshView(false,
|
||||
LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChangedSlightly(LatLng latLng) {
|
||||
refreshView(false, LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED);
|
||||
refreshView(false,
|
||||
LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED);
|
||||
}
|
||||
|
||||
public void prepareViewsForSheetPosition(int bottomSheetState) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
|
|
@ -78,6 +81,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
|||
|
||||
private Place place;
|
||||
private Marker selected;
|
||||
private MarkerOptions currentLocationMarker;
|
||||
|
||||
public NearbyMapFragment() {
|
||||
}
|
||||
|
|
@ -147,7 +151,26 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
|||
}
|
||||
|
||||
public void updateMapWithLocationChanges() {
|
||||
// Get arguments from bundle for new location
|
||||
Bundle bundle = this.getArguments();
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Uri.class, new UriDeserializer())
|
||||
.create();
|
||||
if (bundle != null) {
|
||||
String gsonLatLng = bundle.getString("CurLatLng");
|
||||
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
|
||||
curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
|
||||
}
|
||||
|
||||
updateMapView();
|
||||
}
|
||||
|
||||
private void updateMapView() {
|
||||
// Change
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(currentLocationMarker, "position",
|
||||
new LatLngEvaluator(), currentLocationMarker.getPosition(), curLatLng);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
|
|
@ -245,7 +268,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
|||
}
|
||||
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
MapboxMapOptions options = new MapboxMapOptions()
|
||||
options = new MapboxMapOptions()
|
||||
.styleUrl(Style.OUTDOORS)
|
||||
.camera(new CameraPosition.Builder()
|
||||
.target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()))
|
||||
|
|
@ -473,4 +496,21 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
|||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private static class LatLngEvaluator implements TypeEvaluator<LatLng> {
|
||||
// Method is used to interpolate the marker animation.
|
||||
|
||||
private LatLng latLng = new LatLng();
|
||||
|
||||
@Override
|
||||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
|
||||
latLng.setLatitude(startValue.getLatitude()
|
||||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
|
||||
latLng.setLongitude(startValue.getLongitude()
|
||||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
|
||||
return latLng;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue