|
| 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 | +} |
0 commit comments