|
@@ -1,6 +1,7 @@
|
|
package de.tudarmstadt.informatik.hostage.ui2.adapter;
|
|
package de.tudarmstadt.informatik.hostage.ui2.adapter;
|
|
|
|
|
|
|
|
|
|
|
|
+import android.annotation.TargetApi;
|
|
import android.app.AlertDialog;
|
|
import android.app.AlertDialog;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.content.DialogInterface;
|
|
@@ -26,20 +27,29 @@ import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
|
|
public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
|
|
|
private class ViewHolder {
|
|
private class ViewHolder {
|
|
- public TextView protocolName;
|
|
|
|
- public TextView recordedAttacks;
|
|
|
|
- public Switch activated;
|
|
|
|
- public View circle;
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ public TextView protocolName;
|
|
|
|
+
|
|
|
|
+ public TextView recordedAttacks;
|
|
|
|
+
|
|
|
|
+ public Switch activated;
|
|
|
|
+
|
|
|
|
+ public View circle;
|
|
|
|
+ }
|
|
|
|
|
|
private Context mActivity;
|
|
private Context mActivity;
|
|
|
|
+
|
|
private Switch mServicesSwitch;
|
|
private Switch mServicesSwitch;
|
|
|
|
+
|
|
private CompoundButton.OnCheckedChangeListener mListener;
|
|
private CompoundButton.OnCheckedChangeListener mListener;
|
|
|
|
+
|
|
private final Context context;
|
|
private final Context context;
|
|
|
|
+
|
|
private final List<ServicesListItem> values;
|
|
private final List<ServicesListItem> values;
|
|
|
|
+
|
|
int sdk = Build.VERSION.SDK_INT;
|
|
int sdk = Build.VERSION.SDK_INT;
|
|
|
|
|
|
- public ServicesListAdapter(Context context, List<ServicesListItem> objects){
|
|
|
|
|
|
+ public ServicesListAdapter(Context context, List<ServicesListItem> objects) {
|
|
super(context, R.layout.services_list_item, objects);
|
|
super(context, R.layout.services_list_item, objects);
|
|
|
|
|
|
this.context = context;
|
|
this.context = context;
|
|
@@ -62,7 +72,7 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
|
|
|
final ServicesListItem item = values.get(position);
|
|
final ServicesListItem item = values.get(position);
|
|
|
|
|
|
- if(rowView == null){
|
|
|
|
|
|
+ if (rowView == null) {
|
|
rowView = inflater.inflate(R.layout.services_list_item, parent, false);
|
|
rowView = inflater.inflate(R.layout.services_list_item, parent, false);
|
|
|
|
|
|
holder = new ViewHolder();
|
|
holder = new ViewHolder();
|
|
@@ -72,7 +82,6 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
|
|
holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
|
|
holder.circle = rowView.findViewById(R.id.services_circle);
|
|
holder.circle = rowView.findViewById(R.id.services_circle);
|
|
rowView.setTag(holder);
|
|
rowView.setTag(holder);
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
holder = (ViewHolder) rowView.getTag();
|
|
holder = (ViewHolder) rowView.getTag();
|
|
}
|
|
}
|
|
@@ -82,89 +91,82 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
|
|
|
|
this.updateStatus(item, holder);
|
|
this.updateStatus(item, holder);
|
|
|
|
|
|
- holder.activated.setOnCheckedChangeListener(
|
|
|
|
- new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
- ServicesListItem item = (ServicesListItem) buttonView.getTag();
|
|
|
|
- if(!HelperUtils.isWifiConnected(mActivity)){
|
|
|
|
- new AlertDialog.Builder(mActivity)
|
|
|
|
- .setTitle(R.string.information)
|
|
|
|
- .setMessage(R.string.wifi_not_connected_msg)
|
|
|
|
- .setPositiveButton(android.R.string.ok,
|
|
|
|
- new DialogInterface.OnClickListener() {
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .setIcon(android.R.drawable.ic_dialog_info)
|
|
|
|
- .show();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- buttonView.setChecked(false);
|
|
|
|
- } else {
|
|
|
|
- //check if switch is set to ON and start the concrete listener for the protocol
|
|
|
|
- if(isChecked){
|
|
|
|
- if(!MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
|
|
|
|
- MainActivity.getInstance().getHoneyService().startListener(item.protocol);
|
|
|
|
- System.out.println("Protokoll gestartet innerIFFFFF: ------------------------------" + item.protocol);
|
|
|
|
-
|
|
|
|
- //set the main switch to null, so that he won't react and starts all protocols
|
|
|
|
- mServicesSwitch.setOnCheckedChangeListener(null);
|
|
|
|
- mServicesSwitch.setChecked(true);
|
|
|
|
- mServicesSwitch.setOnCheckedChangeListener(mListener);
|
|
|
|
- buttonView.setChecked(true);
|
|
|
|
|
|
+ holder.activated.setOnCheckedChangeListener(
|
|
|
|
+ new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
+ ServicesListItem item = (ServicesListItem) buttonView.getTag();
|
|
|
|
+
|
|
|
|
+ if (!HelperUtils.isWifiConnected(mActivity)) {
|
|
|
|
+ new AlertDialog.Builder(mActivity)
|
|
|
|
+ .setTitle(R.string.information)
|
|
|
|
+ .setMessage(R.string.wifi_not_connected_msg)
|
|
|
|
+ .setPositiveButton(android.R.string.ok,
|
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
|
+ public void onClick(DialogInterface dialog,
|
|
|
|
+ int which) {
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .setIcon(android.R.drawable.ic_dialog_info).show();
|
|
|
|
+
|
|
|
|
+ buttonView.setChecked(false);
|
|
|
|
+ } else {
|
|
|
|
+ //check if switch is set to ON and start the concrete listener for the protocol
|
|
|
|
+ if (isChecked) {
|
|
|
|
+ if (!MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
|
|
|
|
+ MainActivity.getInstance().getHoneyService().startListener(item.protocol);
|
|
|
|
+
|
|
|
|
+ //set the main switch to null, so that he won't react and starts all protocols
|
|
|
|
+ mServicesSwitch.setOnCheckedChangeListener(null);
|
|
|
|
+ mServicesSwitch.setChecked(true);
|
|
|
|
+ mServicesSwitch.setOnCheckedChangeListener(mListener);
|
|
|
|
+ buttonView.setChecked(true);
|
|
|
|
+ } else if (MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
|
|
|
|
+ buttonView.setChecked(true);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
|
|
|
|
+ MainActivity.getInstance().getHoneyService().stopListener(item.protocol);
|
|
|
|
+ }
|
|
|
|
+ buttonView.setChecked(false);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
|
|
|
|
- System.out.println("Protokoll ist bereits gestartet: ------------------------------" + item.protocol);
|
|
|
|
- buttonView.setChecked(true);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
|
|
|
|
- MainActivity.getInstance().getHoneyService().stopListener(item.protocol);
|
|
|
|
- }
|
|
|
|
- buttonView.setChecked(false);
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ });
|
|
return rowView;
|
|
return rowView;
|
|
}
|
|
}
|
|
|
|
|
|
- private void updateStatus(ServicesListItem item, ViewHolder holder){
|
|
|
|
- if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
|
|
|
|
|
|
+ private void updateStatus(ServicesListItem item, ViewHolder holder) {
|
|
|
|
+ if (MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
|
|
holder.activated.setChecked(true);
|
|
holder.activated.setChecked(true);
|
|
- if(!MainActivity.getInstance().hasProtocolAttacks(item.protocol)){
|
|
|
|
- if(Integer.valueOf(item.attacks) > 0) {
|
|
|
|
|
|
+ if (!MainActivity.getInstance().getHoneyService().hasProtocolActiveAttacks(item.protocol)) {
|
|
|
|
+ if (item.attacks > 0) {
|
|
setBackground(holder, R.drawable.services_circle_yellow);
|
|
setBackground(holder, R.drawable.services_circle_yellow);
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
setBackground(holder, R.drawable.services_circle_green);
|
|
setBackground(holder, R.drawable.services_circle_green);
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- if(MainActivity.getInstance().hasProtocolAttacks(item.protocol)){
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if (MainActivity.getInstance().getHoneyService().hasProtocolActiveAttacks(item.protocol)) {
|
|
setBackground(holder, R.drawable.services_circle_red);
|
|
setBackground(holder, R.drawable.services_circle_red);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else if(Integer.valueOf(item.attacks) > 0){
|
|
|
|
|
|
+ } else if (item.attacks > 0) {
|
|
holder.activated.setChecked(false);
|
|
holder.activated.setChecked(false);
|
|
setBackground(holder, R.drawable.services_circle_yellow);
|
|
setBackground(holder, R.drawable.services_circle_yellow);
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
holder.activated.setChecked(false);
|
|
holder.activated.setChecked(false);
|
|
setBackground(holder, R.drawable.services_circle);
|
|
setBackground(holder, R.drawable.services_circle);
|
|
}
|
|
}
|
|
- holder.recordedAttacks.setText(String.format(MainActivity.getContext().getResources().getString(R.string.recorded_attacks) + " %d", Integer.valueOf(item.attacks)));
|
|
|
|
|
|
+ holder.recordedAttacks
|
|
|
|
+ .setText(String.format(MainActivity.getContext().getResources().getString(R.string.recorded_attacks) + " %d", Integer.valueOf(item.attacks)));
|
|
}
|
|
}
|
|
|
|
|
|
- private void setBackground(ViewHolder holder, int drawable){
|
|
|
|
- if(sdk < Build.VERSION_CODES.JELLY_BEAN){
|
|
|
|
|
|
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
|
|
|
+ private void setBackground(ViewHolder holder, int drawable) {
|
|
|
|
+ if (sdk < Build.VERSION_CODES.JELLY_BEAN) {
|
|
holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(drawable));
|
|
holder.circle.setBackgroundDrawable(MainActivity.getInstance().getResources().getDrawable(drawable));
|
|
- }
|
|
|
|
- else {
|
|
|
|
- holder.circle.setBackground(MainActivity.getInstance().getResources()
|
|
|
|
- .getDrawable(drawable));
|
|
|
|
|
|
+ } else {
|
|
|
|
+ holder.circle.setBackground(MainActivity.getInstance().getResources().getDrawable(drawable));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|