rdy to develop
This commit is contained in:
parent
9a2054deb2
commit
2a79537fbe
@ -18,7 +18,7 @@
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".activity.StartupActivity"
|
||||
android:label="@string/app_name"
|
||||
android:label="@string/title_activity_startup"
|
||||
android:launchMode="singleInstance"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
|
@ -40,10 +40,6 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import android.util.Log;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.maps.MapFragment;
|
||||
import com.uam.wmi.findmytutor.ListViewAdapter;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
@ -10,14 +10,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.util.Log;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
@ -44,15 +36,11 @@ import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class MapActivity extends BaseActivity
|
||||
public class MapActivity extends BaseActivity
|
||||
implements OnMapReadyCallback {
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
|
||||
String tag = "LifeCycleEvents";
|
||||
private static final int REQUEST_PERMISSIONS = 100;
|
||||
private boolean isTutor;
|
||||
|
||||
|
||||
private MapView mapView;
|
||||
@ -169,13 +157,16 @@ import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
|
||||
|
||||
// coordsMap.replace(id,element);
|
||||
coordsMap.remove(id);
|
||||
coordsMap.put(id,element);
|
||||
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
|
||||
Log.d("mapper", "update");
|
||||
Log.d("mapper", " "+cord.getTimeStamp());
|
||||
Log.d("mapper", " " + element.getTimeStamp());
|
||||
// coordsMap.replace(id,element);
|
||||
coordsMap.remove(id);
|
||||
coordsMap.put(id,element);
|
||||
}
|
||||
} else {
|
||||
@ -208,19 +199,7 @@ import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
}
|
||||
startActivity(i);
|
||||
finish();
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
if (isTutor) {
|
||||
fn_permission();
|
||||
}
|
||||
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
|
||||
// Customize map with markers, polylines, etc.
|
||||
|
||||
});
|
||||
// TODO remove logout button
|
||||
configureLogoutButton();
|
||||
}
|
||||
|
||||
|
||||
@ -270,51 +249,6 @@ import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void configureLogoutButton(){
|
||||
// Logout button
|
||||
final FloatingActionButton button = findViewById(R.id.logoutButton);
|
||||
|
||||
button.setOnClickListener(view -> {
|
||||
PrefUtils.cleanUserLocalStorage(getApplicationContext());
|
||||
|
||||
Intent i = getBaseContext().getPackageManager()
|
||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||
if (i != null) {
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
}
|
||||
startActivity(i);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
private void fn_permission() {
|
||||
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
|
||||
if ((ActivityCompat.shouldShowRequestPermissionRationale(MapActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
|
||||
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(MapActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION
|
||||
|
||||
},
|
||||
REQUEST_PERMISSIONS);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (isTutor) {
|
||||
Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(intent);
|
||||
} else {
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() {
|
||||
return R.layout.activity_map;
|
||||
|
@ -1,266 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.RetrofitClientInstance;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class NotificationsActivity extends BaseActivity implements
|
||||
OnMapReadyCallback {
|
||||
|
||||
private int mInterval = 10000;
|
||||
private Handler mHandler;
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Map<String,Coordinate> coordsMap = new HashMap<>();
|
||||
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// This contains the MapView in XML and needs to be called after the access token is configured.
|
||||
setContentView(R.layout.activity_notifications);
|
||||
|
||||
|
||||
// mapInit(savedInstanceState);
|
||||
|
||||
// Mapbox access token is configured here. This needs to be called either in your application
|
||||
// object or in the same activity which contains the mapview.
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
|
||||
|
||||
|
||||
mapView = findViewById(R.id.mapView2);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
|
||||
|
||||
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
||||
final String authToken = sharedPref.getString("authToken",null);
|
||||
|
||||
coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg");
|
||||
|
||||
mHandler = new Handler();
|
||||
|
||||
// fetchTopCoords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.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
|
||||
// location.
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), point);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Runnable mStatusChecker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
fetchTopCoords();
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, mInterval);
|
||||
}
|
||||
}
|
||||
};
|
||||
/*
|
||||
private void mapInit(Bundle savedInstanceState) {
|
||||
// Mapbox access token is configured here. This needs to be called either in your application
|
||||
// object or in the same activity which contains the mapview.
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
// This contains the MapView in XML and needs to be called after the access token is configured.
|
||||
// setContentView(R.layout.activity_notifications);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView2);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
|
||||
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.position(new LatLng(52.466782,16.927549)));
|
||||
|
||||
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(@NonNull LatLng point) {
|
||||
|
||||
// When the user clicks on the map, we want to animate the marker to that
|
||||
// location.
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), point);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}*/
|
||||
|
||||
private void fetchTopCoords() {
|
||||
disposable.add(
|
||||
// coordinateService.getTopCoordinates()
|
||||
coordinateService.getOnlineCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
|
||||
for (Coordinate element : coordsList) {
|
||||
String id = element.getUserId();
|
||||
Coordinate cord = coordsMap.get(id);
|
||||
|
||||
|
||||
Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
|
||||
Log.d("mapper", "b " + coordsMap.size());
|
||||
if (cord != null) {
|
||||
if (!cord.getLongitude().equals(element.getLongitude())
|
||||
) {
|
||||
Log.d("mapper", " cos sie zienilo ");
|
||||
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.title(cord.getUserId())
|
||||
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
|
||||
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
|
||||
coordsMap.replace(id,element);
|
||||
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
|
||||
Log.d("mapper", "update");
|
||||
Log.d("mapper", " "+cord.getTimeStamp());
|
||||
Log.d("mapper", " "+element.getTimeStamp());
|
||||
coordsMap.replace(id,element);
|
||||
}
|
||||
} else {
|
||||
coordsMap.put(id,element);
|
||||
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("Error",e.toString());
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() { return R.layout.activity_notifications; }
|
||||
|
||||
@Override
|
||||
protected int getNavigationMenuItemId() { return R.id.nav_notif; }
|
||||
}
|
BIN
app/src/main/res/.DS_Store
vendored
Normal file
BIN
app/src/main/res/.DS_Store
vendored
Normal file
Binary file not shown.
@ -21,22 +21,6 @@
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/logoutButton"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/logoutButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginRight="@dimen/fab_margin"
|
||||
android:layout_marginTop="77dp"
|
||||
app:backgroundTint="@android:color/holo_red_dark"
|
||||
app:srcCompat="@android:drawable/ic_lock_power_off" />
|
||||
|
||||
<include
|
||||
android:id="@+id/navigation"
|
||||
layout="@layout/element_bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
|
Loading…
Reference in New Issue
Block a user