merge
9
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="IgnoreResultOfCall" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="m_reportAllNonLibraryCalls" value="false" />
|
||||
<option name="callCheckString" value="java.io.File,.*,java.io.InputStream,read|skip|available|markSupported,java.io.Reader,read|skip|ready|markSupported,java.lang.Boolean,.*,java.lang.Byte,.*,java.lang.Character,.*,java.lang.Double,.*,java.lang.Float,.*,java.lang.Integer,.*,java.lang.Long,.*,java.lang.Math,.*,java.lang.Object,equals|hashCode|toString,java.lang.Short,.*,java.lang.StrictMath,.*,java.lang.String,.*,java.lang.Thread,interrupted,java.math.BigInteger,.*,java.math.BigDecimal,.*,java.net.InetAddress,.*,java.net.URI,.*,java.util.Arrays,.*,java.util.List,of,java.util.Set,of,java.util.Map,of|ofEntries|entry,java.util.Collections,(?!addAll).*,java.util.UUID,.*,java.util.regex.Matcher,pattern|toMatchResult|start|end|group|groupCount|matches|find|lookingAt|quoteReplacement|replaceAll|replaceFirst|regionStart|regionEnd|hasTransparentBounds|hasAnchoringBounds|hitEnd|requireEnd,java.util.regex.Pattern,.*,java.util.stream.BaseStream,.*" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -59,7 +59,7 @@ dependencies {
|
||||
implementation 'com.auth0.android:jwtdecode:1.1.1'
|
||||
implementation 'com.annimon:stream:1.2.1'
|
||||
implementation 'com.google.android.gms:play-services-location:16.0.0'
|
||||
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.0.0'
|
||||
// FloatingBarMenu
|
||||
implementation 'com.getbase:floatingactionbutton:1.10.1'
|
||||
|
||||
|
398
app/src/main/assets/building.geojson
Normal file
@ -0,0 +1,398 @@
|
||||
{
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło B",
|
||||
"longitude" : 52.466669,
|
||||
"latitude" : 16.926624
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92618,
|
||||
52.466248
|
||||
],
|
||||
[
|
||||
16.926435,
|
||||
52.466201
|
||||
],
|
||||
[
|
||||
16.92646,
|
||||
52.466255
|
||||
],
|
||||
[
|
||||
16.926516,
|
||||
52.466244
|
||||
],
|
||||
[
|
||||
16.926999,
|
||||
52.46711
|
||||
],
|
||||
[
|
||||
16.926796,
|
||||
52.467145
|
||||
],
|
||||
[
|
||||
16.926782,
|
||||
52.467117
|
||||
],
|
||||
[
|
||||
16.926784,
|
||||
52.467121
|
||||
],
|
||||
[
|
||||
16.926691,
|
||||
52.467139
|
||||
],
|
||||
[
|
||||
16.926662,
|
||||
52.46709
|
||||
],
|
||||
[
|
||||
16.926757,
|
||||
52.467072
|
||||
],
|
||||
[
|
||||
16.926544,
|
||||
52.466691
|
||||
],
|
||||
[
|
||||
16.926434,
|
||||
52.46671
|
||||
],
|
||||
[
|
||||
16.926396,
|
||||
52.466655
|
||||
],
|
||||
[
|
||||
16.926519,
|
||||
52.466628
|
||||
],
|
||||
[
|
||||
16.926323,
|
||||
52.466281
|
||||
],
|
||||
[
|
||||
16.926213,
|
||||
52.466307
|
||||
],
|
||||
[
|
||||
16.92618,
|
||||
52.466248
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "41798cf663bc55c10e6c51c3fe174eda"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Biblioteka",
|
||||
"longitude" : 52.467351,
|
||||
"latitude" : 16.926900
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927048,
|
||||
52.46721
|
||||
],
|
||||
[
|
||||
16.926627,
|
||||
52.467295
|
||||
],
|
||||
[
|
||||
16.926732,
|
||||
52.467482
|
||||
],
|
||||
[
|
||||
16.926876,
|
||||
52.467461
|
||||
],
|
||||
[
|
||||
16.926967,
|
||||
52.467428
|
||||
],
|
||||
[
|
||||
16.927014,
|
||||
52.467402
|
||||
],
|
||||
[
|
||||
16.927171,
|
||||
52.467359
|
||||
],
|
||||
[
|
||||
16.9271,
|
||||
52.467202
|
||||
],
|
||||
[
|
||||
16.927048,
|
||||
52.46721
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "7328c3c9dffd3e76be8d3dcef4f58ddc"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Łącznik",
|
||||
"longitude" : 52.466619,
|
||||
"latitude" : 16.926860
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926759,
|
||||
52.466683
|
||||
],
|
||||
[
|
||||
16.927088,
|
||||
52.46661
|
||||
],
|
||||
[
|
||||
16.927019,
|
||||
52.466502
|
||||
],
|
||||
[
|
||||
16.9267,
|
||||
52.466571
|
||||
],
|
||||
[
|
||||
16.926759,
|
||||
52.466683
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "8c19ee28e4c07ece9756fd21f290713b"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło A",
|
||||
"longitude" : 52.466559,
|
||||
"latitude" : 16.927163
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926771,
|
||||
52.466106
|
||||
],
|
||||
[
|
||||
16.926898,
|
||||
52.466079
|
||||
],
|
||||
[
|
||||
16.926926,
|
||||
52.466126
|
||||
],
|
||||
[
|
||||
16.927026,
|
||||
52.466107
|
||||
],
|
||||
[
|
||||
16.92723,
|
||||
52.466473
|
||||
],
|
||||
[
|
||||
16.927184,
|
||||
52.466483
|
||||
],
|
||||
[
|
||||
16.927243,
|
||||
52.466586
|
||||
],
|
||||
[
|
||||
16.927334,
|
||||
52.46656
|
||||
],
|
||||
[
|
||||
16.927602,
|
||||
52.466889
|
||||
],
|
||||
[
|
||||
16.927275,
|
||||
52.466959
|
||||
],
|
||||
[
|
||||
16.926771,
|
||||
52.466106
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c33bfba772c85cc38ae417843d31b1ff"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Aule",
|
||||
"longitude" : 52.467114,
|
||||
"latitude" : 16.927621
|
||||
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92731,
|
||||
52.467158
|
||||
],
|
||||
[
|
||||
16.927315,
|
||||
52.46718
|
||||
],
|
||||
[
|
||||
16.927348,
|
||||
52.467199
|
||||
],
|
||||
[
|
||||
16.927393,
|
||||
52.467224
|
||||
],
|
||||
[
|
||||
16.927426,
|
||||
52.467239
|
||||
],
|
||||
[
|
||||
16.927476,
|
||||
52.467258
|
||||
],
|
||||
[
|
||||
16.92755,
|
||||
52.467264
|
||||
],
|
||||
[
|
||||
16.927625,
|
||||
52.467263
|
||||
],
|
||||
[
|
||||
16.927699,
|
||||
52.467246
|
||||
],
|
||||
[
|
||||
16.92776,
|
||||
52.467212
|
||||
],
|
||||
[
|
||||
16.927821,
|
||||
52.467158
|
||||
],
|
||||
[
|
||||
16.927838,
|
||||
52.467099
|
||||
],
|
||||
[
|
||||
16.927827,
|
||||
52.467059
|
||||
],
|
||||
[
|
||||
16.927793,
|
||||
52.467012
|
||||
],
|
||||
[
|
||||
16.927738,
|
||||
52.466976
|
||||
],
|
||||
[
|
||||
16.927661,
|
||||
52.466949
|
||||
],
|
||||
[
|
||||
16.927581,
|
||||
52.466939
|
||||
],
|
||||
[
|
||||
16.927534,
|
||||
52.466938
|
||||
],
|
||||
[
|
||||
16.927467,
|
||||
52.466949
|
||||
],
|
||||
[
|
||||
16.927387,
|
||||
52.467047
|
||||
],
|
||||
[
|
||||
16.927315,
|
||||
52.467153
|
||||
],
|
||||
[
|
||||
16.92731,
|
||||
52.467158
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c779419e3fd7faef8555e1099547a82c"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Hol",
|
||||
"longitude" : 52.4671021,
|
||||
"latitude" : 16.927122
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926625,
|
||||
52.467294
|
||||
],
|
||||
[
|
||||
16.926568,
|
||||
52.46719
|
||||
],
|
||||
[
|
||||
16.927008,
|
||||
52.467108
|
||||
],
|
||||
[
|
||||
16.926953,
|
||||
52.467024
|
||||
],
|
||||
[
|
||||
16.927463,
|
||||
52.466919
|
||||
],
|
||||
[
|
||||
16.927467,
|
||||
52.466956
|
||||
],
|
||||
[
|
||||
16.927316,
|
||||
52.467153
|
||||
],
|
||||
[
|
||||
16.926907,
|
||||
52.467235
|
||||
],
|
||||
[
|
||||
16.926625,
|
||||
52.467294
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "facdd5349991758b9ad99d4e123c91cc"
|
||||
}
|
||||
],
|
||||
"type": "FeatureCollection"
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
@ -29,9 +30,16 @@ import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.ActiveFragment;
|
||||
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RxSearchObservable;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||
@ -41,27 +49,29 @@ 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};
|
||||
|
||||
public DrawerLayout drawerLayout;
|
||||
protected BottomNavigationView navigationView;
|
||||
protected NavigationView drawerNavigationView;
|
||||
protected DrawerLayout sideDrawer;
|
||||
protected Toolbar toolbar;
|
||||
protected boolean isTutor;
|
||||
|
||||
String tag = getClass().getName();
|
||||
|
||||
protected FeedbackUtils feedbackUtils;
|
||||
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
private SharingFragment sharingFragment;
|
||||
|
||||
private Fragment userListFragment;
|
||||
private ActiveFragment activeFragment = ActiveFragment.NONE;
|
||||
private SearchView searchView;
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -79,7 +89,9 @@ public abstract class BaseActivity
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
|
||||
/* launchIntent = new Intent(getApplicationContext(), BlacklistActivity.class);
|
||||
startActivity(launchIntent);*/
|
||||
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
|
||||
|
||||
/* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class);
|
||||
startActivity(launchIntent);*/
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
|
||||
@ -88,6 +100,7 @@ public abstract class BaseActivity
|
||||
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
|
||||
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
|
||||
|
||||
stopBackgroundLocalizationTask();
|
||||
}
|
||||
|
||||
@ -122,14 +135,12 @@ public abstract class BaseActivity
|
||||
userListFragment = new UsersListFragment();
|
||||
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
if (!isTutor) {
|
||||
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void checkPermissions() {
|
||||
final List<String> missingPermissions = new ArrayList<String>();
|
||||
|
||||
@ -247,38 +258,46 @@ public abstract class BaseActivity
|
||||
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
|
||||
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
||||
final SearchView searchView = (SearchView) myActionMenuItem.getActionView();
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String input) {
|
||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||
executeUserListSearch(input);
|
||||
}
|
||||
searchView = (SearchView) myActionMenuItem.getActionView();
|
||||
|
||||
return false;
|
||||
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus && activeFragment.equals(ActiveFragment.NONE)) {
|
||||
restoreMapMarkers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String input) {
|
||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||
executeUserListSearch(input);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
RxSearchObservable.fromView(searchView)
|
||||
.map(String::toLowerCase)
|
||||
.filter(t -> !t.trim().isEmpty())
|
||||
.debounce(300, TimeUnit.MILLISECONDS)
|
||||
.distinctUntilChanged()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::executeSearch);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeUserListSearch(String input) {
|
||||
private void executeSearch(String input) {
|
||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||
((UsersListFragment) userListFragment).searchUser(input);
|
||||
} else if (activeFragment.equals(ActiveFragment.NONE)) {
|
||||
searchUser(input);
|
||||
}
|
||||
}
|
||||
|
||||
public void searchUser(String textToSearch) {
|
||||
}
|
||||
|
||||
public void restoreMapMarkers() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -289,7 +308,6 @@ public abstract class BaseActivity
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
@ -311,13 +329,13 @@ public abstract class BaseActivity
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
||||
|
||||
navigationView.postDelayed(() -> {
|
||||
int itemId = item.getItemId();
|
||||
|
||||
if (itemId == R.id.nav_map) {
|
||||
removeFragment(sharingFragment);
|
||||
removeFragment(userListFragment);
|
||||
activeFragment = ActiveFragment.NONE;
|
||||
} else if (itemId == R.id.nav_profile) {
|
||||
loadUserSettingsFragment();
|
||||
} else if (itemId == R.id.nav_user_list) {
|
||||
|
@ -33,6 +33,7 @@ import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -72,12 +73,6 @@ public class LoginActivity extends AppCompatActivity {
|
||||
return false;
|
||||
});
|
||||
|
||||
Switch tutorLogin = findViewById(R.id.tutor_login_switch);
|
||||
|
||||
tutorLogin.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
PrefUtils.storeIsTutor(getApplicationContext(), isChecked);
|
||||
});
|
||||
|
||||
Button mEmailSignInButton = findViewById(R.id.email_sign_in_button);
|
||||
mEmailSignInButton.setOnClickListener(view -> attemptLogin());
|
||||
|
||||
@ -158,17 +153,9 @@ public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private void loginProcess(String email, String password) {
|
||||
Log.e("LOGIN", String.valueOf(PrefUtils.getIsTutor(getApplicationContext())));
|
||||
ValidateUser user = new ValidateUser(email, password);
|
||||
|
||||
//Fake validate
|
||||
LdapUser user = new LdapUser(email, password, "admin", (PrefUtils.getIsTutor(getApplicationContext())) ? "Tutor" : "Student", "Imię", "Nazwisko", email);
|
||||
|
||||
// ValidateUser user = new ValidateUser(email, password);
|
||||
|
||||
// LDAP logging
|
||||
// disposable.add(ldapService.validate(user)
|
||||
|
||||
disposable.add(ldapService.fakeValidate(user)
|
||||
disposable.add(ldapService.validate(user)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
@ -192,13 +179,20 @@ public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
String token = jwtToken.getToken();
|
||||
JWT jwt = new JWT(token);
|
||||
Claim role = jwt.getClaim("nameid");
|
||||
Claim userId = jwt.getClaim("nameid");
|
||||
Claim role = jwt.getClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
|
||||
|
||||
if(Objects.requireNonNull(role.asString()).equals("Student")){
|
||||
PrefUtils.storeIsTutor(getApplicationContext(), false);
|
||||
}
|
||||
|
||||
Log.e("LOGOWANIE",role.asString());
|
||||
|
||||
PrefUtils.storeIsLoggedIn(getApplicationContext(), true);
|
||||
PrefUtils.storeApiKey(getApplicationContext(), token);
|
||||
PrefUtils.storeUserId(getApplicationContext(), role.asString());
|
||||
PrefUtils.storeUserId(getApplicationContext(), userId.asString());
|
||||
|
||||
getUserProfile(role.asString());
|
||||
getUserProfile(userId.asString());
|
||||
|
||||
Intent data = new Intent();
|
||||
String txt = "Main Activity";
|
||||
|
@ -6,13 +6,9 @@ import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
@ -23,6 +19,8 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
@ -39,9 +37,6 @@ import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
@ -56,6 +51,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
@ -64,14 +60,6 @@ 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;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
||||
|
||||
|
||||
public class MapActivity extends BaseActivity
|
||||
implements PermissionsListener, OnMapReadyCallback {
|
||||
@ -87,9 +75,14 @@ public class MapActivity extends BaseActivity
|
||||
private int mInterval = 10000;
|
||||
private Handler mHandler = new Handler();
|
||||
private Runnable mStatusChecker;
|
||||
private Handler manualLocHandler = new Handler();
|
||||
private Runnable manualLocStatusChecker;
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Button selectLocationButton;
|
||||
private Marker droppedMarker;
|
||||
private Marker tmpLocalMarker;
|
||||
private Coordinate droppedMarkercoordinate;
|
||||
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
|
||||
private HashMap<String, Marker> markerHash = new HashMap<>();
|
||||
private Set<String> previousCoordsIds = new HashSet<>();
|
||||
@ -98,13 +91,15 @@ public class MapActivity extends BaseActivity
|
||||
private int zoomParam = 17;
|
||||
private int bearingParam = 180;
|
||||
private int tiltParam = 30;
|
||||
private String myID;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
||||
|
||||
|
||||
myID = PrefUtils.getUserId(getApplicationContext());
|
||||
// fetching coords service
|
||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
@ -120,8 +115,10 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
|
||||
selectLocationButton = findViewById(R.id.select_location_button);
|
||||
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
mapView = findViewById(R.id.mapView);
|
||||
@ -132,14 +129,31 @@ public class MapActivity extends BaseActivity
|
||||
handleBackgroundTaskLifeCycle();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
MapActivity.this.mapboxMap = mapboxMap;
|
||||
mStatusChecker.run();
|
||||
enableLocationPlugin();
|
||||
|
||||
mapboxMap.setOnMarkerClickListener(marker -> {
|
||||
createMarkerModal(marker.getTitle());
|
||||
String id = marker.getTitle();
|
||||
if (id.equals(myID)) {
|
||||
Log.e(tag + "Manual", "my own marker from API");
|
||||
Button rmButton = findViewById(R.id.remove_location_button);
|
||||
rmButton.setVisibility(View.VISIBLE);
|
||||
rmButton.setOnClickListener(view -> {
|
||||
Log.e(tag + "Manual", "manual coords sending stopped");
|
||||
// TODO to remove after BGserv
|
||||
manualLocHandler.removeCallbacks(manualLocStatusChecker);
|
||||
|
||||
rmButton.setVisibility(View.GONE);
|
||||
Toast.makeText(MapActivity.this, "Your marker will disappear in next couple minutes", Toast.LENGTH_SHORT).show();
|
||||
|
||||
});
|
||||
} else {
|
||||
createMarkerModal(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -198,52 +212,69 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
|
||||
|
||||
// Manual loc selection on long tap
|
||||
private void setOnMapLongClickListener() {
|
||||
private void handleError(Throwable error) {
|
||||
showError(error);
|
||||
}
|
||||
|
||||
final boolean[] cancel = {false};
|
||||
Button selectLocationButton = findViewById(R.id.select_location_button);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
private void setOnMapLongClickListener() {
|
||||
|
||||
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
|
||||
selectLocationButton.setVisibility(View.VISIBLE);
|
||||
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.green_marker);
|
||||
|
||||
if (tmpLocalMarker == null) {
|
||||
|
||||
if (droppedMarker == null) {
|
||||
|
||||
droppedMarker = mapboxMap.addMarker(new MarkerOptions()
|
||||
tmpLocalMarker = 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);
|
||||
} else {
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position",
|
||||
new mapUtils.LatLngEvaluator(), tmpLocalMarker.getPosition(), latLng);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
|
||||
selectLocationButton.setOnClickListener((View view) -> {
|
||||
|
||||
if (!cancel[0] && droppedMarker != null) {
|
||||
if (tmpLocalMarker != null) {
|
||||
// Toast instructing user to tap on the mapboxMap
|
||||
|
||||
|
||||
// TODO PUT MANUAL CORD
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
droppedMarkercoordinate = new Coordinate(
|
||||
latLng.getLatitude(),
|
||||
latLng.getLongitude(),
|
||||
latLng.getAltitude(),
|
||||
"approx",
|
||||
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
);
|
||||
|
||||
// TODO remove after BG sending
|
||||
manualLocStatusChecker = () -> {
|
||||
try {
|
||||
Log.e(tag + "Manual", "sending manual coords");
|
||||
// TODO ^^^ wrapper to removve
|
||||
disposable.add(
|
||||
coordinateService
|
||||
.postCoordinate(coordinate)
|
||||
.postCoordinate(droppedMarkercoordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
||||
@ -266,80 +297,36 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
}
|
||||
}));
|
||||
// TODO \/\/\/\/\/ wrapper to removve
|
||||
} finally {
|
||||
manualLocHandler.postDelayed(manualLocStatusChecker, mInterval);
|
||||
}
|
||||
};
|
||||
manualLocStatusChecker.run();
|
||||
|
||||
|
||||
} 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));
|
||||
mapboxMap.removeMarker(tmpLocalMarker);
|
||||
tmpLocalMarker = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void addStaticLayer() {
|
||||
// Toggle layer button
|
||||
final FloatingActionButton button = findViewById(R.id.toggleMarkerLayerButton);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
|
||||
button.setOnClickListener(view -> {
|
||||
|
||||
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() {
|
||||
|
||||
disposable.add(
|
||||
// coordinateService.getTopCoordinates()
|
||||
coordinateService.getOnlineCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -348,12 +335,17 @@ public class MapActivity extends BaseActivity
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
if (coordsList.isEmpty()) {
|
||||
Log.e(tag, "200 empty []");
|
||||
//mapboxMap.clear();
|
||||
return;
|
||||
|
||||
if (coordsList.isEmpty() && droppedMarker == null) {
|
||||
Timber.e("200 empty []");
|
||||
mapboxMap.clear();
|
||||
}
|
||||
|
||||
if (coordsList.isEmpty()) {
|
||||
Timber.e("200 empty []");
|
||||
mapboxMap.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> tmp = new ArrayList<>();
|
||||
for (Coordinate coordinate : coordsList) {
|
||||
@ -364,7 +356,7 @@ public class MapActivity extends BaseActivity
|
||||
if (previousCoordsIds.isEmpty()) {
|
||||
previousCoordsIds.addAll(currentCoordsIds);
|
||||
} else {
|
||||
// here we clear + it returns bool if smthing was removed
|
||||
// here we clear + it returns bool if sth was removed
|
||||
if (previousCoordsIds.removeAll(currentCoordsIds)) {
|
||||
for (String toRemoveId : previousCoordsIds) {
|
||||
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
||||
@ -389,9 +381,6 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
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);
|
||||
@ -417,13 +406,20 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
Log.e(tag, "Marker Added: " + id);
|
||||
|
||||
coordsMap.put(id, element);
|
||||
Marker marker = mapboxMap.addMarker(new MarkerOptions()
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.title(id)
|
||||
.position(new LatLng(element.getLatitude(), element.getLongitude())));
|
||||
.position(new LatLng(element.getLatitude(), element.getLongitude()));
|
||||
// Check if this is me
|
||||
if (id.equals(myID)) {
|
||||
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.blue_marker);
|
||||
markerOptions.setIcon(icon);
|
||||
}
|
||||
Marker marker = mapboxMap.addMarker(markerOptions);
|
||||
|
||||
markerHash.put(id, marker);
|
||||
}
|
||||
|
||||
@ -549,6 +545,8 @@ public class MapActivity extends BaseActivity
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
// TODO remove after BG sending
|
||||
manualLocHandler.removeCallbacks(manualLocStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@ -589,20 +587,52 @@ public class MapActivity extends BaseActivity
|
||||
// }
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
showError(error);
|
||||
|
||||
@Override
|
||||
public void searchUser(String textToSearch) {
|
||||
getUserFromApi(textToSearch);
|
||||
}
|
||||
|
||||
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!";
|
||||
private void getUserFromApi(String userNameToSearch) {
|
||||
disposable.add(
|
||||
userService.apiUsersGet()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map(tutors -> Stream.of(tutors).filter(t ->
|
||||
t.toSearchAbleUserName().toLowerCase().contains(userNameToSearch.toLowerCase())).toList())
|
||||
.subscribeWith(new DisposableSingleObserver<List<User>>() {
|
||||
@Override
|
||||
public void onSuccess(List<User> users) {
|
||||
filterMarkers(users);
|
||||
}
|
||||
|
||||
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void filterMarkers(List<User> users) {
|
||||
restoreMapMarkers();
|
||||
|
||||
Icon icon1 = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.custom_marker);
|
||||
|
||||
List<Marker> markersToSet = Stream.of(mapboxMap.getMarkers())
|
||||
.filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(m.getTitle())))
|
||||
.toList();
|
||||
|
||||
for (Marker marker : markersToSet) {
|
||||
marker.setIcon(icon1);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreMapMarkers() {
|
||||
Icon icon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.red_marker);
|
||||
|
||||
for (Marker marker : mapboxMap.getMarkers()) {
|
||||
marker.setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,8 +27,10 @@ import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.service.FeedbackService;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.RightButtonPreference;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -98,10 +100,10 @@ public class SharingFragment extends PreferenceFragment {
|
||||
getStatuses(disposable);
|
||||
|
||||
locationLevelMapping = new HashMap<Integer, String>();
|
||||
locationLevelMapping.put(0,"presence");
|
||||
locationLevelMapping.put(1,"approximated");
|
||||
locationLevelMapping.put(2,"exact");
|
||||
locationLevelMapping.put(3,"manual");
|
||||
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
|
||||
locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
|
||||
locationLevelMapping.put(2, SharingLevel.EXACT.toString());
|
||||
locationLevelMapping.put(2, SharingLevel.MANUAL.toString());
|
||||
|
||||
statusMapping = new HashMap<Integer, String>();
|
||||
statusMapping.put(0,"available");
|
||||
@ -117,7 +119,6 @@ public class SharingFragment extends PreferenceFragment {
|
||||
|
||||
/** Sharing level list **/
|
||||
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
PrefUtils.storeLocationMode(getApplicationContext(),locationLevelMapping.get(Integer.parseInt((String) newValue)));
|
||||
if(PrefUtils.getLocationLevel(getApplicationContext()) == "manual"){
|
||||
preferenceCategory.addPreference(manualLocationList);
|
||||
@ -139,6 +140,7 @@ public class SharingFragment extends PreferenceFragment {
|
||||
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
//ToDo handle manual location change
|
||||
|
||||
return true;
|
||||
});
|
||||
/** Button 'choose from map' button listener **/
|
||||
|
@ -9,6 +9,7 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -44,15 +44,17 @@ public class Coordinate extends BaseResponse {
|
||||
@SerializedName("label")
|
||||
private String label;
|
||||
|
||||
public Coordinate (Double latitude, Double longitude, Double altitude, String label, String userId, String displayMode) {
|
||||
public Coordinate (Double latitude, Double longitude, Double altitude, String approximatedLocation, String label, String userId, String displayMode) {
|
||||
//if (!latitudeRange.contains(latitude)) throw new IllegalArgumentException("Inappropriate latitude value" + latitude);
|
||||
//if (!longtitudeRange.contains(longitude)) throw new IllegalArgumentException("Inappropriate longitude value" + longitude);
|
||||
//if (approximatedLocation == null) throw new IllegalArgumentException("Inappropriate approximatedLocation");
|
||||
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = altitude;
|
||||
this.label = label;
|
||||
this.userId = userId;
|
||||
this.approximatedLocation = approximatedLocation;
|
||||
this.displayMode = displayMode;
|
||||
}
|
||||
|
||||
|
@ -712,6 +712,15 @@ public class User extends BaseResponse {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toSearchAbleUserName(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getFirstName());
|
||||
sb.append(getLastName());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -27,14 +27,18 @@ import com.google.android.gms.location.FusedLocationProviderClient;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
import com.uam.wmi.findmytutor.utils.Consts;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
@ -43,6 +47,9 @@ import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.presenceApproximatedName;
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.presenceLatitude;
|
||||
import static com.uam.wmi.findmytutor.utils.Consts.presencelongitude;
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||
|
||||
public class BackgroundLocalizationService extends Service {
|
||||
@ -50,7 +57,6 @@ public class BackgroundLocalizationService extends Service {
|
||||
private static final String TAG = "MyLocationService";
|
||||
private static final int LOCATION_INTERVAL = 1000;
|
||||
private static final float LOCATION_DISTANCE = 5f;
|
||||
public static String str_receiver = "background.location.broadcast";
|
||||
private static long notify_interval = 10000;
|
||||
Location mLastLocation;
|
||||
Boolean stopService = false;
|
||||
@ -64,6 +70,7 @@ public class BackgroundLocalizationService extends Service {
|
||||
private Runnable mStatusChecker;
|
||||
private FusedLocationProviderClient mFusedLocationClient;
|
||||
|
||||
|
||||
public BackgroundLocalizationService() {
|
||||
providers.add(LocationManager.GPS_PROVIDER);
|
||||
providers.add(LocationManager.NETWORK_PROVIDER);
|
||||
@ -74,6 +81,7 @@ public class BackgroundLocalizationService extends Service {
|
||||
new LocationListener(LocationManager.NETWORK_PROVIDER),
|
||||
new LocationListener(LocationManager.PASSIVE_PROVIDER)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -114,7 +122,6 @@ public class BackgroundLocalizationService extends Service {
|
||||
|
||||
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
||||
|
||||
|
||||
initializeLocationManager();
|
||||
|
||||
Integer providerIndex = 0;
|
||||
@ -202,20 +209,12 @@ public class BackgroundLocalizationService extends Service {
|
||||
|
||||
Log.e("Best localization:", String.valueOf(bestLocation));
|
||||
|
||||
/* if (bestLocation != null)
|
||||
fn_update(bestLocation);
|
||||
*/
|
||||
|
||||
mFusedLocationClient.getLastLocation().addOnSuccessListener(
|
||||
new OnSuccessListener<Location>() {
|
||||
@Override
|
||||
public void onSuccess(Location location) {
|
||||
location -> {
|
||||
if (location != null) {
|
||||
mLastLocation = location;
|
||||
fn_update(location);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -283,11 +282,13 @@ public class BackgroundLocalizationService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class Task extends AsyncTask {
|
||||
ApproximatedLocalization approximatedLocalization;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Double altitude;
|
||||
|
||||
private String approximatedBuildingPart = null;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
@ -296,16 +297,30 @@ public class BackgroundLocalizationService extends Service {
|
||||
latitude = location.getLatitude();
|
||||
longitude = location.getLongitude();
|
||||
altitude = location.getAltitude();
|
||||
approximatedLocalization = new ApproximatedLocalization(mapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
|
||||
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object[] objects) {
|
||||
|
||||
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
|
||||
latitude = presenceLatitude;
|
||||
longitude = presencelongitude;
|
||||
approximatedBuildingPart = presenceApproximatedName;
|
||||
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
List<Double> points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart);
|
||||
|
||||
latitude = points.get(0);
|
||||
longitude = points.get(1);
|
||||
}
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
latitude,
|
||||
longitude,
|
||||
altitude,
|
||||
approximatedBuildingPart,
|
||||
(PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "",
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
|
@ -0,0 +1,69 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.mapbox.geojson.BoundingBox;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.Geometry;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.geojson.Polygon;
|
||||
import com.mapbox.geojson.gson.BoundingBoxDeserializer;
|
||||
import com.mapbox.geojson.gson.GeoJsonAdapterFactory;
|
||||
import com.mapbox.geojson.gson.GeometryDeserializer;
|
||||
import com.mapbox.geojson.gson.PointDeserializer;
|
||||
import com.mapbox.turf.TurfJoins;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
;
|
||||
|
||||
public class ApproximatedLocalization {
|
||||
private FeatureCollection buildingSchema = null;
|
||||
|
||||
public ApproximatedLocalization(String buildingObject) {
|
||||
buildingSchema = fromJson(buildingObject);
|
||||
}
|
||||
|
||||
private FeatureCollection fromJson(@NonNull String json) {
|
||||
GsonBuilder gson = new GsonBuilder();
|
||||
|
||||
gson.registerTypeAdapterFactory(GeoJsonAdapterFactory.create());
|
||||
gson.registerTypeAdapter(Point.class, new PointDeserializer());
|
||||
gson.registerTypeAdapter(Geometry.class, new GeometryDeserializer());
|
||||
gson.registerTypeAdapter(BoundingBox.class, new BoundingBoxDeserializer());
|
||||
|
||||
return gson.create().fromJson(json, FeatureCollection.class);
|
||||
}
|
||||
|
||||
public String getNameOfBuildingPart(Point point) {
|
||||
|
||||
for (Feature feature : Objects.requireNonNull(buildingSchema.features())) {
|
||||
boolean isInside = TurfJoins.inside(point, (Polygon) Objects.requireNonNull(feature.geometry()));
|
||||
|
||||
if (isInside)
|
||||
return Objects.requireNonNull(Objects.requireNonNull(feature.getStringProperty("name")));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Double> getMiddlePointOfBuildingPart(String buildingPart) {
|
||||
|
||||
for (Feature feature : Objects.requireNonNull(buildingSchema.features())) {
|
||||
String partName = feature.getStringProperty("name");
|
||||
|
||||
if (buildingPart != null && buildingPart.equals(partName)) {
|
||||
Double longitude = feature.getNumberProperty("longitude").doubleValue();
|
||||
Double latitude = feature.getNumberProperty("latitude").doubleValue();
|
||||
|
||||
return Arrays.asList(longitude, latitude);
|
||||
}
|
||||
}
|
||||
|
||||
return Arrays.asList(0.0, 0.0);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
public class Consts {
|
||||
public final static Double presenceLatitude = 65.600244;
|
||||
public final static Double presencelongitude = 480.032153;
|
||||
public final static String presenceApproximatedName = "unknown";
|
||||
}
|
@ -138,7 +138,7 @@ public class PrefUtils {
|
||||
}
|
||||
|
||||
public static String getLocale(Context context) {
|
||||
return getSharedPreferences(context).getString("LOCALE", "pl");
|
||||
return getSharedPreferences(context).getString("LOCALE", "en");
|
||||
}
|
||||
|
||||
public static Boolean isBackgroundLocationServiceRunning(Context context) {
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
|
||||
import android.support.v7.widget.SearchView;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.subjects.PublishSubject;
|
||||
|
||||
|
||||
public class RxSearchObservable {
|
||||
|
||||
private RxSearchObservable() {
|
||||
// no instance
|
||||
}
|
||||
|
||||
public static Observable<String> fromView(SearchView searchView) {
|
||||
|
||||
final PublishSubject<String> subject = PublishSubject.create();
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String s) {
|
||||
subject.onNext(s);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String text) {
|
||||
subject.onNext(text);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
return subject;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
public enum SharingLevel {
|
||||
PRESENCE("presence"),
|
||||
APPROXIMATED("approximated"),
|
||||
EXACT("exact"),
|
||||
MANUAL("manual");
|
||||
|
||||
private final String text;
|
||||
|
||||
SharingLevel(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Polygon;
|
||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
@ -29,6 +30,23 @@ public class mapUtils {
|
||||
.include(new LatLng(52.46548540224137, 16.925255680881094))
|
||||
.build();
|
||||
|
||||
// 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
|
||||
// drawBoundsArea(context, mapboxMap, mapView, check);
|
||||
} else {
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(null);
|
||||
mapboxMap.setMinZoomPreference(2);
|
||||
// drawBoundsArea(context, mapboxMap, mapView, check);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove b4 release
|
||||
private static final PolygonOptions boundsArea = new PolygonOptions()
|
||||
.add(WMI_BOUNDS.getNorthWest())
|
||||
.add(WMI_BOUNDS.getNorthEast())
|
||||
@ -40,15 +58,8 @@ public class mapUtils {
|
||||
private static Polygon polygon;
|
||||
private static View crosshair;
|
||||
|
||||
// Map Bounds Area
|
||||
public static void setMapBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
|
||||
|
||||
private static void drawBoundsArea(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);
|
||||
@ -58,13 +69,10 @@ public class mapUtils {
|
||||
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) {
|
||||
@ -79,22 +87,6 @@ public class mapUtils {
|
||||
.newCameraPosition(position), duration);
|
||||
}
|
||||
|
||||
// Function for marker animation
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// read file to JSON
|
||||
public static String loadJsonFromAsset(Context context, String filename) {
|
||||
// Using this method to load in GeoJSON files from the assets folder.
|
||||
@ -112,4 +104,20 @@ public class mapUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// Function for marker animation
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 923 B After Width: | Height: | Size: 444 B |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 1.3 KiB |
@ -72,11 +72,6 @@
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/tutor_login_switch"
|
||||
android:layout_width="192dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Login as Tutor" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/email_sign_in_button"
|
||||
|
@ -111,6 +111,17 @@
|
||||
android:textColor="@android:color/white"
|
||||
android:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/remove_location_button"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_margin="8dp"
|
||||
android:background="@color/colorAccent"
|
||||
android:text="@string/remove_manual_location"
|
||||
android:textColor="@android:color/white"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -1,19 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<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="colorPrimary">#476483</color>
|
||||
<color name="colorPrimaryDark">#3A3553</color>
|
||||
<color name="colorAccent">#CF0E0F</color>
|
||||
<color name="msg_no_notes">#89c3c3c3</color>
|
||||
<color name="hint_enter_note">#89c3c3c3</color>
|
||||
<color name="timestamp">#858585</color>
|
||||
<color name="note_list_text">#232323</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>
|
||||
|
||||
|
@ -212,5 +212,7 @@
|
||||
<string name="remove_location_updates" translatable="false" />
|
||||
<string name="map_activity_label" translatable="false">MapActivity</string>
|
||||
<string name="nav_profile">User profile</string>
|
||||
<string name="remove_manual_location">Remove Manual location</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|