package com.sunzee.utils;

import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;

import com.sunzee.base.BaseApplication;

import java.lang.reflect.Field;

/**
 * 获取字符串、颜色
 */
public class UiUtil {

    public static String getStringRes(int id) {
        return BaseApplication.getContext().getResources().getString(id);
    }

    public static int getColorRes(int id) {
        return ContextCompat.getColor(BaseApplication.getContext(), id);
    }

    public static String[] getStringArrayRes(int id) {
        return BaseApplication.getContext().getResources().getStringArray(id);
    }

    public static Drawable getDrawableRes(int id) {
        return BaseApplication.getContext().getResources().getDrawable(id);
    }

    public static float getDimensionRes(int id) {
        return BaseApplication.getContext().getResources().getDimension(id);
    }

    public static int getResId(String variableName, Class<?> c) {
        try {
            Field idField = c.getDeclaredField(variableName);
            return idField.getInt(idField);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
}
