Merge branch 'developToMapPravilnie' of s416084/find-my-tutor-android into develop
This commit is contained in:
commit
98ee8d1a21
1
.gitignore
vendored
1
.gitignore
vendored
@ -64,3 +64,4 @@ fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
fastlane/readme.md
|
||||
app/src/main/res/.DS_Store
|
||||
|
@ -44,7 +44,7 @@ dependencies {
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
|
||||
implementation "io.swagger:swagger-annotations:1.5.15"
|
||||
implementation "org.threeten:threetenbp:1.3.5"
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.4.0'
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.6.5'
|
||||
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
|
||||
implementation 'com.android.support:recyclerview-v7:27.1.1'
|
||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
|
||||
@ -58,4 +58,7 @@ dependencies {
|
||||
implementation 'com.auth0.android:jwtdecode:1.1.1'
|
||||
implementation 'com.annimon:stream:1.2.1'
|
||||
|
||||
// FloatingBarMenu
|
||||
implementation 'com.getbase:floatingactionbutton:1.10.1'
|
||||
|
||||
}
|
||||
|
56229
app/src/main/assets/la_hotels.geojson
Normal file
56229
app/src/main/assets/la_hotels.geojson
Normal file
File diff suppressed because it is too large
Load Diff
@ -39,12 +39,14 @@ public abstract class BaseActivity
|
||||
extends AppCompatActivity
|
||||
implements BottomNavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
String tag = getClass().getName();
|
||||
|
||||
protected static final int REQUEST_PERMISSIONS = 100;
|
||||
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
|
||||
|
||||
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[] {
|
||||
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS };
|
||||
|
||||
protected static final int REQUEST_PERMISSIONS = 100;
|
||||
public DrawerLayout drawerLayout;
|
||||
protected BottomNavigationView navigationView;
|
||||
protected NavigationView drawerNavigationView;
|
||||
@ -54,6 +56,9 @@ public abstract class BaseActivity
|
||||
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
private SharingFragment sharingFragment;
|
||||
|
||||
boolean boolean_permission;
|
||||
|
||||
private Fragment userListFragment;
|
||||
private ActiveFragment activeFragment = ActiveFragment.NONE;
|
||||
|
||||
@ -295,6 +300,12 @@ public abstract class BaseActivity
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.activity_content, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void removeFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(fragment);
|
||||
@ -304,6 +315,7 @@ public abstract class BaseActivity
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
||||
|
||||
navigationView.postDelayed(() -> {
|
||||
int itemId = item.getItemId();
|
||||
|
||||
|
@ -1,24 +1,49 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
||||
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.Button;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
@ -26,40 +51,49 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
import okhttp3.ResponseBody;
|
||||
import timber.log.Timber;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class MapActivity extends BaseActivity
|
||||
implements OnMapReadyCallback {
|
||||
implements PermissionsListener, OnMapReadyCallback {
|
||||
private String tag = getClass().getName();
|
||||
|
||||
String tag = "LifeCycleEvents";
|
||||
private PermissionsManager permissionsManager;
|
||||
private LocationComponent locationComponent;
|
||||
LocationManager mLocationManager;
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private int mInterval = 10000;
|
||||
private Handler mHandler;
|
||||
|
||||
private Map<String,Coordinate> coordsMap = new HashMap<>();
|
||||
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private int mInterval = 10000;
|
||||
private Handler mHandler = new Handler();
|
||||
private Runnable mStatusChecker;
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Marker droppedMarker;
|
||||
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
|
||||
private HashMap<String, Marker> markerHash = new HashMap<>();
|
||||
|
||||
private int zoomParam = 17;
|
||||
private int bearingParam = 180;
|
||||
private int tiltParam = 30;
|
||||
|
||||
Locale myLocale;
|
||||
String currentLanguage = "pl", currentLang;
|
||||
|
||||
@ -68,28 +102,25 @@ public class MapActivity extends BaseActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
||||
final String authToken = sharedPref.getString("authToken",null);
|
||||
|
||||
mStatusChecker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
fetchTopCoords();
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, mInterval);
|
||||
}
|
||||
}
|
||||
};
|
||||
final String authToken = sharedPref.getString("authToken", null);
|
||||
|
||||
// fetching coords service
|
||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
mHandler = new Handler();
|
||||
|
||||
//
|
||||
mStatusChecker = () -> {
|
||||
try {
|
||||
fetchTopCoords();
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, mInterval);
|
||||
}
|
||||
};
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
|
||||
@ -97,109 +128,258 @@ public class MapActivity extends BaseActivity
|
||||
startBackgroundLocalizationTask();
|
||||
|
||||
currentLanguage = getIntent().getStringExtra(currentLang);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.position(new LatLng(52.466782,16.927549)));
|
||||
mStatusChecker.run();
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
MapActivity.this.mapboxMap = mapboxMap;
|
||||
enableLocationPlugin();
|
||||
|
||||
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(@NonNull LatLng point) {
|
||||
|
||||
// When the user clicks on the map, we want to animate the marker to that
|
||||
// location.
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), point);
|
||||
// // TODO what should happend on click?
|
||||
// mapboxMap.setOnMarkerClickListener(marker1 -> {
|
||||
//
|
||||
// // Show a toast with the title of the selected marker
|
||||
//// Toast.makeText(MapActivity.this, marker.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
// return true;
|
||||
// });
|
||||
|
||||
|
||||
setOnMapLongClickListener();
|
||||
// addStaticLayer();
|
||||
}
|
||||
|
||||
private void setOnMapLongClickListener() {
|
||||
|
||||
final boolean[] cancel = {false};
|
||||
Button selectLocationButton = findViewById(R.id.select_location_button);
|
||||
|
||||
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
|
||||
selectLocationButton.setVisibility(View.VISIBLE);
|
||||
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
|
||||
|
||||
|
||||
if (droppedMarker == null) {
|
||||
|
||||
droppedMarker = mapboxMap.addMarker(new MarkerOptions()
|
||||
.position(latLng)
|
||||
.icon(icon)
|
||||
.title("My Loc")
|
||||
.setSnippet("Snipecik"));
|
||||
|
||||
} else if (!cancel[0]) {
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(droppedMarker, "position",
|
||||
new mapUtils.LatLngEvaluator(), droppedMarker.getPosition(), latLng);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
|
||||
selectLocationButton.setOnClickListener((View view) -> {
|
||||
|
||||
if (!cancel[0] && droppedMarker != null) {
|
||||
// Toast instructing user to tap on the mapboxMap
|
||||
|
||||
|
||||
// TODO PUT MANUAL CORD
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latLng.getLatitude(),
|
||||
latLng.getLongitude(),
|
||||
latLng.getAltitude(),
|
||||
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext())
|
||||
);
|
||||
|
||||
disposable.add(
|
||||
coordinateService
|
||||
.postCoordinate(coordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onSuccess(Coordinate coord) {
|
||||
Log.e(tag + "POST", String.valueOf(coord));
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
Log.e(tag + "onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
Log.e(tag + "onError", RestApiHelper.getErrorMessage(responseBody));
|
||||
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
}
|
||||
|
||||
|
||||
Toast.makeText(
|
||||
MapActivity.this,
|
||||
"Manual Locations selected!" + latLng,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
|
||||
selectLocationButton.setBackgroundColor(
|
||||
ContextCompat.getColor(MapActivity.this, R.color.colorAccent));
|
||||
selectLocationButton.setText("Remove Manual location");
|
||||
selectLocationButton.setVisibility(View.VISIBLE);
|
||||
cancel[0] = true;
|
||||
} else {
|
||||
|
||||
// TODO REMOVE Manual Locatio
|
||||
mapboxMap.removeMarker(droppedMarker);
|
||||
droppedMarker = null;
|
||||
|
||||
Toast.makeText(
|
||||
MapActivity.this,
|
||||
"REMOVED!!" + latLng,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
|
||||
cancel[0] = false;
|
||||
selectLocationButton.setVisibility(View.GONE);
|
||||
selectLocationButton.setText(R.string.select_a_location);
|
||||
selectLocationButton.setBackgroundColor(
|
||||
ContextCompat.getColor(MapActivity.this, R.color.colorPrimary));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private static class LatLngEvaluator implements TypeEvaluator<LatLng> {
|
||||
// Method is used to interpolate the marker animation.
|
||||
private void addStaticLayer() {
|
||||
// Toggle layer button
|
||||
final FloatingActionButton button = findViewById(R.id.toggleMarkerLayerButton);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
|
||||
private LatLng latLng = new LatLng();
|
||||
button.setOnClickListener(view -> {
|
||||
|
||||
@Override
|
||||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
|
||||
latLng.setLatitude(startValue.getLatitude()
|
||||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
|
||||
latLng.setLongitude(startValue.getLongitude()
|
||||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
|
||||
return latLng;
|
||||
}
|
||||
Layer layer = mapboxMap.getLayer("museums");
|
||||
if (layer != null) {
|
||||
if (VISIBLE.equals(layer.getVisibility().getValue())) {
|
||||
layer.setProperties(visibility(NONE));
|
||||
} else {
|
||||
layer.setProperties(visibility(VISIBLE));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// TODO here we create static layer, we are able to hide/show (but we cannot put markers inthere)
|
||||
VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
|
||||
mapboxMap.addSource(museums);
|
||||
|
||||
CircleLayer museumsLayer = new CircleLayer("museums", "museums_source");
|
||||
museumsLayer.setSourceLayer("museum-cusco");
|
||||
museumsLayer.setProperties(
|
||||
visibility(VISIBLE),
|
||||
circleRadius(8f),
|
||||
circleColor(Color.argb(255, 55, 148, 179))
|
||||
);
|
||||
mapboxMap.addLayer(museumsLayer);
|
||||
}
|
||||
|
||||
private void fetchTopCoords() {
|
||||
private void fetchTopCoords() {
|
||||
|
||||
disposable.add(
|
||||
// coordinateService.getTopCoordinates()
|
||||
coordinateService.getOnlineCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
|
||||
Log.e(tag, "");
|
||||
|
||||
for (Coordinate element : coordsList) {
|
||||
String id = element.getUserId();
|
||||
Coordinate cord = coordsMap.get(id);
|
||||
|
||||
Coordinate coordinate = coordsMap.get(id);
|
||||
Log.e(tag, "hashMapSize: " + coordsMap.size());
|
||||
Log.e(tag, "markerMapSize: " + coordsMap.size());
|
||||
|
||||
Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
|
||||
Log.d("mapper", "b " + coordsMap.size());
|
||||
if (cord != null) {
|
||||
if (!cord.getLongitude().equals(element.getLongitude())
|
||||
) {
|
||||
Log.d("mapper", " cos sie zienilo ");
|
||||
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.title(cord.getUserId())
|
||||
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
|
||||
if (coordinate != null) {
|
||||
Log.e(tag, "Coordin: " + coordinate.getLatitude() + " | " + coordinate.getLongitude());
|
||||
// Log.e(tag, "Element: " + element.getLatitude()+" | " + element.getLongitude());
|
||||
// Log.e(tag, "isEqual: " + coordinate.getLatitude().equals(element.getLatitude()));
|
||||
// Log.e(tag, "isEqual: " + coordinate.getLongitude().equals(element.getLongitude()));
|
||||
|
||||
boolean statement = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
|
||||
Log.e(tag, "diff || diff: " + !statement);
|
||||
if (!statement) {
|
||||
Log.e(tag, "replace and animate");
|
||||
Marker marker = markerHash.get(id);
|
||||
LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude());
|
||||
// TODO fix flickiering markers
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
|
||||
new mapUtils.LatLngEvaluator(),
|
||||
marker.getPosition(),
|
||||
toDestination);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.setInterpolator(new LinearInterpolator());
|
||||
markerAnimator.start();
|
||||
|
||||
|
||||
// coordsMap.replace(id,element);
|
||||
coordsMap.remove(id);
|
||||
coordsMap.put(id,element);
|
||||
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
|
||||
Log.d("mapper", "update");
|
||||
Log.d("mapper", " "+cord.getTimeStamp());
|
||||
Log.d("mapper", " " + element.getTimeStamp());
|
||||
// coordsMap.replace(id,element);
|
||||
coordsMap.remove(id);
|
||||
coordsMap.put(id,element);
|
||||
// chba niepotrzbene
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
|
||||
|
||||
coordsMap.put(id, element);
|
||||
marker.setPosition(toDestination);
|
||||
|
||||
}
|
||||
} else {
|
||||
coordsMap.put(id,element);
|
||||
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
|
||||
Log.e(tag, "Marker Added: " + id);
|
||||
coordsMap.put(id, element);
|
||||
Marker marker = mapboxMap.addMarker(new MarkerOptions()
|
||||
.title(element.getLabel())
|
||||
.position(new LatLng(element.getLatitude(), element.getLongitude())));
|
||||
markerHash.put(id, marker);
|
||||
}
|
||||
}
|
||||
|
||||
for (Coordinate coordinate : coordsMap.values()) {
|
||||
// 300000 = 5mins
|
||||
if ((System.currentTimeMillis() - coordinate.getTimeStamp()) > (long) 300000) {
|
||||
String id = coordinate.getUserId();
|
||||
Marker markerToRemove = markerHash.get(id);
|
||||
markerHash.remove(id);
|
||||
coordsMap.remove(id);
|
||||
mapboxMap.removeMarker(markerToRemove);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("Error",e.toString());
|
||||
|
||||
Log.e("MapActivity onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
Log.e("MapActivity onError", RestApiHelper.getErrorMessage(responseBody));
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add the mapView lifecycle to the activity's lifecycle methods
|
||||
@Override
|
||||
public void onResume() {
|
||||
@ -235,7 +415,7 @@ public class MapActivity extends BaseActivity
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@ -254,4 +434,79 @@ public class MapActivity extends BaseActivity
|
||||
protected int getNavigationMenuItemId() {
|
||||
return R.id.nav_map;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MissingPermission"})
|
||||
private void enableLocationPlugin() {
|
||||
// Check if permissions are enabled and if not request
|
||||
if (PermissionsManager.areLocationPermissionsGranted(this)) {
|
||||
|
||||
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 {
|
||||
permissionsManager = new PermissionsManager(this);
|
||||
permissionsManager.requestLocationPermissions(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
// permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExplanationNeeded(List<String> permissionsToExplain) {
|
||||
Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionResult(boolean granted) {
|
||||
if (granted) {
|
||||
enableLocationPlugin();
|
||||
} else {
|
||||
Toast.makeText(this, R.string.user_location_permission_not_granted, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.content.Context;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class mapUtils {
|
||||
|
||||
|
||||
public static class LatLngEvaluator implements TypeEvaluator<LatLng> {
|
||||
// Method is used to interpolate the marker animation.
|
||||
|
||||
private LatLng latLng = new LatLng();
|
||||
|
||||
@Override
|
||||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
|
||||
latLng.setLatitude(startValue.getLatitude()
|
||||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
|
||||
latLng.setLongitude(startValue.getLongitude()
|
||||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
|
||||
return latLng;
|
||||
}
|
||||
}
|
||||
|
||||
public static String loadJsonFromAsset(Context context, String filename) {
|
||||
// Using this method to load in GeoJSON files from the assets folder.
|
||||
try {
|
||||
InputStream is = context.getAssets().open(filename);
|
||||
int size = is.available();
|
||||
byte[] buffer = new byte[size];
|
||||
is.read(buffer);
|
||||
is.close();
|
||||
return new String(buffer, "UTF-8");
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
11
app/src/main/res/drawable-v24/fab_label_background.xml
Normal file
11
app/src/main/res/drawable-v24/fab_label_background.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/black_semi_transparent"/>
|
||||
<padding
|
||||
android:left="16dp"
|
||||
android:top="4dp"
|
||||
android:right="16dp"
|
||||
android:bottom="4dp"/>
|
||||
<corners
|
||||
android:radius="2dp"/>
|
||||
</shape>
|
BIN
app/src/main/res/drawable/blue_marker.png
Normal file
BIN
app/src/main/res/drawable/blue_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/drawable/blue_marker_view.png
Normal file
BIN
app/src/main/res/drawable/blue_marker_view.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
11
app/src/main/res/drawable/fab_label_background.xml
Normal file
11
app/src/main/res/drawable/fab_label_background.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/black_semi_transparent"/>
|
||||
<padding
|
||||
android:left="16dp"
|
||||
android:top="4dp"
|
||||
android:right="16dp"
|
||||
android:bottom="4dp"/>
|
||||
<corners
|
||||
android:radius="2dp"/>
|
||||
</shape>
|
BIN
app/src/main/res/drawable/green_marker.png
Normal file
BIN
app/src/main/res/drawable/green_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
34
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
34
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
BIN
app/src/main/res/drawable/purple_marker.png
Normal file
BIN
app/src/main/res/drawable/purple_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
BIN
app/src/main/res/drawable/red_marker.png
Normal file
BIN
app/src/main/res/drawable/red_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
app/src/main/res/drawable/yellow_marker.png
Normal file
BIN
app/src/main/res/drawable/yellow_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
@ -2,6 +2,7 @@
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:fab="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -19,5 +20,98 @@
|
||||
|
||||
</com.mapbox.mapboxsdk.maps.MapView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
tools:layout_editor_absoluteX="0dp"
|
||||
tools:layout_editor_absoluteY="1dp">
|
||||
|
||||
<!-- Implementation of find my location button -->
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/toggleMarkerLayerButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:clickable="true"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="@color/msg_no_notes"
|
||||
app:layout_constraintTop_toBottomOf="@+id/logoutButton"
|
||||
mapbox:srcCompat="@android:drawable/ic_dialog_map"
|
||||
tools:layout_editor_absoluteX="0dp" />
|
||||
|
||||
<android.support.design.widget.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"
|
||||
app:borderWidth="0dp"
|
||||
app:elevation="6dp"
|
||||
app:fabSize="normal"
|
||||
app:fab_colorDisabled="@color/mapboxGray"
|
||||
app:fab_colorNormal="@color/mapboxGray"
|
||||
app:pressedTranslationZ="12dp" />
|
||||
|
||||
<com.getbase.floatingactionbutton.FloatingActionsMenu
|
||||
android:id="@+id/multiple_actions_parent_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="16dp"
|
||||
fab:fab_addButtonColorNormal="@color/mapboxRed"
|
||||
fab:fab_addButtonColorPressed="@color/mapboxWhite"
|
||||
fab:fab_addButtonPlusIconColor="@color/mapboxWhite"
|
||||
fab:fab_labelStyle="@style/menu_labels_style"
|
||||
tools:layout_editor_absoluteX="200dp"
|
||||
tools:layout_editor_absoluteY="255dp">
|
||||
|
||||
<com.getbase.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_toggle_hotels"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
fab:fab_colorNormal="@color/mapboxBlue"
|
||||
fab:fab_colorPressed="@color/mapboxWhite"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_title="@string/fab_title_hotels" />
|
||||
|
||||
<com.getbase.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_toggle_parks"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
fab:fab_colorNormal="@color/mapboxGreen"
|
||||
fab:fab_colorPressed="@color/mapboxWhite"
|
||||
fab:fab_size="mini"
|
||||
fab:fab_title="@string/fab_title_parks" />
|
||||
|
||||
<com.getbase.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_toggle_attractions"
|
||||
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" />
|
||||
</com.getbase.floatingactionbutton.FloatingActionsMenu>
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/select_location_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_margin="8dp"
|
||||
android:background="@color/colorPrimary"
|
||||
android:text="@string/select_a_location"
|
||||
android:textColor="@android:color/white"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -39,6 +39,11 @@
|
||||
<string name="url_terms">http://findmytutor.projektstudencki.pl/terms-of-service/</string>
|
||||
<string name="title_version">Wersja</string>
|
||||
<string name="choose_email_client">Wybierz klienta poczty</string>
|
||||
|
||||
<!--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>
|
||||
|
||||
|
@ -1,16 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#dc0004</color>
|
||||
<color name="msg_no_notes">#999</color>
|
||||
<color name="colorPrimary">@color/mapboxGray</color>
|
||||
<color name="colorPrimaryDark">@color/mapboxGrayDark10</color>
|
||||
<color name="colorAccent">@color/mapboxPink</color>
|
||||
<color name="msg_no_notes">#cf5e5e</color>
|
||||
<color name="hint_enter_note">#89c3c3c3</color>
|
||||
<color name="timestamp">#858585</color>
|
||||
<color name="note_list_text">#232323</color>
|
||||
|
||||
|
||||
<color name="colorWhite">#ffffff</color>
|
||||
<color name="colorWhite">#d1e200f6</color>
|
||||
<color name="white">#ffffff</color>
|
||||
<color name="colorWhiteTransparent">#80ffffff</color>
|
||||
|
||||
|
||||
<color name="materialGrey">#F5F5F5</color>
|
||||
<color name="materialDarkGrey">#dfdfdf</color>
|
||||
|
||||
<color name="mapboxWhite">#FFFFFF</color>
|
||||
|
||||
<color name="mapboxGreenDark">#269561</color>
|
||||
<color name="mapboxGreen">#33c377</color>
|
||||
<color name="mapboxGreenLight">#afdec5</color>
|
||||
<color name="mapboxGreenFaint">#e8f5ee</color>
|
||||
|
||||
<color name="mapboxBlue">#4264fb</color>
|
||||
<color name="mapboxBlueDark">#314ccd</color>
|
||||
<color name="mapboxBlueLight">#aab7ef</color>
|
||||
<color name="mapboxBlueFaint">#edf0fd</color>
|
||||
|
||||
<color name="mapboxGrayDark">#273d56</color>
|
||||
<color name="mapboxGrayDark10">#476483</color>
|
||||
<color name="mapboxGrayExtraDark">#2d3c4f</color>
|
||||
<color name="mapboxGray">#607d9c</color>
|
||||
<color name="mapboxGrayLight">#c6d2e1</color>
|
||||
<color name="mapboxGrayFaint">#f4f7fb</color>
|
||||
|
||||
<color name="mapboxPinkDark">#b43b71</color>
|
||||
<color name="mapboxPink">#ee4e8b</color>
|
||||
<color name="mapboxPinkLight">#f8c8da</color>
|
||||
<color name="mapboxPinkFaint">#fbe5ee</color>
|
||||
|
||||
<color name="mapboxPurpleDark">#5a3fc0</color>
|
||||
<color name="mapboxPurpleDark10">#5E3AD2</color>
|
||||
<color name="mapboxPurple">#7753eb</color>
|
||||
<color name="mapboxPurpleLight">#c5b9eb</color>
|
||||
<color name="mapboxPurpleLight10">#916DFF</color>
|
||||
<color name="mapboxPurpleFaint">#f2effa</color>
|
||||
|
||||
<color name="mapboxTealDark">#136174</color>
|
||||
<color name="mapboxTeal">#11b4da</color>
|
||||
<color name="mapboxTealLight">#a4deeb</color>
|
||||
<color name="mapboxTealFaint">#d7f1f6</color>
|
||||
|
||||
<color name="mapboxOrangeDark">#ba7334</color>
|
||||
<color name="mapboxOrange">#f79640</color>
|
||||
<color name="mapboxOrangeLight">#fbcea6</color>
|
||||
<color name="mapboxOrangeFaint">#feefe2</color>
|
||||
|
||||
<color name="mapboxRedDark">#ba3b3f</color>
|
||||
<color name="mapboxRed">#f74e4e</color>
|
||||
<color name="mapboxRedLight">#f6b7b7</color>
|
||||
<color name="mapboxRedFaint">#fbe5e5</color>
|
||||
|
||||
<color name="mapboxYellowDark">#a4a62d</color>
|
||||
<color name="mapboxYellow">#d9d838</color>
|
||||
<color name="mapboxYellowLight">#FFF5A0</color>
|
||||
<color name="mapboxYellowFaint">#FCFCDF</color>
|
||||
|
||||
<!-- FAB menu colors -->
|
||||
<color name="black_semi_transparent">#B2000000</color>
|
||||
<color name="half_black">#808080</color>
|
||||
<color name="white_pressed">#f1f1f1</color>
|
||||
|
||||
</resources>
|
||||
|
@ -163,6 +163,15 @@
|
||||
<item quantity="other">%d locations reported</item>
|
||||
</plurals>
|
||||
|
||||
<string name="title_activity_main2">Main2Activity</string>
|
||||
|
||||
<!--PulsingLayerOpacityColorActivity activity-->
|
||||
<string name="fab_title_hotels">Hotels</string>
|
||||
<string name="fab_title_parks">Parks</string>
|
||||
<string name="fab_title_attractions">Attractions</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>
|
||||
|
||||
<string name="cancel">Close</string>
|
||||
<string name="userRoom"><b>Room</b></string>
|
||||
|
@ -18,5 +18,8 @@
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
|
||||
<style name="menu_labels_style">
|
||||
<item name="android:background">@drawable/fab_label_background</item>
|
||||
<item name="android:textColor">@color/mapboxWhite</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user