1 package com.beem.project.beem; |
1 package com.beem.project.beem; |
2 |
2 |
|
3 import com.beem.project.beem.service.aidl.IBeemConnectionListener; |
|
4 import com.beem.project.beem.service.aidl.IXMPPConnection; |
|
5 import com.beem.project.beem.service.aidl.IXMPPFacade; |
|
6 |
3 import android.app.Activity; |
7 import android.app.Activity; |
|
8 import android.content.ComponentName; |
4 import android.content.Intent; |
9 import android.content.Intent; |
|
10 import android.content.ServiceConnection; |
5 import android.content.SharedPreferences; |
11 import android.content.SharedPreferences; |
6 import android.os.Bundle; |
12 import android.os.Bundle; |
|
13 import android.os.Handler; |
|
14 import android.os.IBinder; |
|
15 import android.os.Message; |
|
16 import android.os.RemoteException; |
|
17 import android.util.Log; |
7 import android.view.Menu; |
18 import android.view.Menu; |
8 import android.view.MenuInflater; |
19 import android.view.MenuInflater; |
9 import android.view.MenuItem; |
20 import android.view.MenuItem; |
10 import android.view.View; |
21 import android.view.View; |
11 import android.view.View.OnClickListener; |
22 import android.view.View.OnClickListener; |
12 import android.widget.Button; |
23 import android.widget.Button; |
13 import android.widget.EditText; |
24 import android.widget.EditText; |
|
25 import android.widget.Toast; |
14 |
26 |
15 public class Beem extends Activity { |
27 public class Beem extends Activity { |
16 |
28 |
17 private SharedPreferences mSettings; |
29 private SharedPreferences mSettings; |
18 |
30 |
|
31 private IXMPPFacade facade; |
|
32 |
|
33 private Handler mHandler; |
|
34 |
19 /** |
35 /** |
20 * Called when the activity is first created. |
36 * Called when the activity is first created. |
21 */ |
37 */ |
22 @Override |
38 @Override |
23 public void onCreate(Bundle savedInstanceState) { |
39 public void onCreate(Bundle savedInstanceState) { |
24 super.onCreate(savedInstanceState); |
40 super.onCreate(savedInstanceState); |
|
41 mHandler = new Handler(); |
25 setContentView(R.layout.main); |
42 setContentView(R.layout.main); |
26 mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE); |
43 mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE); |
27 showJID(); |
44 showJID(); |
28 Button btConnection = (Button) findViewById(R.id.connection); |
45 Button btConnection = (Button) findViewById(R.id.connection); |
29 btConnection.setOnClickListener(new OnClickListener() { |
46 btConnection.setOnClickListener(new OnClickListener() { |
30 |
47 |
31 @Override |
48 @Override |
32 public void onClick(View v) { |
49 public void onClick(View v) { |
33 // TODO Auto-generated method stub |
50 // TODO Auto-generated method stub |
34 startService(new Intent(Beem.this,BeemService.class)); |
51 // startService(new Intent(Beem.this,BeemService.class)); |
|
52 boolean ok = bindService(new Intent(Beem.this,BeemService.class), new ServiceConnection() { |
|
53 |
|
54 @Override |
|
55 public void onServiceDisconnected(ComponentName name) { |
|
56 // TODO Auto-generated method stub |
|
57 |
|
58 } |
|
59 |
|
60 @Override |
|
61 public void onServiceConnected(ComponentName name, IBinder service) { |
|
62 // TODO Auto-generated method stub |
|
63 try { |
|
64 facade = (IXMPPFacade) service; |
|
65 IXMPPConnection con = facade.getXMPPConnection(); |
|
66 con.addConnectionListener(new IBeemConnectionListener.Stub() { |
|
67 |
|
68 @Override |
|
69 public void reconnectionSuccessful() throws RemoteException { |
|
70 // TODO Auto-generated method stub |
|
71 |
|
72 } |
|
73 |
|
74 @Override |
|
75 public void reconnectionFailed() throws RemoteException { |
|
76 // TODO Auto-generated method stub |
|
77 |
|
78 } |
|
79 |
|
80 @Override |
|
81 public void reconnectingIn(int seconds) throws RemoteException { |
|
82 // TODO Auto-generated method stub |
|
83 |
|
84 } |
|
85 |
|
86 @Override |
|
87 public void onConnect() throws RemoteException { |
|
88 // TODO Auto-generated method stub |
|
89 mHandler.post(new Runnable() { |
|
90 |
|
91 @Override |
|
92 public void run() { |
|
93 // TODO Auto-generated method stub |
|
94 Log.w("BEEM", "ON s'est COnnecter !!!"); |
|
95 Toast toast = Toast.makeText(Beem.this, "Connection estabished", Toast.LENGTH_LONG); |
|
96 toast.show(); |
|
97 } |
|
98 }); |
|
99 |
|
100 } |
|
101 |
|
102 @Override |
|
103 public void connectionClosedOnError() throws RemoteException { |
|
104 // TODO Auto-generated method stub |
|
105 |
|
106 } |
|
107 |
|
108 @Override |
|
109 public void connectionClosed() throws RemoteException { |
|
110 // TODO Auto-generated method stub |
|
111 |
|
112 } |
|
113 }); |
|
114 facade.connectAsync(); |
|
115 } catch (RemoteException e) { |
|
116 // TODO Auto-generated catch block |
|
117 e.printStackTrace(); |
|
118 } |
|
119 } |
|
120 }, BIND_AUTO_CREATE); |
|
121 if (! ok) |
|
122 Log.w("BEEM", "Connection au service echoue"); |
35 } |
123 } |
36 }); |
124 }); |
37 } |
125 } |
38 |
126 |
39 @Override |
127 @Override |