Android Battery View

Android Battery View (ABV)


This library was born out of necessity during the development of the Device Info app. I encountered the challenge of presenting battery level and status in a graphical format, yet struggled to find a suitable option that was easy to implement. Despite discovering a few libraries on GitHub, none fulfilled all my requirements, and to my dismay, many were no longer maintained. Faced with this dilemma, I took matters into my own hands and developed Android Battery View (ABV).

ABV was created hastily, with plenty of room for improvement. However, it currently serves its purpose as is.


This one has pretty straightfoward features. 

Charge Level

  • Accurately displays the charge level from 1 to 100, with each level depicted on the canvas.


Includes four distinct stats:

  • Normal: Indicates discharging status.
  • Charging: Represents when the device is charging.
  • Warning: Indicates a low battery level, albeit not critically low.
  • Critical: Signals a critically low battery, prompting immediate action to find a charger.


Offers customization options:

  • Ability to change the color for all four stats.
  • Icons associated with charging, warning, and critical stats can be replaced with custom ones.
  • Compatible with both portrait and landscape modes.


Enables attachment to a BroadcastReceiver intent:

  • Automatically retrieves battery data from the intent, ensuring seamless integration.



Technologies Used

This library is entirely coded in Kotlin, with additional assistance from XML for attribute creation. Android Studio serves as the primary Integrated Development Environment (IDE) for development.

The source code is proudly hosted on GitHub.


  1. Planning: I began by examining existing repositories to gather ideas on how I wanted the library to function. I meticulously noted the limitations of these projects and devised a plan based on these observations.

  2. Draft UI: Utilizing Figma, I created initial drafts and collected the necessary icons required for the project.

  3. Core Coding: The development process kicked off with the core coding phase in Kotlin. Starting from the basic structure, I gradually built upon it, shaping it into its final form.

  4. Finalizing: With the core functionality in place, I dedicated time to refining the library, incorporating additional tweaks and enhancements to ensure its optimal performance and usability.

Problem and Solution

Canvas Resources

Problem: There is a scarcity of resources available on canvas manipulation. While some outdated tutorials exist, they often lack depth and fail to address advanced topics. Consequently, encountering obstacles during development proved challenging, with few avenues for finding solutions beyond basic documentation.

Solution: In the face of this challenge, I adopted a hands-on approach. Testing various theories and techniques, I delved into the intricacies of canvas manipulation. Through perseverance and experimentation, I uncovered solutions to the obstacles encountered along the way. Embracing the age-old tactic of brute-force problem-solving, I navigated through the complexities, ultimately overcoming the limitations imposed by the lack of comprehensive resources.

How to Use

First you need to add the dependency in your build.gradle  or build.gradle.kts and then just add the XML and Kotlin code. 


dependencies {




val abv = binding.abv
abv.size = 50
abv.mRadius = 10f
abv.chargeLevel = 50
abv.batteyOrientation = BatteryOrientation.PORTRAIT
abv.isCharging = false

Broadcast Receiver

class MainActivity : AppCompatActivity() {

    private val binding: ActivityMainBinding by lazy {ActivityMainBinding.inflate(layoutInflater)}

    private val batteryReceiver: BroadcastReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent?) {
            if (intent!=null){

    override fun onCreate(savedInstanceState: Bundle?) {
        registerReceiver(batteryReceiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED))


    override fun onDestroy() {

You can find the whole documentation here -

What I've Learned

  • Developing a solution from scratch requires confronting unfamiliar territories and embracing challenges with an open mind. This experience has made me more receptive to encountering and overcoming new obstacles in future projects.
  • The project provided an opportunity to delve deeper into the Android Canvas, enhancing my understanding and proficiency in this area. Experimentation and hands-on exploration have facilitated a more comprehensive grasp of canvas manipulation techniques and capabilities.
  • Necessity often drives innovation. By venturing into uncharted territory, I've honed my ability to think creatively and devise novel solutions to complex problems. This mindset of innovation will undoubtedly prove beneficial in tackling future projects.

Source Code 

The source code and the whole project is available on GitHub. 

Repository Link -

Repo Page -


In conclusion, the process of developing this new solution has been a journey of challenges and learning. Through experimentation and perseverance, I've expanded my knowledge of Android Canvas and cultivated a mindset of innovation. While there were obstacles along the way, overcoming them has equipped me with valuable skills and experiences for future projects.