blob: ddbd230787a2a4edda16710e633102f008e21952 [file] [log] [blame]
Alexandre Savard14323be2012-10-24 10:02:13 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
32package com.savoirfairelinux.sflphone.client;
33
34import android.app.Activity;
Alexandre Savard4f42ade2012-10-24 18:03:31 -040035import android.content.BroadcastReceiver;
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040036import android.content.Context;
37import android.content.ComponentName;
38import android.content.Intent;
Alexandre Savard4f42ade2012-10-24 18:03:31 -040039import android.content.IntentFilter;
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040040import android.content.ServiceConnection;
Alexandre Savard14323be2012-10-24 10:02:13 -040041import android.os.Bundle;
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040042import android.os.IBinder;
43import android.os.RemoteException;
Alexandre Savard4f42ade2012-10-24 18:03:31 -040044import android.support.v4.content.LocalBroadcastManager;
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040045import android.util.Log;
46import android.view.View;
47import android.view.View.OnClickListener;
Alexandre Savard14323be2012-10-24 10:02:13 -040048
49import com.savoirfairelinux.sflphone.R;
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040050import com.savoirfairelinux.sflphone.client.SipCall;
51import com.savoirfairelinux.sflphone.service.ISipService;
52import com.savoirfairelinux.sflphone.service.SipService;
Alexandre Savard14323be2012-10-24 10:02:13 -040053
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040054public class CallActivity extends Activity implements OnClickListener
Alexandre Savard14323be2012-10-24 10:02:13 -040055{
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040056 static final String TAG = "CallActivity";
57 private ISipService service;
58 private SipCall mCall;
59
Alexandre Savard4f42ade2012-10-24 18:03:31 -040060 private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
61 @Override
62 public void onReceive(Context context, Intent intent) {
63 String signalName = intent.getStringExtra("signal-name");
64 Log.d(TAG, "Signal received: " + signalName);
65
66 if(signalName.equals("new-call-created")) {
67 } else if(signalName.equals("call-state-changed")) {
68 } else if(signalName.equals("incoming-call")) {
69 }
70 }
71 };
72
Alexandre Savard14323be2012-10-24 10:02:13 -040073 @Override
74 protected void onCreate(Bundle savedInstanceState)
75 {
76 super.onCreate(savedInstanceState);
77 setContentView(R.layout.call_activity_layout);
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040078
Alexandre Savard557a5742012-10-24 13:54:53 -040079 Bundle b = getIntent().getExtras();
80 // Parcelable value = b.getParcelable("CallInfo");
81 SipCall.CallInfo info = b.getParcelable("CallInfo"); // new SipCall.CallInfo.CREATOR.createFromParcel
82 Log.i(TAG, "Starting activity for call " + info.mCallID);
Alexandre Savard74c1cad2012-10-24 16:39:00 -040083 mCall = new SipCall(info);
Alexandre Savard557a5742012-10-24 13:54:53 -040084
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040085 Intent intent = new Intent(this, SipService.class);
86 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
Alexandre Savard74c1cad2012-10-24 16:39:00 -040087
88 findViewById(R.id.buttonhangup).setOnClickListener(this);
89
Alexandre Savard4f42ade2012-10-24 18:03:31 -040090 LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("new-call-created"));
91 LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("call-state-changed"));
92 LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("incoming-call"));
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040093 }
94
95 @Override
96 protected void onDestroy() {
Alexandre Savard4f42ade2012-10-24 18:03:31 -040097 LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
98 unbindService(mConnection);
Alexandre Savard6d54bbc2012-10-24 11:04:23 -040099 super.onDestroy();
100 }
101
102 /** Defines callbacks for service binding, passed to bindService() */
103 private ServiceConnection mConnection = new ServiceConnection() {
104 @Override
105 public void onServiceConnected(ComponentName className, IBinder binder) {
106 service = ISipService.Stub.asInterface(binder);
107 }
108
109 @Override
110 public void onServiceDisconnected(ComponentName arg0) {
111 }
112 };
113
114 @Override
115 public void onClick(View view)
116 {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400117 Log.i(TAG, "On click action");
Alexandre Savard6d54bbc2012-10-24 11:04:23 -0400118 if(view.getId() == R.id.buttonhangup) {
Alexandre Savard4f42ade2012-10-24 18:03:31 -0400119 mCall.notifyServiceHangup(service);
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400120 // terminate this activity
121 finish();
Alexandre Savard6d54bbc2012-10-24 11:04:23 -0400122 }
Alexandre Savard14323be2012-10-24 10:02:13 -0400123 }
124}