package com.hgsoft.debuglogshow;

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

import java.io.Closeable;
import java.io.IOException;

public class DebugUtil {

    static String mainPid = String.valueOf(android.os.Process.myPid());

    static boolean close(Closeable closeable) {
        if (closeable != null)
            try {
                closeable.close();
                return true;
            } catch (IOException e) {}
        return false;
    }


    protected static String getSetting(Context context, String key, String defaultValue) {
        try {
            SharedPreferences sharedata = context.getSharedPreferences("logEndsWith", 0);
            return sharedata.getString(key, defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return defaultValue;
    }


    protected static void saveSetting(Context context, String key, String value) {
        try {
            SharedPreferences.Editor sharedata = context.getSharedPreferences("logEndsWith", 0).edit();
            sharedata.putString(key, value);
            sharedata.apply();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
