In the vast realm of Android development, managing graphical objects can be a handful. However, with maoruibin's open-source library - OneDrawable, reusing Drawable objects within your Android applications is now simplified. This library, built with Kotlin and Jetpack Compose, not only brings ease of use but also introduces dynamic updating and configuration management for Drawable objects.
With OneDrawable, reusability is at the forefront:
- Drawable Reusability: Reduce redundancy by reusing Drawable objects across your project.
- Dynamic Updates: Alter Drawable attributes such as color and size on the fly, ensuring your UI remains responsive and updated.
- Configuration Management: Adjust and retrieve configurations effortlessly, allowing for structured and organized Drawable handling.
Getting started with OneDrawable is a breeze. Just include the following dependency in your Android project:
dependencies {
implementation 'com.github.maoruibin:onedrawable:1.2.0'
}
Here is a snippet showcasing the simplicity and power of OneDrawable:
// Create Drawable
val drawable = OneDrawable(this) {
color(Color.RED)
size(100, 100)
}
// Display Drawable
val imageView = findViewById<ImageView>(R.id.imageView)
imageView.setImageDrawable(drawable)
// Update Drawable
drawable.setColor(Color.BLUE)
drawable.setSize(200, 200)
With just a few lines of code, you create a red 100x100 Drawable, display it, and then dynamically update its color to blue and size to 200x200 upon an action like a button click.
Moreover, OneDrawable extends its functionality by allowing for structured configuration management:
// Set Drawable configuration
drawable.config {
color(Color.RED)
size(100, 100)
}
// Get Drawable configuration
val config = drawable.config
// Modify Drawable configuration
config.color = Color.BLUE
config.size = 200, 200
And it doesn’t stop there. You can save, load, and even delete Drawables, making managing graphical objects in your application a structured and straightforward task.