Skip to content

Instantly share code, notes, and snippets.

@abhinav272
Created December 27, 2017 15:17
Show Gist options
  • Save abhinav272/0218da1831e60da263d1dd27d1e6ed74 to your computer and use it in GitHub Desktop.
Save abhinav272/0218da1831e60da263d1dd27d1e6ed74 to your computer and use it in GitHub Desktop.
Util for accessing Android Resources in Presenter or Model (non-Android files)
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import com.task.App;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
public class ResourcesUtil {
private static Context context = App.getContext();
private static Resources.Theme theme = App.getContext().getTheme();
public static Drawable getDrawableById(int resId) {
return SDK_INT >= LOLLIPOP ? context.getResources().getDrawable(resId, theme) :
context.getResources().getDrawable(resId);
}
public static String getString(int resId) {
return SDK_INT >= LOLLIPOP ? context.getResources().getString(resId) :
context.getResources().getString(resId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment