package com.example.beijing_daxing.uitls;

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

/**
 * Created by  wang 18/7/5
 */

public class SharedPreferencesUtils {
    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor edit;

    public static void init(Context context, String name) {
        sharedPreferences = context.getSharedPreferences(name, context.MODE_PRIVATE);
        edit = sharedPreferences.edit();
        edit.commit();
    }

    public static void putstring(String key, String value) {
        if (edit != null) {
            edit.putString(key, value);
            edit.commit();
        }
    }
    public static void putInt(String key, int value) {
        if (edit != null) {
            edit.putInt(key, value);
            edit.commit();
        }
    }

  public static int getInt(String key, int value) {
      if (sharedPreferences != null) {
          return sharedPreferences.getInt(key,value);
      }
      return 0;
    }


    public static void putboolean(String key, boolean value) {
        if (edit != null) {
            edit.putBoolean(key, value);
            edit.commit();
        }
    }

    /**
     * 取得方法
     */

    public static String getstring(String key, String deaflut) {
        if (sharedPreferences != null) {
            return sharedPreferences.getString(key, deaflut);
        }
        return "";
    }

    public static boolean getboolean(String key, boolean aaa) {
        if (sharedPreferences != null) {
            boolean aBoolean = sharedPreferences.getBoolean(key, aaa);
            return aBoolean;
        }
        return aaa;
    }

    /**
     * remo
     */
    public static void removeKey(String key) {
        if (edit != null) {
            edit.remove(key);
            edit.commit();
        }
    }
    public static void Clean() {
        //清空数据
        try {
            edit.clear();
            edit.commit();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
