Skip to content

Commit d918a33

Browse files
committed
Add TranslucentMapActivity demo
1 parent 78b0926 commit d918a33

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

tangramdemos/src/main/AndroidManifest.xml

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
android:label="@string/simplemap_title"
5252
android:exported="true"
5353
android:parentActivityName=".DemoMainActivity"/>
54+
<activity
55+
android:name=".TranslucentMapActivity"
56+
android:label="@string/translucency_title"
57+
android:exported="true"
58+
android:parentActivityName=".DemoMainActivity"/>
5459
</application>
5560

5661
</manifest>

tangramdemos/src/main/java/com/mapzen/tangramdemos/DemoDetails.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ public Class<? extends AppCompatActivity> getActivityClass() {
5252
new DemoDetails(R.string.markers_title, R.string.markers_detail, MarkersActivity.class),
5353
new DemoDetails(R.string.multimap_title, R.string.multimap_detail, MultiMapActivity.class),
5454
new DemoDetails(R.string.sceneupdates_title, R.string.sceneupdates_detail, SceneUpdatesActivity.class),
55+
new DemoDetails(R.string.translucency_title, R.string.translucency_detail, TranslucentMapActivity.class),
5556
};
5657
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.mapzen.tangramdemos;
2+
3+
import android.os.Bundle;
4+
import android.widget.ImageView;
5+
6+
import androidx.appcompat.app.ActionBar;
7+
import androidx.appcompat.app.AppCompatActivity;
8+
9+
import com.mapzen.tangram.MapController;
10+
import com.mapzen.tangram.MapView;
11+
import com.mapzen.tangram.SceneUpdate;
12+
import com.mapzen.tangram.networking.HttpHandler;
13+
import com.mapzen.tangram.viewholder.GLViewHolderFactory;
14+
import com.mapzen.tangram.viewholder.TextureViewHolderFactory;
15+
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
19+
public class TranslucentMapActivity extends AppCompatActivity implements MapView.MapReadyCallback {
20+
21+
// MapController is the main class used to interact with a Tangram map.
22+
MapController map;
23+
24+
// MapView is the View used to display the map.
25+
MapView view;
26+
27+
@Override
28+
protected void onCreate(Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(R.layout.activity_translucency);
31+
32+
// Set up back button to return to the demo list.
33+
ActionBar actionBar = getSupportActionBar();
34+
if (actionBar != null) {
35+
actionBar.setDisplayHomeAsUpEnabled(true);
36+
}
37+
38+
// Our MapView is declared in the layout file.
39+
view = (MapView)findViewById(R.id.map);
40+
41+
// Lifecycle events from the Activity must be forwarded to the MapView.
42+
view.onCreate(savedInstanceState);
43+
44+
// Create an HttpHandler to cache map tiles.
45+
HttpHandler httpHandler = new CachingHttpHandler(getExternalCacheDir());
46+
47+
// Create a factory to build a TextureView with translucency enabled.
48+
GLViewHolderFactory factory = new TextureViewHolderFactory(true);
49+
50+
// Start a background process to set up the map.
51+
view.getMapAsync(this, factory, httpHandler);
52+
}
53+
54+
@Override
55+
public void onMapReady(MapController mapController) {
56+
// We receive a MapController object in this callback when the map is ready for use.
57+
map = mapController;
58+
59+
// Set our API key as a scene update.
60+
List<SceneUpdate> updates = new ArrayList<>();
61+
updates.add(new SceneUpdate("global.sdk_api_key", BuildConfig.NEXTZEN_API_KEY));
62+
63+
// Update the scene background color to be translucent.
64+
updates.add(new SceneUpdate("scene.background.color", "[0, 0, 0, 0]"));
65+
66+
map.loadSceneFileAsync("bubble-wrap/bubble-wrap-style.yaml", updates);
67+
}
68+
69+
// Below are the remaining Activity lifecycle events that must be forwarded to our MapView.
70+
71+
@Override
72+
public void onResume() {
73+
super.onResume();
74+
view.onResume();
75+
}
76+
77+
@Override
78+
public void onPause() {
79+
super.onPause();
80+
view.onPause();
81+
}
82+
83+
@Override
84+
public void onDestroy() {
85+
super.onDestroy();
86+
view.onDestroy();
87+
}
88+
89+
@Override
90+
public void onLowMemory() {
91+
super.onLowMemory();
92+
view.onLowMemory();
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
tools:context=".SimpleMapActivity">
9+
10+
<ImageView
11+
android:id="@+id/imageView"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
android:background="#FFD180"
15+
android:contentDescription="@null"
16+
android:scaleType="center"
17+
app:srcCompat="@drawable/mapzen_logo" />
18+
19+
<com.mapzen.tangram.MapView
20+
android:id="@+id/map"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"/>
23+
</RelativeLayout>

tangramdemos/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<string name="sceneupdates_detail">Modify the scene file on the fly</string>
1515
<string name="simplemap_title">Simple Map</string>
1616
<string name="simplemap_detail">Basic map sample</string>
17+
<string name="translucency_title">Translucent Map</string>
18+
<string name="translucency_detail">Render a map with translucency</string>
1719
<string name="wtc">World Trade Center</string>
1820
<string name="esb">Empire State Building</string>
1921
<string name="cpz">Central Park Zoo</string>

0 commit comments

Comments
 (0)