-
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 #3 from RUGSoftEng/development
Release 0.1 Problems regarding structure, cleanliness, and documentation.
- Loading branch information
Showing
48 changed files
with
3,381 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
/.idea |
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 @@ | ||
/build |
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,30 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "com.rugged.application.hestia" | ||
minSdkVersion 15 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.2.0' | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:recyclerview-v7:25.2.0' | ||
} |
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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/Feiko/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
26 changes: 26 additions & 0 deletions
26
Hestia/app/src/androidTest/java/com/rugged/application/hestia/ExampleInstrumentedTest.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,26 @@ | ||
package com.rugged.application.hestia; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.rugged.application.hestia", appContext.getPackageName()); | ||
} | ||
} |
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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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" /> | ||
|
||
<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"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".PeripheralActivity"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
68 changes: 68 additions & 0 deletions
68
Hestia/app/src/main/java/com/rugged/application/hestia/Client.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,68 @@ | ||
package com.rugged.application.hestia; /** | ||
* Currently we use BufferedReader for Input | ||
* and DataOutputStream for Output | ||
*/ | ||
|
||
import android.util.Log; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.net.Socket; | ||
import json.simple.*; | ||
|
||
public class Client { | ||
private static final String TAG = "Client"; | ||
|
||
private Socket clientSocket; | ||
private DataOutputStream outToServer; | ||
|
||
public Client(String address, Integer port) { | ||
this.openClientSocket(address, port); | ||
this.openOutToServerStream(); | ||
} | ||
|
||
private void openClientSocket(String address, Integer port) { | ||
try { | ||
this.clientSocket = new Socket(address, port); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void openOutToServerStream() { | ||
try { | ||
this.outToServer = new DataOutputStream(clientSocket.getOutputStream()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void sendActionRequest(Integer id, String action) { | ||
// Write JSON | ||
JSONObject jsonObj = new JSONObject(); | ||
// Stripping the text from the new-line separators is necessary to avoid | ||
// Strings line "abc...\n" -> the "\n" would be visible | ||
jsonObj.put("type", action); | ||
jsonObj.put("id", id); | ||
JSONObject jsonAction = new JSONObject(); | ||
jsonAction.put("action", jsonObj); | ||
|
||
this.writeJSONToServer(jsonAction); | ||
} | ||
|
||
private void writeJSONToServer(JSONObject jsonObj) { | ||
try { | ||
this.outToServer.writeBytes(jsonObj.toJSONString() + '\n'); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void closeClientSocket() { | ||
try { | ||
this.clientSocket.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Hestia/app/src/main/java/com/rugged/application/hestia/Peripheral.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,30 @@ | ||
package com.rugged.application.hestia; | ||
|
||
import java.util.UUID; | ||
|
||
public class Peripheral { | ||
private String type; | ||
private int id; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
Hestia/app/src/main/java/com/rugged/application/hestia/PeripheralActivity.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,25 @@ | ||
package com.rugged.application.hestia; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.v4.app.Fragment; | ||
|
||
import java.util.UUID; | ||
|
||
public class PeripheralActivity extends SingleFragmentActivity{ | ||
public static final String EXTRA_PERIPHERAl_ID = | ||
"com.rugged.application.hestia.peripheral_id"; | ||
|
||
public static Intent newIntent(Context packageContext, int peripheralId) { | ||
Intent intent = new Intent(packageContext, PeripheralActivity.class); | ||
intent.putExtra(EXTRA_PERIPHERAl_ID, peripheralId); | ||
return intent; | ||
} | ||
|
||
@Override | ||
protected Fragment createFragment() { | ||
return new PeripheralFragment(); | ||
} | ||
} | ||
|
||
|
80 changes: 80 additions & 0 deletions
80
Hestia/app/src/main/java/com/rugged/application/hestia/PeripheralFragment.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,80 @@ | ||
package com.rugged.application.hestia; | ||
|
||
import android.os.AsyncTask; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.text.Editable; | ||
import android.text.TextWatcher; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import java.util.UUID; | ||
|
||
//Fragment class taking care of a specific Peripheral | ||
public class PeripheralFragment extends Fragment { | ||
private Peripheral mPeripheral; | ||
//lock and unlock button | ||
private Button onButton; | ||
private Button offButton; | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
//receive the id from the PeripheralActivity | ||
int peripheralId = (int) getActivity().getIntent() | ||
.getSerializableExtra(PeripheralActivity.EXTRA_PERIPHERAl_ID); | ||
mPeripheral = PeripheralLab.get(getActivity()).getPeripheral(peripheralId); | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
View v = inflater.inflate(R.layout.fragment_peripheral, container, false); | ||
onButton = (Button)v.findViewById(R.id.on_button); | ||
offButton = (Button)v.findViewById(R.id.off_button); | ||
|
||
switch (mPeripheral.getType()) { | ||
case "Lock" : | ||
onButton.setText("Lock"); | ||
offButton.setText("Unlock"); | ||
break; | ||
case "Light" : | ||
onButton.setText("Light on"); | ||
offButton.setText("Light off"); | ||
break; | ||
default: | ||
onButton.setText("On"); | ||
offButton.setText("Off"); | ||
break; | ||
} | ||
|
||
onButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
new SendJSONFile().execute("172.20.10.2", "openLock"); | ||
} | ||
}); | ||
|
||
offButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
new SendJSONFile().execute("172.20.10.2", "closeLock"); | ||
|
||
} | ||
}); | ||
return v; | ||
} | ||
|
||
//Thread classes taking care of sending commands | ||
private class SendJSONFile extends AsyncTask<String,Void,Void> { | ||
@Override | ||
protected Void doInBackground(String... strings) { | ||
Client client = new Client("172.20.10.2", 8850); | ||
client.sendActionRequest(mPeripheral.getId(), "openLock"); | ||
client.closeClientSocket(); | ||
return null; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Hestia/app/src/main/java/com/rugged/application/hestia/PeripheralLab.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,52 @@ | ||
/* | ||
* This class takes care of the list of peripherals, it is a singleton class since the application | ||
* should take care of only one PeripheralList | ||
*/ | ||
|
||
package com.rugged.application.hestia; | ||
|
||
import android.content.Context; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PeripheralLab { | ||
private static PeripheralLab sPeripheralLab; | ||
private final static String TAG = "PeripheralLab"; | ||
|
||
private List<Peripheral> mPeripherals; | ||
|
||
public static PeripheralLab get(Context context) { | ||
if (sPeripheralLab == null) { | ||
sPeripheralLab = new PeripheralLab(context); | ||
} | ||
return sPeripheralLab; | ||
} | ||
|
||
private PeripheralLab(Context context) { | ||
mPeripherals = new ArrayList<>(); | ||
//set standard peripherals, is hardcoded for now | ||
Peripheral lock = new Peripheral(); | ||
lock.setType("Lock"); | ||
lock.setId(1); | ||
mPeripherals.add(lock); | ||
|
||
Peripheral light = new Peripheral(); | ||
light.setType("Light"); | ||
light.setId(2); | ||
mPeripherals.add(light); | ||
} | ||
|
||
public List<Peripheral> getPeripherals() { | ||
return mPeripherals; | ||
} | ||
|
||
public Peripheral getPeripheral(int id) { | ||
for (Peripheral p : mPeripherals) { | ||
|
||
if (p.getId() == id) { | ||
return p; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Hestia/app/src/main/java/com/rugged/application/hestia/PeripheralListActivity.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,10 @@ | ||
package com.rugged.application.hestia; | ||
|
||
import android.support.v4.app.Fragment; | ||
|
||
public class PeripheralListActivity extends SingleFragmentActivity{ | ||
@Override | ||
protected Fragment createFragment() { | ||
return new PeripheralListFragment(); | ||
} | ||
} |
Oops, something went wrong.