package cn.net.caoyao.cpzshandset.common.util;

import android.content.Context;
import android.content.SharedPreferences;

public class CacheGet {

	public int getCacheIntegerG(Context context, String cacheName, String key) {
		return getCacheInteger(context, cacheName, key);
	}

	public String getCacheStringG(Context context, String cacheName, String key) {
		return getCacheString(context, cacheName, key);
	}

	public long getCacheLongG(Context context, String cacheName, String key) {
		return getCacheLong(context, cacheName, key);
	}

	public boolean getCacheBooleanG(Context context, String cacheName, String key,boolean defaultValue) {
		return getCacheBoolean(context, cacheName, key,defaultValue);
	}

	// 取出cacheName中Key字段对应的int类型的值
	private int getCacheInteger(Context context, String cacheName, String key) {
		SharedPreferences sp = (SharedPreferences) context.getSharedPreferences(cacheName, Context.MODE_PRIVATE);
		int receive = sp.getInt(key, 0);// 如果该字段没对应值，则取出0
		return receive;
	}

	// 取出cacheName中Key字段对应的String类型的值
	private String getCacheString(Context context, String cacheName, String key) {
		SharedPreferences sp = (SharedPreferences) context.getSharedPreferences(cacheName, Context.MODE_PRIVATE);
		String receive = sp.getString(key, "");// 如果该字段没对应值，则取出0
		return receive;
	}

	// 取出cacheName中Key字段对应的long类型的值
	private long getCacheLong(Context context, String cacheName, String key) {
		SharedPreferences sp = (SharedPreferences) context.getSharedPreferences(cacheName, Context.MODE_PRIVATE);
		long receive = sp.getLong(key, 0000000000);// 如果该字段没对应值，则取出0000000000
		return receive;
	}

	// 取出cacheName中Key字段对应的Boolean类型的值
	private boolean getCacheBoolean(Context context, String cacheName, String key, boolean defaultValue) {
		SharedPreferences sp = (SharedPreferences) context.getSharedPreferences(cacheName, Context.MODE_PRIVATE);
		boolean receive = sp.getBoolean(key, defaultValue);// 如果该字段没对应值，则取出false
		return receive;
	}
}
