|
@@ -1,11 +1,14 @@
|
|
package de.tudarmstadt.informatik.hostage.ui2.adapter;
|
|
package de.tudarmstadt.informatik.hostage.ui2.adapter;
|
|
|
|
|
|
|
|
+import android.app.AlertDialog;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
+import android.content.DialogInterface;
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.ArrayAdapter;
|
|
|
|
+import android.widget.CompoundButton;
|
|
import android.widget.ImageButton;
|
|
import android.widget.ImageButton;
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
import android.widget.ListView;
|
|
import android.widget.ListView;
|
|
@@ -13,30 +16,35 @@ import android.widget.Switch;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
import android.widget.ViewSwitcher;
|
|
import android.widget.ViewSwitcher;
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.ui2.fragment.ServicesFragment;
|
|
import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
|
|
import de.tudarmstadt.informatik.hostage.ui2.model.ServicesListItem;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by Daniel Lazar on 06.02.14.
|
|
* Created by Daniel Lazar on 06.02.14.
|
|
*/
|
|
*/
|
|
public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
- private class ViewHolder {
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private class ViewHolder {
|
|
public TextView protocolName;
|
|
public TextView protocolName;
|
|
public TextView recordedAttacks;
|
|
public TextView recordedAttacks;
|
|
public Switch activated;
|
|
public Switch activated;
|
|
public View circle;
|
|
public View circle;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Context mActivity;
|
|
|
|
+ private Switch mServicesSwitch;
|
|
|
|
+ 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;
|
|
|
|
|
|
- ViewHolder holder = null;
|
|
|
|
- private ServicesListItem item;
|
|
|
|
-
|
|
|
|
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);
|
|
|
|
|
|
@@ -44,14 +52,21 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
this.values = objects;
|
|
this.values = objects;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void setActivity(Context activity, Switch servicesSwitch, CompoundButton.OnCheckedChangeListener mainListener) {
|
|
|
|
+ mActivity = activity;
|
|
|
|
+ mServicesSwitch = servicesSwitch;
|
|
|
|
+ mListener = mainListener;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
LayoutInflater inflater = (LayoutInflater) context
|
|
LayoutInflater inflater = (LayoutInflater) context
|
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
-
|
|
|
|
View rowView = convertView;
|
|
View rowView = convertView;
|
|
|
|
|
|
- item = values.get(position);
|
|
|
|
|
|
+ ViewHolder holder = null;
|
|
|
|
+
|
|
|
|
+ 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);
|
|
@@ -60,20 +75,62 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
holder.protocolName = (TextView) rowView.findViewById(R.id.services_item_name);
|
|
holder.protocolName = (TextView) rowView.findViewById(R.id.services_item_name);
|
|
holder.recordedAttacks = (TextView) rowView.findViewById(R.id.services_item_rec_attacks);
|
|
holder.recordedAttacks = (TextView) rowView.findViewById(R.id.services_item_rec_attacks);
|
|
holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
|
|
holder.activated = (Switch) rowView.findViewById(R.id.services_item_switch);
|
|
- holder.circle = (View) rowView.findViewById(R.id.services_circle);
|
|
|
|
- this.notifyDataSetChanged();
|
|
|
|
|
|
+ holder.circle = rowView.findViewById(R.id.services_circle);
|
|
rowView.setTag(holder);
|
|
rowView.setTag(holder);
|
|
|
|
+
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
holder = (ViewHolder) rowView.getTag();
|
|
holder = (ViewHolder) rowView.getTag();
|
|
}
|
|
}
|
|
|
|
|
|
holder.protocolName.setText(item.protocol);
|
|
holder.protocolName.setText(item.protocol);
|
|
|
|
+ holder.activated.setTag(item);
|
|
|
|
+
|
|
|
|
+ this.updateStatus(item, holder);
|
|
|
|
+
|
|
|
|
+ holder.activated.setOnCheckedChangeListener(
|
|
|
|
+ new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
+ ServicesListItem item = (ServicesListItem) buttonView.getTag();
|
|
|
|
+ System.out
|
|
|
|
+ .println("Protokoll: " + item.protocol);
|
|
|
|
+ System.out.println("Position: " + position);
|
|
|
|
+ if(!HelperUtils.isWifiConnected(mActivity)){
|
|
|
|
+ new AlertDialog.Builder(mActivity)
|
|
|
|
+ .setTitle("Information")
|
|
|
|
+ .setMessage("You are not connected to a WiFi network. \n\nPlease connect to one, before trying to activate HosTaGe.")
|
|
|
|
+ .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 {
|
|
|
|
+ if(isChecked){
|
|
|
|
+ if(!MainActivity.getInstance().getHoneyService().isRunning(item.protocol)) {
|
|
|
|
+ MainActivity.getInstance().getHoneyService().startListener(item.protocol);
|
|
|
|
+ mServicesSwitch.setOnCheckedChangeListener(null);
|
|
|
|
+ mServicesSwitch.setChecked(true);
|
|
|
|
+ mServicesSwitch.setOnCheckedChangeListener(mListener);
|
|
|
|
+ }
|
|
|
|
+ buttonView.setChecked(true);
|
|
|
|
+ } else {
|
|
|
|
+ if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
|
|
|
|
+ MainActivity.getInstance().getHoneyService().stopListener(item.protocol);
|
|
|
|
+ }
|
|
|
|
+ buttonView.setChecked(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
return rowView;
|
|
return rowView;
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public void notifyDataSetChanged(){
|
|
|
|
|
|
+ private void updateStatus(ServicesListItem item, ViewHolder holder){
|
|
if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
|
|
if(MainActivity.getInstance().getHoneyService().isRunning(item.protocol)){
|
|
holder.activated.setChecked(true);
|
|
holder.activated.setChecked(true);
|
|
if(sdk < Build.VERSION_CODES.JELLY_BEAN){
|
|
if(sdk < Build.VERSION_CODES.JELLY_BEAN){
|
|
@@ -94,4 +151,14 @@ public class ServicesListAdapter extends ArrayAdapter<ServicesListItem> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /*private void updateProtocolConnections(int connections, String protocolName, ServicesListAdapter adapter) {
|
|
|
|
+ for (int i = 0; i < adapter.getCount(); ++i) {
|
|
|
|
+ HashMap<String, String> d = ((HashMap<String, String>) adapter
|
|
|
|
+ .getItem(i));
|
|
|
|
+ if (d.get("protocol").equals(protocolName)) {
|
|
|
|
+ d.put("connections", String.valueOf(connections));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
|
+ }*/
|
|
}
|
|
}
|