bound area improvment, toggle bounding box in menu fab

This commit is contained in:
Adam Domagalski 2018-11-17 16:30:52 +01:00
parent 5d3ba7e1a1
commit fd9cb37fb3
6 changed files with 96 additions and 59 deletions

View File

@ -258,7 +258,6 @@ public abstract class BaseActivity
} }
@Override @Override
public boolean onQueryTextChange(String input) { public boolean onQueryTextChange(String input) {
if (activeFragment.equals(ActiveFragment.USER_LIST)) { if (activeFragment.equals(ActiveFragment.USER_LIST)) {
executeUserListSearch(input); executeUserListSearch(input);

View File

@ -10,16 +10,16 @@ import android.graphics.Color;
import android.location.Location; import android.location.Location;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import com.getbase.floatingactionbutton.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;
@ -31,11 +31,7 @@ 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.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;
@ -67,6 +63,7 @@ import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import timber.log.Timber; import timber.log.Timber;
import java.util.Set; import java.util.Set;
import static com.mapbox.mapboxsdk.style.layers.Property.NONE; import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
@ -125,6 +122,7 @@ public class MapActivity extends BaseActivity
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
Mapbox.getInstance(this, getString(R.string.access_token)); Mapbox.getInstance(this, getString(R.string.access_token));
mapView = findViewById(R.id.mapView); mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState); mapView.onCreate(savedInstanceState);
@ -145,12 +143,29 @@ public class MapActivity extends BaseActivity
return true; return true;
}); });
mapUtils.setMapBoundsArea(getApplicationContext() , mapboxMap, mapView);
setToggleMapBoundsArea();
setOnMapLongClickListener(); setOnMapLongClickListener();
// addStaticLayer(); // 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) { private void createMarkerModal(String userId) {
disposable.add(userService.getUserById(userId) disposable.add(userService.getUserById(userId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -333,7 +348,7 @@ public class MapActivity extends BaseActivity
@Override @Override
public void onSuccess(List<Coordinate> coordsList) { public void onSuccess(List<Coordinate> coordsList) {
if(coordsList.isEmpty()) { if (coordsList.isEmpty()) {
Log.e(tag, "200 empty []"); Log.e(tag, "200 empty []");
//mapboxMap.clear(); //mapboxMap.clear();
return; return;
@ -346,26 +361,24 @@ public class MapActivity extends BaseActivity
} }
Set<String> currentCoordsIds = new HashSet<>(tmp); Set<String> currentCoordsIds = new HashSet<>(tmp);
if (previousCoordsIds.isEmpty()){ if (previousCoordsIds.isEmpty()) {
previousCoordsIds.addAll(currentCoordsIds); previousCoordsIds.addAll(currentCoordsIds);
} else { } else {
// here we clear + it returns bool if smthing was removed // here we clear + it returns bool if smthing was removed
if (previousCoordsIds.removeAll(currentCoordsIds)) { if (previousCoordsIds.removeAll(currentCoordsIds)) {
for (String toRemoveId: previousCoordsIds) { for (String toRemoveId : previousCoordsIds) {
Log.e(tag+ "delete: " , "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId)); Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
mapboxMap.removeMarker(markerHash.get(toRemoveId)); mapboxMap.removeMarker(markerHash.get(toRemoveId));
markerHash.remove(toRemoveId); markerHash.remove(toRemoveId);
coordsMap.remove(toRemoveId); coordsMap.remove(toRemoveId);
} }
} else { } else {
// TODO double check when some markers api will change // 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) { for (Coordinate element : coordsList) {
String id = element.getUserId(); String id = element.getUserId();
String newLabel = element.getLabel(); String newLabel = element.getLabel();
@ -447,44 +460,42 @@ public class MapActivity extends BaseActivity
if (PermissionsManager.areLocationPermissionsGranted(this)) { if (PermissionsManager.areLocationPermissionsGranted(this)) {
Log.e(tag, "enableLocationPlugin true"); Log.e(tag, "enableLocationPlugin true");
FloatingActionButton myLocationButton = findViewById(R.id.myLocationButton);
myLocationButton.setVisibility(View.VISIBLE);
LocationComponentOptions options = LocationComponentOptions.builder(this) LocationComponentOptions options = LocationComponentOptions.builder(this)
.trackingGesturesManagement(true) .trackingGesturesManagement(false)
.accuracyColor(ContextCompat.getColor(this, R.color.mapboxGray)) .accuracyColor(ContextCompat.getColor(this, R.color.mapboxGray))
.build(); .build();
// Get an instance of the component // Get an instance of the component
locationComponent = mapboxMap.getLocationComponent(); locationComponent = mapboxMap.getLocationComponent();
//Log.e(tag + "Last", locationComponent.getLastKnownLocation() + ""); Log.e(tag + "Last", locationComponent.getLastKnownLocation() + "");
// Activate with options // Activate with options
locationComponent.activateLocationComponent(this, options); locationComponent.activateLocationComponent(this, options);
// Enable to make component visible
// Enable to make component visible + camera animation
// https://www.mapbox.com/android-docs/maps/overview/location-component/
locationComponent.setLocationComponentEnabled(true); locationComponent.setLocationComponentEnabled(true);
// Set the component's camera mode // Set the component's camera mode
locationComponent.setCameraMode(CameraMode.TRACKING); locationComponent.setCameraMode(CameraMode.NONE);
locationComponent.setRenderMode(RenderMode.COMPASS); locationComponent.setRenderMode(RenderMode.COMPASS);
// Button 4 centring // Button 4 centring
FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton); FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton);
myLocFAB.setVisibility(View.VISIBLE);
myLocFAB.setOnClickListener(v -> { myLocFAB.setOnClickListener(v -> {
Location lastKnownLocation = locationComponent.getLastKnownLocation(); Location lastKnownLocation = locationComponent.getLastKnownLocation();
if (lastKnownLocation != null) { if (lastKnownLocation != null) {
mapUtils.makeNewCamera(mapboxMap,
CameraPosition position = new CameraPosition.Builder() lastKnownLocation.getLatitude(),
.target(new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude())) // Sets the new camera position lastKnownLocation.getLongitude(),
.zoom(zoomParam) // Sets the zoom zoomParam,
.bearing(bearingParam) // Rotate the camera bearingParam,
.tilt(tiltParam) // Set the camera tilt tiltParam,
.build(); // Creates a CameraPosition from the builder 4000);
mapboxMap.animateCamera(CameraUpdateFactory
.newCameraPosition(position), 4000);
} }
// Camera aniamtion // Camera aniamtion
@ -588,7 +599,7 @@ public class MapActivity extends BaseActivity
if (e instanceof HttpException) { if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody(); ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody); message = RestApiHelper.getErrorMessage(responseBody);
}else { } else {
message = "Network Error!"; message = "Network Error!";
} }

View File

@ -7,11 +7,16 @@ import android.view.Gravity;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions; 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.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap; 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.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -24,30 +29,54 @@ public class mapUtils {
.include(new LatLng(52.46548540224137, 16.925255680881094)) .include(new LatLng(52.46548540224137, 16.925255680881094))
.build(); .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 // Map Bounds Area
public static void setMapBoundsArea(Context context , MapboxMap mapboxMap, MapView mapView) { public static void setMapBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
// Set bounds to WMI if (check) {
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS); // Set bounds to WMI
mapboxMap.setMinZoomPreference(16); // TODO export to map config 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 // Visualise bounds area
// showBoundsArea // showBoundsArea
PolygonOptions boundsArea = new PolygonOptions() polygon = mapboxMap.addPolygon(boundsArea);
.add(WMI_BOUNDS.getNorthWest()) // showCrosshair
.add(WMI_BOUNDS.getNorthEast()) crosshair = new View(context);
.add(WMI_BOUNDS.getSouthEast()) crosshair.setLayoutParams(new FrameLayout.LayoutParams(15, 15, Gravity.CENTER));
.add(WMI_BOUNDS.getSouthWest()); crosshair.setBackgroundColor(Color.GREEN);
boundsArea.alpha(0.1f); mapView.addView(crosshair);
boundsArea.fillColor(Color.YELLOW); } else {
mapboxMap.addPolygon(boundsArea); mapboxMap.setLatLngBoundsForCameraTarget(null);
mapboxMap.setMinZoomPreference(2);
mapboxMap.removePolygon(polygon);
mapView.removeView(crosshair);
}
// showCrosshair }
View crosshair = new View(context);
crosshair.setLayoutParams(new FrameLayout.LayoutParams(15, 15, Gravity.CENTER)); public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration){
crosshair.setBackgroundColor(Color.GREEN); CameraPosition position = new CameraPosition.Builder()
mapView.addView(crosshair); .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 // Function for marker animation

View File

@ -42,13 +42,11 @@
mapbox:srcCompat="@android:drawable/ic_dialog_map" mapbox:srcCompat="@android:drawable/ic_dialog_map"
tools:layout_editor_absoluteX="0dp" /> tools:layout_editor_absoluteX="0dp" />
<android.support.design.widget.FloatingActionButton <com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/myLocationButton" android:id="@+id/myLocationButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:background="@color/half_black" android:background="@color/half_black"
android:backgroundTint="@color/materialDarkGrey" android:backgroundTint="@color/materialDarkGrey"
android:src="@android:drawable/ic_menu_mylocation" android:src="@android:drawable/ic_menu_mylocation"
@ -92,13 +90,13 @@
fab:fab_title="@string/fab_title_parks" /> fab:fab_title="@string/fab_title_parks" />
<com.getbase.floatingactionbutton.FloatingActionButton <com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_toggle_attractions" android:id="@+id/fab_toggle_bound_area"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
fab:fab_colorNormal="@color/mapboxRed" fab:fab_colorNormal="@color/mapboxRed"
fab:fab_colorPressed="@color/mapboxWhite" fab:fab_colorPressed="@color/mapboxWhite"
fab:fab_size="mini" fab:fab_size="mini"
fab:fab_title="@string/fab_title_attractions" /> fab:fab_title="@string/fab_title_bound_area" />
</com.getbase.floatingactionbutton.FloatingActionsMenu> </com.getbase.floatingactionbutton.FloatingActionsMenu>

View File

@ -43,7 +43,6 @@
<!--PulsingLayerOpacityColorActivity activity--> <!--PulsingLayerOpacityColorActivity activity-->
<string name="fab_title_hotels">Hotele</string> <string name="fab_title_hotels">Hotele</string>
<string name="fab_title_parks">Parkingi</string> <string name="fab_title_parks">Parkingi</string>
<string name="fab_title_attractions">Atrakcje</string>
<string name="app_name">FindMyTutor</string> <string name="app_name">FindMyTutor</string>
<string name="title_activity_startup">Find My Tutor</string> <string name="title_activity_startup">Find My Tutor</string>
@ -128,6 +127,7 @@
<string name="user_location_permission_explanation">Ta aplikacja potrzebuje uprawnień do lokalizacji.</string> <string name="user_location_permission_explanation">Ta aplikacja potrzebuje uprawnień do lokalizacji.</string>
<string name="settings_category_status">Ustawienia statusu</string> <string name="settings_category_status">Ustawienia statusu</string>
<string name="settings_category_manuallocation">Ręczny wybór lokalizacji</string> <string name="settings_category_manuallocation">Ręczny wybór lokalizacji</string>
<string name="fab_title_bound_area">Bounds OFF</string>
</resources> </resources>

View File

@ -170,7 +170,7 @@
<!--PulsingLayerOpacityColorActivity activity--> <!--PulsingLayerOpacityColorActivity activity-->
<string name="fab_title_hotels">TODO</string> <string name="fab_title_hotels">TODO</string>
<string name="fab_title_parks">THIS</string> <string name="fab_title_parks">THIS</string>
<string name="fab_title_attractions">TOO</string> <string name="fab_title_bound_area">Bounds OFF</string>
<string name="select_a_location">Select a location</string> <string name="select_a_location">Select a location</string>
<string name="user_location_permission_explanation">This app needs location permissions in order to show its functionality.</string> <string name="user_location_permission_explanation">This app needs location permissions in order to show its functionality.</string>
<string name="user_location_permission_not_granted">You didn\'t grant location permissions.</string> <string name="user_location_permission_not_granted">You didn\'t grant location permissions.</string>