src/com/beem/project/beem/ui/ContactDialog.java
changeset 502 3091acfe31f4
parent 500 4da77df8f950
child 503 93e5d2d9953f
equal deleted inserted replaced
501:d52918cfaba7 502:3091acfe31f4
    16 import com.beem.project.beem.R;
    16 import com.beem.project.beem.R;
    17 import com.beem.project.beem.service.Contact;
    17 import com.beem.project.beem.service.Contact;
    18 import com.beem.project.beem.service.aidl.IXmppFacade;
    18 import com.beem.project.beem.service.aidl.IXmppFacade;
    19 
    19 
    20 /**
    20 /**
    21  * This activity class provides the view to show dialog when long click on contact list.
    21  * This activity class provides the view to show dialog when long click on
       
    22  * contact list.
       
    23  * 
    22  * @author marseille
    24  * @author marseille
    23  */
    25  */
    24 public class ContactDialog extends Dialog {
    26 public class ContactDialog extends Dialog {
    25 
    27 
    26     private static final Intent SERVICE_INTENT = new Intent();
    28 	private static final Intent SERVICE_INTENT = new Intent();
    27     private final Contact mContact;
    29 	private final Contact mContact;
    28     private final Context mContext;
    30 	private final Context mContext;
    29     private IXmppFacade mXmppFacade;
    31 	private IXmppFacade mXmppFacade;
    30     private final ServiceConnection mServConn = new BeemServiceConnection();
    32 	private final ServiceConnection mServConn = new BeemServiceConnection();
    31 
    33 
    32     static {
    34 	static {
    33 	SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
    35 		SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
    34     }
    36 	}
    35 
       
    36     /**
       
    37      * Constructor.
       
    38      * @param context context where is call the dialog.
       
    39      * @param curContact current contact.
       
    40      */
       
    41     public ContactDialog(final Context context, final Contact curContact) {
       
    42 	super(context);
       
    43 	mContext = context;
       
    44 
       
    45 	setContentView(R.layout.contactdialog);
       
    46 	mContact = curContact;
       
    47 	setTitle(curContact.getJID());
       
    48 
       
    49 	Button button = (Button) findViewById(R.id.CDChat);
       
    50 	button.setOnClickListener(new ChatListener());
       
    51 	button = (Button) findViewById(R.id.CDInfos);
       
    52 	button.setOnClickListener(new InfosListener());
       
    53 	button = (Button) findViewById(R.id.CDCall);
       
    54 	button.setOnClickListener(new CallListener());
       
    55 	mContext.bindService(SERVICE_INTENT, mServConn, Service.BIND_AUTO_CREATE);
       
    56     }
       
    57 
       
    58     @Override
       
    59     public void dismiss() {
       
    60 	super.dismiss();
       
    61 	mContext.unbindService(mServConn);
       
    62     }
       
    63 
       
    64     /**
       
    65      * Event simple click on call button.
       
    66      */
       
    67     class CallListener implements View.OnClickListener {
       
    68 
    37 
    69 	/**
    38 	/**
    70 	 * Constructor.
    39 	 * Constructor.
       
    40 	 * 
       
    41 	 * @param context
       
    42 	 *            context where is call the dialog.
       
    43 	 * @param curContact
       
    44 	 *            current contact.
    71 	 */
    45 	 */
    72 	public CallListener() {
    46 	public ContactDialog(final Context context, final Contact curContact) {
       
    47 		super(context);
       
    48 		mContext = context;
       
    49 
       
    50 		setContentView(R.layout.contactdialog);
       
    51 		mContact = curContact;
       
    52 		setTitle(curContact.getJID());
       
    53 
       
    54 		Button button = (Button) findViewById(R.id.CDChat);
       
    55 		button.setOnClickListener(new ChatListener());
       
    56 		button = (Button) findViewById(R.id.CDInfos);
       
    57 		button.setOnClickListener(new InfosListener());
       
    58 		button = (Button) findViewById(R.id.CDCall);
       
    59 		button.setOnClickListener(new CallListener());
       
    60 		mContext.bindService(SERVICE_INTENT, mServConn, Service.BIND_AUTO_CREATE);
    73 	}
    61 	}
    74 
    62 
    75 	@Override
    63 	@Override
    76 	public void onClick(View v) {
    64 	public void dismiss() {
    77 	    try {
    65 		super.dismiss();
    78 		// TODO permettre a l'user de choisir a quel ressource il veut
    66 		mContext.unbindService(mServConn);
    79 		// faire le call.
       
    80 		mXmppFacade.call(mContact.getJID() + "/psi");
       
    81 	    } catch (RemoteException e) {
       
    82 		e.printStackTrace();
       
    83 	    }
       
    84 	}
    67 	}
    85     }
       
    86 
       
    87     /**
       
    88      * Event simple click on chat button.
       
    89      */
       
    90     class ChatListener implements View.OnClickListener {
       
    91 
    68 
    92 	/**
    69 	/**
    93 	 * Constructor.
    70 	 * Event simple click on call button.
    94 	 */
    71 	 */
    95 	public ChatListener() {
    72 	class CallListener implements View.OnClickListener {
       
    73 
       
    74 		/**
       
    75 		 * Constructor.
       
    76 		 */
       
    77 		public CallListener() {
       
    78 		}
       
    79 
       
    80 		@Override
       
    81 		public void onClick(View v) {
       
    82 			try {
       
    83 				// TODO permettre a l'user de choisir a quel ressource il veut
       
    84 				// faire le call.
       
    85 				mXmppFacade.call(mContact.getJID() + "/psi");
       
    86 			} catch (RemoteException e) {
       
    87 				e.printStackTrace();
       
    88 			}
       
    89 		}
    96 	}
    90 	}
    97 
    91 
    98 	@Override
    92 	/**
    99 	public void onClick(View v) {
    93 	 * Event simple click on chat button.
   100 	    Activity a = ContactDialog.this.getOwnerActivity();
    94 	 */
   101 	    Intent i = new Intent(mContext, Chat.class);
    95 	class ChatListener implements View.OnClickListener {
   102 	    i.setData(mContact.toUri());
    96 
   103 	    a.startActivity(i);
    97 		/**
   104 	    dismiss();
    98 		 * Constructor.
       
    99 		 */
       
   100 		public ChatListener() {
       
   101 		}
       
   102 
       
   103 		@Override
       
   104 		public void onClick(View v) {
       
   105 			Activity a = ContactDialog.this.getOwnerActivity();
       
   106 			Intent i = new Intent(mContext, Chat.class);
       
   107 			i.setData(mContact.toUri());
       
   108 			a.startActivity(i);
       
   109 			dismiss();
       
   110 		}
       
   111 
   105 	}
   112 	}
   106 
   113 
   107     }
   114 	/**
       
   115 	 * Event simple click on info button.
       
   116 	 */
       
   117 	class InfosListener implements View.OnClickListener {
   108 
   118 
   109     /**
   119 		/**
   110      * Event simple click on info button.
   120 		 * Constructor.
   111      */
   121 		 */
   112     class InfosListener implements View.OnClickListener {
   122 		public InfosListener() {
       
   123 		}
       
   124 
       
   125 		@Override
       
   126 		public void onClick(View v) {
       
   127 			Activity a = ContactDialog.this.getOwnerActivity();
       
   128 			Intent i = new Intent(mContext, UserInfo.class);
       
   129 			Log.i("OOO", mContact.getJID());
       
   130 			i.putExtra("contact_contactdialog", mContact.getJID());
       
   131 			a.startActivity(i);
       
   132 			dismiss();
       
   133 		}
       
   134 
       
   135 	}
   113 
   136 
   114 	/**
   137 	/**
   115 	 * Constructor.
   138 	 * The service connection used to connect to the Beem service.
   116 	 */
   139 	 */
   117 	public InfosListener() {
   140 	private class BeemServiceConnection implements ServiceConnection {
       
   141 
       
   142 		/**
       
   143 		 * Constructor.
       
   144 		 */
       
   145 		public BeemServiceConnection() {
       
   146 		}
       
   147 
       
   148 		@Override
       
   149 		public void onServiceConnected(ComponentName name, IBinder service) {
       
   150 			mXmppFacade = IXmppFacade.Stub.asInterface(service);
       
   151 		}
       
   152 
       
   153 		@Override
       
   154 		public void onServiceDisconnected(ComponentName name) {
       
   155 			mXmppFacade = null;
       
   156 		}
   118 	}
   157 	}
   119 
   158 
   120 	@Override
       
   121 	public void onClick(View v) {
       
   122 	    Activity a = ContactDialog.this.getOwnerActivity();
       
   123 	    Intent i = new Intent(mContext, UserInfo.class);
       
   124 	    Log.i("OOO", mContact.getJID());
       
   125 	    i.putExtra("contact_contactdialog", mContact.getJID());
       
   126 	    a.startActivity(i);
       
   127 	    dismiss();
       
   128 	}
       
   129 
       
   130     }
       
   131 
       
   132     /**
       
   133      * The service connection used to connect to the Beem service.
       
   134      */
       
   135     private class BeemServiceConnection implements ServiceConnection {
       
   136 
       
   137 	/**
       
   138 	 * Constructor.
       
   139 	 */
       
   140 	public BeemServiceConnection() {
       
   141 	}
       
   142 
       
   143 	@Override
       
   144 	public void onServiceConnected(ComponentName name, IBinder service) {
       
   145 	    mXmppFacade = IXmppFacade.Stub.asInterface(service);
       
   146 	}
       
   147 
       
   148 	@Override
       
   149 	public void onServiceDisconnected(ComponentName name) {
       
   150 	    mXmppFacade = null;
       
   151 	}
       
   152     }
       
   153 
       
   154 }
   159 }