[android] #5060 - Initial setup of PressForMarkerActivity

This commit is contained in:
Brad Leege
2016-05-17 17:51:00 -07:00
parent d399de01b8
commit dd5af9e901
4 changed files with 142 additions and 1 deletions

View File

@@ -66,6 +66,13 @@
android:name="@string/category"
android:value="@string/category_annotation" />
</activity>
<activity android:name=".activity.annotation.PressForMarkerActivity"
android:description="@string/description_press_for_marker"
android:label="@string/activity_press_for_marker">
<meta-data
android:name="@string/category"
android:value="@string/category_annotation" />
</activity>
<activity
android:name=".activity.camera.CameraAnimationTypeActivity"
android:description="@string/description_camera_animation_types"

View File

@@ -0,0 +1,113 @@
package com.mapbox.mapboxsdk.testapp.activity.annotation;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
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 java.text.DecimalFormat;
import java.util.ArrayList;
public class PressForMarkerActivity extends AppCompatActivity {
private MapView mapView;
private ArrayList<MarkerOptions> mMarkerList = new ArrayList<>();
private static final DecimalFormat LAT_LON_FORMATTER = new DecimalFormat("#.#####");
private static String STATE_MARKER_LIST = "markerList";
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_press_for_marker);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
mapView = (MapView) findViewById(R.id.pressForMarkerMapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(final MapboxMap mapboxMap) {
mapboxMap.setStyleUrl(Style.getOutdoorsStyleUrl(9));
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(45.1855569, 5.7215506), 11));
mapboxMap.setOnMapLongClickListener(new MapboxMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
final PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
String title = LAT_LON_FORMATTER.format(point.getLatitude()) + ", " + LAT_LON_FORMATTER.format(point.getLongitude());
String snippet = "X = " + (int) pixel.x + ", Y = " + (int) pixel.y;
MarkerOptions marker = new MarkerOptions()
.position(point)
.title(title)
.snippet(snippet);
mMarkerList.add(marker);
mapboxMap.addMarker(marker);
}
});
if (savedInstanceState != null) {
mMarkerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
mapboxMap.addMarkers(mMarkerList);
}
}
});
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/pressForMarkerMapView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"/>
</RelativeLayout>

View File

@@ -16,6 +16,7 @@
<string name="activity_dynamic_marker">Dynamic Marker</string>
<string name="activity_polyline">Polyline</string>
<string name="activity_polygon">Polygon</string>
<string name="activity_press_for_marker">Press Map For Marker</string>
<!-- InfoWindow-->
<string name="activity_info_window">Standard InfoWindow example</string>
@@ -55,7 +56,7 @@
<string name="description_cameraposition">CameraPosition capabilities</string>
<string name="description_map_fragment">Showcase MapFragment</string>
<string name="description_map_fragment_support">Showcase SupportMapFragment</string>
<string name="description_press_for_marker">Example how to add a marker to a Map</string>
<string name="description_press_for_marker">Add marker to map on long press</string>
<string name="description_camera_zoom">Different types of zoom methods</string>
<string name="description_minmax_zoom">Configure a max and min zoomlevel</string>
<string name="description_info_window">Learn how to handle the InfoWindow</string>