summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-08-22 17:21:33 +0200
committerTobrun <tobrun@mapbox.com>2018-08-27 11:25:55 +0200
commitfd1ed8ce48fc9eaf6793e852381d8c7e648386af (patch)
tree7d7251d44eaeac85ef3b52b0cb5bad32be7b7960
parentd297bf10ef89e97da30e1a00dd49560e18bcb3f0 (diff)
downloadqtlocation-mapboxgl-fd1ed8ce48fc9eaf6793e852381d8c7e648386af.tar.gz
[android] - update broken test app examples
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/LatLngBoundsActivity.java4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java66
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java14
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml15
4 files changed, 50 insertions, 49 deletions
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 686f564c5c..e069a7fd08 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
@@ -52,7 +52,7 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_latlngbounds);
- mapView = (MapView) findViewById(R.id.mapView);
+ mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(map -> {
mapboxMap = map;
@@ -64,7 +64,7 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl
addMarkers();
initFab();
initBottomSheet();
- moveToBounds(bottomSheet.getMeasuredHeight(), BOUNDS_PADDING_DIVIDER_SMALL, 0);
+ moveToBounds(bottomSheet.getMeasuredHeight(), BOUNDS_PADDING_DIVIDER_SMALL, ANIMATION_DURATION_SHORT);
}
private void addMarkers() {
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 b4dde8d2cd..01c0477610 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,8 +1,8 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
@@ -10,12 +10,16 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Toast;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.mapboxsdk.testapp.R;
+import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
/**
* Test activity showcasing having 2 maps on top of each other.
@@ -26,9 +30,9 @@ import com.mapbox.mapboxsdk.testapp.R;
public class DoubleMapActivity extends AppCompatActivity {
private static final String TAG_FRAGMENT = "map";
-
- // used for ui tests
- private MapboxMap mapboxMap;
+ private static final LatLng MACHU_PICCHU = new LatLng(-13.1650709, -72.5447154);
+ private static final double ZOOM_IN = 12;
+ private static final double ZOOM_OUT = 4;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -36,59 +40,56 @@ public class DoubleMapActivity extends AppCompatActivity {
setContentView(R.layout.activity_map_fragment);
if (savedInstanceState == null) {
+ MapboxMapOptions options = new MapboxMapOptions();
+ options.styleUrl(Style.DARK);
+ options.camera(new CameraPosition.Builder()
+ .target(MACHU_PICCHU)
+ .zoom(ZOOM_IN)
+ .build()
+ );
+
+ DoubleMapFragment doubleMapFragment = new DoubleMapFragment();
+ doubleMapFragment.setArguments(MapFragmentUtils.createFragmentArgs(options));
+
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.add(R.id.fragment_container, new DoubleMapFragment(), TAG_FRAGMENT);
+ transaction.add(R.id.fragment_container, doubleMapFragment, TAG_FRAGMENT);
transaction.commit();
}
}
- 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));
- }
-
/**
* Custom fragment containing 2 MapViews.
*/
public static class DoubleMapFragment extends Fragment {
- private DoubleMapActivity activity;
private MapView mapView;
private MapView mapViewMini;
@Override
- public void onAttach(Context context) {
- super.onAttach(context);
- activity = (DoubleMapActivity) context;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_double_map, container, false);
}
@Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
+ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// MapView large
- mapView = (MapView) view.findViewById(R.id.mapView);
+ mapView = new MapView(view.getContext(), MapFragmentUtils.resolveArgs(view.getContext(), getArguments()));
mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(mapboxMap -> {
- if (activity != null) {
- activity.setMapboxMap(mapboxMap);
- }
- });
+ ((ViewGroup) view.findViewById(R.id.container)).addView(mapView, 0);
// MapView mini
- mapViewMini = (MapView) view.findViewById(R.id.mini_map);
+ mapViewMini = view.findViewById(R.id.mini_map);
mapViewMini.onCreate(savedInstanceState);
+ mapViewMini.setStyleUrl(Style.LIGHT);
mapViewMini.getMapAsync(mapboxMap -> {
- mapboxMap.setStyleUrl(Style.LIGHT);
- mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(4));
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
+ new CameraPosition.Builder().target(MACHU_PICCHU)
+ .zoom(ZOOM_OUT)
+ .build()
+ )
+ );
UiSettings uiSettings = mapboxMap.getUiSettings();
uiSettings.setAllGesturesEnabled(false);
@@ -98,6 +99,7 @@ public class DoubleMapActivity extends AppCompatActivity {
mapboxMap.setOnMapClickListener(point -> {
// test if we can open 2 activities after each other
+ Toast.makeText(mapViewMini.getContext(), "Creating a new Activity instance",Toast.LENGTH_SHORT).show();
startActivity(new Intent(mapViewMini.getContext(), DoubleMapActivity.class));
});
});
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
index ef5913beb0..302fa1ff77 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java
@@ -64,12 +64,14 @@ public class MapSnapshotterReuseActivity extends AppCompatActivity implements Ma
}
private LatLngBounds getRandomBounds() {
- return LatLngBounds.from(
- randomInRange(-5, 5),
- randomInRange(-5, 5),
- randomInRange(5, 10),
- randomInRange(5, 10)
- );
+ return new LatLngBounds.Builder()
+ .include(new LatLng(
+ randomInRange(-5, 5),
+ randomInRange(-5, 5)))
+ .include(new LatLng(
+ randomInRange(5, 10),
+ randomInRange(5, 10))
+ ).build();
}
private CameraPosition getRandomCameraPosition() {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml
index 3cf2fbea55..c7bb167324 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_double_map.xml
@@ -1,13 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- xmlns:maps="http://schemas.android.com/apk/res-auto">
-
- <com.mapbox.mapboxsdk.maps.MapView
- android:id="@id/mapView"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
+<RelativeLayout
+ android:id="@+id/container"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:maps="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
<FrameLayout
android:layout_width="100dp"