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

Commit

Permalink
[android] #6109 - cleanup Hungarian notation sdk and test app, added …
Browse files Browse the repository at this point in the history
…some javadocs todo for public api on mapboxmap
  • Loading branch information
tobrun committed Aug 23, 2016
1 parent 50da6e5 commit 1a811b0
Show file tree
Hide file tree
Showing 29 changed files with 1,269 additions and 1,225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
* @see Marker
*/
public class Icon {
private Bitmap mBitmap;
private String mId;
private Bitmap bitmap;
private String id;

Icon(String id, Bitmap bitmap) {
mId = id;
mBitmap = bitmap;
this.id = id;
this.bitmap = bitmap;
}

public String getId() {
return mId;
return id;
}

public Bitmap getBitmap() {
return mBitmap;
return bitmap;
}

@Override
Expand All @@ -33,19 +33,19 @@ public boolean equals(Object o) {

Icon icon = (Icon) o;

if (!mBitmap.equals(icon.mBitmap)) return false;
return mId.equals(icon.mId);
if (!bitmap.equals(icon.bitmap)) return false;
return id.equals(icon.id);

}

@Override
public int hashCode() {
int result = 0;
if (mBitmap != null) {
result = mBitmap.hashCode();
if (bitmap != null) {
result = bitmap.hashCode();
}
if (mId != null) {
result = 31 * result + mId.hashCode();
if (id != null) {
result = 31 * result + id.hashCode();
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ public final class IconFactory {

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

private Context mContext;
private static IconFactory sInstance;
private Icon mDefaultMarker;
private Icon mDefaultMarkerView;
private BitmapFactory.Options mOptions;
private static IconFactory instance;

private int mNextId = 0;
private Context context;
private Icon defaultMarker;
private Icon defaultMarkerView;
private BitmapFactory.Options options;
private int nextId = 0;

public static synchronized IconFactory getInstance(@NonNull Context context) {
if (sInstance == null) {
sInstance = new IconFactory(context.getApplicationContext());
if (instance == null) {
instance = new IconFactory(context.getApplicationContext());
}
return sInstance;
return instance;
}

private IconFactory(@NonNull Context context) {
mContext = context;
this.context = context;
DisplayMetrics realMetrics = null;
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Expand All @@ -57,20 +57,20 @@ private IconFactory(@NonNull Context context) {
}
wm.getDefaultDisplay().getMetrics(metrics);

mOptions = new BitmapFactory.Options();
mOptions.inScaled = true;
mOptions.inDensity = DisplayMetrics.DENSITY_DEFAULT;
mOptions.inTargetDensity = metrics.densityDpi;
options = new BitmapFactory.Options();
options.inScaled = true;
options.inDensity = DisplayMetrics.DENSITY_DEFAULT;
options.inTargetDensity = metrics.densityDpi;
if (realMetrics != null) {
mOptions.inScreenDensity = realMetrics.densityDpi;
options.inScreenDensity = realMetrics.densityDpi;
}
}

public Icon fromBitmap(@NonNull Bitmap bitmap) {
if (mNextId < 0) {
if (nextId < 0) {
throw new TooManyIconsException();
}
String id = ICON_ID_PREFIX + ++mNextId;
String id = ICON_ID_PREFIX + ++nextId;
return new Icon(id, bitmap);
}

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

public Icon fromResource(@DrawableRes int resourceId) {
Drawable drawable = ContextCompat.getDrawable(mContext, resourceId);
Drawable drawable = ContextCompat.getDrawable(context, resourceId);
Bitmap bitmap;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Expand All @@ -116,43 +116,43 @@ public Icon fromResource(@DrawableRes int resourceId) {
}

public Icon defaultMarker() {
if (mDefaultMarker == null) {
mDefaultMarker = fromResource(R.drawable.default_marker);
if (defaultMarker == null) {
defaultMarker = fromResource(R.drawable.default_marker);
}
return mDefaultMarker;
return defaultMarker;
}

public Icon defaultMarkerView() {
if (mDefaultMarkerView == null) {
mDefaultMarkerView = fromResource(R.drawable.default_markerview);
if (defaultMarkerView == null) {
defaultMarkerView = fromResource(R.drawable.default_markerview);
}
return mDefaultMarkerView;
return defaultMarkerView;
}

private Icon fromInputStream(@NonNull InputStream is) {
Bitmap bitmap = BitmapFactory.decodeStream(is, null, mOptions);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
return fromBitmap(bitmap);
}

public Icon fromAsset(@NonNull String assetName) {
InputStream is;
try {
is = mContext.getAssets().open(assetName);
is = context.getAssets().open(assetName);
} catch (IOException e) {
return null;
}
return fromInputStream(is);
}

public Icon fromPath(@NonNull String absolutePath) {
Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, mOptions);
Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, options);
return fromBitmap(bitmap);
}

public Icon fromFile(@NonNull String fileName) {
FileInputStream is;
try {
is = mContext.openFileInput(fileName);
is = context.openFileInput(fileName);
} catch (FileNotFoundException e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
*/
public class InfoWindow {

private WeakReference<Marker> mBoundMarker;
private WeakReference<MapboxMap> mMapboxMap;
protected WeakReference<View> mView;
private WeakReference<Marker> boundMarker;
private WeakReference<MapboxMap> mapboxMap;
protected WeakReference<View> view;

private float mMarkerHeightOffset;
private float mMarkerWidthOffset;
private float mViewWidthOffset;
private PointF mCoordinates;
private boolean mIsVisible;
private float markerHeightOffset;
private float markerWidthOffset;
private float viewWidthOffset;
private PointF coordinates;
private boolean isVisible;

@LayoutRes
private int mLayoutRes;
private int layoutRes;

InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) {
mLayoutRes = layoutResId;
layoutRes = layoutResId;
View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false);
initialize(view, mapboxMap);
}
Expand All @@ -50,14 +50,14 @@ public class InfoWindow {
}

private void initialize(View view, MapboxMap mapboxMap) {
mMapboxMap = new WeakReference<>(mapboxMap);
mIsVisible = false;
mView = new WeakReference<>(view);
this.mapboxMap = new WeakReference<>(mapboxMap);
isVisible = false;
this.view = new WeakReference<>(view);

view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapboxMap mapboxMap = mMapboxMap.get();
MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get();
if (mapboxMap != null) {
MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener = mapboxMap.getOnInfoWindowClickListener();
boolean handledDefaultClick = false;
Expand All @@ -76,7 +76,7 @@ public void onClick(View v) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
MapboxMap mapboxMap = mMapboxMap.get();
MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get();
if (mapboxMap != null) {
MapboxMap.OnInfoWindowLongClickListener listener = mapboxMap.getOnInfoWindowLongClickListener();
if (listener != null) {
Expand All @@ -103,19 +103,19 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset

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

MapboxMap mapboxMap = mMapboxMap.get();
View view = mView.get();
MapboxMap mapboxMap = this.mapboxMap.get();
View view = this.view.get();
if (view != null && mapboxMap != null) {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

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

// Calculate default Android x,y coordinate
mCoordinates = mapboxMap.getProjection().toScreenLocation(position);
float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX;
float y = mCoordinates.y - view.getMeasuredHeight() + offsetY;
coordinates = mapboxMap.getProjection().toScreenLocation(position);
float x = coordinates.x - (view.getMeasuredWidth() / 2) + offsetX;
float y = coordinates.y - view.getMeasuredHeight() + offsetY;

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

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

close(); //if it was already opened
mapView.addView(view, lp);
mIsVisible = true;
isVisible = true;
}
return this;
}
Expand All @@ -190,10 +190,10 @@ InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offset
* @return this info window
*/
InfoWindow close() {
MapboxMap mapboxMap = mMapboxMap.get();
if (mIsVisible && mapboxMap != null) {
mIsVisible = false;
View view = mView.get();
MapboxMap mapboxMap = this.mapboxMap.get();
if (isVisible && mapboxMap != null) {
isVisible = false;
View view = this.view.get();
if (view != null && view.getParent() != null) {
((ViewGroup) view.getParent()).removeView(view);
}
Expand All @@ -216,12 +216,12 @@ InfoWindow close() {
* @param overlayItem the tapped overlay item
*/
void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) {
View view = mView.get();
View view = this.view.get();
if (view == null) {
view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false);
view = LayoutInflater.from(mapView.getContext()).inflate(layoutRes, mapView, false);
initialize(view, mapboxMap);
}
mMapboxMap = new WeakReference<>(mapboxMap);
this.mapboxMap = new WeakReference<>(mapboxMap);
String title = overlayItem.getTitle();
TextView titleTextView = ((TextView) view.findViewById(R.id.infowindow_title));
if (!TextUtils.isEmpty(title)) {
Expand All @@ -242,39 +242,39 @@ void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView
}

InfoWindow setBoundMarker(Marker boundMarker) {
mBoundMarker = new WeakReference<>(boundMarker);
this.boundMarker = new WeakReference<>(boundMarker);
return this;
}

Marker getBoundMarker() {
if (mBoundMarker == null) {
if (boundMarker == null) {
return null;
}
return mBoundMarker.get();
return boundMarker.get();
}

public void update() {
MapboxMap mapboxMap = mMapboxMap.get();
Marker marker = mBoundMarker.get();
View view = mView.get();
MapboxMap mapboxMap = this.mapboxMap.get();
Marker marker = boundMarker.get();
View view = this.view.get();
if (mapboxMap != null && marker != null && view != null) {
mCoordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
coordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition());

if (view instanceof InfoWindowView) {
view.setX(mCoordinates.x + mViewWidthOffset - mMarkerWidthOffset);
view.setX(coordinates.x + viewWidthOffset - markerWidthOffset);
} else {
view.setX(mCoordinates.x - (view.getMeasuredWidth() / 2) - mMarkerWidthOffset);
view.setX(coordinates.x - (view.getMeasuredWidth() / 2) - markerWidthOffset);
}
view.setY(mCoordinates.y + mMarkerHeightOffset);
view.setY(coordinates.y + markerHeightOffset);
}
}

public View getView() {
return mView != null ? mView.get() : null;
return view != null ? view.get() : null;
}

boolean isVisible() {
return mIsVisible;
return isVisible;
}

}
Loading

0 comments on commit 1a811b0

Please sign in to comment.