diff --git a/src/com/savoirfairelinux/sflphone/account/AccountManagementUI.java b/src/com/savoirfairelinux/sflphone/account/AccountManagementUI.java deleted file mode 100644 index d58aa7cfa68900476f91d1511aba09571f91c7e9..0000000000000000000000000000000000000000 --- a/src/com/savoirfairelinux/sflphone/account/AccountManagementUI.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.account; - -import java.util.ArrayList; - -import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver; - -public interface AccountManagementUI -{ - public void setAccountList(AccountListReceiver accountList); - - public void accountSelectedNotifyAccountList(String accountID); - - public void setSelectedAccount(String accountID); - - public void accountAdded(ArrayList<String> newList); - - public void accountRemoved(); - - public void accountUpdated(); -} diff --git a/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java b/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java index f0f63cca65f766d719b40d9f94cc2ef81627669a..78ff0b5342fdbd2f80a724abb99e7544223df91f 100644 --- a/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java +++ b/src/com/savoirfairelinux/sflphone/account/AccountSelectionSpinner.java @@ -45,11 +45,10 @@ import com.savoirfairelinux.sflphone.adapters.AccountSelectionAdapter; import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver; import com.savoirfairelinux.sflphone.service.ISipService; -public class AccountSelectionSpinner extends Spinner implements AccountManagementUI { +public class AccountSelectionSpinner extends Spinner { private static final String TAG = AccountSelectionSpinner.class.getSimpleName(); public static final String DEFAULT_ACCOUNT_ID = "IP2IP"; private Context mContext; - private AccountListReceiver mAccountList = null; AccountSelectionAdapter mAdapter; ISipService serviceRef; @@ -82,7 +81,7 @@ public class AccountSelectionSpinner extends Spinner implements AccountManagemen ((RadioButton) view.findViewById(R.id.account_checked)).toggle(); } mAdapter.setSelectedAccount(pos); - accountSelectedNotifyAccountList(mAdapter.getItem(pos)); +// accountSelectedNotifyAccountList(mAdapter.getItem(pos)); // setSelection(cursor.getPosition(),true); } @@ -103,52 +102,56 @@ public class AccountSelectionSpinner extends Spinner implements AccountManagemen setAdapter(mAdapter); } + public String getAccount() { + return mAdapter.getSelectedAccount(); + } + /**************************************** * AccountManagementUI Interface ****************************************/ - @Override - public void setAccountList(AccountListReceiver accountList) { - Log.i(TAG, "setAccountList"); - mAccountList = accountList; - - } - - @Override - public void accountSelectedNotifyAccountList(String accountID) { - Log.i(TAG, "->accountSelectedNotifyAccountList"); - if (mAccountList != null) { - mAccountList.accountSelected(accountID, this); - } - } - - @Override - public void setSelectedAccount(String accountID) { - Log.i(TAG, "Account Selected"); - // setText(accountID); - } - - @Override - public void accountAdded(ArrayList<String> newList) { - mAdapter = new AccountSelectionAdapter(mContext, serviceRef, newList); - setOnItemSelectedListener(onClick); - setAdapter(mAdapter); - // Log.i(TAG, "Account added"); - // mList = newList; - // - // if(newList.size() == 1) { - // setText(newList.get(0)); - // } - } - - @Override - public void accountRemoved() { - Log.i(TAG, "Account Removed"); - } - - @Override - public void accountUpdated() { - Log.i(TAG, "Account Updated"); - } +// @Override +// public void setAccountList(AccountListReceiver accountList) { +// Log.i(TAG, "setAccountList"); +// mAccountList = accountList; +// +// } +// +// @Override +// public void accountSelectedNotifyAccountList(String accountID) { +// Log.i(TAG, "->accountSelectedNotifyAccountList"); +// if (mAccountList != null) { +// mAccountList.accountSelected(accountID, this); +// } +// } +// +// @Override +// public void setSelectedAccount(String accountID) { +// Log.i(TAG, "Account Selected"); +// // setText(accountID); +// } +// +// @Override +// public void accountAdded(ArrayList<String> newList) { +// mAdapter = new AccountSelectionAdapter(mContext, serviceRef, newList); +// setOnItemSelectedListener(onClick); +// setAdapter(mAdapter); +// // Log.i(TAG, "Account added"); +// // mList = newList; +// // +// // if(newList.size() == 1) { +// // setText(newList.get(0)); +// // } +// } +// +// @Override +// public void accountRemoved() { +// Log.i(TAG, "Account Removed"); +// } +// +// @Override +// public void accountUpdated() { +// Log.i(TAG, "Account Updated"); +// } } diff --git a/src/com/savoirfairelinux/sflphone/adapters/AccountSelectionAdapter.java b/src/com/savoirfairelinux/sflphone/adapters/AccountSelectionAdapter.java index 7f4b099303ab5e439c541b97f9bb615217dd8e95..1f73eabd16b26e95c51058f3c18d4ff5c0bbdf70 100644 --- a/src/com/savoirfairelinux/sflphone/adapters/AccountSelectionAdapter.java +++ b/src/com/savoirfairelinux/sflphone/adapters/AccountSelectionAdapter.java @@ -229,4 +229,8 @@ public class AccountSelectionAdapter extends BaseAdapter { selectedAccount = pos; } + public String getSelectedAccount() { + return accountIDs.get(selectedAccount); + } + } diff --git a/src/com/savoirfairelinux/sflphone/adapters/CallElementAdapter.java b/src/com/savoirfairelinux/sflphone/adapters/CallElementAdapter.java index 35b694ffc79368c261564e9e68d120aac6068bc9..c89c236d6f2f67ce7e0cf1d782cfcf9634228b1f 100644 --- a/src/com/savoirfairelinux/sflphone/adapters/CallElementAdapter.java +++ b/src/com/savoirfairelinux/sflphone/adapters/CallElementAdapter.java @@ -1,5 +1,7 @@ package com.savoirfairelinux.sflphone.adapters; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -8,7 +10,7 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; +import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; @@ -19,16 +21,20 @@ import com.savoirfairelinux.sflphone.model.SipCall; * A CursorAdapter that creates and update call elements using corresponding contact infos. TODO: handle contact list separatly to allow showing * synchronized contacts on Call cards with multiple contacts etc. */ -public class CallElementAdapter extends ArrayAdapter { +public class CallElementAdapter extends BaseAdapter { private ExecutorService infos_fetcher = Executors.newCachedThreadPool(); private Context mContext; - private final List mCallList; + private final HashMap<String, SipCall> mCallList; private static final String CURRENT_STATE_LABEL = " CURRENT STATE: "; - public CallElementAdapter(Context context, List callList) { - super(context, R.layout.item_contact, callList); + public CallElementAdapter(Context context, List<SipCall> callList) { + super(); mContext = context; - mCallList = callList; + mCallList = new HashMap<String, SipCall>(); + for(SipCall c : callList){ + mCallList.put(c.getCallId(), c); + } + } @Override @@ -58,8 +64,8 @@ public class CallElementAdapter extends ArrayAdapter { // Transfer the stock data from the data object // to the view objects - SipCall call = (SipCall) mCallList.get(position); - call.setAssociatedRowView(rowView); + + SipCall call = (SipCall) mCallList.values().toArray()[position]; entryView.displayName.setText(call.getDisplayName()); entryView.phones.setText(call.getPhone()); entryView.state.setText(CURRENT_STATE_LABEL + call.getCallStateString()); @@ -76,6 +82,52 @@ public class CallElementAdapter extends ArrayAdapter { protected TextView phones; public TextView state; } - - + + @Override + public int getCount() { + return mCallList.size(); + } + + @Override + public Object getItem(int pos) { + return mCallList.values().toArray()[pos]; + } + + @Override + public long getItemId(int arg0) { + // TODO Auto-generated method stub + return 0; + } + + public void add(SipCall c) { + mCallList.put(c.getCallId(), c); + notifyDataSetChanged(); + + } + + + public void update(String id, String newState) { + if(newState.equals("INCOMING")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_INCOMING); + } else if(newState.equals("RINGING")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_RINGING); + } else if(newState.equals("CURRENT")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_CURRENT); + } else if(newState.equals("HUNGUP")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_HUNGUP); + } else if(newState.equals("BUSY")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_BUSY); + } else if(newState.equals("FAILURE")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_FAILURE); + } else if(newState.equals("HOLD")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_HOLD); + } else if(newState.equals("UNHOLD")) { + mCallList.get(id).setCallState(SipCall.CALL_STATE_CURRENT); + } else { + mCallList.get(id).setCallState(SipCall.CALL_STATE_NONE); + } + notifyDataSetChanged(); + + } + } diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java index 226a4a3f0d8fedd3f6dba1d6239da44c8becfc99..34d3ab51ef477641a6fecd64df01cc24c26d24cb 100644 --- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java +++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java @@ -44,487 +44,476 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; +import android.os.RemoteException; import android.support.v13.app.FragmentStatePagerAdapter; -import android.support.v4.content.LocalBroadcastManager; import android.support.v4.view.ViewPager; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; -import android.view.animation.LinearInterpolator; import android.widget.EditText; import android.widget.ImageButton; import com.savoirfairelinux.sflphone.R; -import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver; import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver; -import com.savoirfairelinux.sflphone.fragments.ButtonSectionFragment; import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; import com.savoirfairelinux.sflphone.fragments.ContactListFragment; import com.savoirfairelinux.sflphone.fragments.HistoryFragment; import com.savoirfairelinux.sflphone.model.SipCall; -import com.savoirfairelinux.sflphone.service.CallManagerCallBack; import com.savoirfairelinux.sflphone.service.ConfigurationManagerCallback; +import com.savoirfairelinux.sflphone.service.ISipClient; import com.savoirfairelinux.sflphone.service.ISipService; import com.savoirfairelinux.sflphone.service.SipService; -public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, OnClickListener { - SectionsPagerAdapter mSectionsPagerAdapter = null; - static final String TAG = "SFLPhoneHome"; - private static final int REQUEST_CODE_PREFERENCES = 1; - ImageButton buttonCall, buttonHangup; - static Animation animation; - private ContactListFragment mContactListFragment = null; - private CallElementListFragment mCallElementList = null; - private HistoryFragment mHistorySectionFragment = null; - private ButtonSectionFragment mButtonSectionFragment = null; - private boolean mBound = false; - private ISipService service; - public AccountListReceiver mAccountList; - public CallListReceiver mCallList = new CallListReceiver(this); - private SFLphoneApplication mApplication; - - private static final int ACTION_BAR_TAB_CONTACT = 0; - private static final int ACTION_BAR_TAB_CALL = 1; - private static final int ACTION_BAR_TAB_HISTORY = 2; - private static final int ACTION_BAR_TAB_TEST = 3; - - /** - * The {@link ViewPager} that will host the section contents. - */ - ViewPager mViewPager; - - 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 - - /* called before activity is killed, e.g. rotation */ - @Override - protected void onSaveInstanceState(Bundle bundle) { - super.onSaveInstanceState(bundle); - for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { - try { - /* putFragment (Bundle bundle, String key, Fragment fragment) */ - getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getFragment(i)); - } catch (IllegalStateException e) { - Log.e(TAG, "IllegalStateException: fragment=" + mSectionsPagerAdapter.getFragment(i)); - } - } - Log.w(TAG, "onSaveInstanceState()"); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mApplication = (SFLphoneApplication) getApplication(); - - // 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); - - if (mSectionsPagerAdapter == null) { - mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); - } - - /* getFragment(Bundle, String) */ - if (savedInstanceState != null) { - Log.w(TAG, "Activity restarted, recreating PagerAdapter..."); - /* getFragment (Bundle bundle, String key) */ - mContactListFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, - mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CONTACT)); - mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState, - mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL)); - mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState, - mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY)); - mButtonSectionFragment = (ButtonSectionFragment) getFragmentManager().getFragment(savedInstanceState, - mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_TEST)); - } - - if (mContactListFragment == null) { - mContactListFragment = new ContactListFragment(); - Log.w(TAG, "Recreated mContactListFragment=" + mContactListFragment); - } - if (mCallElementList == null) { - mCallElementList = new CallElementListFragment(); - Log.w(TAG, "Recreated mCallElementList=" + mCallElementList); - } - if (mHistorySectionFragment == null) { - mHistorySectionFragment = new HistoryFragment(); - Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment); - } - if (mButtonSectionFragment == null) { - mButtonSectionFragment = new ButtonSectionFragment(); - Log.w(TAG, "Recreated mButtonSectionFragment=" + mButtonSectionFragment); - } - - final ActionBar actionBar = getActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - // final ActionBar actionBar = getActionBar(); - - // Set up the ViewPager with the sections adapter. - mViewPager = (ViewPager) findViewById(R.id.pager); - mViewPager.setAdapter(mSectionsPagerAdapter); - - // When swiping between different sections, select the corresponding tab. - // We can also use ActionBar.Tab#select() to do this if we have a reference to the - // Tab. - mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { - @Override - public void onPageSelected(int position) { - actionBar.setSelectedNavigationItem(position); - } - }); - - // For each of the sections in the app, add a tab to the action bar. - for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { - // Create a tab with text corresponding to the page title defined by the adapter. - // Also specify this Activity object, which implements the TabListener interface, as the - // listener for when this tab is selected. - actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); - } - - actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL); - - buttonCall = (ImageButton) findViewById(R.id.buttonCall); - buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp); - - // Change alpha from fully visible to invisible - animation = new AlphaAnimation(1, 0); - // duration - half a second - animation.setDuration(500); - // do not alter animation rate - animation.setInterpolator(new LinearInterpolator()); - // Repeat animation infinitely - animation.setRepeatCount(Animation.INFINITE); - // Reverse - animation.setRepeatMode(Animation.REVERSE); - - IntentFilter callFilter = new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED); - callFilter.addAction(CallManagerCallBack.INCOMING_CALL); - callFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); - LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, callFilter); - - mAccountList = mApplication.getAccountList(); - Log.w(TAG, "mAccountList=" + mAccountList + ", mCallElementList=" + mCallElementList); - - IntentFilter accountFilter = new IntentFilter(ConfigurationManagerCallback.ACCOUNTS_CHANGED); +public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, CallElementListFragment.Callbacks { + SectionsPagerAdapter mSectionsPagerAdapter = null; + static final String TAG = "SFLPhoneHome"; + private static final int REQUEST_CODE_PREFERENCES = 1; + ImageButton buttonCall, buttonHangup; + private ContactListFragment mContactListFragment = null; + private CallElementListFragment mCallElementList = null; + private HistoryFragment mHistorySectionFragment = null; + private boolean mBound = false; + private ISipService service; + // public AccountListReceiver mAccountList; + // public CallListReceiver mCallList = new CallListReceiver(this); + private SFLphoneApplication mApplication; + + private static final int ACTION_BAR_TAB_CONTACT = 0; + private static final int ACTION_BAR_TAB_CALL = 1; + private static final int ACTION_BAR_TAB_HISTORY = 2; + + /** + * The {@link ViewPager} that will host the section contents. + */ + ViewPager mViewPager; + + final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history }; + + // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener + + /* called before activity is killed, e.g. rotation */ + @Override + protected void onSaveInstanceState(Bundle bundle) { + super.onSaveInstanceState(bundle); + for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { + try { + /* putFragment (Bundle bundle, String key, Fragment fragment) */ + getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getFragment(i)); + } catch (IllegalStateException e) { + Log.e(TAG, "IllegalStateException: fragment=" + mSectionsPagerAdapter.getFragment(i)); + } + } + Log.w(TAG, "onSaveInstanceState()"); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mApplication = (SFLphoneApplication) getApplication(); + + // 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); + + if (mSectionsPagerAdapter == null) { + mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); + } + + /* getFragment(Bundle, String) */ + if (savedInstanceState != null) { + Log.w(TAG, "Activity restarted, recreating PagerAdapter..."); + /* getFragment (Bundle bundle, String key) */ + mContactListFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, + mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CONTACT)); + mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState, + mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL)); + mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState, + mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY)); + } + + if (mContactListFragment == null) { + mContactListFragment = new ContactListFragment(); + Log.w(TAG, "Recreated mContactListFragment=" + mContactListFragment); + } + if (mCallElementList == null) { + mCallElementList = new CallElementListFragment(); + Log.w(TAG, "Recreated mCallElementList=" + mCallElementList); + } + if (mHistorySectionFragment == null) { + mHistorySectionFragment = new HistoryFragment(); + Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment); + } + + final ActionBar actionBar = getActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + // final ActionBar actionBar = getActionBar(); + + // Set up the ViewPager with the sections adapter. + mViewPager = (ViewPager) findViewById(R.id.pager); + mViewPager.setAdapter(mSectionsPagerAdapter); + + // When swiping between different sections, select the corresponding tab. + // We can also use ActionBar.Tab#select() to do this if we have a reference to the + // Tab. + mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + actionBar.setSelectedNavigationItem(position); + } + }); + + // For each of the sections in the app, add a tab to the action bar. + for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { + // Create a tab with text corresponding to the page title defined by the adapter. + // Also specify this Activity object, which implements the TabListener interface, as the + // listener for when this tab is selected. + actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); + } + + actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL); + + buttonCall = (ImageButton) findViewById(R.id.buttonCall); + buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp); + + buttonCall.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + processingNewCallAction(); + } + }); + + buttonHangup.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + processingHangUpAction(); + + } + }); + + // IntentFilter callFilter = new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED); + // callFilter.addAction(CallManagerCallBack.INCOMING_CALL); + // callFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); + // LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, callFilter); + // + // mAccountList = mApplication.getAccountList(); + // Log.w(TAG, "mAccountList=" + mAccountList + ", mCallElementList=" + mCallElementList); + + IntentFilter accountFilter = new IntentFilter(ConfigurationManagerCallback.ACCOUNTS_CHANGED); accountFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED); - LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, accountFilter); - - SipCall.setSFLPhoneHomeContext(this); - } - - @Override - protected void onStart() { - Log.i(TAG, "onStart"); - super.onStart(); - } - - /* user gets back to the activity, e.g. through task manager */ - @Override - protected void onRestart() { - super.onRestart(); - } - - /* activity gets back to the foreground and user input */ - @Override - protected void onResume() { - Log.i(TAG, "onResume"); - super.onResume(); - } - - /* activity no more in foreground */ - @Override - protected void onPause() { - super.onPause(); - } - - /* activity is no longer visible */ - @Override - protected void 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 */ - if (mBound) { - Log.i(TAG, "onStop: Unbinding service..."); - unbindService(mConnection); - mBound = false; - } - - /* unregister broadcast receiver */ - LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList); - LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList); - - super.onDestroy(); - } - - - - /** Defines callbacks for service binding, passed to bindService() */ - private ServiceConnection mConnection = new ServiceConnection() { - - @Override - public void onServiceConnected(ComponentName className, IBinder binder) { - service = ISipService.Stub.asInterface(binder); - mApplication.setSipService(service); - mBound = true; - mAccountList.setSipService(service); - mCallElementList.onServiceSipBinded(service); - Log.d(TAG, "Service connected service=" + service); - } - - @Override - public void onServiceDisconnected(ComponentName arg0) { - mApplication.setSipService(null); - mBound = false; - Log.d(TAG, "Service disconnected service=" + service); - } - }; - - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId()); - if (item.getItemId() != 0) { - // When the button is clicked, launch an activity through this intent - Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); - - // Make it a subactivity so we know when it returns - startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); - } - - return super.onOptionsItemSelected(item); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); - return true; - } - - @Override - public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - } - - @Override - public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - // When the given tab is selected, switch to the corresponding page in the ViewPager. - mViewPager.setCurrentItem(tab.getPosition()); - } - - @Override - public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { - // Log.d(TAG, "onTabReselected"); - } - - public void onSelectedCallAction(SipCall call) { - int callState = call.getCallStateInt(); - - if ((callState == SipCall.CALL_STATE_NONE) || (callState == SipCall.CALL_STATE_CURRENT)) { - buttonCall.setEnabled(false); - buttonHangup.setEnabled(true); - } else { - buttonCall.setEnabled(true); - buttonHangup.setEnabled(false); - } - - buttonCall.setTag(call); - buttonHangup.setTag(call); - } - - public void onUnselectedCallAction() { - buttonCall.setTag(null); - buttonCall.setTag(null); - - buttonCall.setEnabled(true); - buttonHangup.setEnabled(false); - } - - public void setIncomingCallID(String accountID, String callID, String from) { - Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")"); - buttonCall.startAnimation(animation); - buttonCall.setImageResource(R.drawable.ic_incomingcall); - } - - /** - * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to one of the primary sections of the app. - */ - public class SectionsPagerAdapter extends FragmentStatePagerAdapter { - - public SectionsPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int i) { - Fragment fragment; - - switch (i) { - case 0: - mContactListFragment = new ContactListFragment(); - fragment = mContactListFragment; - Log.w(TAG, "getItem() ContactListFragment=" + fragment); - break; - case 1: - mCallElementList = new CallElementListFragment(); - SipCall.setCallElementList(mCallElementList); - mCallElementList.setAccountList(mAccountList); - fragment = mCallElementList; - Log.w(TAG, "getItem() CallElementList=" + fragment); - break; - case 2: - fragment = new HistoryFragment(); - Log.w(TAG, "getItem() HistoryFragment=" + fragment); - break; - case 3: - fragment = new ButtonSectionFragment(); - Log.w(TAG, "getItem() ButtonSectionFragment=" + fragment); - break; - default: - Log.e(TAG, "getItem() unknown tab position " + i); - return null; - } - - // Log.i(TAG, "getItem() fragment is " + fragment); - Bundle args = new Bundle(); - args.putInt(HistoryFragment.ARG_SECTION_NUMBER, i + 1); - fragment.setArguments(args); - return fragment; - } - - public Fragment getFragment(int i) { - Fragment fragment; - - switch (i) { - case 0: - fragment = mContactListFragment; - break; - case 1: - fragment = mCallElementList; - break; - case 2: - fragment = mHistorySectionFragment; - break; - case 3: - fragment = mButtonSectionFragment; - break; - default: - Log.e(TAG, "getClassName: unknown fragment position " + i); - fragment = null; - } - - // Log.w(TAG, "getFragment: fragment=" + fragment); - return fragment; - } - - public String getClassName(int i) { - String name; - - switch (i) { - case 0: - name = ContactListFragment.class.getName(); - break; - case 1: - name = CallElementListFragment.class.getName(); - break; - case 2: - name = HistoryFragment.class.getName(); - break; - case 3: - name = ButtonSectionFragment.class.getName(); - break; - default: - Log.e(TAG, "getClassName: unknown fragment position " + i); - return null; - } - - // Log.w(TAG, "getClassName: name=" + name); - return name; - } - - @Override - public int getCount() { - return 4; - } - - @Override - public CharSequence getPageTitle(int position) { - switch (position) { - case 0: - return getString(R.string.title_section0).toUpperCase(); - case 1: - return getString(R.string.title_section1).toUpperCase(); - case 2: - return getString(R.string.title_section2).toUpperCase(); - case 3: - return getString(R.string.title_section3).toUpperCase(); - default: - Log.e(TAG, "getPageTitle: unknown tab position " + position); - break; - } - return null; - } - } - - - @Override - public void onClick(View view) { - Log.i(TAG, "onClic from SFLPhoneHome"); - switch (view.getId()) { - case R.id.buttonCall: - processingNewCallAction(); - break; - case R.id.buttonHangUp: - processingHangUpAction(); - break; - default: - Log.w(TAG, "unknown button " + view.getId()); - break; - } - } - - public void processingNewCallAction() { - // String accountID = mAccountList.currentAccountID; - Log.w(TAG, "processingNewCallAction() mCallElementList=" + mCallElementList); - String accountID = mCallElementList.getSelectedAccount(); - EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry); - String to = editText.getText().toString(); - - Random random = new Random(); - String callID = Integer.toString(random.nextInt()); - SipCall.CallInfo info = new SipCall.CallInfo(); - - info.mCallID = callID; - info.mAccountID = accountID; - info.mDisplayName = "Cool Guy!"; - info.mPhone = to; - info.mEmail = "coolGuy@coolGuy.com"; - info.mCallType = SipCall.CALL_TYPE_OUTGOING; - - SipCall call = CallListReceiver.getCallInstance(info); - call.launchCallActivity(this); - call.placeCallUpdateUi(); - call.notifyServicePlaceCall(service); - - onSelectedCallAction(call); - } - - public void processingHangUpAction() { - SipCall call = (SipCall) buttonHangup.getTag(); - if (call != null) - call.notifyServiceHangup(service); - } + // LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, accountFilter); + +// SipCall.setSFLPhoneHomeContext(this); + } + + @Override + protected void onStart() { + Log.i(TAG, "onStart"); + super.onStart(); + } + + /* user gets back to the activity, e.g. through task manager */ + @Override + protected void onRestart() { + super.onRestart(); + } + + /* activity gets back to the foreground and user input */ + @Override + protected void onResume() { + Log.i(TAG, "onResume"); + super.onResume(); + } + + /* activity no more in foreground */ + @Override + protected void onPause() { + super.onPause(); + } + + /* activity is no longer visible */ + @Override + protected void 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 */ + if (mBound) { + Log.i(TAG, "onStop: Unbinding service..."); + unbindService(mConnection); + mBound = false; + } + + /* unregister broadcast receiver */ + // LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList); + // LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList); + + super.onDestroy(); + } + + public void launchCallActivity(SipCall.CallInfo infos) + { + Log.i(TAG, "Launch Call Activity"); + Bundle bundle = new Bundle(); + bundle.putParcelable("CallInfo", infos); + Intent intent = new Intent().setClass(this, CallActivity.class); + intent.putExtras(bundle); + startActivity(intent); + } + + /** Defines callbacks for service binding, passed to bindService() */ + private ServiceConnection mConnection = new ServiceConnection() { + + private ISipClient callback = new ISipClient.Stub() { + + @Override + public void incomingCall(Intent call) throws RemoteException { + Log.i(TAG, "Incoming call transfered from Service"); + SipCall.CallInfo infos = new SipCall.CallInfo(call); + + SipCall c = new SipCall(infos); + mCallElementList.addCall(c); + } + + @Override + public void callStateChanged(Intent callState) throws RemoteException { + Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); + String cID = b.getString("CallID"); + String state = b.getString("State"); + Log.i(TAG,"callStateChanged"+cID+" "+state); + mCallElementList.updateCall(cID, state); + + } + }; + + @Override + public void onServiceConnected(ComponentName className, IBinder binder) { + service = ISipService.Stub.asInterface(binder); + + try { + service.registerClient(callback); + } catch (RemoteException e) { + Log.e(TAG, e.toString()); + } + mApplication.setSipService(service); + mBound = true; + mCallElementList.onServiceSipBinded(service); + Log.d(TAG, "Service connected service=" + service); + } + + @Override + public void onServiceDisconnected(ComponentName arg0) { + mApplication.setSipService(null); + mBound = false; + Log.d(TAG, "Service disconnected service=" + service); + } + }; + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId()); + if (item.getItemId() != 0) { + // When the button is clicked, launch an activity through this intent + Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); + + // Make it a subactivity so we know when it returns + startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); + } + + return super.onOptionsItemSelected(item); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (REQUEST_CODE_PREFERENCES == requestCode && service != null) { + // Refresh Spinner with modified accounts + mCallElementList.onServiceSipBinded(service); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); + return true; + } + + @Override + public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + } + + @Override + public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + // When the given tab is selected, switch to the corresponding page in the ViewPager. + mViewPager.setCurrentItem(tab.getPosition()); + } + + @Override + public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { + // Log.d(TAG, "onTabReselected"); + } + + + public void processingNewCallAction() { + // String accountID = mAccountList.currentAccountID; + Log.w(TAG, "processingNewCallAction() mCallElementList=" + mCallElementList); + String accountID = mCallElementList.getSelectedAccount(); + EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry); + String to = editText.getText().toString(); + + Random random = new Random(); + String callID = Integer.toString(random.nextInt()); + SipCall.CallInfo info = new SipCall.CallInfo(); + + info.mCallID = callID; + info.mAccountID = accountID; + info.mDisplayName = "Cool Guy!"; + info.mPhone = to; + info.mEmail = "coolGuy@coolGuy.com"; + info.mCallType = SipCall.CALL_TYPE_OUTGOING; + + SipCall call = CallListReceiver.getCallInstance(info); + launchCallActivity(call.mCallInfo); + + try { + service.placeCall(info.mAccountID, info.mCallID, info.mPhone); + } catch (RemoteException e) { + Log.e(TAG, "Cannot call service method", e); + } + mCallElementList.addCall(call); + } + + public void processingHangUpAction() { + SipCall call = (SipCall) buttonHangup.getTag(); + if (call != null) + call.notifyServiceHangup(service); + } + + /** + * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to one of the primary sections of the app. + */ + public class SectionsPagerAdapter extends FragmentStatePagerAdapter { + + public SectionsPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int i) { + Fragment fragment; + + switch (i) { + case 0: + mContactListFragment = new ContactListFragment(); + fragment = mContactListFragment; + Log.w(TAG, "getItem() ContactListFragment=" + fragment); + break; + case 1: + mCallElementList = new CallElementListFragment(); +// SipCall.setCallElementList(mCallElementList); + // mCallElementList.setAccountList(mAccountList); + fragment = mCallElementList; + Log.w(TAG, "getItem() CallElementList=" + fragment); + break; + case 2: + fragment = new HistoryFragment(); + Log.w(TAG, "getItem() HistoryFragment=" + fragment); + break; + default: + Log.e(TAG, "getItem() unknown tab position " + i); + return null; + } + + // Log.i(TAG, "getItem() fragment is " + fragment); + Bundle args = new Bundle(); + args.putInt(HistoryFragment.ARG_SECTION_NUMBER, i + 1); + fragment.setArguments(args); + return fragment; + } + + public Fragment getFragment(int i) { + Fragment fragment; + + switch (i) { + case 0: + fragment = mContactListFragment; + break; + case 1: + fragment = mCallElementList; + break; + case 2: + fragment = mHistorySectionFragment; + break; + default: + Log.e(TAG, "getClassName: unknown fragment position " + i); + fragment = null; + } + + // Log.w(TAG, "getFragment: fragment=" + fragment); + return fragment; + } + + public String getClassName(int i) { + String name; + + switch (i) { + case 0: + name = ContactListFragment.class.getName(); + break; + case 1: + name = CallElementListFragment.class.getName(); + break; + case 2: + name = HistoryFragment.class.getName(); + break; + + default: + Log.e(TAG, "getClassName: unknown fragment position " + i); + return null; + } + + // Log.w(TAG, "getClassName: name=" + name); + return name; + } + + @Override + public int getCount() { + return 3; + } + + @Override + public CharSequence getPageTitle(int position) { + switch (position) { + case 0: + return getString(R.string.title_section0).toUpperCase(); + case 1: + return getString(R.string.title_section1).toUpperCase(); + case 2: + return getString(R.string.title_section2).toUpperCase(); + case 3: + return getString(R.string.title_section3).toUpperCase(); + default: + Log.e(TAG, "getPageTitle: unknown tab position " + position); + break; + } + return null; + } + } + + @Override + public void onCallSelected(SipCall c) { + launchCallActivity(c.mCallInfo); + + } + } diff --git a/src/com/savoirfairelinux/sflphone/client/SFLphoneApplication.java b/src/com/savoirfairelinux/sflphone/client/SFLphoneApplication.java index ca598684ca67b5d809bfca4c19f13ec1a5408711..c04cd33eaa22adf50992c9d92256a205634f033b 100644 --- a/src/com/savoirfairelinux/sflphone/client/SFLphoneApplication.java +++ b/src/com/savoirfairelinux/sflphone/client/SFLphoneApplication.java @@ -14,11 +14,9 @@ import com.savoirfairelinux.sflphone.service.SipService; public class SFLphoneApplication extends Application { - static final String TAG = "SFLphoneApplication"; private boolean serviceRunning = false; private ISipService sipService; - private AccountListReceiver accountList = new AccountListReceiver(); private void startSipService() { @@ -88,11 +86,6 @@ public class SFLphoneApplication extends Application sipService = service; } - public AccountListReceiver getAccountList() - { - return accountList; - } - public String getAppPath() { PackageManager pkgMng = getPackageManager(); diff --git a/src/com/savoirfairelinux/sflphone/client/receiver/AccountListReceiver.java b/src/com/savoirfairelinux/sflphone/client/receiver/AccountListReceiver.java index efd6c5b2ef9d7e8d2a4fa6b09142ff1ba945b194..fa17868fbaf3a331df4fedeb0853a3ca8a051801 100644 --- a/src/com/savoirfairelinux/sflphone/client/receiver/AccountListReceiver.java +++ b/src/com/savoirfairelinux/sflphone/client/receiver/AccountListReceiver.java @@ -31,15 +31,14 @@ package com.savoirfairelinux.sflphone.client.receiver; +import java.util.ArrayList; + import android.content.BroadcastReceiver; -import android.content.Intent; import android.content.Context; +import android.content.Intent; import android.os.RemoteException; import android.util.Log; -import java.util.ArrayList; - -import com.savoirfairelinux.sflphone.account.AccountManagementUI; import com.savoirfairelinux.sflphone.service.ConfigurationManagerCallback; import com.savoirfairelinux.sflphone.service.ISipService; @@ -49,7 +48,7 @@ public class AccountListReceiver extends BroadcastReceiver static final String TAG = "AccountList"; private String currentAccountID = ""; private ArrayList<String> mList = new ArrayList<String>(); - private ArrayList<AccountManagementUI> mUserInterfaceList = new ArrayList<AccountManagementUI>(); +// private ArrayList<AccountManagementUI> mUserInterfaceList = new ArrayList<AccountManagementUI>(); private static ISipService mService = null; // private HashMap<String, AccountPreferenceScreen> mAccountList = new HashMap<String, AccountPreferenceScreen>(); @@ -64,17 +63,17 @@ public class AccountListReceiver extends BroadcastReceiver } - public void addManagementUI(AccountManagementUI ui) { - mUserInterfaceList.add(ui); - } - - public void accountSelected(String accountID, AccountManagementUI userInterface) { - if(!mUserInterfaceList.isEmpty()) { - for(AccountManagementUI ui : mUserInterfaceList) { - ui.setSelectedAccount(accountID); - } - } - } +// public void addManagementUI(AccountManagementUI ui) { +// mUserInterfaceList.add(ui); +// } +// +// public void accountSelected(String accountID, AccountManagementUI userInterface) { +// if(!mUserInterfaceList.isEmpty()) { +// for(AccountManagementUI ui : mUserInterfaceList) { +// ui.setSelectedAccount(accountID); +// } +// } +// } @Override public void onReceive(Context context, Intent intent) @@ -112,20 +111,20 @@ public class AccountListReceiver extends BroadcastReceiver newList.remove(DEFAULT_ACCOUNT_ID); - if(!mUserInterfaceList.isEmpty()) { - - if(newList.size() > mList.size()) { - for(AccountManagementUI ui : mUserInterfaceList) { - ui.accountAdded(newList); - } - } - } +// if(!mUserInterfaceList.isEmpty()) { +// +// if(newList.size() > mList.size()) { +// for(AccountManagementUI ui : mUserInterfaceList) { +// ui.accountAdded(newList); +// } +// } +// } mList = newList; } private void processAccountStateChanged(Intent intent) { - if(!mUserInterfaceList.isEmpty()) { - } +// if(!mUserInterfaceList.isEmpty()) { +// } } } diff --git a/src/com/savoirfairelinux/sflphone/client/receiver/CallListReceiver.java b/src/com/savoirfairelinux/sflphone/client/receiver/CallListReceiver.java index 5b1dc16bde8103cf52dda1852b0ec3e3bff8a274..0a65b06a159bc5dea4e7c2ce728702f22faf1698 100644 --- a/src/com/savoirfairelinux/sflphone/client/receiver/CallListReceiver.java +++ b/src/com/savoirfairelinux/sflphone/client/receiver/CallListReceiver.java @@ -121,7 +121,7 @@ public class CallListReceiver extends BroadcastReceiver call.setCallState(SipCall.CALL_STATE_CURRENT); } else if(newState.equals("HUNGUP")) { call.setCallState(SipCall.CALL_STATE_HUNGUP); - call.hangupUpdateUi(); +// call.hangupUpdateUi(); mList.remove(call); } else if(newState.equals("BUSY")) { call.setCallState(SipCall.CALL_STATE_BUSY); @@ -151,7 +151,7 @@ public class CallListReceiver extends BroadcastReceiver info.mCallType = SipCall.CALL_TYPE_INCOMING; SipCall call = getCallInstance(info); - call.receiveCallUpdateUi(); - call.launchCallActivity(mHome); +// call.receiveCallUpdateUi(); +// call.launchCallActivity(mHome); } } diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java index fb9f83b7b1e34c3bbea04183203d7130cb206ae5..82d3abaead61c073e590e6c8c4550c6f32a72270 100644 --- a/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java +++ b/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java @@ -43,6 +43,7 @@ import android.content.ContentUris; import android.content.Context; import android.content.CursorLoader; import android.content.DialogInterface; +import android.content.Intent; import android.content.Loader; import android.database.Cursor; import android.graphics.Bitmap; @@ -60,12 +61,14 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListView; import com.savoirfairelinux.sflphone.R; import com.savoirfairelinux.sflphone.account.AccountSelectionSpinner; import com.savoirfairelinux.sflphone.adapters.CallElementAdapter; +import com.savoirfairelinux.sflphone.client.CallActivity; import com.savoirfairelinux.sflphone.client.SFLPhoneHomeActivity; import com.savoirfairelinux.sflphone.client.SFLphoneApplication; import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver; @@ -77,35 +80,59 @@ import com.savoirfairelinux.sflphone.service.ISipService; */ public class CallElementListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> { private static final String TAG = CallElementListFragment.class.getSimpleName(); - - // private ContactManager mContactManager; private CallElementAdapter mAdapter; private String mCurFilter; private SFLPhoneHomeActivity sflphoneHome; - // private SFLphoneApplication sflphoneApplication; private ISipService service; private AccountSelectionSpinner mAccountSelectionSpinner; - private AccountListReceiver mAccountList; - private boolean isReady = false; static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.LOOKUP_KEY }; 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 }; + private Callbacks mCallbacks = sDummyCallbacks; + /** + * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. + */ + private static Callbacks sDummyCallbacks = new Callbacks() { + @Override + public void onCallSelected(SipCall c) { + } + + }; + + /** + * The Activity calling this fragment has to implement this interface + * + */ + public interface Callbacks { + public void onCallSelected(SipCall c); + + } + @Override public void onAttach(Activity activity) { super.onAttach(activity); sflphoneHome = (SFLPhoneHomeActivity) activity; service = ((SFLphoneApplication) sflphoneHome.getApplication()).getSipService(); - mAccountList = ((SFLphoneApplication) sflphoneHome.getApplication()).getAccountList(); + if (!(activity instanceof Callbacks)) { + throw new IllegalStateException("Activity must implement fragment's callbacks."); + } + + mCallbacks = (Callbacks) activity; Log.w(TAG, "onAttach() service=" + service + ", accountList=" + mAccountList); } + + @Override + public void onDetach(){ + super.onDetach(); + mCallbacks = sDummyCallbacks; + } public String getSelectedAccount() { - // return mAccountSelectionButton.getText().toString(); - return "CIOUCOU"; + return mAccountSelectionSpinner.getAccount(); } /** @@ -180,10 +207,10 @@ public class CallElementListFragment extends ListFragment implements LoaderManag mAdapter.add(c); } - public void removeCall(SipCall c) { - Log.i(TAG, "Removing call " + c.mCallInfo.mDisplayName); - mAdapter.remove(c); - } + // public void removeCall(SipCall c) { + // Log.i(TAG, "Removing call " + c.mCallInfo.mDisplayName); + // mAdapter.remove(c); + // } @Override public void onActivityCreated(Bundle savedInstanceState) { @@ -197,7 +224,7 @@ public class CallElementListFragment extends ListFragment implements LoaderManag setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. - ArrayList calls = new ArrayList(); + ArrayList<SipCall> calls = new ArrayList<SipCall>(); mAdapter = new CallElementAdapter(getActivity(), calls); setListAdapter(mAdapter); @@ -248,6 +275,25 @@ public class CallElementListFragment extends ListFragment implements LoaderManag return true; } }); + + lv.setOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) { + mCallbacks.onCallSelected((SipCall) mAdapter.getItem(pos)); + + } + + }); + } + + public void launchCallActivity(SipCall call) { + Log.i(TAG, "Launch Call Activity"); + Bundle bundle = new Bundle(); + bundle.putParcelable("CallInfo", call.mCallInfo); + Intent intent = new Intent().setClass(getActivity(), CallActivity.class); + intent.putExtras(bundle); + getActivity().startActivity(intent); } @Override @@ -256,9 +302,6 @@ public class CallElementListFragment extends ListFragment implements LoaderManag View inflatedView = inflater.inflate(R.layout.frag_call_element, container, false); mAccountSelectionSpinner = (AccountSelectionSpinner) inflatedView.findViewById(R.id.account_selection_button); - mAccountList.addManagementUI(mAccountSelectionSpinner); - mAccountSelectionSpinner.setAccountList(mAccountList); - isReady = true; if (service != null) { onServiceSipBinded(service); @@ -266,16 +309,6 @@ public class CallElementListFragment extends ListFragment implements LoaderManag return inflatedView; } - public void onListItemClick(ListView l, View v, int position, long id) { - // Insert desired behavior here. - SipCall call = (SipCall) mAdapter.getItem(position); - Log.i(TAG, "Call Clicked: " + call.getCallId()); - - call.launchCallActivity(getActivity()); - - sflphoneHome.onSelectedCallAction(call); - } - @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { @@ -344,4 +377,9 @@ public class CallElementListFragment extends ListFragment implements LoaderManag } + public void updateCall(String iD, String newState) { + mAdapter.update(iD, newState); + + } + } diff --git a/src/com/savoirfairelinux/sflphone/fragments/ContactListFragment.java b/src/com/savoirfairelinux/sflphone/fragments/ContactListFragment.java index 2cdca05040554bbcb258e0b46c7af8578e06bb61..9e4c7c438335aa6b419fb314847d9de5f8a32b42 100644 --- a/src/com/savoirfairelinux/sflphone/fragments/ContactListFragment.java +++ b/src/com/savoirfairelinux/sflphone/fragments/ContactListFragment.java @@ -91,7 +91,6 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList private SFLPhoneHomeActivity sflphoneHome; private SFLphoneApplication sflphoneApplication; private ISipService service; - private AccountListReceiver mAccountList; // These are the Contacts rows that we will retrieve. static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.LOOKUP_KEY }; @@ -104,9 +103,6 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList sflphoneHome = (SFLPhoneHomeActivity) activity; sflphoneApplication = (SFLphoneApplication) sflphoneHome.getApplication(); service = sflphoneApplication.getSipService(); - mAccountList = sflphoneApplication.getAccountList(); - - Log.w(TAG, "onAttach() service=" + service + ", mAccountList=" + mAccountList); } public static class InfosLoader implements Runnable { @@ -226,7 +222,7 @@ public class ContactListFragment extends ListFragment implements OnQueryTextList Log.i(TAG, "Selected " + items[item]); switch (item) { case 0: - call.placeCallUpdateUi(); +// call.placeCallUpdateUi(); break; case 1: call.sendTextMessage(); diff --git a/src/com/savoirfairelinux/sflphone/model/SipCall.java b/src/com/savoirfairelinux/sflphone/model/SipCall.java index 679d2dfe3aa45bb7f3748f1e46c7bb377e211ca7..c9b6f415d4da42b8b3559806bf1d87ecb331f72b 100644 --- a/src/com/savoirfairelinux/sflphone/model/SipCall.java +++ b/src/com/savoirfairelinux/sflphone/model/SipCall.java @@ -51,10 +51,7 @@ public class SipCall { final static String TAG = "SipCall"; public CallInfo mCallInfo; - // Update UI on actions (answer, hangup) - static private CallElementListFragment mCallElementList = null; - static private SFLPhoneHomeActivity mHome = null; - private View mRowView = null; + public static final int CALL_TYPE_UNDETERMINED = 0; public static final int CALL_TYPE_INCOMING = 1; @@ -139,6 +136,13 @@ public class SipCall mCallState = in.readInt(); mMediaState = in.readInt(); } + + public CallInfo(Intent call) { + Bundle b = call.getBundleExtra("com.savoirfairelinux.sflphone.service.newcall"); + mAccountID = b.getString("AccountID"); + mCallID = b.getString("CallID"); + mDisplayName = b.getString("From"); + } } public SipCall() @@ -151,20 +155,7 @@ public class SipCall mCallInfo = info; } - public static void setCallElementList(CallElementListFragment list) - { - mCallElementList = list; - } - - public static void setSFLPhoneHomeContext(SFLPhoneHomeActivity home) - { - mHome = home; - } - public void setAssociatedRowView(View view) - { - mRowView = view; - } public void setCallID(String callID) { mCallInfo.mCallID = callID; @@ -224,15 +215,6 @@ public class SipCall public void setCallState(int callState) { mCallInfo.mCallState = callState; - - // Check if this call is associated to a view in CallElementList - if(mRowView == null) - return; - - // Update the state to the view - CallElementView entryView = (CallElementView) mRowView.getTag(); - final String CURRENT_STATE_LABEL = " CURRENT STATE: "; - entryView.state.setText(CURRENT_STATE_LABEL + getCallStateString()); } public int getCallStateInt() { @@ -283,39 +265,7 @@ public class SipCall return mCallInfo.mMediaState; } - public void placeCallUpdateUi() - { - if(mCallElementList != null) - mCallElementList.addCall(this); - - if(mHome != null) - mHome.onSelectedCallAction(this); - } - - public void notifyServicePlaceCall(ISipService service) - { - try { - service.placeCall(mCallInfo.mAccountID, mCallInfo.mCallID, mCallInfo.mPhone); - } catch (RemoteException e) { - Log.e(TAG, "Cannot call service method", e); - } - } - - public void receiveCallUpdateUi() - { - if(mCallElementList != null) - mCallElementList.addCall(this); - - if(mHome != null) - mHome.onSelectedCallAction(this); - } - - public void answerUpdateUi() - { - if(mHome != null) - mHome.onSelectedCallAction(this); - - } + public boolean notifyServiceAnswer(ISipService service) { @@ -338,15 +288,15 @@ public class SipCall * Perform hangup action without sending request to the service * Used when SipService haved been notified that this call hung up */ - public void hangupUpdateUi() { - Log.i(TAG, "Hangup call " + mCallInfo.mCallID); - - if(mCallElementList != null) - mCallElementList.removeCall(this); - - if(mHome != null) - mHome.onUnselectedCallAction(); - } +// public void hangupUpdateUi() { +// Log.i(TAG, "Hangup call " + mCallInfo.mCallID); +// +// if(mCallElementList != null) +// mCallElementList.removeCall(this); +// +// if(mHome != null) +// mHome.onUnselectedCallAction(); +// } /** * Perform hangup action and send request to the service @@ -440,13 +390,17 @@ public class SipCall Log.i(TAG, " Contact: " + mCallInfo.mRemoteContact); } - public void launchCallActivity(Context context) - { - Log.i(TAG, "Launch Call Activity"); - Bundle bundle = new Bundle(); - bundle.putParcelable("CallInfo", mCallInfo); - Intent intent = new Intent().setClass(context, CallActivity.class); - intent.putExtras(bundle); - context.startActivity(intent); + + + /** + * Compare sip calls based on call ID + */ + @Override + public boolean equals(Object c){ + if(c instanceof SipCall && ((SipCall) c).mCallInfo.mCallID == mCallInfo.mCallID){ + return true; + } + return false; + } } diff --git a/src/com/savoirfairelinux/sflphone/service/ISipClient.aidl b/src/com/savoirfairelinux/sflphone/service/ISipClient.aidl new file mode 100644 index 0000000000000000000000000000000000000000..b845f664584af35063ae9d7b6da6bfbf96a98cdf --- /dev/null +++ b/src/com/savoirfairelinux/sflphone/service/ISipClient.aidl @@ -0,0 +1,6 @@ +package com.savoirfairelinux.sflphone.service; + +interface ISipClient { + void incomingCall(in Intent call); + void callStateChanged(in Intent callState); +} \ No newline at end of file diff --git a/src/com/savoirfairelinux/sflphone/service/ISipService.aidl b/src/com/savoirfairelinux/sflphone/service/ISipService.aidl index 1bcf4b52a7f554ba06875d1f17a027df70b2d5e7..cb7bf4674bb56c3ad38c047f1d4dfb30ba2f9791 100644 --- a/src/com/savoirfairelinux/sflphone/service/ISipService.aidl +++ b/src/com/savoirfairelinux/sflphone/service/ISipService.aidl @@ -1,5 +1,7 @@ package com.savoirfairelinux.sflphone.service; +import com.savoirfairelinux.sflphone.service.ISipClient; + interface ISipService { void placeCall(String accountID, in String callID, in String to); void refuse(in String callID); @@ -14,4 +16,5 @@ interface ISipService { void setAccountDetails(in String accountId, in Map accountDetails); void setAudioPlugin(in String callID); String getCurrentAudioOutputPlugin(); + void registerClient(in ISipClient callback); } diff --git a/src/com/savoirfairelinux/sflphone/service/SipService.java b/src/com/savoirfairelinux/sflphone/service/SipService.java index ec1f0b6d127b6e0049cbc1ee4528834244dbbbd0..6edce10045b25e353a6366255c0cbffda1031281 100644 --- a/src/com/savoirfairelinux/sflphone/service/SipService.java +++ b/src/com/savoirfairelinux/sflphone/service/SipService.java @@ -39,14 +39,13 @@ import android.os.HandlerThread; import android.os.IBinder; import android.os.Looper; import android.os.Message; -import android.os.Vibrator; +import android.os.RemoteException; import android.support.v4.content.LocalBroadcastManager; import android.util.Log; import android.widget.Toast; import com.savoirfairelinux.sflphone.account.AccountDetailsHandler; import com.savoirfairelinux.sflphone.client.SFLphoneApplication; -import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver; public class SipService extends Service { @@ -63,8 +62,7 @@ public class SipService extends Service { private ConfigurationManagerCallback configurationManagerCallback; private ManagerImpl managerImpl; private boolean isPjSipStackStarted = false; - public CallListReceiver mCallList; - + ISipClient client; /* Implement public interface for the service */ private final ISipService.Stub mBinder = new ISipService.Stub() { @@ -138,11 +136,11 @@ public class SipService extends Service { @Override public void setAudioPlugin(final String audioPlugin) { getExecutor().execute(new SipRunnable() { - @Override - protected void doRun() throws SameThreadException { - Log.i(TAG, "SipService.setAudioPlugin() thread running..."); - configurationManagerJNI.setAudioPlugin(audioPlugin); - } + @Override + protected void doRun() throws SameThreadException { + Log.i(TAG, "SipService.setAudioPlugin() thread running..."); + configurationManagerJNI.setAudioPlugin(audioPlugin); + } }); } @@ -154,11 +152,13 @@ public class SipService extends Service { Log.i(TAG, "SipService.getCurrentAudioOutputPlugin() thread running..."); return configurationManagerJNI.getCurrentAudioOutputPlugin(); } - }; + } + ; CurrentAudioPlugin runInstance = new CurrentAudioPlugin(); getExecutor().execute(runInstance); - while(!runInstance.isDone()) {} + while (!runInstance.isDone()) { + } return (String) runInstance.getVal(); } @@ -170,36 +170,44 @@ public class SipService extends Service { Log.i(TAG, "SipService.getAccountList() thread running..."); return configurationManagerJNI.getAccountList(); } - }; + } + ; AccountList runInstance = new AccountList(); getExecutor().execute(runInstance); - while(!runInstance.isDone()) {} + while (!runInstance.isDone()) { + } StringVect swigvect = (StringVect) runInstance.getVal(); ArrayList<String> nativelist = new ArrayList<String>(); - for(int i = 0; i < swigvect.size(); i++) - nativelist.add(swigvect.get(i)); + for (int i = 0; i < swigvect.size(); i++) + nativelist.add(swigvect.get(i)); return nativelist; - } + } @Override - public HashMap<String,String> getAccountDetails(final String accountID) { + public HashMap<String, String> getAccountDetails(final String accountID) { class AccountDetails extends SipRunnableWithReturn { private String id; - AccountDetails(String accountId) { id = accountId; } + + AccountDetails(String accountId) { + id = accountId; + } + @Override protected StringMap doRun() throws SameThreadException { Log.i(TAG, "SipService.getAccountDetails() thread running..."); return configurationManagerJNI.getAccountDetails(id); } - }; + } + ; AccountDetails runInstance = new AccountDetails(accountID); getExecutor().execute(runInstance); - while(!runInstance.isDone()) {} - StringMap swigmap = (StringMap) runInstance.getVal(); + while (!runInstance.isDone()) { + } + StringMap swigmap = (StringMap) runInstance.getVal(); HashMap<String, String> nativemap = AccountDetailsHandler.convertSwigToNative(swigmap); @@ -208,7 +216,7 @@ public class SipService extends Service { @Override public void setAccountDetails(final String accountId, Map map) { - HashMap<String,String> nativemap = (HashMap<String,String>) map; + HashMap<String, String> nativemap = (HashMap<String, String>) map; final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig(nativemap); @@ -225,19 +233,25 @@ public class SipService extends Service { public String addAccount(Map map) { class AddAccount extends SipRunnableWithReturn { StringMap map; - AddAccount(StringMap m) { map = m; } + + AddAccount(StringMap m) { + map = m; + } + @Override protected String doRun() throws SameThreadException { Log.i(TAG, "SipService.getAccountDetails() thread running..."); return configurationManagerJNI.addAccount(map); } - }; + } + ; - final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String,String>)map); + final StringMap swigmap = AccountDetailsHandler.convertFromNativeToSwig((HashMap<String, String>) map); AddAccount runInstance = new AddAccount(swigmap); getExecutor().execute(runInstance); - while(!runInstance.isDone()) {} + while (!runInstance.isDone()) { + } String accountId = (String) runInstance.getVal(); return accountId; @@ -253,21 +267,39 @@ public class SipService extends Service { } }); } + + @Override + public void registerClient(ISipClient callback) throws RemoteException { + client = callback; + } }; private BroadcastReceiver IncomingReceiver = new BroadcastReceiver() { - + @Override public void onReceive(Context context, Intent intent) { - Log.i(TAG, "Received"+ intent.getAction()); - // Get instance of Vibrator from current Context - Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); - mVibrator.vibrate(300); + // Get instance of Vibrator from current Context + // Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + // mVibrator.vibrate(300); + try { + if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_CALL)) { + Log.i(TAG, "Received" + intent.getAction()); + + client.incomingCall(intent); + + } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) { + Log.i(TAG, "Received" + intent.getAction()); + client.callStateChanged(intent); + } else if (intent.getAction().contentEquals(CallManagerCallBack.NEW_CALL_CREATED)) { + Log.i(TAG, "Received" + intent.getAction()); + } + } catch (RemoteException e) { + Log.e(TAG, e.toString()); + } } }; /** - * Class used for the client Binder. Because we know this service always - * runs in the same process as its clients, we don't need to deal with IPC. + * Class used for the client Binder. Because we know this service always runs in the same process as its clients, we don't need to deal with IPC. */ public class LocalBinder extends Binder { public SipService getService() { @@ -276,18 +308,27 @@ public class SipService extends Service { } } + @Override + public boolean onUnbind(Intent i) { + super.onUnbind(i); + Log.i(TAG, "onUnbind(intent)"); + return false; + + } + /* called once by startService() */ @Override public void onCreate() { Log.i(TAG, "onCreated"); super.onCreate(); + sflphoneApp = (SFLphoneApplication) getApplication(); sipServiceThread = new SipServiceThread(); - mCallList = new CallListReceiver(); - - IntentFilter callFilter = new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED); + + IntentFilter callFilter = new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED); callFilter.addAction(CallManagerCallBack.INCOMING_CALL); - LocalBroadcastManager.getInstance(this).registerReceiver(IncomingReceiver , callFilter); + callFilter.addAction(CallManagerCallBack.NEW_CALL_CREATED); + LocalBroadcastManager.getInstance(this).registerReceiver(IncomingReceiver, callFilter); getExecutor().execute(new StartRunnable()); } @@ -316,7 +357,7 @@ public class SipService extends Service { sflphoneApp.setServiceRunning(false); Toast.makeText(this, "Sflphone Service stopped", Toast.LENGTH_SHORT).show(); super.onDestroy(); - + Log.i(TAG, "onDestroyed"); } @@ -327,7 +368,7 @@ public class SipService extends Service { } private static Looper createLooper() { - if(executorThread == null) { + if (executorThread == null) { Log.d(TAG, "Creating new handler thread"); // ADT gives a fake warning due to bad parse rule. executorThread = new HandlerThread("SipService.Executor"); @@ -437,7 +478,7 @@ public class SipService extends Service { public void run() { try { doRun(); - }catch(SameThreadException e) { + } catch (SameThreadException e) { Log.e(TAG, "Not done from same thread"); } } @@ -460,8 +501,8 @@ public class SipService extends Service { public void run() { try { obj = doRun(); - done = true; - }catch(SameThreadException e) { + done = true; + } catch (SameThreadException e) { Log.e(TAG, "Not done from same thread"); } } @@ -475,16 +516,16 @@ public class SipService extends Service { } private class SipServiceThread extends Thread { - + public SipServiceThread() { super("sipServiceThread"); } - + @Override public void run() { Log.i(TAG, "SipService thread running..."); SipService sipService = SipService.this; - while(sipService.runFlag) { + while (sipService.runFlag) { try { Thread.sleep(DELAY); } catch (InterruptedException e) {