Browse Source

made everything right again

Alexander Brakowski 10 years ago
parent
commit
133db3adee

+ 2 - 29
AndroidManifest.xml

@@ -40,7 +40,7 @@
 				android:value="14"/>
 		<meta-data
 				android:name="com.google.android.maps.v2.API_KEY"
-				android:value="AIzaSyDZ-Zr6u5wXwpVIQ_7-J9e82BF_lESvWes"/>
+				android:value="AIzaSyCLAiF5Dx6qkDwWUfNnteMcapILmjCbuZ0"/>
 		<activity
 				android:name="de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity"
 				android:configChanges="keyboardHidden|orientation|screenSize"
@@ -65,7 +65,7 @@
             android:label="@string/database" >
         </activity>
 	    <activity
-			    android:name="de.tudarmstadt.informatik.hostage.ui2.preference.ProfileEditActivity"
+			    android:name=".ui2.activity.ProfileEditActivity"
 			    android:label="Edit Profile" >
 	    </activity>
         <activity
@@ -103,33 +103,6 @@
 			android:label="@string/database" >
 		</activity>
 		-->
-		<activity
-				android:name="de.tudarmstadt.informatik.hostage.ui2.preference.ProfileEditActivity"
-				android:label="Edit Profile">
-		</activity>
-		<activity
-				android:name="de.tudarmstadt.informatik.hostage.ui.SettingsActivity"
-				android:label="@string/settings">
-		</activity>
-		<activity
-				android:name="de.tudarmstadt.informatik.hostage.ui.AboutActivity"
-				android:label="@string/gui_action_about">
-		</activity>
-		<activity
-				android:name="de.tudarmstadt.informatik.hostage.ui.PlayGroundActivity"
-				android:label="@string/gui_playground">
-		</activity>
-		<activity
-				android:name="de.tudarmstadt.informatik.hostage.sync.NFCSync"
-				android:label="@string/gui_playground">
-			<intent-filter>
-				<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
-
-				<category android:name="android.intent.category.DEFAULT"/>
-
-				<data android:mimeType="application/de.tudarmstadt.informatik.hostage"/>
-			</intent-filter>
-		</activity>
 
 		<service android:name="de.tudarmstadt.informatik.hostage.HoneyService">
 		</service>

+ 82 - 0
src/de/tudarmstadt/informatik/hostage/dao/ProfileManager.java

