[android] - add Map change & visibility test activities (#9425)

This commit is contained in:
Tobrun
2017-07-07 10:36:46 +02:00
committed by GitHub
parent 721557bba2
commit 950ab7eb8a
5 changed files with 300 additions and 0 deletions

View File

@@ -414,6 +414,28 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
android:name=".activity.maplayout.MapChangeActivity"
android:description="@string/description_map_change"
android:label="@string/activity_map_change">
<meta-data
android:name="@string/category"
android:value="@string/category_maplayout"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
android:name=".activity.maplayout.VisibilityChangeActivity"
android:description="@string/description_visibility_map"
android:label="@string/activity_map_visibility">
<meta-data
android:name="@string/category"
android:value="@string/category_maplayout"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
android:name=".activity.style.RuntimeStyleActivity"
android:description="@string/description_runtime_style"

View File

@@ -0,0 +1,111 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
import android.os.Bundle;
import android.support.v4.util.LongSparseArray;
import android.support.v7.app.AppCompatActivity;
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;
import timber.log.Timber;
/**
* Test activity showcasing how to listen to map change events.
*/
public class MapChangeActivity extends AppCompatActivity {
private MapView mapView;
private MapboxMap mapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_simple);
final LongSparseArray<String> 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<String> buildMapChangeStringValueSparseArray() {
LongSparseArray<String> 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);
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/viewParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.maplayout.SimpleMapActivity">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"/>
</LinearLayout>

View File

@@ -53,6 +53,8 @@
<string name="activity_add_sprite">Add Custom Sprite</string>
<string name="activity_navigation_drawer">Android SDK View integration</string>
<string name="activity_simple_map">Simple Map</string>
<string name="activity_map_change">Map Change Events</string>
<string name="activity_map_visibility">Visibility Map</string>
<string name="activity_map_in_dialog">Dialog with map</string>
<string name="activity_marker_view_rectangle">Marker views in rectangle</string>
<string name="activity_url_transform">Url transform</string>
@@ -109,6 +111,8 @@
<string name="description_query_rendered_features_box_highlight">Hightligh buildings in box</string>
<string name="description_query_source_features">Query source for features</string>
<string name="description_simple_map">Shows a simple map</string>
<string name="description_map_change">Logs map change events to Logcat</string>
<string name="description_visibility_map">Changes visibility of map and view parent</string>
<string name="description_add_remove_markers">Based on zoom level</string>
<string name="description_style_file">Use a local file as the style</string>
<string name="description_map_in_dialog">Display a map inside a dialog fragment</string>