diff --git a/src/org/linphone/DialerActivity.java b/src/org/linphone/DialerActivity.java index 04d66565d..3aa2c643d 100644 --- a/src/org/linphone/DialerActivity.java +++ b/src/org/linphone/DialerActivity.java @@ -86,13 +86,8 @@ public class DialerActivity extends Activity implements LinphoneGuiListener, Alr private SharedPreferences mPref; 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_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); - 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() { 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.show(); } diff --git a/src/org/linphone/LinphoneActivity.java b/src/org/linphone/LinphoneActivity.java index c8876cad0..3999e2d90 100644 --- a/src/org/linphone/LinphoneActivity.java +++ b/src/org/linphone/LinphoneActivity.java @@ -26,7 +26,10 @@ import static android.media.AudioManager.ROUTE_SPEAKER; import java.util.List; +import org.linphone.LinphoneManager.EcCalibrationListener; +import org.linphone.core.LinphoneCoreException; import org.linphone.core.Version; +import org.linphone.core.LinphoneCore.EcCalibratorStatus; import org.linphone.core.LinphoneCore.RegistrationState; import android.app.AlertDialog; @@ -43,6 +46,7 @@ import android.hardware.SensorManager; import android.media.AudioManager; import android.os.Bundle; import android.preference.PreferenceManager; +import android.text.Html; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -51,25 +55,39 @@ import android.view.View; import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.TabHost; +import android.widget.TextView; import android.widget.Toast; public class LinphoneActivity extends TabActivity { 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 AudioManager mAudioManager; + + private FrameLayout mMainFrame; private SensorManager mSensorManager; private static SensorEventListener mSensorEventListener; 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() { if (instance != null) return instance; @@ -96,13 +114,23 @@ public class LinphoneActivity extends TabActivity { mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); - - if (pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) { + if (!useFirstLoginActivity || pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) { fillTabHost(); } else { 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)) { hideScreen(true); } @@ -115,6 +143,21 @@ public class LinphoneActivity extends TabActivity { if (requestCode == FIRST_LOGIN_ACTIVITY) { 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(); } else { finish(); @@ -200,6 +243,9 @@ public class LinphoneActivity extends TabActivity { // Inflate the currently selected menu XML resource. MenuInflater inflater = getMenuInflater(); 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; } @@ -281,23 +327,27 @@ public class LinphoneActivity extends TabActivity { void showPreferenceErrorDialog(String message) { - AlertDialog.Builder builder = new AlertDialog.Builder(this) - .setMessage(String.format(getString(R.string.config_error), message)) - .setCancelable(false) - .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - Intent intent = new Intent(ACTION_MAIN); - intent.setClass(getApplicationContext(), LinphonePreferencesActivity.class); - startActivity(intent); - } - }) - .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); + if (!useMenuSettings) { + Toast.makeText(this, message, Toast.LENGTH_LONG); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(this) + .setMessage(String.format(getString(R.string.config_error), message)) + .setCancelable(false) + .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Intent intent = new Intent(ACTION_MAIN); + intent.setClass(getApplicationContext(), LinphonePreferencesActivity.class); + startActivity(intent); + } + }) + .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, @@ -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(); + } } diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index f2270b70f..42d0f0c8b 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -535,12 +535,13 @@ public final class LinphoneManager implements LinphoneCoreListener { void tryingNewOutgoingCallButAlreadyInCall(); void onRegistrationStateChanged(RegistrationState state, String message); void onCallStateChanged(LinphoneCall call, State state, String message); - void onEcCalibrationStatus(EcCalibratorStatus status, Object data, - int delayMs); void onRingerPlayerCreated(MediaPlayer mRingerPlayer); void onDisplayStatus(String message); } + public interface EcCalibrationListener { + void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs); + } private LinphoneServiceListener serviceListener; 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) { - 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() { diff --git a/src/org/linphone/LinphonePreferencesActivity.java b/src/org/linphone/LinphonePreferencesActivity.java index 1ae1a866c..f01a62afe 100644 --- a/src/org/linphone/LinphonePreferencesActivity.java +++ b/src/org/linphone/LinphonePreferencesActivity.java @@ -20,8 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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_calibration_launch_message; 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_video_enable_key; +import org.linphone.LinphoneManager.EcCalibrationListener; import org.linphone.core.LinphoneCoreException; import org.linphone.core.Version; +import org.linphone.core.LinphoneCore.EcCalibratorStatus; -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; -import android.media.AudioManager; +import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.Preference.OnPreferenceClickListener; 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 AudioManager mAudioManager; - + private Handler mHandler = new Handler(); + private CheckBoxPreference ecPref; + + private SharedPreferences prefs() { + return getPreferenceManager().getSharedPreferences(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE)); + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.preferences); + + boolean enableIlbc=false; if (LinphoneService.isReady()) { // if not ilbc, we are on low end cpu. enableIlbc = LinphoneManager.getLc().findPayloadType("iLBC", 8000)!=null?true:false; 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); } if (mIsLowEndCpu) { @@ -70,56 +76,62 @@ public class LinphonePreferencesActivity extends PreferenceActivity { } - // Load the preferences from an XML resource - addPreferencesFromResource(R.xml.preferences); + ecPref = (CheckBoxPreference) findPreference(pref_echo_canceller_calibration_key); + ecPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { + public boolean onPreferenceClick(Preference preference) { + startEcCalibration(); + return false; + } + }); + + if (!mIsLowEndCpu) { findPreference(pref_codec_ilbc_key).setEnabled(enableIlbc); findPreference(pref_codec_speex16_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 if (Version.sdkStrictlyBelow(5) || !enableIlbc || !LinphoneManager.getInstance().hasCamera()) { disableCheckbox(pref_video_enable_key); } - if (getPreferenceManager().getSharedPreferences().getBoolean(DialerActivity.PREF_FIRST_LAUNCH,true)) { + if (prefs().getBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,true)) { if (!mIsLowEndCpu ) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(ec_calibration_launch_message).setCancelable(false).setPositiveButton(getString(cont), new OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - startEcCalibration(findPreference(pref_echo_canceller_calibration_key)); - } - }).create().show(); + Toast.makeText(this, getString(ec_calibration_launch_message), Toast.LENGTH_LONG).show(); + startEcCalibration(); } - 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 { - int oldVolume = mAudioManager.getStreamVolume(STREAM_VOICE_CALL); - int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_VOICE_CALL); - mAudioManager.setStreamVolume(STREAM_VOICE_CALL, maxVolume, 0); + LinphoneManager.getInstance().startEcCalibration(this); - LinphoneManager.getLc().startEchoCalibration(preference); - - mAudioManager.setStreamVolume(STREAM_VOICE_CALL, oldVolume, 0); - - preference.setSummary(ec_calibrating); - preference.getEditor().putBoolean(getString(pref_echo_canceller_calibration_key), false).commit(); + ecPref.setSummary(ec_calibrating); + ecPref.getEditor().putBoolean(getString(pref_echo_canceller_calibration_key), false).commit(); } catch (LinphoneCoreException 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) { writeBoolean(key, false); CheckBoxPreference box = (CheckBoxPreference) findPreference(key); @@ -128,11 +140,11 @@ public class LinphonePreferencesActivity extends PreferenceActivity { } private Preference findPreference(int key) { - return getPreferenceScreen().findPreference(getString(key)); + return getPreferenceManager().findPreference(getString(key)); } private void writeBoolean(int key, boolean value) { - getPreferenceManager().getSharedPreferences().edit().putBoolean(getString(key), value).commit(); + prefs().edit().putBoolean(getString(key), value).commit(); } @Override diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index df4228ddf..814b6c8cc 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -25,7 +25,6 @@ import org.linphone.LinphoneManager.NewOutgoingCallUiListener; import org.linphone.core.Hacks; import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall.State; -import org.linphone.core.LinphoneCore.EcCalibratorStatus; import org.linphone.core.LinphoneCore.GlobalState; import org.linphone.core.LinphoneCore.RegistrationState; @@ -40,7 +39,6 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Handler; import android.os.IBinder; -import android.preference.CheckBoxPreference; 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 { void onDisplayStatus(String message);