From d603eb25eca8d51abe27f14cff2926bf9e9961c2 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 4 Jul 2016 15:35:57 +0200 Subject: [PATCH] Fixed toast messages on outgoing call error --- src/org/linphone/CallActivity.java | 17 +++----- src/org/linphone/CallOutgoingActivity.java | 47 +++++++++++++++++----- src/org/linphone/LinphoneActivity.java | 12 ------ 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/org/linphone/CallActivity.java b/src/org/linphone/CallActivity.java index afdbd8b60..b2904a313 100644 --- a/src/org/linphone/CallActivity.java +++ b/src/org/linphone/CallActivity.java @@ -30,6 +30,7 @@ import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreListenerBase; import org.linphone.core.LinphonePlayer; +import org.linphone.core.Reason; import org.linphone.mediastream.Log; import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.ui.Numpad; @@ -180,18 +181,14 @@ public class CallActivity extends Activity implements OnClickListener, SensorEve if (state == State.IncomingReceived) { startIncomingCallActivity(); return; - } - - if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) { + } else if (state == State.Paused || state == State.PausedByRemote || state == State.Pausing) { if(LinphoneManager.getLc().getCurrentCall() != null) { enabledVideoButton(false); } if(isVideoEnabled(call)){ showAudioView(); } - } - - if (state == State.Resuming) { + } else if (state == State.Resuming) { if(LinphonePreferences.instance().isVideoEnabled()){ status.refreshStatusItems(call, isVideoEnabled(call)); if(call.getCurrentParamsCopy().getVideoEnabled()){ @@ -201,9 +198,7 @@ public class CallActivity extends Activity implements OnClickListener, SensorEve if(LinphoneManager.getLc().getCurrentCall() != null) { enabledVideoButton(true); } - } - - if (state == State.StreamsRunning) { + } else if (state == State.StreamsRunning) { switchVideo(isVideoEnabled(call)); enableAndRefreshInCallActions(); @@ -211,9 +206,7 @@ public class CallActivity extends Activity implements OnClickListener, SensorEve videoProgress.setVisibility(View.GONE); status.refreshStatusItems(call, isVideoEnabled(call)); } - } - - if (state == State.CallUpdatedByRemote) { + } else if (state == State.CallUpdatedByRemote) { // If the correspondent proposes video while audio call boolean videoEnabled = LinphonePreferences.instance().isVideoEnabled(); if (!videoEnabled) { diff --git a/src/org/linphone/CallOutgoingActivity.java b/src/org/linphone/CallOutgoingActivity.java index 62a107206..b98bb7c5e 100644 --- a/src/org/linphone/CallOutgoingActivity.java +++ b/src/org/linphone/CallOutgoingActivity.java @@ -26,6 +26,7 @@ import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCallParams; import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCoreListenerBase; +import org.linphone.core.Reason; import org.linphone.mediastream.Log; import android.app.Activity; @@ -33,10 +34,14 @@ import android.content.pm.ActivityInfo; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; +import android.view.Gravity; import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.ViewGroup; import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; public class CallOutgoingActivity extends Activity implements OnClickListener{ @@ -88,16 +93,8 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{ mListener = new LinphoneCoreListenerBase(){ @Override - public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) { - if (LinphoneManager.getLc().getCallsNb() == 0) { - finish(); - return; - } - if (call == mCall && State.CallEnd == state) { - finish(); - } - - if (call == mCall && (State.Connected == state)){ + public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) { + if (call == mCall && State.Connected == state) { if (!LinphoneActivity.isInstanciated()) { return; } @@ -109,6 +106,22 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{ } finish(); return; + } else if (state == State.Error) { + // Convert LinphoneCore message for internalization + if (message != null && call.getErrorInfo().getReason() == Reason.Declined) { + displayCustomToast(getString(R.string.error_call_declined), Toast.LENGTH_SHORT); + } else if (message != null && call.getErrorInfo().getReason() == Reason.NotFound) { + displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_SHORT); + } else if (message != null && call.getErrorInfo().getReason() == Reason.Media) { + displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_SHORT); + } else if (message != null) { + displayCustomToast(getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_SHORT); + } + } + + if (LinphoneManager.getLc().getCallsNb() == 0) { + finish(); + return; } } }; @@ -204,6 +217,20 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{ return super.onKeyDown(keyCode, event); } + public void displayCustomToast(final String message, final int duration) { + LayoutInflater inflater = getLayoutInflater(); + View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot)); + + TextView toastText = (TextView) layout.findViewById(R.id.toastMessage); + toastText.setText(message); + + final Toast toast = new Toast(getApplicationContext()); + toast.setGravity(Gravity.CENTER, 0, 0); + toast.setDuration(duration); + toast.setView(layout); + toast.show(); + } + private void decline() { LinphoneManager.getLc().terminateCall(mCall); } diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index 9774559c8..3db9c5eeb 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -242,16 +242,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta checkAndRequestAudioPermission(false); } } else if (state == State.CallEnd || state == State.Error || state == State.CallReleased) { - // Convert LinphoneCore message for internalization - if (message != null && call.getErrorInfo().getReason() == Reason.Declined) { - displayCustomToast(getString(R.string.error_call_declined), Toast.LENGTH_SHORT); - } else if (message != null && call.getErrorInfo().getReason() == Reason.NotFound) { - displayCustomToast(getString(R.string.error_user_not_found), Toast.LENGTH_SHORT); - } else if (message != null && call.getErrorInfo().getReason() == Reason.Media) { - displayCustomToast(getString(R.string.error_incompatible_media), Toast.LENGTH_SHORT); - } else if (message != null && state == State.Error) { - displayCustomToast(getString(R.string.error_unknown) + " - " + message, Toast.LENGTH_SHORT); - } resetClassicMenuLayoutAndGoBackToCallIfStillRunning(); } @@ -880,8 +870,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta } } - - public void displayCustomToast(final String message, final int duration) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toastRoot));