Kite

Android Resource Wrapper Library.

TLDR

Fed up with typing ContextCompact, resources and context all over your apps to access your resources? Say no more.

implementation 'com.cioccarellia:kite:1.0.0'
  • :kite: Access all app resources with one unified syntax.
  • :dna: Null safe layer between the Android framework java code and your app.
  • :ice_cube: Transparent and lightweight wrapper.
  • :lock: Extensive built-in checks.
  • :zap: Easy to implement in existing apps.
  • :heart: Kotlin powered, 100%.

Usage

Initialize the kite global object (ideally inside your Application class) and pass to it the application context.

class App : Application() {

    companion object {
        lateinit var appContext: Context
        val kite by lazy { Kite.fly(appContext) }
    }

    override fun onCreate() {
        super.onCreate()
        appContext = this
    }
}

You're all set. Simply import the kite object, select what you want to use and access it with the bracket notation [].

// Kite
fab.rippleColor =         kite.color[R.color.md_light_lime]
fab.backgroundTintList =  kite.colorStateList[R.color.md_lime]
fab.text =                kite.string[R.string.ride]

// Standard
fab.rippleColor =         ContextCompact.getColor(appContext, R.color.md_light_lime)
fab.backgroundTintList =  ColorStateList.valueOf(R.color.md_lime)
fab.text =                appContext.getString(R.string.ride)

Supported Resources

Resource Type AAPT class Namespace Input Output Implementation API Variants
Strings R.string Kite.string @StringRes string: Int String Context.getString() / formatArgs
Plurals R.plurals Kite.plural @PluralRes plural: Int, quantity: Int String Resources.getQuantityString() / formatArgs
Texts R.string Kite.text @StringRes text: Int CharSequence Context.getText() / /
Color R.color Kite.color @ColorRes color: Int @ColorInt Color ContextCompat.getColor() / /
ColorStateLists R.color Kite.colorStateList @ColorRes colorStateList: Int ColorStateList ContextCompat.getColorStateList() / /
Drawables R.drawable Kite.drawable @DrawableRes drawable: Int Drawable ContextCompat.getDrawable() / Resources.Theme?
Layouts R.layout Kite.layout @LayoutRes layout: Int XmlResourceParser Resources.getLayout() / /
Integer R.integer Kite.integer @IntegerRes integer: Int Int Resources.getInteger() / /
Booleans R.bool Kite.booleans @BoolRes boolean: Int Boolean Resources.getBoolean() / /
Dimensions R.dimen Kite.dimension @DimenRes dimensions: Int Float Resources.getDimensions() / /
Fractions R.fraction Kite.fraction @FractionRes fraction: Int, base: Int, pbase: Int Float Resources.getFraction() / /
Fonts R.font Kite.font @FontRes font: Int Typeface Resources.getFont() 26 /
Animations R.anim Kite.animation @AnimRes animation: Int Animation AnimationUtils.loadAnimation() / /
Interpolators R.interpolator Kite.interpolation @InterpolatorRes interpolator: Int Interpolator AnimationUtils.loadInterpolator() / /
IntArray R.array Kite.intArray @ArrayRes intArray: Int IntArray Resources.getIntArray() / /
StringArray R.array Kite.stringArray @ArrayRes stringArray: Int Array<out String> Resources.getStringArray() / /
TypedArray R.array Kite.typedArray @ArrayRes typedArray: Int TypedArray Resources.obtainTypedArray() / /
Identifiers R.id Kite.identifier name: String, defType: String, defPackage: String Int Resources.getIdentifier() / /
Xmls R.xml Kite.xml @XmlRes xml: Int XmlResourceParser Resources.getXml() / /
Raws R.raw Kite.raw @RawRes raw: Int InputStream Resources.openRawResource() / TypedValue

GitHub