merged remote
This commit is contained in:
commit
827669a92e
@ -31,7 +31,7 @@ android {
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.3.0-beta01'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.2.2'
|
||||
implementation 'androidx.navigation:navigation-ui:2.2.2'
|
||||
|
@ -40,18 +40,26 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
/** permission code for the storage permisson.*/
|
||||
private final int STORAGE_PERMISSION_CODE = 42;
|
||||
/** was soll angezeigt werden in Navigation.*/
|
||||
private static final int STORAGE_PERMISSION_CODE = 42;
|
||||
|
||||
/** What should be displayed in navigation.*/
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
/** zur Verwendung von xml anstatt der direkten Einbindung.*/
|
||||
public IXML xml;
|
||||
/** zur Verwendung von uebergabe anstatt der direkten Einbindung.*/
|
||||
public Communicator uebergabe;
|
||||
|
||||
/** To use xml instead of direct inclusion.*/
|
||||
private IXML xml;
|
||||
|
||||
/** To use delivery instead of direct inclusion.*/
|
||||
private Communicator delivery;
|
||||
|
||||
/** Handler for the custom user configurations. **/
|
||||
public ConfigurationHandler configurationHandler;
|
||||
/** zur Verwendung von favorite anstatt der direkten Einbindung.*/
|
||||
public IFAVORITES favorite;
|
||||
private ConfigurationHandler configurationHandler;
|
||||
|
||||
/** To use favorite instead of direct inclusion.*/
|
||||
private IFAVORITES favorite;
|
||||
|
||||
/**
|
||||
* On create method of the main activity.
|
||||
* Sets various displays and start settings.
|
||||
* @param savedInstanceState
|
||||
*/
|
||||
@Override
|
||||
@ -61,20 +69,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
ensurePermissions();
|
||||
setupConfigs();
|
||||
favorite = configurationHandler;
|
||||
uebergabe = new Communicator(configurationHandler.getAddress(),
|
||||
delivery = new Communicator(configurationHandler.getAddress(),
|
||||
configurationHandler.getPort(), this);
|
||||
uebergabe.downloadXML();
|
||||
delivery.downloadXML();
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.nav_all_IOs, R.id.nav_your_IOs,R.id.nav_plots)
|
||||
.setDrawerLayout(drawer)
|
||||
R.id.nav_all_IOs, R.id.nav_your_IOs).setDrawerLayout(drawer)
|
||||
.build();
|
||||
NavController navController = Navigation.findNavController(this,
|
||||
R.id.nav_host_fragment);
|
||||
@ -82,13 +88,22 @@ public class MainActivity extends AppCompatActivity {
|
||||
navController, mAppBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navigationView, navController);
|
||||
}
|
||||
/** Fügt Elemente zur Aktionsleiste hinzu, wenn diese vorhanden ist.*/
|
||||
|
||||
/**
|
||||
*Adds elements to the action bar if it exists.
|
||||
* @param menu
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
/**Navigation einrichten.*/
|
||||
|
||||
/**
|
||||
* Set up navigation.
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
NavController navController = Navigation.findNavController(this,
|
||||
@ -96,53 +111,46 @@ public class MainActivity extends AppCompatActivity {
|
||||
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
||||
|| super.onSupportNavigateUp();
|
||||
}
|
||||
/**was soll bei click auf den jeweiligen itembutton passieren.*/
|
||||
/**
|
||||
* What should happen when clicking on the respective itembutton.
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final @NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_set_IP:
|
||||
MaterialAlertDialogBuilder alert = new
|
||||
MaterialAlertDialogBuilder(MainActivity.this);
|
||||
//alert.setTitle(R.string.action_set_connection);
|
||||
View view2 = LayoutInflater.from(MainActivity.this).inflate(R.
|
||||
layout.alert_dialog_ip_pot_eingabe, null);
|
||||
EditText ipAdress = (EditText) view2.findViewById(R.id.
|
||||
editTextIp);
|
||||
layout.alert_dialog_ip_pot, null);
|
||||
EditText ipAdress = view2.findViewById(R.id.editTextIp);
|
||||
ipAdress.setText(configurationHandler.getAddress());
|
||||
EditText port = (EditText) view2.findViewById(R.id.
|
||||
editTextPort);
|
||||
EditText port = view2.findViewById(R.id.editTextPort);
|
||||
port.setText(String.valueOf(configurationHandler.getPort()));
|
||||
alert.setView(view2);
|
||||
alert.setPositiveButton("set",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog,
|
||||
final int which) {
|
||||
// Write your code here to execute after dialog
|
||||
configurationHandler.setAddress(ipAdress.
|
||||
getText().toString());
|
||||
configurationHandler.setPort(Integer.parseInt(
|
||||
port.getText().toString()));
|
||||
Toast.makeText(getApplicationContext(),
|
||||
configurationHandler.getAddress()
|
||||
+ ":" + configurationHandler.
|
||||
getPort() + " is set",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
uebergabe = new Communicator(
|
||||
configurationHandler.getAddress(),
|
||||
configurationHandler.getPort(),
|
||||
MainActivity.this);
|
||||
}
|
||||
(dialog, which) -> {
|
||||
configurationHandler.setAddress(ipAdress.getText()
|
||||
.toString());
|
||||
configurationHandler.setPort(Integer.parseInt(port
|
||||
.getText().toString()));
|
||||
Toast.makeText(getApplicationContext(),
|
||||
configurationHandler.getAddress()
|
||||
+ ":" + configurationHandler.
|
||||
getPort() + " is set",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
delivery = new Communicator(
|
||||
configurationHandler.getAddress(),
|
||||
configurationHandler.getPort(),
|
||||
MainActivity.this);
|
||||
});
|
||||
alert.setNegativeButton("exit",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog,
|
||||
final int which) {
|
||||
// Write your code here to execute after dialog
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"exit clicked",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
dialog.cancel();
|
||||
}
|
||||
(dialog, which) -> {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"exit clicked",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
dialog.cancel();
|
||||
});
|
||||
alert.show();
|
||||
break;
|
||||
@ -172,13 +180,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
break;
|
||||
|
||||
case R.id.action_download_xml:
|
||||
uebergabe.downloadXML();
|
||||
delivery.downloadXML();
|
||||
Toast.makeText(this, "Downloaded .xml",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case R.id.action_upload_xml:
|
||||
try {
|
||||
uebergabe.uploadXML();
|
||||
delivery.uploadXML();
|
||||
Toast.makeText(this, "Upload .xml executed",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, "Upload .xml failed",
|
||||
@ -282,6 +292,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* paul
|
||||
* @param xmlFile
|
||||
*/
|
||||
private void setDefaultXML(final File xmlFile) {
|
||||
try {
|
||||
InputStream inputStream = getAssets().open(
|
||||
@ -298,6 +312,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* paul
|
||||
* @param xmlFile
|
||||
*/
|
||||
private void setDefaultConfig(final File xmlFile) {
|
||||
try {
|
||||
InputStream inputStream = getAssets().open(
|
||||
@ -314,4 +332,69 @@ public class MainActivity extends AppCompatActivity {
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for favorite.
|
||||
* @return favorite get.
|
||||
*/
|
||||
public IFAVORITES getFavorite() {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for favorite.
|
||||
* @param pFavorite set.
|
||||
*/
|
||||
public void setFavorite(final IFAVORITES pFavorite) {
|
||||
this.favorite = pFavorite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for xml.
|
||||
* @return xml get.
|
||||
*/
|
||||
public IXML getXml() {
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for xml.
|
||||
* @param pXml set.
|
||||
*/
|
||||
public void setXml(final IXML pXml) {
|
||||
this.xml = pXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for delivery.
|
||||
* @return delivery get.
|
||||
*/
|
||||
public Communicator getDelivery() {
|
||||
return delivery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for delivery.
|
||||
* @param pDelivery set.
|
||||
*/
|
||||
public void setDelivery(final Communicator pDelivery) {
|
||||
this.delivery = pDelivery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter method for configurationHandler.
|
||||
* @return configurationHandler get.
|
||||
*/
|
||||
public ConfigurationHandler getConfigurationHandler() {
|
||||
return configurationHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter method for configurationHandler.
|
||||
* @param pConfigurationHandler set.
|
||||
*/
|
||||
public void setConfigurationHandler(final ConfigurationHandler
|
||||
pConfigurationHandler) {
|
||||
this.configurationHandler = pConfigurationHandler;
|
||||
}
|
||||
}
|
||||
|
@ -162,6 +162,11 @@ public class Communicator {
|
||||
requestQueue.add(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* paul
|
||||
* @param error
|
||||
* @param method
|
||||
*/
|
||||
private void handleError(final VolleyError error, final String method) {
|
||||
if (error instanceof ServerError) {
|
||||
Log.e("Communicator", "server error during " + method
|
||||
|
@ -14,20 +14,10 @@ import com.example.aped.ui.visualization.MainListViewAdapter;
|
||||
|
||||
|
||||
public class AllIOsFragment extends Fragment {
|
||||
/**
|
||||
* Einbinden der MainActivity.
|
||||
*/
|
||||
/** Include the MainActivity.*/
|
||||
private MainActivity mainActivity;
|
||||
/**
|
||||
* Genutzt für Signallampe.
|
||||
*/
|
||||
private int image;
|
||||
/**
|
||||
* Genutzt für Favoriten icons.
|
||||
*/
|
||||
private int favoriteImage;
|
||||
|
||||
/**
|
||||
* Compiling the data and calling up the AllIOs view.
|
||||
* @param inflater
|
||||
* @param container
|
||||
* @param savedInstanceState
|
||||
@ -41,12 +31,11 @@ public class AllIOsFragment extends Fragment {
|
||||
this.mainActivity = (MainActivity) getActivity();
|
||||
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
||||
false);
|
||||
ListView lv = (ListView) view.findViewById(R.id.idListView);
|
||||
ListView lv = view.findViewById(R.id.idListView);
|
||||
MainListViewAdapter mainListViewAdapter =
|
||||
new MainListViewAdapter(mainActivity, 0);
|
||||
lv.setAdapter(mainListViewAdapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,10 @@ import com.example.aped.R;
|
||||
import com.example.aped.ui.visualization.MainListViewAdapter;
|
||||
|
||||
public class FavoriteIOsFragment extends Fragment {
|
||||
/**
|
||||
* Einbinden der MainActivity.
|
||||
*/
|
||||
/** Include the MainActivity.*/
|
||||
private MainActivity mainActivity;
|
||||
/**
|
||||
*
|
||||
*Compiling the data and calling up the FavoriteIOs view.
|
||||
* @param inflater
|
||||
* @param container
|
||||
* @param savedInstanceState
|
||||
@ -27,15 +25,14 @@ public class FavoriteIOsFragment extends Fragment {
|
||||
*/
|
||||
public View onCreateView(final @NonNull LayoutInflater inflater,
|
||||
final ViewGroup container,
|
||||
final Bundle savedInstanceState) {
|
||||
final Bundle savedInstanceState) {
|
||||
this.mainActivity = (MainActivity) getActivity();
|
||||
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
||||
false);
|
||||
ListView lv = (ListView) view.findViewById(R.id.idListView);
|
||||
ListView lv = view.findViewById(R.id.idListView);
|
||||
MainListViewAdapter mainListViewAdapter =
|
||||
new MainListViewAdapter(mainActivity, 1);
|
||||
lv.setAdapter(mainListViewAdapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
@ -7,39 +7,26 @@ import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.android.volley.Response;
|
||||
import com.example.aped.MainActivity;
|
||||
import com.example.aped.R;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MainListViewAdapter extends BaseAdapter {
|
||||
/**
|
||||
* Einbinden der MainActivity.
|
||||
*/
|
||||
/** Include the MainActivity.*/
|
||||
private MainActivity mainActivity;
|
||||
/**
|
||||
* Welche ansicht gewählt wurde 0 für all IOs, 1 für favorite IOs.
|
||||
*/
|
||||
/** Which view was selected, 0 for all IOs, 1 for favorite IOs.*/
|
||||
private int favoriteMode;
|
||||
/**
|
||||
* Name des devices für den aktuellen durchlauf.
|
||||
*/
|
||||
/** Name of the device for the current run.*/
|
||||
private String deviceName;
|
||||
/**
|
||||
* Bild für Favorit oder nicht.
|
||||
*/
|
||||
/** Image for favorite or not.*/
|
||||
private int favoriteImage;
|
||||
/**
|
||||
* Liste der beim öffnen der Favoritenansicht bestehenden Favoriten.
|
||||
*/
|
||||
/** List of favorites existing when opening the favorites view.*/
|
||||
private List<String> favoritenList;
|
||||
|
||||
|
||||
/**
|
||||
* Transfer of data to MainListViewAdapter.
|
||||
* @param pMainActivity
|
||||
* @param pFavoriteMode
|
||||
*/
|
||||
@ -49,24 +36,27 @@ public class MainListViewAdapter extends BaseAdapter {
|
||||
this.favoriteMode = pFavoriteMode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Anzahl der Anzeigen
|
||||
* Set number of list elements.
|
||||
* @return devices number
|
||||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
int devices;
|
||||
if (favoriteMode == 0) {
|
||||
devices = mainActivity.xml.getDeviceNames().size();
|
||||
devices = mainActivity.getXml().getDeviceNames().size();
|
||||
} else {
|
||||
devices = mainActivity.favorite.getFavorites().size();
|
||||
favoritenList = new ArrayList<>(mainActivity.favorite.
|
||||
getFavorites());
|
||||
devices = mainActivity.getFavorite().getFavorites().size();
|
||||
favoritenList = new ArrayList<>(mainActivity.getFavorite()
|
||||
.getFavorites());
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to retrieve the data item associated.
|
||||
* With the specified position in the data set to get the corresponding
|
||||
* data of the specified location in the data collection.
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
@ -77,6 +67,8 @@ public class MainListViewAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* As for the getItemId it returns the corresponding item element ID.
|
||||
* The function returns a long item position value to the adapter.
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
@ -87,107 +79,68 @@ public class MainListViewAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Device name display and favorite button and data sharing for state
|
||||
* visitation.
|
||||
* @param i
|
||||
* @param view
|
||||
* @param pView
|
||||
* @param viewGroup
|
||||
* @return view
|
||||
*/
|
||||
@Override
|
||||
public View getView(final int i, View view,
|
||||
public View getView(final int i, final View pView,
|
||||
final ViewGroup viewGroup) {
|
||||
view = mainActivity.getLayoutInflater().inflate(R.layout.
|
||||
listview_layout, null);
|
||||
TextView textViewName = (TextView) view.findViewById(
|
||||
R.id.textName);
|
||||
LinearLayout linearLayoutPin = (LinearLayout) view.findViewById(
|
||||
R.id.idLinearLayoutPins);
|
||||
ImageView buttonViewFavoriten = (ImageView) view.findViewById(
|
||||
R.id.imageButtonFavoriten);
|
||||
View view = mainActivity.getLayoutInflater().inflate(R.layout
|
||||
.listview_layout, null);
|
||||
TextView textViewName = view.findViewById(R.id.textName);
|
||||
LinearLayout linearLayoutPin = view.findViewById(R.id
|
||||
.idLinearLayoutPins);
|
||||
ImageView buttonViewFavoriten = view.findViewById(R.id
|
||||
.imageButtonFavoriten);
|
||||
if (favoriteMode == 0) {
|
||||
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
||||
deviceName = mainActivity.getXml().getDeviceNames().get(i);
|
||||
} else {
|
||||
deviceName = mainActivity.favorite.getFavorites().get(i);
|
||||
deviceName = mainActivity.getFavorite().getFavorites().get(i);
|
||||
}
|
||||
|
||||
if (mainActivity.favorite.getFavorites().contains(
|
||||
deviceName)) {
|
||||
if (mainActivity.getFavorite().getFavorites().contains(deviceName)) {
|
||||
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||
} else {
|
||||
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||
}
|
||||
|
||||
buttonViewFavoriten.setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
|
||||
if (favoriteMode == 0) {
|
||||
deviceName = mainActivity.xml.getDeviceNames().
|
||||
get(i);
|
||||
} else {
|
||||
List<String> test = favoritenList;
|
||||
deviceName = favoritenList.get(i);
|
||||
}
|
||||
if (mainActivity.favorite.getFavorites().contains(
|
||||
deviceName)) {
|
||||
mainActivity.favorite.removeFavorite(
|
||||
deviceName);
|
||||
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||
buttonViewFavoriten.setImageResource(
|
||||
favoriteImage);
|
||||
} else {
|
||||
mainActivity.favorite.addFavorite(
|
||||
deviceName);
|
||||
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||
buttonViewFavoriten.setImageResource(
|
||||
favoriteImage);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mainActivity.uebergabe.read(deviceName,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(final JSONObject response) {
|
||||
if (favoriteMode == 0) {
|
||||
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
||||
} else {
|
||||
deviceName = mainActivity.favorite.getFavorites().get(i);
|
||||
}
|
||||
try {
|
||||
JSONObject state = response.getJSONObject("state");
|
||||
List<String> pinValues = new ArrayList<>();
|
||||
for (String pinName: ((List<String>) mainActivity.xml.
|
||||
getPort(deviceName).
|
||||
get("pins"))) {
|
||||
pinValues.add(state.getString(pinName));
|
||||
}
|
||||
PinView pinView = new PinView(mainActivity, deviceName,
|
||||
pinValues);
|
||||
for (int j = 0; j < ((List<String>) mainActivity.xml.
|
||||
getPort(deviceName).
|
||||
get("pins")).size(); j++) {
|
||||
linearLayoutPin.addView(pinView.getView(j));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
// Richtigen log erstellen
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
buttonViewFavoriten.setOnClickListener(view1 -> {
|
||||
if (favoriteMode == 0) {
|
||||
deviceName = mainActivity.getXml().getDeviceNames().get(i);
|
||||
} else {
|
||||
deviceName = favoritenList.get(i);
|
||||
}
|
||||
if (mainActivity.getFavorite().getFavorites()
|
||||
.contains(deviceName)) { mainActivity.getFavorite()
|
||||
.removeFavorite(deviceName);
|
||||
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||
buttonViewFavoriten.setImageResource(favoriteImage);
|
||||
} else {
|
||||
mainActivity.getFavorite().addFavorite(deviceName);
|
||||
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||
buttonViewFavoriten.setImageResource(favoriteImage);
|
||||
}
|
||||
});
|
||||
PinView pinView = new PinView(mainActivity, deviceName);
|
||||
for (int j = 0; j < ((List<String>) mainActivity.getXml()
|
||||
.getPort(deviceName).get("pins")).size(); j++) {
|
||||
linearLayoutPin.addView(pinView.getView(j));
|
||||
}
|
||||
String name = null;
|
||||
switch ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||
switch ((mainActivity.getXml().getPort(deviceName)).get("protocol").
|
||||
toString()) {
|
||||
case "PWM":
|
||||
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||
toString() + ": " + deviceName + " (" + (mainActivity.
|
||||
xml.getPort(deviceName)).get("frequency").toString()
|
||||
+ "Hz)");
|
||||
name = ((mainActivity.getXml().getPort(deviceName))
|
||||
.get("protocol").toString() + ": " + deviceName
|
||||
+ " (" + (mainActivity.getXml().getPort(deviceName))
|
||||
.get("frequency").toString() + "Hz)");
|
||||
break;
|
||||
default:
|
||||
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||
toString() + ": " + deviceName);
|
||||
name = ((mainActivity.getXml().getPort(deviceName)).
|
||||
get("protocol").toString() + ": " + deviceName);
|
||||
break;
|
||||
}
|
||||
textViewName.setText(name);
|
||||
|
@ -1,139 +1,174 @@
|
||||
package com.example.aped.ui.visualization;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import com.android.volley.Response;
|
||||
import com.example.aped.MainActivity;
|
||||
import com.example.aped.R;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.slider.RangeSlider;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PinView {
|
||||
/** Include the MainActivity.*/
|
||||
private MainActivity mainActivity;
|
||||
|
||||
/** Image for state.*/
|
||||
private int image;
|
||||
private List<String> pinValues;
|
||||
/** Values of the pins.*/
|
||||
private List<String> pinValues = new ArrayList<>();
|
||||
/** Device name.*/
|
||||
private String deviceName;
|
||||
|
||||
|
||||
public PinView(MainActivity pMainActivity,String pDevice, List<String> pPinValues){
|
||||
/**
|
||||
* Transfer of data to PinView.
|
||||
* @param pMainActivity
|
||||
* @param pDeviceName
|
||||
*/
|
||||
public PinView(final MainActivity pMainActivity, final String pDeviceName) {
|
||||
this.mainActivity = pMainActivity;
|
||||
this.deviceName = pDevice;
|
||||
this.pinValues = pPinValues;
|
||||
this.deviceName = pDeviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processing of the data in displayed texts of the pins frequencies and
|
||||
* dutycycle as well as the status lamps.
|
||||
* @param i
|
||||
* @return view
|
||||
*/
|
||||
public View getView(final int i) {
|
||||
View view = mainActivity.getLayoutInflater().inflate(R.layout.pin_listview_layout,
|
||||
null);
|
||||
ImageView imageView = (ImageView) view.findViewById(
|
||||
R.id.images);
|
||||
TextView textViewPin = (TextView) view.findViewById(
|
||||
R.id.textPin);
|
||||
|
||||
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View view) {
|
||||
if((mainActivity.xml.getPort(deviceName)).get("protocol").toString().equals("DO")) {
|
||||
try {// Werte erst aktualisieren
|
||||
String setState = null;
|
||||
if(pinValues.get(i).equals("0")) {
|
||||
setState = "{\"output\": \"1\"}";
|
||||
}else{
|
||||
setState = "{\"output\": \"0\"}";
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject(setState);
|
||||
mainActivity.uebergabe.write(deviceName, jsonObject, new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
if (!jsonObject.equals(response)) {
|
||||
// Fehler
|
||||
}
|
||||
switch (response.getInt("output")){
|
||||
case 1:
|
||||
image = R.drawable.green_signal;
|
||||
break;
|
||||
case 0:
|
||||
image = R.drawable.red_signal;
|
||||
break;
|
||||
default:
|
||||
image = R.drawable.off_signal;
|
||||
break;
|
||||
}
|
||||
imageView.setImageResource(image);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}else{
|
||||
Toast.makeText(mainActivity, deviceName
|
||||
+ " is not an output " ,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
mainActivity.uebergabe.read(deviceName,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(final JSONObject response) {
|
||||
try {
|
||||
JSONObject state = response.getJSONObject("state");
|
||||
//List<String> pinValues = new ArrayList<>();
|
||||
pinValues.clear();
|
||||
for(String pinName: ((List<String>)mainActivity.xml.
|
||||
getPort(deviceName).
|
||||
get("pins"))){
|
||||
pinValues.add(state.getString(pinName));
|
||||
}
|
||||
switch (pinValues.get(i)){
|
||||
case "1":
|
||||
image=R.drawable.green_signal;
|
||||
break;
|
||||
case "0":
|
||||
image=R.drawable.red_signal;
|
||||
break;
|
||||
default:
|
||||
image=R.drawable.off_signal;
|
||||
break;
|
||||
}
|
||||
imageView.setImageResource(image);
|
||||
|
||||
} catch (JSONException e) {
|
||||
// Richtigen log erstellen
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
View view = mainActivity.getLayoutInflater().inflate(R.layout
|
||||
.pin_listview_layout, null);
|
||||
TextView textViewPin = view.findViewById(R.id.textPin);
|
||||
textViewPin.setText(((List<String>) (mainActivity.getXml().
|
||||
getPort(deviceName)).get("pins")).get(i));
|
||||
mainActivity.getDelivery().read(deviceName, response -> {
|
||||
displayLamp(response, view, i);
|
||||
if ((mainActivity.getXml().getPort(deviceName)).get("protocol")
|
||||
.toString().equals("PWM")) {
|
||||
textViewPin.setText(Html.fromHtml(((List<String>)
|
||||
(mainActivity.getXml().getPort(deviceName)).get("pins"))
|
||||
.get(i) + " <b> (DC: " + pinValues.get(i) + "%) </b>"
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
switch (pinValues.get(i)){
|
||||
case "1":
|
||||
image=R.drawable.green_signal;
|
||||
break;
|
||||
case "0":
|
||||
image=R.drawable.red_signal;
|
||||
break;
|
||||
default:
|
||||
image=R.drawable.off_signal;
|
||||
break;
|
||||
}
|
||||
imageView.setImageResource(image);
|
||||
view.setOnClickListener(view1 -> {
|
||||
switch ((mainActivity.getXml().getPort(deviceName)).get("protocol")
|
||||
.toString()) {
|
||||
case "DO":
|
||||
try {
|
||||
String setState;
|
||||
if (pinValues.get(i).equals("0")) {
|
||||
setState = "\"1\"";
|
||||
} else {
|
||||
setState = "\"0\"";
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject(
|
||||
"{\"output\":{\"" + ((List<String>) (mainActivity
|
||||
.getXml().getPort(deviceName)).get("pins"))
|
||||
.get(i) + "\":" + setState + "}}");
|
||||
mainActivity.getDelivery().write(deviceName,
|
||||
jsonObject, response -> displayLamp(response,
|
||||
view1, i));
|
||||
} catch (JSONException e) {
|
||||
Log.e("PinView",
|
||||
"Error while generating JSON object: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "PWM":
|
||||
MaterialAlertDialogBuilder alert =
|
||||
new MaterialAlertDialogBuilder(mainActivity);
|
||||
View viewAlert = mainActivity.getLayoutInflater()
|
||||
.inflate(R.layout.alert_dialog_duty, null);
|
||||
RangeSlider readDuty = viewAlert.findViewById(R.id
|
||||
.range_slider_duty);
|
||||
readDuty.setValues(Float.valueOf(pinValues.get(i)
|
||||
.equals("None") ? "0" : pinValues.get(i))
|
||||
);
|
||||
alert.setView(viewAlert);
|
||||
alert.setPositiveButton("set", (dialog, which) -> {
|
||||
int value = readDuty.getValues().get(0).intValue();
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(
|
||||
"{\"output\":{\"" + ((List<String>)
|
||||
(mainActivity.getXml().getPort(deviceName))
|
||||
.get("pins")).get(i) + "\":\"" + value
|
||||
+ "\"}}");
|
||||
mainActivity.getDelivery().write(deviceName,
|
||||
jsonObject, response -> {
|
||||
displayLamp(response, view1, i);
|
||||
textViewPin.setText(Html.fromHtml((
|
||||
(List<String>) (mainActivity.getXml()
|
||||
.getPort(deviceName)).get("pins")).get(i)
|
||||
+ " <b> (DC: " + pinValues.get(i)
|
||||
+ "%) </b>"));
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
Log.e("PinView",
|
||||
"Error while generating JSON object: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
dialog.cancel();
|
||||
});
|
||||
alert.setNegativeButton("exit", (dialog,
|
||||
which) -> dialog.cancel());
|
||||
alert.show();
|
||||
break;
|
||||
default:
|
||||
Toast.makeText(mainActivity, deviceName
|
||||
+ " is not an output ", Toast.LENGTH_SHORT).
|
||||
show();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i));
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for the selection of the lamps.
|
||||
* @param response
|
||||
* @param view
|
||||
* @param i
|
||||
*/
|
||||
private void displayLamp(final JSONObject response, final View view,
|
||||
final int i) {
|
||||
ImageView imageView = view.findViewById(R.id.images);
|
||||
try {
|
||||
JSONObject state = response.getJSONObject("state");
|
||||
if (pinValues.size() != 0) {
|
||||
pinValues.clear();
|
||||
}
|
||||
for (String pinName: ((List<String>) mainActivity.getXml()
|
||||
.getPort(deviceName).get("pins"))) {
|
||||
pinValues.add(state.getString(pinName));
|
||||
}
|
||||
switch (pinValues.get(i)) {
|
||||
case "1":
|
||||
image = R.drawable.green_signal;
|
||||
break;
|
||||
case "0":
|
||||
image = R.drawable.red_signal;
|
||||
break;
|
||||
case "100":
|
||||
image = R.drawable.green_signal;
|
||||
break;
|
||||
default:
|
||||
image = R.drawable.off_signal;
|
||||
break;
|
||||
}
|
||||
imageView.setImageResource(image);
|
||||
} catch (JSONException e) {
|
||||
Log.e("PinView", "Error while generating JSON object: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
package com.example.aped.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* implementation for the favorites interface
|
||||
* does not use persistent storage!
|
||||
*/
|
||||
public class TestFavorites implements IFAVORITES {
|
||||
|
||||
/**
|
||||
* Liste der favoriten.
|
||||
*/
|
||||
private List<String> favorites = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getFavorites() {
|
||||
return favorites;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deviceName the name of the device to be added
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String addFavorite(final String deviceName) {
|
||||
if (!favorites.contains(deviceName)) {
|
||||
favorites.add(deviceName);
|
||||
}
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deviceName the name of the device to be removed
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String removeFavorite(final String deviceName) {
|
||||
if (favorites.contains(deviceName)) {
|
||||
favorites.remove(deviceName);
|
||||
}
|
||||
return deviceName;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.example.aped.utils;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
public class TestXML implements IXML {
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> getDeviceNames() {
|
||||
List<String> returnList = new ArrayList<>();
|
||||
returnList.add("stoff");
|
||||
returnList.add("schnaps");
|
||||
returnList.add("whatever");
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deviceName the name of the relevant device
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Dictionary<String, Object> getPort(final String deviceName) {
|
||||
Dictionary<String, Object> returnDict = new Hashtable<>();
|
||||
returnDict.put("protocol", "DI");
|
||||
Dictionary<String, Object> pins = new Hashtable<>();
|
||||
pins.put("GPIO2", true);
|
||||
pins.put("GPIO3", false);
|
||||
returnDict.put("pins", pins);
|
||||
return returnDict;
|
||||
}
|
||||
}
|
31
APED/app/src/main/res/layout/alert_dialog_duty.xml
Normal file
31
APED/app/src/main/res/layout/alert_dialog_duty.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/volleyToastContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:ignore="MissingClass">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewSlider"
|
||||
android:text="set the duty cycle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_margin="5dp"
|
||||
android:textSize="20dp"/>
|
||||
|
||||
|
||||
<com.google.android.material.slider.RangeSlider
|
||||
android:id="@+id/range_slider_duty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/textViewSlider"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="100"
|
||||
android:stepSize="5"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,8 +1,20 @@
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item name="ic_menu_camera" type="drawable">@android:drawable/ic_menu_camera</item>
|
||||
<item name="ic_menu_gallery" type="drawable">@android:drawable/ic_menu_gallery</item>
|
||||
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
|
||||
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
|
||||
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
|
||||
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
|
||||
<item name="ic_menu_camera" type="drawable">
|
||||
@android:drawable/ic_menu_camera
|
||||
</item>
|
||||
<item name="ic_menu_gallery" type="drawable">
|
||||
@android:drawable/ic_menu_gallery
|
||||
</item>
|
||||
<item name="ic_menu_slideshow" type="drawable">
|
||||
@android:drawable/ic_menu_slideshow
|
||||
</item>
|
||||
<item name="ic_menu_manage" type="drawable">
|
||||
@android:drawable/ic_menu_manage
|
||||
</item>
|
||||
<item name="ic_menu_share" type="drawable">
|
||||
@android:drawable/ic_menu_share
|
||||
</item>
|
||||
<item name="ic_menu_send" type="drawable">
|
||||
@android:drawable/ic_menu_send
|
||||
</item>
|
||||
</resources>
|
@ -1,6 +1,7 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.APED" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<style name="Theme.APED"
|
||||
parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/red</item>
|
||||
<item name="colorPrimaryVariant">@color/grey</item>
|
||||
@ -10,7 +11,8 @@
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||
<item name="android:statusBarColor" tools:targetApi="l">
|
||||
?attr/colorPrimaryVariant</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
@ -19,7 +21,9 @@
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.APED.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
<style name="Theme.APED.AppBarOverlay"
|
||||
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="Theme.APED.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
<style name="Theme.APED.PopupOverlay"
|
||||
parent="ThemeOverlay.AppCompat.Light" />
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user