manual merge to develop

This commit is contained in:
marcin.jedynski 2018-11-18 02:10:25 +01:00
commit e0973ca732
9 changed files with 188 additions and 109 deletions

View File

@ -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
}

BIN
app/release/release/app.aab Normal file

Binary file not shown.

View File

@ -37,7 +37,7 @@
</activity>
<activity
android:name=".activity.MapActivity"
android:label="@string/title_activity_main"
android:label="@string/map_activity_label"
android:launchMode="singleTop" />
<activity
android:name=".activity.LoginActivity"
@ -50,10 +50,6 @@
android:name=".activity.SettingsActivity"
android:label="@string/title_activity_settings" />
<activity
android:name=".service.GoogleLocalizationActivity"
android:label="@string/title_activity_settings" />
<service
android:name=".service.BackgroundLocalizationService"
android:exported="false"

View File

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

View File

@ -10,7 +10,9 @@ import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import com.getbase.floatingactionbutton.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
@ -29,8 +31,6 @@ import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
@ -63,6 +63,7 @@ import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import timber.log.Timber;
import java.util.Set;
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
@ -93,7 +94,7 @@ public class MapActivity extends BaseActivity
private HashMap<String, Marker> markerHash = new HashMap<>();
private Set<String> 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};
@ -349,7 +350,7 @@ public class MapActivity extends BaseActivity
if (coordsList.isEmpty()) {
Log.e(tag, "200 empty []");
mapboxMap.clear();
//mapboxMap.clear();
return;
}
@ -378,8 +379,6 @@ public class MapActivity extends BaseActivity
}
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();
}
}

View File

@ -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<LatLng> {
// 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;
}
}
}

View File

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

View File

@ -43,7 +43,6 @@
<!--PulsingLayerOpacityColorActivity activity-->
<string name="fab_title_hotels">Hotele</string>
<string name="fab_title_parks">Parkingi</string>
<string name="fab_title_attractions">Atrakcje</string>
<string name="app_name">FindMyTutor</string>
<string name="title_activity_startup">Find My Tutor</string>
@ -130,6 +129,7 @@
<string name="settings_category_manuallocation">Ręczny wybór lokalizacji</string>
<string name="navigation_item_feedback">Wyślij nam feedback</string>
<string name="navigation_item_bug">Zgłoś błąd</string>
<string name="fab_title_bound_area">Bounds OFF</string>
</resources>

View File

@ -181,7 +181,7 @@
<!--PulsingLayerOpacityColorActivity activity-->
<string name="fab_title_hotels">TODO</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="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>
@ -205,5 +205,6 @@
<string name="permission_rationale">permission should be granted</string>
<string name="launch_activity" />
<string name="remove_location_updates" />
<string name="map_activity_label">MapActivity</string>
</resources>