author | Da Risk <darisk972@gmail.com> |
Wed, 22 Apr 2009 00:22:58 +0200 | |
changeset 135 | efdae5f9289f |
parent 134 | 3cdc38183ca9 (current diff) |
parent 132 | 728adc0feb4e (diff) |
child 137 | 736d685a3407 |
child 138 | 503f22107d07 |
child 140 | f36049828552 |
--- a/AndroidManifest.xml Wed Apr 22 00:19:34 2009 +0200 +++ b/AndroidManifest.xml Wed Apr 22 00:22:58 2009 +0200 @@ -14,6 +14,7 @@ <activity android:name=".ui.SendIM" android:label="@string/app_name" /> <activity android:name=".ui.ChangeStatus" android:label="@string/app_name" /> <activity android:name=".ui.AccountCreation" android:label="@string/app_name" /> + <activity android:name=".ui.AddContact" android:label="@string/app_name" /> <service android:name="BeemService" android:enabled="true" android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE"> <intent-filter>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/addcontact.xml Wed Apr 22 00:22:58 2009 +0200 @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + > + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + > + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Login:" + android:minWidth="70dp" + /> + + <EditText android:id="@+id/login" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:textSize="16sp" + android:autoText="false" + android:capitalize="none" + android:minWidth="250dp" + android:scrollHorizontally="true"/> + </LinearLayout> + + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + > + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Alias:" + android:minWidth="70dp" + /> + <EditText android:id="@+id/alias" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:textSize="16sp" + android:autoText="false" + android:minWidth="250dp" + android:capitalize="none" + android:scrollHorizontally="true"/> + </LinearLayout> + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + > + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Group:" + android:minWidth="70dp" + /> + <EditText android:id="@+id/group" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:password="true" + android:textSize="16sp" + android:autoText="false" + android:minWidth="250dp" + android:capitalize="none" + android:scrollHorizontally="true"/> + </LinearLayout> + <Button android:id="@+id/ok" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:text="OK"> + <requestFocus/> + </Button> +</LinearLayout> \ No newline at end of file
--- a/res/menu/contactlistmenu.xml Wed Apr 22 00:19:34 2009 +0200 +++ b/res/menu/contactlistmenu.xml Wed Apr 22 00:22:58 2009 +0200 @@ -1,5 +1,6 @@ <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="Creer ou Editer un compte" android:id="@+id/account_edit" android:icon="@drawable/xmpp"/> + <item android:title="@string/MenuAddContact" android:id="@+id/add_contact" /> <item android:title="L'equipe Beem" android:id="@+id/account_about"/> <item android:title="TEMP/createAccount" android:id="@+id/account_create"/> </menu>
--- a/res/values/strings.xml Wed Apr 22 00:19:34 2009 +0200 +++ b/res/values/strings.xml Wed Apr 22 00:22:58 2009 +0200 @@ -48,5 +48,7 @@ <!-- ChangeStatus class --> <string name="ChangeStatusText">Type here your status message :</string> + + <string name="MenuAddContact">Add new contact</string> </resources>
--- a/src/com/beem/project/beem/service/BeemChatManager.java Wed Apr 22 00:19:34 2009 +0200 +++ b/src/com/beem/project/beem/service/BeemChatManager.java Wed Apr 22 00:22:58 2009 +0200 @@ -141,7 +141,7 @@ public void chatCreated(Chat chat, boolean locally) { IChat newchat = getChat(chat); if (!locally) { - // chat.addMessageListener(mChatListener); + // chat.addMessageListener(mChatListener); notifyNewChat(newchat); } chat.addMessageListener(mChatListener); @@ -184,7 +184,8 @@ public void processMessage(Chat chat, Message message) { IChat newchat = getChat(chat); try { - newchat.addToLastMessages(message.getBody()); + if (message.getBody() != null) + newchat.addToLastMessages(message.getBody()); final int n = mRemoteMessageListeners.beginBroadcast(); for (int i = 0; i < n; i++) { IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i);
--- a/src/com/beem/project/beem/service/RosterAdapter.java Wed Apr 22 00:19:34 2009 +0200 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Wed Apr 22 00:22:58 2009 +0200 @@ -49,8 +49,7 @@ if (!mContacts.containsKey(user)) { Contact c = new Contact(user); c.setStatus(roster.getPresence(user)); - mContacts.put(user, c); - + mContacts.put(user, c); } } }
--- a/src/com/beem/project/beem/ui/AccountCreation.java Wed Apr 22 00:19:34 2009 +0200 +++ b/src/com/beem/project/beem/ui/AccountCreation.java Wed Apr 22 00:22:58 2009 +0200 @@ -40,7 +40,6 @@ Button ok = (Button) findViewById(R.id.ok); mSettings = getSharedPreferences( getString(R.string.PreferenceFileName), MODE_PRIVATE); - //mAccountManager = new AccountManager(); ok.setOnClickListener(mOkListener); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/AddContact.java Wed Apr 22 00:22:58 2009 +0200 @@ -0,0 +1,90 @@ +/** + * + */ +package com.beem.project.beem.ui; + +import com.beem.project.beem.BeemApplication; +import com.beem.project.beem.R; +import com.beem.project.beem.service.aidl.IXmppFacade; + +import android.app.Activity; +import android.os.Bundle; +import android.os.RemoteException; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +/** + * @author nikita + * + */ +public class AddContact extends Activity { + + protected static final String TAG = "AddContact"; + private String mLogin; + private String mAlias; + private String[] mGroup; + private IXmppFacade mService; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.addcontact); + Button ok = (Button) findViewById(R.id.ok); + //mAccountManager = new AccountManager(); + ok.setOnClickListener(mOkListener); + mService = BeemApplication.getApplication(this).getXmppFacade(); + } + + private OnClickListener mOkListener = new OnClickListener() { + + @Override + public void onClick(View v) { + boolean valid = true; + if (getWidgetText(R.id.login).length() != 0) { + Log.d(TAG, "login pas ok"); + valid = false; + } else { + mLogin = getWidgetText(R.id.login); + } + if (getWidgetText(R.id.alias).length() != 0) { + Log.d(TAG, "alias pas ok"); + valid = false; + } else { + mAlias = getWidgetText(R.id.alias); + } + if (getWidgetText(R.id.group).length() != 0) { + Log.d(TAG, "group pas ok"); + valid = false; + } else { + mGroup[0] = getWidgetText(R.id.group); + } + if (valid) { + try { + mService.getRoster().addContact(mLogin, mAlias, mGroup); + Toast.makeText(AddContact.this, "Contact added", + 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, "Bad form", + Toast.LENGTH_SHORT).show(); + setResult(RESULT_CANCELED); + } + + } + }; + + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } +}
--- a/src/com/beem/project/beem/ui/ContactList.java Wed Apr 22 00:19:34 2009 +0200 +++ b/src/com/beem/project/beem/ui/ContactList.java Wed Apr 22 00:22:58 2009 +0200 @@ -49,11 +49,11 @@ @SuppressWarnings("unchecked") @Override public boolean onChildClick(ExpandableListView parent, View v, - int groupPosition, int childPosition, long id) { + int groupPosition, int childPosition, long id) { Intent i = new Intent(this, SendIM.class); Map<String, Contact> child = (HashMap<String, Contact>) parent - .getExpandableListAdapter().getChild(groupPosition, - childPosition); + .getExpandableListAdapter().getChild(groupPosition, + childPosition); i.putExtra("contact", child.get("CHILD")); startActivity(i); return true; @@ -66,7 +66,7 @@ mHandler = new Handler(); mBeemApplication = BeemApplication.getApplication(this); mSettings = getSharedPreferences( - getString(R.string.PreferenceFileName), MODE_PRIVATE); + getString(R.string.PreferenceFileName), MODE_PRIVATE); mRosterListener = new BeemRosterListener(); } @@ -74,7 +74,7 @@ protected void onStart() { super.onStart(); } - + @Override protected void onDestroy() { // TODO Auto-generated method stub @@ -118,7 +118,7 @@ if (mRoster != null) try { showContactList(mRoster.getGroupsNames(), mRoster - .getContactList()); + .getContactList()); } catch (RemoteException e) { e.printStackTrace(); } @@ -157,24 +157,27 @@ case R.id.account_create: startActivity(new Intent(this, AccountCreation.class)); return true; + case R.id.add_contact: + startActivity(new Intent(this, AddContact.class)); + return true; default: return false; } } - + protected void onActivityResult(int requestCode, int resultCode, - Intent data) { - if (requestCode == PREFERENCECHANGED) { - if (resultCode == RESULT_OK) { - mBeemApplication.stopBeemService(); - mBeemApplication.startBeemService(); - } - } + Intent data) { + if (requestCode == PREFERENCECHANGED) { + if (resultCode == RESULT_OK) { + mBeemApplication.stopBeemService(); + mBeemApplication.startBeemService(); + } + } } private void showContactList(List<String> listGroup, - List<Contact> listContact) { + List<Contact> listContact) { ExpandableListAdapter Adapter; List<Map<String, String>> groupData = new ArrayList<Map<String, String>>(); List<List<Map<String, Contact>>> childData = new ArrayList<List<Map<String, Contact>>>(); @@ -199,11 +202,11 @@ } Adapter = new ContactExpandableListAdapter(this, groupData, - R.layout.contactlistgroup, new String[] { "GROUP" }, - new int[] { R.id.textgroup }, childData, - R.layout.contactlistcontact, new String[] { "CHILD" }, - new int[] { R.id.contactliststatus, R.id.contactlistpseudo, - R.id.contactlistmsgperso, R.id.contactlistavatar }); + R.layout.contactlistgroup, new String[] { "GROUP" }, + new int[] { R.id.textgroup }, childData, + R.layout.contactlistcontact, new String[] { "CHILD" }, + new int[] { R.id.contactliststatus, R.id.contactlistpseudo, + R.id.contactlistmsgperso, R.id.contactlistavatar }); setListAdapter(Adapter); } @@ -213,19 +216,19 @@ * getGroupView() to define the layout of parents) */ private class ContactExpandableListAdapter extends - SimpleExpandableListAdapter { + SimpleExpandableListAdapter { private List<? extends List<? extends Map<String, ?>>> mChildData; private String[] mChildFrom; private int[] mChildTo; public ContactExpandableListAdapter(Context context, - List<? extends Map<String, ?>> groupData, int groupLayout, + List<? extends Map<String, ?>> groupData, int groupLayout, String[] groupFrom, int[] groupTo, List<? extends List<? extends Map<String, ?>>> childData, - int childLayout, String[] childFrom, int[] childTo) { + int childLayout, String[] childFrom, int[] childTo) { super(context, groupData, groupLayout, groupFrom, groupTo, - childData, childLayout, childFrom, childTo); + childData, childLayout, childFrom, childTo); mChildData = childData; mChildFrom = childFrom; @@ -235,7 +238,7 @@ @Override public View getChildView(int groupPosition, int childPosition, - boolean isLastChild, View convertView, ViewGroup parent) { + boolean isLastChild, View convertView, ViewGroup parent) { View v; if (convertView == null) { @@ -244,12 +247,12 @@ v = convertView; } bindView(v, mChildData.get(groupPosition).get(childPosition), - mChildFrom, mChildTo, groupPosition, childPosition); + mChildFrom, mChildTo, groupPosition, childPosition); return v; } private void bindView(View view, Map<String, ?> data, String[] from, - int[] to, int groupPosition, int childPosition) { + int[] to, int groupPosition, int childPosition) { Contact c = (Contact) data.get(from[0]); if (c != null) { @@ -259,32 +262,32 @@ switch (c.getStatus()) { case Status.CONTACT_STATUS_AVAILABLE: imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.online); + R.drawable.online); break; case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT: imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.chat); + R.drawable.chat); break; case Status.CONTACT_STATUS_AWAY: imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.away); + R.drawable.away); break; case Status.CONTACT_STATUS_BUSY: imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.dnd); + R.drawable.dnd); break; case Status.CONTACT_STATUS_DISCONNECT: imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.offline); + R.drawable.offline); break; case Status.CONTACT_STATUS_UNAVAILABLE: imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.requested); + R.drawable.requested); break; default: imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.error); - break; + R.drawable.error); + break; } imgV.setImageDrawable(imageDrawable); @@ -297,7 +300,7 @@ if (v != null) { v.setText(c.getMsgState()); } - + /* * TODO: Rajouter l'avatar du contact getAvatar() dans la * classe @@ -305,7 +308,7 @@ imgV = (ImageView) view.findViewById(to[3]); if (imgV != null) { imageDrawable = (Drawable) getResources().getDrawable( - R.drawable.avatar); + R.drawable.avatar); imgV.setImageDrawable(imageDrawable); } } @@ -316,28 +319,28 @@ @Override public void onEntriesAdded(List<String> addresses) - throws RemoteException { + throws RemoteException { Log.i(TAG, "ENTRIES ADDED"); } @Override public void onEntriesDeleted(List<String> addresses) - throws RemoteException { + throws RemoteException { Log.i(TAG, "ENTRIES DEL"); } @Override public void onEntriesUpdated(List<String> addresses) - throws RemoteException { + throws RemoteException { Log.i(TAG, "ENTRIES UPD"); } @Override public void onPresenceChanged(PresenceAdapter presence) - throws RemoteException { + throws RemoteException { Log.i(TAG, "PRESENCE CHANGED"); }