From 47f4ed9209c6c3d3a36b7e82d60aee9d0b784214 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Thu, 24 Nov 2011 16:28:07 +0100 Subject: [PATCH] Incall notification (capturing video, active, paused) --- res/values/strings.xml | 4 ++ src/org/linphone/LinphoneActivity.java | 4 +- src/org/linphone/LinphoneManager.java | 16 ++++-- src/org/linphone/LinphoneService.java | 71 ++++++++++++++++++++++++-- submodules/linphone | 2 +- 5 files changed, 85 insertions(+), 12 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 9c063f4cc..78455871c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,6 +1,10 @@ + Audio call ongoing + Paused call ongoing + Video capturing call ongoing + Not ready for a new call Bad contact : %s Reset validated %s diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 651e4c5ba..804126579 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -423,11 +423,11 @@ public class LinphoneActivity extends TabActivity implements // Do not call if video activity already launched as it would cause a pause() of the launched one // and a race condition with capture surfaceview leading to a crash - public void startVideoActivity(LinphoneCall call, int delay) { + public void startVideoActivity(final LinphoneCall call, int delay) { if (VideoCallActivity.launched || call == null) return; - call.enableCamera(true); mHandler.postDelayed(new Runnable() { public void run() { + LinphoneManager.getInstance().enableCamera(call, true); if (VideoCallActivity.launched) return; startActivityForResult(new Intent().setClass( LinphoneActivity.this, diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 08673f824..d76b2b2dc 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -360,15 +360,21 @@ public final class LinphoneManager implements LinphoneCoreListener { public boolean toggleEnableCamera() { if (mLc.isIncall()) { boolean enabled = !mLc.getCurrentCall().cameraEnabled(); - mLc.getCurrentCall().enableCamera(enabled); + enableCamera(mLc.getCurrentCall(), enabled); return enabled; } return false; } - + public void enableCamera(LinphoneCall call, boolean enable) { + if (call != null) { + call.enableCamera(enable); + LinphoneService.instance().refreshIncallIcon(mLc.getCurrentCall()); + } + } + public void sendStaticImage(boolean send) { if (mLc.isIncall()) { - mLc.getCurrentCall().enableCamera(!send); + enableCamera(mLc.getCurrentCall(), !send); } } @@ -998,7 +1004,7 @@ public final class LinphoneManager implements LinphoneCoreListener { */ public boolean addVideo() { LinphoneCall call = mLc.getCurrentCall(); - if (call != null) call.enableCamera(true); + enableCamera(call, true); return reinviteWithVideo(); } @@ -1169,7 +1175,7 @@ public final class LinphoneManager implements LinphoneCoreListener { String message) { if (state==State.OutgoingInit || state==State.IncomingReceived) { boolean sendCamera = shareMyCamera() && mLc.getConferenceSize() == 0; - call.enableCamera(sendCamera); + enableCamera(call, sendCamera); } if (state == State.CallEnd && mLc.getCallsNb() == 0) { routeAudioToReceiver(); diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index cacff619d..b36b3a359 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -25,6 +25,7 @@ import java.lang.reflect.Method; import org.linphone.LinphoneManager.NewOutgoingCallUiListener; import org.linphone.LinphoneSimpleListener.LinphoneServiceListener; import org.linphone.core.LinphoneCall; +import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.Log; import org.linphone.core.OnlineStatus; @@ -88,10 +89,12 @@ public final class LinphoneService extends Service implements LinphoneServiceLis private final static int NOTIF_ID=1; + private final static int INCALL_NOTIF_ID=2; private Notification mNotif; + private Notification mIncallNotif; private PendingIntent mNotifContentIntent; - private String notificationTitle; + private String mNotificationTitle; private static final int IC_LEVEL_ORANGE=0; @@ -114,7 +117,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis PreferenceManager.setDefaultValues(this, R.xml.preferences, true); - notificationTitle = getString(R.string.app_name); + mNotificationTitle = getString(R.string.app_name); // Dump some debugging information to the logs Log.i(START_LINPHONE_LOGS); @@ -128,7 +131,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis Intent notifIntent = new Intent(this, LinphoneActivity.class); mNotifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, 0); - mNotif.setLatestEventInfo(this, notificationTitle,"", mNotifContentIntent); + mNotif.setLatestEventInfo(this, mNotificationTitle,"", mNotifContentIntent); LinphoneManager.createAndStart(this, this); LinphoneManager.getLc().setPresenceInfo(0, null, OnlineStatus.Online); @@ -164,6 +167,58 @@ public final class LinphoneService extends Service implements LinphoneServiceLis } } + private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE} + private IncallIconState mCurrentIncallIconState = IncallIconState.IDLE; + private synchronized void setIncallIcon(IncallIconState state) { + if (state == mCurrentIncallIconState) return; + mCurrentIncallIconState = state; + if (mIncallNotif == null) mIncallNotif = new Notification(); + + int notificationTextId = 0; + switch (state) { + case IDLE: + mNM.cancel(INCALL_NOTIF_ID); + return; + case INCALL: + mIncallNotif.icon = R.drawable.conf_unhook; + notificationTextId = R.string.incall_notif_active; + break; + case PAUSE: + mIncallNotif.icon = R.drawable.conf_status_paused; + notificationTextId = R.string.incall_notif_paused; + break; + case VIDEO: + mIncallNotif.icon = R.drawable.conf_video; + notificationTextId = R.string.incall_notif_video; + break; + default: + throw new IllegalArgumentException("Unknown state " + state); + } + + mIncallNotif.iconLevel = 0; + mIncallNotif.when=System.currentTimeMillis(); + mIncallNotif.flags &= Notification.FLAG_ONGOING_EVENT; + mIncallNotif.setLatestEventInfo(this, mNotificationTitle, getString(notificationTextId), mNotifContentIntent); + mNM.notify(INCALL_NOTIF_ID, mIncallNotif); + } + + public void refreshIncallIcon(LinphoneCall currentCall) { + LinphoneCore lc = LinphoneManager.getLc(); + if (currentCall != null) { + if (currentCall.getCurrentParamsCopy().getVideoEnabled() && currentCall.cameraEnabled()) { + // checking first current params is mandatory + setIncallIcon(IncallIconState.VIDEO); + } else { + setIncallIcon(IncallIconState.INCALL); + } + } else if (lc.getCallsNb() == 0) { + setIncallIcon(IncallIconState.IDLE); + } else if (lc.isInConference()) { + setIncallIcon(IncallIconState.INCALL); + } else { + setIncallIcon(IncallIconState.PAUSE); + } + } private static final Class[] mSetFgSign = new Class[] {boolean.class}; @@ -274,7 +329,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis text = String.format(text, id); } - mNotif.setLatestEventInfo(this, notificationTitle, text, mNotifContentIntent); + mNotif.setLatestEventInfo(this, mNotificationTitle, text, mNotifContentIntent); mNM.notify(NOTIF_ID, mNotif); } @@ -291,6 +346,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis super.onDestroy(); // Make sure our notification is gone. stopForegroundCompat(NOTIF_ID); + mNM.cancel(INCALL_NOTIF_ID); LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceInfo(0, null, OnlineStatus.Offline); LinphoneManager.destroy(); @@ -358,6 +414,13 @@ public final class LinphoneService extends Service implements LinphoneServiceLis .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } + if (state == State.StreamsRunning) { + // Workaround bug current call seems to be updated after state changed to streams running + refreshIncallIcon(call); + } else { + refreshIncallIcon(LinphoneManager.getLc().getCurrentCall()); + } + mHandler.post(new Runnable() { public void run() { if (guiListener() != null) diff --git a/submodules/linphone b/submodules/linphone index 72a508632..bb2582f22 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 72a508632760bf20c2aeac7e253f7a481974f499 +Subproject commit bb2582f220ef902961efc42b3ca526d62605f600