Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Navi/app/src/main/java/com/example/navi_app/Location.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
76 lines (58 sloc)
2 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.navi_app; | |
import android.util.Log; | |
import org.json.JSONArray; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import java.io.Serializable; | |
import java.util.ArrayList; | |
public class Location implements Serializable { | |
public String name; | |
public ArrayList<Node> nodes = new ArrayList<>(); | |
public String type; | |
public String computers; | |
public String workspace; | |
public String food; | |
private final String TAG = "LOCATION"; | |
//Location System | |
private LocationSystem currentSystem; | |
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++) | |
{ | |
JSONObject nodeJSON = nodesArray.getJSONObject(i); | |
// Pulling items from the array | |
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 = ""; | |
} | |
} | |
} |