Binded most of video settings

This commit is contained in:
Sylvain Berfini 2013-10-15 12:06:39 +02:00
parent ed25573be2
commit 3c5d0bea3e
11 changed files with 188 additions and 652 deletions

View file

@ -11,3 +11,6 @@ keepalive_period=30000
[video] [video]
size=qvga size=qvga
[app]
sharing_server=https://www.linphone.org:444/upload.php

View file

@ -10,3 +10,6 @@ keepalive_period=30000
[video] [video]
size=qvga size=qvga
[app]
sharing_server=https://www.linphone.org:444/upload.php

View file

@ -8,6 +8,7 @@
<string name="push_sender_id">622464153529</string> <string name="push_sender_id">622464153529</string>
<string name="default_domain">sip.linphone.org</string> <string name="default_domain">sip.linphone.org</string>
<string name="default_stun">stun.linphone.org</string>
<bool name="override_domain_using_default_one">false</bool> <!-- Replace the domain for outgoing calls by the one above --> <bool name="override_domain_using_default_one">false</bool> <!-- Replace the domain for outgoing calls by the one above -->
<string name="wizard_url">https://www.linphone.org/wizard.php</string> <string name="wizard_url">https://www.linphone.org/wizard.php</string>

View file

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_tunnel_host_default"></string>
<string name="pref_tunnel_port_default">443</string>
<string name="default_tunnel_mode_entry_value">@string/tunnel_mode_entry_value_disabled</string>
<bool name="pref_echo_canceller_default">true</bool>
<!-- Audio codecs -->
<bool name="pref_codec_opus_default">true</bool>
<bool name="pref_codec_speex16_default">true</bool>
<bool name="pref_codec_speex8_default">true</bool>
<bool name="pref_codec_ilbc_default">true</bool>
<bool name="pref_codec_amr_default">false</bool>
<bool name="pref_codec_g729_default">true</bool>
<bool name="pref_codec_amrwb_default">false</bool>
<bool name="pref_codec_gsm_default">true</bool>
<bool name="pref_codec_g722_default">false</bool>
<bool name="pref_codec_silk24_default">false</bool>
<bool name="pref_codec_silk16_default">true</bool>
<bool name="pref_codec_silk8_default">false</bool>
<bool name="pref_codec_pcmu_default">true</bool>
<bool name="pref_codec_pcma_default">true</bool>
<!-- Video -->
<bool name="pref_video_enable_default">true</bool>
<bool name="pref_video_use_front_camera_default">true</bool>
<bool name="pref_video_initiate_call_with_video_default">true</bool>
<bool name="pref_video_automatically_share_my_video_default">true</bool>
<bool name="pref_video_automatically_accept_video_default">true</bool>
<!-- Preferred video size -->
<string name="pref_preferred_video_size_default">@string/pref_preferred_video_size_vga_key</string>
<!-- Video codecs -->
<bool name="pref_video_codec_vp8_default">true</bool>
<bool name="pref_video_codec_h264_default">false</bool>
<bool name="pref_video_codec_mpeg4_default">false</bool>
<bool name="pref_video_codec_h263_default">false</bool>
<!-- Network -->
<bool name="pref_wifi_only_default">false</bool>
<string name="default_stun">stun.linphone.org</string>
<bool name="pref_ice_enabled_default">false</bool>
<bool name="pref_upnp_enabled_default">false</bool>
<bool name="pref_transport_use_random_ports_default">true</bool>
<string name="pref_sip_port_default">5060</string>
<string name="pref_transport_default">@string/pref_transport_udp_key</string>
<string name="default_audio_port">7078</string>
<string name="default_video_port">9078</string>
<string name="pref_media_encryption_default">@string/pref_media_encryption_key_none</string>
<bool name="pref_push_notification_default">false</bool>
<bool name="pref_ipv6_default">false</bool>
<!-- Advanced -->
<bool name="pref_debug_default">false</bool>
<bool name="pref_animation_enable_default">false</bool>
<bool name="pref_autostart_default">false</bool>
<string name="pref_incoming_call_timeout_default">30</string>
<string name="pref_image_sharing_server_default">https://www.linphone.org:444/upload.php</string>
<string name="pref_remote_provisioning_default"></string>
<string name="pref_audio_use_specific_mode_default">0</string>
<string name="pref_expire_default">3600</string>
<string name="pref_display_name_default">Linphone Android</string>
<string name="pref_user_name_default">linphone.android</string>
<bool name="pref_auto_accept_friends_default">false</bool>
<bool name="pref_sipinfo_dtmf_default">false</bool>
<bool name="pref_rfc2833_dtmf_default">true</bool>
<bool name="pref_background_mode_default">true</bool>
</resources>

