Browse Source

added settings fragment, and added a create new button to the action button to the action bar

Alexander Brakowski 10 years ago
parent
commit
b8fff452a9

BIN
res/drawable-hdpi/ic_action_new.png


BIN
res/drawable-hdpi/ic_menu_records.png


BIN
res/drawable-mdpi/ic_action_new.png


BIN
res/drawable-mdpi/ic_menu_records.png


BIN
res/drawable-xhdpi/ic_action_new.png


BIN
res/drawable-xhdpi/ic_menu_records.png


BIN
res/drawable-xxhdpi/ic_menu_records.png


+ 7 - 0
res/menu/profile_manager_actions.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+	<item android:id="@+id/profile_manager_action_add"
+		  android:icon="@drawable/ic_action_new"
+		  android:title="New profile" />
+</menu>

+ 1 - 0
res/values/strings.xml

@@ -43,6 +43,7 @@
     <string name="drawer_settings">Settings</string>
     <string name="drawer_profile_manager">Profile Manager</string>
     <string name="drawer_app_info">Application info</string>
+	<string name="drawer_statistics">Statistics</string>
 
     <string name="button_title_apply">Apply</string>
     <string name="button_title_cancel">Cancel</string>

+ 5 - 5
res/xml/preferences.xml

@@ -38,18 +38,18 @@
             android:showSilent="true"
             android:summary="@string/pref_alarm_summ"
             android:title="@string/pref_alarm" />
-    </PreferenceCategory>    
+    </PreferenceCategory>
     <PreferenceCategory android:title="@string/pref_connection_settings" >
         <EditTextPreference
             android:key="pref_max_connections"
             android:defaultValue="@string/pref_max_connections_default"
             android:title="@string/pref_max_connections" />
-               
+
           <EditTextPreference
             android:key="pref_timeout"
             android:defaultValue="@string/pref_timeout_default"
             android:title="@string/pref_timeout" />
-          
+
           <EditTextPreference
             android:key="pref_sleeptime"
             android:defaultValue="@string/pref_sleeptime_default"
@@ -60,12 +60,12 @@
             android:key="pref_location_time"
             android:defaultValue="@string/pref_location_time_default"
             android:title="@string/pref_location_time" />
-               
+
           <EditTextPreference
             android:key="pref_location_retries"
             android:defaultValue="@string/pref_location_retries_default"
             android:title="@string/pref_location_retries" />
-          
+
     </PreferenceCategory>
 
 

+ 85 - 0
res/xml/settings_preferences.xml

@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+
+	<CheckBoxPreference
+		android:defaultValue="false"
+	    android:key="pref_general_expert"
+	    android:summary="This will activate some expert functionalities."
+	    android:title="Expert Mode"/>
+
+
+	<PreferenceCategory android:title="@string/pref_notification" >
+		<CheckBoxPreference
+				android:defaultValue="true"
+				android:key="pref_vibration"
+				android:summary="@string/pref_vibration_summ"
+				android:title="@string/pref_vibration" />
+
+		<RingtonePreference
+				android:defaultValue="content://settings/system/notification_sound"
+				android:key="pref_notification_sound"
+				android:ringtoneType="notification"
+				android:showDefault="true"
+				android:showSilent="true"
+				android:summary="@string/pref_alarm_summ"
+				android:title="@string/pref_alarm" />
+	</PreferenceCategory>
+
+	<PreferenceCategory android:title="Advanced Settings">
+		<PreferenceScreen
+				android:key="pref_advanced settings"
+				android:title="Advanced Settings"
+				android:persistent="false">
+			<PreferenceCategory android:title="@string/pref_storage" >
+				<CheckBoxPreference
+						android:defaultValue="false"
+						android:key="pref_external_storage"
+						android:summary="@string/pref_external_storage_summ"
+						android:title="@string/pref_external_storage_title" />
+
+				<EditTextPreference
+						android:key="pref_external_location"
+						android:dependency="pref_external_storage"
+						android:defaultValue="/HosTaGe/LogFiles/"
+						android:title="@string/pref_external_location_title"
+						/>
+
+			</PreferenceCategory>
+			<PreferenceCategory android:title="@string/pref_upload" >
+				<EditTextPreference
+						android:key="pref_upload_server"
+						android:defaultValue="https://ssi.cased.de"
+						android:title="@string/pref_upload_server" />
+
+			</PreferenceCategory>
+			<PreferenceCategory android:title="@string/pref_connection_settings" >
+				<EditTextPreference
+						android:key="pref_max_connections"
+						android:defaultValue="@string/pref_max_connections_default"
+						android:title="@string/pref_max_connections" />
+
+				<EditTextPreference
+						android:key="pref_timeout"
+						android:defaultValue="@string/pref_timeout_default"
+						android:title="@string/pref_timeout" />
+
+				<EditTextPreference
+						android:key="pref_sleeptime"
+						android:defaultValue="@string/pref_sleeptime_default"
+						android:title="@string/pref_sleeptime" />
+			</PreferenceCategory>
+			<PreferenceCategory android:title="@string/pref_location_settings" >
+				<EditTextPreference
+						android:key="pref_location_time"
+						android:defaultValue="@string/pref_location_time_default"
+						android:title="@string/pref_location_time" />
+
+				<EditTextPreference
+						android:key="pref_location_retries"
+						android:defaultValue="@string/pref_location_retries_default"
+						android:title="@string/pref_location_retries" />
+
+			</PreferenceCategory>
+		</PreferenceScreen>
+	</PreferenceCategory>
+</PreferenceScreen>

