Code Conventions
This commit is contained in:
parent
feda184aa5
commit
a0ac5d4d0e
@ -3,22 +3,16 @@ package com.example.aped.ui.visualization;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
|
||||||
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 androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.android.volley.Response;
|
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;
|
||||||
import com.google.android.material.slider.RangeSlider;
|
import com.google.android.material.slider.RangeSlider;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -60,24 +54,31 @@ public class PinView {
|
|||||||
*/
|
*/
|
||||||
public View getView(final int i) {
|
public View getView(final int i) {
|
||||||
dutyValue = "";
|
dutyValue = "";
|
||||||
View view = mainActivity.getLayoutInflater().inflate(R.layout.pin_listview_layout, null);
|
View view = mainActivity.getLayoutInflater().inflate(R.layout.
|
||||||
|
pin_listview_layout, null);
|
||||||
TextView textViewPin = (TextView) view.findViewById(R.id.textPin);
|
TextView textViewPin = (TextView) view.findViewById(R.id.textPin);
|
||||||
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i));
|
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(
|
||||||
mainActivity.uebergabe.read(deviceName, new Response.Listener<JSONObject>() {
|
deviceName)).get("pins")).get(i));
|
||||||
|
mainActivity.uebergabe.read(deviceName, new Response.
|
||||||
|
Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(final JSONObject response) {
|
public void onResponse(final JSONObject response) {
|
||||||
displayLamp(response, view, i);
|
displayLamp(response, view, i);
|
||||||
if((mainActivity.xml.getPort(deviceName)).get("protocol").toString().equals("PWM")){
|
if ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||||
textViewPin.setText(Html.fromHtml(((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i)+" <b> (DC: " + pinValues.get(i) + "%) </b>"));
|
toString().equals("PWM")) {
|
||||||
|
textViewPin.setText(Html.fromHtml(((List<String>)
|
||||||
|
(mainActivity.xml.getPort(deviceName)).get("pins")).
|
||||||
|
get(i) + " <b> (DC: " + pinValues.get(i) + "%) </b>"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
view.setOnClickListener(new View.OnClickListener() {
|
view.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View view) {
|
public void onClick(final View view) {
|
||||||
switch ((mainActivity.xml.getPort(deviceName)).get("protocol").toString()) {
|
switch ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||||
|
toString()) {
|
||||||
case "DO":
|
case "DO":
|
||||||
try {
|
try {
|
||||||
String setState = null;
|
String setState = null;
|
||||||
@ -86,10 +87,16 @@ public class PinView {
|
|||||||
} else {
|
} else {
|
||||||
setState = "\"0\"";
|
setState = "\"0\"";
|
||||||
}
|
}
|
||||||
JSONObject jsonObject = new JSONObject("{\"output\":{\"" + ((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i) + "\":" + setState + "}}");
|
JSONObject jsonObject = new JSONObject(
|
||||||
mainActivity.uebergabe.write(deviceName, jsonObject, new Response.Listener<JSONObject>() {
|
"{\"output\":{\"" + ((List<String>)
|
||||||
|
(mainActivity.xml.getPort(
|
||||||
|
deviceName)).get("pins")).
|
||||||
|
get(i) + "\":" + setState + "}}");
|
||||||
|
mainActivity.uebergabe.write(deviceName, jsonObject,
|
||||||
|
new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(final JSONObject response) {
|
public void onResponse(final JSONObject response
|
||||||
|
) {
|
||||||
displayLamp(response, view, i);
|
displayLamp(response, view, i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -98,67 +105,91 @@ public class PinView {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "PWM":
|
case "PWM":
|
||||||
MaterialAlertDialogBuilder alert = new MaterialAlertDialogBuilder(mainActivity);
|
MaterialAlertDialogBuilder alert =
|
||||||
View viewAlert = mainActivity.getLayoutInflater().inflate(R.layout.alert_dialog_pwm, null);
|
new MaterialAlertDialogBuilder(mainActivity);
|
||||||
RangeSlider readDuty = (RangeSlider) viewAlert.findViewById(R.id.range_slider_duty);
|
View viewAlert = mainActivity.getLayoutInflater().
|
||||||
readDuty.setValues((float) Float.valueOf(pinValues.get(i)));
|
inflate(R.layout.alert_dialog_pwm, null);
|
||||||
|
RangeSlider readDuty = (RangeSlider) viewAlert.
|
||||||
|
findViewById(R.id.range_slider_duty);
|
||||||
|
readDuty.setValues((float) Float.valueOf(pinValues.
|
||||||
|
get(i)));
|
||||||
alert.setView(viewAlert);
|
alert.setView(viewAlert);
|
||||||
alert.setPositiveButton("set",
|
alert.setPositiveButton("set",
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(
|
public void onClick(
|
||||||
final DialogInterface dialog, final int which) {
|
final DialogInterface dialog,
|
||||||
int value = readDuty.getValues().get(0).intValue();
|
final int which) {
|
||||||
|
int value = readDuty.getValues().get(0).
|
||||||
|
intValue();
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject("{\"output\":{\"" + ((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i) + "\":\"" + value + "\"}}");
|
JSONObject jsonObject =
|
||||||
mainActivity.uebergabe.write(deviceName, jsonObject, new Response.Listener<JSONObject>() {
|
new JSONObject(
|
||||||
|
"{\"output\":{\""
|
||||||
|
+ ((List<String>)
|
||||||
|
(mainActivity.xml.
|
||||||
|
getPort(deviceName)).
|
||||||
|
get("pins")).get(i)
|
||||||
|
+ "\":\"" + value
|
||||||
|
+ "\"}}");
|
||||||
|
mainActivity.uebergabe.write(
|
||||||
|
deviceName, jsonObject,
|
||||||
|
new Response.
|
||||||
|
Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(
|
||||||
displayLamp(response, view, i);
|
final JSONObject response) {
|
||||||
textViewPin.setText(Html.fromHtml(((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i)+" <b> (DC: " + pinValues.get(i) + "%) </b>"));
|
displayLamp(response, view,
|
||||||
|
i);
|
||||||
|
textViewPin.setText(Html.
|
||||||
|
fromHtml((
|
||||||
|
(List<String>) (
|
||||||
|
mainActivity.xml.
|
||||||
|
getPort(deviceName)).
|
||||||
|
get("pins")).get(i)
|
||||||
|
+ " <b> (DC: "
|
||||||
|
+ pinValues.get(i)
|
||||||
|
+ "%) </b>"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace(); // aaaaa
|
e.printStackTrace(); // aaaaa
|
||||||
}
|
}
|
||||||
// Write your code here to execute after dialog
|
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alert.setNegativeButton("exit", new DialogInterface.OnClickListener() {
|
alert.setNegativeButton("exit",
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(
|
public void onClick(
|
||||||
final DialogInterface dialog, final int which) {
|
final DialogInterface dialog,
|
||||||
|
final int which) {
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alert.show();
|
alert.show();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Toast.makeText(mainActivity, deviceName + " is not an output ", Toast.LENGTH_SHORT).show();
|
Toast.makeText(mainActivity, deviceName
|
||||||
|
+ " is not an output ", Toast.LENGTH_SHORT).
|
||||||
|
show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 = (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.getPort(deviceName).get("pins"))){
|
for (String pinName: ((List<String>) mainActivity.xml.
|
||||||
|
getPort(deviceName).get("pins"))) {
|
||||||
pinValues.add(state.getString(pinName));
|
pinValues.add(state.getString(pinName));
|
||||||
}
|
}
|
||||||
switch (pinValues.get(i)) {
|
switch (pinValues.get(i)) {
|
||||||
@ -176,14 +207,9 @@ public class PinView {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
imageView.setImageResource(image);
|
imageView.setImageResource(image);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
// Richtigen log erstellen
|
// Richtigen log erstellen
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user