diff --git a/Sources/app/src/main/java/com/furwaz/roomview/BuildingActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/BuildingActivity.java index b352572727684237f6794cfbac7906ef0761b4af..f127ea9eab21a03e91d17d5f2892a9b86b893c0b 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/BuildingActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/BuildingActivity.java @@ -40,6 +40,7 @@ public class BuildingActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_building); + // retreive the building from the intent int buildingIndex = getIntent().getExtras().getInt("building"); building = BuildingManager.getBuilding(buildingIndex); if (building == null) { @@ -47,12 +48,15 @@ public class BuildingActivity extends AppCompatActivity { return; } + // retreive the UI elements ListView room_lv = findViewById(R.id.room_list); LinearLayout noDataLayout = findViewById(R.id.no_room_layout); + // create the adapter (list of rooms) room_adapter = new InfoAdapter<RoomInfo>(this, building.getRooms(), noDataLayout, R.layout.room_tile); room_lv.setAdapter(room_adapter); + // remove button click room_adapter.setOnRemoveListener(param -> { new RemovePopup( this, @@ -77,6 +81,7 @@ public class BuildingActivity extends AppCompatActivity { return null; }); + // edit button click room_adapter.setOnEditListener(param -> { Intent intent = new Intent(BuildingActivity.this, RoomActivity.class); intent.putExtra("building", BuildingManager.getBuildings().indexOf(building)); @@ -85,15 +90,16 @@ public class BuildingActivity extends AppCompatActivity { return null; }); - room_adapter.setOnViewListener(param -> { - return null; - }); + // view button click (not used here) + room_adapter.setOnViewListener(param -> null); + // set the bindings (how and where to display the data) room_adapter.setBindings(new InfoBinding[]{ new InfoBinding(param -> ((RoomInfo) param).getName(), R.id.room_name), new InfoBinding(param -> ((RoomInfo) param).getNbZones(), R.id.room_zones) }); + // setup the search bar SearchView building_sv = findViewById(R.id.room_search); building_sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean onQueryTextSubmit(String s) { @@ -107,12 +113,15 @@ public class BuildingActivity extends AppCompatActivity { } }); + // setup the add button ImageButton add_btn = findViewById(R.id.add_room_btn); add_btn.setOnClickListener(this::showAddRoomPopup); + // setup the edit button ImageButton edit_btn = findViewById(R.id.edit_building_name); edit_btn.setOnClickListener(view -> showEditPopup()); + // setup the building name textview TextView building_tv_name = findViewById(R.id.building_name); building_tv_name.setText(building.getName()); } @@ -120,10 +129,12 @@ public class BuildingActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); + // refresh the list of rooms room_adapter.setData(building.getRooms()); } protected void showEditPopup() { + // create a popup to edit the building name new BuildingPopup( BuildingActivity.this, param -> { @@ -146,6 +157,7 @@ public class BuildingActivity extends AppCompatActivity { } protected void showAddRoomPopup(View v) { + // create a popup to add a new room new RoomPopup( BuildingActivity.this, building, diff --git a/Sources/app/src/main/java/com/furwaz/roomview/BuildingView.java b/Sources/app/src/main/java/com/furwaz/roomview/BuildingView.java index 32e9ac57f95905f22c16c234754d1fc50d030841..63da2cb9e1df25664d1e707948eda2426b4da472 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/BuildingView.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/BuildingView.java @@ -20,30 +20,36 @@ public class BuildingView extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_building_view); + // retreive the building from the intent Bundle extras = getIntent().getExtras(); int building_index = extras.getInt("building"); building = BuildingManager.getBuilding(building_index); + // retreive the UI elements TextView b_name = findViewById(R.id.building_name); b_name.setText(building.getName()); LinearLayout tile_goto = findViewById(R.id.tile_goto); LinearLayout tile_directions = findViewById(R.id.tile_directions); + // set the click listeners tile_goto.setOnClickListener(view -> { showGotoPopup(); }); + // set the direcitons tiles listeners tile_directions.setOnClickListener(view -> { showDirectionsPopup(); }); } protected void showGotoPopup() { + // display a goto popup (with a list of rooms) new GotoPopup(this, building).show(); } protected void showDirectionsPopup() { + // display a directions popup (with two rooms to select) new DirectionsPopup( this, building, diff --git a/Sources/app/src/main/java/com/furwaz/roomview/DirectionsActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/DirectionsActivity.java index bd050e2432662f61a7037c2d2f221b566e040bd2..99bacdf65c685b44f4506f7b440b101b813a0c7f 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/DirectionsActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/DirectionsActivity.java @@ -25,6 +25,7 @@ public class DirectionsActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_directions); + // retreive the building from the intent Bundle extras = getIntent().getExtras(); int buildingIndex = extras.getInt("building"); int fromIndex = extras.getInt("from_room"); @@ -34,6 +35,7 @@ public class DirectionsActivity extends AppCompatActivity { RoomInfo fromRoom = building.getRoom(fromIndex); RoomInfo toRoom = building.getRoom(toIndex); + // retreive the UI elements LinearLayout noDataLayout = findViewById(R.id.no_directions_layout); ListView dirs_lv = findViewById(R.id.directions_list); @@ -42,10 +44,12 @@ public class DirectionsActivity extends AppCompatActivity { from_label.setText(fromRoom.getName()); to_label.setText(toRoom.getName()); + // get the route between the two selected rooms and create the adapter List<DirectionStep> res = Directions.findRoute(fromRoom, toRoom); InfoAdapter<DirectionStep> adapter = new InfoAdapter<>(this, res, noDataLayout, R.layout.direction_tile); dirs_lv.setAdapter(adapter); + // set the bindings (what to display in the tile) adapter.setBindings(new InfoBinding[]{ new InfoBinding(param -> ((DirectionStep) param).getTitle(), R.id.direction_title), new InfoBinding(param -> ((DirectionStep) param).getDescription(), R.id.direction_description) diff --git a/Sources/app/src/main/java/com/furwaz/roomview/MainActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/MainActivity.java index 980c8ca35550007118dadb5e0b916d191543d62d..0c90e09e1e3f9bd132879fb896771dc724f180be 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/MainActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/MainActivity.java @@ -45,15 +45,20 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + // set the context for the building manager BuildingManager.setContext(getBaseContext()); + // retreive the UI elements ListView building_lv = findViewById(R.id.building_list); LinearLayout noDataLayout = findViewById(R.id.no_building_layout); + // create the adapter (list of buildings) building_adapter = new InfoAdapter<BuildingInfo>(this, BuildingManager.getBuildings(), noDataLayout, R.layout.building_tile); building_lv.setAdapter(building_adapter); + // set the remove button listener building_adapter.setOnRemoveListener(param -> { + // display the remove popup new RemovePopup( this, param2 -> { @@ -77,6 +82,7 @@ public class MainActivity extends AppCompatActivity { return null; }); + // set the view button listener (open the building view) building_adapter.setOnViewListener(param -> { Intent intent = new Intent(this, BuildingView.class); intent.putExtra("building", BuildingManager.getBuildings().indexOf(param)); @@ -84,6 +90,7 @@ public class MainActivity extends AppCompatActivity { return null; }); + // set the edit button listener (open the building edit view) building_adapter.setOnEditListener(param -> { Intent intent = new Intent(MainActivity.this, BuildingActivity.class); intent.putExtra("building", BuildingManager.getBuildings().indexOf(param)); @@ -91,6 +98,7 @@ public class MainActivity extends AppCompatActivity { return null; }); + // set the bindings (what to display in the list) building_adapter.setBindings(new InfoBinding[]{ new InfoBinding(param -> ((BuildingInfo) param).getName(), R.id.building_name), new InfoBinding(param -> ((BuildingInfo) param).getNbRooms(), R.id.building_nb_rooms), @@ -100,6 +108,7 @@ public class MainActivity extends AppCompatActivity { }, R.id.building_date) }); + // set the search view input listener SearchView building_sv = findViewById(R.id.building_search); building_sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean onQueryTextSubmit(String s) { return true; } @@ -111,6 +120,7 @@ public class MainActivity extends AppCompatActivity { } }); + // set the add button listener ImageButton add_btn = findViewById(R.id.add_building_btn); add_btn.setOnClickListener(this::showAddBuildingPopup); } @@ -118,10 +128,12 @@ public class MainActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); + // refresh the list of buildings building_adapter.setData(BuildingManager.getBuildings()); } protected void showAddBuildingPopup(View v) { + // display the add building popup new BuildingPopup( MainActivity.this, param -> { diff --git a/Sources/app/src/main/java/com/furwaz/roomview/PathwayActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/PathwayActivity.java index b2f8244ee184b85e3f59845cec1aabd4e0e2bbf5..55b945503ae13b235edd38c7220cee5a87f3591f 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/PathwayActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/PathwayActivity.java @@ -33,6 +33,7 @@ public class PathwayActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pathway); + // get the building, room and path Bundle extras = getIntent().getExtras(); int buildingIndex = extras.getInt("building"); int roomIndex = extras.getInt("room"); @@ -42,13 +43,16 @@ public class PathwayActivity extends AppCompatActivity { room = building.getRoom(roomIndex); path = room.getPath(pathIndex); + // set the UI elements setPathInfos(); + // set the cancel button listener Button btn_cancel = findViewById(R.id.btn_cancel); btn_cancel.setOnClickListener(view -> { this.finish(); }); + // set the edit button listener Button btn_edit = findViewById(R.id.btn_edit); btn_edit.setOnClickListener(view -> { this.savePathInfos(); @@ -56,6 +60,7 @@ public class PathwayActivity extends AppCompatActivity { }); } + // set the UI according to the path infos protected void setPathInfos() { TextView path_tv = findViewById(R.id.pathway_name); path_tv.setText(path.getName()); @@ -101,6 +106,7 @@ public class PathwayActivity extends AppCompatActivity { } } + // save the path infos protected void savePathInfos() { EditText input_name = findViewById(R.id.input_pathway_name); diff --git a/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java index 669ffa55d6706350503e14b8fd31e6156ae85243..2b31ca54473a9857484e2ee5bb4db93d71e3c99a 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java @@ -77,8 +77,9 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photo); - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Force portrait mode + // Get the building, room, zone and photo Bundle extras = getIntent().getExtras(); int building_index = extras.getInt("building"); int room_index = extras.getInt("room"); @@ -90,6 +91,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe zone = room.getZone(zone_index); photo = zone.getPhoto(photo_index); + // Setup the view according to if the photo is already taken or not if (new_photo) { this.setViewMode(MODE_PHOTO); } else { @@ -97,6 +99,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe } } + // display or hide the correct elements according to the mode + setup the mode protected void setViewMode(int mode) { FrameLayout cam_prev = findViewById(R.id.camera_preview); LinearLayout cam_hud = findViewById(R.id.camera_hud); @@ -117,24 +120,29 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe @SuppressLint("SetTextI18n") protected void setupPhotoMode() { + // Check if camera is available if (!checkCameraHardware()) { Toast.makeText(this, "Error : no camera detected on this device", Toast.LENGTH_SHORT).show(); this.finish(); } - FrameLayout cam_prev = findViewById(R.id.camera_preview); + // get the UI elements + FrameLayout cam_prev = findViewById(R.id.camera_preview); ImageButton btn_nope = findViewById(R.id.btn_nope); ImageButton btn_foto = findViewById(R.id.btn_foto); + // Setup the cancel button btn_nope.setOnClickListener(view -> { this.finish(); }); + // Setup the camera preview + take picture button getCamera(c -> { Camera camera = (Camera) c; CameraPreview camPrev = new CameraPreview(this, camera); cam_prev.addView(camPrev); + // Setup the take picture button btn_foto.setOnClickListener(view -> { camera.takePicture(null, null, (bytes, cam) -> { photo.setImage(bytes); @@ -152,6 +160,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe return null; }); + // Setup the phone level indicator at the top of the screen levelView = findViewById(R.id.level_view); sm = (SensorManager) getSystemService(SENSOR_SERVICE); if (sm != null) { @@ -160,19 +169,24 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe register(); } + // Setup the meteo indicator at the bottom of the screen MeteoInfo.GetCurrentMeteo(this, meteo -> { + // got meteo, update the UI currentMeteo = (MeteoInfo) meteo; runOnUiThread(() -> { ((TextView) findViewById(R.id.temperature)).setText(Math.round(currentMeteo.getTemperature()) + "°C"); ((TextView) findViewById(R.id.humidity)).setText((int)currentMeteo.getHumidity() + "%"); }); + // get the weather icon currentMeteo.getWeatherIcon(icon -> { + // got icon, update the UI runOnUiThread(() -> { ImageView weather_icon = findViewById(R.id.weather_icon); weather_icon.setImageBitmap((Bitmap) icon); }); return null; }, error -> { + // error, display error message runOnUiThread(() -> { Toast.makeText(this, getResources().getString(R.string.error)+" : "+error, Toast.LENGTH_SHORT).show(); ((TextView) findViewById(R.id.humidity)).setText(R.string.error); @@ -181,6 +195,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe }); return null; }, error -> { + // error, display error message runOnUiThread(() -> { Toast.makeText(this, getResources().getString(R.string.error)+" : "+error, Toast.LENGTH_SHORT).show(); ((TextView) findViewById(R.id.humidity)).setText(R.string.error); @@ -189,6 +204,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe }); } + // Setup the edit mode (display the photo and the edit buttons) protected void setupEditMode() { ImageView photo_prev = findViewById(R.id.photo_preview); photo_prev.setImageBitmap( photo.getBitmap() ); @@ -215,6 +231,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe selector.setPhoto(photo); } + // Returns the layout padding needed to display the given orientation to screen public int getOrientationLayoutPadding(Orientation orient) { switch (orient) { case NORTH: return 0; @@ -225,6 +242,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe return 0; } + // triggers the animation to display the given orientation to screen public void displayOrientation(Orientation orient) { if (this.displayed_orient == orient) return; @@ -252,16 +270,19 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe @Override protected void onPause() { super.onPause(); + // unregister the sensors unregister(); } @Override protected void onResume() { super.onResume(); + // register the sensors register(); } protected void register() { + // activate the accelerometer and the magnetometer if (sm != null) { if (accelerometer != null) sm.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI); @@ -271,6 +292,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe } protected void unregister() { + // deactivate the accelerometer and the magnetometer if (sm != null) { if (accelerometer != null) sm.unregisterListener(this, accelerometer); @@ -284,6 +306,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe @Override public void onSensorChanged(SensorEvent sensorEvent) { + // get the accelerometer values if (sensorEvent.sensor == accelerometer) { accelValues = sensorEvent.values; float x_val = sensorEvent.values[0]; @@ -292,8 +315,11 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe if (levelView != null) levelView.askForDraw(orient); } + // get the magnetometer values if (sensorEvent.sensor == magnet) { magnetValues = sensorEvent.values; + + // if we have the accelerometer values, we can compute the phone's orientation float[] res = new float[9]; SensorManager.getRotationMatrix( res, @@ -306,16 +332,17 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe int angle = ((int)(values[0] * 180 / Math.PI) + 135) % 360; if (angle < 0) angle = 360 + angle; + // we display the orientation to screen Orientation orient = Orientation.SOUTH; if (angle >= 0 && angle < 90) orient = Orientation.WEST; if (angle >= 90 && angle < 180) orient = Orientation.NORTH; if (angle >= 180 && angle < 270) orient = Orientation.EST; - // if (angle >= 270 && angle < 360) [sert a rien, la valeur est deja assignee] - + // if (angle >= 270 && angle < 360) [not used, it's the default value] displayOrientation(orient); } } + // try to get the phone's camera (executes the onResolve callback if success, the onReject callback if error) protected void getCamera(Callback onResolve, Callback onReject) { this._on_resolve_callback = onResolve; this._on_reject_callback = onReject; @@ -337,6 +364,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { + // camera permission, trigger the getCamera method again to maybe execute the callbacks case 621: if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { getCamera(_on_resolve_callback, _on_reject_callback); @@ -344,16 +372,20 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe if (_on_reject_callback != null) _on_reject_callback.call( getResources().getString(R.string.camera_error) ); } break; + + // meteo info permission, trigger the MeteoInfo method to try to get the meteo info case 926: MeteoInfo.SetPermissionResult(grantResults[0] == PackageManager.PERMISSION_GRANTED); } } + // returns if the phone has a camera private boolean checkCameraHardware() { return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY); } protected void showAddWalkPopup() { + // display a walk setup popup (to go from a zone to another) new WalkPopup( this, zone, @@ -373,6 +405,7 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe } protected void showEditWalkPopup() { + // display a walk setup popup (to go from a zone to another) but in edit mode new WalkPopup( this, zone, diff --git a/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java index 4acbfaa48dc851b6f161e202f9d63e2460d5f8d8..967b4f1f2e01cc8f5d6552c5f41807c0af362e8c 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java @@ -63,6 +63,7 @@ public class RoomActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_room); + // get the building and room int buildingIndex = getIntent().getExtras().getInt("building"); int roomIndex = getIntent().getExtras().getInt("room"); building = BuildingManager.getBuilding(buildingIndex); @@ -82,6 +83,7 @@ public class RoomActivity extends AppCompatActivity { } }); + // setup all the UI elements View pathways_btn = findViewById(R.id.btn_tab_pathways); pathways_btn.setOnClickListener(view -> switchToPathways()); @@ -91,9 +93,11 @@ public class RoomActivity extends AppCompatActivity { ListView room_lv = findViewById(R.id.zone_list); LinearLayout noDataLayout = findViewById(R.id.no_zone_layout); + // create the adapter for the zones zone_adapter = new InfoAdapter<ZoneInfo>(this, room.getZones(), noDataLayout, R.layout.zone_tile); room_lv.setAdapter(zone_adapter); + // setup the remove button listener zone_adapter.setOnRemoveListener(param -> { new RemovePopup( this, @@ -117,6 +121,7 @@ public class RoomActivity extends AppCompatActivity { ).show(); return null; }); + // setup the edit button listener zone_adapter.setOnEditListener(param -> { Intent intent = new Intent(this, ZoneActivity.class); intent.putExtra("building", BuildingManager.getBuildings().indexOf(building)); @@ -125,8 +130,10 @@ public class RoomActivity extends AppCompatActivity { this.startActivity(intent); return null; }); + // setup the view button listener (not used) zone_adapter.setOnViewListener(param -> null); + // setup the bindings for the zones (the data to display) zone_adapter.setBindings(new InfoBinding[]{ new InfoBinding(param -> ((ZoneInfo) param).getName(), R.id.zone_name), new InfoBinding(param -> ((ZoneInfo) param).getPhotos().size(), R.id.zone_photos) @@ -135,9 +142,11 @@ public class RoomActivity extends AppCompatActivity { ListView pathways_lv = findViewById(R.id.pathways_list); LinearLayout noPathwaysLayout = findViewById(R.id.no_pathways_layout); + // create the adapter for the pathways pathways_adapter = new InfoAdapter<PathInfo>(this, room.getPaths(), noPathwaysLayout, R.layout.pathway_tile); pathways_lv.setAdapter(pathways_adapter); + // setup the remove button listener pathways_adapter.setOnRemoveListener(param -> { new RemovePopup( this, @@ -161,6 +170,7 @@ public class RoomActivity extends AppCompatActivity { ).show(); return null; }); + // setup the edit button listener pathways_adapter.setOnEditListener(param -> { Intent intent = new Intent(this, PathwayActivity.class); intent.putExtra("building", BuildingManager.getBuildings().indexOf(building)); @@ -169,8 +179,10 @@ public class RoomActivity extends AppCompatActivity { startActivity(intent); return null; }); + // setup the view button listener (not used) pathways_adapter.setOnViewListener(param -> null); + // setup the bindings for the pathways (the data to display) pathways_adapter.setBindings(new InfoBinding[]{ new InfoBinding(param -> ((PathInfo) param).getName(), R.id.pathway_name), new InfoBinding(param -> { @@ -196,6 +208,7 @@ public class RoomActivity extends AppCompatActivity { }, R.id.pathway_dest) }); + // setup the search bar for the pathways and zones SearchView search_sv = findViewById(R.id.list_search); search_sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean onQueryTextSubmit(String s) { return true; } @@ -211,15 +224,18 @@ public class RoomActivity extends AppCompatActivity { } }); + // setup the add button listener ImageButton add_btn = findViewById(R.id.add_zone_btn); add_btn.setOnClickListener(view -> { if (isViewInPathwaysMode) showAddPathwayPopup(view); else showAddZonePopup(view); }); + // setup the edit button listener ImageButton edit_btn = findViewById(R.id.edit_room_name); edit_btn.setOnClickListener(view -> showEditPopup()); + // set the room name TextView room_tv_name = findViewById(R.id.room_name); room_tv_name.setText(room.getName()); } @@ -227,10 +243,12 @@ public class RoomActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); + // update the lists zone_adapter.setData(room.getZones()); pathways_adapter.setData(room.getPaths()); } + // display / hide the correct elements to display the pathways protected void switchToPathways() { isViewInPathwaysMode = true; disableTabButton(R.id.btn_tab_zones); @@ -239,6 +257,7 @@ public class RoomActivity extends AppCompatActivity { findViewById(R.id.zones_tab_view).setVisibility(View.GONE); } + // display / hide the correct elements to display the zones protected void switchToZones() { isViewInPathwaysMode = false; disableTabButton(R.id.btn_tab_pathways); @@ -246,7 +265,8 @@ public class RoomActivity extends AppCompatActivity { findViewById(R.id.pathways_tab_view).setVisibility(View.GONE); findViewById(R.id.zones_tab_view).setVisibility(View.VISIBLE); } - + + // makes the tab button look like it is selected protected void enableTabButton(int id) { TextView tv = findViewById(id); tv.setTextColor(getResources().getColor(R.color.blue_500, getTheme())); @@ -259,6 +279,7 @@ public class RoomActivity extends AppCompatActivity { tv.setPadding(padding, padding, padding, padding); } + // makes the tab button look like it is not selected protected void disableTabButton(int id) { TextView tv = findViewById(id); tv.setTextColor(getResources().getColor(R.color.slate_400, getTheme())); @@ -272,6 +293,7 @@ public class RoomActivity extends AppCompatActivity { } protected void showEditPopup() { + // show the popup to edit the room name new RoomPopup( this, building, @@ -296,6 +318,7 @@ public class RoomActivity extends AppCompatActivity { } protected void showAddZonePopup(View v) { + // show the popup to add a new zone new ZonePopup( this, room, @@ -320,6 +343,7 @@ public class RoomActivity extends AppCompatActivity { } protected void showAddPathwayPopup(View v) { + // show the popup to add a new pathway new PathwayPopup( this, building, diff --git a/Sources/app/src/main/java/com/furwaz/roomview/ZoneActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/ZoneActivity.java index e00d4efef76162cf465c823ad6f0c8f66d8b776e..d7e987d14661cdffc00d0aba824bc86c1c23a12a 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/ZoneActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/ZoneActivity.java @@ -41,6 +41,7 @@ public class ZoneActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zone); + // retreive the building from the intent Bundle extras = getIntent().getExtras(); int building_index = extras.getInt("building"); int room_index = extras.getInt("room"); @@ -52,9 +53,11 @@ public class ZoneActivity extends AppCompatActivity { photo_lv = findViewById(R.id.photo_list); LinearLayout noDataLayout = findViewById(R.id.no_photo_layout); + // create the adapter (list of photos) photo_adapter = new InfoAdapter<>(this, zone.getPhotos(), noDataLayout, R.layout.photo_tile); photo_lv.setAdapter(photo_adapter); + // remove button click photo_adapter.setOnRemoveListener(param -> { new RemovePopup( this, @@ -79,6 +82,7 @@ public class ZoneActivity extends AppCompatActivity { ).show(); return null; }); + // edit button click photo_adapter.setOnEditListener(param -> { Intent intent = new Intent(this, PhotoActivity.class); intent.putExtra("building", BuildingManager.getBuildings().indexOf(building)); @@ -89,6 +93,7 @@ public class ZoneActivity extends AppCompatActivity { startActivity(intent); return null; }); + // view button click (not used) photo_adapter.setOnViewListener(param -> null); photo_adapter.setBindings(new InfoBinding[]{ @@ -107,6 +112,7 @@ public class ZoneActivity extends AppCompatActivity { }); }); + // setup the search bar for the photos SearchView photo_sv = findViewById(R.id.photo_search); photo_sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { public boolean onQueryTextSubmit(String s) { return true; } @@ -118,14 +124,18 @@ public class ZoneActivity extends AppCompatActivity { } }); + // setup the add button add_btn = findViewById(R.id.add_photo_btn); add_btn.setOnClickListener(this::showAddPhotoPopup); + // display of hide the add button (if there are no photos or if there are 4 photos) checkForAddButton(); + // setup the edit button ImageButton edit_btn = findViewById(R.id.edit_zone_name); edit_btn.setOnClickListener(view -> showEditPopup()); + // setup the zone name TextView zone_tv_name = findViewById(R.id.zone_name); zone_tv_name.setText(zone.getName()); } @@ -133,9 +143,11 @@ public class ZoneActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); + // update the photos list photo_lv.setAdapter(photo_adapter); } + // Returns the string name of the orientation protected String stringifyOrientation(Orientation orient) { int stringID = -1; switch (orient) { @@ -148,6 +160,7 @@ public class ZoneActivity extends AppCompatActivity { } protected void showEditPopup() { + // show the popup to edit the zone name new ZonePopup( this, room, @@ -172,6 +185,7 @@ public class ZoneActivity extends AppCompatActivity { } protected void showAddPhotoPopup(View v) { + // show the popup to add a new photo new PhotoPopup( this, zone, @@ -194,6 +208,7 @@ public class ZoneActivity extends AppCompatActivity { } protected void checkForAddButton() { + // display of hide the add button (if there are no photos or if there are 4 photos) if (zone.getPhotos().size() < 4) { add_btn.setVisibility(View.VISIBLE); } else { diff --git a/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java b/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java index b8f9f6d76ce3d501a7c19ba72b0366629df5cd30..8c58817f7b17559fdbfc5d0b79f3fbcceec4e02e 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java @@ -46,6 +46,7 @@ public class ZoneView extends AppCompatActivity { Orientation orient = Orientation.NORTH; + // return the string corresponding to the orientation protected String stringifyOrientation(Orientation orient) { int stringID = -1; switch (orient) { @@ -57,6 +58,7 @@ public class ZoneView extends AppCompatActivity { return getResources().getString(stringID); } + // return the left orientation from the current one protected Orientation getLeft(Orientation o) { switch (orient) { case EST: return Orientation.SOUTH; @@ -67,6 +69,7 @@ public class ZoneView extends AppCompatActivity { return Orientation.NORTH; } + // return the right orientation from the current one protected Orientation getRight(Orientation o) { switch (orient) { case EST: return Orientation.NORTH; @@ -82,6 +85,7 @@ public class ZoneView extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zone_view); + // get the building, room and zone from the intent Bundle extras = getIntent().getExtras(); building_index = extras.getInt("building"); room_index = extras.getInt("room"); @@ -96,23 +100,28 @@ public class ZoneView extends AppCompatActivity { zone = null; } + // set the left-right buttons ImageButton btn_l = findViewById(R.id.btn_turn_l); ImageButton btn_r = findViewById(R.id.btn_turn_r); + // left button listener btn_l.setOnClickListener(view -> { this.orient = getLeft(this.orient); this.updateUI(); }); + // right button listener btn_r.setOnClickListener(view -> { this.orient = getRight(this.orient); this.updateUI(); }); + // set the info button (to display the popup if photo infos on it) ImageView info_btn = findViewById(R.id.info_btn); info_btn.setOnClickListener(view -> { new PhotoInfoPopup(this, photo).show(); }); + // set the photo zone click listener (for pathviews click, to move) ClickDetector bitmap_zone = findViewById(R.id.bitmap_zone); bitmap_zone.setOnClickCallback(param -> { Coord c = (Coord) param; @@ -124,10 +133,12 @@ public class ZoneView extends AppCompatActivity { @Override protected void onResume() { super.onResume(); + // update the UI (photo displayed, or error message if no photo) updateUI(); } protected void updateUI() { + // set the textviews TextView tv_orient = findViewById(R.id.orient_text); TextView tv_room = findViewById(R.id.room_name); TextView tv_zone = findViewById(R.id.zone_name); @@ -136,30 +147,36 @@ public class ZoneView extends AppCompatActivity { tv_room.setText(room == null? "": room.getName()); tv_zone.setText(zone == null? "": zone.getName()); + // hide the error layout (to bring it back if an error occurs) hideErrorLayout(); + // if the zone is null, display an error message if (zone == null) { showErrorLayout(R.string.no_photos, R.string.no_photos_taken); return; } + // if the zone has no photos, display an error message if (zone.getPhotos().size() == 0) { showErrorLayout(R.string.no_photos, R.string.no_photos_taken); return; } + // if the current orientation has no photo, display an error message photo = zone.getPhoto(this.orient); if (photo == null) { showErrorLayout(R.string.no_photos, R.string.no_photos_yet); return; } + // if the photo has not been taken yet, display an error message Bitmap bm = photo.getBitmap(); if (bm == null) { showErrorLayout(R.string.no_photos, R.string.no_photos_yet); return; } + // it's all good, display the photo (and show the walk button if we can walk) ImageView btn_walk = findViewById(R.id.btn_walk); LinearLayout walk_btn = findViewById(R.id.walk_btn); WalkInfo walk = zone.getWalk(this.orient); @@ -176,26 +193,29 @@ public class ZoneView extends AppCompatActivity { }); } - + // display the photo ImageView iv = findViewById(R.id.bitmap_view); iv.setImageBitmap(bm); } protected void showErrorLayout(int title, int description) { + // get the ui elements and hide the photo ClickDetector bitmap_zone = findViewById(R.id.bitmap_zone); ImageView bitmap_view = findViewById(R.id.bitmap_view); bitmap_zone.setVisibility(View.GONE); bitmap_view.setVisibility(View.GONE); + // get the textviews and set the error message LinearLayout error_layout = findViewById(R.id.error_layout); TextView tv_titre = findViewById(R.id.error_title); TextView tv_desc = findViewById(R.id.error_desc); - tv_titre.setText(getResources().getString(title)); tv_desc.setText(getResources().getString(description)); + // show the error layout error_layout.setVisibility(View.VISIBLE); Button btn_back = findViewById(R.id.back_btn); + // on back button click, finish activity or go back to the previous zone if come from it btn_back.setOnClickListener(view -> { if (this.old_zone == null) finish(); else { @@ -205,6 +225,7 @@ public class ZoneView extends AppCompatActivity { } }); + // on edit button click, go to the zone activity to edit it Button btn_edit = findViewById(R.id.edit_btn); btn_edit.setOnClickListener(view -> { Intent intent = new Intent(this, ZoneActivity.class); @@ -216,6 +237,7 @@ public class ZoneView extends AppCompatActivity { } protected void hideErrorLayout() { + // get the ui elements and hide the error layout ClickDetector bitmap_zone = findViewById(R.id.bitmap_zone); ImageView bitmap_view = findViewById(R.id.bitmap_view); bitmap_zone.setVisibility(View.VISIBLE); @@ -226,22 +248,28 @@ public class ZoneView extends AppCompatActivity { } protected void gotoDest(RoomInfo dest) { + // if the destination is null, toast an error message if (dest == null) { Toast.makeText(this, R.string.not_defined, Toast.LENGTH_SHORT).show(); return; } + // if the destination has no zones, toast an error message if (dest.getNbZones() == 0) { Toast.makeText(this, R.string.no_photo_yet, Toast.LENGTH_SHORT).show(); return; } + + // get the nearest room's zone from here and go to it ZoneInfo new_zone = dest.getNearestZone(this.room); old_zone = this.zone; this.room = dest; this.zone = new_zone; + // update the ui to display the new zone this.updateUI(); } protected void displayStairsDirectionPopup(PathStairs ps) { + // if stairs have been clicked on the view, display a popup to choose the direction new StairsDestPopup(this, param -> { gotoDest(ps.getDestination(StairsDirection.UP)); return null; @@ -252,6 +280,9 @@ public class ZoneView extends AppCompatActivity { } protected void onClickAt(Coord c) { + // if the user clicked on the photo, try to get the path at the clicked position + // and trigger the corresponding action + if (photo == null) return; for (PathView pv : photo.getPathViews()) { if (pv.getRect().contains(c.getX(), c.getY())) {