Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 32 | package com.savoirfairelinux.sflphone.client; |
| 33 | |
| 34 | import android.app.Activity; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 35 | import android.content.BroadcastReceiver; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 36 | import android.content.Context; |
| 37 | import android.content.ComponentName; |
| 38 | import android.content.Intent; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 39 | import android.content.IntentFilter; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 40 | import android.content.ServiceConnection; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 41 | import android.os.Bundle; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 42 | import android.os.IBinder; |
| 43 | import android.os.RemoteException; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 44 | import android.support.v4.content.LocalBroadcastManager; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 45 | import android.util.Log; |
| 46 | import android.view.View; |
| 47 | import android.view.View.OnClickListener; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 48 | |
| 49 | import com.savoirfairelinux.sflphone.R; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 50 | import com.savoirfairelinux.sflphone.client.SipCall; |
| 51 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 52 | import com.savoirfairelinux.sflphone.service.SipService; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 53 | |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 54 | public class CallActivity extends Activity implements OnClickListener |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 55 | { |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 56 | static final String TAG = "CallActivity"; |
| 57 | private ISipService service; |
| 58 | private SipCall mCall; |
| 59 | |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 60 | 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 Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 73 | @Override |
| 74 | protected void onCreate(Bundle savedInstanceState) |
| 75 | { |
| 76 | super.onCreate(savedInstanceState); |
| 77 | setContentView(R.layout.call_activity_layout); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 78 | |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 79 | 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 Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 83 | mCall = new SipCall(info); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 84 | |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 85 | Intent intent = new Intent(this, SipService.class); |
| 86 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 87 | |
| 88 | findViewById(R.id.buttonhangup).setOnClickListener(this); |
| 89 | |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 90 | 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 Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | protected void onDestroy() { |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 97 | LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); |
| 98 | unbindService(mConnection); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 99 | 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 Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 117 | Log.i(TAG, "On click action"); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 118 | if(view.getId() == R.id.buttonhangup) { |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame^] | 119 | mCall.notifyServiceHangup(service); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 120 | // terminate this activity |
| 121 | finish(); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 122 | } |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 123 | } |
| 124 | } |