Skip to content

Instantly share code, notes, and snippets.

@saurabhthorat
Created October 14, 2019 05:02
Show Gist options
  • Save saurabhthorat/dcf935502aa97abc2c318db0857b5930 to your computer and use it in GitHub Desktop.
Save saurabhthorat/dcf935502aa97abc2c318db0857b5930 to your computer and use it in GitHub Desktop.
import android.content.Context
import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.IntegerRes
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
class ResourceProvider(val context: Context) {
inline fun getText(@StringRes resId: Int): CharSequence = context.getText(resId)
inline fun getString(@StringRes resId: Int): String = context.getString(resId)
inline fun getInteger(@IntegerRes resId: Int) = context.resources.getInteger(resId)
inline fun getDrawable(@DrawableRes resId: Int): Drawable? = ContextCompat.getDrawable(context, resId)
inline fun getColor(@ColorRes resId: Int) = ContextCompat.getColor(context, resId)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment