* #24938 Modified interface to integrate DialingFragment
* #24839 Added serachview icon on ContactsDrawer
Added getCallList method in JNI for future dev
diff --git a/src/com/savoirfairelinux/sflphone/adapters/MenuAdapter.java b/src/com/savoirfairelinux/sflphone/adapters/MenuAdapter.java
new file mode 100644
index 0000000..2f9ac3f
--- /dev/null
+++ b/src/com/savoirfairelinux/sflphone/adapters/MenuAdapter.java
@@ -0,0 +1,53 @@
+package com.savoirfairelinux.sflphone.adapters;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import com.savoirfairelinux.sflphone.R;
+
+public class MenuAdapter extends BaseAdapter{
+
+ private static final String TAG = MenuAdapter.class.getSimpleName();
+ private Context mContext;
+ String categories[];
+
+ public MenuAdapter(Context c, String[] cat) {
+ mContext = c;
+ categories = cat;
+ }
+
+ @Override
+ public View getView(int pos, View convertView, ViewGroup parent) {
+ View v = convertView;
+
+ LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ if (v == null) {
+ v = inflater.inflate(R.layout.item_menu, null);
+ }
+
+ ((TextView) v.findViewById(R.id.menu_title_categorie)).setText(categories[pos]);
+
+ return v;
+ }
+
+ @Override
+ public int getCount() {
+ return categories.length;
+ }
+
+ @Override
+ public String getItem(int pos) {
+ return categories[pos];
+ }
+
+ @Override
+ public long getItemId(int arg0) {
+ return 0;
+ }
+
+
+}
diff --git a/src/com/savoirfairelinux/sflphone/adapters/SectionsPagerAdapter.java b/src/com/savoirfairelinux/sflphone/adapters/SectionsPagerAdapter.java
new file mode 100644
index 0000000..3fbf79d
--- /dev/null
+++ b/src/com/savoirfairelinux/sflphone/adapters/SectionsPagerAdapter.java
@@ -0,0 +1,119 @@
+package com.savoirfairelinux.sflphone.adapters;
+
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v13.app.FragmentStatePagerAdapter;
+import android.util.Log;
+
+import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
+import com.savoirfairelinux.sflphone.fragments.DialingFragment;
+import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
+
+public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
+
+ private static final String TAG = SectionsPagerAdapter.class.getSimpleName();
+ Context mContext;
+
+ public SectionsPagerAdapter(Context c, FragmentManager fm) {
+ super(fm);
+ mContext = c;
+ }
+
+ @Override
+ public Fragment getItem(int i) {
+ Fragment fragment;
+
+ switch (i) {
+ case 0:
+ fragment = new DialingFragment();
+ Log.w(TAG, "getItem() DialingFragment=" + fragment);
+ break;
+ case 1:
+ fragment = new CallElementListFragment();
+ 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 = new DialingFragment();
+// break;
+// case 1:
+// fragment = new CallElementListFragment();
+// break;
+// case 2:
+// fragment = new HistoryFragment();
+// 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 = DialingFragment.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 mContext.getString(R.string.title_section0).toUpperCase();
+ case 1:
+ return mContext.getString(R.string.title_section1).toUpperCase();
+ case 2:
+ return mContext.getString(R.string.title_section2).toUpperCase();
+ default:
+ Log.e(TAG, "getPageTitle: unknown tab position " + position);
+ break;
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/com/savoirfairelinux/sflphone/client/CallActivity.java b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
index fd2f038..122ee33 100644
--- a/src/com/savoirfairelinux/sflphone/client/CallActivity.java
+++ b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
@@ -46,6 +46,7 @@
import android.graphics.PointF;
import android.os.Bundle;
import android.os.IBinder;
+import android.os.Parcelable;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -64,343 +65,313 @@
import com.savoirfairelinux.sflphone.service.ISipService;
import com.savoirfairelinux.sflphone.service.SipService;
-public class CallActivity extends Activity
-{
- static final String TAG = "CallActivity";
- private ISipService service;
- private String pendingAction = null;
- private SipCall mCall;
+public class CallActivity extends Activity {
+ static final String TAG = "CallActivity";
+ private ISipService service;
+ private String pendingAction = null;
+ private SipCall mCall;
- private BubblesView view;
- private BubbleModel model;
- private PointF screenCenter;
- private DisplayMetrics metrics;
+ private BubblesView view;
+ private BubbleModel model;
+ private PointF screenCenter;
+ private DisplayMetrics metrics;
- private HashMap<CallContact, Bubble> contacts = new HashMap<CallContact, Bubble>();
+ private HashMap<CallContact, Bubble> contacts = new HashMap<CallContact, Bubble>();
- private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
+ private ExecutorService infos_fetcher = Executors.newCachedThreadPool();
- public interface CallFragment
- {
- void setCall(SipCall c);
- }
- /*
- private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent)
- {
- String signalName = intent.getStringExtra(CallManagerCallBack.SIGNAL_NAME);
- Log.d(TAG, "Signal received: " + signalName);
+ public interface CallFragment {
+ void setCall(SipCall c);
+ }
- if (signalName.equals(CallManagerCallBack.NEW_CALL_CREATED)) {
- } else if (signalName.equals(CallManagerCallBack.CALL_STATE_CHANGED)) {
- processCallStateChangedSignal(intent);
- } else if (signalName.equals(CallManagerCallBack.INCOMING_CALL)) {
- }
- }
- };
- */
- private ISipClient callback = new ISipClient.Stub() {
+ /*
+ * private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
+ *
+ * @Override public void onReceive(Context context, Intent intent) { String signalName = intent.getStringExtra(CallManagerCallBack.SIGNAL_NAME);
+ * Log.d(TAG, "Signal received: " + signalName);
+ *
+ * if (signalName.equals(CallManagerCallBack.NEW_CALL_CREATED)) { } else if (signalName.equals(CallManagerCallBack.CALL_STATE_CHANGED)) {
+ * processCallStateChangedSignal(intent); } else if (signalName.equals(CallManagerCallBack.INCOMING_CALL)) { } } };
+ */
+ 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);
- //
- }
+ @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);
+ //
+ }
- @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);
- processCallStateChangedSignal(cID, state);
- }
+ @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);
+ processCallStateChangedSignal(cID, state);
+ }
- @Override
- public void incomingText(Intent msg) throws RemoteException {
- Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
- b.getString("CallID");
- String from = b.getString("From");
- String mess = b.getString("Msg");
- Toast.makeText(getApplicationContext(), "text from "+from+" : " + mess , Toast.LENGTH_LONG).show();
- }
- };
+ @Override
+ public void incomingText(Intent msg) throws RemoteException {
+ Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
+ b.getString("CallID");
+ String from = b.getString("From");
+ String mess = b.getString("Msg");
+ Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
+ }
+ };
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.bubbleview_layout);
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.bubbleview_layout);
- model = new BubbleModel(getResources().getDisplayMetrics().density);
- metrics = getResources().getDisplayMetrics();
- screenCenter = new PointF(metrics.widthPixels / 2, metrics.heightPixels / 3);
- //radiusCalls = metrics.widthPixels / 2 - 150;
- // model.listBubbles.add(new Bubble(this, metrics.widthPixels / 2, metrics.heightPixels / 4, 150, R.drawable.me));
- // model.listBubbles.add(new Bubble(this, metrics.widthPixels / 2, metrics.heightPixels / 4 * 3, 150, R.drawable.callee));
+ model = new BubbleModel(getResources().getDisplayMetrics().density);
+ metrics = getResources().getDisplayMetrics();
+ screenCenter = new PointF(metrics.widthPixels / 2, metrics.heightPixels / 3);
+ // radiusCalls = metrics.widthPixels / 2 - 150;
+ // model.listBubbles.add(new Bubble(this, metrics.widthPixels / 2, metrics.heightPixels / 4, 150, R.drawable.me));
+ // model.listBubbles.add(new Bubble(this, metrics.widthPixels / 2, metrics.heightPixels / 4 * 3, 150, R.drawable.callee));
- view = (BubblesView) findViewById(R.id.main_view);
- view.setModel(model);
+ view = (BubblesView) findViewById(R.id.main_view);
+ view.setModel(model);
+ Bundle b = getIntent().getExtras();
- Bundle b = getIntent().getExtras();
- // Parcelable value = b.getParcelable("CallInfo");
- // SipCall.CallInfo info = b.getParcelable("CallInfo");
- // Log.i(TAG, "Starting activity for call " + info.mCallID);
- // mCall = new SipCall(info);
- //
- Intent intent = new Intent(this, SipService.class);
+
+ SipCall.CallInfo info = b.getParcelable("CallInfo");
+ Log.i(TAG, "Starting activity for call " + info.mCallID);
+ mCall = new SipCall(info);
- //setCallStateDisplay(mCall.getCallStateString());
+ Intent intent = new Intent(this, SipService.class);
- pendingAction = b.getString("action");
- if(pendingAction != null && pendingAction.equals("call")) {
- CallContact contact = b.getParcelable("CallContact");
+ // setCallStateDisplay(mCall.getCallStateString());
- Log.i(TAG,"Calling "+ contact.getmDisplayName());
- callContact(contact);
- // SipCall.CallInfo info = new SipCall.CallInfo();
- // Random random = new Random();
- // String callID = Integer.toString(random.nextInt());
- // Phone phone = contact.getSipPhone();
+ pendingAction = b.getString("action");
+ if (pendingAction != null && pendingAction.equals("call")) {
+ CallContact contact = b.getParcelable("CallContact");
- // info.mCallID = callID;
- // info.mAccountID = ""+contact.getId();
- // info.mDisplayName = contact.getmDisplayName();
- // info.mPhone = phone==null?null:phone.toString();
- // info.mEmail = contact.getmEmail();
- // info.mCallType = SipCall.CALL_TYPE_OUTGOING;
+ Log.i(TAG, "Calling " + contact.getmDisplayName());
+ callContact(contact);
+ // SipCall.CallInfo info = new SipCall.CallInfo();
+ // Random random = new Random();
+ // String callID = Integer.toString(random.nextInt());
+ // Phone phone = contact.getSipPhone();
- // mCall = CallListReceiver.getCallInstance(info);
+ // info.mCallID = callID;
+ // info.mAccountID = ""+contact.getId();
+ // info.mDisplayName = contact.getmDisplayName();
+ // info.mPhone = phone==null?null:phone.toString();
+ // info.mEmail = contact.getmEmail();
+ // info.mCallType = SipCall.CALL_TYPE_OUTGOING;
+ // mCall = CallListReceiver.getCallInstance(info);
- //mCallbacks.onCallSelected(call);
+ // mCallbacks.onCallSelected(call);
- /* try {
- service.placeCall(info.mAccountID, info.mCallID, info.mPhone);
- } catch (RemoteException e) {
- Log.e(TAG, "Cannot call service method", e);
- }*/
- bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
+ /*
+ * try { service.placeCall(info.mAccountID, info.mCallID, info.mPhone); } catch (RemoteException e) { Log.e(TAG,
+ * "Cannot call service method", e); }
+ */
- } else if(pendingAction.equals("incoming")) {
- callIncoming();
- }
+ } else if (pendingAction.equals("incoming")) {
+ callIncoming();
+ }
- /*
- LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED));
- LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED));
- LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.INCOMING_CALL));
- */
- }
+ bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
- private void callContact(final CallContact contact) {
- // TODO off-thread image loading
- Bubble contact_bubble;
- if(contact.getPhoto_id() > 0) {
- Bitmap photo = ContactPictureLoader.loadContactPhoto(getContentResolver(), contact.getId());
- contact_bubble = new Bubble(this, screenCenter.x, screenCenter.y, 150, photo);
- } else {
- contact_bubble = new Bubble(this, screenCenter.x, screenCenter.y, 150, R.drawable.ic_contact_picture);
- }
+ /*
+ * LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED));
+ * LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED));
+ * LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.INCOMING_CALL));
+ */
+ }
- model.attractors.clear();
- model.attractors.add(new Attractor(new PointF(metrics.widthPixels/2, metrics.heightPixels*.8f), new Attractor.Callback() {
- @Override
- public void onBubbleSucked(Bubble b)
- {
- Log.w(TAG, "Bubble sucked ! ");
- onCallEnded();
- }
- }));
+ private void callContact(final CallContact contact) {
+ // TODO off-thread image loading
+ Bubble contact_bubble;
+ if (contact.getPhoto_id() > 0) {
+ Bitmap photo = ContactPictureLoader.loadContactPhoto(getContentResolver(), contact.getId());
+ contact_bubble = new Bubble(this, screenCenter.x, screenCenter.y, 150, photo);
+ } else {
+ contact_bubble = new Bubble(this, screenCenter.x, screenCenter.y, 150, R.drawable.ic_contact_picture);
+ }
- contact_bubble.contact = contact;
- model.listBubbles.add(contact_bubble);
- contacts.put(contact, contact_bubble);
- }
+ model.attractors.clear();
+ model.attractors.add(new Attractor(new PointF(metrics.widthPixels / 2, metrics.heightPixels * .8f), new Attractor.Callback() {
+ @Override
+ public void onBubbleSucked(Bubble b) {
+ Log.w(TAG, "Bubble sucked ! ");
+ onCallEnded();
+ }
+ }));
- private void callIncoming() {
- model.attractors.clear();
- model.attractors.add(new Attractor(new PointF(3*metrics.widthPixels/4, metrics.heightPixels/4), new Attractor.Callback() {
- @Override
- public void onBubbleSucked(Bubble b)
- {
- onCallAccepted();
- }
- }));
- model.attractors.add(new Attractor(new PointF(metrics.widthPixels/4, metrics.heightPixels/4), new Attractor.Callback() {
- @Override
- public void onBubbleSucked(Bubble b)
- {
- onCallRejected();
- }
- }));
+ contact_bubble.contact = contact;
+ model.listBubbles.add(contact_bubble);
+ contacts.put(contact, contact_bubble);
+ }
- }
+ private void callIncoming() {
+ model.attractors.clear();
+ model.attractors.add(new Attractor(new PointF(3 * metrics.widthPixels / 4, metrics.heightPixels / 4), new Attractor.Callback() {
+ @Override
+ public void onBubbleSucked(Bubble b) {
+ onCallAccepted();
+ }
+ }));
+ model.attractors.add(new Attractor(new PointF(metrics.widthPixels / 4, metrics.heightPixels / 4), new Attractor.Callback() {
+ @Override
+ public void onBubbleSucked(Bubble b) {
+ onCallRejected();
+ }
+ }));
- @Override
- protected void onDestroy()
- {
- Log.i(TAG, "Destroying Call Activity for call " + mCall.getCallId());
- //LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
- unbindService(mConnection);
- 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);
- try {
- service.registerClient(callback);
- if(pendingAction != null && pendingAction.contentEquals("call")){
+ @Override
+ protected void onDestroy() {
+ // Log.i(TAG, "Destroying Call Activity for call " + mCall.getCallId());
+ // LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
+ unbindService(mConnection);
- Log.i(TAG, "Placing call");
- CallContact contact = model.listBubbles.get(0).contact;
+ super.onDestroy();
+ }
- String callID = Integer.toString(new Random().nextInt());
- SipCall.CallInfo info = new SipCall.CallInfo();
- info.mCallID = callID;
- info.mAccountID = service.getAccountList().get(0).toString();
- info.mDisplayName = contact.getmDisplayName();
- info.mPhone = contact.getSipPhone().getNumber();
- info.mEmail = contact.getmEmail();
- info.mCallType = SipCall.CALL_TYPE_OUTGOING;
+ /** 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);
+ try {
+ service.registerClient(callback);
+ if (pendingAction != null && pendingAction.contentEquals("call")) {
- mCall = CallListReceiver.getCallInstance(info);
+ Log.i(TAG, "Placing call");
+ CallContact contact = model.listBubbles.get(0).contact;
- service.placeCall(info.mAccountID, info.mCallID, info.mPhone);
- pendingAction = null;
- }
- } catch (RemoteException e) {
- Log.e(TAG, e.toString());
- }
- }
+ String callID = Integer.toString(new Random().nextInt());
+ SipCall.CallInfo info = new SipCall.CallInfo();
+ info.mCallID = callID;
+ info.mAccountID = service.getAccountList().get(0).toString();
+ info.mDisplayName = contact.getmDisplayName();
+ info.mPhone = contact.getSipPhone().getNumber();
+ info.mEmail = contact.getmEmail();
+ info.mCallType = SipCall.CALL_TYPE_OUTGOING;
- @Override
- public void onServiceDisconnected(ComponentName arg0)
- {
- }
- };
+ mCall = CallListReceiver.getCallInstance(info);
- private void processCallStateChangedSignal(String callID, String newState)
- {
- /*Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
- String callID = bundle.getString("CallID");
- String newState = bundle.getString("State");*/
+ service.placeCall(info.mAccountID, info.mCallID, info.mPhone);
+ pendingAction = null;
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
- if (newState.equals("INCOMING")) {
- mCall.setCallState(SipCall.CALL_STATE_INCOMING);
- setCallStateDisplay(newState);
- } else if (newState.equals("RINGING")) {
- mCall.setCallState(SipCall.CALL_STATE_RINGING);
- setCallStateDisplay(newState);
- } else if (newState.equals("CURRENT")) {
- mCall.setCallState(SipCall.CALL_STATE_CURRENT);
- setCallStateDisplay(newState);
- } else if (newState.equals("HUNGUP")) {
- mCall.setCallState(SipCall.CALL_STATE_HUNGUP);
- setCallStateDisplay(newState);
- finish();
- } else if (newState.equals("BUSY")) {
- mCall.setCallState(SipCall.CALL_STATE_BUSY);
- setCallStateDisplay(newState);
- } else if (newState.equals("FAILURE")) {
- mCall.setCallState(SipCall.CALL_STATE_FAILURE);
- setCallStateDisplay(newState);
- } else if (newState.equals("HOLD")) {
- mCall.setCallState(SipCall.CALL_STATE_HOLD);
- setCallStateDisplay(newState);
- } else if (newState.equals("UNHOLD")) {
- mCall.setCallState(SipCall.CALL_STATE_CURRENT);
- setCallStateDisplay("CURRENT");
- } else {
- mCall.setCallState(SipCall.CALL_STATE_NONE);
- setCallStateDisplay(newState);
- }
+ @Override
+ public void onServiceDisconnected(ComponentName arg0) {
+ }
+ };
- Log.w(TAG, "processCallStateChangedSignal " + newState);
+ private void processCallStateChangedSignal(String callID, String newState) {
+ /*
+ * Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); String callID = bundle.getString("CallID"); String
+ * newState = bundle.getString("State");
+ */
- }
+ if (newState.equals("INCOMING")) {
+ mCall.setCallState(SipCall.CALL_STATE_INCOMING);
+ setCallStateDisplay(newState);
+ } else if (newState.equals("RINGING")) {
+ mCall.setCallState(SipCall.CALL_STATE_RINGING);
+ setCallStateDisplay(newState);
+ } else if (newState.equals("CURRENT")) {
+ mCall.setCallState(SipCall.CALL_STATE_CURRENT);
+ setCallStateDisplay(newState);
+ } else if (newState.equals("HUNGUP")) {
+ mCall.setCallState(SipCall.CALL_STATE_HUNGUP);
+ setCallStateDisplay(newState);
+ finish();
+ } else if (newState.equals("BUSY")) {
+ mCall.setCallState(SipCall.CALL_STATE_BUSY);
+ setCallStateDisplay(newState);
+ } else if (newState.equals("FAILURE")) {
+ mCall.setCallState(SipCall.CALL_STATE_FAILURE);
+ setCallStateDisplay(newState);
+ } else if (newState.equals("HOLD")) {
+ mCall.setCallState(SipCall.CALL_STATE_HOLD);
+ setCallStateDisplay(newState);
+ } else if (newState.equals("UNHOLD")) {
+ mCall.setCallState(SipCall.CALL_STATE_CURRENT);
+ setCallStateDisplay("CURRENT");
+ } else {
+ mCall.setCallState(SipCall.CALL_STATE_NONE);
+ setCallStateDisplay(newState);
+ }
- private void setCallStateDisplay(String newState)
- {
- if (newState == null || newState.equals("NULL")) {
- newState = "INCOMING";
- }
+ Log.w(TAG, "processCallStateChangedSignal " + newState);
- Log.w(TAG, "setCallStateDisplay " + newState);
+ }
- /* mCall.printCallInfo();
+ private void setCallStateDisplay(String newState) {
+ if (newState == null || newState.equals("NULL")) {
+ newState = "INCOMING";
+ }
- FragmentManager fm = getFragmentManager();
- Fragment newf, f = fm.findFragmentByTag("call_fragment");
- boolean replace = true;
- if (newState.equals("INCOMING") && !(f instanceof IncomingCallFragment)) {
- newf = new IncomingCallFragment();
- } else if (!newState.equals("INCOMING") && !(f instanceof OngoingCallFragment)) {
- newf = new OngoingCallFragment();
- } else {
- replace = false;
- newf = f;
- }
+ Log.w(TAG, "setCallStateDisplay " + newState);
- ((CallFragment) newf).setCall(mCall);
+ /*
+ * mCall.printCallInfo();
+ *
+ * FragmentManager fm = getFragmentManager(); Fragment newf, f = fm.findFragmentByTag("call_fragment"); boolean replace = true; if
+ * (newState.equals("INCOMING") && !(f instanceof IncomingCallFragment)) { newf = new IncomingCallFragment(); } else if
+ * (!newState.equals("INCOMING") && !(f instanceof OngoingCallFragment)) { newf = new OngoingCallFragment(); } else { replace = false; newf =
+ * f; }
+ *
+ * ((CallFragment) newf).setCall(mCall);
+ *
+ * if (replace) { FragmentTransaction ft = fm.beginTransaction(); if(f != null) // do not animate if there is no previous fragment
+ * ft.setCustomAnimations(R.animator.slide_in, R.animator.slide_out); //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
+ * ft.replace(R.id.fragment_layout, newf, "call_fragment").commit(); }
+ */
+ }
- if (replace) {
- FragmentTransaction ft = fm.beginTransaction();
- if(f != null) // do not animate if there is no previous fragment
- ft.setCustomAnimations(R.animator.slide_in, R.animator.slide_out);
- //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
- ft.replace(R.id.fragment_layout, newf, "call_fragment").commit();
- }*/
- }
+ public void onCallAccepted() {
+ mCall.notifyServiceAnswer(service);
+ }
- public void onCallAccepted()
- {
- mCall.notifyServiceAnswer(service);
- }
+ public void onCallRejected() {
+ if (mCall.notifyServiceHangup(service))
+ finish();
+ }
- public void onCallRejected()
- {
- if (mCall.notifyServiceHangup(service))
- finish();
- }
+ public void onCallEnded() {
+ if (mCall.notifyServiceHangup(service))
+ finish();
+ }
- public void onCallEnded()
- {
- if (mCall.notifyServiceHangup(service))
- finish();
- }
+ public void onCallSuspended() {
+ mCall.notifyServiceHold(service);
+ }
- public void onCallSuspended()
- {
- mCall.notifyServiceHold(service);
- }
+ public void onCallResumed() {
+ mCall.notifyServiceUnhold(service);
+ }
- public void onCallResumed()
- {
- mCall.notifyServiceUnhold(service);
- }
+ public void onCalltransfered(String to) {
+ mCall.notifyServiceTransfer(service, to);
- public void onCalltransfered(String to) {
- mCall.notifyServiceTransfer(service, to);
+ }
- }
+ public void onRecordCall() {
+ mCall.notifyServiceRecord(service);
- public void onRecordCall() {
- mCall.notifyServiceRecord(service);
+ }
- }
+ public void onSendMessage(String msg) {
+ mCall.notifyServiceSendMsg(service, msg);
- public void onSendMessage(String msg) {
- mCall.notifyServiceSendMsg(service,msg);
-
- }
+ }
}
diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java
index 34077a3..1a26b15 100644
--- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java
+++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHomeActivity.java
@@ -33,7 +33,6 @@
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
-import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.ComponentName;
import android.content.Context;
@@ -42,468 +41,417 @@
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
-import android.support.v13.app.FragmentStatePagerAdapter;
+import android.support.v4.app.ActionBarDrawerToggle;
+import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
+import android.support.v4.widget.DrawerLayout;
import android.util.Log;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
import android.widget.ImageButton;
-import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter;
import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
import com.savoirfairelinux.sflphone.fragments.ContactListFragment;
import com.savoirfairelinux.sflphone.fragments.DialingFragment;
import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
+import com.savoirfairelinux.sflphone.fragments.MenuFragment;
import com.savoirfairelinux.sflphone.model.SipCall;
import com.savoirfairelinux.sflphone.service.ISipClient;
import com.savoirfairelinux.sflphone.service.ISipService;
import com.savoirfairelinux.sflphone.service.SipService;
import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer;
-public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, CallElementListFragment.Callbacks, HistoryFragment.Callbacks {
- SectionsPagerAdapter mSectionsPagerAdapter = null;
- static final String TAG = "SFLPhoneHome";
-
- ImageButton buttonCall, buttonHangup;
- private ContactListFragment mContactsFragment = null;
- private DialingFragment mDialingFragment = null;
- private CallElementListFragment mCallElementList = null;
- private HistoryFragment mHistorySectionFragment = null;
- private boolean mBound = false;
- private ISipService service;
-
- private static final int REQUEST_CODE_PREFERENCES = 1;
+public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, CallElementListFragment.Callbacks,
+ HistoryFragment.Callbacks {
+ SectionsPagerAdapter mSectionsPagerAdapter = null;
+ static final String TAG = "SFLPhoneHome";
- private static final int ACTION_BAR_TAB_DIALING = 0;
- private static final int ACTION_BAR_TAB_CALL = 1;
- private static final int ACTION_BAR_TAB_HISTORY = 2;
+ ImageButton buttonCall, buttonHangup;
+ private ContactListFragment mContactsFragment = null;
+ private DialingFragment mDialingFragment = null;
+ private CallElementListFragment mCallElementList = null;
+ private HistoryFragment mHistorySectionFragment = null;
- RelativeLayout mSliderButton;
- /**
- * The {@link ViewPager} that will host the section contents.
- */
- ViewPager mViewPager;
+ Fragment fMenu;
- final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history };
+ private boolean mBound = false;
+ private ISipService service;
- // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
+ private CharSequence mDrawerTitle;
+ private CharSequence mTitle;
- /* 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, "fragment=" + mSectionsPagerAdapter.getFragment(i));
- }
- }
- Log.w(TAG, "onSaveInstanceState()");
- }
+ private static final int REQUEST_CODE_PREFERENCES = 1;
+ private static final int REQUEST_CODE_CALL = 2;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ private static final int ACTION_BAR_TAB_DIALING = 0;
+ private static final int ACTION_BAR_TAB_CALL = 1;
+ private static final int ACTION_BAR_TAB_HISTORY = 2;
- String libraryPath = getApplicationInfo().dataDir + "/lib";
- Log.i(TAG, libraryPath);
+ RelativeLayout mSliderButton;
+ CustomSlidingDrawer mDrawer;
- // 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);
- }
+ private DrawerLayout mDrawerLayout;
- setContentView(R.layout.activity_sflphone_home);
+ private ActionBarDrawerToggle mDrawerToggle;
+ /**
+ * The {@link ViewPager} that will host the section contents.
+ */
+ ViewPager mViewPager;
- if (mSectionsPagerAdapter == null) {
- mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
- }
+ final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history };
- /* getFragment(Bundle, String) */
- if (savedInstanceState != null) {
- Log.w(TAG, "Activity restarted, recreating PagerAdapter...");
- /* getFragment (Bundle bundle, String key) */
- mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState,
- mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING));
- mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState,
- mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL));
- mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState,
- mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY));
- }
-
- if(mDialingFragment == null){
- mDialingFragment = new DialingFragment();
+ // 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 {
+ getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
+ } catch (IllegalStateException e) {
+ Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
+ }
+ }
+
+ getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
+ Log.w(TAG, "onSaveInstanceState()");
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ String libraryPath = getApplicationInfo().dataDir + "/lib";
+ Log.i(TAG, libraryPath);
+
+ // 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(this, getFragmentManager());
+ }
+
+ /* getFragment(Bundle, String) */
+ if (savedInstanceState != null) {
+ Log.w(TAG, "Activity restarted, recreating PagerAdapter...");
+ /* getFragment (Bundle bundle, String key) */
+ mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState,
+ mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING));
+ mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState,
+ mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL));
+ mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState,
+ mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY));
+ }
+
+ if (mDialingFragment == null) {
+ mDialingFragment = new DialingFragment();
Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment);
- }
+ }
- if (mContactsFragment == null) {
- mContactsFragment = new ContactListFragment();
- Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
- getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
- }
- if (mCallElementList == null) {
- mCallElementList = new CallElementListFragment();
- Log.w(TAG, "Recreated mCallElementList=" + mCallElementList);
- }
- if (mHistorySectionFragment == null) {
- mHistorySectionFragment = new HistoryFragment();
- Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment);
- }
-
- CustomSlidingDrawer mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
+ if (mContactsFragment == null) {
+ mContactsFragment = new ContactListFragment();
+ Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
+ getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
+ }
+ if (mCallElementList == null) {
+ mCallElementList = new CallElementListFragment();
+ Log.w(TAG, "Recreated mCallElementList=" + mCallElementList);
+ }
+ if (mHistorySectionFragment == null) {
+ mHistorySectionFragment = new HistoryFragment();
+ Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment);
+ }
+
+ mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
mSliderButton = (RelativeLayout) findViewById(R.id.slider_button);
- ((ImageView) mSliderButton.findViewById(R.id.btnPlay)).setTag(R.id.btnPlay, false);
+ ((ImageButton) mSliderButton.findViewById(R.id.contact_search)).setTag(R.id.contact_search, false);
+ ((ImageButton) mSliderButton.findViewById(R.id.contact_search)).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Log.i(TAG, "Click on serach");
+ mDrawer.toggle();
+ }
+ });
mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
- final ActionBar actionBar = getActionBar();
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
- // final ActionBar actionBar = getActionBar();
+ final ActionBar actionBar = getActionBar();
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
- // Set up the ViewPager with the sections adapter.
- mViewPager = (ViewPager) findViewById(R.id.pager);
- mViewPager.setAdapter(mSectionsPagerAdapter);
+ // 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);
- }
- });
+ mTitle = mDrawerTitle = getTitle();
+ mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+ // mDrawerList = (ListView) findViewById(R.id.left_drawer);
- // 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));
- }
+ // set a custom shadow that overlays the main content when the drawer opens
+ mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
+ // set up the drawer's list view with items and click listener
+ // mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
+ // mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
- actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ getActionBar().setHomeButtonEnabled(true);
- // buttonHangup.setOnClickListener(new OnClickListener() {
- // @Override
- // public void onClick(View v) {
- // processingHangUpAction();
- //
- // }
- // });
+ mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
+ mDrawerLayout, /* DrawerLayout object */
+ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
+ R.string.drawer_open, /* "open drawer" description for accessibility */
+ R.string.drawer_close /* "close drawer" description for accessibility */
+ ) {
+ public void onDrawerClosed(View view) {
+ getActionBar().setTitle(mTitle);
+ invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
+ }
- // 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);
+ public void onDrawerOpened(View drawerView) {
+ getActionBar().setTitle(mDrawerTitle);
+ invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
+ }
+ };
- // IntentFilter accountFilter = new IntentFilter(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
- // accountFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
- // LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, accountFilter);
+ mDrawerLayout.setDrawerListener(mDrawerToggle);
- // SipCall.setSFLPhoneHomeContext(this);
- }
+ mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int position) {
+ actionBar.setSelectedNavigationItem(position);
+ }
+ });
- @Override
- protected void onStart() {
- Log.i(TAG, "onStart");
- super.onStart();
- }
+ // For each of the sections in the app, add a tab to the action bar.
+ for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
- /* user gets back to the activity, e.g. through task manager */
- @Override
- protected void onRestart() {
- super.onRestart();
- }
+ actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
+ }
- /* activity gets back to the foreground and user input */
- @Override
- protected void onResume() {
- Log.i(TAG, "onResume");
- super.onResume();
- }
+ actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
- /* activity no more in foreground */
- @Override
- protected void onPause() {
- super.onPause();
- }
+ fMenu = new MenuFragment();
+ getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
+ }
- /* activity is no longer visible */
- @Override
- protected void onStop() {
- super.onStop();
- }
+ @Override
+ protected void onStart() {
+ Log.i(TAG, "onStart");
+ super.onStart();
+ }
- /* 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, "onDestroy: Unbinding service...");
- unbindService(mConnection);
- mBound = false;
- }
+ /* user gets back to the activity, e.g. through task manager */
+ @Override
+ protected void onRestart() {
+ super.onRestart();
+ }
- /* unregister broadcast receiver */
- // LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList);
- // LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList);
+ /* activity gets back to the foreground and user input */
+ @Override
+ protected void onResume() {
+ Log.i(TAG, "onResume");
+ super.onResume();
+ }
- super.onDestroy();
- }
+ /* activity no more in foreground */
+ @Override
+ protected void onPause() {
+ super.onPause();
+ }
- public void launchCallActivity(SipCall.CallInfo infos) {
- Log.i(TAG, "Launch Call Activity");
- Bundle bundle = new Bundle();
- bundle.putString("action", "incoming");
- //bundle.putParcelable("CallContact", mListAdapter.getItem(pos));
- bundle.putParcelable("CallInfo", infos);
- Intent intent = new Intent().setClass(this, CallActivity.class);
- intent.putExtras(bundle);
- startActivity(intent);
- }
+ /* activity is no longer visible */
+ @Override
+ protected void onStop() {
+ super.onStop();
+ }
- /** Defines callbacks for service binding, passed to bindService() */
- private ServiceConnection mConnection = new ServiceConnection() {
+ /* 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, "onDestroy: Unbinding service...");
+ unbindService(mConnection);
+ mBound = false;
+ }
- private ISipClient callback = new ISipClient.Stub() {
+ /* unregister broadcast receiver */
+ // LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList);
+ // LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList);
- @Override
- public void incomingCall(Intent call) throws RemoteException {
- Log.i(TAG, "Incoming call transfered from Service");
- SipCall.CallInfo infos = new SipCall.CallInfo(call);
+ super.onDestroy();
+ }
- SipCall c = new SipCall(infos);
- mCallElementList.addCall(c);
+ public void launchCallActivity(SipCall.CallInfo infos) {
+ Log.i(TAG, "Launch Call Activity");
+ Bundle bundle = new Bundle();
+ bundle.putString("action", "incoming");
+ // bundle.putParcelable("CallContact", mListAdapter.getItem(pos));
+ bundle.putParcelable("CallInfo", infos);
+ Intent intent = new Intent().setClass(this, CallActivity.class);
+ intent.putExtras(bundle);
+ startActivityForResult(intent, REQUEST_CODE_CALL);
+ }
+
+ private ISipClient callback = new ISipClient.Stub() {
- launchCallActivity(infos);
- }
+ @Override
+ public void incomingCall(Intent call) throws RemoteException {
+ Log.i(TAG, "Incoming call transfered from Service");
+ SipCall.CallInfo infos = new SipCall.CallInfo(call);
- @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);
+ SipCall c = new SipCall(infos);
+ mCallElementList.addCall(c);
- }
+ launchCallActivity(infos);
+ }
- @Override
- public void incomingText(Intent msg) throws RemoteException {
- Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
- b.getString("CallID");
- String from = b.getString("From");
- String mess = b.getString("Msg");
- Toast.makeText(getApplicationContext(), "text from "+from+" : " + mess , Toast.LENGTH_LONG).show();
+ @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);
+ @Override
+ public void incomingText(Intent msg) throws RemoteException {
+ Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
+ b.getString("CallID");
+ String from = b.getString("From");
+ String mess = b.getString("Msg");
+ Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
- mBound = true;
- mCallElementList.onServiceSipBinded(service);
- mHistorySectionFragment.onServiceSipBinded(service);
- Log.d(TAG, "Service connected service=" + service);
+ }
+ };
- try {
- service.registerClient(callback);
- } catch (RemoteException e) {
- Log.e(TAG, e.toString());
- }
- }
+ /** Defines callbacks for service binding, passed to bindService() */
+ private ServiceConnection mConnection = new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName arg0) {
+
- mBound = false;
- Log.d(TAG, "Service disconnected service=" + service);
- }
- };
+ @Override
+ public void onServiceConnected(ComponentName className, IBinder binder) {
+ service = ISipService.Stub.asInterface(binder);
-// @Override
-// public boolean onOptionsItemSelected(MenuItem item) {
-// Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
-// switch(item.getItemId()){
-// case R.id.menu_settings :
-// Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
-// startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
-// break;
-// case R.id.menu_custom_draw:
-// Intent launchNewInterfaceIntent = new Intent().setClass(this, BubblesViewActivity.class);
-// startActivityForResult(launchNewInterfaceIntent, 0);
-// break;
-// }
-//
-// return super.onOptionsItemSelected(item);
-// }
+ mBound = true;
+ mCallElementList.onServiceSipBinded(service);
+ mHistorySectionFragment.onServiceSipBinded(service);
+ mDialingFragment.onServiceSipBinded(service);
+ Log.d(TAG, "Service connected service=" + service);
- @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);
- }
- }
+ try {
+ service.registerClient(callback);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ }
-// @Override
-// public boolean onCreateOptionsMenu(Menu menu) {
-// getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
-// return true;
-// }
+ @Override
+ public void onServiceDisconnected(ComponentName arg0) {
- @Override
- public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
- }
+ mBound = false;
+ Log.d(TAG, "Service disconnected service=" + service);
+ }
+ };
- @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 boolean onOptionsItemSelected(MenuItem item) {
+ Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
- @Override
- public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
- // Log.d(TAG, "onTabReselected");
- }
+ if (mDrawerToggle.onOptionsItemSelected(item)) {
+ return true;
+ }
+ // switch(item.getItemId()){
+ // case R.id.menu_settings :
+ // Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
+ // startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
+ // break;
+ // case R.id.menu_custom_draw:
+ // Intent launchNewInterfaceIntent = new Intent().setClass(this, BubblesViewActivity.class);
+ // startActivityForResult(launchNewInterfaceIntent, 0);
+ // break;
+ // }
- public void processingHangUpAction() {
- SipCall call = (SipCall) buttonHangup.getTag();
- if (call != null)
- call.notifyServiceHangup(service);
- }
+ return super.onOptionsItemSelected(item);
+ }
- /**
- * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to one of the primary sections of the app.
- */
- public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ switch (requestCode){
+ case REQUEST_CODE_PREFERENCES:
+ mCallElementList.onServiceSipBinded(service);
+ break;
+ case REQUEST_CODE_CALL:
+ try {
+ service.registerClient(callback);
+ } catch (RemoteException e) {
+ Log.e(TAG,e.toString());
+ }
+ break;
+ }
- public SectionsPagerAdapter(FragmentManager fm) {
- super(fm);
- }
+ }
- @Override
- public Fragment getItem(int i) {
- Fragment fragment;
+ // @Override
+ // public boolean onCreateOptionsMenu(Menu menu) {
+ // getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
+ // return true;
+ // }
- switch (i) {
- case 0:
- mDialingFragment = new DialingFragment();
- fragment = mDialingFragment;
- Log.w(TAG, "getItem() DialingFragment=" + 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;
- }
+ @Override
+ public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
+ }
- // Log.i(TAG, "getItem() fragment is " + fragment);
- Bundle args = new Bundle();
- args.putInt(HistoryFragment.ARG_SECTION_NUMBER, i + 1);
- fragment.setArguments(args);
- return fragment;
- }
+ @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());
+ }
- public Fragment getFragment(int i) {
- Fragment fragment;
+ @Override
+ public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
+ // Log.d(TAG, "onTabReselected");
+ }
- switch (i) {
- case 0:
- fragment = mDialingFragment;
- break;
- case 1:
- fragment = mCallElementList;
- break;
- case 2:
- fragment = mHistorySectionFragment;
- break;
- default:
- Log.e(TAG, "getClassName: unknown fragment position " + i);
- fragment = null;
- }
+ public void processingHangUpAction() {
+ SipCall call = (SipCall) buttonHangup.getTag();
+ if (call != null)
+ call.notifyServiceHangup(service);
+ }
- // Log.w(TAG, "getFragment: fragment=" + fragment);
- return fragment;
- }
+ @Override
+ public void onCallSelected(SipCall c) {
+ launchCallActivity(c.mCallInfo);
- public String getClassName(int i) {
- String name;
+ }
- switch (i) {
- case 0:
- name = DialingFragment.class.getName();
- break;
- case 1:
- name = CallElementListFragment.class.getName();
- break;
- case 2:
- name = HistoryFragment.class.getName();
- break;
+ @Override
+ public ISipService getService() {
+ return service;
+ }
- 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();
- default:
- Log.e(TAG, "getPageTitle: unknown tab position " + position);
- break;
- }
- return null;
- }
- }
-
- @Override
- public void onCallSelected(SipCall c) {
- launchCallActivity(c.mCallInfo);
-
- }
-
- @Override
- public ISipService getService() {
- return service;
- }
+ @Override
+ public void onCallCreated(SipCall c) {
+ mCallElementList.addCall(c);
+ launchCallActivity(c.mCallInfo);
+
+ }
}
diff --git a/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java b/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java
index a8d28ab..3bdc706 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/CallElementListFragment.java
@@ -31,21 +31,14 @@
package com.savoirfairelinux.sflphone.fragments;
import java.util.ArrayList;
-import java.util.Random;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListFragment;
-import android.app.LoaderManager;
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.net.Uri;
import android.os.Bundle;
-import android.os.RemoteException;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
import android.provider.ContactsContract.Contacts;
@@ -55,422 +48,297 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
-import android.widget.CompoundButton;
-import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.EditText;
-import android.widget.ImageButton;
import android.widget.ListView;
-import android.widget.Toast;
import android.widget.ToggleButton;
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.SFLPhonePreferenceActivity;
-import com.savoirfairelinux.sflphone.client.SFLphoneApplication;
-import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver;
import com.savoirfairelinux.sflphone.model.SipCall;
import com.savoirfairelinux.sflphone.service.ISipService;
/**
* Main list of Call Elements. We don't manage contacts ourself so they are
*/
-public class CallElementListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
- private static final String TAG = CallElementListFragment.class.getSimpleName();
- private CallElementAdapter mAdapter;
- private String mCurFilter;
- private SFLPhoneHomeActivity sflphoneHome;
- private ISipService service;
- ImageButton buttonCall;
- Button attendedTransfer, conference;
- EditText phoneField;
- private AccountSelectionSpinner mAccountSelectionSpinner;
- // private AccountListReceiver mAccountList;
- private boolean isReady = false;
+public class CallElementListFragment extends ListFragment {
+ private static final String TAG = CallElementListFragment.class.getSimpleName();
+ private CallElementAdapter mAdapter;
- 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 ISipService service;
- private Callbacks mCallbacks = sDummyCallbacks;
- private ToggleButton switchHold;
- /**
- * 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) {
- }
+ Button attendedTransfer, conference;
- @Override
- public ISipService getService() {
- // TODO Auto-generated method stub
- return null;
- }
- };
+ private Callbacks mCallbacks = sDummyCallbacks;
+ private boolean isReady = false;
- /**
- * The Activity calling this fragment has to implement this interface
- *
- */
- public interface Callbacks {
- public void onCallSelected(SipCall c);
- public ISipService getService();
+ /**
+ * 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) {
+ }
- }
+ @Override
+ public ISipService getService() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
- @Override
- public void onAttach(Activity activity) {
- super.onAttach(activity);
- sflphoneHome = (SFLPhoneHomeActivity) activity;
- service = ((SFLphoneApplication) sflphoneHome.getApplication()).getSipService();
- if (!(activity instanceof Callbacks)) {
- throw new IllegalStateException("Activity must implement fragment's callbacks.");
- }
+ /**
+ * The Activity calling this fragment has to implement this interface
+ *
+ */
+ public interface Callbacks {
+ public void onCallSelected(SipCall c);
- mCallbacks = (Callbacks) activity;
- }
+ public ISipService getService();
- @Override
- public void onDetach() {
- super.onDetach();
- mCallbacks = sDummyCallbacks;
- }
+ }
- public String getSelectedAccount() {
- return mAccountSelectionSpinner.getAccount();
- }
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
- /**
- * Runnable that fill information in a contact card asynchroniously.
- */
- /*
- * public static class InfosLoader implements Runnable { private View view; private long cid; private ContentResolver cr;
- *
- * public InfosLoader(Context context, View element, long contact_id) { cid = contact_id; cr = context.getContentResolver(); view = element; }
- *
- * public static Bitmap loadContactPhoto(ContentResolver cr, long id) { Uri uri =
- * ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); InputStream input =
- * ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); if (input == null) { return null; } return BitmapFactory.decodeStream(input); }
- *
- * @Override public void run() { final Bitmap photo_bmp = loadContactPhoto(cr, cid);
- *
- * Cursor phones = cr.query(CommonDataKinds.Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]
- * { Long.toString(cid) }, null);
- *
- * final List<String> numbers = new ArrayList<String>(); while (phones.moveToNext()) { String number =
- * phones.getString(phones.getColumnIndex(CommonDataKinds.Phone.NUMBER)); // int type =
- * phones.getInt(phones.getColumnIndex(CommonDataKinds.Phone.TYPE)); numbers.add(number); } phones.close(); // TODO: same for SIP adresses.
- *
- * final Bitmap bmp = photo_bmp; view.post(new Runnable() {
- *
- * @Override public void run() { } }); } }
- */
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
- public CallElementListFragment() {
- super();
- }
+ mCallbacks = (Callbacks) activity;
+ }
- public void addCall(SipCall c) {
- Log.i(TAG, "Adding call " + c.mCallInfo.mDisplayName);
- mAdapter.add(c);
- }
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ mCallbacks = sDummyCallbacks;
+ }
- // public void removeCall(SipCall c) {
- // Log.i(TAG, "Removing call " + c.mCallInfo.mDisplayName);
- // mAdapter.remove(c);
- // }
+ /**
+ * Runnable that fill information in a contact card asynchroniously.
+ */
+ /*
+ * public static class InfosLoader implements Runnable { private View view; private long cid; private ContentResolver cr;
+ *
+ * public InfosLoader(Context context, View element, long contact_id) { cid = contact_id; cr = context.getContentResolver(); view = element; }
+ *
+ * public static Bitmap loadContactPhoto(ContentResolver cr, long id) { Uri uri =
+ * ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); InputStream input =
+ * ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); if (input == null) { return null; } return BitmapFactory.decodeStream(input); }
+ *
+ * @Override public void run() { final Bitmap photo_bmp = loadContactPhoto(cr, cid);
+ *
+ * Cursor phones = cr.query(CommonDataKinds.Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]
+ * { Long.toString(cid) }, null);
+ *
+ * final List<String> numbers = new ArrayList<String>(); while (phones.moveToNext()) { String number =
+ * phones.getString(phones.getColumnIndex(CommonDataKinds.Phone.NUMBER)); // int type =
+ * phones.getInt(phones.getColumnIndex(CommonDataKinds.Phone.TYPE)); numbers.add(number); } phones.close(); // TODO: same for SIP adresses.
+ *
+ * final Bitmap bmp = photo_bmp; view.post(new Runnable() {
+ *
+ * @Override public void run() { } }); } }
+ */
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
+ public void addCall(SipCall c) {
+ Log.i(TAG, "Adding call " + c.mCallInfo.mDisplayName);
+ if (mAdapter == null) {
+ Log.w(TAG, "mAdapter is null");
+ return;
+ }
+ mAdapter.add(c);
+ }
- // Give some text to display if there is no data. In a real
- // application this would come from a resource.
- // setEmptyText("No phone numbers");
+ // public void removeCall(SipCall c) {
+ // Log.i(TAG, "Removing call " + c.mCallInfo.mDisplayName);
+ // mAdapter.remove(c);
+ // }
- // We have a menu item to show in action bar.
- setHasOptionsMenu(true);
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mAdapter = new CallElementAdapter(getActivity(), new ArrayList<SipCall>());
+ }
- // Create an empty adapter we will use to display the loaded data.
- ArrayList<SipCall> calls = new ArrayList<SipCall>();
- mAdapter = new CallElementAdapter(getActivity(), calls);
- setListAdapter(mAdapter);
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
- // Start out with a progress indicator.
- // setListShown(false);
+ // Give some text to display if there is no data. In a real
+ // application this would come from a resource.
+ // setEmptyText("No phone numbers");
- // Prepare the loader. Either re-connect with an existing one,
- // or start a new one.
- // getLoaderManager().initLoader(0, null, this)
+ // We have a menu item to show in action bar.
+ setHasOptionsMenu(true);
- final Context context = getActivity();
- ListView lv = getListView();
- lv.setOnItemLongClickListener(new OnItemLongClickListener() {
- @Override
- public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
- Log.i(TAG, "On Long Click");
- final CharSequence[] items = { "Hang up Call", "Send Message", "Add to Conference" };
- final SipCall call = mAdapter.getItem(pos);
- // // FIXME
- // service = sflphoneApplication.getSipService();
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle("Action to perform with " + call.mCallInfo.mDisplayName).setCancelable(true)
- .setItems(items, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int item) {
- Log.i(TAG, "Selected " + items[item]);
- switch (item) {
- case 0:
- call.notifyServiceHangup(service);
- break;
- case 1:
- call.sendTextMessage();
- // Need to hangup this call immediately since no way to do it after this action
- call.notifyServiceHangup(service);
- break;
- case 2:
- call.addToConference();
- // Need to hangup this call immediately since no way to do it after this action
- call.notifyServiceHangup(service);
- break;
- default:
- break;
- }
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
+ final Context context = getActivity();
+ ListView lv = getListView();
+ lv.setAdapter(mAdapter);
+ lv.setOnItemLongClickListener(new OnItemLongClickListener() {
+ @Override
+ public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
+ Log.i(TAG, "On Long Click");
+ final CharSequence[] items = { "Hang up Call", "Send Message", "Add to Conference" };
+ final SipCall call = mAdapter.getItem(pos);
+ // // FIXME
+ // service = sflphoneApplication.getSipService();
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle("Action to perform with " + call.mCallInfo.mDisplayName).setCancelable(true)
+ .setItems(items, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int item) {
+ Log.i(TAG, "Selected " + items[item]);
+ switch (item) {
+ case 0:
+ call.notifyServiceHangup(service);
+ break;
+ case 1:
+ call.sendTextMessage();
+ // Need to hangup this call immediately since no way to do it after this action
+ call.notifyServiceHangup(service);
+ break;
+ case 2:
+ call.addToConference();
+ // Need to hangup this call immediately since no way to do it after this action
+ call.notifyServiceHangup(service);
+ break;
+ default:
+ break;
+ }
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
- return true;
- }
- });
+ return true;
+ }
+ });
- lv.setOnItemClickListener(new OnItemClickListener() {
+ lv.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) {
- mCallbacks.onCallSelected(mAdapter.getItem(pos));
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) {
+ mCallbacks.onCallSelected(mAdapter.getItem(pos));
- }
+ }
- });
- }
+ });
+ }
- private 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
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.call_element_menu, menu);
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- inflater.inflate(R.menu.call_element_menu, menu);
+ }
- }
+ private static final int REQUEST_CODE_PREFERENCES = 1;
- private static final int REQUEST_CODE_PREFERENCES = 1;
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
+ switch (item.getItemId()) {
+ case R.id.menu_settings:
+ Intent launchPreferencesIntent = new Intent().setClass(getActivity(), SFLPhonePreferenceActivity.class);
+ startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
+ break;
+ }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
- switch (item.getItemId()) {
- case R.id.menu_settings:
- Intent launchPreferencesIntent = new Intent().setClass(getActivity(), SFLPhonePreferenceActivity.class);
- startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
- break;
- }
+ return super.onOptionsItemSelected(item);
+ }
- return super.onOptionsItemSelected(item);
- }
+ public void updateCall(String iD, String newState) {
+ if (mAdapter == null) {
+ Log.w(TAG, "mAdapter is null");
+ return;
+ }
+ mAdapter.update(iD, newState);
+ }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- Log.i(TAG, "onCreateView");
- View inflatedView = inflater.inflate(R.layout.frag_call_element, container, false);
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ Log.i(TAG, "onCreateView");
+ View inflatedView = inflater.inflate(R.layout.frag_call_element, container, false);
- mAccountSelectionSpinner = (AccountSelectionSpinner) inflatedView.findViewById(R.id.account_selection_button);
- phoneField = (EditText) inflatedView.findViewById(R.id.phoneNumberTextEntry);
- buttonCall = (ImageButton) inflatedView.findViewById(R.id.buttonCall);
+ // ((Button) inflatedView.findViewById(R.id.button_attended)).setOnClickListener(new OnClickListener() {
+ //
+ // @Override
+ // public void onClick(View v) {
+ // if (mAdapter.getCount() == 2) {
+ // try {
+ // service.attendedTransfer(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId());
+ // mAdapter.clear();
+ // } catch (RemoteException e) {
+ // Log.e(TAG, e.toString());
+ // }
+ // } else {
+ // Toast.makeText(getActivity(), "You need two calls one on Hold the other current to bind them", Toast.LENGTH_LONG).show();
+ // }
+ //
+ // }
+ // });
- buttonCall.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- processingNewCallAction();
- }
- });
+ // ((Button) inflatedView.findViewById(R.id.button_conf)).setOnClickListener(new OnClickListener() {
+ //
+ // @Override
+ // public void onClick(View v) {
+ // if (mAdapter.getCount() == 2) {
+ // try {
+ // service.joinParticipant(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId());
+ // } catch (RemoteException e) {
+ // Log.e(TAG, e.toString());
+ // }
+ // } else {
+ // Toast.makeText(getActivity(), "You need two calls one on Hold the other current to create a conference", Toast.LENGTH_LONG)
+ // .show();
+ // }
+ // }
+ // });
- attendedTransfer = (Button) inflatedView.findViewById(R.id.button_attended);
- attendedTransfer.setOnClickListener(new OnClickListener() {
+ // ((ToggleButton) inflatedView.findViewById(R.id.switch_hold)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
+ //
+ // @Override
+ // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ // try {
+ // ArrayList<String> confList = (ArrayList<String>) service.getConferenceList();
+ // if (!confList.isEmpty()) {
+ // if (isChecked) {
+ // service.holdConference(confList.get(0));
+ // } else {
+ // service.unholdConference(confList.get(0));
+ // }
+ // }
+ // } catch (RemoteException e) {
+ // Log.e(TAG, e.toString());
+ // }
+ //
+ // }
+ // });
- @Override
- public void onClick(View v) {
- if (mAdapter.getCount() == 2) {
- try {
- service.attendedTransfer(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId());
- mAdapter.clear();
- } catch (RemoteException e) {
- Log.e(TAG, e.toString());
- }
- } else {
- Toast.makeText(getActivity(), "You need two calls one on Hold the other current to bind them", Toast.LENGTH_LONG).show();
- }
+ isReady = true;
+ if (mCallbacks.getService() != null) {
- }
- });
+ onServiceSipBinded(mCallbacks.getService());
+ }
+ return inflatedView;
+ }
- conference = (Button) inflatedView.findViewById(R.id.button_conf);
- conference.setOnClickListener(new OnClickListener() {
+ /**
+ * Called by activity to pass a reference to sipservice to Fragment.
+ *
+ * @param isip
+ */
+ public void onServiceSipBinded(ISipService isip) {
- @Override
- public void onClick(View v) {
- if (mAdapter.getCount() == 2) {
- try {
- service.joinParticipant(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId());
- } catch (RemoteException e) {
- Log.e(TAG, e.toString());
- }
- } else {
- Toast.makeText(getActivity(), "You need two calls one on Hold the other current to create a conference", Toast.LENGTH_LONG)
- .show();
- }
- }
- });
+ if (isReady) {
+ service = isip;
+ }
- switchHold = (ToggleButton) inflatedView.findViewById(R.id.switch_hold);
- switchHold.setOnCheckedChangeListener(new OnCheckedChangeListener() {
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- try {
- ArrayList<String> confList = (ArrayList<String>) service.getConferenceList();
- if (!confList.isEmpty()) {
- if (isChecked) {
- service.holdConference(confList.get(0));
- } else {
- service.unholdConference(confList.get(0));
- }
- }
- } catch (RemoteException e) {
- Log.e(TAG, e.toString());
- }
-
- }
- });
-
- isReady = true;
- if (mCallbacks.getService() != null) {
-
- onServiceSipBinded(mCallbacks.getService());
- }
- return inflatedView;
- }
-
- public void processingNewCallAction() {
- // String accountID = mAccountList.currentAccountID;
- String accountID = mAccountSelectionSpinner.getAccount();
-
- String to = phoneField.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);
- mCallbacks.onCallSelected(call);
-
- try {
- service.placeCall(info.mAccountID, info.mCallID, info.mPhone);
- } catch (RemoteException e) {
- Log.e(TAG, "Cannot call service method", e);
- }
- addCall(call);
- }
-
- @Override
- public Loader<Cursor> onCreateLoader(int id, Bundle args) {
-
- Log.i(TAG, "onCreateLoader");
- Uri baseUri;
-
- if (mCurFilter != null) {
- baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(mCurFilter));
- } else {
- baseUri = Contacts.CONTENT_URI;
- }
-
- // Now create and return a CursorLoader that will take care of
- // creating a Cursor for the data being displayed.
- String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.HAS_PHONE_NUMBER + "=1) AND (" + Contacts.DISPLAY_NAME
- + " != '' ))";
- // String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ))";
-
- return new CursorLoader(getActivity(), baseUri, CONTACTS_SUMMARY_PROJECTION, select, null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
- }
-
- @Override
- public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
- Log.i(TAG, "onLoadFinished");
- // Swap the new cursor in. (The framework will take care of closing the
- // old cursor once we return.)
- // mAdapter.swapCursor(data);
-
- // The list should now be shown.
- /*
- * if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); }
- */
- }
-
- @Override
- public void onLoaderReset(Loader<Cursor> loader) {
- // This is called when the last Cursor provided to onLoadFinished()
- // above is about to be closed. We need to make sure we are no
- // longer using it.
- // mAdapter.swapCursor(null);
- }
-
- /**
- * Called by activity to pass a reference to sipservice to Fragment.
- *
- * @param isip
- */
- public void onServiceSipBinded(ISipService isip) {
-
- if (isReady) {
- service = isip;
- ArrayList<String> accountList;
- try {
- accountList = (ArrayList<String>) mCallbacks.getService().getAccountList();
- mAccountSelectionSpinner.populate(mCallbacks.getService(), accountList);
- } catch (RemoteException e) {
- Log.i(TAG, e.toString());
- }
- }
-
- }
-
- public void updateCall(String iD, String newState) {
- mAdapter.update(iD, newState);
-
- }
+ }
}
diff --git a/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java b/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java
index ccb28ce..1ab198a 100644
--- a/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java
+++ b/src/com/savoirfairelinux/sflphone/fragments/DialingFragment.java
@@ -1,31 +1,77 @@
package com.savoirfairelinux.sflphone.fragments;
+import java.util.ArrayList;
+import java.util.Random;
+
import android.app.Activity;
-import android.os.Bundle;
import android.app.Fragment;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.text.InputType;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.Button;
+import android.widget.ImageButton;
import com.savoirfairelinux.sflphone.R;
-import com.savoirfairelinux.sflphone.adapters.HistoryAdapter;
+import com.savoirfairelinux.sflphone.account.AccountSelectionSpinner;
+import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver;
import com.savoirfairelinux.sflphone.model.SipCall;
import com.savoirfairelinux.sflphone.service.ISipService;
+import com.savoirfairelinux.sflphone.views.ClearableEditText;
-public class DialingFragment extends Fragment{
-
+public class DialingFragment extends Fragment {
+
private static final String TAG = HistoryFragment.class.getSimpleName();
public static final String ARG_SECTION_NUMBER = "section_number";
private boolean isReady;
private ISipService service;
- HistoryAdapter mAdapter;
+ ClearableEditText textField;
+ private AccountSelectionSpinner mAccountSelectionSpinner;
+ 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 onCallCreated(SipCall c) {
+ }
+
+ @Override
+ public ISipService getService() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+
+ /**
+ * The Activity calling this fragment has to implement this interface
+ *
+ */
+ public interface Callbacks {
+ public void onCallCreated(SipCall c);
+
+ public ISipService getService();
+
+ }
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
-
+
+ if (!(activity instanceof Callbacks)) {
+ throw new IllegalStateException("Activity must implement fragment's callbacks.");
+ }
+
+ mCallbacks = (Callbacks) activity;
}
@Override
@@ -43,6 +89,41 @@
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View inflatedView = inflater.inflate(R.layout.frag_dialing, parent, false);
+ mAccountSelectionSpinner = (AccountSelectionSpinner) inflatedView.findViewById(R.id.account_selection_button);
+
+ textField = (ClearableEditText) inflatedView.findViewById(R.id.textField);
+ ((ImageButton) inflatedView.findViewById(R.id.buttonCall)).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ processingNewCallAction();
+ }
+ });
+
+ ((Button) inflatedView.findViewById(R.id.alphabetic_keyboard)).setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ textField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
+ InputMethodManager lManager = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ lManager.showSoftInput(textField.getEdit_text(), 0);
+ }
+ });
+
+ ((Button) inflatedView.findViewById(R.id.numeric_keyboard)).setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ textField.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
+ InputMethodManager lManager = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ lManager.showSoftInput(textField.getEdit_text(), 0);
+ }
+ });
+
+ isReady = true;
+ if (mCallbacks.getService() != null) {
+
+ onServiceSipBinded(mCallbacks.getService());
+ }
return inflatedView;
}
@@ -52,5 +133,57 @@
}
+ public void processingNewCallAction() {
+ // String accountID = mAccountList.currentAccountID;
+ String accountID = mAccountSelectionSpinner.getAccount();
+
+ String to = textField.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);
+ mCallbacks.onCallCreated(call);
+
+ try {
+ service.placeCall(info.mAccountID, info.mCallID, info.mPhone);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Cannot call service method", e);
+ }
+
+ }
+
+ public String getSelectedAccount() {
+ return mAccountSelectionSpinner.getAccount();
+ }
+
+ /**
+ * Called by activity to pass a reference to sipservice to Fragment.
+ *
+ * @param isip
+ */
+ public void onServiceSipBinded(ISipService isip) {
+
+ if (isReady) {
+ service = isip;
+ ArrayList<String> accountList;
+ try {
+ accountList = (ArrayList<String>) mCallbacks.getService().getAccountList();
+ Log.w(TAG, "SIP service binded accounts " + accountList.size());
+ mAccountSelectionSpinner.populate(mCallbacks.getService(), accountList);
+ } catch (RemoteException e) {
+ Log.i(TAG, e.toString());
+ }
+ }
+
+ }
}
diff --git a/src/com/savoirfairelinux/sflphone/fragments/MenuFragment.java b/src/com/savoirfairelinux/sflphone/fragments/MenuFragment.java
new file mode 100644
index 0000000..f8a206c
--- /dev/null
+++ b/src/com/savoirfairelinux/sflphone/fragments/MenuFragment.java
@@ -0,0 +1,55 @@
+package com.savoirfairelinux.sflphone.fragments;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+
+import com.savoirfairelinux.sflphone.R;
+import com.savoirfairelinux.sflphone.adapters.MenuAdapter;
+
+public class MenuFragment extends Fragment{
+
+ private static final String TAG = MenuFragment.class.getSimpleName();
+ public static final String ARG_SECTION_NUMBER = "section_number";
+
+ MenuAdapter mAdapter;
+
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mAdapter = new MenuAdapter(getActivity(),getResources().getStringArray(R.array.menu_categories));
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+ View inflatedView = inflater.inflate(R.layout.frag_menu, parent, false);
+
+ ((ListView) inflatedView.findViewById(R.id.listView)).setAdapter(mAdapter);
+ return inflatedView;
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ }
+
+
+}
diff --git a/src/com/savoirfairelinux/sflphone/service/ISipService.aidl b/src/com/savoirfairelinux/sflphone/service/ISipService.aidl
index 9b7b80f..25ac69c 100644
--- a/src/com/savoirfairelinux/sflphone/service/ISipService.aidl
+++ b/src/com/savoirfairelinux/sflphone/service/ISipService.aidl
@@ -47,6 +47,7 @@
void holdConference(in String confID);
void unholdConference(in String confID);
List getConferenceList();
+ List getCallList();
List getParticipantList(in String confID);
String getConferenceId(in String callID);
Map getConferenceDetails(in String callID);
diff --git a/src/com/savoirfairelinux/sflphone/service/SipService.java b/src/com/savoirfairelinux/sflphone/service/SipService.java
index 2f49975..c8b5d3d 100644
--- a/src/com/savoirfairelinux/sflphone/service/SipService.java
+++ b/src/com/savoirfairelinux/sflphone/service/SipService.java
@@ -871,5 +871,33 @@
return codecs;
}
+ @Override
+ public List getCallList() throws RemoteException {
+ class CallList extends SipRunnableWithReturn {
+
+ @Override
+ protected StringVect doRun() throws SameThreadException {
+ Log.i(TAG, "SipService.getCallList() thread running...");
+ return callManagerJNI.getCallList();
+ }
+ }
+
+ CallList runInstance = new CallList();
+ getExecutor().execute(runInstance);
+ while (!runInstance.isDone()) {
+ Log.w(TAG, "Waiting for getAudioCodecList");
+ }
+ StringVect swigmap = (StringVect) runInstance.getVal();
+
+ ArrayList<String> nativemap = new ArrayList<String>();
+ for (int i = 0; i < swigmap.size(); ++i) {
+
+ String t = swigmap.get(i);
+ nativemap.add(t);
+ }
+
+ return nativemap;
+ }
+
};
}
diff --git a/src/com/savoirfairelinux/sflphone/views/ClearableEditText.java b/src/com/savoirfairelinux/sflphone/views/ClearableEditText.java
index 6938759..b8c92c9 100644
--- a/src/com/savoirfairelinux/sflphone/views/ClearableEditText.java
+++ b/src/com/savoirfairelinux/sflphone/views/ClearableEditText.java
@@ -19,13 +19,11 @@
public ClearableEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- // TODO Auto-generated constructor stub
initViews();
}
public ClearableEditText(Context context, AttributeSet attrs) {
super(context, attrs);
- // TODO Auto-generated constructor stub
initViews();
}
@@ -85,4 +83,15 @@
Editable text = edit_text.getText();
return text;
}
+
+ public void setInputType(int typeClassNumber) {
+ edit_text.setFocusableInTouchMode(true);
+ edit_text.requestFocus();
+ edit_text.setInputType(typeClassNumber);
+
+ }
+
+ public EditText getEdit_text() {
+ return edit_text;
+ }
}