[android] #2519 - Basic GUI infrastructure for Press For Marker test setup

This commit is contained in:
Brad Leege
2015-10-08 16:00:17 -05:00
parent 709c4fdcee
commit 8e324ddb21
6 changed files with 160 additions and 0 deletions

View File

@@ -33,6 +33,9 @@
android:name=".MapFragmentActivity"
android:label="@string/activity_map_fragment" />
<activity android:name=".PressForMarkerActivity"
android:label="@string/activity_press_for_marker"/>
<meta-data
android:name="io.fabric.ApiKey"
android:value="9724157045ff7d083492c6d9ae03e60e8609d461" />

View File

@@ -287,6 +287,11 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_map_fragment:
startActivity(new Intent(getApplicationContext(), MapFragmentActivity.class));
return true;
case R.id.action_press_for_marker:
startActivity(new Intent(getApplicationContext(), PressForMarkerActivity.class));
return true;
/*
case R.id.followNone:
mMapView.setUserLocationTrackingMode(MapView.UserLocationTrackingMode.NONE);

View File

@@ -0,0 +1,126 @@
package com.mapbox.mapboxsdk.testapp;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.GestureDetector;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;
public class PressForMarkerActivity extends AppCompatActivity {
private static final String TAG = "PressForMarkerActivity";
private MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_press_for_marker);
Toolbar toolbar = (Toolbar) findViewById(R.id.secondToolBar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
mMapView = (MapView) findViewById(R.id.pressForMarkerMapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyleUrl(MapView.StyleUrls.MAPBOX_STREETS);
mMapView.onCreate(savedInstanceState);
mMapView.setCenterCoordinate(new LatLng(47.798202, 7.573781));
mMapView.setZoomLevel(4);
final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(final MotionEvent e) {
float x = e.getX();
float y = e.getY();
final LatLng position = mMapView.fromScreenLocation(new PointF(x, y));
Marker marker = mMapView.addMarker(new MarkerOptions()
.position(position)
.title("Dropped Pin")
.snippet("Tap for directions")
.sprite("default_marker"));
}
});
mMapView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
}
/**
* Dispatch onStart() to all fragments. Ensure any created loaders are
* now started.
*/
@Override
protected void onStart() {
super.onStart();
mMapView.onStart();
}
@Override
protected void onStop() {
super.onStop();
mMapView.onStop();
}
// Called when our app goes into the background
@Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
// Called when our app comes into the foreground
@Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
// Called when the system is running low on memory
@Override
public void onLowMemory() {
super.onLowMemory();
mMapView.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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/secondToolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<com.mapbox.mapboxsdk.views.MapView
android:id="@+id/pressForMarkerMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@@ -84,6 +84,9 @@
android:checkable="false"
android:icon="@drawable/ic_widgets_white_24dp"
android:title="@string/action_map_fragment" />
<item android:id="@+id/action_press_for_marker"
android:title="@string/action_press_for_marker"/>
</menu>
</item>

View File

@@ -3,8 +3,10 @@
<string name="app_name">Mapbox GL</string>
<!-- Test Activities -->
<string name="activity_infowindow_adapter">InfoWindow Adapter</string>
<string name="activity_map_fragment">Map Fragment Activity</string>
<string name="activity_press_for_marker">Press For Marker Activity</string>
<string name="navdrawer_menu_title_mainactivity_controls">Main Activity Controls</string>
<string name="navdrawer_menu_title_mainactivity_styles">Main Activity Styles</string>
@@ -18,6 +20,7 @@
<string name="action_point_annotations">Toggle point annotations</string>
<string name="action_info_window_adapter">InfoWindow Adapter</string>
<string name="action_map_fragment">MapFragment</string>
<string name="action_press_for_marker">Press For Marker</string>
<string name="label_fps">FPS:</string>