[android] #3756 - unit test annotations integration in MapboxMap

[android] #3756 - unit tests fixes

[android] #3756 - allow using inheritance Marker, added example to WindowAdapterActivity
This commit is contained in:
Tobrun
2016-02-05 09:05:35 +01:00
parent ef865f04f6
commit fb9021f929
14 changed files with 714 additions and 335 deletions

View File

@@ -150,7 +150,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
public LoadBulkMarkerTask(Context context, MapboxMap mapboxMap, int amount) {
mMapboxMap = mapboxMap;
mapboxMap.removeAllAnnotations();
mapboxMap.removeAnnotations();
mProgressDialog = ProgressDialog.show(context, "Loading", "Fetching markers", false);
mAppContext = context.getApplicationContext();
mAmount = amount;

View File

@@ -78,7 +78,7 @@ public class GeocoderActivity extends AppCompatActivity {
@Override
public void onMapClick(@NonNull LatLng point) {
setMessage("Geocoding...");
mapboxMap.removeAllAnnotations();
mapboxMap.removeAnnotations();
mapboxMap.addMarker(new MarkerOptions()
.position(point)
.title("Your finger is here"));

View File

@@ -16,10 +16,11 @@ import android.widget.TextView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.annotations.CityStateMarker;
import com.mapbox.mapboxsdk.testapp.annotations.CityStateMarkerOptions;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.maps.MapView;
@@ -54,12 +55,12 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
// add markers
mapboxMap.addMarker(generateMarker("Andorra", 42.505777, 1.52529, "#F44336"));
mapboxMap.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5"));
mapboxMap.addMarker(generateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));
mapboxMap.addMarker(generateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
mapboxMap.addMarker(generateMarker("San Marino", 43.942360, 12.457777, "#795548"));
mapboxMap.addMarker(generateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));
mapboxMap.addMarker(generateCityStateMarker("Andorra", 42.505777, 1.52529, "#F44336"));
mapboxMap.addMarker(generateCityStateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5"));
mapboxMap.addMarker(generateCityStateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));
mapboxMap.addMarker(generateCityStateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
mapboxMap.addMarker(generateCityStateMarker("San Marino", 43.942360, 12.457777, "#795548"));
mapboxMap.addMarker(generateCityStateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));
// add custom window adapter
mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
@@ -71,7 +72,12 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
TextView textView = new TextView(InfoWindowAdapterActivity.this);
textView.setText(marker.getTitle());
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.parseColor(marker.getSnippet()));
if(marker instanceof CityStateMarker){
CityStateMarker cityStateMarker = (CityStateMarker)marker;
textView.setBackgroundColor(Color.parseColor(cityStateMarker.getInfoWindowBackgroundColor()));
}
textView.setPadding(tenDp, tenDp, tenDp, tenDp);
return textView;
}
@@ -80,13 +86,13 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
});
}
private MarkerOptions generateMarker(String title, double lat, double lng, String color) {
MarkerOptions marker = new MarkerOptions();
private CityStateMarkerOptions generateCityStateMarker(String title, double lat, double lng, String color) {
CityStateMarkerOptions marker = new CityStateMarkerOptions();
marker.title(title);
marker.snippet(color);
marker.position(new LatLng(lat, lng));
marker.infoWindowBackground(color);
mIconDrawable.setColorFilter(Color.parseColor(marker.getSnippet()), PorterDuff.Mode.SRC_IN);
mIconDrawable.setColorFilter(Color.parseColor(color), PorterDuff.Mode.SRC_IN);
Icon icon = mIconFactory.fromDrawable(mIconDrawable);
marker.icon(icon);
return marker;
@@ -144,4 +150,5 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -655,7 +655,7 @@ public class MainActivity extends AppCompatActivity {
private void removeAnnotations() {
mMarkerList.clear();
mMapboxMap.removeAllAnnotations();
mMapboxMap.removeAnnotations();
}
private void addCustomLayer() {

View File

@@ -169,7 +169,7 @@ public class PolylineActivity extends AppCompatActivity {
case R.id.action_id_remove:
// test to remove all annotations
mPolylineOptions.clear();
mMapboxMap.removeAllAnnotations();
mMapboxMap.removeAnnotations();
return true;
case android.R.id.home:

View File

@@ -0,0 +1,18 @@
package com.mapbox.mapboxsdk.testapp.annotations;
import com.mapbox.mapboxsdk.annotations.Marker;
public class CityStateMarker extends Marker {
private String mInfoWindowBackgroundColor;
public CityStateMarker(CityStateMarkerOptions cityStateOptions, String color) {
super(cityStateOptions);
mInfoWindowBackgroundColor = color;
}
public String getInfoWindowBackgroundColor() {
return mInfoWindowBackgroundColor;
}
}

View File

@@ -0,0 +1,68 @@
package com.mapbox.mapboxsdk.testapp.annotations;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
public class CityStateMarkerOptions extends BaseMarkerOptions<CityStateMarker, CityStateMarkerOptions> {
private String mInfoWindowBackgroundColor;
public CityStateMarkerOptions infoWindowBackground(String color) {
mInfoWindowBackgroundColor = color;
return getThis();
}
public CityStateMarkerOptions() {
}
private CityStateMarkerOptions(Parcel in) {
position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
snippet(in.readString());
String iconId = in.readString();
Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
Icon icon = IconFactory.recreate(iconId, iconBitmap);
icon(icon);
title(in.readString());
}
@Override
public CityStateMarkerOptions getThis() {
return this;
}
@Override
public CityStateMarker getMarker() {
return new CityStateMarker(this, mInfoWindowBackgroundColor);
}
public static final Parcelable.Creator<CityStateMarkerOptions> CREATOR
= new Parcelable.Creator<CityStateMarkerOptions>() {
public CityStateMarkerOptions createFromParcel(Parcel in) {
return new CityStateMarkerOptions(in);
}
public CityStateMarkerOptions[] newArray(int size) {
return new CityStateMarkerOptions[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(position, flags);
out.writeString(snippet);
out.writeString(icon.getId());
out.writeParcelable(icon.getBitmap(), flags);
out.writeString(title);
}
}