Skip to content

Commit

Permalink
Merge pull request #8 from RUGSoftEng/merge_gui_communication
Browse files Browse the repository at this point in the history
Release 0.2
Needs a proper OOP solution for encoding types,fragment class needs refactoring.
  • Loading branch information
Luc van den Brand authored Mar 25, 2017
2 parents 5fb4a62 + fdce51b commit eab2c93
Show file tree
Hide file tree
Showing 59 changed files with 930 additions and 2,804 deletions.
4 changes: 4 additions & 0 deletions Hestia/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
Expand All @@ -27,4 +28,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:25.2.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.android.volley:volley:1.0.0'
}
14 changes: 8 additions & 6 deletions Hestia/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rugged.application.hestia">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PeripheralListActivity">
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".LoginActivity"
android:screenOrientation="locked">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PeripheralActivity">
<activity android:name=".PeripheralListActivity"
android:screenOrientation="locked">

</activity>
</application>

Expand Down
Binary file added Hestia/app/src/main/ic_drawer-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hestia/app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hestia/app/src/main/ic_light-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hestia/app/src/main/ic_lock-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Hestia/app/src/main/java/com/rugged/application/hestia/Device.java
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;
}
}
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();
}
}
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;
}
}
}
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;
}
}
Loading

0 comments on commit eab2c93

Please sign in to comment.