package com.backfire.doudizhu.common;


import android.content.SharedPreferences;

/**
 * 
 * 
 * @author wf
 * 
 */
public class ShareData {
	private final String SETTINGS_NAME = "SHARE";
	private static ShareData mShareData = new ShareData();
	public final byte[] _writeLock = new byte[0]; 

	private ShareData() {

	}

	public static ShareData getInstance() {
		return mShareData;
	}
	
	
	public void  saveIntValue(String name ,int value)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return ;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			settings.edit().putInt(name, value).commit();
		}
	}
	public int getIntValue(String name,int defaultValue)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return defaultValue;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			return settings.getInt(name, defaultValue);
		}
	}
	public void  saveLongValue(String name ,long value)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return ;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			settings.edit().putLong(name, value).commit();
		}
	}
	public long getLongValue(String name,int defaultValue)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return defaultValue;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			return settings.getLong(name, defaultValue);
		}
	}
	public void  saveStringValue(String name ,String value)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return ;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			settings.edit().putString(name, value).commit();
		}
	}
	public String getStringValue(String name,String defaultValue)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return defaultValue;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			return settings.getString(name, defaultValue);
		}
	}
	public void  saveBooleanValue(String name ,Boolean value)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return ;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			settings.edit().putBoolean(name, value).commit();
		}
	}
	public Boolean getBooleanValue(String name,Boolean defaultValue)
	{
		synchronized (_writeLock) {
			if(name==null || name.equals(""))return defaultValue;
			SharedPreferences settings = DdzApplication.getApplication()
				.getSharedPreferences(SETTINGS_NAME, 0);
			return settings.getBoolean(name, defaultValue);
		}
	}
	
	
}
