diff --git a/app/build.gradle b/app/build.gradle
index 87b98e5..3c14510 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -11,7 +11,7 @@ android {
minSdkVersion 22
targetSdkVersion 27
versionCode 1
- versionName "1.0"
+ versionName "0.9.0-alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
diff --git a/app/release/release/app.aab b/app/release/release/app.aab
new file mode 100644
index 0000000..1635523
Binary files /dev/null and b/app/release/release/app.aab differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bb4aa0c..54170df 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -37,7 +37,7 @@
-
-
markerHash = new HashMap<>();
private Set previousCoordsIds = new HashSet<>();
-
+ // Camera Animation params
private int zoomParam = 17;
private int bearingParam = 180;
private int tiltParam = 30;
@@ -121,6 +122,7 @@ public class MapActivity extends BaseActivity
Bundle extras = getIntent().getExtras();
+
Mapbox.getInstance(this, getString(R.string.access_token));
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
@@ -136,17 +138,34 @@ public class MapActivity extends BaseActivity
MapActivity.this.mapboxMap = mapboxMap;
mStatusChecker.run();
enableLocationPlugin();
-
mapboxMap.setOnMarkerClickListener(marker -> {
createMarkerModal(marker.getTitle());
return true;
});
+ setToggleMapBoundsArea();
setOnMapLongClickListener();
// addStaticLayer();
}
+ private void setToggleMapBoundsArea() {
+
+ mapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true);
+
+ FloatingActionButton toggleBoundsAreaFab = findViewById(R.id.fab_toggle_bound_area);
+ toggleBoundsAreaFab.setOnClickListener(view -> {
+ if (toggleBoundsAreaFab.getTitle().equals("Bounds OFF")) {
+ toggleBoundsAreaFab.setTitle("Bounds ON");
+ mapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, false);
+ } else {
+ toggleBoundsAreaFab.setTitle("Bounds OFF");
+ mapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true);
+ }
+
+ });
+ }
+
private void createMarkerModal(String userId) {
disposable.add(userService.getUserById(userId)
.subscribeOn(Schedulers.io())
@@ -179,25 +198,7 @@ public class MapActivity extends BaseActivity
}
- 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();
- }
-
+ // Manual loc selection on long tap
private void setOnMapLongClickListener() {
final boolean[] cancel = {false};
@@ -347,9 +348,9 @@ public class MapActivity extends BaseActivity
@Override
public void onSuccess(List coordsList) {
- if(coordsList.isEmpty()) {
+ if (coordsList.isEmpty()) {
Log.e(tag, "200 empty []");
- mapboxMap.clear();
+ //mapboxMap.clear();
return;
}
@@ -360,26 +361,24 @@ public class MapActivity extends BaseActivity
}
Set currentCoordsIds = new HashSet<>(tmp);
- if (previousCoordsIds.isEmpty()){
+ if (previousCoordsIds.isEmpty()) {
previousCoordsIds.addAll(currentCoordsIds);
} else {
// here we clear + it returns bool if smthing was removed
if (previousCoordsIds.removeAll(currentCoordsIds)) {
- for (String toRemoveId: previousCoordsIds) {
- Log.e(tag+ "delete: " , "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
+ for (String toRemoveId : previousCoordsIds) {
+ Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
mapboxMap.removeMarker(markerHash.get(toRemoveId));
markerHash.remove(toRemoveId);
coordsMap.remove(toRemoveId);
}
} else {
// TODO double check when some markers api will change
- Log.e(tag+ "delete: ","nothing to remove");
+ Log.e(tag + "delete: ", "nothing to remove");
}
}
-
-
for (Coordinate element : coordsList) {
String id = element.getUserId();
String newLabel = element.getLabel();
@@ -453,6 +452,67 @@ public class MapActivity extends BaseActivity
}
+ @SuppressWarnings({"MissingPermission"})
+ private void enableLocationPlugin() {
+ Log.e(tag, "enableLocationPlugin");
+
+ // Check if permissions are enabled and if not request
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ Log.e(tag, "enableLocationPlugin true");
+
+
+ LocationComponentOptions options = LocationComponentOptions.builder(this)
+ .trackingGesturesManagement(false)
+ .accuracyColor(ContextCompat.getColor(this, R.color.mapboxGray))
+ .build();
+
+ // Get an instance of the component
+ locationComponent = mapboxMap.getLocationComponent();
+
+ Log.e(tag + "Last", locationComponent.getLastKnownLocation() + "");
+
+ // Activate with options
+ locationComponent.activateLocationComponent(this, options);
+
+ // Enable to make component visible + camera animation
+ // https://www.mapbox.com/android-docs/maps/overview/location-component/
+ locationComponent.setLocationComponentEnabled(true);
+
+ // Set the component's camera mode
+ locationComponent.setCameraMode(CameraMode.NONE);
+ locationComponent.setRenderMode(RenderMode.COMPASS);
+
+ // Button 4 centring
+ FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton);
+ myLocFAB.setVisibility(View.VISIBLE);
+ myLocFAB.setOnClickListener(v -> {
+
+ Location lastKnownLocation = locationComponent.getLastKnownLocation();
+ if (lastKnownLocation != null) {
+ mapUtils.makeNewCamera(mapboxMap,
+ lastKnownLocation.getLatitude(),
+ lastKnownLocation.getLongitude(),
+ zoomParam,
+ bearingParam,
+ tiltParam,
+ 4000);
+ }
+
+ // Camera aniamtion
+ zoomParam = (zoomParam == 17) ? 19 : 17;
+ bearingParam += 90;
+ tiltParam = (tiltParam == 30) ? 0 : 30;
+ });
+ } else {
+ Log.e(tag, "enableLocationPlugin false");
+
+ permissionsManager = new PermissionsManager(this);
+ permissionsManager.requestLocationPermissions(this);
+ permissionsManager.onRequestPermissionsResult(0, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, new int[]{0});
+
+ }
+ }
+
// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
@@ -508,69 +568,6 @@ public class MapActivity extends BaseActivity
return R.id.nav_map;
}
- @SuppressWarnings({"MissingPermission"})
- private void enableLocationPlugin() {
- Log.e(tag, "enableLocationPlugin");
-
- // Check if permissions are enabled and if not request
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- Log.e(tag, "enableLocationPlugin true");
-
- FloatingActionButton myLocationButton = findViewById(R.id.myLocationButton);
- myLocationButton.setVisibility(View.VISIBLE);
-
- LocationComponentOptions options = LocationComponentOptions.builder(this)
- .trackingGesturesManagement(true)
- .accuracyColor(ContextCompat.getColor(this, R.color.mapboxGray))
- .build();
-
- // Get an instance of the component
- locationComponent = mapboxMap.getLocationComponent();
-
- //Log.e(tag + "Last", locationComponent.getLastKnownLocation() + "");
-
- // Activate with options
- locationComponent.activateLocationComponent(this, options);
- // Enable to make component visible
- locationComponent.setLocationComponentEnabled(true);
-
- // Set the component's camera mode
- locationComponent.setCameraMode(CameraMode.TRACKING);
- locationComponent.setRenderMode(RenderMode.COMPASS);
-
- // Button 4 centring
- FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton);
- myLocFAB.setOnClickListener(v -> {
-
- Location lastKnownLocation = locationComponent.getLastKnownLocation();
- if (lastKnownLocation != null) {
-
- CameraPosition position = new CameraPosition.Builder()
- .target(new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude())) // Sets the new camera position
- .zoom(zoomParam) // Sets the zoom
- .bearing(bearingParam) // Rotate the camera
- .tilt(tiltParam) // Set the camera tilt
- .build(); // Creates a CameraPosition from the builder
-
- mapboxMap.animateCamera(CameraUpdateFactory
- .newCameraPosition(position), 4000);
- }
-
- // Camera aniamtion
- zoomParam = (zoomParam == 17) ? 19 : 17;
- bearingParam += 90;
- tiltParam = (tiltParam == 30) ? 0 : 30;
- });
- } else {
- Log.e(tag, "enableLocationPlugin false");
-
- permissionsManager = new PermissionsManager(this);
- permissionsManager.requestLocationPermissions(this);
- permissionsManager.onRequestPermissionsResult(0, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, new int[]{0});
-
- }
- }
-
@Override
public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@@ -591,4 +588,21 @@ public class MapActivity extends BaseActivity
// 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();
+ }
}
diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java
index a58ca10..10a651b 100644
--- a/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java
+++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/mapUtils.java
@@ -2,15 +2,84 @@ package com.uam.wmi.findmytutor.utils;
import android.animation.TypeEvaluator;
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.Polygon;
+import com.mapbox.mapboxsdk.annotations.PolygonOptions;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
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 com.mapbox.mapboxsdk.style.layers.FillLayer;
+import com.mapbox.mapboxsdk.style.layers.Layer;
import java.io.IOException;
import java.io.InputStream;
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();
+ private static final PolygonOptions boundsArea = new PolygonOptions()
+ .add(WMI_BOUNDS.getNorthWest())
+ .add(WMI_BOUNDS.getNorthEast())
+ .add(WMI_BOUNDS.getSouthEast())
+ .add(WMI_BOUNDS.getSouthWest())
+ .alpha(0.1f)
+ .fillColor(Color.YELLOW);
+ // For adding and removing
+ private static Polygon polygon;
+ private static View crosshair;
+
+ // Map Bounds Area
+ public static void setMapBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
+
+ if (check) {
+ // Set bounds to WMI
+ mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
+ makeNewCamera(mapboxMap, 52.466799, 16.927002, 17, 0, 0,4000);
+ mapboxMap.setMinZoomPreference(16); // TODO export to map config
+
+ // Visualise bounds area
+ // showBoundsArea
+ polygon = mapboxMap.addPolygon(boundsArea);
+ // showCrosshair
+ crosshair = new View(context);
+ crosshair.setLayoutParams(new FrameLayout.LayoutParams(15, 15, Gravity.CENTER));
+ crosshair.setBackgroundColor(Color.GREEN);
+ mapView.addView(crosshair);
+ } else {
+ mapboxMap.setLatLngBoundsForCameraTarget(null);
+ mapboxMap.setMinZoomPreference(2);
+ mapboxMap.removePolygon(polygon);
+ mapView.removeView(crosshair);
+ }
+
+
+ }
+
+ public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration){
+ CameraPosition position = new CameraPosition.Builder()
+ .target(new LatLng(lat, lon)) // Sets the new camera position
+ .zoom(zoomParam) // Sets the zoom
+ .bearing(bearingParam) // Rotate the camera
+ .tilt(tiltParam) // Set the camera tilt
+ .build(); // Creates a CameraPosition from the builder
+
+ mapboxMap.animateCamera(CameraUpdateFactory
+ .newCameraPosition(position), duration);
+ }
+
+ // Function for marker animation
public static class LatLngEvaluator implements TypeEvaluator {
// Method is used to interpolate the marker animation.
@@ -26,6 +95,7 @@ public class mapUtils {
}
}
+ // read file to JSON
public static String loadJsonFromAsset(Context context, String filename) {
// Using this method to load in GeoJSON files from the assets folder.
try {
@@ -41,4 +111,5 @@ public class mapUtils {
return null;
}
}
+
}
diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml
index f1f614e..dd40aea 100644
--- a/app/src/main/res/layout/activity_map.xml
+++ b/app/src/main/res/layout/activity_map.xml
@@ -42,13 +42,11 @@
mapbox:srcCompat="@android:drawable/ic_dialog_map"
tools:layout_editor_absoluteX="0dp" />
-
+ fab:fab_title="@string/fab_title_bound_area" />
diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index 52c7a2b..ec438d4 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -43,7 +43,6 @@
Hotele
Parkingi
- Atrakcje
FindMyTutor
Find My Tutor
@@ -130,6 +129,7 @@
Ręczny wybór lokalizacji
Wyślij nam feedback
Zgłoś błąd
+ Bounds OFF
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 08e405a..69f5ad4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -181,7 +181,7 @@
TODO
THIS
- TOO
+ Bounds OFF
Select a location
This app needs location permissions in order to show its functionality.
You didn\'t grant location permissions.
@@ -205,5 +205,6 @@
permission should be granted
+ MapActivity