Skip to content
Snippets Groups Projects
Commit 1f1ced38 authored by Emeric Vigier's avatar Emeric Vigier
Browse files

#17105: Go up to the Activity or the Application to get a service reference

parent ec560de5
No related branches found
No related tags found
No related merge requests found
......@@ -57,8 +57,6 @@ import java.util.ArrayList;
import com.savoirfairelinux.sflphone.R;
import com.savoirfairelinux.sflphone.service.ISipService;
import com.savoirfairelinux.sflphone.service.SipService;
import com.savoirfairelinux.sflphone.service.ServiceConstants;
import com.savoirfairelinux.sflphone.utils.AccountDetail;
import com.savoirfairelinux.sflphone.utils.AccountDetailsHandler;
import com.savoirfairelinux.sflphone.utils.AccountDetailBasic;
......@@ -73,6 +71,7 @@ public class AccountManagementFragment extends PreferenceFragment
static final String DEFAULT_ACCOUNT_ID = "IP2IP";
static final int ACCOUNT_CREATE_REQUEST = 1;
static final int ACCOUNT_EDIT_REQUEST = 2;
private SFLPhonePreferenceActivity sflphonePreferenceActivity;
private ISipService service;
ArrayList<AccountDetail.PreferenceEntry> basicDetailKeys = null;
......@@ -82,12 +81,16 @@ public class AccountManagementFragment extends PreferenceFragment
HashMap<String, Preference> accountPreferenceHashMap = null;
PreferenceScreen mRoot = null;
Activity context = getActivity();
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
sflphonePreferenceActivity = (SFLPhonePreferenceActivity) activity;
service = sflphonePreferenceActivity.getSipService();
Log.i(TAG, "onAttach() service " + service);
}
public AccountManagementFragment(ISipService s)
public AccountManagementFragment()
{
service = s;
basicDetailKeys = AccountDetailBasic.getPreferenceEntries();
advancedDetailKeys = AccountDetailAdvanced.getPreferenceEntries();
srtpDetailKeys = AccountDetailSrtp.getPreferenceEntries();
......
......@@ -37,7 +37,6 @@ import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.ServiceConnection;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
......
......@@ -36,6 +36,7 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import android.app.Activity;
import android.app.ListFragment;
import android.app.LoaderManager;
import android.app.AlertDialog;
......@@ -91,6 +92,14 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade
static final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
static final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
sflphoneHome = (SFLPhoneHome) activity;
service = ((SFLphoneApplication) sflphoneHome.getApplication()).getSipService();
Log.i(TAG, "onAttach() service " + service);
}
public String getSelectedAccount() {
return mAccountSelectionButton.getText().toString();
}
......@@ -238,16 +247,9 @@ public class CallElementList extends ListFragment implements LoaderManager.Loade
protected TextView state;
}
public CallElementList(ISipService s, SFLPhoneHome home)
public CallElementList()
{
super();
service = s;
sflphoneHome = home;
}
public void setService(ISipService s)
{
service = s;
}
public void setAccountList(AccountList accountList) {
......
......@@ -30,6 +30,7 @@
*/
package com.savoirfairelinux.sflphone.client;
import android.app.Activity;
import android.app.ListFragment;
import android.app.LoaderManager;
import android.app.AlertDialog;
......@@ -87,6 +88,7 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList
ContactElementAdapter mAdapter;
Context mContext;
String mCurFilter;
private SFLPhoneHome sflphoneHome;
private ISipService service;
private AccountSelectionButton mAccountSelectionButton;
private AccountList mAccountList;
......@@ -97,6 +99,14 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList
static final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
static final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
sflphoneHome = (SFLPhoneHome) activity;
service = ((SFLphoneApplication) sflphoneHome.getApplication()).getSipService();
Log.i(TAG, "onAttach() service " + service);
}
public static class InfosLoader implements Runnable
{
private View view;
......@@ -185,15 +195,9 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList
}
};
public ContactListFragment(ISipService s)
public ContactListFragment()
{
super();
service = s;
}
public void setService(ISipService s)
{
service = s;
}
public void setAccountList(AccountList accountList) {
......
......@@ -52,17 +52,14 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.savoirfairelinux.sflphone.R;
import com.savoirfairelinux.sflphone.service.ISipService;
public class PrefManagementFragment extends PreferenceFragment
{
static final String TAG = "PrefManagementFragment";
static final String CURRENT_VALUE = "Current value:: ";
private ISipService service;
public PrefManagementFragment(ISipService s)
public PrefManagementFragment()
{
service = s;
}
@Override
......
......@@ -82,7 +82,6 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
static final String TAG = "SFLPhoneHome";
private ButtonSectionFragment buttonFragment;
/* default callID */
static boolean serviceIsOn = false;
private String incomingCallID = "";
private static final int REQUEST_CODE_PREFERENCES = 1;
ImageButton buttonCall, buttonHangup;
......@@ -94,6 +93,7 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
private ISipService service;
public AccountList mAccountList = new AccountList();
public CallList mCallList = new CallList(this);
private SFLphoneApplication mApplication;
private static final int ACTION_BAR_TAB_CONTACT = 0;
private static final int ACTION_BAR_TAB_CALL = 1;
......@@ -113,7 +113,9 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
{
super.onCreate(savedInstanceState);
if (!serviceIsOn) {
mApplication = (SFLphoneApplication) getApplication();
if (!mApplication.isServiceRunning()) {
Log.i(TAG, "starting SipService");
startSipService();
}
......@@ -226,7 +228,7 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
}
Log.i(TAG, "onDestroy: stopping SipService...");
stopService(new Intent(this, SipService.class));
serviceIsOn = false;
mApplication.setServiceRunning(false);
super.onDestroy();
}
......@@ -237,15 +239,15 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
public void onServiceConnected(ComponentName className,
IBinder binder) {
service = ISipService.Stub.asInterface(binder);
mApplication.setSipService(service);
mBound = true;
mContactListFragment.setService(service);
mCallElementList.setService(service);
mAccountList.setSipService(service);
Log.d(TAG, "Service connected");
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
mApplication.setSipService(null);
mBound = false;
Log.d(TAG, "Service disconnected");
}
......@@ -257,7 +259,7 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
//sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
startService(sipServiceIntent);
serviceIsOn = true;
mApplication.setServiceRunning(true);
};
};
try {
......@@ -361,12 +363,12 @@ public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnC
switch (i) {
case 0:
mContactListFragment = new ContactListFragment(service);
mContactListFragment = new ContactListFragment();
mContactListFragment.setAccountList(mAccountList);
fragment = mContactListFragment;
break;
case 1:
mCallElementList = new CallElementList(service, mHome);
mCallElementList = new CallElementList();
SipCall.setCallElementList(mCallElementList);
mCallElementList.setAccountList(mAccountList);
fragment = mCallElementList;
......
......@@ -85,25 +85,6 @@ public class SFLPhonePreferenceActivity extends Activity implements ActionBar.Ta
}
};
private void startSipService() {
Thread thread = new Thread("StartSFLphoneService") {
public void run() {
Intent sipServiceIntent = new Intent(SFLPhonePreferenceActivity.this, SipService.class);
startService(sipServiceIntent);
serviceIsOn = true;
};
};
try {
thread.start();
} catch (IllegalThreadStateException e) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Cannot start SFLPhone SipService!");
AlertDialog alert = builder.create();
alert.show();
finish();
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
......@@ -166,6 +147,10 @@ public class SFLPhonePreferenceActivity extends Activity implements ActionBar.Ta
super.onDestroy();
}
public ISipService getSipService() {
return service;
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
{
......@@ -202,10 +187,10 @@ public class SFLPhonePreferenceActivity extends Activity implements ActionBar.Ta
switch (position) {
case 0:
fragment = new AccountManagementFragment(service);
fragment = new AccountManagementFragment();
break;
case 1:
fragment = new PrefManagementFragment(service);
fragment = new PrefManagementFragment();
break;
default:
Log.i(TAG, "Get new fragment " + position + " is null");
......
......@@ -6,13 +6,13 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
import com.savoirfairelinux.sflphone.service.SipService;
import com.savoirfairelinux.sflphone.service.ISipService;
public class SFLphoneApplication extends Application {
static final String TAG = "SFLphoneApplication";
private boolean serviceRunning;
private SipService sipService;
private ISipService sipService;
@Override
public void onCreate() {
......@@ -34,11 +34,11 @@ public class SFLphoneApplication extends Application {
this.serviceRunning = r;
}
public SipService getSipService() {
public ISipService getSipService() {
return sipService;
}
public void setSipService(SipService service) {
public void setSipService(ISipService service) {
sipService = service;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment