Started to use linphone to store settings

This commit is contained in:
Sylvain Berfini 2013-10-04 15:17:26 +02:00
parent 018c96e20e
commit 61749c28bc
6 changed files with 189 additions and 3 deletions

View file

@ -94,7 +94,6 @@
<string name="pref_stun_server_key">pref_stun_server_key</string>
<string name="pref_ice_enable_key">pref_ice_enable_key</string>
<string name="pref_video_codec_vp8_key">pref_video_codec_vp8_key</string>
<string name="pref_media_encryption_key">pref_media_encryption_key</string>
<string name="pref_media_encryption_key_none">none</string>
<string name="pref_media_encryption_key_srtp">srtp</string>
<string name="pref_media_encryption_key_zrtp">zrtp</string>
@ -121,4 +120,36 @@
<string name="pref_upnp_enable_key">pref_upnp_enable_key</string>
<string name="pref_first_time_linphone_chat_storage">pref_first_time_linphone_chat_storage</string>
<!-- LP Config bindings from Android preferences -->
<string name="pref_media_encryption_key">lpconfig_sip_media_enc_key</string>
<!-- LP Config preferences names -->
<string name="lpconfig_net_downloadbw_key">download_bw</string>
<string name="lpconfig_net_uloadbw_key">upload_bw</string>
<string-array name="lpconfig_net_keys">
</string-array>
<string name="lpconfig_sip_media_enc_key">media_encryption</string>
<string-array name="lpconfig_sip_keys">
<item>@string/lpconfig_sip_media_enc_key</item>
</string-array>
<string-array name="lpconfig_rtp_keys">
<item></item>
</string-array>
<string-array name="lpconfig_sound_keys">
<item></item>
</string-array>
<string-array name="lpconfig_video_keys">
<item></item>
</string-array>
<string-array name="lpconfig_misc_keys">
<item></item>
</string-array>
</resources>

14
res/xml/settings.xml Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/pref_preferences">
<ListPreference
android:title="@string/pref_media_encryption"
android:key="@string/pref_media_encryption_key"
android:defaultValue="@string/pref_media_encryption_default" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -289,7 +289,7 @@ public class LinphoneActivity extends FragmentActivity implements
dialerFragment = newFragment;
break;
case SETTINGS:
newFragment = new PreferencesFragment();
newFragment = new SettingsFragment();
break;
case ACCOUNT_SETTINGS:
newFragment = new AccountPreferencesFragment();

View file

@ -204,7 +204,7 @@ public class LinphoneManager implements LinphoneCoreListener {
private final String mLPConfigXsd;
private final String mLinphoneInitialConfigFile;
private final String mLinphoneRootCaFile;
private final String mLinphoneConfigFile;
public final String mLinphoneConfigFile;
private final String mRingSoundFile;
private final String mRingbackSoundFile;
private final String mPauseSoundFile;

View file

@ -0,0 +1,100 @@
package org.linphone;
/*
ChatListFragment.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.util.HashMap;
import java.util.Map;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LpConfig;
import android.content.res.Resources;
/**
* @author Sylvain Berfini
*/
public class LinphonePreferences {
private static LinphonePreferences instance;
private Map<String,String> dict, changesDict;
private LpConfig config;
public static final synchronized LinphonePreferences getInstance() {
if (instance == null) {
instance = new LinphonePreferences();
instance.Load();
}
return instance;
}
private LinphonePreferences() {
dict = new HashMap<String,String>();
changesDict = new HashMap<String,String>();
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() == null) {
config = LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile);
} else {
config = LinphoneManager.getLc().getConfig();
}
}
public String get(String key) {
if (dict.containsKey(key)) {
return dict.get(key);
}
return null;
}
public String getNew(String key) {
if (changesDict.containsKey(key)) {
return changesDict.get(key);
} else if (dict.containsKey(key)) {
return dict.get(key);
}
return null;
}
public void set(String key, String value) {
if (dict.containsKey(key)) {
if (dict.get(key) != value || value.length() == 0) {
changesDict.put(key, value);
}
} else {
changesDict.put(key, value);
}
}
public boolean hasValueChanged(String key) {
return changesDict.containsKey(key);
}
public void Load() {
Resources res = LinphoneService.instance().getResources();
for (String key : res.getStringArray(R.array.lpconfig_net_keys)) {
dict.put(key, config.getString("net", key, null));
}
}
public void Save() {
Resources res = LinphoneService.instance().getResources();
for (String key : res.getStringArray(R.array.lpconfig_net_keys)) {
if (hasValueChanged(key)) {
config.setString("net", key, getNew(key));
}
}
config.sync();
}
}

View file

@ -0,0 +1,41 @@
package org.linphone;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.ui.PreferencesListFragment;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
public class SettingsFragment extends PreferencesListFragment implements EcCalibrationListener {
@Override
public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) {
}
public SettingsFragment() {
super(R.xml.settings);
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
final LinphonePreferences prefs = LinphonePreferences.getInstance();
int count = getPreferenceScreen().getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference pref = getPreferenceScreen().getPreference(i);
if (pref.hasKey()) {
pref.setDefaultValue(prefs.get(pref.getKey()));
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
prefs.set(preference.getKey(), newValue.toString());
return true;
}
});
}
}
}
}