Using the same call buttons as the home activity.
diff --git a/res/drawable/hold_button.xml b/res/drawable/hold_button.xml
new file mode 100644
index 0000000..061f383
--- /dev/null
+++ b/res/drawable/hold_button.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector
+ xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item android:state_pressed="true"
+ android:state_enabled="true" >
+ <shape>
+ <gradient
+ android:startColor="#FFBB33"
+ android:endColor="#FF8800"
+ android:angle="270" />
+ <stroke
+ android:width="3dp"
+ android:color="#FF8800" />
+ <corners
+ android:radius="3dp" />
+ <padding
+ android:left="10dp"
+ android:top="20dp"
+ android:right="10dp"
+ android:bottom="20dp" />
+ </shape>
+ </item>
+
+ <item android:state_enabled="false" >
+ <shape>
+ <gradient
+ android:startColor="#cccccc"
+ android:endColor="#cc0000"
+ android:angle="270" />
+ <stroke
+ android:width="3dp"
+ android:color="#FF8800" />
+ <corners
+ android:radius="3dp" />
+ <padding
+ android:left="10dp"
+ android:top="20dp"
+ android:right="10dp"
+ android:bottom="20dp" />
+ </shape>
+ </item>
+
+ <item>
+ <shape>
+ <gradient
+ android:startColor="#FFBB33"
+ android:endColor="#FF8800"
+ android:angle="270" />
+ <stroke
+ android:width="3dp"
+ android:color="#FF8800" />
+ <corners
+ android:radius="3dp" />
+ <padding
+ android:left="10dp"
+ android:top="20dp"
+ android:right="10dp"
+ android:bottom="20dp" />
+ </shape>
+ </item>
+</selector>
diff --git a/res/layout/activity_call_layout.xml b/res/layout/activity_call_layout.xml
index 44b54da..e585001 100644
--- a/res/layout/activity_call_layout.xml
+++ b/res/layout/activity_call_layout.xml
@@ -37,6 +37,7 @@
android:gravity="center_horizontal"
android:orientation="vertical" >
+ <!--
<Button
android:id="@+id/buttonanswer"
android:layout_width="match_parent"
@@ -59,7 +60,7 @@
android:id="@+id/buttonunhold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="Unhold" />
+ android:text="Unhold" /> -->
<LinearLayout
android:id="@+id/fragment_layout"
diff --git a/res/layout/frag_call_incoming.xml b/res/layout/frag_call_incoming.xml
index 4625371..f715d27 100644
--- a/res/layout/frag_call_incoming.xml
+++ b/res/layout/frag_call_incoming.xml
@@ -39,16 +39,18 @@
android:id="@+id/decline_btn"
android:layout_width="wrap_content"
android:layout_height="120dp"
+ android:layout_margin="10dp"
android:layout_weight="1"
- android:background="#FF4444"
+ android:background="@drawable/hangup_button"
android:text="Decline" />
<Button
android:id="@+id/accept_btn"
android:layout_width="wrap_content"
android:layout_height="120dp"
+ android:layout_margin="10dp"
android:layout_weight="1"
- android:background="#99CC00"
+ android:background="@drawable/call_button"
android:text="Accept" />
</LinearLayout>
diff --git a/res/layout/frag_call_ongoing.xml b/res/layout/frag_call_ongoing.xml
index 0124ed1..3a6ea37 100644
--- a/res/layout/frag_call_ongoing.xml
+++ b/res/layout/frag_call_ongoing.xml
@@ -3,31 +3,34 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
- <LinearLayout
- android:layout_width="match_parent"
+ <TextView
+ android:id="@+id/calllength_txt"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:orientation="vertical" >
+ android:layout_margin="10dp"
+ android:text="0:00"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
- <TextView
- android:id="@+id/calllength_txt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:text="0:00"
- android:textAppearance="?android:attr/textAppearanceMedium" />
+ <TextView
+ android:id="@+id/callstatus_txt"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignBaseline="@+id/calllength_txt"
+ android:layout_alignBottom="@+id/calllength_txt"
+ android:layout_alignParentRight="true"
+ android:layout_marginRight="10dp"
+ android:text="Calling"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
- <TextView
- android:id="@+id/contact_name_txt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/textView1"
- android:layout_margin="10dp"
- android:layout_marginTop="76dp"
- android:text="Caller Name"
- android:textAppearance="?android:attr/textAppearanceLarge" />
- </LinearLayout>
+ <TextView
+ android:id="@+id/contact_name_txt"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@+id/calllength_txt"
+ android:layout_margin="10dp"
+ android:text="Caller Name"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
@@ -37,18 +40,20 @@
<Button
android:id="@+id/end_btn"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="120dp"
+ android:layout_margin="10dp"
android:layout_weight="1"
- android:background="#FF4444"
+ android:background="@drawable/hangup_button"
android:text="End" />
<Button
android:id="@+id/suspend_btn"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="120dp"
+ android:layout_margin="10dp"
android:layout_weight="1"
- android:background="#FFBB33"
+ android:background="@drawable/hold_button"
android:text="Suspend" />
</LinearLayout>
diff --git a/src/com/savoirfairelinux/sflphone/client/CallActivity.java b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
index 8d8fc6e..c9392b9 100644
--- a/src/com/savoirfairelinux/sflphone/client/CallActivity.java
+++ b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
@@ -2,6 +2,7 @@
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
*
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
+ * Author: Adrien Béraud <adrien.beraud@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
@@ -33,6 +34,7 @@
import android.app.Activity;
import android.app.Fragment;
+import android.app.FragmentManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -41,12 +43,10 @@
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
-//import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
@@ -56,11 +56,15 @@
import com.savoirfairelinux.sflphone.service.ISipService;
import com.savoirfairelinux.sflphone.service.SipService;
-public class CallActivity extends Activity implements OnClickListener, IncomingCallFragment.ICallActionListener
+public class CallActivity extends Activity //implements IncomingCallFragment.ICallActionListener, OngoingCallFragment.ICallActionListener //OnClickListener
{
static final String TAG = "CallActivity";
private ISipService service;
private SipCall mCall;
+
+ public interface CallFragment {
+ void setCall(SipCall c);
+ }
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
@@ -91,12 +95,12 @@
Intent intent = new Intent(this, SipService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
-
- findViewById(R.id.buttonanswer).setOnClickListener(this);
- findViewById(R.id.buttonhangup).setOnClickListener(this);
- findViewById(R.id.buttonhold).setOnClickListener(this);
- findViewById(R.id.buttonunhold).setOnClickListener(this);
-
+ /*
+ findViewById(R.id.buttonanswer).setOnClickListener(this);
+ findViewById(R.id.buttonhangup).setOnClickListener(this);
+ findViewById(R.id.buttonhold).setOnClickListener(this);
+ findViewById(R.id.buttonunhold).setOnClickListener(this);
+ */
setCallStateDisplay(mCall.getCallStateString());
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED));
@@ -127,29 +131,30 @@
}
};
- @Override
- public void onClick(View view)
- {
- Log.i(TAG, "On click action");
- switch (view.getId()) {
- case R.id.buttonanswer:
- mCall.notifyServiceAnswer(service);
- break;
- case R.id.buttonhangup:
- if (mCall.notifyServiceHangup(service))
- finish();
- break;
- case R.id.buttonhold:
- mCall.notifyServiceHold(service);
- break;
- case R.id.buttonunhold:
- mCall.notifyServiceUnhold(service);
- break;
- default:
- Log.e(TAG, "Invalid button clicked");
+ /*
+ @Override
+ public void onClick(View view)
+ {
+ Log.i(TAG, "On click action");
+ switch (view.getId()) {
+ case R.id.buttonanswer:
+ mCall.notifyServiceAnswer(service);
+ break;
+ case R.id.buttonhangup:
+ if (mCall.notifyServiceHangup(service))
+ finish();
+ break;
+ case R.id.buttonhold:
+ mCall.notifyServiceHold(service);
+ break;
+ case R.id.buttonunhold:
+ mCall.notifyServiceUnhold(service);
+ break;
+ default:
+ Log.e(TAG, "Invalid button clicked");
+ }
}
- }
-
+ */
private void processCallStateChangedSignal(Intent intent)
{
Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
@@ -197,46 +202,51 @@
}
Log.w(TAG, "setCallStateDisplay " + newState);
-
+
mCall.printCallInfo();
- Fragment f = null;
- if (newState.equals("INCOMING")) {
- Log.w(TAG, "New CallingFragment");
+ FragmentManager fm = getFragmentManager();
+ Fragment f = fm.findFragmentByTag("call_fragment");
+ boolean replace = true;
+ if (newState.equals("INCOMING") && !(f instanceof IncomingCallFragment)) {
f = new IncomingCallFragment();
- ((IncomingCallFragment)f).setCall(mCall);
- } else if (newState.equals("CURRENT")) {
- Log.w(TAG, "New InCallFragment");
- f = new InCallFragment();
+ } else if (!newState.equals("INCOMING") && !(f instanceof OngoingCallFragment)) {
+ f = new OngoingCallFragment();
+ } else {
+ replace = false;
}
-
- if (f != null)
- getFragmentManager().beginTransaction().replace(R.id.fragment_layout, f).commit();
+
+ ((CallFragment)f).setCall(mCall);
+
+ if (replace)
+ getFragmentManager().beginTransaction().replace(R.id.fragment_layout, f, "call_fragment").commit();
}
- public static class InCallFragment extends Fragment
- {
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
- {
- EditText v = new EditText(getActivity());
- v.setText("Hello InCallFragment!");
- return v;
- //return inflater.inflate(R.layout.article_view, container, false);
- }
- }
-
- @Override
public void onCallAccepted()
{
mCall.notifyServiceAnswer(service);
}
- @Override
public void onCallRejected()
{
if (mCall.notifyServiceHangup(service))
finish();
}
+ public void onCallEnded()
+ {
+ if (mCall.notifyServiceHangup(service))
+ finish();
+ }
+
+ public void onCallSuspended()
+ {
+ mCall.notifyServiceHold(service);
+ }
+
+ public void onCallResumed()
+ {
+ mCall.notifyServiceUnhold(service);
+ }
+
}
diff --git a/src/com/savoirfairelinux/sflphone/client/IncomingCallFragment.java b/src/com/savoirfairelinux/sflphone/client/IncomingCallFragment.java
index f393c7a..7f586d8 100644
--- a/src/com/savoirfairelinux/sflphone/client/IncomingCallFragment.java
+++ b/src/com/savoirfairelinux/sflphone/client/IncomingCallFragment.java
@@ -1,7 +1,5 @@
package com.savoirfairelinux.sflphone.client;
-import java.lang.ref.WeakReference;
-
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
@@ -15,46 +13,50 @@
import com.savoirfairelinux.sflphone.R;
import com.savoirfairelinux.sflphone.model.SipCall;
-public class IncomingCallFragment extends Fragment implements OnClickListener
+public class IncomingCallFragment extends Fragment implements CallActivity.CallFragment, OnClickListener
{
- public interface ICallActionListener
- {
- public void onCallAccepted();
- public void onCallRejected();
- }
- private ICallActionListener listener;
+ private CallActivity listener;
private Button accept_btn, decline_btn;
+ private TextView contact_name_txt;
- private WeakReference<SipCall> call = null;
+ private SipCall mCall = null;
- public void setCall(SipCall mCall)
+ public void setCall(SipCall call)
{
- call = new WeakReference<SipCall>(mCall);
+ mCall = call; // = new WeakReference<SipCall>(mCall);
+ if(isAdded())
+ updateUI();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
ViewGroup v = (ViewGroup) inflater.inflate(R.layout.frag_call_incoming, container, false);
+
+ contact_name_txt = (TextView) v.findViewById(R.id.contact_name_txt);
decline_btn = (Button) v.findViewById(R.id.decline_btn);
accept_btn = (Button) v.findViewById(R.id.accept_btn);
+
decline_btn.setOnClickListener(this);
accept_btn.setOnClickListener(this);
- TextView contact_name_txt = (TextView) v.findViewById(R.id.contact_name_txt);
- if(call != null && call.get() != null) {
- contact_name_txt.setText(call.get().getDisplayName());
- }
-
+ updateUI();
return v;
}
+
+ private void updateUI()
+ {
+ if (mCall == null)
+ return;
+ contact_name_txt.setText(mCall.getDisplayName());
+ }
@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
- listener = (ICallActionListener) activity;
+ listener = (CallActivity) activity;
}
@Override
diff --git a/src/com/savoirfairelinux/sflphone/client/OngoingCallFragment.java b/src/com/savoirfairelinux/sflphone/client/OngoingCallFragment.java
index 2a9cdac..6bbc3ad 100644
--- a/src/com/savoirfairelinux/sflphone/client/OngoingCallFragment.java
+++ b/src/com/savoirfairelinux/sflphone/client/OngoingCallFragment.java
@@ -1,7 +1,5 @@
package com.savoirfairelinux.sflphone.client;
-import java.lang.ref.WeakReference;
-
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
@@ -15,53 +13,60 @@
import com.savoirfairelinux.sflphone.R;
import com.savoirfairelinux.sflphone.model.SipCall;
-public class OngoingCallFragment extends Fragment implements OnClickListener
+public class OngoingCallFragment extends Fragment implements CallActivity.CallFragment, OnClickListener
{
- public interface ICallActionListener
- {
- public void onCallEnded();
- public void onCallSuspended();
- public void onCallResumed();
- }
-
- private ICallActionListener listener;
+ private CallActivity listener;
private Button end_btn, suspend_btn;
-
- private WeakReference<SipCall> call = null;
+ private TextView callstatus_txt;
+ private TextView calllength_txt;
+ private TextView contact_name_txt;
- public void setCall(SipCall mCall)
+ private SipCall mCall = null;
+
+ public void setCall(SipCall call)
{
- call = new WeakReference<SipCall>(mCall);
+ mCall = call;
+ if(isAdded())
+ updateUI();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
- ViewGroup v = (ViewGroup) inflater.inflate(R.layout.frag_call_incoming, container, false);
+ ViewGroup v = (ViewGroup) inflater.inflate(R.layout.frag_call_ongoing, container, false);
+
+ contact_name_txt = (TextView) v.findViewById(R.id.contact_name_txt);
end_btn = (Button) v.findViewById(R.id.end_btn);
suspend_btn = (Button) v.findViewById(R.id.suspend_btn);
+ callstatus_txt = (TextView) v.findViewById(R.id.callstatus_txt);
+ calllength_txt = (TextView) v.findViewById(R.id.calllength_txt);
+
end_btn.setOnClickListener(this);
suspend_btn.setOnClickListener(this);
- TextView contact_name_txt = (TextView) v.findViewById(R.id.contact_name_txt);
- if(call != null && call.get() != null) {
- contact_name_txt.setText(call.get().getDisplayName());
- }
-
+ updateUI();
return v;
}
+ private void updateUI()
+ {
+ if (mCall == null)
+ return;
+ contact_name_txt.setText(mCall.getDisplayName());
+ callstatus_txt.setText(mCall.getCallStateString());
+ }
+
@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
- listener = (ICallActionListener) activity;
+ listener = (CallActivity) activity;
}
@Override
public void onClick(View v)
{
- if(v == end_btn) {
+ if (v == end_btn) {
listener.onCallEnded();
} else if (v == suspend_btn) {
listener.onCallSuspended();