Skip to content
Snippets Groups Projects
Commit 5ded7768 authored by FurWaz's avatar FurWaz
Browse files

Added lots of comments again

parent eecf5e6c
No related branches found
No related tags found
No related merge requests found
......@@ -28,10 +28,12 @@ public class BuildingManager {
save_dir = context.getFilesDir();
}
// set the context of the building manager
public static Context getContext() {
return context;
}
// remove a building from the list (+ saves the list)
public static void removeBuilding(BuildingInfo b) {
if (BuildingManager.buildings == null)
loadBuildings();
......@@ -39,6 +41,7 @@ public class BuildingManager {
new File(save_dir, b.getName()).delete();
}
// adds a building from the list (+ saves the list)
public static void addBuilding(BuildingInfo b) {
if (BuildingManager.buildings == null)
loadBuildings();
......@@ -46,18 +49,21 @@ public class BuildingManager {
BuildingManager.saveBuilding(b);
}
// returns the list of buildings (loads it if not loaded)
public static List<BuildingInfo> getBuildings() {
if (BuildingManager.buildings == null)
loadBuildings();
return BuildingManager.buildings;
}
// returns the building at the given index (loads the list if not loaded)
public static BuildingInfo getBuilding(int index) {
if (BuildingManager.buildings == null)
loadBuildings();
return BuildingManager.buildings.get(index);
}
// returns the building with the given name (loads the list if not loaded)
public static BuildingInfo getBuilding(String name) {
if (BuildingManager.buildings == null)
loadBuildings();
......@@ -67,6 +73,7 @@ public class BuildingManager {
return null;
}
// saves the given building to the file system
public static void saveBuilding(BuildingInfo building) {
new File(save_dir, building.getName()).delete();
......@@ -87,11 +94,13 @@ public class BuildingManager {
BuildingManager.buildings.add(building);
}
// saves all the buildings to the file system
public static void saveBuildings() {
for(BuildingInfo building: BuildingManager.buildings)
saveBuilding(building);
}
// loads all the buildings from the file system
public static void loadBuildings() {
BuildingManager.buildings = new ArrayList<>();
if (save_dir == null) return;
......
package Common;
public interface Callback {
// callback function
public Object call(Object param);
}
......@@ -4,15 +4,24 @@ import android.view.View;
public class Coord {
private float x, y;
// constructor
public Coord() { }
// constructor with x and y coords
public Coord(float x, float y) { this.x = x; this.y = y; }
public float getY() { return y; }
// returns the x coord
public float getX() { return x; }
// returns the y coord
public float getY() { return y; }
// returns the distance between this coord and the given coord
public float distance(Coord c) {
return (float) Math.sqrt( Math.pow(c.getX() - this.getX(), 2) + Math.pow(c.getY() - this.getY(), 2) );
}
// returns the relative coordinates (in percent) of this coord (relative to the given view)
public Coord getRelativeCoord(View v) {
float width = v.getWidth();
float height = v.getHeight();
......@@ -22,6 +31,7 @@ public class Coord {
);
}
// returns the absolute coordinates (in px) of this coord (relative to the given view)
public Coord getAbsoluteCoord(View v) {
float width = v.getWidth();
float height = v.getHeight();
......
......@@ -12,6 +12,7 @@ public class DirectionStep {
String title = "";
String description = "";
// generates the direction's title and description for user display
private void generateStrings() {
this.title = context.getString(R.string.go_to_value).replace("{{value}}", path.getDestination().getName());
this.description = context.getString(R.string.go_to_value_desc)
......@@ -19,26 +20,31 @@ public class DirectionStep {
.replace("{{value2}}", path.getName());
}
// Constructor
public DirectionStep(PathInfo path) {
this.context = BuildingManager.getContext();
this.path = path;
this.generateStrings();
}
// Set the path of the direction
public void setPath(PathInfo path) {
this.path = path;
this.generateStrings();
}
// Get the path of the direction
public PathInfo getPath() {
return path;
}
// Get the title of the direction
public String getTitle() {
if (this.title.equals("")) this.generateStrings();
return title;
}
// Get the description of the direction
public String getDescription() {
if (this.description.equals("")) this.generateStrings();
return description;
......
......@@ -12,6 +12,7 @@ import Structures.RoomInfo;
import Structures.StairsDirection;
public class Directions {
// Returns a list of directions to follow to the destination if found (list of size 0 if no path found)
private static List<DirectionStep> testRoute(List<RoomInfo> blacklist, PathInfo path, RoomInfo pdest, RoomInfo dest) {
if (pdest == null || dest == null || path == null) return new ArrayList<>();
......@@ -33,19 +34,23 @@ public class Directions {
return res;
}
// adds the list of steps to the list of paths if it is not empty
private static void tryToAdd(List<DirectionStep> steps, List<List<DirectionStep>> paths) {
if (steps.size() > 0) paths.add(steps);
}
// Returns the list of directions to go from the given room to the given destination (list of size 0 if no path found)
public static List<DirectionStep> findRoute(RoomInfo from, RoomInfo to) {
return findRoute(new ArrayList<>(), from, to);
}
// Returns the list of directions to go from the given room to the given destination, with blacklisted rooms if already used for path (list of size 0 if no path found)
public static List<DirectionStep> findRoute(List<RoomInfo> blacklist, RoomInfo from, RoomInfo to) {
if (from == null || to == null) return new ArrayList<>();
blacklist.add(from);
blacklist.add(from); // add the current room to the blacklist
List<List<DirectionStep>> paths = new ArrayList<>();
// for each path of the current room, try to find (recursively) a path to the destination
for (PathInfo path: from.getPaths()) {
List<RoomInfo> blacklist_copy = new ArrayList<>(blacklist);
if (path.getType() == PathType.STAIRS) {
......@@ -78,6 +83,7 @@ public class Directions {
List<DirectionStep> res = new ArrayList<>();
if (paths.size() == 0) return res;
// find the shortest path
int length = paths.get(0).size() + 1;
for (List<DirectionStep> path: paths) {
int size = path.size();
......@@ -86,6 +92,8 @@ public class Directions {
res = path;
}
}
// return the shortest path
return res;
}
}
......
......@@ -18,6 +18,7 @@ import Structures.RoomInfo;
import Structures.ZoneInfo;
public class ImageManager {
// Retreived the bitmap from the given url (executes onResolve with the bitmap on success, onReject with the error message on failure)
public static void bitmapFromURL(Callback onResolve, Callback onReject, String url) {
ExecutorService service = Executors.newSingleThreadExecutor();
service.execute(() -> {
......
package Common;
public class InfoBinding {
// callback function to execute to get the data
private Callback callback;
// if of the element to bind the data to
private int element;
// constructor
public InfoBinding(Callback cb, int el) {
this.element = el;
this.callback = cb;
}
// returns the callback function
public Callback getCallback() {
return callback;
}
// returns the id of the element to bind the data to
public int getElement() {
return element;
}
......
......@@ -8,25 +8,30 @@ public class Position implements Serializable {
public double latitude;
public double longitude;
// constructor with latitude and longitude
public Position(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
// constructor with a location object
public Position(Location location) {
this.latitude = location.getLatitude();
this.longitude = location.getLongitude();
}
// constructor with no parameters
public Position() {
this.latitude = 0;
this.longitude = 0;
}
// returns latitude
public double getLatitude() {
return latitude;
}
// returns longitude
public double getLongitude() {
return longitude;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment