From a0f05e4a2f22a5b43b305634e539411212b4b847 Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Thu, 7 Jan 2021 19:04:40 +0100 Subject: [PATCH 1/3] improved documentation --- APED/app/src/main/assets/defaultConfig.json | 2 +- .../java/com/example/aped/MainActivity.java | 17 ++++++++--------- .../aped/communication/Communicator.java | 10 +++++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/APED/app/src/main/assets/defaultConfig.json b/APED/app/src/main/assets/defaultConfig.json index 9816475..9285101 100644 --- a/APED/app/src/main/assets/defaultConfig.json +++ b/APED/app/src/main/assets/defaultConfig.json @@ -1,5 +1,5 @@ { - "address": "192.168.2.203", + "address": "192.168.1.100", "port" : 8080, "favorites" : [ ] } \ No newline at end of file diff --git a/APED/app/src/main/java/com/example/aped/MainActivity.java b/APED/app/src/main/java/com/example/aped/MainActivity.java index 52ff8bc..b9bc7d5 100644 --- a/APED/app/src/main/java/com/example/aped/MainActivity.java +++ b/APED/app/src/main/java/com/example/aped/MainActivity.java @@ -2,7 +2,6 @@ package com.example.aped; import android.Manifest; import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -293,8 +292,8 @@ public class MainActivity extends AppCompatActivity { } /** - * paul - * @param xmlFile + * Method to set the config.xml to a default. + * @param xmlFile the config.xml file */ private void setDefaultXML(final File xmlFile) { try { @@ -307,23 +306,23 @@ public class MainActivity extends AppCompatActivity { fileOutputStream.write(buffer); fileOutputStream.close(); } catch (Exception e) { - Log.e("MainActivity", "error while transferring the " - + "default.xml into the config.xml: " + e.getMessage()); + Log.e("MainActivity", "error while transferring" + + "a default config: " + e.getMessage()); } } /** - * paul - * @param xmlFile + * Method to set the config.json to a default. + * @param jsonFile the config.json file */ - private void setDefaultConfig(final File xmlFile) { + private void setDefaultConfig(final File jsonFile) { try { InputStream inputStream = getAssets().open( "defaultConfig.json"); byte[] buffer = new byte[inputStream.available()]; inputStream.read(buffer); inputStream.close(); - FileOutputStream fileOutputStream = new FileOutputStream(xmlFile); + FileOutputStream fileOutputStream = new FileOutputStream(jsonFile); fileOutputStream.write(buffer); fileOutputStream.close(); } catch (Exception e) { diff --git a/APED/app/src/main/java/com/example/aped/communication/Communicator.java b/APED/app/src/main/java/com/example/aped/communication/Communicator.java index 208281c..f2bec72 100644 --- a/APED/app/src/main/java/com/example/aped/communication/Communicator.java +++ b/APED/app/src/main/java/com/example/aped/communication/Communicator.java @@ -163,9 +163,9 @@ public class Communicator { } /** - * paul - * @param error - * @param method + * Method for handling various {@link VolleyError}. + * @param error the {@link VolleyError} + * @param method the name of the method where the error occurred */ private void handleError(final VolleyError error, final String method) { if (error instanceof ServerError) { @@ -181,6 +181,10 @@ public class Communicator { } } + /** + * Method for making a custom toast message for serious {@link VolleyError}. + * @param message the message to be displayed in the toast + */ private void makeToast(final String message) { Toast toast = new Toast(mainActivity); View toastView = mainActivity.getLayoutInflater().inflate(R.layout. From c94331eeaf5d9ace2e4726b5197bf550e61cafed Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Thu, 7 Jan 2021 19:15:33 +0100 Subject: [PATCH 2/3] added current view variable to configurations --- APED/app/src/main/assets/defaultConfig.json | 1 + .../aped/utils/ConfigurationHandler.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/APED/app/src/main/assets/defaultConfig.json b/APED/app/src/main/assets/defaultConfig.json index 9285101..a3f1800 100644 --- a/APED/app/src/main/assets/defaultConfig.json +++ b/APED/app/src/main/assets/defaultConfig.json @@ -1,5 +1,6 @@ { "address": "192.168.1.100", "port" : 8080, + "currentView" : "", "favorites" : [ ] } \ No newline at end of file diff --git a/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java b/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java index c1eac72..9c89348 100644 --- a/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java +++ b/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java @@ -117,6 +117,18 @@ public class ConfigurationHandler implements IFAVORITES { return deviceName; } + //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + public String getCurrentView() { + return configurations.getCurrentView(); + } + + //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + public String setCurrentView(String viewName) { + configurations.setCurrentView(viewName); + writeJsonFile(); + return getCurrentView(); + } + //endregion //region private methods @@ -136,6 +148,7 @@ public class ConfigurationHandler implements IFAVORITES { JSONObject jsonObject = new JSONObject(jsonData); configurations.setAddress(jsonObject.getString("address")); configurations.setPort(jsonObject.getInt("port")); + configurations.setCurrentView(jsonObject.getString("currentView")); List favoriteNames = new ArrayList<>(); JSONArray favorites = jsonObject.getJSONArray("favorites"); for (int i = 0; i < favorites.length(); i++) { @@ -192,6 +205,19 @@ public class ConfigurationHandler implements IFAVORITES { /** The names of the favorite devices. **/ private List favoriteNames = new ArrayList<>(); + //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + public String getCurrentView() { + return currentView; + } + + //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + public void setCurrentView(String currentView) { + this.currentView = currentView; + } + + /** The name of the current view. **/ + private String currentView = ""; + /** * Getter for the address variable. * @return the address of the raspberry @@ -254,6 +280,7 @@ public class ConfigurationHandler implements IFAVORITES { return "{\n" + "\t\"address\":\"" + address + "\",\n" + "\t\"port\":\"" + port + "\",\n" + + "\t\"currentView\":\"" + currentView + "\",\n" + "\t\"favorites\":" + favoriteNamesString.toString() + "\n" + "}"; } From 0faf25f00b8957d307c1858acbceceeaa8cd7bf0 Mon Sep 17 00:00:00 2001 From: paul-loedige Date: Thu, 7 Jan 2021 19:24:07 +0100 Subject: [PATCH 3/3] added documentation --- .../aped/utils/ConfigurationHandler.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java b/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java index 9c89348..cf8e85d 100644 --- a/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java +++ b/APED/app/src/main/java/com/example/aped/utils/ConfigurationHandler.java @@ -117,13 +117,20 @@ public class ConfigurationHandler implements IFAVORITES { return deviceName; } - //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + /** + * Method to get the name of the current view. + * @return the name of the current view + */ public String getCurrentView() { return configurations.getCurrentView(); } - //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc - public String setCurrentView(String viewName) { + /** + * Method to set the name of the current view. + * @param viewName the name to be set + * @return the name that has been set + */ + public String setCurrentView(final String viewName) { configurations.setCurrentView(viewName); writeJsonFile(); return getCurrentView(); @@ -205,14 +212,20 @@ public class ConfigurationHandler implements IFAVORITES { /** The names of the favorite devices. **/ private List favoriteNames = new ArrayList<>(); - //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + /** + * Getter for currentView. + * @return the name of the current view + */ public String getCurrentView() { return currentView; } - //cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc - public void setCurrentView(String currentView) { - this.currentView = currentView; + /** + * Setter for currentView. + * @param pCurrentView the name of the current view + */ + public void setCurrentView(final String pCurrentView) { + this.currentView = pCurrentView; } /** The name of the current view. **/