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

Commit

Permalink
[android] #3145 - MapboxMap
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jan 29, 2016
1 parent 710398b commit 8ed1dc9
Show file tree
Hide file tree
Showing 87 changed files with 4,946 additions and 3,396 deletions.
1 change: 0 additions & 1 deletion platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ android {
lintOptions {
checkAllWarnings true
warningsAsErrors true
disable 'InvalidPackage'
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import android.support.annotation.NonNull;

import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;

/**
* Annotation is a overlay on top of a {@link MapView},
Expand All @@ -21,7 +22,7 @@ public abstract class Annotation implements Comparable<Annotation> {
* Internal C++ id is stored as unsigned int.
*/
private long id = -1; // -1 unless added to a MapView
private MapView mapView;
private MapboxMap mapboxMap;

protected Annotation() {
}
Expand All @@ -38,10 +39,10 @@ public long getId() {
}

public void remove() {
if (mapView == null) {
if (mapboxMap == null) {
return;
}
mapView.removeAnnotation(this);
mapboxMap.removeAnnotation(this);
}

/**
Expand All @@ -54,15 +55,12 @@ public void setId(long id) {
/**
* Do not use this method. Used internally by the SDK.
*/
public void setMapView(MapView mapView) {
this.mapView = mapView;
public void setMapboxMap(MapboxMap mapView) {
this.mapboxMap = mapView;
}

protected MapView getMapView() {
if (mapView == null) {
return null;
}
return mapView;
protected MapboxMap getMapboxMap() {
return mapboxMap;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import android.graphics.Bitmap;

import com.mapbox.mapboxsdk.maps.MapView;

/**
* Icon is the visual representation of a {@link Marker} on a {@link com.mapbox.mapboxsdk.views.MapView}.
* Icon is the visual representation of a {@link Marker} on a {@link MapView}.
* @see Marker
*/
public final class Icon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;

import java.lang.ref.WeakReference;

Expand All @@ -26,7 +27,7 @@
public class InfoWindow {

private WeakReference<Marker> mBoundMarker;
private WeakReference<MapView> mMapView;
private WeakReference<MapboxMap> mMapboxMap;
protected WeakReference<View> mView;

private float mMarkerHeightOffset;
Expand All @@ -37,18 +38,18 @@ public class InfoWindow {
@LayoutRes
private int mLayoutRes;

InfoWindow(int layoutResId, MapView mapView) {
InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) {
mLayoutRes = layoutResId;
View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false);
initialize(view, mapView);
initialize(view, mapboxMap);
}

InfoWindow(View view, MapView mapView) {
initialize(view, mapView);
InfoWindow(View view, MapboxMap mapboxMap) {
initialize(view, mapboxMap);
}

private void initialize(View view, MapView mapView) {
mMapView = new WeakReference<>(mapView);
private void initialize(View view, MapboxMap mapboxMap) {
mMapboxMap = new WeakReference<>(mapboxMap);
mIsVisible = false;
mView = new WeakReference<>(view);

Expand All @@ -58,8 +59,8 @@ private void initialize(View view, MapView mapView) {
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_UP) {
boolean handledDefaultClick = false;
MapView.OnInfoWindowClickListener onInfoWindowClickListener =
mMapView.get().getOnInfoWindowClickListener();
MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener =
mMapboxMap.get().getOnInfoWindowClickListener();
if (onInfoWindowClickListener != null) {
handledDefaultClick = onInfoWindowClickListener.onMarkerClick(getBoundMarker());
}
Expand Down Expand Up @@ -88,15 +89,17 @@ 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();
if (view != null) {
if (view != null && mapboxMap != null) {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

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

// Calculate default Android x,y coordinate
mCoordinates = mapView.toScreenLocation(position);

mCoordinates = mapboxMap.toScreenLocation(position);
float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX;
float y = mCoordinates.y - view.getMeasuredHeight() + offsetY;

Expand Down Expand Up @@ -191,21 +194,24 @@ InfoWindow close() {
*
* @param overlayItem the tapped overlay item
*/
void adaptDefaultMarker(Marker overlayItem, MapView mapView) {
void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) {
View view = mView.get();
if (view == null) {
view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false);
initialize(view, mapView);
initialize(view, mapboxMap);
}
mMapView = new WeakReference<>(mapView);
mMapboxMap = new WeakReference<>(mapboxMap);
String title = overlayItem.getTitle();
((TextView) view.findViewById(R.id.infowindow_title)).setText(title);
String snippet = overlayItem.getSnippet();
((TextView) view.findViewById(R.id.infowindow_description)).setText(snippet);
}

private void onClose() {
mMapView.get().deselectMarker(getBoundMarker());
MapboxMap mapboxMap = mMapboxMap.get();
if (mapboxMap != null) {
mapboxMap.deselectMarker(getBoundMarker());
}
}

InfoWindow setBoundMarker(Marker boundMarker) {
Expand All @@ -221,11 +227,11 @@ Marker getBoundMarker() {
}

public void update() {
MapView mapView = mMapView.get();
MapboxMap mapboxMap = mMapboxMap.get();
Marker marker = mBoundMarker.get();
View view = mView.get();
if (mapView != null && marker != null && view != null) {
mCoordinates = mapView.toScreenLocation(marker.getPosition());
if (mapboxMap != null && marker != null && view != null) {
mCoordinates = mapboxMap.toScreenLocation(marker.getPosition());
view.setX(mCoordinates.x + mViewWidthOffset);
view.setY(mCoordinates.y + mMarkerHeightOffset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import android.support.annotation.Nullable;
import android.view.View;

import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.views.MapView;
import com.mapbox.mapboxsdk.maps.MapView;

/**
* Marker is an annotation that shows an icon image at a geographical location.
* </p>
* An {@link InfoWindow} can be shown when a Marker is pressed
* <p>
* <p/>
*/
public final class Marker extends Annotation {

Expand Down Expand Up @@ -55,8 +56,6 @@ public void hideInfoWindow() {

/**
* Do not use this method. Used internally by the SDK.
*
* @return boolean State of a InfoWindow
*/
public boolean isInfoWindowShown() {
return infoWindowShown;
Expand All @@ -72,8 +71,6 @@ void setSnippet(String snippet) {

/**
* Do not use this method. Used internally by the SDK.
*
* @param icon The icon to be used as Marker image
*/
public void setIcon(@Nullable Icon icon) {
this.icon = icon;
Expand All @@ -89,25 +86,25 @@ void setTitle(String title) {

/**
* Do not use this method. Used internally by the SDK.
*
* @param mapView The MapView to show the InfoWindow on.
* @return infoWindow The infoWindow to show
*/
public InfoWindow showInfoWindow(@NonNull MapView mapView) {
setMapView(mapView);
MapView.InfoWindowAdapter infoWindowAdapter = getMapView().getInfoWindowAdapter();
public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) {
setMapboxMap(mapboxMap);
MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter();
if (infoWindowAdapter != null) {
// end developer is using a custom InfoWindowAdapter
View content = infoWindowAdapter.getInfoWindow(this);
if (content != null) {
infoWindow = new InfoWindow(content, getMapView());
infoWindow = new InfoWindow(content, mapboxMap);
showInfoWindow(infoWindow, mapView);
return infoWindow;
}
}

getInfoWindow().adaptDefaultMarker(this, mapView);
return showInfoWindow(getInfoWindow(), mapView);
InfoWindow infoWindow = getInfoWindow(mapView);
if (mapView.getContext() != null) {
infoWindow.adaptDefaultMarker(this, mapboxMap, mapView);
}
return showInfoWindow(infoWindow, mapView);
}

private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) {
Expand All @@ -116,27 +113,15 @@ private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) {
return iw;
}

private InfoWindow getInfoWindow() {
if (infoWindow == null) {
infoWindow = new InfoWindow(R.layout.infowindow_view, getMapView());
private InfoWindow getInfoWindow(@NonNull MapView mapView) {
if (infoWindow == null && mapView.getContext() != null) {
infoWindow = new InfoWindow(mapView, R.layout.infowindow_view, getMapboxMap());
}
return infoWindow;
}

/*
@Override
void setVisible(boolean visible) {
super.setVisible(visible);
if (!visible && infoWindowShown) {
hideInfoWindow();
}
}
*/

/**
* Do not use this method. Used internally by the SDK.
*
* @param topOffsetPixels the pixels to have as offset
*/
public void setTopOffsetPixels(int topOffsetPixels) {
this.topOffsetPixels = topOffsetPixels;
Expand Down
Loading

0 comments on commit 8ed1dc9

Please sign in to comment.