# HG changeset patch # User Da Risk # Date 1300740923 -3600 # Node ID bfb4326524f8594531e5546cafbf67c62ae6450c # Parent b2c242da8a1e57a8faa33f2d0e9ba8bfc2db192b Check if pep is enabled before showing ui to select an avatar. diff -r b2c242da8a1e -r bfb4326524f8 res/values/arrays.xml --- 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 @@ @string/contact_status_msg_xa @string/contact_status_msg_offline + + @string/take_photo + @string/pick_photo + @string/delete_avatar + Buddies Groups diff -r b2c242da8a1e -r bfb4326524f8 src/com/beem/project/beem/BeemApplication.java --- 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 { diff -r b2c242da8a1e -r bfb4326524f8 src/com/beem/project/beem/service/XmppConnectionAdapter.java --- 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 avatarInfos){ + @Override + public void onAvatarChange(String from, String avatarId, List avatarInfos) { String jid = mUserInfo.getJid(); if (jid.equals(from)) { mUserInfo.setAvatarId(avatarId); diff -r b2c242da8a1e -r bfb4326524f8 src/com/beem/project/beem/ui/ChangeStatus.java --- 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(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);