Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visited points branch #42

Merged
merged 21 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
30fb605
Merge remote-tracking branch 'origin/MapManager_VM_Intergration_Branc…
JustRostin Dec 16, 2021
a6dd5fb
Merge branch 'development' into MapIntegration
JustRostin Dec 16, 2021
1fa711e
Auto stash before merge of "MapIntegration" and "development"
JustRostin Dec 16, 2021
187e8f1
Merge branch 'development' into MapIntegration
JustRostin Dec 16, 2021
046fa24
Auto stash before merge of "MapIntegration" and "development"
JustRostin Dec 16, 2021
a45b6b3
Created shell for marking route by visited
Jesse592 Dec 16, 2021
19b8bcb
Merge remote-tracking branch 'origin/development' into Visited_points…
Jesse592 Dec 16, 2021
8313634
MapIntegration
JustRostin Dec 16, 2021
e231821
MapIntegration
JustRostin Dec 16, 2021
b64f75b
Started on splitting visited and not visited points
Jesse592 Dec 16, 2021
ef265d1
Merge remote-tracking branch 'origin/MapIntegration' into Visited_poi…
Jesse592 Dec 17, 2021
7c75bc7
Non-visited points are drawn on the map
Jesse592 Dec 17, 2021
4ed913d
Changed zoom a bit
Jesse592 Dec 17, 2021
f72cdc5
Switched lon, lat for waypoints
Jesse592 Dec 17, 2021
2b65b27
Implemented showing walked route
Jesse592 Dec 17, 2021
fe7d89b
empty
Jesse592 Dec 20, 2021
ca8caee
fixed gezeik
Jesse592 Dec 20, 2021
ba13b4c
Added background permissions to the request
Jesse592 Dec 20, 2021
0297b50
Merge branch 'development' into Visited_points_Branch
JustRostin Dec 20, 2021
f11e024
Small changed to the calculation of the route
Jesse592 Dec 20, 2021
a1c75dc
Added internet permissions
Jesse592 Dec 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ dependencies {

//osmdroid
implementation 'org.osmdroid:osmdroid-android:6.1.11'
implementation 'com.github.MKergall:osmbonuspack:6.7.0'
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

<activity
android:name=".UI.MapActivity"
android:exported="true"/>
android:exported="true"
/>

</application>

Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/nl/ags/picum/UI/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_main);
dialogPermission = new PermissionDeniedDialog();
requestPermission(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
} );
requestPermission(new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_BACKGROUND_LOCATION,
Manifest.permission.INTERNET
});

RecyclerView recyclerView = findViewById(R.id.main_routes_recyclerview);
recyclerView.setAdapter(new RouteAdapter(routes, this));
Expand Down
222 changes: 204 additions & 18 deletions app/src/main/java/nl/ags/picum/UI/MapActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package nl.ags.picum.UI;


import android.graphics.Paint;
import android.graphics.drawable.Drawable;

import android.os.Bundle;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
Expand All @@ -9,40 +15,58 @@
import androidx.lifecycle.ViewModelProvider;

import org.osmdroid.api.IMapController;
import org.osmdroid.bonuspack.routing.OSRMRoadManager;
import org.osmdroid.bonuspack.routing.Road;
import org.osmdroid.bonuspack.routing.RoadManager;
import org.osmdroid.bonuspack.routing.RoadNode;
import org.osmdroid.config.Configuration;
import org.osmdroid.library.BuildConfig;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;

import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.Polyline;
import org.osmdroid.views.CustomZoomButtonsController;

import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nl.ags.picum.R;
import nl.ags.picum.UI.fragments.RouteDetailsFragment;
import nl.ags.picum.UI.fragments.SightDetailsPopupFragment;
import nl.ags.picum.UI.fragments.SightsListFragment;
import nl.ags.picum.UI.viewmodels.MapViewModel;
import nl.ags.picum.dataStorage.dataUtil.Point;
import nl.ags.picum.dataStorage.managing.AppDatabaseManager;
import nl.ags.picum.dataStorage.roomData.AppDatabase;
import nl.ags.picum.dataStorage.roomData.Route;
import nl.ags.picum.dataStorage.roomData.Sight;
import nl.ags.picum.mapManagement.MapManager;
import nl.ags.picum.UI.viewmodels.SightViewModel;
import nl.ags.picum.dataStorage.roomData.Waypoint;

