Browse Source

added detail view in record overview

Julien Clauter 10 years ago
parent
commit
2f2da8d2c4

+ 10 - 0
res/layout/fragment_record_detail.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@android:color/transparent"
+    >
+
+
+</RelativeLayout>

+ 149 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordDetailFragment.java

@@ -0,0 +1,149 @@
+package de.tudarmstadt.informatik.hostage.ui2.fragment;
+
+import android.annotation.SuppressLint;
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.logging.Record;
+import de.tudarmstadt.informatik.hostage.logging.UglyDbHelper;
+
+/**
+ * Created by Julien on 02.03.14.
+ */
+public class RecordDetailFragment extends Fragment {
+
+    private class Location{
+        private double longitude;
+        private double latitude;
+        private float accuracy;
+
+        public double getLatitude() {
+            return latitude;
+        }
+        public void setLatitude(double latitude) {
+            this.latitude = latitude;
+        }
+        public float getAccuracy() {
+            return accuracy;
+        }
+        public void setAccuracy(float accuracy) {
+            this.accuracy = accuracy;
+        }
+        public double getLongitude(){
+            return this.longitude;
+        }
+        public void setLongitude(double longitude){
+            this.longitude = longitude;
+        }
+
+        public Location(){
+            super();
+        }
+        public Location(double latitude, double longitude, float accuracy){
+            super();
+            this.latitude = latitude;
+            this.longitude = longitude;
+            this.accuracy = accuracy;
+        }
+    }
+
+    private Record record;
+    private UglyDbHelper dbh;
+    private View rootView;
+
+    public void setRecord(Record rec){
+        this.record = rec;
+    }
+    public Record getRecord(){
+        return this.record;
+    }
+
+    public int getLayoutId(){
+        return R.layout.fragment_record_detail;
+    }
+
+
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setHasOptionsMenu(true);
+    }
+
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+                             Bundle savedInstanceState) {
+        super.onCreateView(inflater, container, savedInstanceState);
+
+        this.dbh = new UglyDbHelper(this.getActivity().getBaseContext());
+
+        this.rootView = inflater.inflate(this.getLayoutId(), container, false);
+        this.configurateRootView(rootView);
+
+
+        return rootView;
+    }
+
+    public void onStart() {
+        super.onStart();
+
+    }
+
+    private void configurateRootView(View rootView) {
+        String protocol = this.record.getProtocol();
+        String type = "" + this.record.getType();
+        String externalIP = this.record.getExternalIP();
+        String localIP = this.record.getLocalIP();
+        String localPort = "" + this.record.getLocalPort();
+        String remoteIP = this.record.getRemoteIP();
+        String bssid = this.record.getBssid() ;
+        String essid = this.record.getSsid();
+        double latitude = this.record.getLatitude();
+        double longitude = this.record.getLongitude();
+        float accuracy =this.record.getAccuracy();
+
+        Location  location = new Location(latitude, longitude, accuracy);
+
+        String packet = this.record.getPacket();
+        String timeStamp = this.getDateAsString(this.record.getTimestamp());
+
+    }
+
+
+    /*****************************
+     *
+     *          Date Transform
+     *
+     * ***************************/
+
+
+    @SuppressLint("SimpleDateFormat")
+    private String getDateAsString(long timeStamp) {
+
+        try {
+            DateFormat sdf = new SimpleDateFormat("H:mm d.M.yy");
+            Date netDate = (new Date(timeStamp));
+            return sdf.format(netDate);
+        } catch (Exception ex) {
+            return "xx";
+        }
+    }
+
+
+    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        super.onCreateOptionsMenu(menu, inflater);
+    }
+
+
+
+
+
+
+}

+ 35 - 31
src/de/tudarmstadt/informatik/hostage/ui2/fragment/RecordOverviewFragment.java

@@ -2,6 +2,8 @@ package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
 import android.annotation.SuppressLint;
 import android.app.Fragment;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
@@ -11,10 +13,8 @@ import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.AdapterView;
 import android.widget.ExpandableListView;
 import android.widget.ImageButton;
-import android.widget.Toast;
 
 import com.google.android.gms.maps.model.LatLng;
 
