Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🪁 Android Resources Wrapper Library

License

NotificationsYou must be signed in to change notification settings

cioccarellia/kite

Repository files navigation

Kite

Android Resource Wrapper Library.

Download from MavenCentralAndroid ArsenalCircleCIAndroid CICodacyKotlinAndroid Min SdkAndroid Compile VersionLicense

TLDR

Fed up with typingContextCompat,resources andcontext all over your apps to access your resources? Say no more.

Gradle
dependencies {    implementation'com.github.cioccarellia:kite:1.2.1'}
Kotlin DSL
dependencies {    implementation("com.github.cioccarellia:kite:1.2.1")}
Maven
<dependency>    <groupId>com.github.cioccarellia</groupId>    <artifactId>kite</artifactId>    <version>1.2.1</version>    <type>pom</type></dependency>
  • 🪁 Access all app resources with one unified syntax.
  • 🧬 Null safe layer between the Android framework java code and your app.
  • 🧊 Transparent and lightweight wrapper.
  • 🔒 Extensive built-in checks.
  • ⚡ Easy to implement in existing apps.
  • ❤️ Kotlin powered, 100%.
val text=Kite.string[R.string.welcome_back]

Usage

Kite is a handy and lightweight android library which aims at reducing redundancy and decreasing android code complexity.It encloses and simplifies resource access within the Kite domain, and abstracts away the implementation logic needed to fetch the desired value, making interactions with the android framework smooth and frictionless.To get started initialize kite (ideally inside yourApplication class) and pass to it the application context.

classApp :Application() {overridefunonCreate() {super.onCreate()Kite.fly(this)    }}

You're all set. You can now import theKite object, select whichever resource category you want to access and fetch it using the resource id and the bracket notation[].

Beware: kite can not andwill not save you from the mess that is dealing with AndroidContext.After all, kite is some cleverly placed syntactic sugar over those same android methods you are used to: kite itself holds a reference toContext.It will, however, unify and thoroughly uniform your experience with dealing with all android related resource extraction operations, which can turn to be extremely practical.It may also save you from typing againContextCompat in your life. That's the precise reason kite was created.

Samples

// 🪁 Kitefab.rippleColor=Kite.color[R.color.md_light_lime]fab.backgroundTintList=Kite.colorStateList[R.color.md_lime]fab.text=Kite.string[R.string.unread_notifications,"69"]fab.isVisible=Kite.bools[R.bool.show_fab]// Standardfab.rippleColor=ContextCompat.getColor(context,R.color.md_light_lime)fab.backgroundTintList=ColorStateList.valueOf(R.color.md_lime)fab.text=                appContext.getString(R.string.unread_notifications,"69")fab.isVisible=           resources.getBoolean(R.bool.show_fab)

Context Switching

One clear disadvantage to using kite with respect to doing things the old way is choosing which context to use.That's why Kite comes packed with extension functions for permanent change / temporary switch the in-use context, so that you have full control over which context is used to do what.

  • runWith can be invoked on anyKiteFetcher object, it is chainable and it temporarily runs the passed lambda in the desired context.
Kite.color.runWith(this) { color->    button.setBackground(        color[R.color.colorAccent]    )}

Supported Resources

Kite delegates resource collection toKiteFetchers. Those classes contain a well defined implementation of the actual process of converting the givenid to the output type.

Resource TypeAAPT classFetcherInputOutputImplementationAPIVariants
StringsR.stringKite.string@StringRes string: IntStringContext.getString()/formatArgs
PluralsR.pluralsKite.plural@PluralRes plural: Int,quantity: IntStringResources.getQuantityString()/formatArgs
TextsR.stringKite.text@StringRes text: IntCharSequenceContext.getText()//
ColorR.colorKite.color@ColorRes color: Int@ColorInt ColorContextCompat.getColor()//
ColorStateListsR.colorKite.colorStateList@ColorRes colorStateList: IntColorStateListContextCompat.getColorStateList()//
DrawablesR.drawableKite.drawable@DrawableRes drawable: IntDrawableContextCompat.getDrawable()/Resources.Theme?
LayoutsR.layoutKite.layout@LayoutRes layout: IntXmlResourceParserResources.getLayout()//
IntegerR.integerKite.integer@IntegerRes integer: IntIntResources.getInteger()//
BooleansR.boolKite.booleans@BoolRes boolean: IntBooleanResources.getBoolean()//
DimensionsR.dimenKite.dimension@DimenRes dimensions: IntFloatResources.getDimensions()//
FractionsR.fractionKite.fraction@FractionRes fraction: Int,base: Int,pbase: IntFloatResources.getFraction()//
FontsR.fontKite.font@FontRes font: IntTypefaceResources.getFont()26/
AnimationsR.animKite.animation@AnimRes animation: IntAnimationAnimationUtils.loadAnimation()//
InterpolatorsR.interpolatorKite.interpolation@InterpolatorRes interpolator: IntInterpolatorAnimationUtils.loadInterpolator()//
IntArrayR.arrayKite.intArray@ArrayRes intArray: IntIntArrayResources.getIntArray()//
StringArrayR.arrayKite.stringArray@ArrayRes stringArray: IntArray<out String>Resources.getStringArray()//
TypedArrayR.arrayKite.typedArray@ArrayRes typedArray: IntTypedArrayResources.obtainTypedArray()//
IdentifiersR.idKite.identifiername: String,defType: String,defPackage: StringIntResources.getIdentifier()//
XmlsR.xmlKite.xml@XmlRes xml: IntXmlResourceParserResources.getXml()//
RawsR.rawKite.raw@RawRes raw: IntInputStreamResources.openRawResource()/TypedValue

⚠️ Known Issues

  • Annotation checks over resource function parameters (functions which take as argument some annotated value, like@ColorRes,@StringRes) are not extensively performed by Android Studio, when using kotlin operator functions. I created a bug report @ google issue trackerhere. Hope to see it fixed soon, by2020 2021 Marked as fixed

Kite Puns

  • A kite usually comes with differentcolors
  • A kite is flown and controlled withstrings

[8]ページ先頭

©2009-2025 Movatter.jp