author | darisk@kaaliyah |
Mon, 10 Aug 2009 07:17:15 +0200 | |
changeset 349 | 84d45a88699f |
parent 340 | 5dee5c1e4a29 |
child 351 | 718557c6c309 |
permissions | -rw-r--r-- |
132 | 1 |
/** |
2 |
* |
|
3 |
*/ |
|
4 |
package com.beem.project.beem.ui; |
|
5 |
||
136
4cba5e27fcb3
debug et fin de l'ajout de contacte, il faut encore gerer la
nikita@nikita-rack
parents:
132
diff
changeset
|
6 |
import java.util.ArrayList; |
4cba5e27fcb3
debug et fin de l'ajout de contacte, il faut encore gerer la
nikita@nikita-rack
parents:
132
diff
changeset
|
7 |
import java.util.List; |
289 | 8 |
import java.util.regex.Pattern; |
136
4cba5e27fcb3
debug et fin de l'ajout de contacte, il faut encore gerer la
nikita@nikita-rack
parents:
132
diff
changeset
|
9 |
|
132 | 10 |
import android.app.Activity; |
244
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
11 |
import android.content.ComponentName; |
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
12 |
import android.content.Intent; |
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
13 |
import android.content.ServiceConnection; |
132 | 14 |
import android.os.Bundle; |
244
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
15 |
import android.os.IBinder; |
132 | 16 |
import android.os.RemoteException; |
336 | 17 |
import android.util.Log; |
132 | 18 |
import android.view.View; |
19 |
import android.view.View.OnClickListener; |
|
20 |
import android.widget.Button; |
|
21 |
import android.widget.EditText; |
|
22 |
import android.widget.Toast; |
|
23 |
||
244
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
24 |
import com.beem.project.beem.BeemService; |
212 | 25 |
import com.beem.project.beem.R; |
26 |
import com.beem.project.beem.service.aidl.IXmppFacade; |
|
27 |
||
132 | 28 |
/** |
29 |
* @author nikita |
|
30 |
*/ |
|
31 |
public class AddContact extends Activity { |
|
212 | 32 |
|
286 | 33 |
protected static final String TAG = "AddContact"; |
34 |
private final List<String> mGroup = new ArrayList<String>(); |
|
340 | 35 |
private IXmppFacade mXmppFacade; |
286 | 36 |
private final ServiceConnection mServConn = new BeemServiceConnection(); |
37 |
||
349 | 38 |
/** |
39 |
* Constructor. |
|
40 |
*/ |
|
41 |
public AddContact() { } |
|
42 |
||
286 | 43 |
@Override |
44 |
protected void onCreate(Bundle savedInstanceState) { |
|
45 |
super.onCreate(savedInstanceState); |
|
46 |
setContentView(R.layout.addcontact); |
|
47 |
Button ok = (Button) findViewById(R.id.addc_ok); |
|
48 |
ok.setOnClickListener(mOkListener); |
|
49 |
bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); |
|
50 |
} |
|
51 |
||
52 |
@Override |
|
287 | 53 |
protected void onStop() { |
54 |
super.onStop(); |
|
286 | 55 |
unbindService(mServConn); |
56 |
} |
|
57 |
||
349 | 58 |
/** |
59 |
* The ServiceConnection used to connect to the Beem service. |
|
60 |
*/ |
|
286 | 61 |
private class BeemServiceConnection implements ServiceConnection { |
212 | 62 |
|
349 | 63 |
/** |
64 |
* Constructor. |
|
65 |
*/ |
|
66 |
public BeemServiceConnection() { } |
|
67 |
||
256 | 68 |
@Override |
286 | 69 |
public void onServiceConnected(ComponentName name, IBinder service) { |
340 | 70 |
mXmppFacade = IXmppFacade.Stub.asInterface(service); |
244
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
71 |
} |
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
72 |
|
7c67ea0a501c
Suppression beemapplication dans addcontact.
marseille@marseille-desktop
parents:
213
diff
changeset
|
73 |
@Override |
286 | 74 |
public void onServiceDisconnected(ComponentName name) { |
340 | 75 |
mXmppFacade = null; |
265
3ee7b8fdbddd
L'ajout de contact ne necessite plus de remplir tous les champs
Da Risk <darisk972@gmail.com>
parents:
256
diff
changeset
|
76 |
} |
286 | 77 |
} |
265
3ee7b8fdbddd
L'ajout de contact ne necessite plus de remplir tous les champs
Da Risk <darisk972@gmail.com>
parents:
256
diff
changeset
|
78 |
|
349 | 79 |
/** |
80 |
* Get the text of a widget. |
|
81 |
* @param id the id of the widget. |
|
82 |
*/ |
|
286 | 83 |
private String getWidgetText(int id) { |
84 |
EditText widget = (EditText) this.findViewById(id); |
|
85 |
return widget.getText().toString(); |
|
86 |
} |
|
265
3ee7b8fdbddd
L'ajout de contact ne necessite plus de remplir tous les champs
Da Risk <darisk972@gmail.com>
parents:
256
diff
changeset
|
87 |
|
286 | 88 |
private final OnClickListener mOkListener = new OnClickListener() { |
265
3ee7b8fdbddd
L'ajout de contact ne necessite plus de remplir tous les champs
Da Risk <darisk972@gmail.com>
parents:
256
diff
changeset
|
89 |
|
286 | 90 |
@Override |
91 |
public void onClick(View v) { |
|
336 | 92 |
String login; |
93 |
login = getWidgetText(R.id.addc_login); |
|
94 |
if (login.length() == 0) { |
|
95 |
Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show(); |
|
96 |
return; |
|
97 |
} |
|
98 |
boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login); |
|
289 | 99 |
if (!isEmail) { |
100 |
Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT) |
|
101 |
.show(); |
|
102 |
return; |
|
103 |
} |
|
336 | 104 |
String alias; |
105 |
alias = getWidgetText(R.id.addc_alias); |
|
286 | 106 |
if (getWidgetText(R.id.addc_group).length() != 0) |
107 |
mGroup.add(getWidgetText(R.id.addc_group)); |
|
336 | 108 |
try { |
340 | 109 |
if (mXmppFacade != null) { |
110 |
if (mXmppFacade.getRoster().getContact(login) != null) |
|
111 |
mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups()); |
|
349 | 112 |
if (mXmppFacade.getRoster().addContact(login, alias, |
113 |
mGroup.toArray(new String[mGroup.size()])) == null) { |
|
286 | 114 |
Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT) |
115 |
.show(); |
|
289 | 116 |
return; |
286 | 117 |
} else { |
118 |
Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT) |
|
119 |
.show(); |
|
336 | 120 |
finish(); |
286 | 121 |
} |
265
3ee7b8fdbddd
L'ajout de contact ne necessite plus de remplir tous les champs
Da Risk <darisk972@gmail.com>
parents:
256
diff
changeset
|
122 |
} |
336 | 123 |
} catch (RemoteException e) { |
124 |
Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show(); |
|
125 |
Log.e(TAG, "Problem adding contact", e); |
|
286 | 126 |
} |
127 |
||
128 |
} |
|
129 |
}; |
|
132 | 130 |
} |