View file

@ -580,6 +580,14 @@ public class LinphoneManager implements LinphoneCoreListener {
int availableCores = Runtime.getRuntime().availableProcessors(); int availableCores = Runtime.getRuntime().availableProcessors();
Log.w("MediaStreamer : " + availableCores + " cores detected and configured"); Log.w("MediaStreamer : " + availableCores + " cores detected and configured");
mLc.setCpuCount(availableCores); mLc.setCpuCount(availableCores);
int camId = 0;
AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras();
for (AndroidCamera androidCamera : cameras) {
if (androidCamera.frontFacing == mPrefs.useFrontCam())
camId = androidCamera.id;
}
LinphoneManager.getLc().setVideoDevice(camId);
TimerTask lTask = new TimerTask() { TimerTask lTask = new TimerTask() {
@Override @Override
@ -597,7 +605,7 @@ public class LinphoneManager implements LinphoneCoreListener {
copyIfNotExist(R.raw.ringback,mRingbackSoundFile); copyIfNotExist(R.raw.ringback,mRingbackSoundFile);
copyIfNotExist(R.raw.toy_mono,mPauseSoundFile); copyIfNotExist(R.raw.toy_mono,mPauseSoundFile);
copyIfNotExist(R.raw.linphonerc_default, mLinphoneConfigFile); copyIfNotExist(R.raw.linphonerc_default, mLinphoneConfigFile);
copyFromPackage(R.raw.linphonerc, new File(mLinphoneInitialConfigFile).getName()); copyFromPackage(R.raw.linphonerc_factory, new File(mLinphoneInitialConfigFile).getName());
copyIfNotExist(R.raw.lpconfig, mLPConfigXsd); copyIfNotExist(R.raw.lpconfig, mLPConfigXsd);
copyIfNotExist(R.raw.rootca, mLinphoneRootCaFile); copyIfNotExist(R.raw.rootca, mLinphoneRootCaFile);
} }

View file

@ -333,20 +333,71 @@ public class LinphonePreferences {
// Video settings // Video settings
public boolean useFrontCam() { public boolean useFrontCam() {
return false; //TODO return getConfig().getBool("app", "front_camera_default", true);
} }
public void setFrontCamAsDefault(boolean frontcam) {
getConfig().setBool("app", "front_camera_default", frontcam);
}
public boolean isVideoEnabled() { public boolean isVideoEnabled() {
return false; //TODO return getLc().isVideoSupported() && getLc().isVideoEnabled();
}
public void enableVideo(boolean enable) {
if (enable) {
getLc().enableVideo(shouldAutomaticallyShareMyVideo(), true);
} else {
getLc().enableVideo(false, false);
}
} }
public boolean shouldInitiateVideoCall() { public boolean shouldInitiateVideoCall() {
return false; //TODO return getLc().getVideoAutoInitiatePolicy();
}
public void setInitiateVideoCall(boolean initiate) {
getLc().setVideoPolicy(initiate, shouldAutomaticallyAcceptVideoRequests());
} }
public boolean shouldAutomaticallyAcceptVideoRequests() { public boolean shouldAutomaticallyAcceptVideoRequests() {
return getLc().getVideoAutoAcceptPolicy();
}
public void setAutomaticallyAcceptVideoRequests(boolean accept) {
getLc().setVideoPolicy(shouldInitiateVideoCall(), accept);
}
public boolean shouldAutomaticallyShareMyVideo() {
return false; //TODO return false; //TODO
} }
public void setAutomaticallyShareMyVideo(boolean accept) {
//TODO
}
public String getPreferredVideoSize() {
//LinphoneCore can only return video size (width and height), not the name
return getConfig().getString("video", "size", "qvga");
}
public void setPreferredVideoSize(String preferredVideoSize) {
int bandwidth = 512 + 60;
if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_hd_key))) {
preferredVideoSize = "uxga";
bandwidth = 1024 + 60;
} else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_vga_key))) {
preferredVideoSize = "vga";
bandwidth = 512 + 60;
} else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_qvga_key))) {
preferredVideoSize = "qvga";
bandwidth = 380 + 60;
}
getLc().setPreferredVideoSizeByName(preferredVideoSize);
getLc().setUploadBandwidth(bandwidth);
getLc().setDownloadBandwidth(bandwidth);
}
// End of video settings // End of video settings
// Call settings // Call settings

