Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 04ac363

Browse files
ivovandongentobrun
authored andcommitted
[android] test app - texture view test activities
1 parent 4fc8a46 commit 04ac363

File tree

11 files changed

+744
-2
lines changed

11 files changed

+744
-2
lines changed

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
2929
import com.mapbox.mapboxsdk.constants.MapboxConstants;
3030
import com.mapbox.mapboxsdk.constants.Style;
31-
import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer;
3231
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
32+
import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer;
3333
import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer;
3434
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
3535
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
@@ -50,7 +50,6 @@
5050

5151
import timber.log.Timber;
5252

53-
import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
5453
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
5554
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
5655

platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml

+23
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,29 @@
728728
android:value="@string/category_maplayout"/>
729729
</activity>
730730

731+
<!-- TextureView -->
732+
<activity android:name=".activity.textureview.TextureViewDebugModeActivity"
733+
android:description="@string/description_textureview_debug"
734+
android:label="@string/activity_textureview_debug">
735+
<meta-data
736+
android:name="@string/category"
737+
android:value="@string/category_textureview"/>
738+
</activity>
739+
<activity android:name=".activity.textureview.TextureViewResizeActivity"
740+
android:description="@string/description_textureview_resize"
741+
android:label="@string/activity_textureview_resize">
742+
<meta-data
743+
android:name="@string/category"
744+
android:value="@string/category_textureview"/>
745+
</activity>
746+
<activity android:name=".activity.textureview.TextureViewAnimationActivity"
747+
android:description="@string/description_textureview_animate"
748+
android:label="@string/activity_textureview_animate">
749+
<meta-data
750+
android:name="@string/category"
751+
android:value="@string/category_textureview"/>
752+
</activity>
753+
731754
<!-- For Instrumentation tests -->
732755
<activity
733756
android:name=".activity.style.RuntimeStyleTestActivity"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package com.mapbox.mapboxsdk.testapp.activity.textureview;
2+
3+
import android.animation.ObjectAnimator;
4+
import android.os.Bundle;
5+
import android.os.Handler;
6+
import android.support.v7.app.ActionBar;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.widget.TextView;
9+
10+
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
11+
import com.mapbox.mapboxsdk.geometry.LatLng;
12+
import com.mapbox.mapboxsdk.maps.MapView;
13+
import com.mapbox.mapboxsdk.maps.MapboxMap;
14+
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
15+
import com.mapbox.mapboxsdk.testapp.R;
16+
17+
import java.util.Locale;
18+
19+
/**
20+
* Test animating a {@link android.view.TextureView} backed map.
21+
*/
22+
public class TextureViewAnimationActivity extends AppCompatActivity {
23+
24+
private MapView mapView;
25+
private MapboxMap mapboxMap;
26+
private Handler handler;
27+
private Runnable delayed;
28+
29+
private static LatLng[] PLACES = {
30+
new LatLng(37.7749, -122.4194), // SF
31+
new LatLng(38.9072, -77.0369), // DC
32+
new LatLng(52.3702, 4.8952), // AMS
33+
new LatLng(60.1699, 24.9384), // HEL
34+
new LatLng(-13.1639, -74.2236), // AYA
35+
new LatLng(52.5200, 13.4050), // BER
36+
new LatLng(12.9716, 77.5946), // BAN
37+
new LatLng(31.2304, 121.4737) // SHA
38+
};
39+
40+
@Override
41+
protected void onCreate(Bundle savedInstanceState) {
42+
super.onCreate(savedInstanceState);
43+
setContentView(R.layout.activity_textureview_animate);
44+
handler = new Handler(getMainLooper());
45+
setupToolbar();
46+
setupMapView(savedInstanceState);
47+
}
48+
49+
private void setupToolbar() {
50+
ActionBar actionBar = getSupportActionBar();
51+
if (actionBar != null) {
52+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
53+
getSupportActionBar().setHomeButtonEnabled(true);
54+
}
55+
}
56+
57+
private void setupMapView(Bundle savedInstanceState) {
58+
mapView = (MapView) findViewById(R.id.mapView);
59+
mapView.getMapAsync(new OnMapReadyCallback() {
60+
@Override
61+
public void onMapReady(MapboxMap mapboxMap) {
62+
TextureViewAnimationActivity.this.mapboxMap = mapboxMap;
63+
64+
setFpsView(mapboxMap);
65+
66+
// Animate the map view
67+
ObjectAnimator animation = ObjectAnimator.ofFloat(mapView, "rotationY", 0.0f, 360f);
68+
animation.setDuration(3600);
69+
animation.setRepeatCount(ObjectAnimator.INFINITE);
70+
animation.start();
71+
72+
// Start an animation on the map as well
73+
flyTo(mapboxMap, 0, 14);
74+
}
75+
});
76+
}
77+
78+
private void flyTo(final MapboxMap mapboxMap, final int place, final double zoom) {
79+
mapboxMap.animateCamera(
80+
CameraUpdateFactory.newLatLngZoom(PLACES[place], zoom),
81+
10000,
82+
new MapboxMap.CancelableCallback() {
83+
@Override
84+
public void onCancel() {
85+
delayed = new Runnable() {
86+
@Override
87+
public void run() {
88+
delayed = null;
89+
flyTo(mapboxMap, place, zoom);
90+
}
91+
};
92+
handler.postDelayed(delayed, 2000);
93+
}
94+
95+
@Override
96+
public void onFinish() {
97+
flyTo(mapboxMap, place == (PLACES.length - 1) ? 0 : place + 1, zoom);
98+
}
99+
});
100+
}
101+
102+
private void setFpsView(MapboxMap mapboxMap) {
103+
final TextView fpsView = (TextView) findViewById(R.id.fpsView);
104+
mapboxMap.setOnFpsChangedListener(new MapboxMap.OnFpsChangedListener() {
105+
@Override
106+
public void onFpsChanged(double fps) {
107+
fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps));
108+
}
109+
});
110+
}
111+
112+
@Override
113+
protected void onStart() {
114+
super.onStart();
115+
mapView.onStart();
116+
}
117+
118+
@Override
119+
protected void onResume() {
120+
super.onResume();
121+
mapView.onResume();
122+
}
123+
124+
@Override
125+
protected void onPause() {
126+
super.onPause();
127+
mapView.onPause();
128+
}
129+
130+
@Override
131+
protected void onStop() {
132+
super.onStop();
133+
mapView.onStop();
134+
if (handler != null && delayed != null) {
135+
handler.removeCallbacks(delayed);
136+
}
137+
}
138+
139+
@Override
140+
protected void onSaveInstanceState(Bundle outState) {
141+
super.onSaveInstanceState(outState);
142+
mapView.onSaveInstanceState(outState);
143+
}
144+
145+
@Override
146+
protected void onDestroy() {
147+
super.onDestroy();
148+
mapView.onDestroy();
149+
}
150+
151+
@Override
152+
public void onLowMemory() {
153+
super.onLowMemory();
154+
mapView.onLowMemory();
155+
}
156+
157+
}

0 commit comments

Comments
 (0)