From 950ab7eb8aed1c288acea128771bd0c5b16eaeff Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 7 Jul 2017 10:36:46 +0200 Subject: [android] - add Map change & visibility test activities (#9425) --- .../src/main/AndroidManifest.xml | 22 ++++ .../activity/maplayout/MapChangeActivity.java | 111 ++++++++++++++++ .../maplayout/VisibilityChangeActivity.java | 146 +++++++++++++++++++++ .../main/res/layout/activity_map_visibility.xml | 17 +++ .../src/main/res/values/strings.xml | 4 + 5 files changed, 300 insertions(+) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_visibility.xml diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index d57136755f..93ac4101d4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -414,6 +414,28 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity"/> + + + + + + + + mapChangeMap = buildMapChangeStringValueSparseArray(); + mapView = (MapView) findViewById(R.id.mapView); + mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() { + @Override + public void onMapChanged(int change) { + Timber.e("OnMapChange: %s, %s", change, mapChangeMap.get(change)); + } + }); + + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom( + new LatLng(55.754020, 37.620948), 12), 9000); + } + }); + } + + private LongSparseArray buildMapChangeStringValueSparseArray() { + LongSparseArray mapChangeArray = new LongSparseArray<>(); + mapChangeArray.put(MapView.REGION_WILL_CHANGE, "Region will change"); + mapChangeArray.put(MapView.REGION_WILL_CHANGE_ANIMATED, "Region will change animated"); + mapChangeArray.put(MapView.REGION_IS_CHANGING, "Region is changing"); + mapChangeArray.put(MapView.REGION_DID_CHANGE, "Region did change"); + mapChangeArray.put(MapView.REGION_DID_CHANGE_ANIMATED, "Region did change animated"); + mapChangeArray.put(MapView.WILL_START_LOADING_MAP, "Will start loading map"); + mapChangeArray.put(MapView.DID_FINISH_LOADING_MAP, "Did finish loading map"); + mapChangeArray.put(MapView.DID_FAIL_LOADING_MAP, "Did fail loading map"); + mapChangeArray.put(MapView.WILL_START_RENDERING_FRAME, "Will start rendering frame"); + mapChangeArray.put(MapView.DID_FINISH_RENDERING_FRAME, "Did finish rendering frame"); + mapChangeArray.put(MapView.DID_FINISH_RENDERING_FRAME_FULLY_RENDERED, "Did finish rendering frame fully rendered"); + mapChangeArray.put(MapView.WILL_START_RENDERING_MAP, "Will start rendering map"); + mapChangeArray.put(MapView.DID_FINISH_RENDERING_MAP, "Did finish rendering map"); + mapChangeArray.put(MapView.DID_FINISH_RENDERING_MAP_FULLY_RENDERED, "Did finish rendering map fully rendered"); + mapChangeArray.put(MapView.DID_FINISH_LOADING_STYLE, "Did finish loading style"); + mapChangeArray.put(MapView.SOURCE_DID_CHANGE, "Source did change"); + return mapChangeArray; + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.java new file mode 100644 index 0000000000..393abb7cd4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.java @@ -0,0 +1,146 @@ +package com.mapbox.mapboxsdk.testapp.activity.maplayout; + +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; +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; + +/** + * Test activity showcasing visibility changes to the mapview. + */ +public class VisibilityChangeActivity extends AppCompatActivity { + + private MapView mapView; + private MapboxMap mapboxMap; + private Handler handler = new Handler(); + private Runnable runnable; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_map_visibility); + + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap map) { + mapboxMap = map; + mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom( + new LatLng(55.754020, 37.620948), 12), 9000); + } + }); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + handler.post(runnable = new VisibilityRunner(mapView, findViewById(R.id.viewParent), handler)); + } + + @Override + protected void onResume() { + super.onResume(); + mapView.onResume(); + } + + private static class VisibilityRunner implements Runnable { + + private MapView mapView; + private View viewParent; + private Handler handler; + private int currentStep; + + VisibilityRunner(MapView mapView, View viewParent, Handler handler) { + this.mapView = mapView; + this.viewParent = viewParent; + this.handler = handler; + } + + @Override + public void run() { + if (isViewHiearchyReady()) { + if (isEvenStep()) { + viewParent.setVisibility(View.VISIBLE); + mapView.setVisibility(View.VISIBLE); + } else if (isFirstOrThirdStep()) { + mapView.setVisibility(getVisibilityForStep()); + } else if (isFifthOrSeventhStep()) { + viewParent.setVisibility(getVisibilityForStep()); + } + updateStep(); + } + handler.postDelayed(this, 1500); + } + + private void updateStep() { + if (currentStep == 7) { + currentStep = 0; + } else { + currentStep++; + } + } + + private int getVisibilityForStep() { + return (currentStep == 1 || currentStep == 5) ? View.GONE : View.INVISIBLE; + } + + private boolean isFifthOrSeventhStep() { + return currentStep == 5 || currentStep == 7; + } + + private boolean isFirstOrThirdStep() { + return currentStep == 1 || currentStep == 3; + } + + private boolean isEvenStep() { + return currentStep == 0 || currentStep % 2 == 0; + } + + private boolean isViewHiearchyReady() { + return mapView != null && viewParent != null; + } + } + + @Override + protected void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + if (runnable != null) { + handler.removeCallbacks(runnable); + runnable = null; + } + mapView.onStop(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_visibility.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_visibility.xml new file mode 100644 index 0000000000..c33034181c --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_map_visibility.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 7f9a08fd30..09f0c307ab 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -53,6 +53,8 @@ Add Custom Sprite Android SDK View integration Simple Map + Map Change Events + Visibility Map Dialog with map Marker views in rectangle Url transform @@ -109,6 +111,8 @@ Hightligh buildings in box Query source for features Shows a simple map + Logs map change events to Logcat + Changes visibility of map and view parent Based on zoom level Use a local file as the style Display a map inside a dialog fragment -- cgit v1.2.1