Merge branch 'mapManualLocation' into tmp20nov
This commit is contained in:
commit
86cafe1d5a
@ -75,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<>();
|
||||
@ -86,6 +91,7 @@ public class MapActivity extends BaseActivity
|
||||
private int zoomParam = 17;
|
||||
private int bearingParam = 180;
|
||||
private int tiltParam = 30;
|
||||
private String myID;
|
||||
|
||||
|
||||
@Override
|
||||
@ -93,7 +99,7 @@ public class MapActivity extends BaseActivity
|
||||
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);
|
||||
@ -109,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);
|
||||
@ -126,8 +134,25 @@ public class MapActivity extends BaseActivity
|
||||
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);
|
||||
|
||||
});
|
||||
} else {
|
||||
createMarkerModal(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -207,38 +232,31 @@ public class MapActivity extends BaseActivity
|
||||
|
||||
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 (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(),
|
||||
@ -248,64 +266,57 @@ public class MapActivity extends BaseActivity
|
||||
PrefUtils.getLocationLevel(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));
|
||||
}
|
||||
// TODO remove after BG sending
|
||||
manualLocStatusChecker = () -> {
|
||||
try {
|
||||
Log.e(tag+"Manual", "sending manual coords");
|
||||
// TODO ^^^ wrapper to removve
|
||||
disposable.add(
|
||||
coordinateService
|
||||
.postCoordinate(droppedMarkercoordinate)
|
||||
.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) {
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
Log.e(tag + "onError", e.getMessage());
|
||||
Log.e(tag + "onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
Log.e(tag + "onError", RestApiHelper.getErrorMessage(responseBody));
|
||||
|
||||
}
|
||||
}
|
||||
}));
|
||||
// TODO \/\/\/\/\/ wrapper to removve
|
||||
} finally {
|
||||
manualLocHandler.postDelayed(manualLocStatusChecker, mInterval);
|
||||
}
|
||||
};
|
||||
manualLocStatusChecker.run();
|
||||
|
||||
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));
|
||||
mapboxMap.removeMarker(tmpLocalMarker);
|
||||
tmpLocalMarker = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -330,13 +341,11 @@ public class MapActivity extends BaseActivity
|
||||
}
|
||||
|
||||
if (coordsList.isEmpty()) {
|
||||
Log.e(tag, "200 empty []");
|
||||
//mapboxMap.clear();
|
||||
|
||||
Timber.e("200 empty []");
|
||||
mapboxMap.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ArrayList<String> tmp = new ArrayList<>();
|
||||
for (Coordinate coordinate : coordsList) {
|
||||
tmp.add(coordinate.getUserId());
|
||||
@ -371,9 +380,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);
|
||||
@ -406,7 +412,11 @@ public class MapActivity extends BaseActivity
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.title(id)
|
||||
.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);
|
||||
@ -534,6 +544,8 @@ public class MapActivity extends BaseActivity
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
// TODO remove after BG sending
|
||||
manualLocHandler.removeCallbacks(manualLocStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,11 @@ package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Polygon;
|
||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
|
@ -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>
|
@ -206,5 +206,6 @@
|
||||
<string name="launch_activity" />
|
||||
<string name="remove_location_updates" />
|
||||
<string name="map_activity_label">MapActivity</string>
|
||||
<string name="remove_manual_location">Remove Manual location</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user