4 package com.beem.project.beem.ui; |
4 package com.beem.project.beem.ui; |
5 |
5 |
6 import org.jivesoftware.smack.packet.Presence; |
6 import org.jivesoftware.smack.packet.Presence; |
7 import org.jivesoftware.smack.packet.Presence.Type; |
7 import org.jivesoftware.smack.packet.Presence.Type; |
8 |
8 |
|
9 import com.beem.project.beem.BeemApplication; |
|
10 import com.beem.project.beem.R; |
|
11 import com.beem.project.beem.service.PresenceAdapter; |
|
12 import com.beem.project.beem.service.aidl.IXmppFacade; |
|
13 |
9 import android.app.Activity; |
14 import android.app.Activity; |
10 import android.os.Bundle; |
15 import android.os.Bundle; |
11 import android.os.RemoteException; |
16 import android.os.RemoteException; |
12 import android.view.View; |
17 import android.view.View; |
13 import android.view.View.OnClickListener; |
18 import android.view.View.OnClickListener; |
|
19 import android.widget.TextView; |
14 import android.widget.Toast; |
20 import android.widget.Toast; |
15 |
|
16 import com.beem.project.beem.BeemApplication; |
|
17 import com.beem.project.beem.R; |
|
18 import com.beem.project.beem.service.PresenceAdapter; |
|
19 import com.beem.project.beem.service.aidl.IXmppFacade; |
|
20 |
21 |
21 /** |
22 /** |
22 * @author nikita |
23 * @author nikita |
|
24 * |
23 */ |
25 */ |
24 public class Subscription extends Activity { |
26 public class Subscription extends Activity { |
25 |
27 |
26 private IXmppFacade mService; |
28 private IXmppFacade mService; |
27 private String mContact; |
29 private String mContact; |
28 |
|
29 private OnClickListener mClickListener = new OnClickListener() { |
|
30 |
|
31 @Override |
|
32 public void onClick(View v) { |
|
33 switch (v.getId()) { |
|
34 case R.id.SubscriptionAccept: |
|
35 Presence presence = new Presence(Type.subscribed); |
|
36 presence.setTo(mContact); |
|
37 PresenceAdapter preAdapt = new PresenceAdapter(presence); |
|
38 try { |
|
39 mService.sendPresencePacket(preAdapt); |
|
40 Toast.makeText(Subscription.this, |
|
41 getString(R.string.SubscriptAccept), |
|
42 Toast.LENGTH_SHORT).show(); |
|
43 finish(); |
|
44 } catch (RemoteException e) { |
|
45 Toast.makeText(Subscription.this, |
|
46 getString(R.string.SubscriptError), |
|
47 Toast.LENGTH_SHORT).show(); |
|
48 e.printStackTrace(); |
|
49 } |
|
50 break; |
|
51 case R.id.SubscriptionRefuse: |
|
52 Toast |
|
53 .makeText(Subscription.this, |
|
54 getString(R.string.SubscriptRefused), |
|
55 Toast.LENGTH_SHORT).show(); |
|
56 |
|
57 break; |
|
58 default: |
|
59 Toast.makeText(Subscription.this, |
|
60 getString(R.string.SubscriptError), Toast.LENGTH_SHORT) |
|
61 .show(); |
|
62 } |
|
63 ; |
|
64 |
|
65 } |
|
66 |
|
67 }; |
|
68 |
30 |
69 @Override |
31 @Override |
70 protected void onCreate(Bundle savedInstanceState) { |
32 protected void onCreate(Bundle savedInstanceState) { |
71 super.onCreate(savedInstanceState); |
33 super.onCreate(savedInstanceState); |
72 setContentView(R.layout.subscription); |
34 setContentView(R.layout.subscription); |
73 findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener); |
35 findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener); |
74 findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener); |
36 findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener); |
75 mContact = getIntent().getStringExtra("from"); |
37 mContact = getIntent().getStringExtra("from"); |
|
38 TextView tv = (TextView) findViewById(R.id.SubscriptionText); |
|
39 String str = String.format(getString(R.string.SubscriptText), mContact); |
|
40 tv.setText(str); |
76 mService = BeemApplication.getApplication(this).getXmppFacade(); |
41 mService = BeemApplication.getApplication(this).getXmppFacade(); |
77 } |
42 } |
|
43 |
|
44 private OnClickListener mClickListener = new OnClickListener() { |
|
45 |
|
46 @Override |
|
47 public void onClick(View v) { |
|
48 switch (v.getId()) { |
|
49 case R.id.SubscriptionAccept: |
|
50 Presence presence = new Presence(Type.subscribed); |
|
51 presence.setTo(mContact); |
|
52 PresenceAdapter preAdapt = new PresenceAdapter(presence); |
|
53 try { |
|
54 mService.sendPresencePacket(preAdapt); |
|
55 Toast.makeText(Subscription.this, getString(R.string.SubscriptAccept), |
|
56 Toast.LENGTH_SHORT).show(); |
|
57 finish(); |
|
58 } catch (RemoteException e) { |
|
59 Toast.makeText(Subscription.this, getString(R.string.SubscriptError), |
|
60 Toast.LENGTH_SHORT).show(); |
|
61 e.printStackTrace(); |
|
62 } |
|
63 break ; |
|
64 case R.id.SubscriptionRefuse: |
|
65 Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused), |
|
66 Toast.LENGTH_SHORT).show(); |
|
67 |
|
68 break ; |
|
69 default: |
|
70 Toast.makeText(Subscription.this, getString(R.string.SubscriptError), |
|
71 Toast.LENGTH_SHORT).show(); |
|
72 }; |
|
73 |
|
74 } |
|
75 |
|
76 }; |
78 } |
77 } |