26
26
*/
27
27
public class InfoWindow {
28
28
29
- private WeakReference <Marker > mBoundMarker ;
30
- private WeakReference <MapboxMap > mMapboxMap ;
31
- protected WeakReference <View > mView ;
29
+ private WeakReference <Marker > boundMarker ;
30
+ private WeakReference <MapboxMap > mapboxMap ;
31
+ protected WeakReference <View > view ;
32
32
33
- private float mMarkerHeightOffset ;
34
- private float mMarkerWidthOffset ;
35
- private float mViewWidthOffset ;
36
- private PointF mCoordinates ;
37
- private boolean mIsVisible ;
33
+ private float markerHeightOffset ;
34
+ private float markerWidthOffset ;
35
+ private float viewWidthOffset ;
36
+ private PointF coordinates ;
37
+ private boolean isVisible ;
38
38
39
39
@ LayoutRes
40
- private int mLayoutRes ;
40
+ private int layoutRes ;
41
41
42
42
InfoWindow (MapView mapView , int layoutResId , MapboxMap mapboxMap ) {
43
- mLayoutRes = layoutResId ;
43
+ layoutRes = layoutResId ;
44
44
View view = LayoutInflater .from (mapView .getContext ()).inflate (layoutResId , mapView , false );
45
45
initialize (view , mapboxMap );
46
46
}
@@ -50,14 +50,14 @@ public class InfoWindow {
50
50
}
51
51
52
52
private void initialize (View view , MapboxMap mapboxMap ) {
53
- mMapboxMap = new WeakReference <>(mapboxMap );
54
- mIsVisible = false ;
55
- mView = new WeakReference <>(view );
53
+ this . mapboxMap = new WeakReference <>(mapboxMap );
54
+ isVisible = false ;
55
+ this . view = new WeakReference <>(view );
56
56
57
57
view .setOnClickListener (new View .OnClickListener () {
58
58
@ Override
59
59
public void onClick (View v ) {
60
- MapboxMap mapboxMap = mMapboxMap .get ();
60
+ MapboxMap mapboxMap = InfoWindow . this . mapboxMap .get ();
61
61
if (mapboxMap != null ) {
62
62
MapboxMap .OnInfoWindowClickListener onInfoWindowClickListener = mapboxMap .getOnInfoWindowClickListener ();
63
63
boolean handledDefaultClick = false ;
@@ -76,7 +76,7 @@ public void onClick(View v) {
76
76
view .setOnLongClickListener (new View .OnLongClickListener () {
77
77
@ Override
78
78
public boolean onLongClick (View v ) {
79
- MapboxMap mapboxMap = mMapboxMap .get ();
79
+ MapboxMap mapboxMap = InfoWindow . this . mapboxMap .get ();
80
80
if (mapboxMap != null ) {
81
81
MapboxMap .OnInfoWindowLongClickListener listener = mapboxMap .getOnInfoWindowLongClickListener ();
82
82
if (listener != null ) {
@@ -103,19 +103,19 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
103
103
104
104
MapView .LayoutParams lp = new MapView .LayoutParams (MapView .LayoutParams .WRAP_CONTENT , MapView .LayoutParams .WRAP_CONTENT );
105
105
106
- MapboxMap mapboxMap = mMapboxMap .get ();
107
- View view = mView .get ();
106
+ MapboxMap mapboxMap = this . mapboxMap .get ();
107
+ View view = this . view .get ();
108
108
if (view != null && mapboxMap != null ) {
109
109
view .measure (View .MeasureSpec .UNSPECIFIED , View .MeasureSpec .UNSPECIFIED );
110
110
111
111
// Calculate y-offset for update method
112
- mMarkerHeightOffset = -view .getMeasuredHeight () + offsetY ;
113
- mMarkerWidthOffset = -offsetX ;
112
+ markerHeightOffset = -view .getMeasuredHeight () + offsetY ;
113
+ markerWidthOffset = -offsetX ;
114
114
115
115
// Calculate default Android x,y coordinate
116
- mCoordinates = mapboxMap .getProjection ().toScreenLocation (position );
117
- float x = mCoordinates .x - (view .getMeasuredWidth () / 2 ) + offsetX ;
118
- float y = mCoordinates .y - view .getMeasuredHeight () + offsetY ;
116
+ coordinates = mapboxMap .getProjection ().toScreenLocation (position );
117
+ float x = coordinates .x - (view .getMeasuredWidth () / 2 ) + offsetX ;
118
+ float y = coordinates .y - view .getMeasuredHeight () + offsetY ;
119
119
120
120
if (view instanceof InfoWindowView ) {
121
121
// only apply repositioning/margin for InfoWindowView
@@ -175,11 +175,11 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
175
175
view .setY (y );
176
176
177
177
// Calculate x-offset for update method
178
- mViewWidthOffset = x - mCoordinates .x - offsetX ;
178
+ viewWidthOffset = x - coordinates .x - offsetX ;
179
179
180
180
close (); //if it was already opened
181
181
mapView .addView (view , lp );
182
- mIsVisible = true ;
182
+ isVisible = true ;
183
183
}
184
184
return this ;
185
185
}
@@ -190,10 +190,10 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
190
190
* @return this info window
191
191
*/
192
192
InfoWindow close () {
193
- MapboxMap mapboxMap = mMapboxMap .get ();
194
- if (mIsVisible && mapboxMap != null ) {
195
- mIsVisible = false ;
196
- View view = mView .get ();
193
+ MapboxMap mapboxMap = this . mapboxMap .get ();
194
+ if (isVisible && mapboxMap != null ) {
195
+ isVisible = false ;
196
+ View view = this . view .get ();
197
197
if (view != null && view .getParent () != null ) {
198
198
((ViewGroup ) view .getParent ()).removeView (view );
199
199
}
@@ -216,12 +216,12 @@ InfoWindow close() {
216
216
* @param overlayItem the tapped overlay item
217
217
*/
218
218
void adaptDefaultMarker (Marker overlayItem , MapboxMap mapboxMap , MapView mapView ) {
219
- View view = mView .get ();
219
+ View view = this . view .get ();
220
220
if (view == null ) {
221
- view = LayoutInflater .from (mapView .getContext ()).inflate (mLayoutRes , mapView , false );
221
+ view = LayoutInflater .from (mapView .getContext ()).inflate (layoutRes , mapView , false );
222
222
initialize (view , mapboxMap );
223
223
}
224
- mMapboxMap = new WeakReference <>(mapboxMap );
224
+ this . mapboxMap = new WeakReference <>(mapboxMap );
225
225
String title = overlayItem .getTitle ();
226
226
TextView titleTextView = ((TextView ) view .findViewById (R .id .infowindow_title ));
227
227
if (!TextUtils .isEmpty (title )) {
@@ -242,39 +242,39 @@ void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView
242
242
}
243
243
244
244
InfoWindow setBoundMarker (Marker boundMarker ) {
245
- mBoundMarker = new WeakReference <>(boundMarker );
245
+ this . boundMarker = new WeakReference <>(boundMarker );
246
246
return this ;
247
247
}
248
248
249
249
Marker getBoundMarker () {
250
- if (mBoundMarker == null ) {
250
+ if (boundMarker == null ) {
251
251
return null ;
252
252
}
253
- return mBoundMarker .get ();
253
+ return boundMarker .get ();
254
254
}
255
255
256
256
public void update () {
257
- MapboxMap mapboxMap = mMapboxMap .get ();
258
- Marker marker = mBoundMarker .get ();
259
- View view = mView .get ();
257
+ MapboxMap mapboxMap = this . mapboxMap .get ();
258
+ Marker marker = boundMarker .get ();
259
+ View view = this . view .get ();
260
260
if (mapboxMap != null && marker != null && view != null ) {
261
- mCoordinates = mapboxMap .getProjection ().toScreenLocation (marker .getPosition ());
261
+ coordinates = mapboxMap .getProjection ().toScreenLocation (marker .getPosition ());
262
262
263
263
if (view instanceof InfoWindowView ) {
264
- view .setX (mCoordinates .x + mViewWidthOffset - mMarkerWidthOffset );
264
+ view .setX (coordinates .x + viewWidthOffset - markerWidthOffset );
265
265
} else {
266
- view .setX (mCoordinates .x - (view .getMeasuredWidth () / 2 ) - mMarkerWidthOffset );
266
+ view .setX (coordinates .x - (view .getMeasuredWidth () / 2 ) - markerWidthOffset );
267
267
}
268
- view .setY (mCoordinates .y + mMarkerHeightOffset );
268
+ view .setY (coordinates .y + markerHeightOffset );
269
269
}
270
270
}
271
271
272
272
public View getView () {
273
- return mView != null ? mView .get () : null ;
273
+ return view != null ? view .get () : null ;
274
274
}
275
275
276
276
boolean isVisible () {
277
- return mIsVisible ;
277
+ return isVisible ;
278
278
}
279
279
280
280
}
0 commit comments