Prechádzať zdrojové kódy

connection info in services and home. learned and followed alex way of fragment injection

Fabio Arnold 11 rokov pred
rodič
commit
b003ea9078

+ 1 - 1
res/layout/fragment_services.xml

@@ -23,7 +23,7 @@
                 android:textStyle="bold" />
 
         <ImageView
-                android:id="@+id/imageView2"
+                android:id="@+id/services_button_connection_info"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentEnd="true"

+ 29 - 4
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ConnectionInfoDialogFragment.java

@@ -4,6 +4,7 @@ import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.view.ContextThemeWrapper;
@@ -11,33 +12,57 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.TextView;
 
+import java.util.ArrayList;
+
 import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.ui.LogFilter;
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 
 /**
  * Created by Fabio Arnold on 03.03.14.
  */
 public class ConnectionInfoDialogFragment extends DialogFragment {
 	public Dialog onCreateDialog(Bundle savedInstance) {
+		// get connection infos
 		SharedPreferences sharedPreferences = getActivity().getSharedPreferences(getString(R.string.connection_info), Context.MODE_PRIVATE);
-		String ssid = sharedPreferences.getString(getString(R.string.connection_info_ssid), "");
+		final String ssid = sharedPreferences.getString(getString(R.string.connection_info_ssid), "");
 		String bssid = sharedPreferences.getString(getString(R.string.connection_info_bssid), "");
 		String internalIP = sharedPreferences.getString(getString(R.string.connection_info_internal_ip), "");
 		String externalIP = sharedPreferences.getString(getString(R.string.connection_info_external_ip), "");
 
+		// inflate the layout with a dark theme
 		Context context = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo);
 		LayoutInflater localInflater = getActivity().getLayoutInflater().cloneInContext(context);
-
-		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK);
 		View view = localInflater.inflate(R.layout.fragment_connectioninfo_dialog, null);
 
+		// assign values in layout
 		((TextView)view.findViewById(R.id.connectioninfo_ssid_value)).setText(ssid);
 		((TextView)view.findViewById(R.id.connectioninfo_bssid_value)).setText(bssid);
 		((TextView)view.findViewById(R.id.connectioninfo_internalip_value)).setText(internalIP);
 		((TextView)view.findViewById(R.id.connectioninfo_externalip_value)).setText(externalIP);
+
+		// build the dialog
+		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK);
 		builder.setView(view);
 		builder.setTitle(R.string.title_connection_info);
-		builder.setPositiveButton(R.string.show_records, null);
+		builder.setPositiveButton(R.string.show_records, new DialogInterface.OnClickListener() {
+			@Override
+			public void onClick(DialogInterface dialog, int which) {
+				ArrayList<String> ssids = new ArrayList<String>();
+				ssids.add(ssid);
+
+				LogFilter filter = new LogFilter();
+				filter.setESSIDs(ssids);
+
+				RecordOverviewFragment recordOverviewFragment = new RecordOverviewFragment();
+				recordOverviewFragment.setFilter(filter);
+				recordOverviewFragment.setGroupKey("ESSID");
+
+				MainActivity.getInstance().injectFragment(recordOverviewFragment, false);
+			}
+		});
 		builder.setNegativeButton(R.string.close, null);
+
 		return builder.create();
 	}
 }

+ 8 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ServicesFragment.java

@@ -48,6 +48,14 @@ public class ServicesFragment extends Fragment{
 	private void assignViews(){
 		mServicesSwitchService = (Switch) rootView.findViewById(R.id.service_switch_connection);
 		mServicesTextName = (TextView) rootView.findViewById(R.id.services_text_name);
+
+		rootView.findViewById(R.id.services_button_connection_info).setOnClickListener(new View.OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				ConnectionInfoDialogFragment connectionInfoDialogFragment = new ConnectionInfoDialogFragment();
+				connectionInfoDialogFragment.show(getFragmentManager().beginTransaction(), connectionInfoDialogFragment.getTag());
+			}
+		});
 	}
 
 	public void updateUI(){

+ 17 - 11
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ThreatMapFragment.java

@@ -77,18 +77,24 @@ public class ThreatMapFragment extends Fragment implements GoogleMap.OnInfoWindo
 	 */
 	@Override
 	public void onInfoWindowClick(Marker marker) {
-		MainActivity.getInstance().displayView(MainActivity.MainMenuItem.RECORDS.getValue());
-		RecordOverviewFragment recordOverviewFragment = (RecordOverviewFragment)MainActivity.getInstance().getCurrentFragment();
-		if (recordOverviewFragment != null) {
-			String ssid = sMarkerIDToSSID.get(marker.getId());
-			ArrayList<String> ssids = new ArrayList<String>();
-			ssids.add(ssid);
-			LogFilter filter = new LogFilter();
-			filter.setESSIDs(ssids);
-			recordOverviewFragment.setFilter(filter);
-			recordOverviewFragment.setGroupKey("ESSID");
+		//MainActivity.getInstance().displayView(MainActivity.MainMenuItem.RECORDS.getValue());
+		//RecordOverviewFragment recordOverviewFragment = (RecordOverviewFragment)MainActivity.getInstance().getCurrentFragment();
+		//if (recordOverviewFragment != null) {
+		String ssid = sMarkerIDToSSID.get(marker.getId());
+
+		ArrayList<String> ssids = new ArrayList<String>();
+		ssids.add(ssid);
+
+		LogFilter filter = new LogFilter();
+		filter.setESSIDs(ssids);
+
+		RecordOverviewFragment recordOverviewFragment = new RecordOverviewFragment();
+		recordOverviewFragment.setFilter(filter);
+		recordOverviewFragment.setGroupKey("ESSID");
+
+		MainActivity.getInstance().injectFragment(recordOverviewFragment, false);
 			//recordOverviewFragment.showDetailsForSSID(getActivity(), ssid);
-		}
+		//}
 	}
 
 	/**