@@ -266,8 +266,11 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 
             ExpandableListItem item = new ExpandableListItem();
             item.setData(map);
+
             item.setId_Mapping(mapping);
 
+            item.setTag(val.getId());
+
             String groupID = this.getGroupValue(val);
 
             ArrayList<ExpandableListItem> items = sectionData.get(groupID);
@@ -311,37 +314,20 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	}
 
 	private void registerListClickCallback(ExpandableListView mylist) {
+        mylist.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
+            @Override
+            public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
+                RecordListAdapter adapter = (RecordListAdapter)expandableListView.getExpandableListAdapter();
 
-		mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-			public void onItemClick(AdapterView<?> parent, View viewClicked,
-					int position, long idInDB) {
-				UglyDbHelper dbh = new UglyDbHelper(getBaseContext());
-				Record rec = dbh.getRecord((int) idInDB);
-				String message = createInformationStringFromRecord(rec);
-				Toast.makeText(getApplicationContext(), message,
-						Toast.LENGTH_LONG).show();
-                // TODO add detail view in here
-                /*OPEN DETAIL VIEW*/
-			}
+                ExpandableListItem item = (ExpandableListItem)adapter.getChild(i,i2);
 
-			private String createInformationStringFromRecord(Record rec) {
-				String message = "id: " + rec.getId() + "\n" + "attack_id: "
-						+ rec.getAttack_id() + "\n" + "protocol: "
-						+ rec.getProtocol() + "\n" + "type: " + rec.getType()
-						+ "\n" + "externalIP: " + rec.getExternalIP() + "\n"
-						+ "localIP: " + rec.getLocalIP() + "\n"
-						+ "local port: " + rec.getLocalPort() + "\n"
-						+ "remoteIP: " + rec.getRemoteIP() + "\n" + "BSSID: "
-						+ rec.getBssid() + "\n" + "SSID: " + rec.getSsid()
-						+ "\n" + "latitude: " + rec.getLatitude() + "\n"
-						+ "longitude: " + rec.getLongitude() + "\n"
-						+ "accuracy: " + rec.getAccuracy() + "\n" + "packet: "
-						+ rec.getPacket() + "\n"
-						+ getDateAsString(rec.getTimestamp()) + "";
-				return message;
-			}
+                UglyDbHelper dbh = new UglyDbHelper(getBaseContext());
+                Record rec = dbh.getRecord((int) item.getTag());
+                RecordOverviewFragment.this.pushRecordDetailViewForRecord(rec);
+                return true;
+            }
+        });
 
-		});
 	}
 
 
@@ -357,7 +343,7 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
 	private String getDateAsString(long timeStamp) {
 
 		try {
-			DateFormat sdf = new SimpleDateFormat("H:mm  dd/MM/yyyy");
+			DateFormat sdf = new SimpleDateFormat("H:mm d.M.yy");
 			Date netDate = (new Date(timeStamp));
 			return sdf.format(netDate);
 		} catch (Exception ex) {
@@ -786,4 +772,22 @@ public class RecordOverviewFragment extends Fragment implements ChecklistDialog.
     }
 
 
+    /*Navigation*/
+    private void pushRecordDetailViewForRecord(Record record){
+
+        FragmentManager fm = this.getActivity().getFragmentManager();
+
+        if (fm != null){
+            RecordDetailFragment newFragment = new RecordDetailFragment();
+            newFragment.setRecord(record);
+
+            FragmentTransaction transaction = fm.beginTransaction();
+            transaction.replace(R.id.content_frame, newFragment, newFragment.getTag());
+            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
+            transaction.addToBackStack(null);
+
+            transaction.commit();
+        }
+
+    }
 }

+ 9 - 0
src/de/tudarmstadt/informatik/hostage/ui2/model/ExpandableListItem.java

@@ -14,6 +14,15 @@ public class ExpandableListItem {
     /*Data Key To Textual Information*/
     public HashMap<String, String> data;
 
+    public long getTag() {
+        return tag;
+    }
+    public void setTag(long tag) {
+        this.tag = tag;
+    }
+
+    private long tag;
+
 
 
     public HashMap<String, Integer> getId_Mapping() {