weitere Code Conventions und auf Englisch übersetzt + Komentare
This commit is contained in:
parent
40bfeb64c0
commit
1630c2fe89
@ -2,7 +2,6 @@ package com.example.aped;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -40,17 +39,17 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
|||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
/** permission code for the storage permisson.*/
|
/** permission code for the storage permisson.*/
|
||||||
private final int STORAGE_PERMISSION_CODE = 42;
|
private static final int STORAGE_PERMISSION_CODE = 42;
|
||||||
/** was soll angezeigt werden in Navigation.*/
|
/** What should be displayed in navigation.*/
|
||||||
private AppBarConfiguration mAppBarConfiguration;
|
private AppBarConfiguration mAppBarConfiguration;
|
||||||
/** zur Verwendung von xml anstatt der direkten Einbindung.*/
|
/** To use xml instead of direct inclusion.*/
|
||||||
public IXML xml;
|
private IXML xml;
|
||||||
/** zur Verwendung von uebergabe anstatt der direkten Einbindung.*/
|
/** To use delivery instead of direct inclusion.*/
|
||||||
public Communicator delivery;
|
private Communicator delivery;
|
||||||
/** Handler for the custom user configurations. **/
|
/** Handler for the custom user configurations. **/
|
||||||
public ConfigurationHandler configurationHandler;
|
private ConfigurationHandler configurationHandler;
|
||||||
/** zur Verwendung von favorite anstatt der direkten Einbindung.*/
|
/** To use favorite instead of direct inclusion.*/
|
||||||
public IFAVORITES favorite;
|
private IFAVORITES favorite;
|
||||||
/**
|
/**
|
||||||
* @param savedInstanceState
|
* @param savedInstanceState
|
||||||
*/
|
*/
|
||||||
@ -82,13 +81,22 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
navController, mAppBarConfiguration);
|
navController, mAppBarConfiguration);
|
||||||
NavigationUI.setupWithNavController(navigationView, navController);
|
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
|
@Override
|
||||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.main, menu);
|
getMenuInflater().inflate(R.menu.main, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/**Navigation einrichten.*/
|
|
||||||
|
/**
|
||||||
|
* Set up navigation.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onSupportNavigateUp() {
|
public boolean onSupportNavigateUp() {
|
||||||
NavController navController = Navigation.findNavController(this,
|
NavController navController = Navigation.findNavController(this,
|
||||||
@ -96,32 +104,30 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
||||||
|| super.onSupportNavigateUp();
|
|| super.onSupportNavigateUp();
|
||||||
}
|
}
|
||||||
/**was soll bei click auf den jeweiligen itembutton passieren.*/
|
/**
|
||||||
|
* What should happen when clicking on the respective itembutton.
|
||||||
|
* @param item
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final @NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(final @NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_set_IP:
|
case R.id.action_set_IP:
|
||||||
MaterialAlertDialogBuilder alert = new
|
MaterialAlertDialogBuilder alert = new
|
||||||
MaterialAlertDialogBuilder(MainActivity.this);
|
MaterialAlertDialogBuilder(MainActivity.this);
|
||||||
//alert.setTitle(R.string.action_set_connection);
|
|
||||||
View view2 = LayoutInflater.from(MainActivity.this).inflate(R.
|
View view2 = LayoutInflater.from(MainActivity.this).inflate(R.
|
||||||
layout.alert_dialog_ip_pot, null);
|
layout.alert_dialog_ip_pot, null);
|
||||||
EditText ipAdress = (EditText) view2.findViewById(R.id.
|
EditText ipAdress = view2.findViewById(R.id.editTextIp);
|
||||||
editTextIp);
|
|
||||||
ipAdress.setText(configurationHandler.getAddress());
|
ipAdress.setText(configurationHandler.getAddress());
|
||||||
EditText port = (EditText) view2.findViewById(R.id.
|
EditText port = view2.findViewById(R.id.editTextPort);
|
||||||
editTextPort);
|
|
||||||
port.setText(String.valueOf(configurationHandler.getPort()));
|
port.setText(String.valueOf(configurationHandler.getPort()));
|
||||||
alert.setView(view2);
|
alert.setView(view2);
|
||||||
alert.setPositiveButton("set",
|
alert.setPositiveButton("set",
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> {
|
||||||
public void onClick(final DialogInterface dialog,
|
configurationHandler.setAddress(ipAdress.getText()
|
||||||
final int which) {
|
.toString());
|
||||||
// Write your code here to execute after dialog
|
configurationHandler.setPort(Integer.parseInt(port
|
||||||
configurationHandler.setAddress(ipAdress.
|
.getText().toString()));
|
||||||
getText().toString());
|
|
||||||
configurationHandler.setPort(Integer.parseInt(
|
|
||||||
port.getText().toString()));
|
|
||||||
Toast.makeText(getApplicationContext(),
|
Toast.makeText(getApplicationContext(),
|
||||||
configurationHandler.getAddress()
|
configurationHandler.getAddress()
|
||||||
+ ":" + configurationHandler.
|
+ ":" + configurationHandler.
|
||||||
@ -131,18 +137,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
configurationHandler.getAddress(),
|
configurationHandler.getAddress(),
|
||||||
configurationHandler.getPort(),
|
configurationHandler.getPort(),
|
||||||
MainActivity.this);
|
MainActivity.this);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
alert.setNegativeButton("exit",
|
alert.setNegativeButton("exit",
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> {
|
||||||
public void onClick(final DialogInterface dialog,
|
|
||||||
final int which) {
|
|
||||||
// Write your code here to execute after dialog
|
|
||||||
Toast.makeText(getApplicationContext(),
|
Toast.makeText(getApplicationContext(),
|
||||||
"exit clicked",
|
"exit clicked",
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
alert.show();
|
alert.show();
|
||||||
break;
|
break;
|
||||||
@ -316,4 +317,69 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
+ e.getMessage());
|
+ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ public class AllIOsFragment extends Fragment {
|
|||||||
private MainActivity mainActivity;
|
private MainActivity mainActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Compiling the data and calling up the AllIOs view.
|
||||||
* @param inflater
|
* @param inflater
|
||||||
* @param container
|
* @param container
|
||||||
* @param savedInstanceState
|
* @param savedInstanceState
|
||||||
@ -33,7 +34,7 @@ public class AllIOsFragment extends Fragment {
|
|||||||
this.mainActivity = (MainActivity) getActivity();
|
this.mainActivity = (MainActivity) getActivity();
|
||||||
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
||||||
false);
|
false);
|
||||||
ListView lv = (ListView) view.findViewById(R.id.idListView);
|
ListView lv = view.findViewById(R.id.idListView);
|
||||||
MainListViewAdapter mainListViewAdapter =
|
MainListViewAdapter mainListViewAdapter =
|
||||||
new MainListViewAdapter(mainActivity, 0);
|
new MainListViewAdapter(mainActivity, 0);
|
||||||
lv.setAdapter(mainListViewAdapter);
|
lv.setAdapter(mainListViewAdapter);
|
||||||
|
@ -19,7 +19,7 @@ public class FavoriteIOsFragment extends Fragment {
|
|||||||
*/
|
*/
|
||||||
private MainActivity mainActivity;
|
private MainActivity mainActivity;
|
||||||
/**
|
/**
|
||||||
*
|
*Compiling the data and calling up the FavoriteIOs view.
|
||||||
* @param inflater
|
* @param inflater
|
||||||
* @param container
|
* @param container
|
||||||
* @param savedInstanceState
|
* @param savedInstanceState
|
||||||
@ -31,7 +31,7 @@ public class FavoriteIOsFragment extends Fragment {
|
|||||||
this.mainActivity = (MainActivity) getActivity();
|
this.mainActivity = (MainActivity) getActivity();
|
||||||
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
||||||
false);
|
false);
|
||||||
ListView lv = (ListView) view.findViewById(R.id.idListView);
|
ListView lv = view.findViewById(R.id.idListView);
|
||||||
MainListViewAdapter mainListViewAdapter =
|
MainListViewAdapter mainListViewAdapter =
|
||||||
new MainListViewAdapter(mainActivity, 1);
|
new MainListViewAdapter(mainActivity, 1);
|
||||||
lv.setAdapter(mainListViewAdapter);
|
lv.setAdapter(mainListViewAdapter);
|
||||||
|
@ -37,6 +37,7 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Transfer of data to MainListViewAdapter.
|
||||||
* @param pMainActivity
|
* @param pMainActivity
|
||||||
* @param pFavoriteMode
|
* @param pFavoriteMode
|
||||||
*/
|
*/
|
||||||
@ -47,17 +48,18 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set number of list elements.
|
||||||
* @return devices number
|
* @return devices number
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
int devices;
|
int devices;
|
||||||
if (favoriteMode == 0) {
|
if (favoriteMode == 0) {
|
||||||
devices = mainActivity.xml.getDeviceNames().size();
|
devices = mainActivity.getXml().getDeviceNames().size();
|
||||||
} else {
|
} else {
|
||||||
devices = mainActivity.favorite.getFavorites().size();
|
devices = mainActivity.getFavorite().getFavorites().size();
|
||||||
favoritenList = new ArrayList<>(mainActivity.favorite.
|
favoritenList = new ArrayList<>(mainActivity.getFavorite()
|
||||||
getFavorites());
|
.getFavorites());
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
@ -83,69 +85,68 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Device name display and favorite button and data sharing for state
|
||||||
|
* visitation.
|
||||||
* @param i
|
* @param i
|
||||||
* @param view
|
* @param pView
|
||||||
* @param viewGroup
|
* @param viewGroup
|
||||||
* @return view
|
* @return view
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int i, View view,
|
public View getView(final int i, final View pView,
|
||||||
final ViewGroup viewGroup) {
|
final ViewGroup viewGroup) {
|
||||||
view = mainActivity.getLayoutInflater().inflate(R.layout.
|
View view = mainActivity.getLayoutInflater().inflate(R.layout
|
||||||
listview_layout, null);
|
.listview_layout, null);
|
||||||
TextView textViewName = (TextView) view.findViewById(R.id.textName);
|
TextView textViewName = view.findViewById(R.id.textName);
|
||||||
LinearLayout linearLayoutPin = (LinearLayout) view.findViewById(R.id.
|
LinearLayout linearLayoutPin = view.findViewById(R.id
|
||||||
idLinearLayoutPins);
|
.idLinearLayoutPins);
|
||||||
ImageView buttonViewFavoriten = (ImageView) view.findViewById(R.id.
|
ImageView buttonViewFavoriten = view.findViewById(R.id
|
||||||
imageButtonFavoriten);
|
.imageButtonFavoriten);
|
||||||
if (favoriteMode == 0) {
|
if (favoriteMode == 0) {
|
||||||
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
deviceName = mainActivity.getXml().getDeviceNames().get(i);
|
||||||
} else {
|
} 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;
|
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||||
} else {
|
} else {
|
||||||
favoriteImage = android.R.drawable.btn_star_big_off;
|
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||||
}
|
}
|
||||||
buttonViewFavoriten.setOnClickListener(new View.OnClickListener() {
|
buttonViewFavoriten.setOnClickListener(view1 -> {
|
||||||
@Override
|
|
||||||
public void onClick(final View view) {
|
|
||||||
|
|
||||||
if (favoriteMode == 0) {
|
if (favoriteMode == 0) {
|
||||||
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
deviceName = mainActivity.getXml().getDeviceNames().get(i);
|
||||||
} else {
|
} else {
|
||||||
deviceName = favoritenList.get(i);
|
deviceName = favoritenList.get(i);
|
||||||
}
|
}
|
||||||
if (mainActivity.favorite.getFavorites().contains(deviceName)) {
|
if (mainActivity.getFavorite().getFavorites()
|
||||||
mainActivity.favorite.removeFavorite(deviceName);
|
.contains(deviceName)) { mainActivity.getFavorite()
|
||||||
|
.removeFavorite(deviceName);
|
||||||
favoriteImage = android.R.drawable.btn_star_big_off;
|
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||||
buttonViewFavoriten.setImageResource(favoriteImage);
|
buttonViewFavoriten.setImageResource(favoriteImage);
|
||||||
} else {
|
} else {
|
||||||
mainActivity.favorite.addFavorite(deviceName);
|
mainActivity.getFavorite().addFavorite(deviceName);
|
||||||
favoriteImage = android.R.drawable.btn_star_big_on;
|
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||||
buttonViewFavoriten.setImageResource(favoriteImage);
|
buttonViewFavoriten.setImageResource(favoriteImage);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
PinView pinView = new PinView(mainActivity, deviceName);
|
PinView pinView = new PinView(mainActivity, deviceName);
|
||||||
for (int j = 0; j < ((List<String>) mainActivity.xml.
|
for (int j = 0; j < ((List<String>) mainActivity.getXml()
|
||||||
getPort(deviceName).get("pins")).size(); j++) {
|
.getPort(deviceName).get("pins")).size(); j++) {
|
||||||
linearLayoutPin.addView(pinView.getView(j));
|
linearLayoutPin.addView(pinView.getView(j));
|
||||||
}
|
}
|
||||||
String name = null;
|
String name = null;
|
||||||
switch ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
switch ((mainActivity.getXml().getPort(deviceName)).get("protocol").
|
||||||
toString()) {
|
toString()) {
|
||||||
case "PWM":
|
case "PWM":
|
||||||
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
name = ((mainActivity.getXml().getPort(deviceName))
|
||||||
toString() + ": " + deviceName + " (" + (mainActivity.
|
.get("protocol").toString() + ": " + deviceName
|
||||||
xml.getPort(deviceName)).get("frequency").toString()
|
+ " (" + (mainActivity.getXml().getPort(deviceName))
|
||||||
+ "Hz)");
|
.get("frequency").toString() + "Hz)");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
name = ((mainActivity.getXml().getPort(deviceName)).
|
||||||
toString() + ": " + deviceName);
|
get("protocol").toString() + ": " + deviceName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
textViewName.setText(name);
|
textViewName.setText(name);
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package com.example.aped.ui.visualization;
|
package com.example.aped.ui.visualization;
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.example.aped.MainActivity;
|
import com.example.aped.MainActivity;
|
||||||
import com.example.aped.R;
|
import com.example.aped.R;
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
@ -35,6 +33,7 @@ public class PinView {
|
|||||||
private String deviceName;
|
private String deviceName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Transfer of data to PinView.
|
||||||
* @param pMainActivity
|
* @param pMainActivity
|
||||||
* @param pDeviceName
|
* @param pDeviceName
|
||||||
*/
|
*/
|
||||||
@ -44,120 +43,85 @@ public class PinView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Processing of the data in nzeigetezte of the pins frequencies and
|
||||||
|
* dutycycle as well as the status lamps.
|
||||||
* @param i
|
* @param i
|
||||||
* @return view
|
* @return view
|
||||||
*/
|
*/
|
||||||
public View getView(final int i) {
|
public View getView(final int i) {
|
||||||
View view = mainActivity.getLayoutInflater().inflate(R.layout.
|
View view = mainActivity.getLayoutInflater().inflate(R.layout
|
||||||
pin_listview_layout, null);
|
.pin_listview_layout, null);
|
||||||
TextView textViewPin = (TextView) view.findViewById(R.id.textPin);
|
TextView textViewPin = view.findViewById(R.id.textPin);
|
||||||
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(
|
textViewPin.setText(((List<String>) (mainActivity.getXml().
|
||||||
deviceName)).get("pins")).get(i));
|
getPort(deviceName)).get("pins")).get(i));
|
||||||
mainActivity.delivery.read(deviceName, new Response.
|
mainActivity.getDelivery().read(deviceName, response -> {
|
||||||
Listener<JSONObject>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(final JSONObject response) {
|
|
||||||
displayLamp(response, view, i);
|
displayLamp(response, view, i);
|
||||||
if ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
if ((mainActivity.getXml().getPort(deviceName)).get("protocol")
|
||||||
toString().equals("PWM")) {
|
.toString().equals("PWM")) {
|
||||||
textViewPin.setText(Html.fromHtml(((List<String>)
|
textViewPin.setText(Html.fromHtml(((List<String>)
|
||||||
(mainActivity.xml.getPort(deviceName)).get("pins")).
|
(mainActivity.getXml().getPort(deviceName)).get("pins"))
|
||||||
get(i) + " <b> (DC: " + pinValues.get(i) + "%) </b>"
|
.get(i) + " <b> (DC: " + pinValues.get(i) + "%) </b>"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
view.setOnClickListener(new View.OnClickListener() {
|
view.setOnClickListener(view1 -> {
|
||||||
@Override
|
switch ((mainActivity.getXml().getPort(deviceName)).get("protocol")
|
||||||
public void onClick(final View view) {
|
.toString()) {
|
||||||
switch ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
|
||||||
toString()) {
|
|
||||||
case "DO":
|
case "DO":
|
||||||
try {
|
try {
|
||||||
String setState = null;
|
String setState;
|
||||||
if (pinValues.get(i).equals("0")) {
|
if (pinValues.get(i).equals("0")) {
|
||||||
setState = "\"1\"";
|
setState = "\"1\"";
|
||||||
} else {
|
} else {
|
||||||
setState = "\"0\"";
|
setState = "\"0\"";
|
||||||
}
|
}
|
||||||
JSONObject jsonObject = new JSONObject(
|
JSONObject jsonObject = new JSONObject(
|
||||||
"{\"output\":{\"" + ((List<String>)
|
"{\"output\":{\"" + ((List<String>) (mainActivity
|
||||||
(mainActivity.xml.getPort(
|
.getXml().getPort(deviceName)).get("pins"))
|
||||||
deviceName)).get("pins")).
|
.get(i) + "\":" + setState + "}}");
|
||||||
get(i) + "\":" + setState + "}}");
|
mainActivity.getDelivery().write(deviceName,
|
||||||
mainActivity.delivery.write(deviceName, jsonObject,
|
jsonObject, response -> displayLamp(response,
|
||||||
new Response.Listener<JSONObject>() {
|
view1, i));
|
||||||
@Override
|
|
||||||
public void onResponse(final JSONObject response
|
|
||||||
) {
|
|
||||||
displayLamp(response, view, i);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace(); // dd
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "PWM":
|
case "PWM":
|
||||||
MaterialAlertDialogBuilder alert =
|
MaterialAlertDialogBuilder alert =
|
||||||
new MaterialAlertDialogBuilder(mainActivity);
|
new MaterialAlertDialogBuilder(mainActivity);
|
||||||
View viewAlert = mainActivity.getLayoutInflater().
|
View viewAlert = mainActivity.getLayoutInflater()
|
||||||
inflate(R.layout.alert_dialog_duty, null);
|
.inflate(R.layout.alert_dialog_duty, null);
|
||||||
RangeSlider readDuty = (RangeSlider) viewAlert.
|
RangeSlider readDuty = viewAlert.findViewById(R.id
|
||||||
findViewById(R.id.range_slider_duty);
|
.range_slider_duty);
|
||||||
readDuty.setValues((float) Float.valueOf(pinValues.
|
readDuty.setValues(Float.valueOf(pinValues.get(i)
|
||||||
get(i).equals("None") ? "0" : pinValues.get(i))
|
.equals("None") ? "0" : pinValues.get(i))
|
||||||
);
|
);
|
||||||
alert.setView(viewAlert);
|
alert.setView(viewAlert);
|
||||||
alert.setPositiveButton("set",
|
alert.setPositiveButton("set", (dialog, which) -> {
|
||||||
new DialogInterface.OnClickListener() {
|
int value = readDuty.getValues().get(0).intValue();
|
||||||
public void onClick(
|
|
||||||
final DialogInterface dialog,
|
|
||||||
final int which) {
|
|
||||||
int value = readDuty.getValues().get(0).
|
|
||||||
intValue();
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject =
|
JSONObject jsonObject = new JSONObject(
|
||||||
new JSONObject("{\"output\":{\""
|
"{\"output\":{\"" + ((List<String>)
|
||||||
+ ((List<String>) (
|
(mainActivity.getXml().getPort(deviceName))
|
||||||
mainActivity.xml.getPort(
|
.get("pins")).get(i) + "\":\"" + value
|
||||||
deviceName)).get("pins")
|
+ "\"}}");
|
||||||
).get(i) + "\":\""
|
mainActivity.getDelivery().write(deviceName,
|
||||||
+ value + "\"}}");
|
jsonObject, response -> {
|
||||||
mainActivity.delivery.write(
|
displayLamp(response, view1, i);
|
||||||
deviceName, jsonObject,
|
textViewPin.setText(Html.fromHtml((
|
||||||
new Response.
|
(List<String>) (mainActivity.getXml()
|
||||||
Listener<JSONObject>() {
|
.getPort(deviceName)).get("pins")).get(i)
|
||||||
@Override
|
+ " <b> (DC: " + pinValues.get(i)
|
||||||
public void onResponse(
|
|
||||||
final JSONObject response) {
|
|
||||||
displayLamp(response, view,
|
|
||||||
i);
|
|
||||||
textViewPin.setText(Html.
|
|
||||||
fromHtml((
|
|
||||||
(List<String>) (
|
|
||||||
mainActivity.xml.
|
|
||||||
getPort(deviceName)).
|
|
||||||
get("pins")).get(i)
|
|
||||||
+ " <b> (DC: "
|
|
||||||
+ pinValues.get(i)
|
|
||||||
+ "%) </b>"));
|
+ "%) </b>"));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace(); // aaaaa
|
e.printStackTrace(); // aaaaa
|
||||||
}
|
}
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
|
||||||
});
|
|
||||||
alert.setNegativeButton("exit",
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(
|
|
||||||
final DialogInterface dialog,
|
|
||||||
final int which) {
|
|
||||||
dialog.cancel();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
alert.setNegativeButton("exit", (dialog,
|
||||||
|
which) -> dialog.cancel());
|
||||||
alert.show();
|
alert.show();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -168,21 +132,26 @@ public class PinView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for the selection of the lamps.
|
||||||
|
* @param response
|
||||||
|
* @param view
|
||||||
|
* @param i
|
||||||
|
*/
|
||||||
private void displayLamp(final JSONObject response, final View view,
|
private void displayLamp(final JSONObject response, final View view,
|
||||||
final int i) {
|
final int i) {
|
||||||
ImageView imageView = (ImageView) view.findViewById(R.id.images);
|
ImageView imageView = view.findViewById(R.id.images);
|
||||||
try {
|
try {
|
||||||
JSONObject state = response.getJSONObject("state");
|
JSONObject state = response.getJSONObject("state");
|
||||||
if (pinValues.size() != 0) {
|
if (pinValues.size() != 0) {
|
||||||
pinValues.clear();
|
pinValues.clear();
|
||||||
}
|
}
|
||||||
for (String pinName: ((List<String>) mainActivity.xml.
|
for (String pinName: ((List<String>) mainActivity.getXml()
|
||||||
getPort(deviceName).get("pins"))) {
|
.getPort(deviceName).get("pins"))) {
|
||||||
pinValues.add(state.getString(pinName));
|
pinValues.add(state.getString(pinName));
|
||||||
}
|
}
|
||||||
switch (pinValues.get(i)) {
|
switch (pinValues.get(i)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user