View file

@ -1,554 +0,0 @@
package org.linphone;
/*
PreferencesFragment.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 static org.linphone.R.string.ec_calibrating;
import static org.linphone.R.string.pref_codec_amr_key;
import static org.linphone.R.string.pref_codec_amrwb_key;
import static org.linphone.R.string.pref_codec_ilbc_key;
import static org.linphone.R.string.pref_codec_speex16_key;
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_media_encryption_key;
import static org.linphone.R.string.pref_preferred_video_size_key;
import static org.linphone.R.string.pref_transport_key;
import static org.linphone.R.string.pref_video_enable_key;
import java.util.ArrayList;
import java.util.List;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.compatibility.Compatibility;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.MediaEncryption;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import org.linphone.setup.SetupActivity;
import org.linphone.ui.LedPreference;
import org.linphone.ui.PreferencesListFragment;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
public class PreferencesFragment extends PreferencesListFragment implements EcCalibrationListener {
private Handler mHandler = new Handler();
private Context mContext;
private Preference ecCalibratePref;
private CheckBoxPreference ecPref;
private ListPreference mencPref;
private int nbAccounts = 1;
private PreferenceCategory accounts;
private static final int WIZARD_INTENT = 1;
public PreferencesFragment() {
super(R.xml.preferences);
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
mContext = getActivity();
if (getResources().getBoolean(R.bool.hide_accounts)) {
// Hide category
PreferenceCategory accounts = (PreferenceCategory) findPreference(getString(R.string.pref_sipaccounts_key));
accounts.removeAll();
accounts.setLayoutResource(R.layout.hidden);
}
if (getResources().getBoolean(R.bool.hide_wizard) || getResources().getBoolean(R.bool.replace_wizard_with_old_interface)) {
Preference wizard = findPreference(getString(R.string.setup_key));
if (getResources().getBoolean(R.bool.replace_wizard_with_old_interface)) {
createAddAccountButton();
} else {
wizard.setLayoutResource(R.layout.hidden);
}
} else {
addWizardPreferenceButton();
}
if (getResources().getBoolean(R.bool.disable_animations)) {
uncheckDisableAndHideCheckbox(R.string.pref_animation_enable_key);
}
if (!getResources().getBoolean(R.bool.enable_linphone_friends)) {
PreferenceCategory friends = (PreferenceCategory) findPreference(getString(R.string.pref_linphone_friend_key));
friends.removeAll();
friends.setLayoutResource(R.layout.hidden);
}
EditTextPreference imageSharingServer = (EditTextPreference) findPreference(getString(R.string.pref_image_sharing_server_key));
if (getResources().getBoolean(R.bool.disable_chat)) {
imageSharingServer.setLayoutResource(R.layout.hidden);
}
if (!getResources().getBoolean(R.bool.enable_push_id)) {
findPreference(getString(R.string.pref_push_notification_key)).setLayoutResource(R.layout.hidden);
}
initializeTransportPreferences();
ecCalibratePref = findPreference(pref_echo_canceller_calibration_key);
ecCalibratePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
startEcCalibration();
return false;
}
});
ecPref = (CheckBoxPreference) findPreference(pref_echo_cancellation_key);
mencPref = (ListPreference) findPreference(pref_media_encryption_key);
boolean fastCpu = Version.hasFastCpu();
if (fastCpu) {
detectAudioCodec(pref_codec_ilbc_key, "iLBC", 8000, 1, false);
findPreference(pref_codec_speex16_key).setEnabled(true);
//findPreference(pref_codec_speex32_key)).setEnabled(enableIlbc);
}
initializeMediaEncryptionPreferences();
detectAudioCodec(pref_codec_amr_key,"AMR", 8000, 1, false);
detectAudioCodec(pref_codec_amrwb_key,"AMR-WB", 16000, 1, false);
//detectAudioCodec(R.string.pref_codec_silk8_key,"SILK",8000, 1, true);
//detectAudioCodec(R.string.pref_codec_silk12_key,"SILK",12000, 1, true);
detectAudioCodec(R.string.pref_codec_silk16_key,"SILK",16000, 1, true);
//detectAudioCodec(R.string.pref_codec_silk24_key,"SILK",24000, 1, true);
detectAudioCodec(R.string.pref_codec_g729_key,"G729",8000, 1, true);
detectAudioCodec(R.string.pref_codec_opus_key,"OPUS",48000, 1, true);
// No video
if (!Version.isVideoCapable()) {
uncheckAndDisableCheckbox(pref_video_enable_key);
} else {
if (!AndroidCameraConfiguration.hasFrontCamera()) {
uncheckDisableAndHideCheckbox(R.string.pref_video_use_front_camera_key);
}
}
initializePreferredVideoSizePreferences();
if (Hacks.hasBuiltInEchoCanceller()) {
uncheckDisableAndHideCheckbox(R.string.pref_echo_cancellation_key);
findPreference(R.string.pref_echo_canceller_calibration_key).setLayoutResource(R.layout.hidden);
}
if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
Preference prefH264 = findPreference(R.string.pref_video_codec_h264_key);
prefH264.setEnabled(false);
prefH264.setSummary(R.string.pref_video_codec_h264_unavailable);
Preference prefMPEG4 = findPreference(R.string.pref_video_codec_mpeg4_key);
prefMPEG4.setEnabled(false);
prefMPEG4.setSummary(R.string.pref_video_codec_mpeg4_unavailable);
} else {
detectVideoCodec(R.string.pref_video_codec_h264_key, "H264");
if (!Version.hasFastCpuWithAsmOptim())
{
// Android without neon doesn't support H264
Log.w("CPU does not have asm optimisations available, disabling H264");
findPreference(R.string.pref_video_codec_h264_key).setEnabled(false);
findPreference(R.string.pref_video_codec_h264_key).setDefaultValue(false);
}
}
if (Hacks.needSoftvolume()) {
Log.w("Using Audio Hack");
checkAndDisableCheckbox(R.string.pref_audio_hacks_use_galaxys_hack_key);
}
if (!LinphoneManager.getLc().isTunnelAvailable()) {
hidePreferenceCategory(R.string.pref_tunnel_key);
}
if (getResources().getBoolean(R.bool.hide_camera_settings)) {
PreferenceScreen videoSettings = (PreferenceScreen) findPreference(getString(R.string.pref_video_key));
videoSettings.removeAll();
videoSettings.setLayoutResource(R.layout.hidden);
Preference enableVideo = findPreference(R.string.pref_video_enable_key);
enableVideo.setLayoutResource(R.layout.hidden);
}
if (getResources().getBoolean(R.bool.display_about_in_settings)) {
findPreference(getString(R.string.menu_about_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayAbout();
return true;
}
return false;
}
});
} else {
findPreference(getString(R.string.menu_about_key)).setLayoutResource(R.layout.hidden);
}
final CheckBoxPreference useRandomPort = (CheckBoxPreference) findPreference(R.string.pref_transport_use_random_ports_key);
final Preference sipPort = findPreference(R.string.pref_sip_port_key);
sipPort.setEnabled(!useRandomPort.isChecked());
useRandomPort.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean isChecked = (Boolean) newValue;
sipPort.setEnabled(!isChecked);
return true;
}
});
CheckBoxPreference wifiOnly = (CheckBoxPreference) findPreference(R.string.pref_wifi_only_key);
wifiOnly.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
LinphoneManager.getInstance().updateNetworkReachability();
return true;
}
});
final CheckBoxPreference useIce = (CheckBoxPreference) findPreference(R.string.pref_ice_enable_key);
final CheckBoxPreference useUpnp = (CheckBoxPreference) findPreference(R.string.pref_upnp_enable_key);
useIce.setEnabled(!useUpnp.isChecked());
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
useUpnp.setEnabled(lc.upnpAvailable() && !useIce.isChecked());
useIce.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean isChecked = (Boolean) newValue;
useUpnp.setEnabled(!isChecked);
return true;
}
});
useUpnp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean isChecked = (Boolean) newValue;
useIce.setEnabled(!isChecked);
return true;
}
});
if (getResources().getBoolean(R.bool.disable_every_log)) {
uncheckDisableAndHideCheckbox(R.string.pref_debug_key);
}
}
private void createAddAccountButton() {
Preference addAccount = findPreference(getString(R.string.setup_key));
addAccount.setTitle(getString(R.string.pref_add_account));
addAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
nbAccounts = LinphonePreferences.instance().getAccountCount();
//LinphonePreferences.instance().setAccountCount(nbAccounts + 1);
addExtraAccountPreferencesButton(accounts, nbAccounts, true);
LinphoneActivity.instance().displayAccountSettings(nbAccounts);
nbAccounts++;
return true;
}
});
}
private void hidePreferenceCategory(int key) {
PreferenceCategory p = (PreferenceCategory) findPreference(key);
p.removeAll();
p.setLayoutResource(R.layout.hidden);
}
private synchronized void startEcCalibration() {
try {
LinphoneManager.getInstance().startEcCalibration(this);
ecCalibratePref.setSummary(ec_calibrating);
ecCalibratePref.getEditor().putBoolean(getString(pref_echo_canceller_calibration_key), false).commit();
} catch (LinphoneCoreException e) {
Log.w(e, "Cannot calibrate EC");
}
}
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
mHandler.post(new Runnable() {
public void run() {
if (status == EcCalibratorStatus.DoneNoEcho) {
ecCalibratePref.setSummary(R.string.no_echo);
ecPref.setChecked(false);
} else if (status == EcCalibratorStatus.Done) {
ecCalibratePref.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
ecPref.setChecked(true);
} else if (status == EcCalibratorStatus.Failed) {
ecCalibratePref.setSummary(R.string.failed);
ecPref.setChecked(true);
}
}
});
}
private void uncheckDisableAndHideCheckbox(int key) {
manageCheckbox(key, false, false, true);
}
private void uncheckAndDisableCheckbox(int key) {
manageCheckbox(key, false, false, false);
}
private void checkAndDisableCheckbox(int key) {
manageCheckbox(key, true, false, false);
}
private void manageCheckbox(int key, boolean value, boolean enabled, boolean hidden) {
Preference box = findPreference(key);
box.setEnabled(enabled);
Compatibility.setPreferenceChecked(box, value);
if (hidden) box.setLayoutResource(R.layout.hidden);
}
private void detectAudioCodec(int id, String mime, int rate, int channels, boolean hide) {
Log.w("Payload type for codec " + mime + " = " + LinphoneManager.getLc().findPayloadType(mime, rate, channels));
boolean enable = LinphoneService.isReady() && LinphoneManager.getLc().findPayloadType(mime, rate, channels)!=null;
Preference cb = findPreference(id);
cb.setEnabled(enable);
if (hide && !enable) {
cb.setLayoutResource(R.layout.hidden);
}
}
private void detectVideoCodec(int id, String mime) {
findPreference(id).setEnabled(LinphoneManager.getInstance().detectVideoCodec(mime));
}
private void createDynamicAccountsPreferences() {
accounts = (PreferenceCategory) findPreference(getString(R.string.pref_sipaccounts_key));
accounts.removeAll();
// Get already configured extra accounts
nbAccounts = LinphonePreferences.instance().getAccountCount();
for (int i = 0; i < nbAccounts; i++) {
// For each, add menus to configure it
addExtraAccountPreferencesButton(accounts, i, false);
}
}
public int getNbAccountsExtra() {
return nbAccounts;
}
private void addExtraAccountPreferencesButton(PreferenceCategory parent, final int n, boolean isNewAccount) {
if (isNewAccount) {
//LinphonePreferences.instance().setAccountCount(n+1);
}
final LedPreference led = new LedPreference(mContext);
String username = LinphonePreferences.instance().getAccountUsername(n);
String domain = LinphonePreferences.instance().getAccountDomain(n);
if (username == null) {
led.setTitle(getString(R.string.pref_sipaccount));
} else {
led.setTitle(username + "@" + domain);
}
led.setOnPreferenceClickListener(new OnPreferenceClickListener()
{
public boolean onPreferenceClick(Preference preference) {
LinphoneActivity.instance().displayAccountSettings(n);
return false;
}
});
updateAccountLed(led, username, domain);
parent.addPreference(led);
}
private void updateAccountLed(final LedPreference me, final String username, final String domain) {
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null) {
for (LinphoneProxyConfig lpc : LinphoneManager.getLc().getProxyConfigList()) {
if (lpc.getIdentity().contains(username) && lpc.getIdentity().contains(domain)) {
if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationOk) {
me.setLed(R.drawable.led_connected);
} else if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationFailed) {
me.setLed(R.drawable.led_error);
} else if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationProgress) {
me.setLed(R.drawable.led_inprogress);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
updateAccountLed(me, username, domain);
}
}, 1500);
} else {
me.setLed(R.drawable.led_disconnected);
}
break;
}
}
}
}
private void addWizardPreferenceButton() {
Preference wizard = findPreference(getString(R.string.setup_key));
wizard.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(mContext, SetupActivity.class);
startActivityForResult(intent, WIZARD_INTENT);
return true;
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == WIZARD_INTENT && resultCode == Activity.RESULT_OK) {
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().goToDialer();
}
}
}
private void initializeMediaEncryptionPreferences() {
LinphoneCore lc = null;
try {
lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
} catch (Exception e) {}
List<CharSequence> mencEntries=new ArrayList<CharSequence>();
List<CharSequence> mencEntryValues=new ArrayList<CharSequence>();
mencEntries.add(getString(R.string.media_encryption_none));
mencEntryValues.add(getString(R.string.pref_media_encryption_key_none));
if (lc == null || getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
CharSequence[] contents=new CharSequence[mencEntries.size()];
mencEntries.toArray(contents);
mencPref.setEntries(contents);
contents=new CharSequence[mencEntryValues.size()];
mencEntryValues.toArray(contents);
mencPref.setEntryValues(contents);
mencPref.setDefaultValue(getString(R.string.media_encryption_none));
return;
}
boolean hasZrtp = lc.mediaEncryptionSupported(MediaEncryption.ZRTP);
boolean hasSrtp = lc.mediaEncryptionSupported(MediaEncryption.SRTP);
if (!hasSrtp && !hasZrtp){
mencPref.setEnabled(false);
}else{
if (hasSrtp){
mencEntries.add(getString(R.string.media_encryption_srtp));
mencEntryValues.add(getString(R.string.pref_media_encryption_key_srtp));
}
if (hasZrtp){
mencEntries.add(getString(R.string.media_encryption_zrtp));
mencEntryValues.add(getString(R.string.pref_media_encryption_key_zrtp));
}
CharSequence[] contents=new CharSequence[mencEntries.size()];
mencEntries.toArray(contents);
mencPref.setEntries(contents);
contents=new CharSequence[mencEntryValues.size()];
mencEntryValues.toArray(contents);
mencPref.setEntryValues(contents);
mencPref.setDefaultValue(getString(R.string.media_encryption_none));
//mencPref.setValueIndex(mencPref.findIndexOfValue(getString(R.string.media_encryption_none)));
}
}
private void initializePreferredVideoSizePreferences() {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
if (Version.isHDVideoCapable()) {
entries.add(getString(R.string.pref_preferred_video_size_hd));
values.add(getString(R.string.pref_preferred_video_size_hd_key));
}
entries.add(getString(R.string.pref_preferred_video_size_vga));
values.add(getString(R.string.pref_preferred_video_size_vga_key));
entries.add(getString(R.string.pref_preferred_video_size_qvga));
values.add(getString(R.string.pref_preferred_video_size_qvga_key));
ListPreference preferredVideoSize = (ListPreference) findPreference(pref_preferred_video_size_key);
CharSequence[] content = new CharSequence[entries.size()];
entries.toArray(content);
preferredVideoSize.setEntries(content);
content = new CharSequence[values.size()];
values.toArray(content);
preferredVideoSize.setEntryValues(content);
}
private void initializeTransportPreferences() {
List<CharSequence> mencEntries=new ArrayList<CharSequence>();
List<CharSequence> mencEntryValues=new ArrayList<CharSequence>();
mencEntries.add(getString(R.string.pref_transport_udp));
mencEntryValues.add(getString(R.string.pref_transport_udp_key));
mencEntries.add(getString(R.string.pref_transport_tcp));
mencEntryValues.add(getString(R.string.pref_transport_tcp_key));
if (!getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
mencEntries.add(getString(R.string.pref_transport_tls));
mencEntryValues.add(getString(R.string.pref_transport_tls_key));
}
ListPreference transport = (ListPreference) findPreference(pref_transport_key);
CharSequence[] contents=new CharSequence[mencEntries.size()];
mencEntries.toArray(contents);
transport.setEntries(contents);
contents=new CharSequence[mencEntryValues.size()];
mencEntryValues.toArray(contents);
transport.setEntryValues(contents);
}
private Preference findPreference(int key) {
return getPreferenceManager().findPreference(getString(key));
}
@Override
public void onPause() {
super.onPause();
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().applyConfigChangesIfNeeded();
}
}
@Override
public void onResume() {
super.onResume();
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS);
}
if (!getResources().getBoolean(R.bool.hide_accounts)) {
createDynamicAccountsPreferences();
}
}
}

View file

@ -56,9 +56,8 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
//initAccounts(); Init accounts on Resume instead of on Create to update the account list when coming back from wizard //initAccounts(); Init accounts on Resume instead of on Create to update the account list when coming back from wizard
initAudioSettings(); initAudioSettings();
initVideoSettings();
initNetworkSettings(); initNetworkSettings();
initializePreferredVideoSizePreferences((ListPreference) findPreference(getString(R.string.pref_preferred_video_size_key)));
initAdvancedSettings(); initAdvancedSettings();
// Add action on About button // Add action on About button
@ -80,29 +79,12 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
return true; return true;
} }
}); });
if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
Preference prefH264 = findPreference(getString(R.string.pref_video_codec_h264_key));
prefH264.setEnabled(false);
prefH264.setSummary(R.string.pref_video_codec_h264_unavailable);
Preference prefMPEG4 = findPreference(getString(R.string.pref_video_codec_mpeg4_key));
prefMPEG4.setEnabled(false);
prefMPEG4.setSummary(R.string.pref_video_codec_mpeg4_unavailable);
} else {
if (!Version.hasFastCpuWithAsmOptim())
{
// Android without neon doesn't support H264
Log.w("CPU does not have asm optimisations available, disabling H264");
findPreference(getString(R.string.pref_video_codec_h264_key)).setEnabled(false);
findPreference(getString(R.string.pref_video_codec_h264_key)).setDefaultValue(false);
}
}
} }
// Sets listener for each preference to update the matching value in linphonecore // Sets listener for each preference to update the matching value in linphonecore
private void setListeners() { private void setListeners() {
setAudioPreferencesListener(); setAudioPreferencesListener();
setVideoPreferencesListener();
setNetworkPreferencesListener(); setNetworkPreferencesListener();
setAdvancedPreferencesListener(); setAdvancedPreferencesListener();
} }
@ -344,6 +326,7 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
values.add(getString(R.string.pref_transport_tls_key)); values.add(getString(R.string.pref_transport_tls_key));
} }
setListPreferenceValues(pref, entries, values); setListPreferenceValues(pref, entries, values);
String value = mPrefs.getTransport(); String value = mPrefs.getTransport();
pref.setSummary(value); pref.setSummary(value);
String key = getString(R.string.pref_transport_udp_key); String key = getString(R.string.pref_transport_udp_key);
@ -365,8 +348,16 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
values.add(getString(R.string.pref_preferred_video_size_vga_key)); values.add(getString(R.string.pref_preferred_video_size_vga_key));
entries.add(getString(R.string.pref_preferred_video_size_qvga)); entries.add(getString(R.string.pref_preferred_video_size_qvga));
values.add(getString(R.string.pref_preferred_video_size_qvga_key)); values.add(getString(R.string.pref_preferred_video_size_qvga_key));
setListPreferenceValues(pref, entries, values); setListPreferenceValues(pref, entries, values);
String value = mPrefs.getPreferredVideoSize();
pref.setSummary(value);
String key = getString(R.string.pref_preferred_video_size_qvga_key);
if (value.equals(getString(R.string.pref_preferred_video_size_vga)))
key = getString(R.string.pref_preferred_video_size_vga_key);
else if (value.equals(getString(R.string.pref_preferred_video_size_hd)))
key = getString(R.string.pref_preferred_video_size_hd_key);
pref.setDefaultValue(key);
} }
private static void setListPreferenceValues(ListPreference pref, List<CharSequence> entries, List<CharSequence> values) { private static void setListPreferenceValues(ListPreference pref, List<CharSequence> entries, List<CharSequence> values) {
@ -435,6 +426,110 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
}); });
} }
private void initVideoSettings() {
initializePreferredVideoSizePreferences((ListPreference) findPreference(getString(R.string.pref_preferred_video_size_key)));
PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key));
codecs.removeAll();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
for(final PayloadType pt : lc.getVideoCodecs()) {
CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
codec.setTitle(pt.getMime());
if (!pt.getMime().equals("VP8")) {
if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
continue;
} else {
if (!Version.hasFastCpuWithAsmOptim() && pt.getMime().equals("H264"))
{
// Android without neon doesn't support H264
Log.w("CPU does not have asm optimisations available, disabling H264");
continue;
}
}
}
codec.setChecked(lc.isPayloadTypeEnabled(pt));
codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
try {
LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
return true;
}
});
codecs.addPreference(codec);
}
((CheckBoxPreference) findPreference(getString(R.string.pref_video_enable_key))).setChecked(mPrefs.isVideoEnabled());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_use_front_camera_key))).setChecked(mPrefs.useFrontCam());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_initiate_call_with_video_key))).setChecked(mPrefs.shouldInitiateVideoCall());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_share_my_video_key))).setChecked(mPrefs.shouldAutomaticallyShareMyVideo());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_accept_video_key))).setChecked(mPrefs.shouldAutomaticallyAcceptVideoRequests());
}
private void setVideoPreferencesListener() {
findPreference(getString(R.string.pref_video_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.enableVideo(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_use_front_camera_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setFrontCamAsDefault(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_initiate_call_with_video_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setInitiateVideoCall(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_automatically_share_my_video_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setAutomaticallyShareMyVideo(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_automatically_accept_video_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setAutomaticallyAcceptVideoRequests(enable);
return true;
}
});
findPreference(getString(R.string.pref_preferred_video_size_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setPreferredVideoSize(newValue.toString());
preference.setSummary(mPrefs.getPreferredVideoSize());
return true;
}
});
}
private void initNetworkSettings() { private void initNetworkSettings() {
initMediaEncryptionPreference((ListPreference) findPreference(getString(R.string.pref_media_encryption_key))); initMediaEncryptionPreference((ListPreference) findPreference(getString(R.string.pref_media_encryption_key)));
initializeTransportPreferences((ListPreference) findPreference(getString(R.string.pref_transport_key))); initializeTransportPreferences((ListPreference) findPreference(getString(R.string.pref_transport_key)));

@ -1 +1 @@
Subproject commit fc61fbd1aab9d5cf715682bd16d30399df46da48 Subproject commit 08c59397cbb5e34786f6cfb8187675ad501929ea