“I always say, 'This will be my last 'Metal Gear.'” Hideo Kojima

Using HoloCircularProgressBar with Action Bar Style Generator under Android Studio

Hello everyone!

I’ve been busy lately and haven’t got so much time to write posts. Anyway, I’m coming here today with something that has been troubling me for days. On my WhatsAnnoy project I’m using Action Bar Style Generator because the designer wanted it to be green. It’s an easy tool and provides an excelent result.

But then, the designer asked me to use HoloCircularProgressBar library written by Pascal Welsch. I found that it was an Eclipse library and it has no gradle files. I did a pull request with gradle files because I thought it would be the best solution: create an aar package and import it. Trust me, don’t even try this.

Why not?

It’s a pain in the ass. Period.

Then I found this post on StackOverflow. Give a try to the first answer, and found it was easy and also found that it worked.

If you want to import HoloCircularProgressBar (at least on 1.0.0 version) under Android Studio do as exposed on the first answer of mentioned post. I’ll write a reference here in case StackOverflow post is deleted:

  1. Open your project on Android Studio.
  2. Create a new Module as Android Library without activities (don’t forget to name it accordingly).
  3. Delete everything under src/main folder of your newly created module.
  4. Copy AndroidManifest.xml, res, src and ic_launcher-web.png from HCPB and paste it under src/main. Change HCPB src folder name to java.
  5. Delete dependencies and release blocks from build.gradle.
  6. Add your new module as a dependency through Project Structure dialog.

Can’t use the circular progress bar yet.

I know, I know. At this moment, you will find that you can add HoloCircularProgressBar view on Layout Editor. But project will crash when running.

What you have to do is simple. Copy attrs.xml and styles.xml from HCPB to res folder of your app module (not the library, of course). Rename them so they don’t conflict (p.e: attrs_hcpb.xml and styles_hcpb.xml).

Now, edit attrs_hcpb.xml so it links to your custom theme (generated by Action Bar Style Generator). For instance, in my case will look like this:

    <declare-styleable name="Theme.WhatsAnnoy">
        <attr name="circularProgressBarStyle" format="reference"></attr>       
    </declare-styleable>

Finally, add to your custom theme the following line as suggested by Pascal Welsch:

    <item name="circularProgressBarStyle">@style/CircularProgressBar</item>
As an alternative, you can create this files directly. Anyway, you can then customize them to your like.

Build and enjoy :D

Happy coding!

Jordi

Links: