-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from RUGSoftEng/merge_gui_communication
Release 0.2 Needs a proper OOP solution for encoding types,fragment class needs refactoring.
- Loading branch information
Showing
59 changed files
with
930 additions
and
2,804 deletions.
There are no files selected for viewing
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions
59
Hestia/app/src/main/java/com/rugged/application/hestia/Activator.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.rugged.application.hestia; | ||
|
||
|
||
/** | ||
* This class represents a single activator on a device. A single device can have multiple | ||
* activators. The activator has an id so we can reference it on the server. Furthermore there is a | ||
* string name and a string state type, which is currently used for casting the generic state | ||
* variable to an actual type. | ||
* @see Device | ||
* @param <T> Type of the state of the activator. This can be a boolean (for a switch) or a float | ||
* (for a slider) | ||
*/ | ||
public class Activator<T> { | ||
private int activatorId; | ||
private T state; | ||
private String name; | ||
private String stateType; | ||
|
||
private String requiredInfo; | ||
|
||
public Activator(int id, T state, String name, String type) { | ||
this.activatorId = id; | ||
this.state = state; | ||
this.name = name; | ||
this.stateType = type; | ||
} | ||
|
||
public int getId() { | ||
return activatorId; | ||
} | ||
|
||
public void setId(int id) { | ||
this.activatorId = id; | ||
} | ||
|
||
public T getState() { | ||
return state; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getType() { | ||
return stateType; | ||
} | ||
|
||
public void setType(String type) { | ||
this.stateType = type; | ||
} | ||
|
||
public String toString() { | ||
return name + " " + state; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
Hestia/app/src/main/java/com/rugged/application/hestia/Device.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* This class contains the clients internal representation of the peripheral connected to the | ||
* server. | ||
*/ | ||
|
||
package com.rugged.application.hestia; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Represents the internal representation of the device class on the client. The device contains an | ||
* id with which we can reference its remote version on the server. The name string contains the | ||
* local name of the device, for instance "Front door lock". The type string is used to denote the | ||
* type of the device so a GUI can be generated with the right icons at the correct location. | ||
* <p> | ||
* Finally, there is a list of activators. These activators represent all the actions which can | ||
* be performed remotely on the device. An activator can be for instance an On/Off switch, or | ||
* an intensity slider. | ||
* </p> | ||
* @see Activator | ||
*/ | ||
public class Device { | ||
int deviceId; | ||
String name; | ||
String type; | ||
ArrayList<Activator> activators; | ||
|
||
public Device(int id, String name, String type, ArrayList<Activator> a) { | ||
this.deviceId = id; | ||
this.name = name; | ||
this.type = type; | ||
this.activators = a; | ||
} | ||
|
||
public int getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
public void setDeviceId(int deviceId) { | ||
this.deviceId = deviceId; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public ArrayList<Activator> getActivators() { | ||
return activators; | ||
} | ||
|
||
public void setActivators(ArrayList<Activator> activators) { | ||
this.activators = activators; | ||
} | ||
public String toString(){ | ||
return name +" "+ deviceId + " "+activators; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Hestia/app/src/main/java/com/rugged/application/hestia/DeviceListActivity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
This class is the host of the PeripheralListFragment. | ||
*/ | ||
|
||
package com.rugged.application.hestia; | ||
|
||
import android.support.v4.app.Fragment; | ||
|
||
/** | ||
* The activity which presents a list containing all peripherals to the user. An activity is a | ||
* single, focused thing the user can do. | ||
*/ | ||
public class DeviceListActivity extends SingleFragmentActivity{ | ||
private final static String TAG = "DeviceListActivity"; | ||
@Override | ||
protected Fragment createFragment() { | ||
return new DeviceListFragment(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
Hestia/app/src/main/java/com/rugged/application/hestia/DeviceListFragment.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.rugged.application.hestia; | ||
import android.content.Context; | ||
import android.graphics.Typeface; | ||
import android.os.AsyncTask; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.widget.PopupMenu; | ||
import android.view.LayoutInflater; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseExpandableListAdapter; | ||
import android.widget.ExpandableListView; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
/** | ||
* This fragment takes care of generating the list of peripherals on the phone. It sends an HTTP | ||
* GET request to the server to populate the device list. | ||
* | ||
* @see DeviceListActivity | ||
*/ | ||
public class DeviceListFragment extends Fragment { | ||
|
||
private final static String TAG = "DeviceListFragment"; | ||
|
||
ExpandableListAdapter listAdapter; | ||
ExpandableListView expListView; | ||
List<String> listDataHeader; | ||
HashMap<String, List<Device>> listDataChild; | ||
|
||
/** | ||
* | ||
* @param inflater The layout inflater used to generate the layout hierarchy | ||
* @param container The viewgroup with which the layout is instantiated | ||
* @return A view of an expandable list linked to the listDataHeader and listDataChild | ||
* variables. Filling these lists will generate the GUI. | ||
*/ | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.fragment_peripheral_list, container, false); | ||
|
||
expListView = (ExpandableListView) view.findViewById(R.id.lvExp); | ||
|
||
listDataHeader = new ArrayList<>(); | ||
listDataChild = new HashMap<>(); | ||
|
||
listAdapter = new ExpandableListAdapter(listDataHeader, listDataChild, getActivity()); | ||
|
||
expListView.setAdapter(listAdapter); | ||
|
||
//request the list | ||
new RetrievePeripheralList().execute(); | ||
|
||
// setting list adapter | ||
return view; | ||
} | ||
|
||
private class RetrievePeripheralList extends AsyncTask<Void, Void, Void> { | ||
@Override | ||
protected Void doInBackground(Void... voids) { | ||
//mock data | ||
ArrayList<Activator> activators = new ArrayList<>(); | ||
activators.add(new Activator<>(0, false, "light_OnOROff", "TOGGLE")); | ||
ArrayList<Activator> a2 = new ArrayList<>(); | ||
a2.add(new Activator<>(0, 0, "Lock_OnOROff", "SLIDER")); | ||
Device d1 = new Device(0, "Light 1", "Light", activators); | ||
Device d2 = new Device(0, "Light 2", "Light", activators); | ||
Device d3 = new Device(0, "lock 1", "Lock", a2); | ||
ArrayList<Device> devices = new ArrayList<>(); | ||
devices.add(d1); | ||
devices.add(d2); | ||
devices.add(d3); | ||
|
||
// add header data | ||
for (Device d : devices) { | ||
if (!listDataHeader.contains(d.getType())) { | ||
listDataHeader.add(d.getType()); | ||
listDataChild.put(d.getType(), new ArrayList<Device>()); | ||
} | ||
//find corresponding header for the child | ||
listDataChild.get(d.getType()).add(d); | ||
} | ||
// listAdapter.notifyDataSetChanged(); | ||
return null; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Hestia/app/src/main/java/com/rugged/application/hestia/DeviceListRetriever.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.rugged.application.hestia; | ||
|
||
import android.os.AsyncTask; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by root on 24-3-17. | ||
*/ | ||
|
||
class DeviceListRetriever extends AsyncTask<Void,Void,Void> { | ||
@Override | ||
protected Void doInBackground(Void... voids) { | ||
//mock data | ||
ArrayList<Activator> activators = new ArrayList<>(); | ||
activators.add(new Activator<>(0, false, "light_OnOROff", "TOGGLE")); | ||
ArrayList<Activator> a2 = new ArrayList<>(); | ||
a2.add(new Activator<>(0, 0, "Lock_OnOROff", "SLIDER")); | ||
Device d1 = new Device(0, "Light 1", "Light", activators); | ||
Device d2 = new Device(0, "Light 2", "Light", activators); | ||
Device d3 = new Device(0, "lock 1", "Lock", a2); | ||
ArrayList<Device> devices = new ArrayList<>(); | ||
devices.add(d1); | ||
devices.add(d2); | ||
devices.add(d3); | ||
|
||
// add header data | ||
/* | ||
for (Device d : devices) { | ||
if (!listDataHeader.contains(d.getType())) { | ||
listDataHeader.add(d.getType()); | ||
listDataChild.put(d.getType(), new ArrayList<Device>()); | ||
} | ||
//find corresponding header for the child | ||
listDataChild.get(d.getType()).add(d); | ||
}*/ | ||
// listAdapter.notifyDataSetChanged(); | ||
return null; | ||
} | ||
} |
Oops, something went wrong.