Code Conventions
This commit is contained in:
parent
8b8cc32697
commit
465c9aa9ba
@ -17,70 +17,99 @@ import java.util.List;
|
|||||||
|
|
||||||
|
|
||||||
public class MainListViewAdapter extends BaseAdapter {
|
public class MainListViewAdapter extends BaseAdapter {
|
||||||
|
/**
|
||||||
|
* Einbinden der MainActivity.
|
||||||
|
*/
|
||||||
private MainActivity mainActivity;
|
private MainActivity mainActivity;
|
||||||
|
/**
|
||||||
|
* Welche ansicht gewählt wurde 0 für all IOs, 1 für favorite IOs.
|
||||||
|
*/
|
||||||
private int favoriteMode;
|
private int favoriteMode;
|
||||||
|
/**
|
||||||
|
* Name des devices für den aktuellen durchlauf.
|
||||||
|
*/
|
||||||
private String deviceName;
|
private String deviceName;
|
||||||
|
/**
|
||||||
|
* Bild für den atuellen durchlauf.
|
||||||
|
*/
|
||||||
private int image;
|
private int image;
|
||||||
|
/**
|
||||||
|
* Bild für Favorit oder nicht.
|
||||||
|
*/
|
||||||
private int favoriteImage;
|
private int favoriteImage;
|
||||||
|
/**
|
||||||
|
* Liste der beim öffnen der Favoritenansicht bestehenden Favoriten.
|
||||||
|
*/
|
||||||
|
private List<String> favoritenList;
|
||||||
|
|
||||||
|
|
||||||
List<String> favoritenList;
|
/**
|
||||||
|
* @param pMainActivity
|
||||||
|
* @param pFavoriteMode
|
||||||
public MainListViewAdapter(MainActivity pMainActivity,int pFavoriteMode){
|
*/
|
||||||
|
public MainListViewAdapter(final MainActivity pMainActivity,
|
||||||
|
final int pFavoriteMode) {
|
||||||
this.mainActivity = pMainActivity;
|
this.mainActivity = pMainActivity;
|
||||||
this.favoriteMode = pFavoriteMode;
|
this.favoriteMode = pFavoriteMode;
|
||||||
/**
|
|
||||||
* pFavoriteMode 0 oder 1 möglich
|
|
||||||
* 1 für wir befinden uns in Anzeige favorite IOs
|
|
||||||
* 0 für wir befinden uns in Anzeige all IOs
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Anzahl der Anzeigen
|
||||||
|
*/
|
||||||
@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.xml.getDeviceNames().size();
|
||||||
}else{
|
} else {
|
||||||
devices = mainActivity.favorite.getFavorites().size();
|
devices = mainActivity.favorite.getFavorites().size();
|
||||||
favoritenList = new ArrayList<>(mainActivity.favorite.getFavorites()) ;
|
favoritenList = new ArrayList<>(mainActivity.favorite.
|
||||||
|
getFavorites());
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param position
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(final int position) {
|
public Object getItem(final int position) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param position
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(final int position) {
|
public long getItemId(final int position) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param i
|
||||||
|
* @param view
|
||||||
|
* @param viewGroup
|
||||||
|
* @return view
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int i, View view,
|
public View getView(final int i, View view,
|
||||||
final ViewGroup viewGroup) {
|
final ViewGroup viewGroup) {
|
||||||
view = mainActivity.getLayoutInflater().inflate(R.layout.listview_layout,
|
view = mainActivity.getLayoutInflater().inflate(R.layout.
|
||||||
null);
|
listview_layout, null);
|
||||||
TextView textViewName = (TextView) view.findViewById(
|
TextView textViewName = (TextView) view.findViewById(
|
||||||
R.id.textName);
|
R.id.textName);
|
||||||
LinearLayout linearLayoutPin = (LinearLayout) view.findViewById(
|
LinearLayout linearLayoutPin = (LinearLayout) view.findViewById(
|
||||||
R.id.idLinearLayoutPins);
|
R.id.idLinearLayoutPins);
|
||||||
ImageView buttonViewFavoriten = (ImageView) view.findViewById(
|
ImageView buttonViewFavoriten = (ImageView) view.findViewById(
|
||||||
R.id.imageButtonFavoriten);
|
R.id.imageButtonFavoriten);
|
||||||
if (favoriteMode == 0){
|
if (favoriteMode == 0) {
|
||||||
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
||||||
}else{
|
} else {
|
||||||
deviceName = mainActivity.favorite.getFavorites().get(i);
|
deviceName = mainActivity.favorite.getFavorites().get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,9 +125,10 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(final View view) {
|
public void onClick(final View view) {
|
||||||
|
|
||||||
if (favoriteMode == 0){
|
if (favoriteMode == 0) {
|
||||||
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
deviceName = mainActivity.xml.getDeviceNames().
|
||||||
}else{
|
get(i);
|
||||||
|
} else {
|
||||||
List<String> test = favoritenList;
|
List<String> test = favoritenList;
|
||||||
deviceName = favoritenList.get(i);
|
deviceName = favoritenList.get(i);
|
||||||
}
|
}
|
||||||
@ -116,35 +146,29 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
buttonViewFavoriten.setImageResource(
|
buttonViewFavoriten.setImageResource(
|
||||||
favoriteImage);
|
favoriteImage);
|
||||||
}
|
}
|
||||||
/**Intent intentneustart = mainActivity.getIntent();// gegen richtigen Befehl tauschen da nur die visualisierung neu gestartet werden soll
|
|
||||||
mainActivity.finish();
|
|
||||||
mainActivity.startActivity(intentneustart);*/
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//textViewPin.setText(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mainActivity.uebergabe.read(deviceName,
|
mainActivity.uebergabe.read(deviceName,
|
||||||
new Response.Listener<JSONObject>() {
|
new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(final JSONObject response) {
|
public void onResponse(final JSONObject response) {
|
||||||
if (favoriteMode == 0){
|
if (favoriteMode == 0) {
|
||||||
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
deviceName = mainActivity.xml.getDeviceNames().get(i);
|
||||||
}else{
|
} else {
|
||||||
deviceName = mainActivity.favorite.getFavorites().get(i);
|
deviceName = mainActivity.favorite.getFavorites().get(i);
|
||||||
}
|
}
|
||||||
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.
|
for (String pinName: ((List<String>) mainActivity.xml.
|
||||||
getPort(deviceName).
|
getPort(deviceName).
|
||||||
get("pins"))){
|
get("pins"))) {
|
||||||
pinValues.add(state.getString(pinName));
|
pinValues.add(state.getString(pinName));
|
||||||
}
|
}
|
||||||
PinView pinView = new PinView(mainActivity,deviceName, pinValues);
|
PinView pinView = new PinView(mainActivity, deviceName,
|
||||||
for(int j = 0; j < ((List<String>)mainActivity.xml.
|
pinValues);
|
||||||
|
for (int j = 0; j < ((List<String>)mainActivity.xml.
|
||||||
getPort(deviceName).
|
getPort(deviceName).
|
||||||
get("pins")).size(); j++) {
|
get("pins")).size(); j++) {
|
||||||
linearLayoutPin.addView(pinView.getView(j));
|
linearLayoutPin.addView(pinView.getView(j));
|
||||||
@ -156,16 +180,18 @@ public class MainListViewAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String name = null;
|
String name = null;
|
||||||
switch((mainActivity.xml.getPort(deviceName)).get("protocol").toString()){
|
switch ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||||
|
toString()) {
|
||||||
case "PWM":
|
case "PWM":
|
||||||
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").toString() + ": " + deviceName + " (" + (mainActivity.xml.getPort(deviceName)).get("frequency").toString() + "Hz)" );
|
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||||
|
toString() + ": " + deviceName + " (" + (mainActivity.
|
||||||
|
xml.getPort(deviceName)).get("frequency").toString()
|
||||||
|
+ "Hz)");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").toString() + ": " + deviceName);
|
name = ((mainActivity.xml.getPort(deviceName)).get("protocol").
|
||||||
|
toString() + ": " + deviceName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
textViewName.setText(name);
|
textViewName.setText(name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user