gt: 		return gPrefStringValue(prefs, key);
context: /**
   * Copyright (C) 2010 Regis Montoya (aka r3gis - www.r3gis.fr)
   * This file is part of CSipSimple.
   *
   *  CSipSimple 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 3 of the License, or
   *  (at your option) any later version.
   *
   *  CSipSimple 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 CSipSimple.  If not, see <http://www.gnu.org/licenses/>.
   */
  package com.csipsimple.utils;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.regex.Pattern;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.content.ContentResolver;
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.os.Environment;
  import android.preference.PreferenceManager;
  import android.provider.Settings;
  import android.text.TextUtils;
  
  import com.csipsimple.api.SipConfigManager;
  import com.csipsimple.ui.SipHome;
  
  
  public class PreferencesWrapper {
  	
  	//Internal use
  	public static final String HAS_BEEN_QUIT = "has_been_quit";
  	public static final String IS_ADVANCED_USER = "is_advanced_user";
  	public static final String HAS_ALREADY_SETUP = "has_already_setup";
  	public static final String HAS_ALREADY_SETUP_SERVICE = "has_already_setup_service";
  	
  	
  	private static final String THIS_FILE = "PreferencesWrapper";
  	private SharedPreferences prefs;
  	private ContentResolver resolver;
  	private Context context;
  
  	
  	
  	public final static HashMap<String, String> STRING_PREFS = new HashMap<String, String>(){
  		private static final long serialVersionUID = 1L;
  	{
  		
  		put(SipConfigManager.USER_AGENT, CustomDistribution.getUserAgent());
  		put(SipConfigManager.LOG_LEVEL, "1");
  		
  		put(SipConfigManager.USE_SRTP, "0");
  		put(SipConfigManager.USE_ZRTP, "1"); /* 1 is no zrtp */
  		put(SipConfigManager.UDP_TRANSPORT_PORT, "0");
  		put(SipConfigManager.TCP_TRANSPORT_PORT, "0");
  		put(SipConfigManager.TLS_TRANSPORT_PORT, "0");
  		put(SipConfigManager.KEEP_ALIVE_INTERVAL_WIFI, "80");
  		put(SipConfigManager.KEEP_ALIVE_INTERVAL_MOBILE, "40");
  		put(SipConfigManager.RTP_PORT, "4000");
  		put(SipConfigManager.OVERRIDE_NAMESERVER, "");
  		put(SipConfigManager.TIMER_MIN_SE, "90");
  		put(SipConfigManager.TIMER_SESS_EXPIRES, "1800");
  		
  		put(SipConfigManager.SND_AUTO_CLOSE_TIME, "1");
  		put(SipConfigManager.ECHO_CANCELLATION_TAIL, "200");
  		put(SipConfigManager.ECHO_MODE, "3"); /* WEBRTC */
  		put(SipConfigManager.SND_MEDIA_QUALITY, "4");
  		put(SipConfigManager.SND_CLOCK_RATE, "16000");
  		put(SipConfigManager.SND_PTIME, "20");
  		put(SipConfigManager.BITS_PER_SAMPLE, "16");
  		put(SipConfigManager.SIP_AUDIO_MODE, "0");
  		put(SipConfigManager.MICRO_SOURCE, "1");
  		//put(SipConfigManager.THREAD_COUNT, "0");
  		put(SipConfigManager.HEADSET_ACTION, "0");
  		
  		put(SipConfigManager.STUN_SERVER, "stun.counterpath.com");
  		put(SipConfigManager.TURN_SERVER, "");
  		put(SipConfigManager.TURN_USERNAME, "");
  		put(SipConfigManager.TURN_PASSWORD, "");
  		put(SipConfigManager.TLS_SERVER_NAME, "");
  		put(SipConfigManager.CA_LIST_FILE, "");
  		put(SipConfigManager.CERT_FILE, "");
  		put(SipConfigManager.PRIVKEY_FILE, "");
  		put(SipConfigManager.TLS_PASSWORD, "");
  		put(SipConfigManager.TLS_METHOD, "0");
  		
  		put(SipConfigManager.DSCP_VAL, "26");
  		put(SipConfigManager.DTMF_MODE, "0");
  		
  
  		put(SipConfigManager.GSM_INTEGRATION_TYPE, "0");
  		put(SipConfigManager.DIAL_PRESS_TONE_MODE, "0");
  		put(SipConfigManager.DIAL_PRESS_VIBRATE_MODE, "0");
  		
  		put(SipConfigManager.DEFAULT_CALLER_ID, "");
  		put(SipConfigManager.THEME, "");
  		put(SipConfigManager.RINGTONE, "");
  		
  		
  	}};
  	
  	
  	private final static HashMap<String, Boolean> BOOLEAN_PREFS = new HashMap<String, Boolean>(){
  		private static final long serialVersionUID = 1L;
  	{
  		//Network
  		put(SipConfigManager.LOCK_WIFI, true);
  		put(SipConfigManager.LOCK_WIFI_PERFS, false);
  		put(SipConfigManager.ENABLE_TCP, true);
  		put(SipConfigManager.ENABLE_UDP, true);
  		put(SipConfigManager.ENABLE_TLS, false);
  		put(SipConfigManager.USE_IPV6, false);
  		put(SipConfigManager.ENABLE_DNS_SRV, false);
  		put(SipConfigManager.ENABLE_ICE, false);
  		put(SipConfigManager.ENABLE_TURN, false);
  		put(SipConfigManager.ENABLE_STUN, false);
  		put(SipConfigManager.ENABLE_QOS, false);
  		put(SipConfigManager.USE_COMPACT_FORM, false);
  		put("use_wifi_in", true);
  		put("use_wifi_out", true);
  		put("use_other_in", true);
  		put("use_other_out", true);
  		put("use_3g_in", false);
  		put("use_3g_out", false);
  		put("use_gprs_in", false);
  		put("use_gprs_out", false);
  		put("use_edge_in", false);
  		put("use_edge_out", false);
  		put(SipConfigManager.FORCE_NO_UPDATE, true);
  		
  		
  		//Media
  		put(SipConfigManager.ECHO_CANCELLATION, true);
  		put(SipConfigManager.ENABLE_VAD, false);
  		put(SipConfigManager.USE_SOFT_VOLUME, false);
  		put(SipConfigManager.USE_ROUTING_API, false);
  		put(SipConfigManager.USE_MODE_API, false);
  		put(SipConfigManager.HAS_IO_QUEUE, false);
  		put(SipConfigManager.SET_AUDIO_GENERATE_TONE, false);
  		put(SipConfigManager.USE_SGS_CALL_HACK, false);
  		put(SipConfigManager.USE_WEBRTC_HACK, false);
  		put(SipConfigManager.DO_FOCUS_AUDIO, true);
  		put(SipConfigManager.INTEGRATE_WITH_NATIVE_MUSIC, true);
  		
  		//UI
  		put(SipConfigManager.PREVENT_SCREEN_ROTATION, true);
  		put(SipConfigManager.KEEP_AWAKE_IN_CALL, false);
  		put(SipConfigManager.INVERT_PROXIMITY_SENSOR, false);
  		put(SipConfigManager.ICON_IN_STATUS_BAR, true);
  		put(SipConfigManager.USE_PARTIAL_WAKE_LOCK, false);
  		put(SipConfigManager.ICON_IN_STATUS_BAR_NBR, false);
  		put(SipConfigManager.INTEGRATE_WITH_CALLLOGS, true);
  		put(SipConfigManager.INTEGRATE_WITH_DIALER, true);
  		put(HAS_BEEN_QUIT, false);
  		put(HAS_ALREADY_SETUP_SERVICE, false);
  		
  		//Calls
  		put(SipConfigManager.AUTO_RECORD_CALLS, false);
  		put(SipConfigManager.SUPPORT_MULTIPLE_CALLS, false);
  		
  		//Secure
  		put(SipConfigManager.TLS_VERIFY_SERVER, false);
  		put(SipConfigManager.TLS_VERIFY_CLIENT, false);
  		
  	}};
  	
  	private final static HashMap<String, Float> FLOAT_PREFS = new HashMap<String, Float>(){
  		private static final long serialVersionUID = 1L;
  	{
  		put(SipConfigManager.SND_MIC_LEVEL, (float)1.0);
  		put(SipConfigManager.SND_SPEAKER_LEVEL, (float)1.0);
  		put(SipConfigManager.SND_BT_MIC_LEVEL, (float)1.0);
  		put(SipConfigManager.SND_BT_SPEAKER_LEVEL, (float)1.0);
  		put(SipConfigManager.SND_STREAM_LEVEL, (float)8.0);
  	}};
  	
  	
  	public PreferencesWrapper(Context aContext) {
  		context = aContext;
  		prefs = PreferenceManager.getDefaultSharedPreferences(aContext);
  		resolver = aContext.getContentResolver();
  		
  	}
  	
  
  	//Public setters
  	/**
  	 * Set a preference string value
  	 * @param key the preference key to set
  	 * @param value the value for this key
  	 */
  	public void setPreferenceStringValue(String key, String value) {
  		//TODO : authorized values
  		Editor editor = prefs.edit();
  		editor.putString(key, value);
  		editor.commit();
  	}
  	
  	/**
  	 * Set a preference boolean value
  	 * @param key the preference key to set
  	 * @param value the value for this key
  	 */
  	public void setPreferenceBooleanValue(String key, boolean value) {
  		Editor editor = prefs.edit();
  		editor.putBoolean(key, value);
  		editor.commit();
  	}
  	
  	/**
  	 * Set a preference float value
  	 * @param key the preference key to set
  	 * @param value the value for this key
  	 */
  	public void setPreferenceFloatValue(String key, float value) {
  		Editor editor = prefs.edit();
  		editor.putFloat(key, value);
  		editor.commit();
  		Log.d(THIS_FILE, "Changed value of "+key+" : "+value);
  	}
  	
  	//Private static getters
  	// For string
  	private static String gPrefStringValue(SharedPreferences aPrefs, String key) {
  		if(STRING_PREFS.containsKey(key)) {
  			return aPrefs.getString(key, STRING_PREFS.get(key));
  		}
  		return aPrefs.getString(key, (String) null);
  	}
  	
  	// For boolean
  	private static Boolean gPrefBooleanValue(SharedPreferences aPrefs, String key) {
  		if(BOOLEAN_PREFS.containsKey(key)) {
  			return aPrefs.getBoolean(key, BOOLEAN_PREFS.get(key));
  		}
  		return aPrefs.getBoolean(key, (Boolean) null);
  	}
  	
  	// For float
  	private static Float gPrefFloatValue(SharedPreferences aPrefs, String key) {
  		if(FLOAT_PREFS.containsKey(key)) {
  			return aPrefs.getFloat(key, FLOAT_PREFS.get(key));
  		}
  		return aPrefs.getFloat(key, (Float) null) ;
  	}
  	
  	public static Class<?> gPrefClass(String key) {
  		if(STRING_PREFS.containsKey(key)) {
  			return String.class;
  		}else if(BOOLEAN_PREFS.containsKey(key)) {
  			return Boolean.class;
  		}else if(FLOAT_PREFS.containsKey(key)) {
  			return Float.class;
  		}
  		return null;
  	}
  	
  	/**
  	 * Get string preference value
  	 * @param key the key preference to retrieve
  	 * @return the value
  	 */
  	public String getPreferenceStringValue(String key) {
  