[android] #2809 - addPolylines and removeAnnotations in JNI, added feature activity + sanity test case
@@ -0,0 +1,34 @@
|
||||
package com.mapbox.mapboxsdk.testapp;
|
||||
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Tests on PolyLineActivity
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class PolylineActivityTest extends BaseTest {
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<PolylineActivity> mActivityRule = new ActivityTestRule<>(
|
||||
PolylineActivity.class);
|
||||
|
||||
private PolylineActivity mActivity = null;
|
||||
|
||||
@Before
|
||||
public void setActivity() {
|
||||
mActivity = mActivityRule.getActivity();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
checkViewIsDisplayed(R.id.mapView);
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,10 @@
|
||||
android:name=".MyLocationTrackingModeActivity"
|
||||
android:label="@string/activity_user_tracking_mode" />
|
||||
|
||||
<activity
|
||||
android:name=".PolylineActivity"
|
||||
android:label="@string/activity_polyline" />
|
||||
|
||||
<meta-data
|
||||
android:name="io.fabric.ApiKey"
|
||||
android:value="9724157045ff7d083492c6d9ae03e60e8609d461" />
|
||||
|
||||
@@ -343,6 +343,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(new Intent(getApplicationContext(), MyLocationTrackingModeActivity.class));
|
||||
return true;
|
||||
|
||||
case R.id.action_polyline:
|
||||
startActivity(new Intent(getApplicationContext(), PolylineActivity.class));
|
||||
return true;
|
||||
|
||||
default:
|
||||
return changeMapStyle(menuItem.getItemId());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.mapbox.mapboxsdk.testapp;
|
||||
|
||||
import android.graphics.Color;
|
||||
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.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Polyline;
|
||||
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
import com.mapbox.mapboxsdk.views.MapView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PolylineActivity extends AppCompatActivity {
|
||||
|
||||
private List<Polyline> mPolyLines;
|
||||
private MapView mMapView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_polyline);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mapView);
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
|
||||
mPolyLines = mMapView.addPolylines(PolylineProvider.getAll());
|
||||
|
||||
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mPolyLines != null && mPolyLines.size() > 0) {
|
||||
if (mPolyLines.size() == 1) {
|
||||
// test for removing annotation
|
||||
mMapView.removeAnnotation(mPolyLines.get(0));
|
||||
} else {
|
||||
// test for removing annotations
|
||||
mMapView.removeAnnotations(mPolyLines);
|
||||
}
|
||||
}
|
||||
mPolyLines = mMapView.addPolylines(PolylineProvider.getRandomLine());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mMapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mMapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mMapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mMapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_polyline, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_id_remove:
|
||||
// test to remove all annotations
|
||||
mMapView.removeAllAnnotations();
|
||||
return true;
|
||||
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static class PolylineProvider {
|
||||
private static final LatLng ANDORRA = new LatLng(42.505777, 1.52529);
|
||||
private static final LatLng LUXEMBOURG = new LatLng(49.815273, 6.129583);
|
||||
private static final LatLng MONACO = new LatLng(43.738418, 7.424616);
|
||||
private static final LatLng VATICAN_CITY = new LatLng(41.902916, 12.453389);
|
||||
private static final LatLng SAN_MARINO = new LatLng(43.942360, 12.457777);
|
||||
private static final LatLng LIECHTENSTEIN = new LatLng(47.166000, 9.555373);
|
||||
|
||||
private static final List<PolylineOptions> POLYLINES = new ArrayList<PolylineOptions>() {{
|
||||
add(generatePolyline(ANDORRA, LUXEMBOURG, "#F44336"));
|
||||
add(generatePolyline(ANDORRA, MONACO, "#FF5722"));
|
||||
add(generatePolyline(MONACO, VATICAN_CITY, "#673AB7"));
|
||||
add(generatePolyline(VATICAN_CITY, SAN_MARINO, "#009688"));
|
||||
add(generatePolyline(SAN_MARINO, LIECHTENSTEIN, "#795548"));
|
||||
add(generatePolyline(LIECHTENSTEIN, LUXEMBOURG, "#3F51B5"));
|
||||
}};
|
||||
|
||||
private static PolylineOptions generatePolyline(LatLng start, LatLng end, String color) {
|
||||
PolylineOptions line = new PolylineOptions();
|
||||
line.add(start);
|
||||
line.add(end);
|
||||
line.color(Color.parseColor(color));
|
||||
return line;
|
||||
}
|
||||
|
||||
public static List<PolylineOptions> getAll() {
|
||||
return POLYLINES;
|
||||
}
|
||||
|
||||
public static List<PolylineOptions> getRandomLine() {
|
||||
List<PolylineOptions> randomLines = new ArrayList<>();
|
||||
Collections.shuffle(POLYLINES);
|
||||
randomLines.add(POLYLINES.get(0));
|
||||
return randomLines;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
After Width: | Height: | Size: 124 B |
|
After Width: | Height: | Size: 161 B |
|
After Width: | Height: | Size: 227 B |
|
After Width: | Height: | Size: 86 B |
|
After Width: | Height: | Size: 115 B |
|
After Width: | Height: | Size: 179 B |
|
After Width: | Height: | Size: 108 B |
|
After Width: | Height: | Size: 151 B |
|
After Width: | Height: | Size: 243 B |
|
After Width: | Height: | Size: 114 B |
|
After Width: | Height: | Size: 194 B |
|
After Width: | Height: | Size: 367 B |
|
After Width: | Height: | Size: 119 B |
|
After Width: | Height: | Size: 243 B |
|
After Width: | Height: | Size: 408 B |
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
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.views.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/toolbar"
|
||||
app:center_latitude="47.798202"
|
||||
app:center_longitude="7.573781"
|
||||
app:style_url="@string/style_mapbox_streets"
|
||||
app:zoom_level="4" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_add_black_24dp"
|
||||
app:backgroundTint="@android:color/white" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -108,6 +108,12 @@
|
||||
android:icon="@drawable/ic_gps_fixed_white_24dp"
|
||||
android:title="@string/activity_user_tracking_mode" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_polyline"
|
||||
android:checkable="false"
|
||||
android:icon="@drawable/ic_trending_up_white_24dp"
|
||||
android:title="@string/activity_polyline"/>
|
||||
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_id_remove"
|
||||
android:icon="@drawable/ic_delete_white_24dp"
|
||||
android:title="@string/action_remove_polylines"
|
||||
mapbox:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
@@ -11,6 +11,7 @@
|
||||
<string name="activity_info_window">InfoWindow Activity</string>
|
||||
<string name="activity_visible_coordinate_bounds">Visible Coordinate Bounds</string>
|
||||
<string name="activity_user_tracking_mode">User tracking mode</string>
|
||||
<string name="activity_polyline">Polyline Activity</string>
|
||||
|
||||
<string name="navdrawer_menu_title_mainactivity_controls">Main Activity Controls</string>
|
||||
<string name="navdrawer_menu_title_mainactivity_styles">Main Activity Styles</string>
|
||||
@@ -27,6 +28,7 @@
|
||||
<string name="action_add_bulk_markers">Add Markers in bulk</string>
|
||||
<string name="action_visible_bounds">Set Visible Bounds</string>
|
||||
<string name="action_visible_bounds_explanation">Center map around 2 markers</string>
|
||||
<string name="action_remove_polylines">Remove polylines</string>
|
||||
|
||||
<string name="label_fps">FPS:</string>
|
||||
|
||||
|
||||