3
import android.graphics.Bitmap;
4
import android.graphics.Color;
5
import android.os.Bundle;
6
import android.os.Parcel;
7
import android.os.Parcelable;
8
import android.view.LayoutInflater;
9
import android.view.View;
10
import android.widget.ImageView;
11
import android.widget.TextView;
13
import ai.nextbillion.maps.annotations.BaseMarkerOptions;
14
import ai.nextbillion.maps.annotations.Icon;
15
import ai.nextbillion.maps.annotations.IconFactory;
16
import ai.nextbillion.maps.annotations.Marker;
17
import ai.nextbillion.maps.core.MapView;
18
import ai.nextbillion.maps.core.NextbillionMap;
19
import ai.nextbillion.maps.core.OnMapReadyCallback;
20
import ai.nextbillion.maps.core.Style;
21
import ai.nextbillion.maps.geometry.LatLng;
22
import ai.nextbillion.utils.SymbolGenerator;
23
import androidx.annotation.NonNull;
24
import androidx.annotation.Nullable;
25
import androidx.appcompat.app.AppCompatActivity;
27
public class CustomInfoWindowActivity extends AppCompatActivity implements OnMapReadyCallback {
29
private MapView mapView;
30
private NextbillionMap mMap;
31
private ImageView ivBack;
34
protected void onCreate(Bundle savedInstanceState) {
35
super.onCreate(savedInstanceState);
36
setContentView(R.layout.activity_animate_markers);
38
ivBack = findViewById(R.id.iv_back);
39
mapView = findViewById(R.id.map_view);
40
mapView.onCreate(savedInstanceState);
41
mapView.getMapAsync(this);
43
ivBack.setOnClickListener(v -> finish());
47
public void onMapReady(@NonNull NextbillionMap nextbillionMap) {
48
mMap = nextbillionMap;
49
mMap.getStyle(new Style.OnStyleLoaded() {
51
public void onStyleLoaded(@NonNull Style style) {
52
customiseInfoWindow();
59
///////////////////////////////////////////////////////////////////////////
61
///////////////////////////////////////////////////////////////////////////
63
private Bitmap generateTextIcon() {
64
// View view = LayoutInflater.from(this).inflate(R.layout.text_marker_layout, mapView, false);
65
View view = LayoutInflater.from(this).inflate(R.layout.custom_marker_layout, mapView, false);
66
return SymbolGenerator.generate(view);
69
private void addMarker() {
70
Bitmap iconBitmap = generateTextIcon();
71
Icon icon = IconFactory.getInstance(this).fromBitmap(iconBitmap);
72
mMap.addMarker(new CustomMarkerOptions().icon(icon).position(new LatLng(53.55095026373886, 9.992248999933745)));
76
///////////////////////////////////////////////////////////////////////////
77
// Customise InfoWindow
78
///////////////////////////////////////////////////////////////////////////
80
private void customiseInfoWindow() {
81
mMap.setInfoWindowAdapter(new NextbillionMap.InfoWindowAdapter() {
84
public View getInfoWindow(@NonNull Marker marker) {
85
String title = marker.getTitle();
86
if (marker instanceof CustomMarker) {
87
View infoWidow = LayoutInflater.from(CustomInfoWindowActivity.this).inflate(R.layout.custom_info_window, mapView, false);
88
TextView infoText = infoWidow.findViewById(R.id.info_text);
89
// int color = ((CustomMarker) marker).getInfoWindowColor();
90
// TextView textView = defaultTextView(title);
91
// textView.setBackgroundColor(color);
95
return defaultTextView(title);
100
private TextView defaultTextView(String text) {
101
TextView textView = new TextView(this);
102
int sixteenDp = (int) getResources().getDimension(R.dimen.attr_margin);
103
textView.setText(text);
104
textView.setTextColor(Color.WHITE);
105
textView.setPadding(sixteenDp, sixteenDp, sixteenDp, sixteenDp);
109
static class CustomMarker extends Marker {
111
private final int infoWindowColor;
113
public CustomMarker(BaseMarkerOptions baseMarkerOptions, int color) {
114
super(baseMarkerOptions);
115
infoWindowColor = color;
118
public int getInfoWindowColor() {
119
return infoWindowColor;
123
static class CustomMarkerOptions extends BaseMarkerOptions<CustomMarker, CustomMarkerOptions> {
127
public CustomMarkerOptions() {
130
public CustomMarkerOptions infoWindowColor(int color) {
136
public CustomMarkerOptions getThis() {
141
public CustomMarker getMarker() {
142
return new CustomMarker(this, color);
145
private CustomMarkerOptions(Parcel in) {
146
position((LatLng) in.readParcelable(LatLng.class.getClassLoader()));
147
snippet(in.readString());
148
String iconId = in.readString();
149
Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());
150
Icon icon = IconFactory.recreate(iconId, iconBitmap);
152
title(in.readString());
153
infoWindowColor(in.readInt());
156
public static final Parcelable.Creator<CustomMarkerOptions> CREATOR
157
= new Parcelable.Creator<CustomMarkerOptions>() {
158
public CustomMarkerOptions createFromParcel(Parcel in) {
159
return new CustomMarkerOptions(in);
162
public CustomMarkerOptions[] newArray(int size) {
163
return new CustomMarkerOptions[size];
168
public int describeContents() {
173
public void writeToParcel(Parcel out, int flags) {
174
out.writeParcelable(position, flags);
175
out.writeString(snippet);
176
out.writeString(icon.getId());
177
out.writeParcelable(icon.getBitmap(), flags);
178
out.writeString(title);
183
///////////////////////////////////////////////////////////////////////////
185
///////////////////////////////////////////////////////////////////////////
188
protected void onStart() {
194
protected void onResume() {
200
protected void onPause() {
206
protected void onStop() {
212
protected void onSaveInstanceState(@NonNull Bundle outState) {
213
super.onSaveInstanceState(outState);
214
mapView.onSaveInstanceState(outState);
218
protected void onDestroy() {
224
public void onLowMemory() {
226
mapView.onLowMemory();