Merge branch 'mapBoundsArea' of s416084/find-my-tutor-android into develop

This commit is contained in:
Adam Domagalski 2018-11-12 21:19:50 +00:00 committed by Gogs
commit 5d3ba7e1a1
2 changed files with 122 additions and 77 deletions

View File

@ -14,10 +14,12 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.animation.LinearInterpolator; import android.view.animation.LinearInterpolator;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -29,9 +31,11 @@ import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory; import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.location.LocationComponent; import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.LocationComponentOptions; import com.mapbox.mapboxsdk.location.LocationComponentOptions;
import com.mapbox.mapboxsdk.location.modes.CameraMode; import com.mapbox.mapboxsdk.location.modes.CameraMode;
@ -93,7 +97,7 @@ public class MapActivity extends BaseActivity
private HashMap<String, Marker> markerHash = new HashMap<>(); private HashMap<String, Marker> markerHash = new HashMap<>();
private Set<String> previousCoordsIds = new HashSet<>(); private Set<String> previousCoordsIds = new HashSet<>();
// Camera Animation params
private int zoomParam = 17; private int zoomParam = 17;
private int bearingParam = 180; private int bearingParam = 180;
private int tiltParam = 30; private int tiltParam = 30;
@ -136,12 +140,12 @@ public class MapActivity extends BaseActivity
MapActivity.this.mapboxMap = mapboxMap; MapActivity.this.mapboxMap = mapboxMap;
mStatusChecker.run(); mStatusChecker.run();
enableLocationPlugin(); enableLocationPlugin();
mapboxMap.setOnMarkerClickListener(marker -> { mapboxMap.setOnMarkerClickListener(marker -> {
createMarkerModal(marker.getTitle()); createMarkerModal(marker.getTitle());
return true; return true;
}); });
mapUtils.setMapBoundsArea(getApplicationContext() , mapboxMap, mapView);
setOnMapLongClickListener(); setOnMapLongClickListener();
// addStaticLayer(); // addStaticLayer();
@ -179,25 +183,7 @@ public class MapActivity extends BaseActivity
} }
private void handleError(Throwable error) { // Manual loc selection on long tap
showError(error);
}
private void showError(Throwable e) {
String message;
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
}else {
message = "Network Error!";
}
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
}
private void setOnMapLongClickListener() { private void setOnMapLongClickListener() {
final boolean[] cancel = {false}; final boolean[] cancel = {false};
@ -349,7 +335,7 @@ public class MapActivity extends BaseActivity
if(coordsList.isEmpty()) { if(coordsList.isEmpty()) {
Log.e(tag, "200 empty []"); Log.e(tag, "200 empty []");
mapboxMap.clear(); //mapboxMap.clear();
return; return;
} }
@ -453,61 +439,6 @@ public class MapActivity extends BaseActivity
} }
// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker);
disposable.dispose();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
protected int getContentViewId() {
return R.layout.activity_map;
}
@Override
protected int getNavigationMenuItemId() {
return R.id.nav_map;
}
@SuppressWarnings({"MissingPermission"}) @SuppressWarnings({"MissingPermission"})
private void enableLocationPlugin() { private void enableLocationPlugin() {
Log.e(tag, "enableLocationPlugin"); Log.e(tag, "enableLocationPlugin");
@ -571,6 +502,61 @@ public class MapActivity extends BaseActivity
} }
} }
// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker);
disposable.dispose();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
protected int getContentViewId() {
return R.layout.activity_map;
}
@Override
protected int getNavigationMenuItemId() {
return R.id.nav_map;
}
@Override @Override
public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@ -591,4 +577,21 @@ public class MapActivity extends BaseActivity
// finish(); // finish();
// } // }
} }
private void handleError(Throwable error) {
showError(error);
}
private void showError(Throwable e) {
String message;
if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody);
}else {
message = "Network Error!";
}
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
}
} }

View File

@ -2,15 +2,55 @@ package com.uam.wmi.findmytutor.utils;
import android.animation.TypeEvaluator; import android.animation.TypeEvaluator;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class mapUtils { public class mapUtils {
// Boundires
private static final LatLngBounds WMI_BOUNDS = new LatLngBounds.Builder()
.include(new LatLng(52.467886048833094, 16.92912980245876))
.include(new LatLng(52.46548540224137, 16.925255680881094))
.build();
// Map Bounds Area
public static void setMapBoundsArea(Context context , MapboxMap mapboxMap, MapView mapView) {
// Set bounds to WMI
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
mapboxMap.setMinZoomPreference(16); // TODO export to map config
// Visualise bounds area
// showBoundsArea
PolygonOptions boundsArea = new PolygonOptions()
.add(WMI_BOUNDS.getNorthWest())
.add(WMI_BOUNDS.getNorthEast())
.add(WMI_BOUNDS.getSouthEast())
.add(WMI_BOUNDS.getSouthWest());
boundsArea.alpha(0.1f);
boundsArea.fillColor(Color.YELLOW);
mapboxMap.addPolygon(boundsArea);
// showCrosshair
View crosshair = new View(context);
crosshair.setLayoutParams(new FrameLayout.LayoutParams(15, 15, Gravity.CENTER));
crosshair.setBackgroundColor(Color.GREEN);
mapView.addView(crosshair);
}
// Function for marker animation
public static class LatLngEvaluator implements TypeEvaluator<LatLng> { public static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation. // Method is used to interpolate the marker animation.
@ -26,6 +66,7 @@ public class mapUtils {
} }
} }
// read file to JSON
public static String loadJsonFromAsset(Context context, String filename) { public static String loadJsonFromAsset(Context context, String filename) {
// Using this method to load in GeoJSON files from the assets folder. // Using this method to load in GeoJSON files from the assets folder.
try { try {
@ -41,4 +82,5 @@ public class mapUtils {
return null; return null;
} }
} }
} }