From 704fefc80a108ef6e964c84e2db62f39c5b6bfe9 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 23 Jul 2012 17:09:36 +0200 Subject: [PATCH] Fix some issues --- AndroidManifest.xml | 4 +-- src/org/linphone/AudioCallFragment.java | 5 ++++ src/org/linphone/InCallActivity.java | 36 +++++-------------------- src/org/linphone/LinphoneActivity.java | 19 ++++++++----- src/org/linphone/LinphoneUtils.java | 28 +++++++++++++++++++ 5 files changed, 53 insertions(+), 39 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index cf252626f..c2738d87f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -54,7 +54,7 @@ android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:screenOrientation="portrait" - android:launchMode="singleInstance"> + android:launchMode="singleTask"> @@ -63,7 +63,7 @@ diff --git a/src/org/linphone/AudioCallFragment.java b/src/org/linphone/AudioCallFragment.java index 4f3b44efd..f6187253a 100644 --- a/src/org/linphone/AudioCallFragment.java +++ b/src/org/linphone/AudioCallFragment.java @@ -173,6 +173,11 @@ public class AudioCallFragment extends Fragment { callsList.removeAllViews(); int index = 0; + + if (LinphoneManager.getLc().getCallsNb() == 0) { + inCallActivity.goBackToDialer(); + return; + } for (LinphoneCall call : LinphoneManager.getLc().getCalls()) { LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call, container, false); diff --git a/src/org/linphone/InCallActivity.java b/src/org/linphone/InCallActivity.java index 695c2cf1d..6f4aaa411 100644 --- a/src/org/linphone/InCallActivity.java +++ b/src/org/linphone/InCallActivity.java @@ -77,7 +77,7 @@ public class InCallActivity extends FragmentActivity implements if (LinphoneManager.getLc().getCallsNb() > 0) { LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; - if (isCallEstablished(call)) { + if (LinphoneUtils.isCallEstablished(call)) { enableAndRefreshInCallActions(); isVideoEnabled = call.getCurrentParamsCopy().getVideoEnabled(); } @@ -204,8 +204,7 @@ public class InCallActivity extends FragmentActivity implements toogleSpeaker(); } else if (id == R.id.addCall) { - setResult(Activity.RESULT_FIRST_USER); - finish(); + goBackToDialer(); } else if (id == R.id.pause) { pause(); @@ -317,7 +316,7 @@ public class InCallActivity extends FragmentActivity implements private void pause() { LinphoneCore lc = LinphoneManager.getLc(); LinphoneCall call = lc.getCurrentCall(); - if (call != null && isCallRunning(call)) { + if (call != null && LinphoneUtils.isCallRunning(call)) { lc.pauseCall(call); pause.setImageResource(R.drawable.pause_on); } else { @@ -482,32 +481,9 @@ public class InCallActivity extends FragmentActivity implements } } - private boolean isCallRunning(LinphoneCall call) - { - if (call == null) { - return false; - } - - LinphoneCall.State state = call.getState(); - - return state == LinphoneCall.State.Connected || - state == LinphoneCall.State.CallUpdated || - state == LinphoneCall.State.CallUpdatedByRemote || - state == LinphoneCall.State.StreamsRunning || - state == LinphoneCall.State.Resuming; - } - - private boolean isCallEstablished(LinphoneCall call) { - if (call == null) { - return false; - } - - LinphoneCall.State state = call.getState(); - - return isCallRunning(call) || - state == LinphoneCall.State.Paused || - state == LinphoneCall.State.PausedByRemote || - state == LinphoneCall.State.Pausing; + public void goBackToDialer() { + setResult(Activity.RESULT_FIRST_USER); + finish(); } @Override diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index b5cc83547..fbc0ceb43 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -495,11 +495,9 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene } @Override - public void onCallStateChanged(LinphoneCall call, State state, - String message) { + public void onCallStateChanged(LinphoneCall call, State state, String message) { if (state == State.IncomingReceived) { - Intent intent = new Intent(this, IncomingCallActivity.class); - startActivity(intent); + startActivity(new Intent(this, IncomingCallActivity.class)); } else if (state == State.OutgoingInit) { if (call.getCurrentParamsCopy().getVideoEnabled()) { startVideoActivity(call); @@ -681,14 +679,21 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene updateMissedChatCount(); displayMissedCalls(LinphoneManager.getLc().getMissedCallsCount()); + + if (LinphoneManager.getLc().getCalls().length > 0) { + LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; + LinphoneCall.State callState = call.getState(); + if (callState == State.IncomingReceived) { + startActivity(new Intent(this, IncomingCallActivity.class)); + } + } } @Override - protected void onPause() { - super.onPause(); - + protected void onDestroy() { chatStorage.close(); chatStorage = null; + super.onDestroy(); } @Override diff --git a/src/org/linphone/LinphoneUtils.java b/src/org/linphone/LinphoneUtils.java index bc962dd29..f080c300a 100644 --- a/src/org/linphone/LinphoneUtils.java +++ b/src/org/linphone/LinphoneUtils.java @@ -241,5 +241,33 @@ public final class LinphoneUtils { public static int pixelsToDpi(Resources res, int pixels) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) pixels, res.getDisplayMetrics()); } + + public static boolean isCallRunning(LinphoneCall call) + { + if (call == null) { + return false; + } + + LinphoneCall.State state = call.getState(); + + return state == LinphoneCall.State.Connected || + state == LinphoneCall.State.CallUpdated || + state == LinphoneCall.State.CallUpdatedByRemote || + state == LinphoneCall.State.StreamsRunning || + state == LinphoneCall.State.Resuming; + } + + public static boolean isCallEstablished(LinphoneCall call) { + if (call == null) { + return false; + } + + LinphoneCall.State state = call.getState(); + + return isCallRunning(call) || + state == LinphoneCall.State.Paused || + state == LinphoneCall.State.PausedByRemote || + state == LinphoneCall.State.Pausing; + } }