Skip to content
Permalink
Browse files
Added some simple user interface for the current location data and al…
…so have updated the code to allow for the location to hold and display this extra data
  • Loading branch information
eggintod committed Mar 16, 2019
1 parent 970e682 commit a26ae0a3d7a017dfc6f37a557080ada8b2c489b0
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 52 deletions.

Some generated files are not rendered by default. Learn more.

@@ -13,7 +13,13 @@ public class Location implements Serializable {

public String name;
public ArrayList<Node> nodes = new ArrayList<>();
public int computersAvadiable;
public String type;

public String computers;
public String workspace;
public String food;


private final String TAG = "LOCATION";

//Location System
@@ -22,11 +28,33 @@ public class Location implements Serializable {

public Location(JSONObject location, LocationSystem currentSystem) {

// INIT Current location system
this.currentSystem = currentSystem;

// Try INIT location from json
try {
this.name = location.getString("name");

this.type = location.getString("type");

JSONObject locationData = location.getJSONObject("data");

try{
this.computers = locationData.getString("computers");
}catch (JSONException e){
this.computers = "";
}
try{
this.workspace = locationData.getString("workspace");
}catch (JSONException e){
this.workspace = "";
}
try{
this.food = locationData.getString("food");
}catch (JSONException e){
this.food = "";
}

JSONArray nodesArray = location.getJSONArray("nodes");

for (int i=0; i < nodesArray.length(); i++)
@@ -36,9 +64,13 @@ public class Location implements Serializable {
nodes.add(new Node(nodeJSON, currentSystem));
}
Log.i(TAG, name);

} catch (JSONException e) {
e.printStackTrace();
this.name = "";
this.type = "";
this.computers = "";
this.workspace = "";
this.food = "";
}
}
}
@@ -128,7 +128,7 @@ public class MainActivity extends AppCompatActivity {
}

public void btn_login_Clicked(View view) {
LocationSystem ls = new LocationSystem("https://gist.githubusercontent.com/dominicegginton/99dc73485e5a1937b2d0bfadd0fa8d0c/raw/7ae81355ff7ddd4339c01cd58f8d5c1262686463/coventryUniNaviData.json");
LocationSystem ls = new LocationSystem("https://gist.githubusercontent.com/dominicegginton/99dc73485e5a1937b2d0bfadd0fa8d0c/raw/366c0aa82a74cc03ec0a0f13cf6f1a146c82fa38/coventryUniNaviData.json");
// Create new intent to open new page
Intent intent = new Intent(getBaseContext(), menu.class);
intent.putExtra("location_system", ls);
@@ -11,13 +11,15 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

@@ -36,7 +38,20 @@ public class current_location extends AppCompatActivity {
TextView txt_location_level;
TextView txt_location_building;
ProgressBar progress_spinner;


ConstraintLayout layout_location_data_type;
ImageView img_location_data_type;
TextView txt_location_data_type;
ConstraintLayout layout_location_data_computers;
ImageView img_location_data_computers;
TextView txt_location_data_computers;
ConstraintLayout layout_location_data_workspaces;
ImageView img_location_data_workspaces;
TextView txt_location_data_workspaces;
ConstraintLayout layout_location_data_food;
ImageView img_location_data_food;
TextView txt_location_data_food;

//Location System Objects
private LocationSystem ls;

@@ -66,6 +81,19 @@ public class current_location extends AppCompatActivity {
txt_location_building = (TextView) findViewById(R.id.txt_location_Building);
progress_spinner = (ProgressBar) findViewById(R.id.progress_spinner);

layout_location_data_type = (ConstraintLayout) findViewById(R.id.layout_location_data_type);
img_location_data_type = (ImageView) findViewById(R.id.img_location_data_type);
txt_location_data_type = (TextView) findViewById(R.id.txt_location_data_type);
layout_location_data_computers = (ConstraintLayout) findViewById(R.id.layout_location_data_computers);
img_location_data_computers = (ImageView) findViewById(R.id.img_location_data_computer);
txt_location_data_computers = (TextView) findViewById(R.id.txt_location_data_computers);
layout_location_data_workspaces = (ConstraintLayout) findViewById(R.id.layout_location_data_workspace);
img_location_data_workspaces = (ImageView) findViewById(R.id.img_location_data_workspaces);
txt_location_data_workspaces = (TextView) findViewById(R.id.txt_location_data_workspaces);
layout_location_data_food = (ConstraintLayout) findViewById(R.id.layout_location_data_food);
img_location_data_food = (ImageView) findViewById(R.id.img_location_data_food);
txt_location_data_food = (TextView) findViewById(R.id.txt_location_data_food);

// update Current Location
displayCurrentLocation();
}
@@ -175,6 +203,19 @@ public class current_location extends AppCompatActivity {
txt_location_name.setVisibility(View.GONE);
txt_location_level.setVisibility(View.GONE);
txt_location_building.setVisibility(View.GONE);

layout_location_data_type.setVisibility(View.GONE);
//img_location_data_type.setVisibility(View.GONE);
//txt_location_data_type.setVisibility(View.GONE);
layout_location_data_computers.setVisibility(View.GONE);
//img_location_data_computers.setVisibility(View.GONE);
//txt_location_data_computers.setVisibility(View.GONE);
layout_location_data_workspaces.setVisibility(View.GONE);
//img_location_data_workspaces.setVisibility(View.GONE);
//txt_location_data_workspaces.setVisibility(View.GONE);
layout_location_data_food.setVisibility(View.GONE);
//img_location_data_food.setVisibility(View.GONE);
//txt_location_data_food.setVisibility(View.GONE);
scan();

// Create new delay handler of 10 seconds
@@ -185,13 +226,49 @@ public class current_location extends AppCompatActivity {
// Get current location object
Location currentLocation = ls.getCurrentLocation(scannedNodes);

// Check for null location
// Check for null locations
if (currentLocation != null) {
// End Spinner
progress_spinner.setVisibility(View.GONE);

// Output location details to UI
txt_location_building.setText(ls.getCurrentBuilding(currentLocation).name);
txt_location_level.setText(ls.getCurrentLevel(currentLocation).name);
txt_location_name.setText(currentLocation.name);
txt_location_name.setVisibility(View.VISIBLE);
txt_location_level.setVisibility(View.VISIBLE);
txt_location_building.setVisibility(View.VISIBLE);

txt_location_data_type.setText(currentLocation.type);
//txt_location_data_type.setVisibility(View.VISIBLE);
Log.i("computers", currentLocation.computers);
if(currentLocation.type.equals("Classroom") | currentLocation.type.equals("Lecture")) {
img_location_data_type.setImageResource(R.drawable.icon_presenter);
} else if (currentLocation.type.equals("Reception")) {
img_location_data_type.setImageResource(R.drawable.icon_reception);
} else if (currentLocation.type.equals("Walkway")) {
img_location_data_type.setImageResource(R.drawable.icon_path);
} else {
img_location_data_type.setImageResource(R.drawable.icon_building);
}
//img_location_data_type.setVisibility(View.VISIBLE);
layout_location_data_type.setVisibility(View.VISIBLE);

if(!currentLocation.computers.equals("")) {
txt_location_data_computers.setText(currentLocation.computers);
img_location_data_computers.setImageResource(R.drawable.icon_computer);
layout_location_data_computers.setVisibility(View.VISIBLE);
}
if(!currentLocation.workspace.equals("")) {
txt_location_data_workspaces.setText(currentLocation.workspace);
img_location_data_workspaces.setImageResource(R.drawable.icon_table);
layout_location_data_workspaces.setVisibility(View.VISIBLE);
}
if(!currentLocation.food.equals("")) {
txt_location_data_food.setText(currentLocation.food);
img_location_data_food.setImageResource(R.drawable.icon_food);
layout_location_data_food.setVisibility(View.VISIBLE);
}

// Log Nodes that belong to the location
String output = currentLocation.name + " - {";
@@ -202,10 +279,6 @@ public class current_location extends AppCompatActivity {
Log.i("Current Location", output);


progress_spinner.setVisibility(View.GONE);
txt_location_name.setVisibility(View.VISIBLE);
txt_location_level.setVisibility(View.VISIBLE);
txt_location_building.setVisibility(View.VISIBLE);
}else {
// cant get current location
// Create Alert Dialog
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a26ae0a

Please sign in to comment.