Merge branch 'master' of https://its-gitlab.init.hs-owl.de/mo_b_l/aped_app
This commit is contained in:
commit
bec40cb402
@ -37,6 +37,7 @@ dependencies {
|
|||||||
implementation 'androidx.navigation:navigation-ui:2.2.2'
|
implementation 'androidx.navigation:navigation-ui:2.2.2'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
|
||||||
|
implementation 'com.android.volley:volley:1.1.1'
|
||||||
testImplementation 'junit:junit:4.+'
|
testImplementation 'junit:junit:4.+'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
<!-- permission to read and write the XML file -->
|
<!-- permission to read and write the XML file -->
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<!-- permission to access send http requests -->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@ -11,7 +13,8 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.APED">
|
android:theme="@style/Theme.APED"
|
||||||
|
android:usesCleartextTraffic="true">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
@ -2,18 +2,15 @@ package com.example.aped;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.res.AssetManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.example.aped.communication.IIO;
|
import com.example.aped.communication.Communicator;
|
||||||
import com.example.aped.utils.ExternalStorageHandler;
|
import com.example.aped.utils.ExternalStorageHandler;
|
||||||
import com.example.aped.communication.TestIO;
|
|
||||||
import com.example.aped.utils.IFAVORITES;
|
import com.example.aped.utils.IFAVORITES;
|
||||||
import com.example.aped.utils.IXML;
|
import com.example.aped.utils.IXML;
|
||||||
import com.example.aped.utils.TestFavorites;
|
import com.example.aped.utils.TestFavorites;
|
||||||
@ -50,9 +47,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
/** was soll angezeigt werden in Navigation.*/
|
/** was soll angezeigt werden in Navigation.*/
|
||||||
private AppBarConfiguration mAppBarConfiguration;
|
private AppBarConfiguration mAppBarConfiguration;
|
||||||
/** zur Verwendung von xml anstatt der direkten Einbindung.*/
|
/** zur Verwendung von xml anstatt der direkten Einbindung.*/
|
||||||
public IXML xml = new TestXML();
|
public IXML xml;
|
||||||
/** zur Verwendung von uebergabe anstatt der direkten Einbindung.*/
|
/** zur Verwendung von uebergabe anstatt der direkten Einbindung.*/
|
||||||
public IIO uebergabe = new TestIO();
|
public Communicator uebergabe;
|
||||||
/** zur Verwendung von favorite anstatt der direkten Einbindung.*/
|
/** zur Verwendung von favorite anstatt der direkten Einbindung.*/
|
||||||
public IFAVORITES favorite = new TestFavorites();
|
public IFAVORITES favorite = new TestFavorites();
|
||||||
/** allgemeines.*/
|
/** allgemeines.*/
|
||||||
@ -63,6 +60,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
//checks that the permission to read and write the xml is granted
|
//checks that the permission to read and write the xml is granted
|
||||||
ensurePermissions();
|
ensurePermissions();
|
||||||
setXML();
|
setXML();
|
||||||
|
uebergabe = new Communicator("",8080,this);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
@ -110,16 +108,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.action_download_xml:
|
case R.id.action_download_xml:
|
||||||
if (uebergabe.downloadXML() == 0) {
|
|
||||||
Toast.makeText(this, "Downloaded .xml",
|
Toast.makeText(this, "Downloaded .xml",
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case R.id.action_upload_xml:
|
case R.id.action_upload_xml:
|
||||||
if (uebergabe.uploadXML(new File("")) == 0) {
|
|
||||||
Toast.makeText(this, "Upload .xml",
|
Toast.makeText(this, "Upload .xml",
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e("MainActivity", "unknown item: "
|
Log.e("MainActivity", "unknown item: "
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.example.aped.communication;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.volley.Request;
|
||||||
|
import com.android.volley.RequestQueue;
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.android.volley.VolleyError;
|
||||||
|
import com.android.volley.toolbox.JsonObjectRequest;
|
||||||
|
import com.android.volley.toolbox.StringRequest;
|
||||||
|
import com.android.volley.toolbox.Volley;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import kotlin.NotImplementedError;
|
||||||
|
|
||||||
|
public class Communicator{
|
||||||
|
private String address;
|
||||||
|
private int port;
|
||||||
|
private RequestQueue requestQueue;
|
||||||
|
|
||||||
|
public Communicator(String address, int port, Context context){
|
||||||
|
this.address = address;
|
||||||
|
this.port = port;
|
||||||
|
requestQueue = Volley.newRequestQueue(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(String deviceName, Response.Listener<JSONObject> responseListener) {
|
||||||
|
String requestString = "http://" + address + ":" + port + "/device/" + deviceName + "/";
|
||||||
|
JsonObjectRequest request = new JsonObjectRequest(
|
||||||
|
Request.Method.GET,
|
||||||
|
requestString,
|
||||||
|
null,
|
||||||
|
responseListener,
|
||||||
|
error -> Log.e("Communicator","Error during READ: " + error.getMessage())
|
||||||
|
);
|
||||||
|
requestQueue.add(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(String deviceName, JSONObject message, Response.Listener<JSONObject> responseListener) {
|
||||||
|
String requestString = "http://" + address + ":" + port + "/device/" + deviceName + "/";
|
||||||
|
JsonObjectRequest request = new JsonObjectRequest(
|
||||||
|
Request.Method.POST,
|
||||||
|
requestString,
|
||||||
|
message,
|
||||||
|
responseListener,
|
||||||
|
error -> {Log.e("Communicator", "Error during WRITE: " + error.getMessage()); error.printStackTrace();}
|
||||||
|
);
|
||||||
|
requestQueue.add(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void uploadXML(File xmlFile) {
|
||||||
|
throw new NotImplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void downloadXML() {
|
||||||
|
throw new NotImplementedError();
|
||||||
|
}
|
||||||
|
}
|
@ -1,34 +0,0 @@
|
|||||||
package com.example.aped.communication;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public interface IIO
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* reads a value from a device connected to the raspberry
|
|
||||||
* @param deviceName the name of the device to read from
|
|
||||||
* @return the value read
|
|
||||||
*/
|
|
||||||
String read(String deviceName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* writes a value to a device connected to the raspberry
|
|
||||||
* @param deviceName the name of the device to write to
|
|
||||||
* @param value the value to write to the device
|
|
||||||
* @return the value written
|
|
||||||
*/
|
|
||||||
String write(String deviceName, String value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* uploads the config.xml to the raspberry
|
|
||||||
* @param xmlFile the config.xml
|
|
||||||
* @return 0 if everything worked
|
|
||||||
*/
|
|
||||||
int uploadXML(File xmlFile);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* downloads the current config.xml from the raspberry
|
|
||||||
* @return 0 if everything worked
|
|
||||||
*/
|
|
||||||
int downloadXML();
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
package com.example.aped.communication;
|
|
||||||
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.example.aped.R;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class TestIO implements IIO {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String read(String deviceName) {
|
|
||||||
|
|
||||||
String Wert;
|
|
||||||
switch (deviceName) {
|
|
||||||
case "stoff":
|
|
||||||
Wert = "TRUE";
|
|
||||||
break;
|
|
||||||
case "schnaps":
|
|
||||||
Wert = "FALSE";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Wert="default";
|
|
||||||
}
|
|
||||||
return Wert;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String write(String deviceName, String value) {
|
|
||||||
return "TRUE";//Wenn erfolgreich gesendet
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int uploadXML(File xmlFile) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int downloadXML() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -71,14 +71,14 @@ public class AllIOsFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||||
if(mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i)).equals("TRUE")) {
|
/*if(mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i)).equals("TRUE")) {
|
||||||
image=R.drawable.green_signal;
|
image=R.drawable.green_signal;
|
||||||
}else if (mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i)).equals("FALSE")) {
|
}else if (mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i)).equals("FALSE")) {
|
||||||
image = R.drawable.red_signal;
|
image = R.drawable.red_signal;
|
||||||
}
|
}
|
||||||
else{
|
else{*/
|
||||||
image = R.drawable.off_signal;
|
image = R.drawable.off_signal;
|
||||||
}
|
//}
|
||||||
if (mainActivity.favorite.getFavorites().contains(mainActivity.xml.getDeviceNames().get(i))) {
|
if (mainActivity.favorite.getFavorites().contains(mainActivity.xml.getDeviceNames().get(i))) {
|
||||||
favorite_image = android.R.drawable.btn_star_big_on;
|
favorite_image = android.R.drawable.btn_star_big_on;
|
||||||
}else {
|
}else {
|
||||||
@ -120,7 +120,7 @@ public class AllIOsFragment extends Fragment {
|
|||||||
|
|
||||||
imageView.setImageResource(image);
|
imageView.setImageResource(image);
|
||||||
TextView_Name.setText(mainActivity.xml.getDeviceNames().get(i));
|
TextView_Name.setText(mainActivity.xml.getDeviceNames().get(i));
|
||||||
TextView_State.setText(mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i)));
|
//TextView_State.setText(mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i)));
|
||||||
ButtonView_Favoriten.setImageResource(favorite_image);
|
ButtonView_Favoriten.setImageResource(favorite_image);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user