Import PreferenceActivity-less-EC-calibration
This commit is contained in:
parent
be7faa516e
commit
eaabeb2fb7
5 changed files with 213 additions and 173 deletions
|
@ -86,13 +86,8 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Alr
|
||||||
private SharedPreferences mPref;
|
private SharedPreferences mPref;
|
||||||
private AddVideoButton mAddVideo;
|
private AddVideoButton mAddVideo;
|
||||||
|
|
||||||
private static final String PREF_CHECK_CONFIG = "pref_check_config";
|
|
||||||
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
|
|
||||||
private static final String CURRENT_ADDRESS = "org.linphone.current-address";
|
private static final String CURRENT_ADDRESS = "org.linphone.current-address";
|
||||||
private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
|
private static final String CURRENT_DISPLAYNAME = "org.linphone.current-displayname";
|
||||||
|
|
||||||
private static boolean checkAccount = true;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,17 +179,6 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Alr
|
||||||
mStatus = (TextView) findViewById(R.id.status_label);
|
mStatus = (TextView) findViewById(R.id.status_label);
|
||||||
|
|
||||||
|
|
||||||
if (checkAccount) {
|
|
||||||
if (mPref.getBoolean(PREF_FIRST_LAUNCH, true)) {
|
|
||||||
onFirstLaunch();
|
|
||||||
} else if (!mPref.getBoolean(PREF_CHECK_CONFIG, false)
|
|
||||||
&& !checkDefined(R.string.pref_username_key, R.string.pref_passwd_key, R.string.pref_domain_key)) {
|
|
||||||
onBadSettings();
|
|
||||||
} else {
|
|
||||||
checkAccount = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,66 +197,7 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Alr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***** Check Account *******/
|
|
||||||
private boolean checkDefined(int ... keys) {
|
|
||||||
for (int key : keys) {
|
|
||||||
String conf = mPref.getString(getString(key), null);
|
|
||||||
if (conf == null || "".equals(conf))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onFirstLaunch() {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
TextView lDialogTextView = new TextView(this);
|
|
||||||
lDialogTextView.setAutoLinkMask(0x0f/*all*/);
|
|
||||||
lDialogTextView.setPadding(10, 10, 10, 10);
|
|
||||||
|
|
||||||
lDialogTextView.setText(Html.fromHtml(getString(R.string.first_launch_message)));
|
|
||||||
|
|
||||||
builder.setCustomTitle(lDialogTextView)
|
|
||||||
.setCancelable(false)
|
|
||||||
.setPositiveButton(getString(R.string.cont), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
LinphoneActivity.instance().startprefActivity();
|
|
||||||
checkAccount = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onBadSettings() {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
||||||
TextView lDialogTextView = new TextView(this);
|
|
||||||
lDialogTextView.setAutoLinkMask(0x0f/*all*/);
|
|
||||||
lDialogTextView.setPadding(10, 10, 10, 10);
|
|
||||||
|
|
||||||
lDialogTextView.setText(Html.fromHtml(getString(R.string.initial_config_error)));
|
|
||||||
|
|
||||||
builder.setCustomTitle(lDialogTextView)
|
|
||||||
.setCancelable(false)
|
|
||||||
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
LinphoneActivity.instance().startprefActivity();
|
|
||||||
checkAccount = false;
|
|
||||||
}
|
|
||||||
}).setNeutralButton(getString(R.string.no), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
dialog.cancel();
|
|
||||||
checkAccount = false;
|
|
||||||
}
|
|
||||||
}).setNegativeButton(getString(R.string.never_remind), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
mPref.edit().putBoolean(PREF_CHECK_CONFIG, true).commit();
|
|
||||||
dialog.cancel();
|
|
||||||
checkAccount = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -449,7 +374,7 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Alr
|
||||||
|
|
||||||
public void onWrongDestinationAddress() {
|
public void onWrongDestinationAddress() {
|
||||||
Toast toast = Toast.makeText(this
|
Toast toast = Toast.makeText(this
|
||||||
,String.format(getResources().getString(R.string.warning_wrong_destination_address),mAddress.getText().toString())
|
,String.format(getString(R.string.warning_wrong_destination_address),mAddress.getText().toString())
|
||||||
,Toast.LENGTH_LONG);
|
,Toast.LENGTH_LONG);
|
||||||
toast.show();
|
toast.show();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,10 @@ import static android.media.AudioManager.ROUTE_SPEAKER;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.linphone.LinphoneManager.EcCalibrationListener;
|
||||||
|
import org.linphone.core.LinphoneCoreException;
|
||||||
import org.linphone.core.Version;
|
import org.linphone.core.Version;
|
||||||
|
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
||||||
import org.linphone.core.LinphoneCore.RegistrationState;
|
import org.linphone.core.LinphoneCore.RegistrationState;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
@ -43,6 +46,7 @@ import android.hardware.SensorManager;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.text.Html;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
@ -51,25 +55,39 @@ import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class LinphoneActivity extends TabActivity {
|
public class LinphoneActivity extends TabActivity {
|
||||||
public static final String DIALER_TAB = "dialer";
|
public static final String DIALER_TAB = "dialer";
|
||||||
private AudioManager mAudioManager;
|
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
|
||||||
|
static final int VIDEO_VIEW_ACTIVITY = 100;
|
||||||
|
static final int FIRST_LOGIN_ACTIVITY = 101;
|
||||||
|
static final int INCALL_ACTIVITY = 102;
|
||||||
|
private static final String PREF_CHECK_CONFIG = "pref_check_config";
|
||||||
|
|
||||||
private static LinphoneActivity instance;
|
private static LinphoneActivity instance;
|
||||||
|
private AudioManager mAudioManager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private FrameLayout mMainFrame;
|
private FrameLayout mMainFrame;
|
||||||
private SensorManager mSensorManager;
|
private SensorManager mSensorManager;
|
||||||
private static SensorEventListener mSensorEventListener;
|
private static SensorEventListener mSensorEventListener;
|
||||||
|
|
||||||
private static final String SCREEN_IS_HIDDEN ="screen_is_hidden";
|
private static final String SCREEN_IS_HIDDEN ="screen_is_hidden";
|
||||||
static final int VIDEO_VIEW_ACTIVITY = 100;
|
|
||||||
static final int FIRST_LOGIN_ACTIVITY = 101;
|
|
||||||
static final int INCALL_ACTIVITY = 102;
|
// Customization
|
||||||
|
private static final boolean useFirstLoginActivity = false;
|
||||||
|
private static final boolean useMenuSettings = true;
|
||||||
|
private static final boolean useMenuAbout = true;
|
||||||
|
private boolean checkAccount = !useFirstLoginActivity;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static final LinphoneActivity instance() {
|
static final LinphoneActivity instance() {
|
||||||
if (instance != null) return instance;
|
if (instance != null) return instance;
|
||||||
|
|
||||||
|
@ -96,13 +114,23 @@ public class LinphoneActivity extends TabActivity {
|
||||||
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
if (!useFirstLoginActivity || pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
|
||||||
if (pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
|
|
||||||
fillTabHost();
|
fillTabHost();
|
||||||
} else {
|
} else {
|
||||||
startActivityForResult(new Intent().setClass(this, FirstLoginActivity.class), FIRST_LOGIN_ACTIVITY);
|
startActivityForResult(new Intent().setClass(this, FirstLoginActivity.class), FIRST_LOGIN_ACTIVITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkAccount && !useFirstLoginActivity) {
|
||||||
|
if (pref.getBoolean(PREF_FIRST_LAUNCH, true)) {
|
||||||
|
onFirstLaunch();
|
||||||
|
} else if (!pref.getBoolean(PREF_CHECK_CONFIG, false)
|
||||||
|
&& !checkDefined(pref, R.string.pref_username_key, R.string.pref_passwd_key, R.string.pref_domain_key)) {
|
||||||
|
onBadSettings(pref);
|
||||||
|
} else {
|
||||||
|
checkAccount = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (savedInstanceState !=null && savedInstanceState.getBoolean(SCREEN_IS_HIDDEN,false)) {
|
if (savedInstanceState !=null && savedInstanceState.getBoolean(SCREEN_IS_HIDDEN,false)) {
|
||||||
hideScreen(true);
|
hideScreen(true);
|
||||||
}
|
}
|
||||||
|
@ -115,6 +143,21 @@ public class LinphoneActivity extends TabActivity {
|
||||||
|
|
||||||
if (requestCode == FIRST_LOGIN_ACTIVITY) {
|
if (requestCode == FIRST_LOGIN_ACTIVITY) {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
|
Toast.makeText(this, getString(R.string.ec_calibration_launch_message), Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
try {
|
||||||
|
LinphoneManager.getInstance().startEcCalibration(new EcCalibrationListener() {
|
||||||
|
public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.this)
|
||||||
|
.edit().putBoolean(
|
||||||
|
getString(R.string.pref_echo_canceller_calibration_key),
|
||||||
|
status == EcCalibratorStatus.Done).commit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (LinphoneCoreException e) {
|
||||||
|
Log.e(LinphoneManager.TAG, "Unable to calibrate EC", e);
|
||||||
|
}
|
||||||
|
|
||||||
fillTabHost();
|
fillTabHost();
|
||||||
} else {
|
} else {
|
||||||
finish();
|
finish();
|
||||||
|
@ -200,6 +243,9 @@ public class LinphoneActivity extends TabActivity {
|
||||||
// Inflate the currently selected menu XML resource.
|
// Inflate the currently selected menu XML resource.
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.linphone_activity_menu, menu);
|
inflater.inflate(R.menu.linphone_activity_menu, menu);
|
||||||
|
|
||||||
|
menu.findItem(R.id.menu_settings).setVisible(useMenuSettings);
|
||||||
|
menu.findItem(R.id.menu_about).setVisible(useMenuAbout);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,23 +327,27 @@ public class LinphoneActivity extends TabActivity {
|
||||||
|
|
||||||
|
|
||||||
void showPreferenceErrorDialog(String message) {
|
void showPreferenceErrorDialog(String message) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
if (!useMenuSettings) {
|
||||||
.setMessage(String.format(getString(R.string.config_error), message))
|
Toast.makeText(this, message, Toast.LENGTH_LONG);
|
||||||
.setCancelable(false)
|
} else {
|
||||||
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
.setMessage(String.format(getString(R.string.config_error), message))
|
||||||
Intent intent = new Intent(ACTION_MAIN);
|
.setCancelable(false)
|
||||||
intent.setClass(getApplicationContext(), LinphonePreferencesActivity.class);
|
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
|
||||||
startActivity(intent);
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
}
|
Intent intent = new Intent(ACTION_MAIN);
|
||||||
})
|
intent.setClass(getApplicationContext(), LinphonePreferencesActivity.class);
|
||||||
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
|
startActivity(intent);
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
}
|
||||||
dialog.cancel();
|
})
|
||||||
}
|
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
|
||||||
});
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRegistrationStateChanged(RegistrationState state,
|
public void onRegistrationStateChanged(RegistrationState state,
|
||||||
|
@ -308,5 +358,67 @@ public class LinphoneActivity extends TabActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***** Check Account *******/
|
||||||
|
private boolean checkDefined(SharedPreferences pref, int ... keys) {
|
||||||
|
for (int key : keys) {
|
||||||
|
String conf = pref.getString(getString(key), null);
|
||||||
|
if (conf == null || "".equals(conf))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onFirstLaunch() {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
TextView lDialogTextView = new TextView(this);
|
||||||
|
lDialogTextView.setAutoLinkMask(0x0f/*all*/);
|
||||||
|
lDialogTextView.setPadding(10, 10, 10, 10);
|
||||||
|
|
||||||
|
lDialogTextView.setText(Html.fromHtml(getString(R.string.first_launch_message)));
|
||||||
|
|
||||||
|
builder.setCustomTitle(lDialogTextView)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(getString(R.string.cont), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
LinphoneActivity.instance().startprefActivity();
|
||||||
|
checkAccount = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onBadSettings(final SharedPreferences pref) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
TextView lDialogTextView = new TextView(this);
|
||||||
|
lDialogTextView.setAutoLinkMask(0x0f/*all*/);
|
||||||
|
lDialogTextView.setPadding(10, 10, 10, 10);
|
||||||
|
|
||||||
|
lDialogTextView.setText(Html.fromHtml(getString(R.string.initial_config_error)));
|
||||||
|
|
||||||
|
builder.setCustomTitle(lDialogTextView)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
LinphoneActivity.instance().startprefActivity();
|
||||||
|
checkAccount = false;
|
||||||
|
}
|
||||||
|
}).setNeutralButton(getString(R.string.no), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.cancel();
|
||||||
|
checkAccount = false;
|
||||||
|
}
|
||||||
|
}).setNegativeButton(getString(R.string.never_remind), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
pref.edit().putBoolean(PREF_CHECK_CONFIG, true).commit();
|
||||||
|
dialog.cancel();
|
||||||
|
checkAccount = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -535,12 +535,13 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
||||||
void tryingNewOutgoingCallButAlreadyInCall();
|
void tryingNewOutgoingCallButAlreadyInCall();
|
||||||
void onRegistrationStateChanged(RegistrationState state, String message);
|
void onRegistrationStateChanged(RegistrationState state, String message);
|
||||||
void onCallStateChanged(LinphoneCall call, State state, String message);
|
void onCallStateChanged(LinphoneCall call, State state, String message);
|
||||||
void onEcCalibrationStatus(EcCalibratorStatus status, Object data,
|
|
||||||
int delayMs);
|
|
||||||
void onRingerPlayerCreated(MediaPlayer mRingerPlayer);
|
void onRingerPlayerCreated(MediaPlayer mRingerPlayer);
|
||||||
void onDisplayStatus(String message);
|
void onDisplayStatus(String message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface EcCalibrationListener {
|
||||||
|
void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs);
|
||||||
|
}
|
||||||
|
|
||||||
private LinphoneServiceListener serviceListener;
|
private LinphoneServiceListener serviceListener;
|
||||||
private LinphoneCall.State mCurrentCallState;
|
private LinphoneCall.State mCurrentCallState;
|
||||||
|
@ -611,20 +612,30 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ecCalibrationStatus(final LinphoneCore lc,final EcCalibratorStatus status, final int delay_ms,
|
public void ecCalibrationStatus(final LinphoneCore lc,final EcCalibratorStatus status, final int delayMs,
|
||||||
final Object data) {
|
final Object data) {
|
||||||
serviceListener.onEcCalibrationStatus(status, data, delay_ms);
|
EcCalibrationListener listener = (EcCalibrationListener) data;
|
||||||
|
listener.onEcCalibrationStatus(status, delayMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void startEcCalibration(EcCalibrationListener l) throws LinphoneCoreException {
|
||||||
|
int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL);
|
||||||
|
int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL);
|
||||||
|
mAudioManager.setStreamVolume(STREAM_VOICE_CALL, maxVolume, 0);
|
||||||
|
|
||||||
|
mLc.startEchoCalibration(l);
|
||||||
|
|
||||||
|
mAudioManager.setStreamVolume(STREAM_VOICE_CALL, oldVolume, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private synchronized void startRinging() {
|
private synchronized void startRinging() {
|
||||||
|
|
|
@ -20,8 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
|
|
||||||
import static android.media.AudioManager.STREAM_VOICE_CALL;
|
|
||||||
import static org.linphone.R.string.cont;
|
|
||||||
import static org.linphone.R.string.ec_calibrating;
|
import static org.linphone.R.string.ec_calibrating;
|
||||||
import static org.linphone.R.string.ec_calibration_launch_message;
|
import static org.linphone.R.string.ec_calibration_launch_message;
|
||||||
import static org.linphone.R.string.pref_codec_ilbc_key;
|
import static org.linphone.R.string.pref_codec_ilbc_key;
|
||||||
|
@ -31,35 +29,43 @@ import static org.linphone.R.string.pref_echo_cancellation_key;
|
||||||
import static org.linphone.R.string.pref_echo_canceller_calibration_key;
|
import static org.linphone.R.string.pref_echo_canceller_calibration_key;
|
||||||
import static org.linphone.R.string.pref_video_enable_key;
|
import static org.linphone.R.string.pref_video_enable_key;
|
||||||
|
|
||||||
|
import org.linphone.LinphoneManager.EcCalibrationListener;
|
||||||
import org.linphone.core.LinphoneCoreException;
|
import org.linphone.core.LinphoneCoreException;
|
||||||
import org.linphone.core.Version;
|
import org.linphone.core.Version;
|
||||||
|
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.content.SharedPreferences;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.DialogInterface.OnClickListener;
|
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class LinphonePreferencesActivity extends PreferenceActivity {
|
public class LinphonePreferencesActivity extends PreferenceActivity implements EcCalibrationListener {
|
||||||
private boolean mIsLowEndCpu = true;
|
private boolean mIsLowEndCpu = true;
|
||||||
private AudioManager mAudioManager;
|
private Handler mHandler = new Handler();
|
||||||
|
private CheckBoxPreference ecPref;
|
||||||
|
|
||||||
|
private SharedPreferences prefs() {
|
||||||
|
return getPreferenceManager().getSharedPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
|
|
||||||
boolean enableIlbc=false;
|
boolean enableIlbc=false;
|
||||||
if (LinphoneService.isReady()) {
|
if (LinphoneService.isReady()) {
|
||||||
// if not ilbc, we are on low end cpu.
|
// if not ilbc, we are on low end cpu.
|
||||||
enableIlbc = LinphoneManager.getLc().findPayloadType("iLBC", 8000)!=null?true:false;
|
enableIlbc = LinphoneManager.getLc().findPayloadType("iLBC", 8000)!=null?true:false;
|
||||||
mIsLowEndCpu=!enableIlbc;
|
mIsLowEndCpu=!enableIlbc;
|
||||||
if (!mIsLowEndCpu && !getPreferenceManager().getSharedPreferences().contains(getString(pref_echo_cancellation_key))) {
|
if (!mIsLowEndCpu && !prefs().contains(getString(pref_echo_cancellation_key))) {
|
||||||
writeBoolean(pref_echo_cancellation_key, true);
|
writeBoolean(pref_echo_cancellation_key, true);
|
||||||
}
|
}
|
||||||
if (mIsLowEndCpu) {
|
if (mIsLowEndCpu) {
|
||||||
|
@ -70,56 +76,62 @@ public class LinphonePreferencesActivity extends PreferenceActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the preferences from an XML resource
|
ecPref = (CheckBoxPreference) findPreference(pref_echo_canceller_calibration_key);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
ecPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
startEcCalibration();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
if (!mIsLowEndCpu) {
|
if (!mIsLowEndCpu) {
|
||||||
findPreference(pref_codec_ilbc_key).setEnabled(enableIlbc);
|
findPreference(pref_codec_ilbc_key).setEnabled(enableIlbc);
|
||||||
findPreference(pref_codec_speex16_key).setEnabled(enableIlbc);
|
findPreference(pref_codec_speex16_key).setEnabled(enableIlbc);
|
||||||
//findPreference(pref_codec_speex32_key)).setEnabled(enableIlbc);
|
//findPreference(pref_codec_speex32_key)).setEnabled(enableIlbc);
|
||||||
}
|
}
|
||||||
findPreference(pref_echo_canceller_calibration_key)
|
|
||||||
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
|
||||||
startEcCalibration(preference);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Force disable video
|
// Force disable video
|
||||||
if (Version.sdkStrictlyBelow(5) || !enableIlbc || !LinphoneManager.getInstance().hasCamera()) {
|
if (Version.sdkStrictlyBelow(5) || !enableIlbc || !LinphoneManager.getInstance().hasCamera()) {
|
||||||
disableCheckbox(pref_video_enable_key);
|
disableCheckbox(pref_video_enable_key);
|
||||||
}
|
}
|
||||||
if (getPreferenceManager().getSharedPreferences().getBoolean(DialerActivity.PREF_FIRST_LAUNCH,true)) {
|
if (prefs().getBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,true)) {
|
||||||
if (!mIsLowEndCpu ) {
|
if (!mIsLowEndCpu ) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
Toast.makeText(this, getString(ec_calibration_launch_message), Toast.LENGTH_LONG).show();
|
||||||
builder.setTitle(ec_calibration_launch_message).setCancelable(false).setPositiveButton(getString(cont), new OnClickListener() {
|
startEcCalibration();
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
startEcCalibration(findPreference(pref_echo_canceller_calibration_key));
|
|
||||||
}
|
|
||||||
}).create().show();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
getPreferenceManager().getSharedPreferences().edit().putBoolean(DialerActivity.PREF_FIRST_LAUNCH, false).commit();
|
prefs().edit().putBoolean(LinphoneActivity.PREF_FIRST_LAUNCH, false).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private synchronized void startEcCalibration(Preference preference) {
|
private synchronized void startEcCalibration() {
|
||||||
try {
|
try {
|
||||||
int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL);
|
LinphoneManager.getInstance().startEcCalibration(this);
|
||||||
int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL);
|
|
||||||
mAudioManager.setStreamVolume(STREAM_VOICE_CALL, maxVolume, 0);
|
|
||||||
|
|
||||||
LinphoneManager.getLc().startEchoCalibration(preference);
|
ecPref.setSummary(ec_calibrating);
|
||||||
|
ecPref.getEditor().putBoolean(getString(pref_echo_canceller_calibration_key), false).commit();
|
||||||
mAudioManager.setStreamVolume(STREAM_VOICE_CALL, oldVolume, 0);
|
|
||||||
|
|
||||||
preference.setSummary(ec_calibrating);
|
|
||||||
preference.getEditor().putBoolean(getString(pref_echo_canceller_calibration_key), false).commit();
|
|
||||||
} catch (LinphoneCoreException e) {
|
} catch (LinphoneCoreException e) {
|
||||||
Log.w(LinphoneManager.TAG, "Cannot calibrate EC",e);
|
Log.w(LinphoneManager.TAG, "Cannot calibrate EC",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
|
||||||
|
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (status == EcCalibratorStatus.Done) {
|
||||||
|
ecPref.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
|
||||||
|
ecPref.setChecked(true);
|
||||||
|
|
||||||
|
} else if (status == EcCalibratorStatus.Failed) {
|
||||||
|
ecPref.setSummary(R.string.failed);
|
||||||
|
ecPref.setChecked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void disableCheckbox(int key) {
|
private void disableCheckbox(int key) {
|
||||||
writeBoolean(key, false);
|
writeBoolean(key, false);
|
||||||
CheckBoxPreference box = (CheckBoxPreference) findPreference(key);
|
CheckBoxPreference box = (CheckBoxPreference) findPreference(key);
|
||||||
|
@ -128,11 +140,11 @@ public class LinphonePreferencesActivity extends PreferenceActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Preference findPreference(int key) {
|
private Preference findPreference(int key) {
|
||||||
return getPreferenceScreen().findPreference(getString(key));
|
return getPreferenceManager().findPreference(getString(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeBoolean(int key, boolean value) {
|
private void writeBoolean(int key, boolean value) {
|
||||||
getPreferenceManager().getSharedPreferences().edit().putBoolean(getString(key), value).commit();
|
prefs().edit().putBoolean(getString(key), value).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.linphone.LinphoneManager.NewOutgoingCallUiListener;
|
||||||
import org.linphone.core.Hacks;
|
import org.linphone.core.Hacks;
|
||||||
import org.linphone.core.LinphoneCall;
|
import org.linphone.core.LinphoneCall;
|
||||||
import org.linphone.core.LinphoneCall.State;
|
import org.linphone.core.LinphoneCall.State;
|
||||||
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
|
|
||||||
import org.linphone.core.LinphoneCore.GlobalState;
|
import org.linphone.core.LinphoneCore.GlobalState;
|
||||||
import org.linphone.core.LinphoneCore.RegistrationState;
|
import org.linphone.core.LinphoneCore.RegistrationState;
|
||||||
|
|
||||||
|
@ -40,7 +39,6 @@ import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -225,24 +223,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onEcCalibrationStatus(final EcCalibratorStatus status, Object data,
|
|
||||||
final int delay_ms) {
|
|
||||||
final CheckBoxPreference pref = (CheckBoxPreference) data;
|
|
||||||
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (status == EcCalibratorStatus.Done) {
|
|
||||||
pref.setSummary(String.format(getString(R.string.ec_calibrated), delay_ms));
|
|
||||||
pref.setChecked(true);
|
|
||||||
|
|
||||||
} else if (status == EcCalibratorStatus.Failed) {
|
|
||||||
pref.setSummary(R.string.failed);
|
|
||||||
pref.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public interface LinphoneGuiListener extends NewOutgoingCallUiListener {
|
public interface LinphoneGuiListener extends NewOutgoingCallUiListener {
|
||||||
void onDisplayStatus(String message);
|
void onDisplayStatus(String message);
|
||||||
|
|
Loading…
Reference in a new issue