Debian Codegraph @

templates/activities/GoogleMapsWearActivity/root/src/app_package/MapActivity.java.ftl

raw
1 package ${packageName};
2
3 import com.google.android.gms.maps.CameraUpdateFactory;
4 import com.google.android.gms.maps.GoogleMap;
5 import com.google.android.gms.maps.MapFragment;
6 import com.google.android.gms.maps.OnMapReadyCallback;
7 import com.google.android.gms.maps.model.LatLng;
8 import com.google.android.gms.maps.model.MarkerOptions;
9
10 import android.app.Activity;
11 import android.os.Bundle;
12 import android.support.wearable.view.DismissOverlayView;
13 import android.view.View;
14 import android.view.WindowInsets;
15 import android.widget.FrameLayout;
16
17 public class ${activityClass} extends Activity implements OnMapReadyCallback,
18 GoogleMap.OnMapLongClickListener {
19
20 /**
21 * Overlay that shows a short help text when first launched. It also provides an option to
22 * exit the app.
23 */
24 private DismissOverlayView mDismissOverlay;
25
26 /**
27 * The map. It is initialized when the map has been fully loaded and is ready to be used.
28 *
29 * @see #onMapReady(com.google.android.gms.maps.GoogleMap)
30 */
31 private GoogleMap mMap;
32
33 public void onCreate(Bundle savedState) {
34 super.onCreate(savedState);
35
36 // Set the layout. It only contains a MapFragment and a DismissOverlay.
37 setContentView(R.layout.${layoutName});
38
39 // Retrieve the containers for the root of the layout and the map. Margins will need to be
40 // set on them to account for the system window insets.
41 final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.root_container);
42 final FrameLayout mapFrameLayout = (FrameLayout) findViewById(R.id.map_container);
43
44 // Set the system view insets on the containers when they become available.
45 topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
46 @Override
47 public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
48 // Call through to super implementation and apply insets
49 insets = topFrameLayout.onApplyWindowInsets(insets);
50
51 FrameLayout.LayoutParams params =
52 (FrameLayout.LayoutParams) mapFrameLayout.getLayoutParams();
53
54 // Add Wearable insets to FrameLayout container holding map as margins
55 params.setMargins(
56 insets.getSystemWindowInsetLeft(),
57 insets.getSystemWindowInsetTop(),
58 insets.getSystemWindowInsetRight(),
59 insets.getSystemWindowInsetBottom());
60 mapFrameLayout.setLayoutParams(params);
61
62 return insets;
63 }
64 });
65
66 // Obtain the DismissOverlayView and display the introductory help text.
67 mDismissOverlay = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
68 mDismissOverlay.setIntroText(R.string.intro_text);
69 mDismissOverlay.showIntroIfNecessary();
70
71 // Obtain the MapFragment and set the async listener to be notified when the map is ready.
72 MapFragment mapFragment =
73 (MapFragment) getFragmentManager().findFragmentById(R.id.map);
74 mapFragment.getMapAsync(this);
75
76 }
77
78 @Override
79 public void onMapReady(GoogleMap googleMap) {
80 // Map is ready to be used.
81 mMap = googleMap;
82
83 // Set the long click listener as a way to exit the map.
84 mMap.setOnMapLongClickListener(this);
85
86 // Add a marker in Sydney, Australia and move the camera.
87 LatLng sydney = new LatLng(-34, 151);
88 mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
89 mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
90 }
91
92 @Override
93 public void onMapLongClick(LatLng latLng) {
94 // Display the dismiss overlay with a button to exit this activity.
95 mDismissOverlay.show();
96 }
97 }