Skip to content
Snippets Groups Projects
Commit 8987339a authored by FurWaz's avatar FurWaz
Browse files

Added route finding + minor improvements

parent ac3f1185
No related branches found
No related tags found
No related merge requests found
Showing
with 581 additions and 40 deletions
......@@ -22,6 +22,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.RoomView"
tools:targetApi="31">
<activity
android:name=".DirectionsActivity"
android:exported="false" />
<activity
android:name=".ZoneView"
android:exported="false" />
......
......
package Common;
import android.content.Context;
import com.furwaz.roomview.R;
import Structures.PathInfo;
public class DirectionStep {
Context context;
PathInfo path;
String title = "";
String description = "";
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)
.replace("{{value1}}", path.getDestination().getName())
.replace("{{value2}}", path.getName());
}
public DirectionStep(PathInfo path) {
this.context = BuildingManager.getContext();
this.path = path;
this.generateStrings();
}
public void setPath(PathInfo path) {
this.path = path;
this.generateStrings();
}
public PathInfo getPath() {
return path;
}
public String getTitle() {
if (this.title.equals("")) this.generateStrings();
return title;
}
public String getDescription() {
if (this.description.equals("")) this.generateStrings();
return description;
}
}
package Common;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import Structures.PathInfo;
import Structures.PathStairs;
import Structures.PathType;
import Structures.RoomInfo;
import Structures.StairsDirection;
public class Directions {
private static List<DirectionStep> testRoute(List<RoomInfo> blacklist, PathInfo path, RoomInfo pdest, RoomInfo dest) {
if (pdest == null || dest == null || path == null) return new ArrayList<>();
for (int i = 0; i < blacklist.size(); i++) {
if (blacklist.get(i) == pdest)
return new ArrayList<>();
}
List<DirectionStep> res = new ArrayList<>();
if (pdest == dest) {
res.add(new DirectionStep(path));
} else {
List<DirectionStep> route = findRoute(blacklist, pdest, dest);
if (route.size() > 0) {
res.add(new DirectionStep(path));
res.addAll(route);
}
}
return res;
}
private static void tryToAdd(List<DirectionStep> steps, List<List<DirectionStep>> paths) {
if (steps.size() > 0) paths.add(steps);
}
public static List<DirectionStep> findRoute(RoomInfo from, RoomInfo to) {
return findRoute(new ArrayList<>(), from, to);
}
public static List<DirectionStep> findRoute(List<RoomInfo> blacklist, RoomInfo from, RoomInfo to) {
if (from == null || to == null) return new ArrayList<>();
blacklist.add(from);
List<List<DirectionStep>> paths = new ArrayList<>();
for (PathInfo path: from.getPaths()) {
List<RoomInfo> blacklist_copy = new ArrayList<>(blacklist);
if (path.getType() == PathType.STAIRS) {
PathStairs stairs = (PathStairs) path;
switch (stairs.getDirection()) {
case UP: {
List<DirectionStep> up = testRoute(blacklist_copy, path, stairs.getDestination(StairsDirection.UP), to);
tryToAdd(up, paths);
break;
}
case DOWN: {
List<DirectionStep> down = testRoute(blacklist_copy, path, stairs.getDestination(StairsDirection.DOWN), to);
tryToAdd(down, paths);
break;
}
default: {
List<DirectionStep> up = testRoute(blacklist_copy, path, stairs.getDestination(StairsDirection.UP), to);
tryToAdd(up, paths);
List<DirectionStep> down = testRoute(blacklist_copy, path, stairs.getDestination(StairsDirection.DOWN), to);
tryToAdd(down, paths);
break;
}
}
} else {
List<DirectionStep> route = testRoute(blacklist_copy, path, path.getDestination(), to);
if (route.size() > 0) paths.add(route);
}
}
List<DirectionStep> res = new ArrayList<>();
if (paths.size() == 0) return res;
int length = paths.get(0).size() + 1;
for (List<DirectionStep> path: paths) {
int size = path.size();
if (size < length) {
length = size;
res = path;
}
}
return res;
}
}
......@@ -5,6 +5,7 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
......@@ -49,6 +50,17 @@ public class BuildingPopup {
validate_btn.setText(btn_text);
validate_btn.setEnabled(false);
b_err.setText("");
// display the keyboard
b_name.setOnFocusChangeListener(((view, hasFocus) -> {
if (hasFocus) {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
inputMgr.showSoftInput(b_name, InputMethodManager.SHOW_IMPLICIT);
}
}));
b_name.requestFocus();
b_name.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
......@@ -77,6 +89,11 @@ public class BuildingPopup {
validate_btn.setOnClickListener(view -> onValidate.call(this));
});
dialog.setOnDismissListener(dialogInterface -> {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
});
}
public void show() {
......
......
package Popups;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import com.furwaz.roomview.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.Function;
import Common.Callback;
import Structures.BuildingInfo;
import Structures.Orientation;
import Structures.RoomInfo;
public class DirectionsPopup {
final int ZONE_FROM = 0;
final int ZONE_TO = 1;
AlertDialog dialog;
Context context;
RoomInfo fromRoom;
RoomInfo toRoom;
BuildingInfo building;
List<RoomInfo> matching_rooms = new ArrayList<>();
private String[] getMatchingRooms(String query) {
matching_rooms.clear();
for (RoomInfo room: building.getRooms()) {
String formattedName = room.getName().toLowerCase(Locale.ROOT).replaceAll(" ", "");
String formattedQuery = query.toLowerCase(Locale.ROOT).replaceAll(" ", "");
if (formattedName.contains(formattedQuery))
matching_rooms.add(room);
}
String[] res = new String[matching_rooms.size()];
for (int i = 0; i < res.length; i++) res[i] = matching_rooms.get(i).getName();
return res;
}
private void setupSelectionZone(int ZONE_ID) {
LinearLayout select_zone = dialog.findViewById(ZONE_ID==ZONE_FROM? R.id.select_from_room : R.id.select_to_room);
LinearLayout show_zone = dialog.findViewById(ZONE_ID==ZONE_FROM? R.id.show_from_room : R.id.show_to_room);
View edit_btn = dialog.findViewById(ZONE_ID==ZONE_FROM? R.id.edit_from_room : R.id.edit_to_room);
TextView room_name = dialog.findViewById(ZONE_ID==ZONE_FROM? R.id.name_from_room : R.id.name_to_room);
ListView room_list = dialog.findViewById(ZONE_ID==ZONE_FROM? R.id.room_list_from : R.id.room_list_to);
SearchView search = dialog.findViewById(ZONE_ID==ZONE_FROM? R.id.room_search_from : R.id.room_search_to);
show_zone.setOnClickListener(view -> {
show_zone.setVisibility(View.GONE);
select_zone.setVisibility(View.VISIBLE);
});
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
public boolean onQueryTextSubmit(String s) { return true; }
public boolean onQueryTextChange(String s) {
room_list.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, getMatchingRooms(s)));
return true;
}
});
room_list.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, getMatchingRooms("")));
room_list.setOnItemClickListener((adapterView, view, i, l) -> {
show_zone.setVisibility(View.VISIBLE);
select_zone.setVisibility(View.GONE);
RoomInfo selected = matching_rooms.get(i);
room_name.setText(selected.getName());
if (ZONE_ID == ZONE_FROM) fromRoom = selected;
else toRoom = selected;
});
}
public DirectionsPopup(Context context, BuildingInfo building, Callback onSearch) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
dialog = builder.create();
LayoutInflater factory = LayoutInflater.from(context);
View popup = factory.inflate(R.layout.directions_popup, null);
dialog.setView(popup);
this.context = context;
this.building = building;
dialog.setOnShowListener(dialogInterface -> {
setupSelectionZone(ZONE_FROM);
setupSelectionZone(ZONE_TO);
Button cancel_btn = dialog.findViewById(R.id.btn_cancel);
cancel_btn.setOnClickListener(view -> this.dismiss());
Button search_btn = dialog.findViewById(R.id.btn_search);
search_btn.setOnClickListener(view -> onSearch.call(this));
});
dialog.show();
}
public void dismiss() {
dialog.dismiss();
}
public RoomInfo getFromRoom() {
return this.fromRoom;
}
public RoomInfo getToRoom() {
return this.toRoom;
}
public void show() {
dialog.show();
}
}
......@@ -5,6 +5,7 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
......@@ -64,6 +65,17 @@ public class PathwayPopup {
validate_btn.setEnabled(false);
p_err.setText("");
// display the keyboard
p_name.setOnFocusChangeListener(((view, hasFocus) -> {
if (hasFocus) {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
inputMgr.showSoftInput(p_name, InputMethodManager.SHOW_IMPLICIT);
}
}));
p_name.requestFocus();
p_name.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
......@@ -117,7 +129,11 @@ public class PathwayPopup {
cancel_btn.setOnClickListener(view -> onCancel.call(this));
validate_btn.setOnClickListener(view -> onValidate.call(this));
});
dialog.show();
dialog.setOnDismissListener(dialogInterface -> {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
});
}
public void dismiss() {
......
......
package Popups;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import com.furwaz.roomview.R;
import java.text.SimpleDateFormat;
import java.util.Date;
import Common.Callback;
import Structures.PhotoInfo;
public class PhotoInfoPopup {
public static final int MODE_NEW = 1;
public static final int MODE_EDIT = 2;
AlertDialog dialog = null;
Button validate_btn = null;
public PhotoInfoPopup(Context context, PhotoInfo photo) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
dialog = builder.create();
LayoutInflater factory = LayoutInflater.from(context);
View popup = factory.inflate(R.layout.photo_info_popup, null);
dialog.setView(popup);
dialog.setOnShowListener(dialogInterface -> {
TextView tv_hour = popup.findViewById(R.id.photo_hour);
TextView tv_date = popup.findViewById(R.id.photo_date);
Date d = photo.getDate();
tv_hour.setText(new SimpleDateFormat("HH:mm").format(d));
tv_date.setText(new SimpleDateFormat("yyyy / MM / dd").format(d));
validate_btn = popup.findViewById(R.id.btn_validate_room);
validate_btn.setOnClickListener(view -> this.dismiss());
});
dialog.show();
}
public void dismiss() {
dialog.dismiss();
}
public void show() {
dialog.show();
}
}
......@@ -5,6 +5,7 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
......@@ -51,6 +52,17 @@ public class RoomPopup {
validate_btn.setText(btn_text);
validate_btn.setEnabled(false);
r_err.setText("");
// display the keyboard
r_name.setOnFocusChangeListener(((view, hasFocus) -> {
if (hasFocus) {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
inputMgr.showSoftInput(r_name, InputMethodManager.SHOW_IMPLICIT);
}
}));
r_name.requestFocus();
r_name.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
......@@ -75,7 +87,11 @@ public class RoomPopup {
validate_btn.setOnClickListener(view -> onValidate.call(this));
});
dialog.show();
dialog.setOnDismissListener(dialogInterface -> {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
});
}
public void dismiss() {
......
......
package Popups;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import com.furwaz.roomview.R;
import java.text.SimpleDateFormat;
import java.util.Date;
import Common.Callback;
import Structures.PhotoInfo;
public class StairsDestPopup {
public static final int MODE_NEW = 1;
public static final int MODE_EDIT = 2;
AlertDialog dialog = null;
public StairsDestPopup(Context context, Callback onUpSelected, Callback onDownSelected) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
dialog = builder.create();
LayoutInflater factory = LayoutInflater.from(context);
View popup = factory.inflate(R.layout.stairs_dest_popup, null);
dialog.setView(popup);
dialog.setOnShowListener(dialogInterface -> {
Button btn_up = popup.findViewById(R.id.btn_dir_up);
Button btn_down = popup.findViewById(R.id.btn_dir_down);
btn_up.setOnClickListener(view -> {
onUpSelected.call(this);
this.dismiss();
});
btn_down.setOnClickListener(view -> {
onDownSelected.call(this);
this.dismiss();
});
});
dialog.show();
}
public void dismiss() {
dialog.dismiss();
}
public void show() {
dialog.show();
}
}
......@@ -5,6 +5,7 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
......@@ -43,6 +44,17 @@ public class ZonePopup {
validate_btn.setEnabled(false);
z_err.setText("");
// display the keyboard
z_name.setOnFocusChangeListener(((view, hasFocus) -> {
if (hasFocus) {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
inputMgr.showSoftInput(z_name, InputMethodManager.SHOW_IMPLICIT);
}
}));
z_name.requestFocus();
z_name.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
......@@ -73,7 +85,11 @@ public class ZonePopup {
validate_btn.setText(context.getResources().getString(R.string.edit));
}
});
dialog.show();
dialog.setOnDismissListener(dialogInterface -> {
InputMethodManager inputMgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
});
}
public void dismiss() {
......
......
......@@ -19,7 +19,7 @@ public class BuildingInfo implements Serializable {
}
public BuildingInfo(String name, Date date) {
this.name = name;
this.name = name.trim();
this.date = date;
}
......
......
......@@ -3,6 +3,11 @@ package Structures;
import java.io.Serializable;
public class MeteoInfo implements Serializable {
public static MeteoInfo GetCurrentMeteo() {
// TODO
return null;
}
float temperature = 0f;
float humidity = 0f;
float pressure = 1000f;
......
......
......@@ -16,7 +16,7 @@ public class PathInfo implements Serializable {
}
public PathInfo(String name, RoomInfo destination) {
this.name = name;
this.name = name.trim();
this.destination = destination;
this.askForSave();
}
......
......
......@@ -26,6 +26,9 @@ public class PathStairs extends PathInfo implements Serializable {
}
else if (dir == StairsDirection.UP) this.destination = dest;
else this.roomDown = dest;
this.direction = (destination == null)? StairsDirection.DOWN:
( (roomDown == null)? StairsDirection.UP : StairsDirection.BOTH );
this.askForSave();
}
......
......
......@@ -6,12 +6,15 @@ import android.graphics.Matrix;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class PhotoInfo implements Serializable {
Orientation orientation = Orientation.NORTH;
byte[] image = null;
ZoneInfo zone = null;
MeteoInfo meteo = null;
Date date = null;
List<PathView> pathViews = new ArrayList<>();
transient Bitmap bitmap = null;
......@@ -22,6 +25,12 @@ public class PhotoInfo implements Serializable {
this.bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), mat, true);
}
protected void setPicture(byte[] im) {
this.image = im;
this.date = new Date();
this.meteo = MeteoInfo.GetCurrentMeteo();
}
public PhotoInfo() {
}
......@@ -31,13 +40,13 @@ public class PhotoInfo implements Serializable {
}
public PhotoInfo(byte[] im) {
this.image = im;
setPicture(im);
createBitmap();
this.askForSave();
}
public PhotoInfo(byte[] im, Orientation orientation) {
this.image = im;
setPicture(im);
this.orientation = orientation;
createBitmap();
this.askForSave();
......@@ -66,7 +75,7 @@ public class PhotoInfo implements Serializable {
}
public void setImage(byte[] data) {
this.image = data;
setPicture(data);
createBitmap();
this.askForSave();
}
......@@ -98,6 +107,24 @@ public class PhotoInfo implements Serializable {
return zone;
}
public MeteoInfo getMeteo() {
return this.meteo;
}
public void setMeteo(MeteoInfo meteo) {
this.meteo = meteo;
this.askForSave();
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
this.askForSave();
}
public void askForSave() {
if (this.zone != null) this.zone.askForSave();
}
......
......
......@@ -16,7 +16,7 @@ enum RoomType {
}
public class RoomInfo implements Serializable {
String name = "X";
String name = "";
RoomType type = RoomType.ROOM;
List<ZoneInfo> zones = new ArrayList<>();
List<PathInfo> paths = new ArrayList<>();
......@@ -27,7 +27,7 @@ public class RoomInfo implements Serializable {
}
public RoomInfo(String name) {
this.name = name;
this.name = name.trim();
this.addZone(new ZoneInfo(BuildingManager.getContext().getResources().getString(com.furwaz.roomview.R.string.center)));
this.askForSave();
}
......
......
......@@ -6,9 +6,8 @@ import java.util.Date;
import java.util.List;
public class ZoneInfo implements Serializable {
String name = "X";
String name = "";
Date date;
MeteoInfo meteo;
RoomInfo room = null;
List<PhotoInfo> photos = new ArrayList<>();
List<WalkInfo> walks = new ArrayList<>();
......@@ -18,14 +17,13 @@ public class ZoneInfo implements Serializable {
}
public ZoneInfo(String name) {
this.name = name;
this.name = name.trim();
this.askForSave();
}
public ZoneInfo(String name, Date date, MeteoInfo meteo) {
public ZoneInfo(String name, Date date) {
this.name = name;
this.date = date;
this.meteo = meteo;
this.askForSave();
}
......@@ -78,15 +76,6 @@ public class ZoneInfo implements Serializable {
this.askForSave();
}
public MeteoInfo getMeteo() {
return meteo;
}
public void setMeteo(MeteoInfo meteo) {
this.meteo = meteo;
this.askForSave();
}
public List<WalkInfo> getWalks() {
return walks;
}
......
......
......@@ -104,23 +104,35 @@ public class InfoAdapter<A> extends BaseAdapter {
LinearLayout ll = view.findViewById(R.id.tile_box);
Button b1 = view.findViewById(R.id.tile_remove);
Button b2 = view.findViewById(R.id.tile_edit);
if (b2 == null) {
ll.setOnClickListener(view1 -> {
if (this.viewCallback != null)
this.viewCallback.call(this.queryList.get(i));
if (this.editCallback != null)
this.editCallback.call(this.queryList.get(i));
this.updateQueryList();
});
b1.setOnClickListener(view12 -> {
if (this.removeCallback != null)
this.removeCallback.call(this.queryList.get(i));
} else {
ll.setOnClickListener(view1 -> {
if (this.viewCallback != null)
this.viewCallback.call(this.queryList.get(i));
this.updateQueryList();
});
b2.setOnClickListener(view13 -> {
b2.setOnClickListener(view2 -> {
if (this.editCallback != null)
this.editCallback.call(this.queryList.get(i));
this.updateQueryList();
});
}
if (b1 != null)
b1.setOnClickListener(view1 -> {
if (this.removeCallback != null)
this.removeCallback.call(this.queryList.get(i));
this.updateQueryList();
});
}
public void setBindings(InfoBinding[] objs) {
this.objs = objs;
}
......
......
......@@ -2,11 +2,13 @@ package com.furwaz.roomview;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import Common.BuildingManager;
import Popups.DirectionsPopup;
import Popups.GotoPopup;
import Structures.BuildingInfo;
......@@ -42,6 +44,18 @@ public class BuildingView extends AppCompatActivity {
}
protected void showDirectionsPopup() {
new DirectionsPopup(
this,
building,
param -> {
DirectionsPopup popup = (DirectionsPopup) param;
Intent intent = new Intent(this, DirectionsActivity.class);
intent.putExtra("building", BuildingManager.getBuildings().indexOf(building));
intent.putExtra("from_room", building.getRooms().indexOf(popup.getFromRoom()));
intent.putExtra("to_room", building.getRooms().indexOf(popup.getToRoom()));
this.startActivity(intent);
return null;
}
).show();
}
}
\ No newline at end of file
package com.furwaz.roomview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
import Common.BuildingManager;
import Common.DirectionStep;
import Common.Directions;
import Common.InfoBinding;
import Structures.BuildingInfo;
import Structures.RoomInfo;
import Views.InfoAdapter;
public class DirectionsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_directions);
Bundle extras = getIntent().getExtras();
int buildingIndex = extras.getInt("building");
int fromIndex = extras.getInt("from_room");
int toIndex = extras.getInt("to_room");
BuildingInfo building = BuildingManager.getBuilding(buildingIndex);
RoomInfo fromRoom = building.getRoom(fromIndex);
RoomInfo toRoom = building.getRoom(toIndex);
LinearLayout noDataLayout = findViewById(R.id.no_directions_layout);
ListView dirs_lv = findViewById(R.id.directions_list);
TextView from_label = findViewById(R.id.from_room_name);
TextView to_label = findViewById(R.id.to_room_name);
from_label.setText(fromRoom.getName());
to_label.setText(toRoom.getName());
List<DirectionStep> res = Directions.findRoute(fromRoom, toRoom);
InfoAdapter<DirectionStep> adapter = new InfoAdapter<>(this, res, noDataLayout, R.layout.direction_tile);
dirs_lv.setAdapter(adapter);
adapter.setBindings(new InfoBinding[]{
new InfoBinding(param -> ((DirectionStep) param).getTitle(), R.id.direction_title),
new InfoBinding(param -> ((DirectionStep) param).getDescription(), R.id.direction_description)
});
adapter.setSearchQuery("");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment