Move automatic echo canceller calibration in the wizard and collect the results on the linphone server.

This commit is contained in:
Ghislain MARY 2012-10-17 12:39:40 +02:00
parent bfa129656c
commit 6e65574e16
10 changed files with 179 additions and 38 deletions

BIN
res/drawable-xhdpi/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:contentDescription="@string/content_description_welcome"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:src="@drawable/logo"/>
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal|bottom" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:gravity="center_horizontal|top"
android:text="@string/setup_ec_calibration"
android:textColor="@android:color/white" />
</FrameLayout>

View file

@ -385,6 +385,7 @@
<string name="pref_auto_accept_friends_desc">utomatically accept new friend requests</string>
<string name="linphone_friend_new_request_title">Friend request</string>
<string name="linphone_friend_new_request_desc">wants to share it\'s presence status with you and be aware of yours.</string>
<string name="setup_ec_calibration">Echo canceller calibration in progress</string>
</resources>

View file

@ -25,7 +25,6 @@ import java.util.Calendar;
import java.util.List;
import org.linphone.LinphoneManager.AddressType;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.LinphoneManager.LinphoneConfigException;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceivedListener;
@ -39,7 +38,6 @@ import org.linphone.core.LinphoneCallLog;
import org.linphone.core.LinphoneCallLog.CallStatus;
import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
@ -47,7 +45,6 @@ import org.linphone.core.LinphoneFriend;
import org.linphone.core.Log;
import org.linphone.core.OnlineStatus;
import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import org.linphone.setup.SetupActivity;
import org.linphone.ui.AddressText;
@ -90,8 +87,7 @@ import android.widget.Toast;
public class LinphoneActivity extends FragmentActivity implements OnClickListener, ContactPicked,
LinphoneOnCallStateChangedListener,
LinphoneOnMessageReceivedListener,
LinphoneOnRegistrationStateChangedListener,
EcCalibrationListener {
LinphoneOnRegistrationStateChangedListener {
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
private static final int SETTINGS_ACTIVITY = 123;
private static final int FIRST_LOGIN_ACTIVITY = 101;
@ -1137,30 +1133,9 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
stopService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
}
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = prefs.edit();
if (status == EcCalibratorStatus.DoneNoEcho) {
editor.putBoolean(getString(R.string.pref_echo_cancellation_key), false);
} else if ((status == EcCalibratorStatus.Done) || (status == EcCalibratorStatus.Failed)) {
editor.putBoolean(getString(R.string.pref_echo_cancellation_key), true);
}
editor.commit();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == FIRST_LOGIN_ACTIVITY) && (resultCode == RESULT_OK)) {
if (!Hacks.hasBuiltInEchoCanceller()) {
Toast.makeText(this, getString(R.string.ec_calibration_launch_message), Toast.LENGTH_LONG).show();
try {
LinphoneManager.getInstance().startEcCalibration(this);
} catch (LinphoneCoreException e) {
Log.e(e, "Unable to calibrate EC");
}
}
}
else if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
if (resultCode == Activity.RESULT_FIRST_USER && requestCode == SETTINGS_ACTIVITY) {
if (data.getExtras().getBoolean("Exit", false)) {
exit();
} else {

View file

@ -0,0 +1,109 @@
package org.linphone.setup;
/*
EchoCancellerCalibrationFragment.java
Copyright (C) 2012 Belledonne Communications, Grenoble, France
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 the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import java.net.URL;
import org.linphone.LinphoneManager;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.R;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.Log;
import de.timroes.axmlrpc.XMLRPCCallback;
import de.timroes.axmlrpc.XMLRPCClient;
import de.timroes.axmlrpc.XMLRPCException;
import de.timroes.axmlrpc.XMLRPCServerException;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
/**
* @author Ghislain MARY
*/
public class EchoCancellerCalibrationFragment extends Fragment implements EcCalibrationListener {
private Handler mHandler = new Handler();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.setup_ec_calibration, container, false);
try {
LinphoneManager.getInstance().startEcCalibration(this);
} catch (LinphoneCoreException e) {
Log.e(e, "Unable to calibrate EC");
}
return view;
}
@Override
public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = prefs.edit();
if (status == EcCalibratorStatus.DoneNoEcho) {
editor.putBoolean(getString(R.string.pref_echo_cancellation_key), false);
} else if ((status == EcCalibratorStatus.Done) || (status == EcCalibratorStatus.Failed)) {
editor.putBoolean(getString(R.string.pref_echo_cancellation_key), true);
}
editor.commit();
sendEcCalibrationResult(status, delayMs);
}
private void sendEcCalibrationResult(EcCalibratorStatus status, int delayMs) {
try {
XMLRPCClient client = new XMLRPCClient(new URL(getString(R.string.wizard_url)));
XMLRPCCallback listener = new XMLRPCCallback() {
Runnable runFinished = new Runnable() {
public void run() {
SetupActivity.instance().isEchoCalibrationFinished();
}
};
public void onResponse(long id, Object result) {
mHandler.post(runFinished);
}
public void onError(long id, XMLRPCException error) {
mHandler.post(runFinished);
}
public void onServerError(long id, XMLRPCServerException error) {
mHandler.post(runFinished);
}
};
Log.i("Add echo canceller calibration result: manufacturer=" + Build.MANUFACTURER + " model=" + Build.MODEL + " status=" + status + " delay=" + delayMs + "ms");
client.callAsync(listener, "add_ec_calibration_result", Build.MANUFACTURER, Build.MODEL, status.toString(), delayMs);
}
catch(Exception ex) {}
}
}

View file

@ -59,7 +59,7 @@ public class GenericLoginFragment extends Fragment implements OnClickListener {
return;
}
SetupActivity.instance().logIn(login.getText().toString(), password.getText().toString(), domain.getText().toString());
SetupActivity.instance().genericLogIn(login.getText().toString(), password.getText().toString(), domain.getText().toString());
}
}
}

View file

@ -58,7 +58,7 @@ public class LinphoneLoginFragment extends Fragment implements OnClickListener {
return;
}
SetupActivity.instance().logIn(login.getText().toString(), password.getText().toString(), getString(R.string.default_domain));
SetupActivity.instance().linphoneLogIn(login.getText().toString(), password.getText().toString());
}
}
}

View file

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import org.linphone.LinphoneManager;
import org.linphone.R;
import org.linphone.core.Log;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import android.app.Activity;
import android.content.Context;
@ -141,14 +142,32 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
Log.e(e, "Error while initializing from config in first login activity");
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
}
public void linphoneLogIn(String username, String password) {
logIn(username, password, getString(R.string.default_domain));
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
writePreference(R.string.first_launch_suceeded_once_key, true);
setResult(Activity.RESULT_OK);
finish();
if (!Hacks.hasBuiltInEchoCanceller()) {
EchoCancellerCalibrationFragment fragment = new EchoCancellerCalibrationFragment();
changeFragment(fragment);
currentFragment = SetupFragments.ECHO_CANCELLER_CALIBRATION;
back.setVisibility(View.GONE);
next.setVisibility(View.VISIBLE);
next.setEnabled(false);
cancel.setEnabled(false);
} else {
success();
}
}
}
public void genericLogIn(String username, String password, String domain) {
logIn(username, password, domain);
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
success();
}
}
private void writePreference(int key, String value) {
mPref.edit().putString(getString(key), value).commit();
}
@ -237,9 +256,12 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
Log.e(e, "Error while initializing from config in first login activity");
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
writePreference(R.string.first_launch_suceeded_once_key, true);
finish();
success();
}
public void isEchoCalibrationFinished() {
success();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
@ -249,4 +271,10 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
}
return super.onKeyDown(keyCode, event);
}
public void success() {
writePreference(R.string.first_launch_suceeded_once_key, true);
setResult(Activity.RESULT_OK);
finish();
}
}

View file

@ -26,5 +26,6 @@ public enum SetupFragments {
WIZARD,
WIZARD_CONFIRM,
LINPHONE_LOGIN,
GENERIC_LOGIN;
GENERIC_LOGIN,
ECHO_CANCELLER_CALIBRATION;
}