Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 1a811b0

Browse files
committed
[android] #6109 - cleanup Hungarian notation sdk and test app, added some javadocs todo for public api on mapboxmap
1 parent 50da6e5 commit 1a811b0

29 files changed

+1269
-1225
lines changed

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
* @see Marker
1111
*/
1212
public class Icon {
13-
private Bitmap mBitmap;
14-
private String mId;
13+
private Bitmap bitmap;
14+
private String id;
1515

1616
Icon(String id, Bitmap bitmap) {
17-
mId = id;
18-
mBitmap = bitmap;
17+
this.id = id;
18+
this.bitmap = bitmap;
1919
}
2020

2121
public String getId() {
22-
return mId;
22+
return id;
2323
}
2424

2525
public Bitmap getBitmap() {
26-
return mBitmap;
26+
return bitmap;
2727
}
2828

2929
@Override
@@ -33,19 +33,19 @@ public boolean equals(Object o) {
3333

3434
Icon icon = (Icon) o;
3535

36-
if (!mBitmap.equals(icon.mBitmap)) return false;
37-
return mId.equals(icon.mId);
36+
if (!bitmap.equals(icon.bitmap)) return false;
37+
return id.equals(icon.id);
3838

3939
}
4040

4141
@Override
4242
public int hashCode() {
4343
int result = 0;
44-
if (mBitmap != null) {
45-
result = mBitmap.hashCode();
44+
if (bitmap != null) {
45+
result = bitmap.hashCode();
4646
}
47-
if (mId != null) {
48-
result = 31 * result + mId.hashCode();
47+
if (id != null) {
48+
result = 31 * result + id.hashCode();
4949
}
5050
return result;
5151
}

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ public final class IconFactory {
3030

3131
private static final String ICON_ID_PREFIX = "com.mapbox.icons.icon_";
3232

33-
private Context mContext;
34-
private static IconFactory sInstance;
35-
private Icon mDefaultMarker;
36-
private Icon mDefaultMarkerView;
37-
private BitmapFactory.Options mOptions;
33+
private static IconFactory instance;
3834

39-
private int mNextId = 0;
35+
private Context context;
36+
private Icon defaultMarker;
37+
private Icon defaultMarkerView;
38+
private BitmapFactory.Options options;
39+
private int nextId = 0;
4040

4141
public static synchronized IconFactory getInstance(@NonNull Context context) {
42-
if (sInstance == null) {
43-
sInstance = new IconFactory(context.getApplicationContext());
42+
if (instance == null) {
43+
instance = new IconFactory(context.getApplicationContext());
4444
}
45-
return sInstance;
45+
return instance;
4646
}
4747

4848
private IconFactory(@NonNull Context context) {
49-
mContext = context;
49+
this.context = context;
5050
DisplayMetrics realMetrics = null;
5151
DisplayMetrics metrics = new DisplayMetrics();
5252
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
@@ -57,20 +57,20 @@ private IconFactory(@NonNull Context context) {
5757
}
5858
wm.getDefaultDisplay().getMetrics(metrics);
5959

60-
mOptions = new BitmapFactory.Options();
61-
mOptions.inScaled = true;
62-
mOptions.inDensity = DisplayMetrics.DENSITY_DEFAULT;
63-
mOptions.inTargetDensity = metrics.densityDpi;
60+
options = new BitmapFactory.Options();
61+
options.inScaled = true;
62+
options.inDensity = DisplayMetrics.DENSITY_DEFAULT;
63+
options.inTargetDensity = metrics.densityDpi;
6464
if (realMetrics != null) {
65-
mOptions.inScreenDensity = realMetrics.densityDpi;
65+
options.inScreenDensity = realMetrics.densityDpi;
6666
}
6767
}
6868

6969
public Icon fromBitmap(@NonNull Bitmap bitmap) {
70-
if (mNextId < 0) {
70+
if (nextId < 0) {
7171
throw new TooManyIconsException();
7272
}
73-
String id = ICON_ID_PREFIX + ++mNextId;
73+
String id = ICON_ID_PREFIX + ++nextId;
7474
return new Icon(id, bitmap);
7575
}
7676

@@ -96,7 +96,7 @@ public Icon fromDrawable(@NonNull Drawable drawable, int width, int height) {
9696
}
9797

9898
public Icon fromResource(@DrawableRes int resourceId) {
99-
Drawable drawable = ContextCompat.getDrawable(mContext, resourceId);
99+
Drawable drawable = ContextCompat.getDrawable(context, resourceId);
100100
Bitmap bitmap;
101101
if (drawable instanceof BitmapDrawable) {
102102
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
@@ -116,43 +116,43 @@ public Icon fromResource(@DrawableRes int resourceId) {
116116
}
117117

118118
public Icon defaultMarker() {
119-
if (mDefaultMarker == null) {
120-
mDefaultMarker = fromResource(R.drawable.default_marker);
119+
if (defaultMarker == null) {
120+
defaultMarker = fromResource(R.drawable.default_marker);
121121
}
122-
return mDefaultMarker;
122+
return defaultMarker;
123123
}
124124

125125
public Icon defaultMarkerView() {
126-
if (mDefaultMarkerView == null) {
127-
mDefaultMarkerView = fromResource(R.drawable.default_markerview);
126+
if (defaultMarkerView == null) {
127+
defaultMarkerView = fromResource(R.drawable.default_markerview);
128128
}
129-
return mDefaultMarkerView;
129+
return defaultMarkerView;
130130
}
131131

132132
private Icon fromInputStream(@NonNull InputStream is) {
133-
Bitmap bitmap = BitmapFactory.decodeStream(is, null, mOptions);
133+
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
134134
return fromBitmap(bitmap);
135135
}
136136

137137
public Icon fromAsset(@NonNull String assetName) {
138138
InputStream is;
139139
try {
140-
is = mContext.getAssets().open(assetName);
140+
is = context.getAssets().open(assetName);
141141
} catch (IOException e) {
142142
return null;
143143
}
144144
return fromInputStream(is);
145145
}
146146

147147
public Icon fromPath(@NonNull String absolutePath) {
148-
Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, mOptions);
148+
Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, options);
149149
return fromBitmap(bitmap);
150150
}
151151

152152
public Icon fromFile(@NonNull String fileName) {
153153
FileInputStream is;
154154
try {
155-
is = mContext.openFileInput(fileName);
155+
is = context.openFileInput(fileName);
156156
} catch (FileNotFoundException e) {
157157
return null;
158158
}

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java

+43-43
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
*/
2727
public class InfoWindow {
2828

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;
3232

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;
3838

3939
@LayoutRes
40-
private int mLayoutRes;
40+
private int layoutRes;
4141

4242
InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) {
43-
mLayoutRes = layoutResId;
43+
layoutRes = layoutResId;
4444
View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false);
4545
initialize(view, mapboxMap);
4646
}
@@ -50,14 +50,14 @@ public class InfoWindow {
5050
}
5151

5252
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);
5656

5757
view.setOnClickListener(new View.OnClickListener() {
5858
@Override
5959
public void onClick(View v) {
60-
MapboxMap mapboxMap = mMapboxMap.get();
60+
MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get();
6161
if (mapboxMap != null) {
6262
MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener = mapboxMap.getOnInfoWindowClickListener();
6363
boolean handledDefaultClick = false;
@@ -76,7 +76,7 @@ public void onClick(View v) {
7676
view.setOnLongClickListener(new View.OnLongClickListener() {
7777
@Override
7878
public boolean onLongClick(View v) {
79-
MapboxMap mapboxMap = mMapboxMap.get();
79+
MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get();
8080
if (mapboxMap != null) {
8181
MapboxMap.OnInfoWindowLongClickListener listener = mapboxMap.getOnInfoWindowLongClickListener();
8282
if (listener != null) {
@@ -103,19 +103,19 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
103103

104104
MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT);
105105

106-
MapboxMap mapboxMap = mMapboxMap.get();
107-
View view = mView.get();
106+
MapboxMap mapboxMap = this.mapboxMap.get();
107+
View view = this.view.get();
108108
if (view != null && mapboxMap != null) {
109109
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
110110

111111
// Calculate y-offset for update method
112-
mMarkerHeightOffset = -view.getMeasuredHeight() + offsetY;
113-
mMarkerWidthOffset = -offsetX;
112+
markerHeightOffset = -view.getMeasuredHeight() + offsetY;
113+
markerWidthOffset = -offsetX;
114114

115115
// 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;
119119

120120
if (view instanceof InfoWindowView) {
121121
// only apply repositioning/margin for InfoWindowView
@@ -175,11 +175,11 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
175175
view.setY(y);
176176

177177
// Calculate x-offset for update method
178-
mViewWidthOffset = x - mCoordinates.x - offsetX;
178+
viewWidthOffset = x - coordinates.x - offsetX;
179179

180180
close(); //if it was already opened
181181
mapView.addView(view, lp);
182-
mIsVisible = true;
182+
isVisible = true;
183183
}
184184
return this;
185185
}
@@ -190,10 +190,10 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
190190
* @return this info window
191191
*/
192192
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();
197197
if (view != null && view.getParent() != null) {
198198
((ViewGroup) view.getParent()).removeView(view);
199199
}
@@ -216,12 +216,12 @@ InfoWindow close() {
216216
* @param overlayItem the tapped overlay item
217217
*/
218218
void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) {
219-
View view = mView.get();
219+
View view = this.view.get();
220220
if (view == null) {
221-
view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false);
221+
view = LayoutInflater.from(mapView.getContext()).inflate(layoutRes, mapView, false);
222222
initialize(view, mapboxMap);
223223
}
224-
mMapboxMap = new WeakReference<>(mapboxMap);
224+
this.mapboxMap = new WeakReference<>(mapboxMap);
225225
String title = overlayItem.getTitle();
226226
TextView titleTextView = ((TextView) view.findViewById(R.id.infowindow_title));
227227
if (!TextUtils.isEmpty(title)) {
@@ -242,39 +242,39 @@ void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView
242242
}
243243

244244
InfoWindow setBoundMarker(Marker boundMarker) {
245-
mBoundMarker = new WeakReference<>(boundMarker);
245+
this.boundMarker = new WeakReference<>(boundMarker);
246246
return this;
247247
}
248248

249249
Marker getBoundMarker() {
250-
if (mBoundMarker == null) {
250+
if (boundMarker == null) {
251251
return null;
252252
}
253-
return mBoundMarker.get();
253+
return boundMarker.get();
254254
}
255255

256256
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();
260260
if (mapboxMap != null && marker != null && view != null) {
261-
mCoordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
261+
coordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
262262

263263
if (view instanceof InfoWindowView) {
264-
view.setX(mCoordinates.x + mViewWidthOffset - mMarkerWidthOffset);
264+
view.setX(coordinates.x + viewWidthOffset - markerWidthOffset);
265265
} else {
266-
view.setX(mCoordinates.x - (view.getMeasuredWidth() / 2) - mMarkerWidthOffset);
266+
view.setX(coordinates.x - (view.getMeasuredWidth() / 2) - markerWidthOffset);
267267
}
268-
view.setY(mCoordinates.y + mMarkerHeightOffset);
268+
view.setY(coordinates.y + markerHeightOffset);
269269
}
270270
}
271271

272272
public View getView() {
273-
return mView != null ? mView.get() : null;
273+
return view != null ? view.get() : null;
274274
}
275275

276276
boolean isVisible() {
277-
return mIsVisible;
277+
return isVisible;
278278
}
279279

280280
}

0 commit comments

Comments
 (0)