Browse Source

improved the settings fragment a bit

Alexander Brakowski 10 years ago
parent
commit
08a66c91b3

+ 2 - 0
TODO

@@ -0,0 +1,2 @@
+! [Overview]    Greeting animation only to show on application start, not on every fragment creation/recreating
+! [Statistics]  Switch to records view on record click

+ 2 - 2
res/layout/fragment_settings.xml

@@ -27,14 +27,14 @@
 				android:layout_height="wrap_content"
 				android:textAppearance="?android:attr/textAppearanceMedium"
 				android:text="Yes"
-				android:id="@+id/textView3" android:layout_above="@+id/textView2"
+				android:id="@+id/settings_device_rooted" android:layout_above="@+id/textView2"
 				android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
 		<TextView
 				android:layout_width="wrap_content"
 				android:layout_height="wrap_content"
 				android:textAppearance="?android:attr/textAppearanceMedium"
 				android:text="Yes"
-				android:id="@+id/textView4" android:layout_below="@+id/textView3"
+				android:id="@+id/settings_porthack_installed" android:layout_below="@+id/settings_device_rooted"
 				android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
 	</RelativeLayout>
 	<FrameLayout

+ 8 - 8
src/de/tudarmstadt/informatik/hostage/HoneyService.java

@@ -350,14 +350,14 @@ public class HoneyService extends Service {
 					&& listener.getPort() == port) {
 				if (!listener.isRunning()) {
 					if (listener.start()) {
-						Toast.makeText(getApplicationContext(),
+						/*Toast.makeText(getApplicationContext(),
 								protocolName + " SERVICE STARTED!",
-								Toast.LENGTH_SHORT).show();
+								Toast.LENGTH_SHORT).show();*/
 						return true;
 					}
-					Toast.makeText(getApplicationContext(),
+					/*Toast.makeText(getApplicationContext(),
 							protocolName + " SERVICE COULD NOT BE STARTED!",
-							Toast.LENGTH_SHORT).show();
+							Toast.LENGTH_SHORT).show();*/
 					return false;
 				}
 
@@ -366,15 +366,15 @@ public class HoneyService extends Service {
 		HoneyListener listener = createListener(protocolName, port);
 		if (listener != null) {
 			if (listener.start()) {
-				Toast.makeText(getApplicationContext(),
+				/*Toast.makeText(getApplicationContext(),
 						protocolName + " SERVICE STARTED!", Toast.LENGTH_SHORT)
-						.show();
+						.show();*/
 				return true;
 			}
 		}
-		Toast.makeText(getApplicationContext(),
+		/*Toast.makeText(getApplicationContext(),
 				protocolName + " SERVICE COULD NOT BE STARTED!",
-				Toast.LENGTH_SHORT).show();
+				Toast.LENGTH_SHORT).show();*/
 		return false;
 	}
 

+ 60 - 1
src/de/tudarmstadt/informatik/hostage/ui2/fragment/PreferenceHostageFrament.java

@@ -1,19 +1,78 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
+import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.preference.Preference;
 import android.preference.PreferenceFragment;
 
+import java.util.HashMap;
+
 import de.tudarmstadt.informatik.hostage.R;
 
 /**
  * @author Alexander Brakowski
  * @created 02.03.14 21:03
  */
-public class PreferenceHostageFrament extends PreferenceFragment {
+public class PreferenceHostageFrament extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
+	private HashMap<String, String> mSuffixMap;
+	private String[] mTextPreferences;
+
 	@Override
 	public void onCreate(Bundle savedInstanceState){
 		super.onCreate(savedInstanceState);
 
+		this.mTextPreferences = new String[]{
+			"pref_external_location",
+			"pref_upload_server",
+			"pref_max_connections",
+			"pref_timeout",
+			"pref_sleeptime",
+			"pref_location_time",
+			"pref_location_retries"
+		};
+
+		this.mSuffixMap = new HashMap<String, String>();
+		this.mSuffixMap.put("pref_timeout", "s");
+		this.mSuffixMap.put("pref_sleeptime", "ms");
+		this.mSuffixMap.put("pref_location_time", "ms");
+
 		addPreferencesFromResource(R.xml.settings_preferences);
+
+		for(String k: this.mTextPreferences){
+			updatePreferenceSummary(k);
+		}
+	}
+
+	private void updatePreferenceSummary(String key){
+		Preference p = findPreference(key);
+		SharedPreferences sharedPreferences = this.getPreferenceManager().getSharedPreferences();
+
+		if(p != null && p instanceof EditTextPreference){
+			String suffix = "";
+
+			if(this.mSuffixMap.containsKey(key)){
+				suffix = this.mSuffixMap.get(key);
+			}
+
+			p.setSummary(sharedPreferences.getString(key, "") + " " + suffix);
+		}
+	}
+
+	@Override
+	public void onResume() {
+		super.onResume();
+		getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+	}
+
+	@Override
+	public void onPause() {
+		getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
+		super.onPause();
+	}
+
+	@Override
+	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+		updatePreferenceSummary(key);
 	}
 }

+ 24 - 2
src/de/tudarmstadt/informatik/hostage/ui2/fragment/SettingsFragment.java

@@ -3,12 +3,13 @@ package de.tudarmstadt.informatik.hostage.ui2.fragment;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.os.Bundle;
-import android.preference.PreferenceFragment;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.TextView;
 
 import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 
 /**
  * @author Alexander Brakowski
@@ -17,7 +18,28 @@ import de.tudarmstadt.informatik.hostage.R;
 public class SettingsFragment extends Fragment {
 	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
 		super.onCreateView(inflater, container, savedInstanceState);
-		return inflater.inflate(R.layout.fragment_settings, container, false);
+		View v = inflater.inflate(R.layout.fragment_settings, container, false);
+
+		TextView rootedText = (TextView) v.findViewById(R.id.settings_device_rooted);
+		TextView porthackText = (TextView) v.findViewById(R.id.settings_porthack_installed);
+
+		if(MainActivity.isRooted){
+			rootedText.setText("Yes");
+			rootedText.setTextColor(getResources().getColor(R.color.holo_dark_green));
+		} else {
+			rootedText.setText("No");
+			rootedText.setTextColor(getResources().getColor(R.color.holo_red));
+		}
+
+		if(MainActivity.porthackInstalled){
+			porthackText.setText("Yes");
+			porthackText.setTextColor(getResources().getColor(R.color.holo_dark_green));
+		} else {
+			porthackText.setText("No");
+			porthackText.setTextColor(getResources().getColor(R.color.holo_red));
+		}
+
+		return v;
 	}
 
 	public void onViewCreated(View view, Bundle savedInstanceState) {