Thursday, June 19, 2014

Using Ivy + Ant for Android in Eclipse (Dependency management and building made easy)

Recently I discovered Apache Ivy, a dependency management system supporting Maven repositories, that can be integrated with your Eclipse IDE and also with your Ant build scripts. Since I found very little documentation on how to integrate these things and struggled myself quiet a bit, I decided to make a guide to help others with the same problems.

How to extend a Classpath entry in Ant

When dealing with Ivy in an Ant build script I wanted to simply add Ivy's classpath to the buildpath of my app instead of copying all the JARs around. The challenge boiled down to overriding, i.e. extending the default script's classpath entry named project.all.jars.path.

Here's what you can not do:

<path id="project.all.jars.path">
    <path refid="project.all.jars.path" />
    <path refid="ivy.build.path" />
</path>

Defining a path by referencing itself doesn't work because both these references would point to the same object. Here's what does work:

<pathconvert property="classpathPropBefore" refid="project.all.jars.path" />

<path id="project.all.jars.path">
    <path path="${classpathPropBefore}" />
    <path refid="ivy.build.path" />
</path>

It's simple if you think about it. All I did was write the old content of the classpathentry into the property classpathPropBefore and then redefined the classpath entry with it's old content plus my addition.

Monday, November 11, 2013

Help, my spinner is too wide!


When dealing with the Spinner widget, especially when using NAVIGATION_MODE_LIST in your Actionbar, you might have stumbled over its weird sizing behavior. Namely, it's much wider than it needs to be. Here's an example of what a spinner in the Actionbar might look like:

The spinner is apparently much wider than it needs to be.
In this post I will explain what the reason for this behavior is, highlight the responsible bit of code from the Android framework and present a method for fixing it.

Saturday, November 2, 2013

Multiple dependencies in Android preferences

While adding a new feature to my Android app Changelog Droid I discovered the need for a checkbox preference that is dependent on two separate preferences, i.e. the preference is only enabled if two other preferences are cheked. If either one is unchecked, it should be disabled. The (simplified) hierarchy looks as follows:

  • Enable notifications
    • Enable notifications for updated apps
      • Enable detailed notifications for updated apps

Logically, the preference "Enable detailed notifications" should only be enabled, if "Enable notifications for updated apps" is checked and both should only be enabled, if "Enable notifications" is checked. I googled a bit to find out there is no built-in way to achieve this, as preferences can only have one value for the "dependency" attribute, so I created my own implementation.