diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-08-17 08:53:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-17 08:53:33 +0200 |
commit | fff0ebaa1754aabd9584c994624b7b948bec95af (patch) | |
tree | 745006b1a761856e6651738cd7d26e0e08c6cbbf /platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp | |
parent | 0062cf2f949fe1b0080e2de45aaf0b3d5e028bf3 (diff) | |
download | qtlocation-mapboxgl-fff0ebaa1754aabd9584c994624b7b948bec95af.tar.gz |
5859 generate sanity tests (#5870)
* [android] #5859 - generate espresso tests
[android] #5859 - cleanup xml files, use all the same resource id for map view
[android] #5859 - update scripts
[android] #5859 - update Activity to match mapboxMap naming
[android] #5859 - make SurfaceViewMediaControlActivity compatible
[android] #5859 - make MarkerViewScaleActivity test generation compatible
[android] #5859 - make PolygonActivity test generation compatible
[android] #5859 - integration within make file
[android] #5859 - made CameraPostion generation safe
[android] #5859 - generate sanity test
[android] #5859 - add generated test cases
[android] #5859 - add documentation
* [android] #5859 - remove generated files, introduce gen package, added gitignore to package
* [android] #5859 - regenerated test code
* [android] #5859 - added AWS gradle plugin + bitrise configuration
* [android] #5859 - fixes running locally without having the properties configured
* [android] #6010 - remove python from android sdk
* [android] #5859 - update docs about aws gradle plugin
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp')
29 files changed, 508 insertions, 437 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java index c06e58dc26..282ac9b18c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/AnimatedMarkerActivity.java @@ -32,7 +32,7 @@ import java.util.Random; public class AnimatedMarkerActivity extends AppCompatActivity { private MapView mMapView; - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; private LatLng dupontCircle = new LatLng(38.90962, -77.04341); @@ -59,9 +59,9 @@ public class AnimatedMarkerActivity extends AppCompatActivity { @Override public void onMapReady(@NonNull final MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + AnimatedMarkerActivity.this.mapboxMap = mapboxMap; setupMap(); - + for (int i = 0; i < 10; i++) { addRandomCar(); } @@ -78,7 +78,7 @@ public class AnimatedMarkerActivity extends AppCompatActivity { .target(dupontCircle) .zoom(15) .build(); - mMapboxMap.setCameraPosition(cameraPosition); + mapboxMap.setCameraPosition(cameraPosition); } private void addPassenger() { @@ -87,7 +87,7 @@ public class AnimatedMarkerActivity extends AppCompatActivity { if (passengerMarker == null) { Icon icon = IconFactory.getInstance(AnimatedMarkerActivity.this) .fromResource(R.drawable.ic_directions_run_black_24dp); - passengerMarker = mMapboxMap.addMarker(new MarkerViewOptions() + passengerMarker = mapboxMap.addMarker(new MarkerViewOptions() .position(randomLatLng) .icon(icon)); } else { @@ -105,7 +105,7 @@ public class AnimatedMarkerActivity extends AppCompatActivity { } // Make sure the car marker is selected so that it's always brought to the front (#5285) - mMapboxMap.selectMarker(carMarker); + mapboxMap.selectMarker(carMarker); } private void animateMoveToPassenger(final MarkerView car) { @@ -154,19 +154,19 @@ public class AnimatedMarkerActivity extends AppCompatActivity { .fromResource(carResource); //View Markers - return mMapboxMap.addMarker(new MarkerViewOptions() + return mapboxMap.addMarker(new MarkerViewOptions() .position(start) .icon(icon)); //GL Markers -// return mMapboxMap.addMarker(new MarkerOptions() +// return mapboxMap.addMarker(new MarkerOptions() // .position(start) // .icon(icon)); } private LatLng getLatLngInBounds() { - LatLngBounds bounds = mMapboxMap.getProjection().getVisibleRegion().latLngBounds; + LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds; Random generator = new Random(); double randomLat = bounds.getLatSouth() + generator.nextDouble() * (bounds.getLatNorth() - bounds.getLatSouth()); double randomLon = bounds.getLonWest() + generator.nextDouble() * (bounds.getLonEast() - bounds.getLonWest()); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java index e4bf383c96..f49407626d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/BulkMarkerActivity.java @@ -43,7 +43,7 @@ import java.util.Random; public class BulkMarkerActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; private MapView mMapView; private boolean mCustomMarkerView; private List<LatLng> mLocations; @@ -68,7 +68,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + BulkMarkerActivity.this.mapboxMap = mapboxMap; if (actionBar != null) { ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item); @@ -102,7 +102,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView } private void showMarkers(int amount) { - mMapboxMap.clear(); + mapboxMap.clear(); if (mLocations.size() < amount) { amount = mLocations.size(); @@ -128,7 +128,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView for (int i = 0; i < amount; i++) { randomIndex = random.nextInt(mLocations.size()); LatLng latLng = mLocations.get(randomIndex); - mMapboxMap.addMarker(new MarkerViewOptions() + mapboxMap.addMarker(new MarkerViewOptions() .position(latLng) .icon(icon) .title(String.valueOf(i)) @@ -151,7 +151,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView .snippet(formatter.format(latLng.getLatitude()) + ", " + formatter.format(latLng.getLongitude()))); } - mMapboxMap.addMarkers(markerOptionsList); + mapboxMap.addMarkers(markerOptionsList); } @Override @@ -203,7 +203,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView private class FabClickListener implements View.OnClickListener { @Override public void onClick(final View v) { - if (mMapboxMap != null) { + if (mapboxMap != null) { mCustomMarkerView = true; // remove fab @@ -226,7 +226,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView @Override public void onMapChanged(@MapView.MapChange int change) { if (change == MapView.REGION_IS_CHANGING || change == MapView.REGION_DID_CHANGE) { - if (!mMapboxMap.getMarkerViewManager().getMarkerViewAdapters().isEmpty()) { + if (!mapboxMap.getMarkerViewManager().getMarkerViewAdapters().isEmpty()) { TextView viewCountView = (TextView) findViewById(R.id.countView); viewCountView.setText("ViewCache size " + (mMapView.getChildCount() - 5)); } @@ -234,7 +234,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView } }); - mMapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() { + mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() { @Override public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) { Toast.makeText(BulkMarkerActivity.this, "Hello " + marker.getId(), Toast.LENGTH_SHORT).show(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java index 0c4eeae5ad..ce86a78099 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewActivity.java @@ -5,7 +5,6 @@ import android.animation.AnimatorInflater; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.content.Context; -import android.graphics.PointF; import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; @@ -42,7 +41,7 @@ import java.util.Random; public class MarkerViewActivity extends AppCompatActivity { - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; private MapView mMapView; private MarkerView movingMarkerOne, movingMarkerTwo; @@ -80,7 +79,7 @@ public class MarkerViewActivity extends AppCompatActivity { mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + MarkerViewActivity.this.mapboxMap = mapboxMap; final MarkerViewManager markerViewManager = mapboxMap.getMarkerViewManager(); @@ -89,7 +88,7 @@ public class MarkerViewActivity extends AppCompatActivity { // add default ViewMarker markers for (int i = 0; i < LAT_LNGS.length; i++) { - mMapboxMap.addMarker(new MarkerViewOptions() + MarkerViewActivity.this.mapboxMap.addMarker(new MarkerViewOptions() .position(LAT_LNGS[i]) .title(String.valueOf(i)) .alpha(0.5f) @@ -106,22 +105,22 @@ public class MarkerViewActivity extends AppCompatActivity { options.flat(true); mapboxMap.addMarker(options); - mMapboxMap.addMarker(new MarkerOptions() + MarkerViewActivity.this.mapboxMap.addMarker(new MarkerOptions() .title("United States") .position(new LatLng(38.902580, -77.050102)) ); - mMapboxMap.addMarker(new TextMarkerViewOptions() + MarkerViewActivity.this.mapboxMap.addMarker(new TextMarkerViewOptions() .text("A") .position(new LatLng(38.889876, -77.008849)) ); - mMapboxMap.addMarker(new TextMarkerViewOptions() + MarkerViewActivity.this.mapboxMap.addMarker(new TextMarkerViewOptions() .text("B") .position(new LatLng(38.907327, -77.041293)) ); - mMapboxMap.addMarker(new TextMarkerViewOptions() + MarkerViewActivity.this.mapboxMap.addMarker(new TextMarkerViewOptions() .text("C") .position(new LatLng(38.897642, -77.041980)) ); @@ -144,7 +143,7 @@ public class MarkerViewActivity extends AppCompatActivity { }); // add a OnMarkerView click listener - mMapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() { + MarkerViewActivity.this.mapboxMap.getMarkerViewManager().setOnMarkerViewClickListener(new MapboxMap.OnMarkerViewClickListener() { @Override public boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MapboxMap.MarkerViewAdapter adapter) { Toast.makeText(MarkerViewActivity.this, "Hello " + marker.getId(), Toast.LENGTH_SHORT).show(); @@ -152,7 +151,7 @@ public class MarkerViewActivity extends AppCompatActivity { } }); - movingMarkerOne = mMapboxMap.addMarker(new MarkerViewOptions() + movingMarkerOne = MarkerViewActivity.this.mapboxMap.addMarker(new MarkerViewOptions() .position(CarLocation.CAR_0_LNGS[0]) .icon(IconFactory.getInstance(mMapView.getContext()) .fromResource(R.drawable.ic_chelsea)) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewScaleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewScaleActivity.java index 37b1d32a68..bd183b9ab9 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewScaleActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/MarkerViewScaleActivity.java @@ -21,10 +21,11 @@ import com.mapbox.mapboxsdk.testapp.R; import java.util.Locale; -public class MarkerViewScaleActivity extends AppCompatActivity { +public class MarkerViewScaleActivity extends AppCompatActivity implements OnMapReadyCallback { - private MapView mMapView; - private View mMarkerView; + private MapboxMap mapboxMap; + private MapView mapView; + private View markerView; @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,22 +45,23 @@ public class MarkerViewScaleActivity extends AppCompatActivity { TextView xText = (TextView) findViewById(R.id.textview_factor); xBar.setOnSeekBarChangeListener(new FactorChangeListener(xText)); - mMapView = (MapView) findViewById(R.id.mapView); - mMapView.onCreate(savedInstanceState); - mMapView.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(MapboxMap mapboxMap) { - Icon icon = IconFactory.getInstance(MarkerViewScaleActivity.this) - .fromResource(R.drawable.ic_circle); + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } - MarkerView mMarker = mapboxMap.addMarker(new MarkerViewOptions() - .position(new LatLng(38.907192, -77.036871)) - .icon(icon) - .flat(true)); + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + Icon icon = IconFactory.getInstance(MarkerViewScaleActivity.this) + .fromResource(R.drawable.ic_circle); - mMarkerView = mapboxMap.getMarkerViewManager().getView(mMarker); - } - }); + MarkerView mMarker = mapboxMap.addMarker(new MarkerViewOptions() + .position(new LatLng(38.907192, -77.036871)) + .icon(icon) + .flat(true)); + + markerView = mapboxMap.getMarkerViewManager().getView(mMarker); } @Override @@ -76,31 +78,31 @@ public class MarkerViewScaleActivity extends AppCompatActivity { @Override public void onResume() { super.onResume(); - mMapView.onResume(); + mapView.onResume(); } @Override public void onPause() { super.onPause(); - mMapView.onPause(); + mapView.onPause(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mMapView.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); } @Override protected void onDestroy() { super.onDestroy(); - mMapView.onDestroy(); + mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); - mMapView.onLowMemory(); + mapView.onLowMemory(); } private class FactorChangeListener implements SeekBar.OnSeekBarChangeListener { @@ -115,10 +117,9 @@ public class MarkerViewScaleActivity extends AppCompatActivity { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { float newScale = getScale(progress); xText.setText(String.format(Locale.US, "Scale: %.1f", newScale)); - if (MarkerViewScaleActivity.this.mMarkerView != null) { - mMarkerView.setScaleX(newScale); - mMarkerView.setScaleY(newScale); - + if (MarkerViewScaleActivity.this.markerView != null) { + markerView.setScaleX(newScale); + markerView.setScaleY(newScale); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java index 9f3940bd3f..e4dbaf54db 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java @@ -23,7 +23,7 @@ import com.mapbox.mapboxsdk.testapp.R; import java.util.ArrayList; import java.util.List; -public class PolygonActivity extends AppCompatActivity { +public class PolygonActivity extends AppCompatActivity implements OnMapReadyCallback { private static final int BLUE_COLOR = Color.parseColor("#3bb2d0"); private static final int RED_COLOR = Color.parseColor("#AF0000"); @@ -52,6 +52,7 @@ public class PolygonActivity extends AppCompatActivity { }}; private MapView mapView; + private MapboxMap mapboxMap; private Polygon polygon; private boolean fullAlpha = true; @@ -85,22 +86,24 @@ public class PolygonActivity extends AppCompatActivity { // create map mapView = new MapView(this, options); + mapView.setId(R.id.mapView); mapView.onCreate(savedInstanceState); - mapView.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(MapboxMap mapboxMap) { - POINTS.addAll(ADDITIONAL_POINTS); - polygon = mapboxMap.addPolygon(new PolygonOptions() - .addAll(POINTS) - .fillColor(BLUE_COLOR)); - } - }); + mapView.getMapAsync(this); // add to layout ((ViewGroup) findViewById(R.id.container)).addView(mapView); } @Override + public void onMapReady(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + POINTS.addAll(ADDITIONAL_POINTS); + polygon = mapboxMap.addPolygon(new PolygonOptions() + .addAll(POINTS) + .fillColor(BLUE_COLOR)); + } + + @Override public void onResume() { super.onResume(); mapView.onResume(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java index 5b45223da0..7dec4e9038 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolylineActivity.java @@ -40,7 +40,7 @@ public class PolylineActivity extends AppCompatActivity { private List<Polyline> mPolylines; private ArrayList<PolylineOptions> mPolylineOptions = new ArrayList<>(); private MapView mMapView; - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; private boolean fullAlpha = true; private boolean visible = true; @@ -72,7 +72,7 @@ public class PolylineActivity extends AppCompatActivity { mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + PolylineActivity.this.mapboxMap = mapboxMap; mPolylines = mapboxMap.addPolylines(mPolylineOptions); } }); @@ -82,19 +82,19 @@ public class PolylineActivity extends AppCompatActivity { fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mMapboxMap != null) { + if (mapboxMap != null) { if (mPolylines != null && mPolylines.size() > 0) { if (mPolylines.size() == 1) { // test for removing annotation - mMapboxMap.removeAnnotation(mPolylines.get(0)); + mapboxMap.removeAnnotation(mPolylines.get(0)); } else { // test for removing annotations - mMapboxMap.removeAnnotations(mPolylines); + mapboxMap.removeAnnotations(mPolylines); } } mPolylineOptions.clear(); mPolylineOptions.addAll(getRandomLine()); - mPolylines = mMapboxMap.addPolylines(mPolylineOptions); + mPolylines = mapboxMap.addPolylines(mPolylineOptions); } } @@ -172,7 +172,7 @@ public class PolylineActivity extends AppCompatActivity { case R.id.action_id_remove: // test to remove all annotations mPolylineOptions.clear(); - mMapboxMap.clear(); + mapboxMap.clear(); return true; case R.id.action_id_alpha: diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java index 0c014f7693..6784ac0914 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PressForMarkerActivity.java @@ -44,7 +44,7 @@ public class PressForMarkerActivity extends AppCompatActivity { actionBar.setDisplayShowHomeEnabled(true); } - mapView = (MapView) findViewById(R.id.pressForMarkerMapView); + mapView = (MapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() { @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.java index 44758cd146..6494fff9f5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.java @@ -1,7 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.camera; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -10,24 +9,24 @@ import android.view.MenuItem; import android.view.View; import android.widget.Toast; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.maps.MapView; -public class CameraAnimationTypeActivity extends AppCompatActivity { +public class CameraAnimationTypeActivity extends AppCompatActivity implements OnMapReadyCallback { private static final String TAG = "CameraActivity"; + private static final LatLng LAT_LNG_LONDON_EYE = new LatLng(51.50325, -0.11968); + private static final LatLng LAT_LNG_TOWER_BRIDGE = new LatLng(51.50550, -0.07520); + private MapboxMap mapboxMap; private MapView mapView; - private boolean cameraState; - private static final LatLng LAT_LNG_LONDON_EYE = new LatLng(51.50325, -0.11968); - private static final LatLng LAT_LNG_TOWER_BRIDGE = new LatLng(51.50550, -0.07520); @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,92 +43,103 @@ public class CameraAnimationTypeActivity extends AppCompatActivity { } mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(new OnMapReadyCallback() { + if (mapView != null) { + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + mapboxMap.getUiSettings().setAttributionEnabled(false); + mapboxMap.getUiSettings().setLogoEnabled(false); + mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() { @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - mapboxMap.getUiSettings().setAttributionEnabled(false); - mapboxMap.getUiSettings().setLogoEnabled(false); - mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() { - @Override - public void onCameraChange(CameraPosition position) { - Log.v(MapboxConstants.TAG, position.toString()); - } - }); - - // handle move button clicks - findViewById(R.id.cameraMoveButton).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - CameraPosition cameraPosition = new CameraPosition.Builder() - .target(getNextLatLng()) - .zoom(14) - .tilt(30) - .tilt(0) - .build(); - - mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - } - }); - - // handle ease button clicks - findViewById(R.id.cameraEaseButton).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - CameraPosition cameraPosition = new CameraPosition.Builder() - .target(getNextLatLng()) - .zoom(15) - .bearing(180) - .tilt(30) - .build(); - - MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() { - @Override - public void onCancel() { - Log.i(TAG, "Duration onCancel Callback called."); - Toast.makeText(CameraAnimationTypeActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show(); - } - - @Override - public void onFinish() { - Log.i(TAG, "Duration onFinish Callback called."); - Toast.makeText(CameraAnimationTypeActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show(); - } - }; - - mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback); - } - }); - - // handle animate button clicks - findViewById(R.id.cameraAnimateButton).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - CameraPosition cameraPosition = new CameraPosition.Builder() - .target(getNextLatLng()) - .bearing(270) - .tilt(20) - .build(); - - MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() { - @Override - public void onCancel() { - Log.i(TAG, "Duration onCancel Callback called."); - Toast.makeText(CameraAnimationTypeActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show(); - } - - @Override - public void onFinish() { - Log.i(TAG, "Duration onFinish Callback called."); - Toast.makeText(CameraAnimationTypeActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show(); - } - }; - - mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback); - } - }); + public void onCameraChange(CameraPosition position) { + Log.v(MapboxConstants.TAG, position.toString()); } }); + + // handle move button clicks + View moveButton = findViewById(R.id.cameraMoveButton); + if (moveButton != null) { + moveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + CameraPosition cameraPosition = new CameraPosition.Builder() + .target(getNextLatLng()) + .zoom(14) + .tilt(30) + .tilt(0) + .build(); + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); + } + }); + } + + // handle ease button clicks + View easeButton = findViewById(R.id.cameraEaseButton); + if (easeButton != null) { + easeButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + CameraPosition cameraPosition = new CameraPosition.Builder() + .target(getNextLatLng()) + .zoom(15) + .bearing(180) + .tilt(30) + .build(); + + MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() { + @Override + public void onCancel() { + Log.i(TAG, "Duration onCancel Callback called."); + Toast.makeText(CameraAnimationTypeActivity.this, "Ease onCancel Callback called.", Toast.LENGTH_LONG).show(); + } + + @Override + public void onFinish() { + Log.i(TAG, "Duration onFinish Callback called."); + Toast.makeText(CameraAnimationTypeActivity.this, "Ease onFinish Callback called.", Toast.LENGTH_LONG).show(); + } + }; + + mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback); + } + }); + } + + // handle animate button clicks + View animateButton = findViewById(R.id.cameraAnimateButton); + if (animateButton != null) { + animateButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + CameraPosition cameraPosition = new CameraPosition.Builder() + .target(getNextLatLng()) + .bearing(270) + .tilt(20) + .build(); + + MapboxMap.CancelableCallback callback = new MapboxMap.CancelableCallback() { + @Override + public void onCancel() { + Log.i(TAG, "Duration onCancel Callback called."); + Toast.makeText(CameraAnimationTypeActivity.this, "Duration onCancel Callback called.", Toast.LENGTH_LONG).show(); + } + + @Override + public void onFinish() { + Log.i(TAG, "Duration onFinish Callback called."); + Toast.makeText(CameraAnimationTypeActivity.this, "Duration onFinish Callback called.", Toast.LENGTH_LONG).show(); + } + }; + + mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback); + } + }); + } } private LatLng getNextLatLng() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java index 220bef197b..3f4763ba48 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java @@ -30,6 +30,7 @@ import com.mapbox.mapboxsdk.testapp.R; public class CameraPositionActivity extends AppCompatActivity implements OnMapReadyCallback { private MapView mapView; + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -52,6 +53,7 @@ public class CameraPositionActivity extends AppCompatActivity implements OnMapRe @Override public void onMapReady(@NonNull final MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; // add a listener to FAB FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setColorFilter(ContextCompat.getColor(CameraPositionActivity.this, R.color.primary)); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java index 3ab8f7e763..311991d0d1 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java @@ -1,7 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.camera; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -23,12 +22,13 @@ import com.mapbox.mapboxsdk.testapp.R; import java.util.ArrayList; import java.util.List; -public class LatLngBoundsActivity extends AppCompatActivity { +public class LatLngBoundsActivity extends AppCompatActivity implements OnMapReadyCallback { private static final LatLng LOS_ANGELES = new LatLng(34.053940, -118.242622); private static final LatLng NEW_YORK = new LatLng(40.712730, -74.005953); - private MapView mMapView; + private MapView mapView; + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,77 +44,78 @@ public class LatLngBoundsActivity extends AppCompatActivity { actionBar.setDisplayShowHomeEnabled(true); } - mMapView = (MapView) findViewById(R.id.mapView); - mMapView.setStyleUrl(Style.DARK); - mMapView.onCreate(savedInstanceState); - mMapView.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - - UiSettings uiSettings = mapboxMap.getUiSettings(); - uiSettings.setAllGesturesEnabled(false); - - mapboxMap.addMarker(new MarkerOptions() - .title("Los Angeles") - .snippet("City Hall") - .position(LOS_ANGELES)); - - mapboxMap.addMarker(new MarkerOptions() - .title("New York") - .snippet("City Hall") - .position(NEW_YORK)); - - List<LatLng> points = new ArrayList<>(); - points.add(NEW_YORK); - points.add(LOS_ANGELES); - - // Create Bounds - final LatLngBounds bounds = new LatLngBounds.Builder() - .includes(points) - .build(); - - // Add map padding - int mapPadding = (int) getResources().getDimension(R.dimen.fab_margin); - mapboxMap.setPadding(mapPadding, mapPadding, mapPadding, mapPadding); - - // Move camera to the bounds with added padding - int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin); - mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding)); - - // Call mapboxMap.getProjection().getVisibleRegion().latLngBounds to retrieve the bounds - Log.v(MapboxConstants.TAG, mapboxMap.getProjection().getVisibleRegion().latLngBounds.toString()); - } - }); + mapView = (MapView) findViewById(R.id.mapView); + mapView.setStyleUrl(Style.DARK); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + UiSettings uiSettings = mapboxMap.getUiSettings(); + uiSettings.setAllGesturesEnabled(false); + + mapboxMap.addMarker(new MarkerOptions() + .title("Los Angeles") + .snippet("City Hall") + .position(LOS_ANGELES)); + + mapboxMap.addMarker(new MarkerOptions() + .title("New York") + .snippet("City Hall") + .position(NEW_YORK)); + + List<LatLng> points = new ArrayList<>(); + points.add(NEW_YORK); + points.add(LOS_ANGELES); + + // Create Bounds + final LatLngBounds bounds = new LatLngBounds.Builder() + .includes(points) + .build(); + + // Add map padding + int mapPadding = (int) getResources().getDimension(R.dimen.fab_margin); + mapboxMap.setPadding(mapPadding, mapPadding, mapPadding, mapPadding); + + // Move camera to the bounds with added padding + int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin); + mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding)); + + // Log data + Log.e(MapboxConstants.TAG, "Move to bounds: " + bounds.toString()); + Log.e(MapboxConstants.TAG, "Resulting bounds:" + mapboxMap.getProjection().getVisibleRegion().latLngBounds.toString()); } @Override public void onResume() { super.onResume(); - mMapView.onResume(); + mapView.onResume(); } @Override public void onPause() { super.onPause(); - mMapView.onPause(); + mapView.onPause(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mMapView.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); } @Override protected void onDestroy() { super.onDestroy(); - mMapView.onDestroy(); + mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); - mMapView.onLowMemory(); + mapView.onLowMemory(); } @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.java index 897380d1aa..477ef64e86 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.java @@ -20,7 +20,7 @@ import com.mapbox.mapboxsdk.testapp.R; public class ManualZoomActivity extends AppCompatActivity { - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; private MapView mMapView; @Override @@ -37,15 +37,15 @@ public class ManualZoomActivity extends AppCompatActivity { actionBar.setDisplayShowHomeEnabled(true); } - mMapView = (MapView) findViewById(R.id.manualZoomMapView); + mMapView = (MapView) findViewById(R.id.mapView); mMapView.setStyleUrl(Style.SATELLITE); mMapView.onCreate(savedInstanceState); mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull final MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + ManualZoomActivity.this.mapboxMap = mapboxMap; - UiSettings uiSettings = mMapboxMap.getUiSettings(); + UiSettings uiSettings = ManualZoomActivity.this.mapboxMap.getUiSettings(); uiSettings.setAllGesturesEnabled(false); } }); @@ -67,23 +67,23 @@ public class ManualZoomActivity extends AppCompatActivity { return true; case R.id.action_zoom_in: - mMapboxMap.animateCamera(CameraUpdateFactory.zoomIn()); + mapboxMap.animateCamera(CameraUpdateFactory.zoomIn()); return true; case R.id.action_zoom_out: - mMapboxMap.animateCamera(CameraUpdateFactory.zoomOut()); + mapboxMap.animateCamera(CameraUpdateFactory.zoomOut()); return true; case R.id.action_zoom_by: - mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2)); + mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2)); return true; case R.id.action_zoom_to: - mMapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2)); + mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2)); return true; case R.id.action_zoom_to_point: View view = getWindow().getDecorView(); - mMapboxMap.animateCamera(CameraUpdateFactory.zoomBy(1, new Point(view.getMeasuredWidth() / 4, view.getMeasuredHeight() / 4))); + mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(1, new Point(view.getMeasuredWidth() / 4, view.getMeasuredHeight() / 4))); return true; default: diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.java index e9a9647d45..9fcdfa3880 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.java @@ -1,7 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.camera; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -10,14 +9,15 @@ import android.view.MenuItem; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; -import com.mapbox.mapboxsdk.maps.UiSettings; import com.mapbox.mapboxsdk.testapp.R; -public class MaxMinZoomActivity extends AppCompatActivity { +public class MaxMinZoomActivity extends AppCompatActivity implements OnMapReadyCallback { - private MapView mMapView; + private MapView mapView; + private MapboxMap mapboxMap; @Override + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maxmin_zoom); @@ -31,15 +31,16 @@ public class MaxMinZoomActivity extends AppCompatActivity { actionBar.setDisplayShowHomeEnabled(true); } - mMapView = (MapView) findViewById(R.id.mapView); - mMapView.onCreate(savedInstanceState); - mMapView.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - mapboxMap.setMinZoom(3); - mapboxMap.setMaxZoom(5); - } - }); + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + mapboxMap.setMinZoom(3); + mapboxMap.setMaxZoom(5); } @Override @@ -55,31 +56,31 @@ public class MaxMinZoomActivity extends AppCompatActivity { @Override public void onResume() { super.onResume(); - mMapView.onResume(); + mapView.onResume(); } @Override public void onPause() { super.onPause(); - mMapView.onPause(); + mapView.onPause(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mMapView.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); } @Override protected void onDestroy() { super.onDestroy(); - mMapView.onDestroy(); + mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); - mMapView.onLowMemory(); + mapView.onLowMemory(); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.java index 729a08758e..1154cccb6e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.java @@ -20,11 +20,13 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.UiSettings; import com.mapbox.mapboxsdk.testapp.R; -public class ScrollByActivity extends AppCompatActivity { +public class ScrollByActivity extends AppCompatActivity implements OnMapReadyCallback { public static final int MULTIPLIER_PER_PIXEL = 50; - private MapView mMapView; + private MapView mapView; + private MapboxMap mapboxMap; + private SeekBar xBar, yBar; @Override protected void onCreate(Bundle savedInstanceState) { @@ -40,35 +42,36 @@ public class ScrollByActivity extends AppCompatActivity { actionBar.setDisplayShowHomeEnabled(true); } - final SeekBar xBar = (SeekBar) findViewById(R.id.seekbar_move_x); + xBar = (SeekBar) findViewById(R.id.seekbar_move_x); TextView xText = (TextView) findViewById(R.id.textview_x); xBar.setOnSeekBarChangeListener(new PixelBarChangeListener(xText, R.string.scrollby_x_value)); - final SeekBar yBar = (SeekBar) findViewById(R.id.seekbar_move_y); + yBar = (SeekBar) findViewById(R.id.seekbar_move_y); TextView yText = (TextView) findViewById(R.id.textview_y); yBar.setOnSeekBarChangeListener(new PixelBarChangeListener(yText, R.string.scrollby_y_value)); - mMapView = (MapView) findViewById(R.id.mapView); - mMapView.setTag(true); - mMapView.onCreate(savedInstanceState); - mMapView.getMapAsync(new OnMapReadyCallback() { + mapView = (MapView) findViewById(R.id.mapView); + mapView.setTag(true); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + UiSettings uiSettings = mapboxMap.getUiSettings(); + uiSettings.setLogoEnabled(false); + uiSettings.setAttributionEnabled(false); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setColorFilter(ContextCompat.getColor(ScrollByActivity.this, R.color.primary)); + fab.setOnClickListener(new View.OnClickListener() { @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - UiSettings uiSettings = mapboxMap.getUiSettings(); - uiSettings.setLogoEnabled(false); - uiSettings.setAttributionEnabled(false); - - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - fab.setColorFilter(ContextCompat.getColor(ScrollByActivity.this, R.color.primary)); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - mapboxMap.easeCamera(CameraUpdateFactory.scrollBy( - xBar.getProgress() * MULTIPLIER_PER_PIXEL, - yBar.getProgress() * MULTIPLIER_PER_PIXEL) - ); - } - }); + public void onClick(View v) { + mapboxMap.easeCamera(CameraUpdateFactory.scrollBy( + xBar.getProgress() * MULTIPLIER_PER_PIXEL, + yBar.getProgress() * MULTIPLIER_PER_PIXEL) + ); } }); } @@ -76,31 +79,31 @@ public class ScrollByActivity extends AppCompatActivity { @Override public void onResume() { super.onResume(); - mMapView.onResume(); + mapView.onResume(); } @Override public void onPause() { super.onPause(); - mMapView.onPause(); + mapView.onPause(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - mMapView.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); } @Override protected void onDestroy() { super.onDestroy(); - mMapView.onDestroy(); + mapView.onDestroy(); } @Override public void onLowMemory() { super.onLowMemory(); - mMapView.onLowMemory(); + mapView.onLowMemory(); } @Override @@ -141,6 +144,4 @@ public class ScrollByActivity extends AppCompatActivity { } } - - }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/directions/DirectionsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/directions/DirectionsActivity.java index 7d46cdb6bb..c725d9a7d7 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/directions/DirectionsActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/directions/DirectionsActivity.java @@ -35,7 +35,7 @@ public class DirectionsActivity extends AppCompatActivity { private final static String LOG_TAG = "DirectionsActivity"; private MapView mMapView; - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,7 +56,7 @@ public class DirectionsActivity extends AppCompatActivity { mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + DirectionsActivity.this.mapboxMap = mapboxMap; loadRoute(); } }); @@ -74,17 +74,17 @@ public class DirectionsActivity extends AppCompatActivity { (origin.getLatitude() + destination.getLatitude()) / 2, (origin.getLongitude() + destination.getLongitude()) / 2); - mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder() + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder() .target(centroid) .zoom(14) .build())); // Add origin and destination to the map - mMapboxMap.addMarker(new MarkerOptions() + mapboxMap.addMarker(new MarkerOptions() .position(new LatLng(origin.getLatitude(), origin.getLongitude())) .title("Origin") .snippet("Dupont Circle")); - mMapboxMap.addMarker(new MarkerOptions() + mapboxMap.addMarker(new MarkerOptions() .position(new LatLng(destination.getLatitude(), destination.getLongitude())) .title("Destination") .snippet("The White House")); @@ -142,7 +142,7 @@ public class DirectionsActivity extends AppCompatActivity { } // Draw Points on MapView - mMapboxMap.addPolyline(builder); + mapboxMap.addPolyline(builder); } @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.java index 9d72c2b02a..8233e59fd4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.java @@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.activity.fragment; import android.app.FragmentTransaction; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -18,7 +17,9 @@ import com.mapbox.mapboxsdk.maps.MapboxMapOptions; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; -public class MapFragmentActivity extends AppCompatActivity { +public class MapFragmentActivity extends AppCompatActivity implements OnMapReadyCallback { + + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -68,12 +69,13 @@ public class MapFragmentActivity extends AppCompatActivity { mapFragment = (MapFragment) getFragmentManager().findFragmentByTag("com.mapbox.map"); } - mapFragment.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(@NonNull MapboxMap mapboxMap) { - mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(45.0).build()), 10000); - } - }); + mapFragment.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(45.0).build()), 10000); } @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.java index cc61eb4698..cb3db5f2d3 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.java @@ -1,7 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.fragment; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; @@ -18,7 +17,9 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.SupportMapFragment; import com.mapbox.mapboxsdk.testapp.R; -public class SupportMapFragmentActivity extends AppCompatActivity { +public class SupportMapFragmentActivity extends AppCompatActivity implements OnMapReadyCallback { + + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -68,12 +69,13 @@ public class SupportMapFragmentActivity extends AppCompatActivity { mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map"); } - mapFragment.getMapAsync(new OnMapReadyCallback() { - @Override - public void onMapReady(@NonNull MapboxMap mapboxMap) { - mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(45.0).build()), 10000); - } - }); + mapFragment.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(45.0).build()), 10000); } @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/geocoding/GeocoderActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/geocoding/GeocoderActivity.java index 18b4daf3a7..42cc5d8618 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/geocoding/GeocoderActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/geocoding/GeocoderActivity.java @@ -1,7 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.geocoding; import android.graphics.PointF; -import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.ActionBar; @@ -14,6 +13,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; + import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; @@ -34,13 +34,14 @@ import java.util.List; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -import retrofit2.Retrofit; -public class GeocoderActivity extends AppCompatActivity { +public class GeocoderActivity extends AppCompatActivity implements OnMapReadyCallback { private static final String LOG_TAG = "GeocoderActivity"; + private MapboxMap mapboxMap; private MapView mapView; + private ImageView dropPinView; private TextView textView; @Override @@ -64,34 +65,34 @@ public class GeocoderActivity extends AppCompatActivity { mapView.setStyleUrl(Style.MAPBOX_STREETS); mapView.onCreate(savedInstanceState); - final ImageView dropPinView = new ImageView(this); + dropPinView = new ImageView(this); dropPinView.setImageResource(R.drawable.ic_droppin_24dp); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER); dropPinView.setLayoutParams(params); mapView.addView(dropPinView); + mapView.getMapAsync(this); + } - mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + final Projection projection = mapboxMap.getProjection(); + final int width = mapView.getMeasuredWidth(); + final int height = mapView.getMeasuredHeight(); + + // Click listener + mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() { @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - final Projection projection = mapboxMap.getProjection(); - final int width = mapView.getMeasuredWidth(); - final int height = mapView.getMeasuredHeight(); + public void onMapClick(@NonNull LatLng point) { + PointF centerPoint = new PointF(width / 2, (height + dropPinView.getHeight()) / 2); + LatLng centerLatLng = new LatLng(projection.fromScreenLocation(centerPoint)); - // Click listener - mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() { - @Override - public void onMapClick(@NonNull LatLng point) { - PointF centerPoint = new PointF(width / 2, (height + dropPinView.getHeight()) / 2); - LatLng centerLatLng = new LatLng(projection.fromScreenLocation(centerPoint)); + setMessage("Geocoding..."); - setMessage("Geocoding..."); + mapboxMap.removeAnnotations(); + mapboxMap.addMarker(new MarkerOptions().position(centerLatLng)); - mapboxMap.removeAnnotations(); - mapboxMap.addMarker(new MarkerOptions().position(centerLatLng)); - - geocode(centerLatLng); - } - }); + geocode(centerLatLng); } }); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java index 4d19b4702e..935851c445 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java @@ -1,9 +1,7 @@ package com.mapbox.mapboxsdk.testapp.activity.imagegenerator; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.os.Bundle; -import android.app.Activity; import android.support.annotation.NonNull; import android.support.v4.print.PrintHelper; import android.support.v7.app.ActionBar; @@ -11,19 +9,16 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.Spinner; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.annotation.BulkMarkerActivity; public class PrintActivity extends AppCompatActivity implements MapboxMap.SnapshotReadyCallback { private MapView mMapView; - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,7 +39,7 @@ public class PrintActivity extends AppCompatActivity implements MapboxMap.Snapsh mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + PrintActivity.this.mapboxMap = mapboxMap; } }); @@ -53,8 +48,8 @@ public class PrintActivity extends AppCompatActivity implements MapboxMap.Snapsh fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(mMapboxMap!=null) { - mMapboxMap.snapshot(PrintActivity.this); + if(mapboxMap !=null) { + mapboxMap.snapshot(PrintActivity.this); } } }); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java index 84e394c72d..356bf6677b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java @@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.activity.imagegenerator; import android.graphics.Bitmap; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; @@ -12,15 +11,17 @@ import android.view.MenuItem; import android.view.View; import android.widget.ImageView; import android.widget.Toast; + import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; -public class SnapshotActivity extends AppCompatActivity { +public class SnapshotActivity extends AppCompatActivity implements OnMapReadyCallback, View.OnClickListener { private MapView mapView; + private MapboxMap mapboxMap; @Override public void onCreate(Bundle savedInstanceState) { @@ -38,28 +39,31 @@ public class SnapshotActivity extends AppCompatActivity { mapView = (MapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); - mapView.getMapAsync(new OnMapReadyCallback() { + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + mapboxMap.setStyleUrl(Style.OUTDOORS); + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + if (fab != null) { + fab.setColorFilter(ContextCompat.getColor(SnapshotActivity.this, R.color.primary)); + fab.setOnClickListener(this); + } + } + + @Override + public void onClick(View v) { + final long startTime = System.nanoTime(); + mapboxMap.snapshot(new MapboxMap.SnapshotReadyCallback() { @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - mapboxMap.setStyleUrl(Style.OUTDOORS); - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - fab.setColorFilter(ContextCompat.getColor(SnapshotActivity.this, R.color.primary)); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - final long startTime = System.nanoTime(); - mapboxMap.snapshot(new MapboxMap.SnapshotReadyCallback() { - @Override - public void onSnapshotReady(Bitmap snapshot) { - long endTime = System.nanoTime(); - long duration = (long) ((endTime - startTime) / 1e6); - ImageView snapshotView = (ImageView) findViewById(R.id.imageView); - snapshotView.setImageBitmap(snapshot); - Toast.makeText(SnapshotActivity.this, String.format("Snapshot taken in %d ms", duration), Toast.LENGTH_LONG).show(); - } - }); - } - }); + public void onSnapshotReady(Bitmap snapshot) { + long endTime = System.nanoTime(); + long duration = (long) ((endTime - startTime) / 1e6); + ImageView snapshotView = (ImageView) findViewById(R.id.imageView); + snapshotView.setImageBitmap(snapshot); + Toast.makeText(SnapshotActivity.this, String.format("Snapshot taken in %d ms", duration), Toast.LENGTH_LONG).show(); } }); } 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 5b2cae5e04..cf522d7f39 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 @@ -29,8 +29,9 @@ import com.mapbox.mapboxsdk.testapp.R; /** * Shows how to dynamically update InfoWindow when Using an MapboxMap.InfoWindowAdapter */ -public class DynamicInfoWindowAdapterActivity extends AppCompatActivity { +public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implements OnMapReadyCallback { + private MapboxMap mapboxMap; private MapView mapView; private LatLng paris = new LatLng(48.864716, 2.349014); @@ -44,45 +45,47 @@ public class DynamicInfoWindowAdapterActivity extends AppCompatActivity { mapView = (MapView) findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap map) { + + mapboxMap = map; + + //Add info window adapter + addCustomInfoWindowAdapter(mapboxMap); + + //Keep info windows open on click + mapboxMap.getUiSettings().setDeselectMarkersOnTap(false); - mapView.getMapAsync(new OnMapReadyCallback() { + //Add a marker + final MarkerView marker = addMarker(mapboxMap); + mapboxMap.selectMarker(marker); + + //On map click, change the info window contents + mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() { @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - //Add info window adapter - addCustomInfoWindowAdapter(mapboxMap); - - //Keep info windows open on click - mapboxMap.getUiSettings().setDeselectMarkersOnTap(false); - - //Add a marker - final MarkerView marker = addMarker(mapboxMap); - mapboxMap.selectMarker(marker); - - //On map click, change the info window contents - mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() { - @Override - public void onMapClick(@NonNull LatLng point) { - //Distance from click to marker - double distanceKm = marker.getPosition().distanceTo(point) / 1000; - - //Get the info window - 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("%.2fkm", distanceKm)); - - //Update the info window position (as the text length changes) - infoWindow.update(); - } - } - }); - - //Focus on Paris - mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(paris)); + public void onMapClick(@NonNull LatLng point) { + //Distance from click to marker + double distanceKm = marker.getPosition().distanceTo(point) / 1000; + + //Get the info window + 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("%.2fkm", distanceKm)); + + //Update the info window position (as the text length changes) + infoWindow.update(); + } } }); + + //Focus on Paris + mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(paris)); } private MarkerView addMarker(MapboxMap mapboxMap) { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java index 2c74702253..8066dbc60e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java @@ -13,20 +13,21 @@ import android.view.MenuItem; import android.view.View; import android.widget.TextView; -import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.IconFactory; +import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarker; import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarkerOptions; -import com.mapbox.mapboxsdk.maps.MapView; public class InfoWindowAdapterActivity extends AppCompatActivity { private MapView mapView; + private MapboxMap mapboxMap; private IconFactory iconFactory; private Drawable iconDrawable; @@ -51,14 +52,15 @@ public class InfoWindowAdapterActivity extends AppCompatActivity { mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() { @Override - public void onMapReady(@NonNull MapboxMap mapboxMap) { - addMarkers(mapboxMap); - addCustomInfoWindowAdapter(mapboxMap); + public void onMapReady(@NonNull MapboxMap map) { + mapboxMap = map; + addMarkers(); + addCustomInfoWindowAdapter(); } }); } - private void addMarkers(MapboxMap mapboxMap){ + private void addMarkers() { mapboxMap.addMarker(generateCityStateMarker("Andorra", 42.505777, 1.52529, "#F44336")); mapboxMap.addMarker(generateCityStateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5")); mapboxMap.addMarker(generateCityStateMarker("Monaco", 43.738418, 7.424616, "#673AB7")); @@ -79,7 +81,7 @@ public class InfoWindowAdapterActivity extends AppCompatActivity { return marker; } - private void addCustomInfoWindowAdapter(MapboxMap mapboxMap){ + private void addCustomInfoWindowAdapter() { mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() { private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java index ee54461357..ffea7594d9 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.maplayout; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; @@ -29,6 +30,9 @@ public class DoubleMapActivity extends AppCompatActivity { private static final String TAG_FRAGMENT = "map"; + // used for ui tests + private MapboxMap mapboxMap; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -53,12 +57,35 @@ public class DoubleMapActivity extends AppCompatActivity { } } + public void setMapboxMap(MapboxMap map) { + // we need to set mapboxmap on the parent activity, + // for auto-generated ui tests + + mapboxMap = map; + mapboxMap.setStyleUrl(Style.DARK); + mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18)); + try { + TrackingSettings settings = mapboxMap.getTrackingSettings(); + settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); + } catch (SecurityException e) { + // permission is handled in MainActivity + finish(); + } + } + public static class DoubleMapFragment extends Fragment { + private DoubleMapActivity activity; private MapView mMapView; private MapView mMapViewMini; @Override + public void onAttach(Context context) { + super.onAttach(context); + activity = (DoubleMapActivity) context; + } + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_double_map, container, false); } @@ -73,15 +100,8 @@ public class DoubleMapActivity extends AppCompatActivity { mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mapboxMap.setStyleUrl(Style.DARK); - - mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(18)); - try { - TrackingSettings settings = mapboxMap.getTrackingSettings(); - settings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW); - } catch (SecurityException e) { - // permission is handled in MainActivity - getActivity().finish(); + if (activity != null) { + activity.setMapboxMap(mapboxMap); } } }); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java index 62762f7116..f90741ee83 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.java @@ -22,7 +22,7 @@ import com.mapbox.mapboxsdk.testapp.R; public class MapPaddingActivity extends AppCompatActivity { private MapView mMapView; - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -45,7 +45,7 @@ public class MapPaddingActivity extends AppCompatActivity { mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + MapPaddingActivity.this.mapboxMap = mapboxMap; int paddingLeft = (int) getResources().getDimension(R.dimen.map_padding_left); int paddingBottom = (int) getResources().getDimension(R.dimen.map_padding_bottom); @@ -96,9 +96,9 @@ public class MapPaddingActivity extends AppCompatActivity { private void toggleGps(boolean enable) { try { // Enable user location - mMapboxMap.setMyLocationEnabled(enable); + mapboxMap.setMyLocationEnabled(enable); - TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings(); + TrackingSettings trackingSettings = mapboxMap.getTrackingSettings(); trackingSettings.setDismissTrackingOnGesture(false); trackingSettings.setMyLocationTrackingMode(enable ? MyLocationTracking.TRACKING_FOLLOW : MyLocationTracking.TRACKING_NONE); } catch (SecurityException e) { @@ -118,8 +118,8 @@ public class MapPaddingActivity extends AppCompatActivity { .tilt(45) .build(); - mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - mMapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore)); + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); + mapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore)); } @Override @@ -130,13 +130,13 @@ public class MapPaddingActivity extends AppCompatActivity { return true; case R.id.action_user_tracking: - if (mMapboxMap != null) { + if (mapboxMap != null) { toggleGps(true); } return true; case R.id.action_bangalore: - if (mMapboxMap != null) { + if (mapboxMap != null) { moveToBangalore(); } return true; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/NavigationDrawerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/NavigationDrawerActivity.java index baa4142489..46afd11674 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/NavigationDrawerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/NavigationDrawerActivity.java @@ -5,7 +5,6 @@ import android.app.Fragment; import android.app.FragmentManager; import android.content.SharedPreferences; import android.content.res.Configuration; -import android.graphics.Color; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.design.widget.Snackbar; @@ -26,12 +25,15 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapFragment; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.MapboxMapOptions; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; public class NavigationDrawerActivity extends AppCompatActivity { private boolean firstStyle = true; + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -58,17 +60,29 @@ public class NavigationDrawerActivity extends AppCompatActivity { // update the main content by replacing fragments switch (position) { case 0: + // options MapboxMapOptions options = new MapboxMapOptions(); options.styleUrl(firstStyle ? Style.LIGHT : Style.SATELLITE); options.camera(new CameraPosition.Builder() .target(new LatLng(39.913271, 116.413891)) .zoom(12) .build()); + + // fragment + MapFragment mapFragment = MapFragment.newInstance(options); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() - .replace(R.id.container, MapFragment.newInstance(options)) + .replace(R.id.container, mapFragment) .commit(); + // get callback when map is ready + mapFragment.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + } + }); + firstStyle = !firstStyle; break; case 1: diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SurfaceViewMediaControlActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SurfaceViewMediaControlActivity.java index 4e193573dd..ed87d75ca0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SurfaceViewMediaControlActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SurfaceViewMediaControlActivity.java @@ -12,14 +12,17 @@ import android.view.MotionEvent; import android.widget.FrameLayout; import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.testapp.R; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; -public class SurfaceViewMediaControlActivity extends AppCompatActivity { +public class SurfaceViewMediaControlActivity extends AppCompatActivity implements OnMapReadyCallback { private MapView mMapView; + private MapboxMap mapboxMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -37,6 +40,7 @@ public class SurfaceViewMediaControlActivity extends AppCompatActivity { mMapView = (MapView) findViewById(R.id.mapView); mMapView.onCreate(savedInstanceState); + mMapView.getMapAsync(this); // add another SurfaceView to the Layout FrameLayout container = (FrameLayout) findViewById(R.id.container); @@ -46,6 +50,11 @@ public class SurfaceViewMediaControlActivity extends AppCompatActivity { } @Override + public void onMapReady(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + } + + @Override public void onResume() { super.onResume(); mMapView.onResume(); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java index 8819168478..4d5e2552fd 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.java @@ -47,7 +47,7 @@ public class OfflineActivity extends AppCompatActivity * UI elements */ private MapView mMapView; - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; private ProgressBar mProgressBar; private Button downloadRegion; private Button listRegions; @@ -82,7 +82,7 @@ public class OfflineActivity extends AppCompatActivity @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { Log.d(LOG_TAG, "Map is ready"); - mMapboxMap = mapboxMap; + OfflineActivity.this.mapboxMap = mapboxMap; // Set initial position to UNHQ in NYC mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition( @@ -240,10 +240,10 @@ public class OfflineActivity extends AppCompatActivity startProgress(); // Definition - String styleURL = mMapboxMap.getStyleUrl(); - LatLngBounds bounds = mMapboxMap.getProjection().getVisibleRegion().latLngBounds; - double minZoom = mMapboxMap.getCameraPosition().zoom; - double maxZoom = mMapboxMap.getMaxZoom(); + String styleURL = mapboxMap.getStyleUrl(); + LatLngBounds bounds = mapboxMap.getProjection().getVisibleRegion().latLngBounds; + double minZoom = mapboxMap.getCameraPosition().zoom; + double maxZoom = mapboxMap.getMaxZoom(); float pixelRatio = this.getResources().getDisplayMetrics().density; OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition( styleURL, bounds, minZoom, maxZoom, pixelRatio); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationDrawableActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationDrawableActivity.java index d630ee6d21..d19e55d508 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationDrawableActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationDrawableActivity.java @@ -7,7 +7,6 @@ import android.location.Location; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.annotation.UiThread; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; @@ -17,7 +16,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.geometry.LatLng; @@ -70,6 +68,7 @@ public class MyLocationDrawableActivity extends AppCompatActivity implements Loc mapboxMapOptions.myLocationAccuracyAlpha(155); mapView = new MapView(this, mapboxMapOptions); + mapView.setId(R.id.mapView); ViewGroup parent = (ViewGroup) findViewById(R.id.container); parent.addView(mapView); @@ -102,7 +101,7 @@ public class MyLocationDrawableActivity extends AppCompatActivity implements Loc Location location = mapboxMap.getMyLocation(); if (location != null) { onLocationChanged(location); - }else{ + } else { LocationServices.getLocationServices(this).addLocationListener(this); } } else { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java index ba86fa5774..3fc793ad1d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTintActivity.java @@ -30,7 +30,7 @@ import com.mapbox.mapboxsdk.testapp.R; public class MyLocationTintActivity extends AppCompatActivity implements LocationListener { private MapView mapView; - private MapboxMap map; + private MapboxMap mapboxMap; private boolean firstRun; private static final int PERMISSIONS_LOCATION = 0; @@ -53,8 +53,8 @@ public class MyLocationTintActivity extends AppCompatActivity implements Locatio mapView.onCreate(savedInstanceState); mapView.getMapAsync(new OnMapReadyCallback() { @Override - public void onMapReady(MapboxMap mapboxMap) { - map = mapboxMap; + public void onMapReady(MapboxMap map) { + mapboxMap = map; toggleGps(!mapboxMap.isMyLocationEnabled()); final MyLocationViewSettings myLocationViewSettings = mapboxMap.getMyLocationViewSettings(); @@ -92,8 +92,8 @@ public class MyLocationTintActivity extends AppCompatActivity implements Locatio @Override public void onLocationChanged(Location location) { - if (map != null && firstRun) { - map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15)); + if (mapboxMap != null && firstRun) { + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15)); firstRun = false; } } @@ -167,12 +167,14 @@ public class MyLocationTintActivity extends AppCompatActivity implements Locatio private void enableLocation(boolean enabled) { if (enabled) { - map.setMyLocationEnabled(true); - if (map.getMyLocation() != null) { - map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(map.getMyLocation().getLatitude(), map.getMyLocation().getLongitude()), 15)); + mapboxMap.setMyLocationEnabled(true); + if (mapboxMap.getMyLocation() != null) { + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom( + new LatLng(mapboxMap.getMyLocation().getLatitude(), + mapboxMap.getMyLocation().getLongitude()), 15)); } } else { - map.setMyLocationEnabled(false); + mapboxMap.setMyLocationEnabled(false); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java index 36fc87630e..d65eeda9f0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java @@ -35,7 +35,7 @@ import com.mapbox.mapboxsdk.testapp.R; public class MyLocationTrackingModeActivity extends AppCompatActivity implements MapboxMap.OnMyLocationChangeListener, AdapterView.OnItemSelectedListener { private MapView mMapView; - private MapboxMap mMapboxMap; + private MapboxMap mapboxMap; private Spinner mLocationSpinner, mBearingSpinner; private Location mLocation; private static final int PERMISSIONS_LOCATION = 0; @@ -60,7 +60,7 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { - mMapboxMap = mapboxMap; + MyLocationTrackingModeActivity.this.mapboxMap = mapboxMap; // disable dismissal when a gesture occurs TrackingSettings trackingSettings = mapboxMap.getTrackingSettings(); @@ -126,13 +126,13 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements private void enableLocation(boolean enabled) { if (enabled) { - mMapboxMap.setMyLocationEnabled(true); - Location location = mMapboxMap.getMyLocation(); + mapboxMap.setMyLocationEnabled(true); + Location location = mapboxMap.getMyLocation(); if (location != null) { setInitialPosition(new LatLng(location)); } } else { - mMapboxMap.setMyLocationEnabled(false); + mapboxMap.setMyLocationEnabled(false); } } @@ -148,8 +148,8 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements } private void setInitialPosition(LatLng latLng) { - mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14)); - mMapboxMap.setMyLocationEnabled(true); + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14)); + mapboxMap.setMyLocationEnabled(true); mLocationSpinner.setEnabled(true); mBearingSpinner.setEnabled(true); } @@ -189,7 +189,7 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) throws SecurityException { - TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings(); + TrackingSettings trackingSettings = mapboxMap.getTrackingSettings(); if (parent.getId() == R.id.spinner_location) { switch (position) { case 0: @@ -267,13 +267,13 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements return true; case R.id.action_toggle_dismissible_tracking: state = !item.isChecked(); - mMapboxMap.getTrackingSettings().setDismissLocationTrackingOnGesture(state); + mapboxMap.getTrackingSettings().setDismissLocationTrackingOnGesture(state); Toast.makeText(this, "Dismiss tracking mode on gesture = " + state, Toast.LENGTH_SHORT).show(); item.setChecked(state); return true; case R.id.action_toggle_dismissible_bearing: state = !item.isChecked(); - mMapboxMap.getTrackingSettings().setDismissBearingTrackingOnGesture(state); + mapboxMap.getTrackingSettings().setDismissBearingTrackingOnGesture(state); Toast.makeText(this, "Dismiss bearing mode on gesture = " + state, Toast.LENGTH_SHORT).show(); item.setChecked(state); return true; |