Skip to content
Snippets Groups Projects
Commit 817dc506 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

#16843: Launch SFLphone service in SFLphoneHome activity creation

parent cf7e95a0
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
*
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
package com.savoirfairelinux.sflphone.client;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
public class AccountSelectionDialog extends AlertDialog
{
Context mContext;
ListView mListView;
ArrayAdapter mListAdapter;
ArrayList<String> mItems;
public AccountSelectionDialog(Context context, ArrayList<String> items)
{
super(context);
mContext = context;
mItems = items;
}
private DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which) {
}
};
public void onCreate(Bundle savedInstanceState)
{
mListView = new ListView(mContext);
mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, mItems.toArray());
mListView.setAdapter(mListAdapter);
setContentView(mListView);
}
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Account Selection");
return builder.create();
}
}
...@@ -51,6 +51,7 @@ import android.graphics.Bitmap; ...@@ -51,6 +51,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException;
import android.provider.*; import android.provider.*;
import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Phone;
...@@ -65,6 +66,7 @@ import java.util.List; ...@@ -65,6 +66,7 @@ import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import com.savoirfairelinux.sflphone.R; import com.savoirfairelinux.sflphone.R;
import com.savoirfairelinux.sflphone.service.ISipService;
/** /**
* Main list of Call Elements. * Main list of Call Elements.
...@@ -76,6 +78,7 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade ...@@ -76,6 +78,7 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade
ContactManager mContactManager; ContactManager mContactManager;
ArrayAdapter mAdapter; ArrayAdapter mAdapter;
String mCurFilter; String mCurFilter;
private ISipService service;
static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME,
Contacts.PHOTO_ID, Contacts.LOOKUP_KEY }; Contacts.PHOTO_ID, Contacts.LOOKUP_KEY };
...@@ -221,6 +224,17 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade ...@@ -221,6 +224,17 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade
protected TextView phones; protected TextView phones;
} }
public CallElementList(ISipService s)
{
super();
service = s;
}
public void setService(ISipService s)
{
service = s;
}
public void addCall(SipCall c) public void addCall(SipCall c)
{ {
Log.i(TAG, "Adding call " + c.mCallInfo.mDisplayName); Log.i(TAG, "Adding call " + c.mCallInfo.mDisplayName);
...@@ -304,13 +318,41 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade ...@@ -304,13 +318,41 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//LayoutInflater newInflater = inflater.cloneInContext(new ContextThemeWrapper(getActivity(), R.style.)); //LayoutInflater newInflater = inflater.cloneInContext(new ContextThemeWrapper(getActivity(), R.style.));
View inflatedView = inflater.inflate(R.layout.call_element_list, container, false); View inflatedView = inflater.inflate(R.layout.call_element_list, container, false);
Button accountSelectionButton = (Button) inflatedView.findViewById(R.id.account_selection_button);
accountSelectionButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/*
ArrayList<String> list = new ArrayList<String>();
list.add("IP2IP");
list.add("SFL-181");
AccountSelectionDialog accountSelectionDialog = new AccountSelectionDialog(getActivity(), list);
accountSelectionDialog.show();
*/
try {
if(service != null) {
ArrayList<String> list = (ArrayList<String>)service.getAccountList();
if(list != null) {
AccountSelectionDialog accountSelectionDialog = new AccountSelectionDialog(getActivity(), list);
accountSelectionDialog.show();
}
else { Log.i(TAG, "Could not get account list"); }
}
else { Log.i(TAG, "Could not get service"); }
}
catch (RemoteException e) {
Log.e(TAG, "Remote exception", e);
}
}
});
return inflatedView; return inflatedView;
} }
public void onListItemClick(ListView l, View v, int position, long id) public void onListItemClick(ListView l, View v, int position, long id)
{ {
// Insert desired behavior here. // Insert desired behavior here.
Log.i("CallElementList", "Item clicked: " + id); Log.i(TAG, "Item clicked: " + id);
SipCall call = (SipCall) mAdapter.getItem(position); SipCall call = (SipCall) mAdapter.getItem(position);
call.hangup(); call.hangup();
} }
......
...@@ -45,6 +45,7 @@ import android.graphics.Bitmap; ...@@ -45,6 +45,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException;
import android.provider.*; import android.provider.*;
import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Phone;
...@@ -57,6 +58,7 @@ import android.view.MenuItem; ...@@ -57,6 +58,7 @@ import android.view.MenuItem;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
...@@ -75,6 +77,7 @@ import java.util.List; ...@@ -75,6 +77,7 @@ import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import com.savoirfairelinux.sflphone.R; import com.savoirfairelinux.sflphone.R;
import com.savoirfairelinux.sflphone.service.ISipService;
public class ContactListFragment extends ListFragment implements OnQueryTextListener, LoaderManager.LoaderCallbacks<Cursor> public class ContactListFragment extends ListFragment implements OnQueryTextListener, LoaderManager.LoaderCallbacks<Cursor>
{ {
...@@ -82,6 +85,7 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList ...@@ -82,6 +85,7 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList
ContactElementAdapter mAdapter; ContactElementAdapter mAdapter;
Context mContext; Context mContext;
String mCurFilter; String mCurFilter;
private ISipService service;
// These are the Contacts rows that we will retrieve. // These are the Contacts rows that we will retrieve.
static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME,
...@@ -177,16 +181,22 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList ...@@ -177,16 +181,22 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList
} }
}; };
public ContactListFragment() public ContactListFragment(ISipService s)
{ {
super(); super();
mContext = getActivity(); service = s;
}
public void setService(ISipService s)
{
service = s;
} }
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) public void onActivityCreated(Bundle savedInstanceState)
{ {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mContext = getActivity();
// In order to onCreateOptionsMenu be called // In order to onCreateOptionsMenu be called
setHasOptionsMenu(true); setHasOptionsMenu(true);
...@@ -255,7 +265,23 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList ...@@ -255,7 +265,23 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{ {
return inflater.inflate(R.layout.call_element_list, container, false); View inflatedView = inflater.inflate(R.layout.call_element_list, container, false);
Button accountSelectionButton = (Button) inflatedView.findViewById(R.id.account_selection_button);
accountSelectionButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
ArrayList<String> list = (ArrayList<String>)service.getAccountList();
AccountSelectionDialog accountSelectionDialog = new AccountSelectionDialog(getActivity(), list);
accountSelectionDialog.show();
}
catch (RemoteException e) {
Log.e(TAG, "Remote exception", e);
}
}
});
return inflatedView;
} }
@Override @Override
......
...@@ -97,10 +97,25 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC ...@@ -97,10 +97,25 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
final private int[] icon_res_id = {R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history, R.drawable.ic_tab_play_selected}; final private int[] icon_res_id = {R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history, R.drawable.ic_tab_play_selected};
// public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (!serviceIsOn) {
Log.i(TAG, "starting SipService");
startSipService();
}
// Bind to LocalService
if (!mBound) {
Log.i(TAG, "onStart: Binding service...");
Intent intent = new Intent(this, SipService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
setContentView(R.layout.activity_sflphone_home); setContentView(R.layout.activity_sflphone_home);
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
...@@ -147,23 +162,12 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC ...@@ -147,23 +162,12 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
animation.setRepeatCount(Animation.INFINITE); animation.setRepeatCount(Animation.INFINITE);
// Reverse // Reverse
animation.setRepeatMode(Animation.REVERSE); animation.setRepeatMode(Animation.REVERSE);
if (!serviceIsOn) {
Log.i(TAG, "starting SipService");
startSipService();
}
} }
@Override @Override
protected void onStart() { protected void onStart() {
Log.i(TAG, "onStart"); Log.i(TAG, "onStart");
super.onStart(); super.onStart();
// Bind to LocalService
if (!mBound) {
Log.i(TAG, "onStart: Binding service...");
Intent intent = new Intent(this, SipService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
} }
/* user gets back to the activity, e.g. through task manager */ /* user gets back to the activity, e.g. through task manager */
...@@ -189,17 +193,17 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC ...@@ -189,17 +193,17 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
}
/* activity finishes itself or is being killed by the system */
@Override
protected void onDestroy() {
/* stop the service, if no other bound user, no need to check if it is running */ /* stop the service, if no other bound user, no need to check if it is running */
if (mBound) { if (mBound) {
Log.i(TAG, "onStop: Unbinding service..."); Log.i(TAG, "onStop: Unbinding service...");
unbindService(mConnection); unbindService(mConnection);
mBound = false; mBound = false;
} }
}
/* activity finishes itself or is being killed by the system */
@Override
protected void onDestroy() {
Log.i(TAG, "onDestroy: stopping SipService..."); Log.i(TAG, "onDestroy: stopping SipService...");
stopService(new Intent(this, SipService.class)); stopService(new Intent(this, SipService.class));
serviceIsOn = false; serviceIsOn = false;
...@@ -214,6 +218,8 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC ...@@ -214,6 +218,8 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
IBinder binder) { IBinder binder) {
service = ISipService.Stub.asInterface(binder); service = ISipService.Stub.asInterface(binder);
mBound = true; mBound = true;
mContactListFragment.setService(service);
mCallElementList.setService(service);
Log.d(TAG, "Service connected"); Log.d(TAG, "Service connected");
} }
...@@ -309,11 +315,11 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC ...@@ -309,11 +315,11 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
switch (i) { switch (i) {
case 0: case 0:
mContactListFragment = new ContactListFragment(); mContactListFragment = new ContactListFragment(service);
fragment = mContactListFragment; fragment = mContactListFragment;
break; break;
case 1: case 1:
mCallElementList = new CallElementList(); mCallElementList = new CallElementList(service);
SipCall.setCallElementList(mCallElementList); SipCall.setCallElementList(mCallElementList);
fragment = mCallElementList; fragment = mCallElementList;
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment