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


package com.zj.zjsdk.utils;

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

public class SPUtil {
    private static final String a = ("ZjSdk" + "_Config");
    private static SPUtil c = null;
    private SharedPreferences b;

    private SPUtil(Context context) {
        a(context);
    }

    private void a(Context context) {
        if (this.b == null && context != null) {
            try {
                this.b = context.getSharedPreferences(a, 0);
            } catch (Throwable unused) {
            }
        }
    }

    public static SPUtil instance(Context context) {
        if (c == null) {
            c = new SPUtil(context);
        }
        return c;
    }

    public int getIntValueWhitKey(String str) {
        return getIntValueWhitKey(str, 0);
    }

    public int getIntValueWhitKey(String str, int i) {
        try {
            return this.b.getInt(str, i);
        } catch (Throwable unused) {
            return i;
        }
    }

    public String getStringValue(String str, String str2) {
        try {
            return this.b.getString(str, str2);
        } catch (Throwable unused) {
            return str2;
        }
    }

    public void setIntValueWhitKey(String str, int i) {
        if (str != null) {
            try {
                SharedPreferences.Editor edit = this.b.edit();
                edit.putInt(str, i);
                edit.apply();
            } catch (NullPointerException unused) {
            }
        }
    }

    public void setStringValue(String str, String str2) {
        if (str != null) {
            try {
                SharedPreferences.Editor edit = this.b.edit();
                edit.putString(str, str2);
                edit.apply();
            } catch (NullPointerException unused) {
            }
        }
    }
}