public class MapActivity extends AppCompatActivity {

private MapViewModel mapViewModel;
private SightViewModel sightViewModel;


private MapView mMap;
private IMapController mMapController;
private List<Sight> sights;

private MyLocationNewOverlay mLocationOverlay;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);


// this.items = new ArrayList<OverlayItem>();
Configuration.getInstance().setUserAgentValue("AGSPicum/1.0");
this.mapViewModel = new ViewModelProvider(this).get(MapViewModel.class);
this.sightViewModel = new ViewModelProvider(this).get(SightViewModel.class);

Expand All @@ -51,44 +75,186 @@ protected void onCreate(Bundle savedInstanceState) {
this.sightViewModel.getCurrentSight().observe(this, this::onSightChanged);
this.sightViewModel.getSights().observe(this, this::onSightsChanged);

// Observe CalculatedRoute points
this.mapViewModel.getCalculatedRoute().observe(this, (pointsMap) -> {
List<Point> points = pointsMap.get(false);
mMapController.setCenter(convertPointToGeoPoint(points.get(0)));
// TODO: 17-12-2021 setPointsInMap method not called, visited points line are other method
//setPointsInMap(points);
drawRouteList(pointsMap);
});

// observer the raw-route
this.mapViewModel.getOSMRoute().observe(this, (nodes) ->{
setPointsInMap(nodes);
});

this.mMap = findViewById(R.id.MainMap);
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);
mMapController = mMap.getController();
initializeMap();
mMapController.setZoom(20.1);


Route selectedRoute = (Route)getIntent().getSerializableExtra("SelectedRoute");
Route selectedRoute = (Route) getIntent().getSerializableExtra("SelectedRoute");
mapViewModel.setCurrentRoute(selectedRoute);
new Thread(() -> {getSights();}).start();
new Thread(this::getSights).start();


Log.d("pizzaparty", "onCreate: " + mapViewModel.getCurrentRoute());
}

public void getSights(){
private Polyline visitedLine;
private Polyline notVisitedLine;

private void drawRouteList(HashMap<Boolean, List<Point>> pointsMap) {
// Checking if the lists exist
if (pointsMap.get(true) == null || pointsMap.get(false) == null) return;

// Getting the two lists from the map
List<GeoPoint> visitedPoints = convertPointToGeoPoint(pointsMap.get(true));
List<GeoPoint> notVisitedPoints = convertPointToGeoPoint(pointsMap.get(false));

// Checking if the lines have been made
if(visitedLine == null || notVisitedLine == null) {
this.visitedLine = new Polyline();
this.visitedLine.getOutlinePaint().setColor(getColor(R.color.visited_line_color));
this.visitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND);
mMap.getOverlayManager().add(this.visitedLine);

this.notVisitedLine = new Polyline();
this.notVisitedLine.getOutlinePaint().setColor(getColor(R.color.not_visited_line_color));
this.notVisitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND);
mMap.getOverlayManager().add(this.notVisitedLine);
}

//Drawing the two lines
notVisitedLine.setPoints(notVisitedPoints);
visitedLine.setPoints(visitedPoints);

mMap.invalidate();
Log.d("MapActivity", notVisitedPoints.toString());
Log.d("MapActivity", "Points of the route have been drawn");
}

public void getSights() {
AppDatabaseManager dbManager = new AppDatabaseManager(this);
sights = dbManager.getSightsPerRoute(mapViewModel.getCurrentRoute());
}


