Check if pep is enabled before showing ui to select an avatar.
authorDa Risk <darisk972@gmail.com>
Mon, 21 Mar 2011 21:55:23 +0100
changeset 875 bfb4326524f8
parent 874 b2c242da8a1e
child 876 98060a89b5ec
Check if pep is enabled before showing ui to select an avatar.
res/values/arrays.xml
src/com/beem/project/beem/BeemApplication.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/ui/ChangeStatus.java
--- a/res/values/arrays.xml	Mon Mar 21 21:54:08 2011 +0100
+++ b/res/values/arrays.xml	Mon Mar 21 21:55:23 2011 +0100
@@ -13,6 +13,11 @@
 		<item name="Unavailable">@string/contact_status_msg_xa</item>
 		<item name="Disconnected">@string/contact_status_msg_offline</item>
 	</string-array>
+	<string-array name="pick_photo_items">
+		<item>@string/take_photo</item>
+		<item>@string/pick_photo</item>
+		<item>@string/delete_avatar</item>
+	</string-array>
 	<string-array name="privacy_list_select_dialog">
 		<item name="@string/privacy_list_select_dialog_buddies">Buddies</item>
 		<item name="@string/privacy_list_select_dialog_groups">Groups</item>
--- a/src/com/beem/project/beem/BeemApplication.java	Mon Mar 21 21:54:08 2011 +0100
+++ b/src/com/beem/project/beem/BeemApplication.java	Mon Mar 21 21:55:23 2011 +0100
@@ -94,6 +94,7 @@
 
     private boolean mIsConnected;
     private boolean mIsAccountConfigured;
+    private boolean mPepEnabled;
     private SharedPreferences mSettings;
     private final PreferenceListener mPreferenceListener = new PreferenceListener();
 
@@ -117,7 +118,6 @@
     public void onTerminate() {
 	super.onTerminate();
 	mSettings.unregisterOnSharedPreferenceChangeListener(mPreferenceListener);
-
     }
 
     /**
@@ -145,6 +145,24 @@
     }
 
     /**
+     * Enable Pep in the application context.
+     *
+     * @param enabled true to enable pep
+     */
+    public void setPepEnabled(boolean enabled) {
+	mPepEnabled = enabled;
+    }
+
+    /**
+     * Check if Pep is enabled.
+     *
+     * @return true if enabled
+     */
+    public boolean isPepEnabled() {
+	return mPepEnabled;
+    }
+
+    /**
      * A listener for all the change in the preference file. It is used to maintain the global state of the application.
      */
     private class PreferenceListener implements SharedPreferences.OnSharedPreferenceChangeListener {
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Mon Mar 21 21:54:08 2011 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Mon Mar 21 21:55:23 2011 +0100
@@ -127,6 +127,7 @@
     /**
      * Constructor.
      * @param config Configuration to use in order to connect
+     * @param jid the jid of the user
      * @param login login to use on connect
      * @param password password to use on connect
      * @param service the background service associated with the connection.
@@ -414,6 +415,11 @@
 	return mRoster;
     }
 
+    /**
+     * Get the user informations.
+     *
+     * @return the user infos
+     */
     public UserInfo getUserInfo() {
 	return mUserInfo;
     }
@@ -500,7 +506,7 @@
 		}
 	    }
 	} catch (XMPPException e) {
-	    // No Pep
+	    Log.w(TAG, "Unable to discover server features", e);
 	}
     }
 
@@ -509,12 +515,22 @@
      */
     private void initPEP() {
 	// Enable pep sending
+	Log.d(TAG, "Pep enabled");
 	// API 8
 	// mService.getExternalCacheDir()
 	mPepManager = new PepSubManager(mAdaptee);
 	AvatarCache avatarCache = new BeemAvatarCache(mService);
 	mAvatarManager = new BeemAvatarManager(mService, mAdaptee, mPepManager, avatarCache, true);
 	mAvatarManager.addAvatarListener(mUserInfoManager);
+	mApplication.setPepEnabled(true);
+    }
+
+    /**
+     * Reset the application state.
+     */
+    private void resetApplication() {
+	mApplication.setConnected(false);
+	mApplication.setPepEnabled(false);
     }
 
     /**
@@ -541,7 +557,7 @@
 	    intent.putExtra("normally", true);
 	    mService.sendBroadcast(intent);
 	    mService.stopSelf();
-	    mApplication.setConnected(false);
+	    resetApplication();
 	}
 
 	/**
@@ -555,7 +571,7 @@
 	    intent.putExtra("message", exception.getMessage());
 	    mService.sendBroadcast(intent);
 	    mService.stopSelf();
-	    mApplication.setConnected(false);
+	    resetApplication();
 	}
 
 	/**
@@ -579,7 +595,7 @@
 	    }
 	    mRemoteConnListeners.finishBroadcast();
 	    mService.stopSelf();
-	    mApplication.setConnected(false);
+	    resetApplication();
 	}
 
 	/**
@@ -715,12 +731,19 @@
 	}
     }
 
+    /**
+     * The UserInfoManager listen to XMPP events and update the user information accoldingly.
+     */
     private class UserInfoManager implements AvatarListener {
 
+	/**
+	 * Constructor.
+	 */
 	public UserInfoManager() {
 	}
 
-	public void onAvatarChange(String from, String avatarId, List<AvatarMetadataExtension.Info> avatarInfos){
+	@Override
+	public void onAvatarChange(String from, String avatarId, List<AvatarMetadataExtension.Info> avatarInfos) {
 	    String jid = mUserInfo.getJid();
 	    if (jid.equals(from)) {
 		mUserInfo.setAvatarId(avatarId);
--- a/src/com/beem/project/beem/ui/ChangeStatus.java	Mon Mar 21 21:54:08 2011 +0100
+++ b/src/com/beem/project/beem/ui/ChangeStatus.java	Mon Mar 21 21:55:23 2011 +0100
@@ -166,8 +166,14 @@
 	mContact = (Button) findViewById(R.id.OpenContactList);
 	mContact.setOnClickListener(mOnClickOk);
 
+	BeemApplication app = (BeemApplication) getApplication();
 	mAvatar = (ImageButton) findViewById(R.id.avatarButton);
 	mAvatar.setOnClickListener(mOnClickOk);
+	if (!app.isPepEnabled()) {
+	    View avatarPanel = findViewById(R.id.avatar_panel);
+	    avatarPanel.setVisibility(View.GONE);
+	}
+
 
 	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
 	mStatusMessageEditText = (EditText) findViewById(R.id.ChangeStatusMessage);
@@ -375,16 +381,9 @@
         final Context dialogContext = new ContextThemeWrapper(this,
                 android.R.style.Theme_Light);
 
-
-        String[] choices;
-
-        choices = new String[3];
-        choices[0] = getString(R.string.take_photo);
-        choices[1] = getString(R.string.pick_photo);
-        choices[2] = getString(R.string.delete_avatar);
-
-        final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
-                android.R.layout.simple_list_item_1, choices);
+        final ListAdapter adapter = ArrayAdapter.createFromResource(dialogContext,
+		R.array.pick_photo_items,
+                android.R.layout.simple_list_item_1);
 
         final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
         builder.setTitle(R.string.select_avatar);