Browse Source

Preparing to move profile manager from database to persisting to filesystem

Alexander Brakowski 10 năm trước cách đây
mục cha
commit
74eb808bbe

+ 1 - 0
res/xml/profile_preferences.xml

@@ -16,5 +16,6 @@
 		<Preference android:key="pref_profile_general_image"
 		            android:title="Icon"
 		            android:summary="Choose an icon for this profile" />
+
 	</PreferenceCategory>
 </PreferenceScreen>

+ 73 - 3
src/de/tudarmstadt/informatik/hostage/model/Profile.java

@@ -1,9 +1,18 @@
 package de.tudarmstadt.informatik.hostage.model;
 
+import android.content.Context;
+import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
 
 import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
 
@@ -11,12 +20,12 @@ import de.tudarmstadt.informatik.hostage.ui2.activity.MainActivity;
  * @author Alexander Brakowski
  * @created 14.01.14 18:04
  */
-public class Profile {
+public class Profile implements Serializable {
 	public String mText;
 	public String mLabel;
 	public int mId;
 	public boolean mActivated;
-	public Bitmap mIcon;
+	transient public Bitmap mIcon;
 	public int mIconId;
 	public String mIconName;
 
@@ -25,6 +34,8 @@ public class Profile {
 	public boolean mIsBackVisible = false;
 	public boolean mEditable = false;
 
+	public HashMap<String, Boolean> mActiveProtocols = new HashMap<String, Boolean>();
+
 	public Profile(){
 		this.mEditable = true;
 		this.mActivated = false;
@@ -55,6 +66,18 @@ public class Profile {
 		this.mEditable = editable;
 	}
 
+	public Profile(Parcel in) {
+		mText = in.readString();
+		mLabel = in.readString();
+		mId = in.readInt();
+		mActivated = in.readInt() == 1;
+		mIconId = in.readInt();
+		mIconName = in.readString();
+		mIconPath = in.readString();
+		mEditable = in.readInt() == 1;
+		mActiveProtocols = (HashMap<String,Boolean>) in.readSerializable();
+	}
+
 	public void setIcon(Bitmap bitmap){
 		this.mIcon = bitmap;
 	}
@@ -90,8 +113,13 @@ public class Profile {
 		return null;
 	}
 
+	public boolean isProtocolActive(String protocol){
+		if(!mActiveProtocols.containsKey(protocol)) return false;
+		return mActiveProtocols.get(protocol);
+	}
+
 	public Drawable getIconDrawable(){
-		return new BitmapDrawable(getIconBitmap());
+		return new BitmapDrawable(MainActivity.context.getResources(), getIconBitmap());
 	}
 
 	public boolean isEditable(){
@@ -101,4 +129,46 @@ public class Profile {
 	public Profile cloneProfile(){
 		return new Profile(mId, mLabel, mText, mIcon, mEditable);
 	}
+
+	/**
+	 * Describe the kinds of special objects contained in this Parcelable's
+	 * marshalled representation.
+	 *
+	 * @return a bitmask indicating the set of special object types marshalled
+	 * by the Parcelable.
+	 */
+	//@Override
+	public int describeContents() {
+		return 0;
+	}
+
+	/**
+	 * Flatten this object in to a Parcel.
+	 *
+	 * @param dest  The Parcel in which the object should be written.
+	 * @param flags Additional flags about how the object should be written.
+	 *              May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
+	 */
+	//@Override
+	public void writeToParcel(Parcel dest, int flags) {
+		dest.writeString(this.mText);
+		dest.writeString(this.mLabel);
+		dest.writeInt(this.mId);
+		dest.writeInt(this.mActivated ? 1 : 0);
+		dest.writeInt(this.mIconId);
+		dest.writeString(this.mIconName);
+		dest.writeString(this.mIconPath);
+		dest.writeInt(this.mEditable ? 1 : 0);
+		dest.writeSerializable(mActiveProtocols);
+	}
+
+	public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+		public Profile createFromParcel(Parcel in) {
+			return new Profile(in);
+		}
+
+		public Profile[] newArray(int size) {
+			return new Profile[size];
+		}
+	};
 }

+ 2 - 1
src/de/tudarmstadt/informatik/hostage/ui2/adapter/ProfileManagerListAdapter.java

@@ -92,7 +92,8 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
 			public void onClick(View v) {
 				Intent intent = new Intent(context, ProfileEditActivity.class);
 				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-				intent.putExtra("profile_id", item.mId);
+				//intent.putExtra("profile_id", item.mId);
+				intent.putExtra("profile", item);
 				context.startActivity(intent);
 			}
 		});

+ 5 - 3
src/de/tudarmstadt/informatik/hostage/ui2/fragment/ProfileEditFragment.java

@@ -145,13 +145,15 @@ public class ProfileEditFragment extends PreferenceFragment implements
 		ProfileManager pmanager = ProfileManager.getInstance();
 
 		Intent intent = getActivity().getIntent();
-		int profile_id = intent.getIntExtra("profile_id", -1);
+		Profile profile = (Profile) intent.getSerializableExtra("profile");
+
+		/*int profile_id = intent.getIntExtra("profile_id", -1);
 
 		if(profile_id != -1){
 			return pmanager.getProfile(profile_id);
-		}
+		}*/
 
-		return null;
+		return profile;
 	}
 
 	@Override