@@ -0,0 +1,82 @@
+package de.tudarmstadt.informatik.hostage.dao;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.model.Profile;
+import de.tudarmstadt.informatik.hostage.ui2.model.ProfileListItem;
+
+/**
+ * @author Alexander Brakowski
+ * @created 10.02.14 20:24
+ */
+public class ProfileManager {
+	private static ProfileManager INSTANCE = null;
+
+	private Map<Integer, Profile> mProfiles;
+
+	public static ProfileManager getInstance(){
+		if(INSTANCE == null){
+			INSTANCE = new ProfileManager();
+		}
+
+		return INSTANCE;
+	}
+
+	private ProfileManager(){
+		this.mProfiles = new HashMap<Integer, Profile>();
+		this.mProfiles.put(0, new Profile(
+				0,
+				"Windows Vista",
+				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+				R.drawable.ic_profile_vista));
+
+		this.mProfiles.put(1, new Profile(
+				1,
+				"Windows 7",
+				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+				R.drawable.ic_profile_w7));
+
+		this.mProfiles.put(2, new Profile(
+				2,
+				"Unix Distro",
+				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+				R.drawable.ic_profile_unix));
+
+		this.mProfiles.put(3, new Profile(
+				3,
+				"Random",
+				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+				R.drawable.ic_service_green));
+
+		this.mProfiles.put(4, new Profile(
+				4,
+				"Mix",
+				"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+				R.drawable.ic_service_green));
+	}
+
+	public List<Profile> getProfilesList(){
+		return new ArrayList<Profile>(getProfilesCollection());
+	}
+
+	public Collection<Profile> getProfilesCollection(){
+		return mProfiles.values();
+	}
+
+	public Map<Integer, Profile> getMapProfiles(){
+		return mProfiles;
+	}
+
+	public Profile getProfile(int id){
+		if(this.mProfiles.containsKey(id)){
+			return this.mProfiles.get(id);
+		}
+
+		return null;
+	}
+}

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

@@ -0,0 +1,40 @@
+package de.tudarmstadt.informatik.hostage.model;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
+import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
+
+/**
+ * @author Alexander Brakowski
+ * @created 14.01.14 18:04
+ */
+public class Profile {
+	public String label;
+	public String text;
+	public int id;
+	public boolean activated;
+	public Bitmap icon;
+
+	public boolean isBackVisible = false;
+
+	public Profile(int id, String text, String label, Bitmap icon){
+		this.id = id;
+		this.text = text;
+		this.label = label;
+		this.activated = false;
+		this.icon = icon;
+	}
+
+	public Profile(int id, String text, String label, int icon){
+		this(id, text, label, BitmapFactory.decodeResource(MainActivity.context.getResources(), icon));
+	}
+
+	public void setIcon(Bitmap bitmap){
+		this.icon = bitmap;
+	}
+
+	public void setIcon(int icon){
+		this.icon = BitmapFactory.decodeResource(MainActivity.context.getResources(), icon);
+	}
+}

+ 2 - 6
src/de/tudarmstadt/informatik/hostage/ui2/preference/ProfileEditActivity.java → src/de/tudarmstadt/informatik/hostage/ui2/activity/ProfileEditActivity.java

@@ -1,13 +1,9 @@
-package de.tudarmstadt.informatik.hostage.ui2.preference;
+package de.tudarmstadt.informatik.hostage.ui2.activity;
 
-import android.content.Context;
 import android.os.Bundle;
 import android.preference.PreferenceActivity;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.LinearLayout;
 
-import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.ui2.fragment.ProfileEditFragment;
 
 /**
  * @author Alexander Brakowski

+ 7 - 8
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -5,28 +5,26 @@ import android.content.Intent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
 import android.widget.ArrayAdapter;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
-import android.widget.ViewSwitcher;
 
 import com.fortysevendeg.android.swipelistview.SwipeListView;
 
 import java.util.List;
 
 import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.model.Profile;
 import de.tudarmstadt.informatik.hostage.ui2.model.ProfileListItem;
-import de.tudarmstadt.informatik.hostage.ui2.preference.ProfileEditActivity;
+import de.tudarmstadt.informatik.hostage.ui2.activity.ProfileEditActivity;
 
 /**
  * @author Alexander Brakowski
  * @created 14.01.14 18:00
  */
-public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
+public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 	private class ViewHolder {
 		public TextView labelView;
 		public TextView textView;
@@ -37,9 +35,9 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
 	}
 
     private final Context context;
-    private final List<ProfileListItem> values;
+    private final List<Profile> values;
 
-    public ProfileManagerListAdapter(Context context, List<ProfileListItem> objects) {
+    public ProfileManagerListAdapter(Context context, List<Profile> objects) {
         super(context, R.layout.profile_manager_list_item, objects);
         this.context = context;
         this.values  = objects;
@@ -54,7 +52,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
         View rowView = convertView;
 	    ViewHolder holder = null;
 
-	    final ProfileListItem item = values.get(position);
+	    final Profile item = values.get(position);
 
 	    if(rowView == null){
 		    rowView = inflater.inflate(R.layout.profile_manager_list_item, parent, false);
@@ -83,6 +81,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<ProfileListItem> {
 			public void onClick(View v) {
 				Intent intent = new Intent(context, ProfileEditActivity.class);
 				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+				intent.putExtra("profile_id", item.id);
 				context.startActivity(intent);
 			}
 		});

+ 91 - 0
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileEditFragment.java

@@ -0,0 +1,91 @@
+package de.tudarmstadt.informatik.hostage.ui2.fragment;
+
+import android.app.ActionBar;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+
+import de.tudarmstadt.informatik.hostage.R;
+import de.tudarmstadt.informatik.hostage.dao.ProfileManager;
+import de.tudarmstadt.informatik.hostage.model.Profile;
+
+/**
+ * @author Alexander Brakowski
+ * @created 08.02.14 23:39
+ */
+public class ProfileEditFragment extends PreferenceFragment implements
+		SharedPreferences.OnSharedPreferenceChangeListener {
+
+	private LayoutInflater mInflater;
+
+	@Override
+	public void onCreate(Bundle savedInstanceState){
+		getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+		super.onCreate(savedInstanceState);
+
+		mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+		View actionBarButtons = mInflater.inflate(R.layout.actionbar_donebar, new LinearLayout(getActivity()), false);
+		getActivity().getActionBar().setCustomView(actionBarButtons);
+
+		Profile profile = getProfile();
+		SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
+
+		if(profile != null){
+
+			prefs.putString("pref_profile_general_name", profile.text);
+			prefs.commit();
+		}
+
+		addPreferencesFromResource(R.xml.profile_preferences);
+
+		findPreference("pref_profile_general_name").setSummary(profile.text);
+	}
+
+	public Profile getProfile(){
+		ProfileManager pmanager = ProfileManager.getInstance();
+
+		Intent intent = getActivity().getIntent();
+		int profile_id = intent.getIntExtra("profile_id", -1);
+
+		if(profile_id != -1){
+			return pmanager.getProfile(profile_id);
+		}
+
+		return null;
+	}
+
+	@Override
+	public void onResume() {
+		super.onResume();
+		getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+	}
+
+	@Override
+	public void onPause() {
+		getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
+		super.onPause();
+	}
+
+	/**
+	 * Called when a shared preference is changed, added, or removed. This
+	 * may be called even if a preference is set to its existing value.
+	 *
+	 * <p>This callback will be run on your main thread.
+	 *
+	 * @param sharedPreferences The {@link android.content.SharedPreferences} that received
+	 *                          the change.
+	 * @param key               The key of the preference that was changed, added, or
+	 */
+	@Override
+	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+		Log.i("settings", "preference changed: " + key);
+	}
+}

+ 5 - 29
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileManagerFragment.java

@@ -10,8 +10,11 @@ import android.widget.ListView;
 import com.fortysevendeg.android.swipelistview.SwipeListView;
 
 import java.util.ArrayList;
+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.adapter.ProfileManagerListAdapter;
 import de.tudarmstadt.informatik.hostage.ui2.model.ProfileListItem;
 
@@ -30,38 +33,11 @@ public class ProfileManagerFragment extends Fragment {
 	    super.onCreateView(inflater, container, savedInstanceState);
 
         View rootView = inflater.inflate(R.layout.fragment_profile_manager, container, false);
-
 	    SwipeListView list = (SwipeListView) rootView.findViewById(R.id.profile_manager_listview);
 
-	    list.setItemsCanFocus(false);
-
-        ArrayList<ProfileListItem> strList = new ArrayList<ProfileListItem>();
-
-
-        strList.add(new ProfileListItem(
-                "Windows Vista",
-		        "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-		        R.drawable.ic_profile_vista));
-
-	    strList.add(new ProfileListItem(
-			    "Windows 7",
-			    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-			    R.drawable.ic_profile_w7));
-
-        strList.add(new ProfileListItem(
-                "Unix Distro",
-		        "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-		        R.drawable.ic_profile_unix));
-
-        strList.add(new ProfileListItem(
-                "Random",
-		        "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-		        R.drawable.ic_service_green));
+		ProfileManager pmanager = ProfileManager.getInstance();
 
-	    strList.add(new ProfileListItem(
-			    "Mix",
-			    "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
-			    R.drawable.ic_service_green));
+        List<Profile> strList = pmanager.getProfilesList();
 
         ProfileManagerListAdapter adapter = new ProfileManagerListAdapter(getActivity().getBaseContext(), strList);
         list.setAdapter(adapter);

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

@@ -1,10 +0,0 @@
-package de.tudarmstadt.informatik.hostage.ui2.model;
-
-/**
- * @author Alexander Brakowski
- * @created 08.02.14 18:33
- */
-public class Profile {
-
-
-}

+ 0 - 34
src/de/tudarmstadt/informatik/hostage/ui2/preference/ProfileEditFragment.java

@@ -1,34 +0,0 @@
-package de.tudarmstadt.informatik.hostage.ui2.preference;
-
-import android.app.ActionBar;
-import android.content.Context;
-import android.os.Bundle;
-import android.preference.PreferenceFragment;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.LinearLayout;
-
-import de.tudarmstadt.informatik.hostage.R;
-
-/**
- * @author Alexander Brakowski
- * @created 08.02.14 23:39
- */
-public class ProfileEditFragment extends PreferenceFragment {
-
-	private LayoutInflater mInflater;
-
-	@Override
-	public void onCreate(Bundle savedInstanceState){
-		getActivity().getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
-		super.onCreate(savedInstanceState);
-
-		mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
-		View actionBarButtons = mInflater.inflate(R.layout.actionbar_donebar, new LinearLayout(getActivity()), false);
-		getActivity().getActionBar().setCustomView(actionBarButtons);
-
-		addPreferencesFromResource(R.xml.profile_preferences);
-	}
-
-}