Merge.
authormarseille@marseille-desktop
Mon, 22 Jun 2009 22:29:03 +0200
changeset 268 68eb7cb08ba3
parent 267 ab5493f08c57 (current diff)
parent 266 a224ac0a1e95 (diff)
child 271 e5040078e3bb
child 276 673ee3896d50
Merge.
src/com/beem/project/beem/service/RosterAdapter.java
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Mon Jun 22 22:14:25 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Mon Jun 22 22:29:03 2009 +0200
@@ -31,6 +31,174 @@
  */
 public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
 
+    private static final String TAG = "RosterAdapter";
+    private Roster mAdaptee;
+    private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = new RemoteCallbackList<IBeemRosterListener>();
+
+    private Map<String, Contact> mContacts = new HashMap<String, Contact>();
+
+    private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
+
+    /**
+     * Constructor.
+     * @param roster the roster to adapt
+     */
+    public RosterAdapter(final Roster roster) {
+	mAdaptee = roster;
+	roster.addRosterListener(mRosterListener);
+	for (RosterEntry entry : roster.getEntries()) {
+	    String user = StringUtils.parseBareAddress(entry.getUser());
+	    if (!mContacts.containsKey(user)) {
+		Contact c = new Contact(user);
+		c.setStatus(roster.getPresence(user));
+		c.setGroups(entry.getGroups());
+		c.setName(entry.getName());
+		mContacts.put(user, c);
+	    }
+	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteRosListeners.register(listen);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Contact addContact(String user, String name, String[] groups) throws RemoteException {
+	Contact res = null;
+	RosterEntry contact = mAdaptee.getEntry(user);
+	if (contact != null) {
+	    res = mContacts.get(user);
+	    if (groups != null) {
+		for (String groupStr : groups) {
+		    boolean found = false;
+		    for (RosterGroup group : mAdaptee.getGroups()) {
+			if (group.getName().equals(groupStr) && !group.contains(contact)) {
+			    try {
+				group.addEntry(contact);
+				res.addGroup(groupStr);
+				found = true;
+			    } catch (XMPPException e) {
+				e.printStackTrace();
+			    }
+			}
+		    }
+		    if (!found) {
+			try {
+			    mAdaptee.createGroup(groupStr).addEntry(contact);
+			} catch (XMPPException e) {
+			    e.printStackTrace();
+			} catch (IllegalArgumentException e) {
+			}
+			res.addGroup(groupStr);
+		    }
+		}
+	    }
+	} else {
+	    try {
+		mAdaptee.createEntry(user, name, groups);
+		res = new Contact(user);
+		mContacts.put(user, res);
+		if (groups != null) {
+		    for (String groupStr : groups) {
+			try {
+			    mAdaptee.createGroup(groupStr);
+			} catch (IllegalArgumentException e) {
+			    // e.printStackTrace();
+			}
+			res.addGroup(groupStr);
+		    }
+		}
+	    } catch (XMPPException e) {
+		Log.e(TAG, "Error while adding new contact", e);
+		return null;
+	    }
+	}
+	return res;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void deleteContact(Contact contact, String group) throws RemoteException {
+	mContacts.get(contact.getJID()).delGroup(group);
+	try {
+	    mAdaptee.getGroup(group).removeEntry(mAdaptee.getEntry(contact.getJID()));
+	} catch (XMPPException e) {
+	    e.printStackTrace();
+	}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void createGroup(String groupname) throws RemoteException {
+	mAdaptee.createGroup(groupname);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Contact getContact(String jid) throws RemoteException {
+	return mContacts.get(jid);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<Contact> getContactList() throws RemoteException {
+	List<Contact> res = new ArrayList<Contact>();
+	res.addAll(mContacts.values());
+	return res;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<String> getGroupsNames() throws RemoteException {
+	Collection<RosterGroup> groups = mAdaptee.getGroups();
+	ArrayList<String> result = new ArrayList<String>(groups.size());
+	for (RosterGroup rosterGroup : groups) {
+	    result.add(rosterGroup.getName());
+	}
+	return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
+	if (listen != null)
+	    mRemoteRosListeners.unregister(listen);
+    }
+
+    /**
+	 * 
+	 */
+    @Override
+    public void setContactName(String jid, String name) throws RemoteException {
+	mContacts.get(jid).setName(name);
+	mAdaptee.getEntry(jid).setName(name);
+    }
+
+    @Override
+    public PresenceAdapter getPresence(String jid) throws RemoteException {
+	return new PresenceAdapter(mAdaptee.getPresence(jid));
+    }
+
     /**
      * Listener for the roster events. It will call the remote listeners registered.
      * @author darisk
@@ -141,168 +309,4 @@
 	}
     }
 
-    private static final String TAG = "RosterAdapter";
-    private Roster mAdaptee;
-    private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = new RemoteCallbackList<IBeemRosterListener>();
-
-    private Map<String, Contact> mContacts = new HashMap<String, Contact>();
-
-    private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
-
-    /**
-     * Constructor.
-     * @param roster the roster to adapt
-     */
-    public RosterAdapter(final Roster roster) {
-	mAdaptee = roster;
-	roster.addRosterListener(mRosterListener);
-	for (RosterEntry entry : roster.getEntries()) {
-	    String user = StringUtils.parseBareAddress(entry.getUser());
-	    if (!mContacts.containsKey(user)) {
-		Contact c = new Contact(user);
-		c.setStatus(roster.getPresence(user));
-		c.setGroups(entry.getGroups());
-		c.setName(entry.getName());
-		mContacts.put(user, c);
-	    }
-	}
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
-	if (listen != null)
-	    mRemoteRosListeners.register(listen);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Contact addContact(String user, String name, String[] groups) throws RemoteException {
-	Contact res = null;
-	RosterEntry contact = mAdaptee.getEntry(user);
-	if (contact != null) {
-	    res = mContacts.get(user);
-	    for (String groupStr : groups) {
-		boolean found = false;
-		for (RosterGroup group : mAdaptee.getGroups()) {
-		    if (group.getName().equals(groupStr) && !group.contains(contact)) {
-			try {
-			    group.addEntry(contact);
-			    res.addGroup(groupStr);
-			    found = true;
-			} catch (XMPPException e) {
-			    e.printStackTrace();
-			}
-		    }
-		}
-		if (!found) {
-		    try {
-			mAdaptee.createGroup(groupStr).addEntry(contact);
-		    } catch (XMPPException e) {
-			e.printStackTrace();
-		    } catch (IllegalArgumentException e) {
-		    }
-		    res.addGroup(groupStr);
-		}
-	    }
-	} else {
-	    try {
-		mAdaptee.createEntry(user, name, groups);
-		res = new Contact(user);
-		mContacts.put(user, res);
-		for (String groupStr : groups) {
-		    try {
-			mAdaptee.createGroup(groupStr);
-		    } catch (IllegalArgumentException e) {
-			// e.printStackTrace();
-		    }
-		    res.addGroup(groupStr);
-		}
-	    } catch (XMPPException e) {
-		Log.e(TAG, "Error while adding new contact", e);
-		return null;
-	    }
-	}
-	return res;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void createGroup(String groupname) throws RemoteException {
-	mAdaptee.createGroup(groupname);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void deleteContact(Contact contact, String group) throws RemoteException {
-	mContacts.get(contact.getJID()).delGroup(group);
-	try {
-	    mAdaptee.getGroup(group).removeEntry(mAdaptee.getEntry(contact.getJID()));
-	} catch (XMPPException e) {
-	    e.printStackTrace();
-	}
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Contact getContact(String jid) throws RemoteException {
-	return mContacts.get(jid);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public List<Contact> getContactList() throws RemoteException {
-	List<Contact> res = new ArrayList<Contact>();
-	res.addAll(mContacts.values());
-	return res;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public List<String> getGroupsNames() throws RemoteException {
-	Collection<RosterGroup> groups = mAdaptee.getGroups();
-	ArrayList<String> result = new ArrayList<String>(groups.size());
-	for (RosterGroup rosterGroup : groups) {
-	    result.add(rosterGroup.getName());
-	}
-	return result;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
-	if (listen != null)
-	    mRemoteRosListeners.unregister(listen);
-    }
-
-    /**
-	 * 
-	 */
-    @Override
-    public void setContactName(String jid, String name) throws RemoteException {
-	mContacts.get(jid).setName(name);
-	mAdaptee.getEntry(jid).setName(name);
-    }
-
-    @Override
-    public PresenceAdapter getPresence(String jid) throws RemoteException {
-	return new PresenceAdapter(mAdaptee.getPresence(jid));
-    }
-
 }
--- a/src/com/beem/project/beem/ui/AddContact.java	Mon Jun 22 22:14:25 2009 +0200
+++ b/src/com/beem/project/beem/ui/AddContact.java	Mon Jun 22 22:29:03 2009 +0200
@@ -28,81 +28,79 @@
  */
 public class AddContact extends Activity {
 
-    protected static final String TAG = "AddContact";
-    private String mLogin;
-    private String mAlias;
-    private final List<String> mGroup = new ArrayList<String>();
-    private IXmppFacade xmppFacade;
-    private final ServiceConnection mServConn = new BeemServiceConnection();
-
-    private final OnClickListener mOkListener = new OnClickListener() {
+	protected static final String TAG = "AddContact";
+	private String mLogin;
+	private String mAlias;
+	private final List<String> mGroup = new ArrayList<String>();
+	private IXmppFacade xmppFacade;
+	private final ServiceConnection mServConn = new BeemServiceConnection();
 
 	@Override
-	public void onClick(View v) {
-	    boolean valid = true;
-	    if (getWidgetText(R.id.addc_login).length() == 0) {
-		valid = false;
-	    } else {
-		mLogin = getWidgetText(R.id.addc_login);
-	    }
-	    if (getWidgetText(R.id.addc_alias).length() == 0) {
-		valid = false;
-	    } else {
-		mAlias = getWidgetText(R.id.addc_alias);
-	    }
-	    if (getWidgetText(R.id.addc_group).length() == 0) {
-		valid = false;
-	    } else {
-		mGroup.add(getWidgetText(R.id.addc_group));
-	    }
-	    if (valid) {
-		try {
-		    xmppFacade.getRoster().addContact(mLogin, mAlias, mGroup.toArray(new String[mGroup.size()]));
-		    Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT).show();
-		    finish();
-		} catch (RemoteException e) {
-		    Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show();
-		    e.printStackTrace();
-		}
-		setResult(RESULT_OK);
-	    } else {
-		Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
-		setResult(RESULT_CANCELED);
-	    }
-
-	}
-    };
-
-    private String getWidgetText(int id) {
-	EditText widget = (EditText) this.findViewById(id);
-	return widget.getText().toString();
-    }
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-	super.onCreate(savedInstanceState);
-	setContentView(R.layout.addcontact);
-	Button ok = (Button) findViewById(R.id.addc_ok);
-	ok.setOnClickListener(mOkListener);
-	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-    }
-
-    @Override
-    protected void onDestroy() {
-	super.onDestroy();
-	unbindService(mServConn);
-    }
-
-    private class BeemServiceConnection implements ServiceConnection {
-
-	@Override
-	public void onServiceConnected(ComponentName name, IBinder service) {
-	    xmppFacade = IXmppFacade.Stub.asInterface(service);
+	protected void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.addcontact);
+		Button ok = (Button) findViewById(R.id.addc_ok);
+		ok.setOnClickListener(mOkListener);
+		bindService(new Intent(this, BeemService.class), mServConn,
+				BIND_AUTO_CREATE);
 	}
 
 	@Override
-	public void onServiceDisconnected(ComponentName name) {
-	    xmppFacade = null;
+	protected void onDestroy() {
+		super.onDestroy();
+		unbindService(mServConn);
+	}
+
+	private class BeemServiceConnection implements ServiceConnection {
+
+		@Override
+		public void onServiceConnected(ComponentName name, IBinder service) {
+			xmppFacade = IXmppFacade.Stub.asInterface(service);
+		}
+
+		@Override
+		public void onServiceDisconnected(ComponentName name) {
+			xmppFacade = null;
+		}
+	}
+
+	private String getWidgetText(int id) {
+		EditText widget = (EditText) this.findViewById(id);
+		return widget.getText().toString();
 	}
-    }
+
+	private final OnClickListener mOkListener = new OnClickListener() {
+	
+		@Override
+		public void onClick(View v) {
+			boolean valid = true;
+			mLogin = getWidgetText(R.id.addc_login);
+			mAlias = getWidgetText(R.id.addc_alias);
+			if (mLogin.length() == 0)
+				valid = false;
+			if (getWidgetText(R.id.addc_group).length() != 0)
+				mGroup.add(getWidgetText(R.id.addc_group));
+			if (valid) {
+				try {
+					xmppFacade.getRoster().addContact(mLogin, mAlias,
+							mGroup.toArray(new String[mGroup.size()]));
+					Toast.makeText(AddContact.this,
+							getString(R.string.AddCContactAdded),
+							Toast.LENGTH_SHORT).show();
+					finish();
+				} catch (RemoteException e) {
+					Toast.makeText(AddContact.this, e.getMessage(),
+							Toast.LENGTH_SHORT).show();
+					e.printStackTrace();
+				}
+				setResult(RESULT_OK);
+			} else {
+				Toast.makeText(AddContact.this,
+						getString(R.string.AddCBadForm), Toast.LENGTH_SHORT)
+						.show();
+				setResult(RESULT_CANCELED);
+			}
+	
+		}
+	};
 }
--- a/src/com/beem/project/beem/ui/CreateAccount.java	Mon Jun 22 22:14:25 2009 +0200
+++ b/src/com/beem/project/beem/ui/CreateAccount.java	Mon Jun 22 22:29:03 2009 +0200
@@ -238,8 +238,8 @@
 
 		if (!checkPasswords())
 		    createErrorDialog(getString(R.string.create_account_err_passwords));
-		else
-		    createAccount(usernameFieldValue, passwordFieldValue);
+		else if (createAccount(usernameFieldValue, passwordFieldValue))
+			finish();
 	    }
 	});
 	Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button);