private void onSightsChanged(List<Sight> sights) {
private void onSightsChanged(Map<Sight, Point> sights) {
setMarkersInMap(sights);
Log.d("TAG", "Sights updated: " + sights.toString());
}

private void onSightChanged(Sight sight) {
Log.d("TAG", "Sight location triggered: " + sight);
}

public void onStartRouteButtonClick(View view){
((Button)view).setVisibility(View.INVISIBLE);
public void onStartRouteButtonClick(View view) {
((Button) view).setVisibility(View.INVISIBLE);
//TODO add function to start route
}

public void initializeMap(){

public void setPointsInMap(List<RoadNode> points) {

Drawable nodeIcon = getDrawable(R.drawable.osm_ic_follow_me);
// nodeIcon.setHotspot(0.5f, 0.5f);spo
int actualSteps = 1;
String lastInstruction = "";
for (int i = 0; i < points.size(); i++) {
RoadNode node = points.get(i);
Log.d("MarkerNodes", "NODE: " + node.mInstructions);
//
if (node.mManeuverType != 24 && node.mInstructions != null) {
if (node.mInstructions.equals(lastInstruction) && node.mLength < 0.01) {

} else {

Marker nodeMarker = new Marker(mMap);
nodeMarker.setPosition(node.mLocation);
nodeMarker.setIcon(nodeIcon);
nodeMarker.setSnippet(node.mInstructions);
nodeMarker.setSubDescription(Road.getLengthDurationText(this, node.mLength, node.mDuration));
nodeMarker.setTitle("Step " + actualSteps);
Drawable icon = getDrawable(getDirectionIcon(node.mManeuverType));
nodeMarker.setImage(icon);
actualSteps++;
lastInstruction = node.mInstructions;
mMap.getOverlays().add(nodeMarker);
}
}

}
mMap.invalidate();

}


public int getDirectionIcon(int instruction) {
switch (instruction) {
case 1:
case 11:
return R.drawable.ic_continue;
case 0:
case 2:
default:
return R.drawable.ic_empty;
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 33:
case 34:
return R.drawable.ic_roundabout;
case 5:
return R.drawable.ic_sharp_left;
case 8:
return R.drawable.ic_sharp_right;
case 3:
case 9:
case 17:
case 20:
return R.drawable.ic_slight_left;
case 6:
case 10:
case 18:
case 21:
return R.drawable.ic_slight_right;
case 4:
return R.drawable.ic_turn_left;
case 7:
return R.drawable.ic_turn_right;
case 12:
case 13:
case 14:
return R.drawable.ic_u_turn;
}
}

public void setMarkersInMap(Map<Sight, Point> sights) {
sights.forEach((k, v) -> {
Marker m = new Marker(mMap);
m.setPosition(convertPointToGeoPoint(v));
m.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
m.setIcon(getResources().getDrawable(R.drawable.marker_default));
m.setTitle(k.getSightName());
m.setSnippet(k.getSightDescription());
mMap.getOverlays().add(m);
mMap.invalidate();

});
}

public void initializeMap() {
mMap.setTileSource(TileSourceFactory.MAPNIK);
mMapController.setZoom(20.1);
//TODO Get Location
GeoPoint startPoint = new GeoPoint(51.585474, 4.792315);
//TODO
mMapController.setCenter(startPoint); //(Middelpunt route?)
mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(getApplicationContext()), mMap);
mLocationOverlay.enableMyLocation();
RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mMap);
mRotationGestureOverlay.setEnabled(true);
mMap.setMultiTouchControls(true);
Expand Down Expand Up @@ -121,8 +287,28 @@ public void onPause() {
}



public void onFABClicked (View view){

new SightsListFragment(sights, this).show(getSupportFragmentManager(), "list");
}


public GeoPoint convertPointToGeoPoint(Point point) {
return new GeoPoint(point.getLatitude(), point.getLongitude());
}

public List<GeoPoint> convertPointToGeoPoint(List<Point> points) {
List<GeoPoint> geoPoints = new ArrayList<>();
for (Point point : points)
geoPoints.add(new GeoPoint(point.getLatitude(), point.getLongitude()));
return geoPoints;
}

public List<GeoPoint> convertWayPointToGeoPoint(List<Waypoint> points) {
List<GeoPoint> geoPoints = new ArrayList<>();
for (Waypoint point : points)
geoPoints.add(new GeoPoint(point.getLatitude(), point.getLongitude()));
return geoPoints;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -17,14 +18,13 @@
import java.util.Locale;

import nl.ags.picum.R;
import nl.ags.picum.UI.viewmodels.MapViewModel;

public class SettingsFragment extends DialogFragment {


@Override
public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
}

Expand Down
Loading