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

This commit is contained in:
Adam Domagalski 2018-11-04 17:25:16 +00:00 committed by Gogs
commit 98ee8d1a21
20 changed files with 56868 additions and 97 deletions

1
.gitignore vendored
View File

@ -64,3 +64,4 @@ fastlane/Preview.html
fastlane/screenshots fastlane/screenshots
fastlane/test_output fastlane/test_output
fastlane/readme.md fastlane/readme.md
app/src/main/res/.DS_Store

View File

@ -44,7 +44,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.4.0' implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation "io.swagger:swagger-annotations:1.5.15" implementation "io.swagger:swagger-annotations:1.5.15"
implementation "org.threeten:threetenbp:1.3.5" 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 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
@ -58,4 +58,7 @@ dependencies {
implementation 'com.auth0.android:jwtdecode:1.1.1' implementation 'com.auth0.android:jwtdecode:1.1.1'
implementation 'com.annimon:stream:1.2.1' implementation 'com.annimon:stream:1.2.1'
// FloatingBarMenu
implementation 'com.getbase:floatingactionbutton:1.10.1'
} }

File diff suppressed because it is too large Load Diff

View File

@ -39,12 +39,14 @@ public abstract class BaseActivity
extends AppCompatActivity extends AppCompatActivity
implements BottomNavigationView.OnNavigationItemSelectedListener { implements BottomNavigationView.OnNavigationItemSelectedListener {
String tag = getClass().getName();
protected static final int REQUEST_PERMISSIONS = 100;
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1; private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[] { 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 }; 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; public DrawerLayout drawerLayout;
protected BottomNavigationView navigationView; protected BottomNavigationView navigationView;
protected NavigationView drawerNavigationView; protected NavigationView drawerNavigationView;
@ -54,6 +56,9 @@ public abstract class BaseActivity
private ActionBarDrawerToggle actionBarDrawerToggle; private ActionBarDrawerToggle actionBarDrawerToggle;
private SharingFragment sharingFragment; private SharingFragment sharingFragment;
boolean boolean_permission;
private Fragment userListFragment; private Fragment userListFragment;
private ActiveFragment activeFragment = ActiveFragment.NONE; private ActiveFragment activeFragment = ActiveFragment.NONE;
@ -295,6 +300,12 @@ public abstract class BaseActivity
overridePendingTransition(0, 0); 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) { private void removeFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.hide(fragment); fragmentTransaction.hide(fragment);
@ -304,6 +315,7 @@ public abstract class BaseActivity
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
navigationView.postDelayed(() -> { navigationView.postDelayed(() -> {
int itemId = item.getItemId(); int itemId = item.getItemId();

View File

@ -1,24 +1,49 @@
package com.uam.wmi.findmytutor.activity; package com.uam.wmi.findmytutor.activity;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.location.Location;
import android.content.res.Resources; import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; 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.util.Log;
import android.widget.Toast; 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.Mapbox;
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.MarkerViewOptions;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap; 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.R;
import com.uam.wmi.findmytutor.model.Coordinate; import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.ApiClient; 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.service.CoordinateService;
import com.uam.wmi.findmytutor.utils.PrefUtils; 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.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import timber.log.Timber;
import java.util.Locale; import java.util.Locale;
public class MapActivity extends BaseActivity 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 CoordinateService coordinateService;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
private int mInterval = 10000;
private Handler mHandler = new Handler();
private Runnable mStatusChecker; 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; Locale myLocale;
String currentLanguage = "pl", currentLang; String currentLanguage = "pl", currentLang;
@ -68,28 +102,25 @@ public class MapActivity extends BaseActivity
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
final String authToken = sharedPref.getString("authToken",null); final String authToken = sharedPref.getString("authToken", null);
mStatusChecker = new Runnable() {
@Override
public void run() {
try{
fetchTopCoords();
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
}
};
// fetching coords service // fetching coords service
coordinateService = ApiClient.getClient(getApplicationContext()) coordinateService = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class); .create(CoordinateService.class);
mHandler = new Handler();
//
mStatusChecker = () -> {
try {
fetchTopCoords();
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
};
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 = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState); mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this); mapView.getMapAsync(this);
@ -97,109 +128,258 @@ public class MapActivity extends BaseActivity
startBackgroundLocalizationTask(); startBackgroundLocalizationTask();
currentLanguage = getIntent().getStringExtra(currentLang); currentLanguage = getIntent().getStringExtra(currentLang);
} }
@Override @Override
public void onMapReady(MapboxMap map) { public void onMapReady(MapboxMap mapboxMap) {
mapboxMap = map; MapActivity.this.mapboxMap = mapboxMap;
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions() enableLocationPlugin();
.position(new LatLng(52.466782,16.927549)));
mStatusChecker.run();
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 // // TODO what should happend on click?
// location. // mapboxMap.setOnMarkerClickListener(marker1 -> {
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position", //
new LatLngEvaluator(), marker.getPosition(), point); // // 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.setDuration(2000);
markerAnimator.start(); 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> { private void addStaticLayer() {
// Method is used to interpolate the marker animation. // Toggle layer button
final FloatingActionButton button = findViewById(R.id.toggleMarkerLayerButton);
button.setVisibility(View.VISIBLE);
private LatLng latLng = new LatLng(); button.setOnClickListener(view -> {
@Override Layer layer = mapboxMap.getLayer("museums");
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) { if (layer != null) {
latLng.setLatitude(startValue.getLatitude() if (VISIBLE.equals(layer.getVisibility().getValue())) {
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction)); layer.setProperties(visibility(NONE));
latLng.setLongitude(startValue.getLongitude() } else {
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction)); layer.setProperties(visibility(VISIBLE));
return latLng; }
} }
});
// 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( disposable.add(
// coordinateService.getTopCoordinates() // coordinateService.getTopCoordinates()
coordinateService.getOnlineCoordinates() coordinateService.getOnlineCoordinates()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() { .subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
@Override @Override
public void onSuccess(List<Coordinate> coordsList) { public void onSuccess(List<Coordinate> coordsList) {
Log.e(tag, "");
for (Coordinate element : coordsList) { for (Coordinate element : coordsList) {
String id = element.getUserId(); 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()); if (coordinate != null) {
Log.d("mapper", "b " + coordsMap.size()); Log.e(tag, "Coordin: " + coordinate.getLatitude() + " | " + coordinate.getLongitude());
if (cord != null) { // Log.e(tag, "Element: " + element.getLatitude()+" | " + element.getLongitude());
if (!cord.getLongitude().equals(element.getLongitude()) // Log.e(tag, "isEqual: " + coordinate.getLatitude().equals(element.getLatitude()));
) { // Log.e(tag, "isEqual: " + coordinate.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())));
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", 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.setDuration(2000);
markerAnimator.setInterpolator(new LinearInterpolator());
markerAnimator.start(); markerAnimator.start();
// coordsMap.replace(id,element); // chba niepotrzbene
coordsMap.remove(id); mapboxMap.getMarkerViewManager().update();
coordsMap.put(id,element);
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
Log.d("mapper", "update"); coordsMap.put(id, element);
Log.d("mapper", " "+cord.getTimeStamp()); marker.setPosition(toDestination);
Log.d("mapper", " " + element.getTimeStamp());
// coordsMap.replace(id,element);
coordsMap.remove(id);
coordsMap.put(id,element);
} }
} else { } else {
coordsMap.put(id,element); Log.e(tag, "Marker Added: " + id);
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude()))); 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 @Override
public void onError(Throwable e) { 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 // Add the mapView lifecycle to the activity's lifecycle methods
@Override @Override
public void onResume() { public void onResume() {
@ -235,7 +415,7 @@ public class MapActivity extends BaseActivity
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
mapView.onDestroy(); mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker); mHandler.removeCallbacks(mStatusChecker);
disposable.dispose(); disposable.dispose();
} }
@ -254,4 +434,79 @@ public class MapActivity extends BaseActivity
protected int getNavigationMenuItemId() { protected int getNavigationMenuItemId() {
return R.id.nav_map; 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();
}
}
} }

View File

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

View 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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View 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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View 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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -2,6 +2,7 @@
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:mapbox="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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -19,5 +20,98 @@
</com.mapbox.mapboxsdk.maps.MapView> </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> </android.support.constraint.ConstraintLayout>

View File

@ -39,6 +39,11 @@
<string name="url_terms">http://findmytutor.projektstudencki.pl/terms-of-service/</string> <string name="url_terms">http://findmytutor.projektstudencki.pl/terms-of-service/</string>
<string name="title_version">Wersja</string> <string name="title_version">Wersja</string>
<string name="choose_email_client">Wybierz klienta poczty</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="app_name">FindMyTutor</string>
<string name="title_activity_startup">Find My Tutor</string> <string name="title_activity_startup">Find My Tutor</string>

View File

@ -1,16 +1,76 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#3F51B5</color> <color name="colorPrimary">@color/mapboxGray</color>
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">@color/mapboxGrayDark10</color>
<color name="colorAccent">#dc0004</color> <color name="colorAccent">@color/mapboxPink</color>
<color name="msg_no_notes">#999</color> <color name="msg_no_notes">#cf5e5e</color>
<color name="hint_enter_note">#89c3c3c3</color> <color name="hint_enter_note">#89c3c3c3</color>
<color name="timestamp">#858585</color> <color name="timestamp">#858585</color>
<color name="note_list_text">#232323</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="white">#ffffff</color>
<color name="colorWhiteTransparent">#80ffffff</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> </resources>

View File

@ -163,6 +163,15 @@
<item quantity="other">%d locations reported</item> <item quantity="other">%d locations reported</item>
</plurals> </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="cancel">Close</string>
<string name="userRoom"><b>Room</b></string> <string name="userRoom"><b>Room</b></string>

View File

@ -18,5 +18,8 @@
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> <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> </resources>