summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun Van Nuland <tobrun.van.nuland@gmail.com>2017-08-07 13:05:30 +0200
committerTobrun Van Nuland <tobrun.van.nuland@gmail.com>2017-08-07 13:50:30 +0200
commit8593e39cecf4d3cdb24042de49ffec229a7997e7 (patch)
tree68926507f656e3875c1dfaa815c838f37ee1c0eb
parent466728b441308de4bb0579d8b871c587607c76ae (diff)
downloadqtlocation-mapboxgl-upstream/9682-infowindow-update.tar.gz
[andriod] - post updating InfoWinw update for Dynamic InfoWindowAdapter exampleupstream/9682-infowindow-update
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java26
1 files changed, 14 insertions, 12 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java
index e8525b6a62..7fa4792a38 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java
@@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.testapp.activity.infowindow;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
@@ -28,11 +27,11 @@ import java.util.Locale;
*/
public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implements OnMapReadyCallback {
+ private static final LatLng PARIS = new LatLng(48.864716, 2.349014);
+
private MapboxMap mapboxMap;
private MapView mapView;
- private LatLng paris = new LatLng(48.864716, 2.349014);
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -45,7 +44,6 @@ public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implemen
@Override
public void onMapReady(MapboxMap map) {
-
mapboxMap = map;
// Add info window adapter
@@ -66,27 +64,32 @@ public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implemen
double distanceKm = marker.getPosition().distanceTo(point) / 1000;
// Get the info window
- InfoWindow infoWindow = marker.getInfoWindow();
+ final InfoWindow infoWindow = marker.getInfoWindow();
// Get the view from the info window
if (infoWindow != null && infoWindow.getView() != null) {
// Set the new text on the text view in the info window
- ((TextView) infoWindow.getView()).setText(String.format(Locale.getDefault(), "%.2fkm", distanceKm));
-
- // Update the info window position (as the text length changes)
- infoWindow.update();
+ TextView textView = (TextView) infoWindow.getView();
+ textView.setText(String.format(Locale.getDefault(), "%.2fkm", distanceKm));
+ textView.post(new Runnable() {
+ @Override
+ public void run() {
+ // Update the info window position (as the text length changes)
+ infoWindow.update();
+ }
+ });
}
}
});
// Focus on Paris
- mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(paris));
+ mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(PARIS));
}
private MarkerView addMarker(MapboxMap mapboxMap) {
return mapboxMap.addMarker(
new MarkerViewOptions()
- .position(paris)
+ .position(PARIS)
.icon(IconUtils.drawableToIcon(this, R.drawable.ic_location_city,
ResourcesCompat.getColor(getResources(), R.color.mapbox_blue, getTheme()))
));
@@ -96,7 +99,6 @@ public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implemen
final int padding = (int) getResources().getDimension(R.dimen.attr_margin);
mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
- @Nullable
@Override
public View getInfoWindow(@NonNull Marker marker) {
TextView textView = new TextView(DynamicInfoWindowAdapterActivity.this);