+ 6 - 0
src/de/tudarmstadt/informatik/hostage/model/Profile.java

@@ -22,6 +22,12 @@ public class Profile {
 	public boolean mIsBackVisible = false;
 	public boolean mEditable = false;
 
+	public Profile(){
+		this.mEditable = true;
+		this.mActivated = false;
+		this.mId = -1;
+	}
+
 	public Profile(int id, String label, String text, Bitmap icon, boolean editable){
 		this.mId = id;
 		this.mLabel = text;

+ 10 - 5
src/de/tudarmstadt/informatik/hostage/ui2/activity/MainActivity.java

@@ -34,6 +34,7 @@ import de.tudarmstadt.informatik.hostage.ui2.fragment.HomeFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.ProfileManagerFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.RecordOverviewFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.ServicesFragment;
+import de.tudarmstadt.informatik.hostage.ui2.fragment.SettingsFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.StatisticsFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.ThreatMapFragment;
 import de.tudarmstadt.informatik.hostage.ui2.fragment.opengl.ThreatIndicatorGLRenderer;
@@ -155,7 +156,8 @@ public class MainActivity extends Activity {
 		mDrawerItems = new ArrayList<DrawerListItem>();
 		mDrawerItems.add(new DrawerListItem(R.string.drawer_overview, R.drawable.ic_menu_home));
 		mDrawerItems.add(new DrawerListItem(R.string.drawer_threat_map, R.drawable.ic_menu_mapmode));
-		mDrawerItems.add(new DrawerListItem(R.string.drawer_records, R.drawable.ic_action_stats));
+		mDrawerItems.add(new DrawerListItem(R.string.drawer_records, R.drawable.ic_menu_records));
+		mDrawerItems.add(new DrawerListItem(R.string.drawer_statistics, R.drawable.ic_menu_stats));
 		mDrawerItems.add(new DrawerListItem(R.string.drawer_services, R.drawable.ic_menu_set_as));
 		mDrawerItems.add(
 				new DrawerListItem(R.string.drawer_profile_manager, R.drawable.ic_menu_allfriends));
@@ -286,7 +288,7 @@ public class MainActivity extends Activity {
 				fragment = new RecordOverviewFragment();
 				break;
             }
-            case STATISTICS:{
+            case STATISTICS: {
                 Intent intent = this.getIntent();
                 intent.removeExtra(LogFilter.LOG_FILTER_INTENT_KEY);
                 fragment = new StatisticsFragment();
@@ -298,6 +300,9 @@ public class MainActivity extends Activity {
 			case PROFILE_MANAGER:
 				fragment = new ProfileManagerFragment();
 				break;
+			case SETTINGS:
+				fragment = new SettingsFragment();
+				break;
 			default:
 				break;
 		}
@@ -385,9 +390,9 @@ public class MainActivity extends Activity {
         HOME(0),
         THREAT_MAP(1),
         RECORDS(2),
-        SERVICES(3),
-        PROFILE_MANAGER(4),
-        STATISTICS(5),
+		STATISTICS(3),
+        SERVICES(4),
+        PROFILE_MANAGER(5),
         SETTINGS(6),
         APPLICATION_INFO(7);
 

+ 26 - 10
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileEditFragment.java

@@ -54,12 +54,18 @@ public class ProfileEditFragment extends PreferenceFragment implements
 				ProfileManager pmanager = ProfileManager.getInstance();
 
 				Profile profile = getProfile();
+
 				boolean createNew = false;
 
-				if(!profile.isEditable()){
-					profile = profile.cloneProfile();
-					profile.mEditable = true;
+				if(profile == null){
+					profile = new Profile();
 					createNew = true;
+				} else {
+					if(!profile.isEditable()){
+						profile = profile.cloneProfile();
+						profile.mEditable = true;
+						createNew = true;
+					}
 				}
 
 				profile.mLabel = prefs.getString("pref_profile_general_name", profile.mLabel);
@@ -87,14 +93,22 @@ public class ProfileEditFragment extends PreferenceFragment implements
 		Profile profile = getProfile();
 		prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
 
-		if(profile != null){
-			prefs.putString("pref_profile_general_name", profile.mLabel);
-			prefs.putString("pref_profile_general_image", profile.mIconPath);
-			prefs.putString("pref_profile_general_description", profile.mText);
+		String pname = "",
+			   pimage = "",
+			   pdesc = "";
 
-			prefs.commit();
+		if(profile != null){
+			pname = profile.mLabel;
+			pimage = profile.mIconPath;
+			pdesc = profile.mText;
 		}
 
+		prefs.putString("pref_profile_general_name", pname);
+		prefs.putString("pref_profile_general_image", pimage);
+		prefs.putString("pref_profile_general_description", pdesc);
+
+		prefs.commit();
+
 		addPreferencesFromResource(R.xml.profile_preferences);
 
 		Preference pref = findPreference("pref_profile_general_image");
@@ -119,8 +133,10 @@ public class ProfileEditFragment extends PreferenceFragment implements
 				}
 		);
 
-		findPreference("pref_profile_general_name").setSummary(profile.mLabel);
-		findPreference("pref_profile_general_description").setSummary(profile.mText);
+		if(profile != null){
+			findPreference("pref_profile_general_name").setSummary(profile.mLabel);
+			findPreference("pref_profile_general_description").setSummary(profile.mText);
+		}
 	}
 
 	public Profile getProfile(){

+ 25 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileManagerFragment.java

@@ -1,8 +1,12 @@
 package de.tudarmstadt.informatik.hostage.ui2.fragment;
 
 import android.app.Fragment;
+import android.content.Intent;
 import android.os.Bundle;
 import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 
@@ -14,6 +18,7 @@ import java.util.List;
 import de.tudarmstadt.informatik.hostage.R;
 import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
 import de.tudarmstadt.informatik.hostage.model.Profile;
+import de.tudarmstadt.informatik.hostage.ui2.activity.ProfileEditActivity;
 import de.tudarmstadt.informatik.hostage.ui2.adapter.ProfileManagerListAdapter;
 
 /**
@@ -30,6 +35,7 @@ public class ProfileManagerFragment extends Fragment {
                              Bundle savedInstanceState) {
 
 	    super.onCreateView(inflater, container, savedInstanceState);
+	    setHasOptionsMenu(true);
 
         View rootView = inflater.inflate(R.layout.fragment_profile_manager, container, false);
 	    SwipeListView list = (SwipeListView) rootView.findViewById(R.id.profile_manager_listview);
@@ -62,4 +68,23 @@ public class ProfileManagerFragment extends Fragment {
 		super.onResume();
 		mAdapter.notifyDataSetChanged();
 	}
+
+	@Override
+	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+		// Inflate the menu items for use in the action bar
+		inflater.inflate(R.menu.profile_manager_actions, menu);
+	}
+
+	@Override
+	public boolean onOptionsItemSelected(MenuItem item) {
+		switch(item.getItemId()){
+			case R.id.profile_manager_action_add:
+				Intent intent = new Intent(getActivity(), ProfileEditActivity.class);
+				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+				getActivity().startActivity(intent);
+				return true;
+		}
+
+		return false;
+	}
 }

+ 20 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/SettingsFragment.java

@@ -0,0 +1,20 @@
+package de.tudarmstadt.informatik.hostage.ui2.fragment;
+
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+import de.tudarmstadt.informatik.hostage.R;
+
+/**
+ * @author Alexander Brakowski
+ * @created 24.02.14 23:37
+ */
+public class SettingsFragment extends PreferenceFragment {
+
+	@Override
+	public void onCreate(Bundle savedInstanceState){
+		super.onCreate(savedInstanceState);
+
+		addPreferencesFromResource(R.xml.settings_preferences);
+	}
+}