Skip to content

Instantly share code, notes, and snippets.

@kakai248
Created January 19, 2018 16:51
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakai248/ae13648d97f14d210557809b74f2f8b0 to your computer and use it in GitHub Desktop.
Save kakai248/ae13648d97f14d210557809b74f2f8b0 to your computer and use it in GitHub Desktop.
public class ResourceProvider {
private final Context context;
@Inject
public ResourceProvider(Context context) {
this.context = context;
}
@NonNull
public CharSequence getText(@StringRes int resId) {
return context.getText(resId);
}
@NonNull
public CharSequence[] getTextArray(@ArrayRes int resId) {
return context.getResources().getTextArray(resId);
}
@NonNull
public CharSequence getQuantityText(@PluralsRes int resId, int quantity) {
return context.getResources().getQuantityText(resId, quantity);
}
@NonNull
public String getString(@StringRes int resId) {
return context.getString(resId);
}
@NonNull
public String getString(@StringRes int resId, Object... formatArgs) {
return context.getString(resId, formatArgs);
}
@NonNull
public String[] getStringArray(@ArrayRes int resId) {
return context.getResources().getStringArray(resId);
}
@NonNull
public String getQuantityString(@PluralsRes int resId, int quantity) {
return context.getResources().getQuantityString(resId, quantity);
}
@NonNull
public String getQuantityString(@PluralsRes int resId, int quantity, Object... formatArgs) {
return context.getResources().getQuantityString(resId, quantity, formatArgs);
}
public int getInteger(@IntegerRes int resId) {
return context.getResources().getInteger(resId);
}
@NonNull
public int[] getIntArray(@ArrayRes int resId) {
return context.getResources().getIntArray(resId);
}
public boolean getBoolean(@BoolRes int resId) {
return context.getResources().getBoolean(resId);
}
public float getDimension(@DimenRes int resId) {
return context.getResources().getDimension(resId);
}
public int getDimensionPixelSize(@DimenRes int resId) {
return context.getResources().getDimensionPixelSize(resId);
}
public int getDimensionPixelOffset(@DimenRes int resId) {
return context.getResources().getDimensionPixelOffset(resId);
}
public Drawable getDrawable(@DrawableRes int resId) {
return ContextCompat.getDrawable(context, resId);
}
@ColorInt
public int getColor(@ColorRes int resId) {
return ContextCompat.getColor(context, resId);
}
public ColorStateList getColorStateList(@ColorRes int resId) {
return ContextCompat.getColorStateList(context, resId);
}
@Nullable
public Typeface getFont(@FontRes int id) throws Resources.NotFoundException {
return ResourcesCompat.getFont(context, id);
}
public Animation loadAnimation(@AnimRes int id) {
return AnimationUtils.loadAnimation(context, id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment