|
|
|
@ -4,16 +4,21 @@ import android.Manifest;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
|
import android.animation.ValueAnimator;
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.graphics.PointF;
|
|
|
|
|
import android.location.Location;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.Gravity;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.view.animation.LinearInterpolator;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
@ -22,6 +27,7 @@ import com.getbase.floatingactionbutton.FloatingActionButton;
|
|
|
|
|
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
|
|
|
|
import com.mapbox.android.core.permissions.PermissionsListener;
|
|
|
|
|
import com.mapbox.android.core.permissions.PermissionsManager;
|
|
|
|
|
import com.mapbox.geojson.Point;
|
|
|
|
|
import com.mapbox.mapboxsdk.Mapbox;
|
|
|
|
|
import com.mapbox.mapboxsdk.annotations.Icon;
|
|
|
|
|
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
|
|
|
@ -74,12 +80,15 @@ public class MapActivity extends BaseActivity
|
|
|
|
|
private Handler mHandler = new Handler();
|
|
|
|
|
private Runnable mStatusChecker;
|
|
|
|
|
private Handler manualLocHandler = new Handler();
|
|
|
|
|
private ImageView hoveringMarkerView;
|
|
|
|
|
private Runnable manualLocStatusChecker;
|
|
|
|
|
private MapView mapView;
|
|
|
|
|
private MapboxMap mapboxMap;
|
|
|
|
|
private Button selectLocationButton;
|
|
|
|
|
private Button removeLocationButton;
|
|
|
|
|
private Button hoverSelectLocationButton;
|
|
|
|
|
private Marker tmpLocalMarker;
|
|
|
|
|
private Marker droppedMarker;
|
|
|
|
|
private Coordinate droppedMarkercoordinate;
|
|
|
|
|
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
|
|
|
|
|
private HashMap<String, Marker> markerHash = new HashMap<>();
|
|
|
|
@ -157,10 +166,81 @@ public class MapActivity extends BaseActivity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setToggleMapBoundsArea();
|
|
|
|
|
setHoveringMarker();
|
|
|
|
|
if (PrefUtils.getIsTutor(this)){
|
|
|
|
|
setOnMapLongClickListener();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// addStaticLayer();
|
|
|
|
|
}
|
|
|
|
|
// TODO:
|
|
|
|
|
private void setHoveringMarker() {
|
|
|
|
|
// When user is still picking a location, we hover a marker above the mapboxMap in the center.
|
|
|
|
|
// This is done by using an image view with the default marker found in the SDK. You can
|
|
|
|
|
// swap out for your own marker image, just make sure it matches up with the dropped marker.
|
|
|
|
|
hoveringMarkerView = new ImageView(this);
|
|
|
|
|
hoveringMarkerView.setImageResource(R.drawable.green_marker);
|
|
|
|
|
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
|
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
|
|
|
|
|
hoveringMarkerView.setLayoutParams(params);
|
|
|
|
|
mapView.addView(hoveringMarkerView); // somewhere esle
|
|
|
|
|
hoverSelectLocationButton = findViewById(R.id.drop_hovering_location_button);
|
|
|
|
|
hoverSelectLocationButton.setVisibility(View.VISIBLE);
|
|
|
|
|
hoveringMarkerView.setVisibility(View.VISIBLE);
|
|
|
|
|
selectLocationButton.setVisibility(View.GONE);
|
|
|
|
|
removeLocationButton.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
hoverSelectLocationButton.setOnClickListener(view -> {
|
|
|
|
|
if (mapboxMap != null) {
|
|
|
|
|
if (droppedMarker == null) {
|
|
|
|
|
// We first find where the hovering marker position is relative to the mapboxMap.
|
|
|
|
|
// Then we set the visibility to gone.
|
|
|
|
|
float coordinateX = hoveringMarkerView.getLeft() + (hoveringMarkerView.getWidth() / 2);
|
|
|
|
|
float coordinateY = hoveringMarkerView.getBottom() - (hoveringMarkerView.getHeight() / 2);
|
|
|
|
|
float[] coords = new float[]{coordinateX, coordinateY};
|
|
|
|
|
final Point latLng = Point.fromLngLat(mapboxMap.getProjection().fromScreenLocation(
|
|
|
|
|
new PointF(coords[0], coords[1])).getLongitude(), mapboxMap.getProjection().fromScreenLocation(
|
|
|
|
|
new PointF(coords[0], coords[1])).getLatitude());
|
|
|
|
|
hoveringMarkerView.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
// Transform the appearance of the button to become the cancel button
|
|
|
|
|
hoverSelectLocationButton.setBackgroundColor(
|
|
|
|
|
ContextCompat.getColor(MapActivity.this, R.color.colorAccent));
|
|
|
|
|
hoverSelectLocationButton.setText("Drop my marker");
|
|
|
|
|
|
|
|
|
|
// Create the marker icon the dropped marker will be using.
|
|
|
|
|
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker);
|
|
|
|
|
|
|
|
|
|
// Placing the marker on the mapboxMap as soon as possible causes the illusion
|
|
|
|
|
// that the hovering marker and dropped marker are the same.
|
|
|
|
|
|
|
|
|
|
droppedMarker = mapboxMap.addMarker(new MarkerOptions().setIcon(icon)
|
|
|
|
|
.position(new LatLng(latLng.latitude(), latLng.longitude())));
|
|
|
|
|
|
|
|
|
|
PrefUtils.putManualLocation(this, new LatLng(latLng.latitude(), latLng.longitude()));
|
|
|
|
|
handleBackgroundTaskLifeCycle();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// else {
|
|
|
|
|
// // When the marker is dropped, the user has clicked the button to cancel.
|
|
|
|
|
// // Therefore, we pick the marker back up.
|
|
|
|
|
// mapboxMap.removeMarker(droppedMarker);
|
|
|
|
|
//
|
|
|
|
|
// // Switch the button apperance back to select a location.
|
|
|
|
|
// hoverSelectLocationButton.setBackgroundColor(
|
|
|
|
|
// ContextCompat.getColor(MapActivity.this, R.color.colorPrimary));
|
|
|
|
|
// hoverSelectLocationButton.setText("Pick Up ");
|
|
|
|
|
//
|
|
|
|
|
// // Lastly, set the hovering marker back to visible.
|
|
|
|
|
// hoveringMarkerView.setVisibility(View.VISIBLE);
|
|
|
|
|
// droppedMarker = null;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setToggleMapBoundsArea() {
|
|
|
|
@ -258,15 +338,15 @@ public class MapActivity extends BaseActivity
|
|
|
|
|
// Toast instructing user to tap on the mapboxMap
|
|
|
|
|
// TODO PUT MANUAL CORD
|
|
|
|
|
try {
|
|
|
|
|
droppedMarkercoordinate = new Coordinate(
|
|
|
|
|
latLng.getLatitude(),
|
|
|
|
|
latLng.getLongitude(),
|
|
|
|
|
latLng.getAltitude(),
|
|
|
|
|
"approx",
|
|
|
|
|
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
|
|
|
|
PrefUtils.getUserId(getApplicationContext()),
|
|
|
|
|
PrefUtils.getLocationLevel(getApplicationContext())
|
|
|
|
|
);
|
|
|
|
|
// droppedMarkercoordinate = new Coordinate(
|
|
|
|
|
// latLng.getLatitude(),
|
|
|
|
|
// latLng.getLongitude(),
|
|
|
|
|
// latLng.getAltitude(),
|
|
|
|
|
// "approx",
|
|
|
|
|
// PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
|
|
|
|
// PrefUtils.getUserId(getApplicationContext()),
|
|
|
|
|
// PrefUtils.getLocationLevel(getApplicationContext())
|
|
|
|
|
// );
|
|
|
|
|
PrefUtils.putManualLocation(this, latLng);
|
|
|
|
|
handleBackgroundTaskLifeCycle();
|
|
|
|
|
|
|
|
|
|