Kaynağa Gözat

Profile manager icons now changed; removed back button for now

Alexander Brakowski 10 yıl önce
ebeveyn
işleme
d8a5162304

+ 24 - 5
src/de/tudarmstadt/informatik/hostage/logging/UglyDbHelper.java

@@ -33,7 +33,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 
 	// All Static variables
 	// Database Version
-	private static final int DATABASE_VERSION = 7;
+	private static final int DATABASE_VERSION = 9;
 
 	// Database Name
 	private static final String DATABASE_NAME = "recordManager";
@@ -70,6 +70,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 	public static final String KEY_PROFILE_ICON = "profile_icon";
 	public static final String KEY_PROFILE_EDITABLE = "profile_editable";
 	public static final String KEY_PROFILE_ACTIVE = "profile_active";
+	public static final String KEY_PROFILE_ICON_NAME = "profile_icon_name";
 
 	// Database sql create statements
 	private static final String CREATE_PROFILE_TABLE = "CREATE TABLE "
@@ -78,6 +79,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 			+ KEY_PROFILE_NAME + " TEXT,"
 			+ KEY_PROFILE_DESCRIPTION + " TEXT,"
 			+ KEY_PROFILE_ICON + " TEXT,"
+			+ KEY_PROFILE_ICON_NAME + " TEXT,"
 			+ KEY_PROFILE_EDITABLE + " INTEGER,"
 			+ KEY_PROFILE_ACTIVE + " INTEGER"
 			+ ")";
@@ -821,12 +823,14 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		// looping through all rows and adding to list
 		if (cursor.moveToFirst()) {
 			do {
-				Profile profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(4) == 1);
+				Profile profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(5) == 1);
 
-				if(cursor.getInt(5) == 1){
+				if(cursor.getInt(6) == 1){
 					profile.mActivated = true;
 				}
 
+				profile.mIconName = cursor.getString(4);
+
 				// Adding record to list
 				profiles.add(profile);
 			} while (cursor.moveToNext());
@@ -856,6 +860,7 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		values.put(KEY_PROFILE_NAME, profile.mLabel);
 		values.put(KEY_PROFILE_DESCRIPTION, profile.mText);
 		values.put(KEY_PROFILE_ICON, profile.mIconPath);
+		values.put(KEY_PROFILE_ICON_NAME, profile.mIconName);
 		values.put(KEY_PROFILE_ACTIVE, profile.mActivated);
 		values.put(KEY_PROFILE_EDITABLE, profile.mEditable);
 
@@ -863,6 +868,18 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 	}
 
 
+	/**
+	 * private static final String CREATE_PROFILE_TABLE = "CREATE TABLE "
+	 + TABLE_PROFILES + "("
+	 + KEY_PROFILE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+	 + KEY_PROFILE_NAME + " TEXT,"
+	 + KEY_PROFILE_DESCRIPTION + " TEXT,"
+	 + KEY_PROFILE_ICON + " TEXT,"
+	 + KEY_PROFILE_ICON_ID + " INTEGER,"
+	 + KEY_PROFILE_EDITABLE + " INTEGER,"
+	 + KEY_PROFILE_ACTIVE + " INTEGER"
+	 + ")";
+	 */
 	public Profile getProfile(int id) {
 		String selectQuery = "SELECT  * FROM " + TABLE_PROFILES + " WHERE " + TABLE_PROFILES + "." + KEY_PROFILE_ID + " = " + id;
 		SQLiteDatabase db = this.getReadableDatabase();
@@ -871,11 +888,13 @@ public class UglyDbHelper extends SQLiteOpenHelper {
 		Profile profile = null;
 
 		if (cursor.moveToFirst()) {
-			profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(4) == 1);
+			profile = new Profile(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(5) == 1);
 
-			if(cursor.getInt(5) == 1){
+			if(cursor.getInt(6) == 1){
 				profile.mActivated = true;
 			}
+
+			profile.mIconName = cursor.getString(5);
 		}
 
 		cursor.close();

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

@@ -17,6 +17,9 @@ public class Profile {
 	public int mId;
 	public boolean mActivated;
 	public Bitmap mIcon;
+	public int mIconId;
+	public String mIconName;
+
 	public String mIconPath;
 
 	public boolean mIsBackVisible = false;
@@ -39,6 +42,8 @@ public class Profile {
 
 	public Profile(int id, String label, String text, int icon, boolean editable){
 		this(id, text, label, BitmapFactory.decodeResource(MainActivity.context.getResources(), icon), editable);
+		mIconId = icon;
+		mIconName = MainActivity.context.getResources().getResourceName(icon);
 	}
 
 	public Profile(int id, String label, String text, String iconPath, boolean editable){
@@ -61,6 +66,19 @@ public class Profile {
 	public Bitmap getIconBitmap(){
 		if(this.mIcon != null) return mIcon;
 
+		if(this.mIconId != 0){
+			this.mIcon = BitmapFactory.decodeResource(MainActivity.context.getResources(), mIconId);
+			return this.mIcon;
+		}
+
+		if(!this.mIconName.isEmpty()){
+			this.mIconId = MainActivity.context.getResources().getIdentifier(this.mIconName,
+					"drawable", "de.tudarmstadt.informatik.hostage");
+			this.mIcon = BitmapFactory.decodeResource(MainActivity.context.getResources(), this.mIconId);
+
+			return this.mIcon;
+		}
+
 		if(this.mIconPath != null){
 			BitmapFactory.Options options = new BitmapFactory.Options();
 			options.inPreferredConfig = Bitmap.Config.ARGB_8888;

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

@@ -410,7 +410,7 @@ public class MainActivity extends Activity {
 
 	private void injectFragment(Fragment fragment, boolean enableBack, Object tagObj){
 		if(enableBack){
-			mDrawerToggle.setDrawerIndicatorEnabled(false);
+			//mDrawerToggle.setDrawerIndicatorEnabled(false);
 		}
 
 		String tag = (tagObj == null ? null : tagObj.toString());
@@ -434,7 +434,7 @@ public class MainActivity extends Activity {
 	@Override
 	public void onBackPressed() {
 		super.onBackPressed();
-		if(getCurrentFragment().getTag() != null) mDrawerToggle.setDrawerIndicatorEnabled(true);
+		//if(getCurrentFragment().getTag() != null) mDrawerToggle.setDrawerIndicatorEnabled(true);
 	}
 
 	public static void displayBackStack(FragmentManager fm) {

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

@@ -74,6 +74,8 @@ public class ProfileEditFragment extends PreferenceFragment implements
 
 				if(createNew){
 					profile.mId = -1;
+					profile.mIconId = 0;
+					profile.mIconName = "";
 					pmanager.addProfile(profile);
 				} else {
 					pmanager.persistProfile(profile);