|
@@ -1,6 +1,7 @@
|
|
|
package de.tudarmstadt.informatik.hostage.ui2.adapter;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.os.Build;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
@@ -15,6 +16,7 @@ import android.widget.ViewSwitcher;
|
|
|
import java.util.List;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
|
|
|
|
|
|
/**
|
|
@@ -25,10 +27,15 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
public TextView protocolName;
|
|
|
public TextView recordedAttacks;
|
|
|
public Switch activated;
|
|
|
+ public View circle;
|
|
|
}
|
|
|
|
|
|
private final Context context;
|
|
|
private final List<ServicesListItem> values;
|
|
|
+ int sdk = Build.VERSION.SDK_INT;
|
|
|
+
|
|
|
+ ViewHolder holder = null;
|
|
|
+ private ServicesListItem item;
|
|
|
|
|
|
public ServicesListAdapter(Context context, List<ServicesListItem> objects){
|
|
|
super(context, R.layout.services_list_item, objects);
|
|
@@ -43,9 +50,8 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
|
View rowView = convertView;
|
|
|
- ViewHolder holder = null;
|
|
|
|
|
|
- final ServicesListItem item = values.get(position);
|
|
|
+ item = values.get(position);
|
|
|
|
|
|
if(rowView == null){
|
|
|
rowView = inflater.inflate(R.layout.services_list_item, parent, false);
|
|
@@ -54,7 +60,8 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
holder.protocolName = (TextView) rowView.findViewById(R.id.services_item_name);
|
|
|
holder.recordedAttacks = (TextView) rowView.findViewById(R.id.services_item_rec_attacks);
|
|
|
holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
|
|
|
-
|
|
|
+ holder.circle = (View) rowView.findViewById(R.id.services_circle);
|
|
|
+ this.notifyDataSetChanged();
|
|
|
rowView.setTag(holder);
|
|
|
} else {
|
|
|
holder = (ViewHolder) rowView.getTag();
|
|
@@ -62,8 +69,29 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
|
|
|
holder.protocolName.setText(item.protocol);
|
|
|
|
|
|
-
|
|
|
return rowView;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void notifyDataSetChanged(){
|
|
|
+ if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
|
|
|
+ holder.activated.setChecked(true);
|
|
|
+ if(sdk < Build.VERSION_CODES.JELLY_BEAN){
|
|
|
+ holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(R.drawable.services_circle_green));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ holder.circle.setBackground(MainActivity.getInstance().getResources().getDrawable(R.drawable.services_circle_green));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ holder.activated.setChecked(false);
|
|
|
+ if(sdk < Build.VERSION_CODES.JELLY_BEAN){
|
|
|
+ holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(R.drawable.services_circle));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ holder.circle.setBackground(MainActivity.getInstance().getResources().getDrawable(R.drawable.services_circle));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|