Skip to content
Stanislav Koshutsky edited this page Mar 9, 2017 · 4 revisions

This intended to help you to access any resources from any class/instance at runtime. As you know you only have access to resources from the Context, but when you have to get some dimension or resource inside a class which has no access to Context (not a View, Fragment, Activity, Application etc) it becomes tricky. This class, being initialized with Application Context (or by global Initializer) will help you in such cases. Also it wraps out methods which are deprecated so your code will not have Lint warnings for it. Also the resources access is more simple cuz you don't have to call it like context.getResources().getDimension() but ResHelper.getDimension() instead. It was created a bit before ContextCompat came out. Also its not applicable at design time for custom views.

public static String getString(final int resId)

public static String getString(final int resId, final Object... args) 

public static String[] getStringArray(final int arrayResId)  

public static String getQuantityString(final int resId, final int quantity)  

public static String getQuantityString(final int resId, final int quantity, Object... formatArgs)  

public static Drawable getDrawable(final int resId) 

public static int getColor(final int colorResId) 

public static float getDimension(final int dimensResId)  

public static int getDimensPx(final int dimensResId)  

public static DisplayMetrics getDisplayMetrics()  

public static int getInteger(final int intResId)  

public static boolean getBoolean(final int booleanResId)  

public static int[] getIntArray(final int arrayResId)  

public static int getIdentifier(final String name, final String defType, final String defPackage)  

public static InputStream openRawResource(final int rawResId)  

public static int getResId(final String resName, final Class<?> c)  

public static boolean isResourceAvailable(int resId)  

Clone this wiki locally