Funktion Ansteuerung der digital out mit leben gefüllt
This commit is contained in:
parent
f56d526058
commit
5427325d4d
@ -4,6 +4,7 @@ import android.Manifest;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -14,11 +14,8 @@ import androidx.fragment.app.Fragment;
|
|||||||
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 org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.Dictionary;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,20 +5,16 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
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 org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.LineNumberReader;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class MainListViewAdapter extends BaseAdapter {
|
public class MainListViewAdapter extends BaseAdapter {
|
||||||
|
|
||||||
private MainActivity mainActivity;
|
private MainActivity mainActivity;
|
||||||
@ -34,7 +30,6 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
int temp = mainActivity.xml.getDeviceNames().size();
|
|
||||||
return mainActivity.xml.getDeviceNames().size();
|
return mainActivity.xml.getDeviceNames().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,17 +87,25 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
//textViewPin.setText(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
//textViewPin.setText(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
||||||
|
|
||||||
|
|
||||||
mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i), new Response.Listener<JSONObject>() {
|
|
||||||
|
|
||||||
|
mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().get(i),
|
||||||
|
new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(final JSONObject response) {
|
public void onResponse(final JSONObject response) {
|
||||||
try {
|
try {
|
||||||
JSONObject state = response.getJSONObject("state");
|
JSONObject state = response.getJSONObject("state");
|
||||||
List<String> pinValues = new ArrayList<>();
|
List<String> pinValues = new ArrayList<>();
|
||||||
for(String pinName: ((List<String>)mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i)).get("pins"))){
|
for(String pinName: ((List<String>)mainActivity.xml.
|
||||||
|
getPort(mainActivity.xml.getDeviceNames().get(i)).
|
||||||
|
get("pins"))){
|
||||||
pinValues.add(state.getString(pinName));
|
pinValues.add(state.getString(pinName));
|
||||||
}
|
}
|
||||||
PinView pinView = new PinView(mainActivity,mainActivity.xml.getDeviceNames().get(i), pinValues);
|
PinView pinView = new PinView(mainActivity,mainActivity.xml.
|
||||||
for(int j = 0; j < ((List<String>)mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i)).get("pins")).size(); j++) {
|
getDeviceNames().get(i), pinValues);
|
||||||
|
for(int j = 0; j < ((List<String>)mainActivity.xml.
|
||||||
|
getPort(mainActivity.xml.getDeviceNames().get(i)).
|
||||||
|
get("pins")).size(); j++) {
|
||||||
linearLayoutPin.addView(pinView.getView(j));
|
linearLayoutPin.addView(pinView.getView(j));
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package com.example.aped.ui.all_IOs;
|
package com.example.aped.ui.all_IOs;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
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 org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PinView {
|
public class PinView {
|
||||||
@ -32,16 +34,78 @@ public class PinView {
|
|||||||
TextView textViewPin = (TextView) view.findViewById(
|
TextView textViewPin = (TextView) view.findViewById(
|
||||||
R.id.textPin);
|
R.id.textPin);
|
||||||
|
|
||||||
String pinState = pinValues.get(i);
|
switch (pinValues.get(i)){
|
||||||
|
case "1":
|
||||||
if(pinState.equals("1")) {
|
image=R.drawable.green_signal;
|
||||||
image=R.drawable.green_signal;
|
break;
|
||||||
}else if (pinState.equals("0")) {
|
case "0":
|
||||||
image = R.drawable.red_signal;
|
image=R.drawable.red_signal;
|
||||||
} else{ image = R.drawable.off_signal; }
|
break;
|
||||||
|
default:
|
||||||
|
image=R.drawable.off_signal;
|
||||||
|
break;
|
||||||
|
}
|
||||||
imageView.setImageResource(image);
|
imageView.setImageResource(image);
|
||||||
|
|
||||||
|
|
||||||
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i));
|
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(deviceName)).get("pins")).get(i));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
String test = pinValues.get(i);
|
||||||
|
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 a output " ,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
Intent intentneustart = mainActivity.getIntent();
|
||||||
|
mainActivity.finish();
|
||||||
|
mainActivity.startActivity(intentneustart);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user