Fehlerbehebung
Anzeige AllIOsFragment.java geändert Testclasse TestIO.java mit Leben gefüllt
This commit is contained in:
parent
09e127bbb6
commit
86e5da0570
@ -10,6 +10,7 @@ import android.view.Menu;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.aped.communication.IIO;
|
||||
import com.example.aped.communication.TestIO;
|
||||
import com.example.aped.utils.IXML;
|
||||
import com.example.aped.utils.TestXML;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
@ -33,10 +34,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
/** was soll angezeigt werden in Navigation.*/
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
/** zur Verwendung von xml anstatt der direkten Einbindung.*/
|
||||
private IXML xml;
|
||||
public static IXML xml = new TestXML();
|
||||
/** zur Verwendung von uebergabe anstatt der direkten Einbindung.*/
|
||||
private IIO uebergabe;
|
||||
public static IIO uebergabe = new TestIO();
|
||||
/** allgemeines.*/
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -1,14 +1,30 @@
|
||||
package com.example.aped.communication;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.aped.R;
|
||||
|
||||
public class TestIO implements IIO {
|
||||
|
||||
@Override
|
||||
public String read(String deviceName) {
|
||||
return "test";
|
||||
|
||||
String Wert;
|
||||
switch (deviceName) {
|
||||
case "stoff":
|
||||
Wert = "TRUE";
|
||||
break;
|
||||
case "schnaps":
|
||||
Wert = "FALSE";
|
||||
break;
|
||||
default:
|
||||
Wert="default";
|
||||
}
|
||||
return Wert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String write(String deviceName, String value) {
|
||||
return value;
|
||||
return "TRUE";//Wenn erfolgreich gesendet
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package com.example.aped.ui.all_IOs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
@ -17,31 +21,91 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.aped.MainActivity;
|
||||
import com.example.aped.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AllIOsFragment extends Fragment {
|
||||
ListView lv;
|
||||
|
||||
SearchView searchView;
|
||||
ArrayAdapter<String> adapter;
|
||||
String[] name = {"IN1", "Temperatur extern","Strom Heizung"};
|
||||
List<String> name = MainActivity.xml.getDeviceNames();//{"IN1", "Temperatur extern > 5°C", "Strom Heizung < 10A"};
|
||||
//String[] state = {"FALSE", "TRUE", "FALSE"};
|
||||
int[] images =new int[name.size()];// {R.drawable.red_signal, R.drawable.green_signal, R.drawable.red_signal};
|
||||
int[] favoriten = new int[name.size()];//{android.R.drawable.btn_star_big_off, android.R.drawable.btn_star_big_on, android.R.drawable.btn_star_big_off};
|
||||
int[] favoriten_state = new int[name.size()];
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
||||
false);
|
||||
lv = (ListView) view.findViewById(R.id.idListView);
|
||||
adapter = new ArrayAdapter<String>(getActivity(),
|
||||
android.R.layout.simple_expandable_list_item_1,name);
|
||||
lv.setAdapter(adapter);
|
||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Toast.makeText(getContext(),"Position:"+position, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
return view;
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_all_ios, container,
|
||||
false);
|
||||
lv = (ListView) view.findViewById(R.id.idListView);
|
||||
CustomAdapter customAdapter = new CustomAdapter();
|
||||
lv.setAdapter(customAdapter);
|
||||
return view;
|
||||
}
|
||||
|
||||
class CustomAdapter extends BaseAdapter {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return name.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
if(MainActivity.uebergabe.read(name.get(i))=="FALSE")
|
||||
{
|
||||
images[i]=R.drawable.red_signal;
|
||||
}else {
|
||||
images[i] = R.drawable.green_signal;
|
||||
}
|
||||
if(favoriten_state[i]==0)
|
||||
{
|
||||
favoriten[i]=android.R.drawable.btn_star_big_off;
|
||||
}else {
|
||||
favoriten[i] = android.R.drawable.btn_star_big_on;
|
||||
}
|
||||
view = getLayoutInflater().inflate(R.layout.listview_layout, null);
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.images);
|
||||
TextView TextView_Name = (TextView) view.findViewById(R.id.textName);
|
||||
TextView TextView_State = (TextView) view.findViewById(R.id.textState);
|
||||
ImageView ButtonView_Favoriten = (ImageView) view.findViewById(R.id.imageButtonFavoriten);
|
||||
|
||||
ButtonView_Favoriten.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view){
|
||||
if(favoriten_state[i]==0){
|
||||
favoriten_state[i]=1;
|
||||
favoriten[i]=android.R.drawable.btn_star_big_on;
|
||||
ButtonView_Favoriten.setImageResource(favoriten[i]);
|
||||
}else{
|
||||
favoriten_state[i]=0;
|
||||
favoriten[i]=android.R.drawable.btn_star_big_off;
|
||||
ButtonView_Favoriten.setImageResource(favoriten[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
imageView.setImageResource(images[i]);
|
||||
TextView_Name.setText(name.get(i));
|
||||
TextView_State.setText(MainActivity.uebergabe.read(name.get(i)));
|
||||
ButtonView_Favoriten.setImageResource(favoriten[i]);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
APED/app/src/main/res/drawable/green_signal.jpg
Normal file
BIN
APED/app/src/main/res/drawable/green_signal.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
BIN
APED/app/src/main/res/drawable/red_signal.jpg
Normal file
BIN
APED/app/src/main/res/drawable/red_signal.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
44
APED/app/src/main/res/layout/listview_layout.xml
Normal file
44
APED/app/src/main/res/layout/listview_layout.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/images"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:layout_x="12dp"
|
||||
android:layout_y="28dp"
|
||||
tools:srcCompat="@tools:sample/avatars" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textName"
|
||||
android:layout_width="253dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_x="62dp"
|
||||
android:layout_y="12dp"
|
||||
android:text="TextView"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textState"
|
||||
android:layout_width="234dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_x="81dp"
|
||||
android:layout_y="49dp"
|
||||
android:text="TextView"
|
||||
android:textSize="20dp" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/imageButtonFavoriten"
|
||||
android:layout_width="67dp"
|
||||
android:layout_height="69dp"
|
||||
android:layout_x="322dp"
|
||||
android:layout_y="8dp"
|
||||
app:srcCompat="@android:drawable/btn_star_big_on" />
|
||||
|
||||
|
||||
</AbsoluteLayout>
|
Loading…
x
Reference in New Issue
Block a user