翰林优商.apk(点击下载) / SdkSharedPreferences.java


package com.sjm.sjmdsp.core.config;

import android.content.Context;
import android.content.SharedPreferences;
import com.sjm.sjmdsp.core.init.DspInit;

public class SdkSharedPreferences {
    private static final String SharedPreferencesTag = "HZ_sjm_DSP_Config";
    private static SdkSharedPreferences instance;
    Context context;
    private SharedPreferences share;

    private SdkSharedPreferences(Context context2) {
        this.context = context2;
    }

    public static void setString(Context context2, String str, String str2) {
        shared(context2).setValueWhitKey(str, str2);
    }

    public static String getString(Context context2, String str) {
        return shared(context2).getValueWhitKey(str);
    }

    public static SdkSharedPreferences shared(Context context2) {
        if (instance == null) {
            synchronized (DspInit.class) {
                if (instance == null) {
                    instance = new SdkSharedPreferences(context2);
                }
            }
        }
        return instance;
    }

    public void setValueWhitKey(String str, String str2) {
        if (str != null) {
            SharedPreferences.Editor edit = getShare(this.context).edit();
            if (str2 == null) {
                str2 = "";
            }
            edit.putString(str, str2);
            edit.commit();
        }
    }

    public String getValueWhitKey(String str) {
        try {
            return getShare(this.context).getString(str, "");
        } catch (Exception unused) {
            return null;
        }
    }

    private SharedPreferences getShare(Context context2) {
        if (this.share == null && context2 != null) {
            try {
                this.share = context2.getSharedPreferences(SharedPreferencesTag, 0);
            } catch (Exception unused) {
            }
        }
        return this.share;
    }
}