June 24th, 2012

Written by Stoyan Rachev

I recently created Feeder, a fully functional yet simple Android RSS Feed Reader application. Although I wrote it for an internal contest at SAP, my main goal was to explore and showcase best Android programming practices in areas such as content providers, asynchronous processing, data binding, custom views and adapters, background services, and advanced UI features.

You can explore the source code on github. There is also a Wiki which highlights the most intersting parts. Feedback, comments, and contributions are welcome!


Channels ViewItems View

Application Features

  • Subscribe and unsubscribe to RSS and Atom feeds.
  • View feeds and feed entries as picture mosaics rather than plain lists.
  • Conveniently navigate between feeds and feed entries.
  • Refresh feeds with a button click and in the background.
  • Read feeds offline.
  • View featured entries that contain one or more predefined keywords.
  • Clean old feed entries with a button click.

Programming Highlights

  • Uses the Android port of Rome for parsing RSS and Atom feeds.
  • Uses ORMLite for simple annotation-based persistence of Java objects.
  • Feeds and their entries are exposed via a content provider, so they can be accessed also from other applications. The provider implementation is based on a mini-framework which saves a lot of boilerplate code.
  • All operations on data such as querying the content provider, performing database operations, and downloading feeds from the Internet are performed asynchronously in background threads.
  • Uses custom views managed via data binding for lists of feeds and their entries in order to display them as picture mosaics.
  • There is a background service for refreshing the feeds on a regular interval.
  • On Android 3.0 or higher, makes use of advanced UI features such as action bars.

For more highlihts, as well as known issues / TODOs, see Feeder’s Wiki.

The Content Provider Framework

Perhaps the most interesting programming highlight in Feeder is the Content Provider Framework. It enables you to create a fully functional Android content provider with much less code than when using the standard approach. Behind the scenes, the framework uses database functionality and metadata information provided by ORMLite and a few additional custom annotations to build content queries and manage database tables in a generic way.

At the moment, this framework is part of the Feeder application, so it cannot be readily used in other applications. If there is enough interest, I will extract it into its own open source project, or integrate it into an existing one such as android-annotations.

Using this framework is as simple as following these two trivial steps:

1. In your data model entity classes, extend Data and add a few annotations such as @UriPaths, @MimeType, and @DefaultSortOrder.

2. To create your content provider, extend AbstractContentProvider and override its onCreate() method to configure it appropriately.

And that’s it. If you have written Android content providers in the standard way, you should be missing here a few hundred lines more of boilerplate code. All this is largely replaced by the functionality available in the framework AbstractContentProvider and DatabaseHelper classes.

For more information on this mini-framework, see it’s dedicated Wiki page.

June 20th, 2012

by Ivan St. Ivanov

Before I start with my quick overview of this year’s Eclipse demo camp, I’d like to share my attitude to the presented technologies. Eclipse is my favorite IDE. However, I don’t use most of the wizards. To be honest I just use the editor and some plugins like m2eclipse, FindBugs and once in a while Scala. Ath the same time for git I prefer its command line instead of EGit. Actually the good old command line is my first choice for a lot of other things (as you will understand if you keep reading). I occasionally write some small web apps and I do it in the Java perspective. I don’t like OSGi, Equinox and p2. I think that they have their niche, where they are the perfect fit, but in the last few years the Eclipse community tried to push them into areas where there are still much better choices (I will write about this later in this post). So, yes, I am biased and be prepared for that 😉

Another disclaimer: although I am SAP employee, the thoughts below express just my personal opinion as a geek.

The keynotes

Last time we had Mike Milinkovich (the executive director of Eclipse foundation) himself give the keynote. This time it was Ralph Mueller, the director of the European ecosystem. Unfortunately he was not able to come, so we heard his talk thanks to the Skype connection. He started with the recent announcement that Eclipse has received the Software System Award by the Association for Computer Machinery (ACM). If it doesn’t sound familiar to you (as it was to me), this prestigious award has been granted to really awesome achievements like UNIX, Smalltalk, TCP/IP, World Wide Web, Mosaic, Apache and Java. The presentation continued with the history of Eclipse – how it all began, how it evolved and how it was used in some industries. So it was yet another corporate keynote, though you cannot call the Eclipse foundation a real corporation. Before the keynote, our host (and also speaker) Katya Todorova started with a very quick overview of what is there in Eclipse’s Juno release. So what I really expected was that Ralph would elaborate more on this – what are these changes in the APIs that would make E4 more attractive both for Eclipse users and for the RCP and Equinox developers. That is why I was a bit disappointed with the conference beginning.

Good that the second keynote (at least I took it as keynote) was purely technical. It was given by my colleagues (all the next speakers were actually my colleagues) Diyan Yordanov and my fellow geek Vladimir Pavlov. The session started with a few slides, where I was pleased to see that SAP uses and integrates tons of open source software for its products. I cannot be happier, as I am a huge fan of using and contributing back to the community. After this introduction came the real action – the stuff that all us went to the conference about. The Juno IDE was open and the demo application was developed. And what an app it was: JPA, REST, HTML5, and even some Servlets for initialization. It was actually a mashup – it called a web service from an HR backend system, Google geolocation APIs and weather services. Well, to be honest, most of the code was already prepared and the presenters copied step by step each of the layers and modules into the project.

Still to come was deployment in the cloud. For that the presenters used SAP’s Platform As A Service solution – NetWeaver Cloud. It is based on a [nearly] Java EE 6 web profile server. You can first test your web app on a local instance that emulates the real cloud solution. Then you can very easily deploy your package without leaving your IDE. It took some time on the demo, which was caused mostly by the fact that the size of the WAR was more than 40 MB – it contained tons of libraries that Apache CXF depended on.

Control your IDE!

Next was the most impressive demo. It was about Jnect and was given by Assia Djambazova. Jnect is Eclipse plugin that serves as a bridge to the Kinect SDK published by Microsoft several years ago. Using this plugin you can build RCP applications that can take advantage of this popular motion sensing device’s capabilities. The API reacts on events like moving your left/right hand, elbow, shoulder, hip, knee, foot, your head, your body, etc. It can also recognize and differentiate voice commands.

The demo app that was presented used body and natural language to make the Eclipse debugger step over and into various method calls in a java program. Then Assia issued a voice command to enable window resize and used her hands to shrink and stretch that window.

As the SDK is available just for Windows (surprise!), maybe you cannot use this plugin on different operating systems. You should also find a strange adaptor to connect your Kinect tool to the computer (prepare to visit your favorite Chinese website!). BTW, on the last edition of the Devoxx conference we were able to scroll up and down the agenda in front of each hall without touching the screen with the help of the same sensors. But the application there looked more like Adobe Flex than Eclipse RCP. So I believe that Microsoft’s SDK was ported to other programming platforms as well.

First demo panel

After the lunch break we had two panels of three 20-minutes demos each. First Lazar Kirchev showed what’s new in the Equinox console. Besides the fact that you can do ‘| grep’, can start a telnet server from the Eclipse console and then have tab completion and command history, the most interesting part was about the new console commands programming model.

And here came my biggest disappointment of the day. I expected something more from a new programming model. It’s good that you don’t have to implement a special interface any more if you want to define a class containing commands. But you must add the names of your methods in an array of Strings and put this array in a Hashtable, which is then registered in a kind of tracker. So I believe that if you forget to do that, if you misspell your method or if you rename it afterwards and forget to update the registry, then you are screwed. And this is in the era of dependency injection and annotating nearly everything?! Maybe this approach is perfectly fine for an embedded application. But then let’s stop pretending that OSGi is worth for anything more than that!

Then on the stage came Violeta Georgieva to try to prove just the opposite – that you can use Equinox-based runtime to run your web server and web applications. To develop this strange hybrid apps (both web and at the same time OSGi plugins), you may take advantage of the Libra project which combines the Web Tool Platform and the Plugin Development Environment features. The next step is to have the web server modules as OSGi bundles. There is another Eclipse project – Gemini, which brings Tomcat to OSGi. Fortunately the rest of the libraries implementing Java EE 6 web profile technologies (like EJB Lite, JSF, JPA) are already there. Making your pure Equinox runtime a Java EE web server is as easy as installing an Eclipse feature on top of it.

After you create and deploy your web app on the runtime, an OSGi service is automatically registered for you. It exposes the ServletContext object, which in turns provides access to the BundleContext available to the OSGi bundles. So at this time I thought that it is an elegant mix between the two worlds (Java EE and OSGi), which relieves you from having to package all your dependencies into the WEB-INF/lib directory of your war file.

However this comes with a price. If you want to access a service exported by another bundle in the runtime (an example was given with the OSGi standard log service), you have to first look it up from the service tracker. Looking up something was fine in J2EE 1.4, but I thought that this page was closed long ago. The service tracker is now generified (Amen!), but is still too tedious to initialize and call. You can definitely use declarative services, but then you need to write tons of XML, which sounds again J2EE 1.4-ish. Finally, after you have looked up the service, you have to check it for not being null before every call. Imagine doing this every time you want to log something:

if (logger != null) {

With that being said, I stopped listening. I started pondering what is the benefit of not packaging a jar or two, if you have to do all this heavy lifting. If you look at the real Java EE servers (Glassfish, JBoss AS7, etc.), you don’t even have to bring your dependencies inside your war – they are provided for you by the container. All you have to do there is drop a couple of @Inject statements and that’s it. So, next time when somebody suggests using OSGi for web apps, I’ll probably ask them to stick to the embedded world.

The final demo in this first panel was by Vasil Panushev and was about Android. It actually didn’t show anything new from the E4 world, nor did it go in too much detail about the Android Development Tools. Nevertheless, it was really entertaining with some well placed “bugs” in the code (or in the scenario of the demo ;-)). I also learned something new from it – you can write unit tests for your Android apps. However, they can’t be in the same project (unless you don’t want to ship them) and JUnit 4 is not supported. Vasil also mentioned that there is mocking framework for UI testing.

Second demo panel

The second demo panel started with a talk by Petya Sabeva about the JPA editor in Eclipse. I was particularly interested in this topic as it concerns one of the many functionalities of my favorite tool JBoss Forge: generating JPA entities. You can create new entities by dragging icons to the diagram, which results in generating the necessary Java code. You can also import existing entities into the diagram. You can do whatever you want with the entities once they are brought to the drawing surface: add or remove fields, manage relationships. It has even support for mapped superclasses. I’ve heard that we had such tool in SAP for many years, but this particular solution is part of the community – the Eclipse Graphiti project. I mentioned in the beginning that I am more a command line tool lover than GUI editor fan boy. With the command line I feel that I am in control of what is going on (well, not really with Spring Roo ;-)). With the GUI editors I always fear that something is happening behind my back or that I have forgotten to click a checkbox somewhere.

The final two demos were about my most “favorite” of the “favorites”: p2.In a nutshell: it is Eclipse Equinox’s means to deliver plugins and features from a remote location (called update site) to a running runtime. First off Katya Todorova started with a brief introduction into the concepts of p2 and how it works. Then she introduced another Equinox based solution – Virgo. It is an OSGi based fully modular application server, which some of you may remember as dm Server. It was contributed by SpringSource to the community once Rod Johnson (SpringSource’s CEO) found that OSGi is not easy to use and not as productive as it should be.

Katya then showed how you can install the Virgo server by yourself using Eclipse, p2, a couple of update sites and a strange thing called Director. This Director is supposed to make a real product out of your plugins. And it works only on demos. If you try to have your product created as part of your continuous integration process, then be prepared to dump some hundred lines of ant commands, half of which you don’t understand and can’t read anywhere about. They say that p2 can be used for updating your product with the newest version of its plugins. I saw it work once, after months of hard work and hot discussions on the p2 mailing list.

Anyway, just for the record, we had our Virgo up and running and ready to serve. Then on the stage came our last year’s JavaOne star Borislav Kapukaranov, who showed how you can build a simple web application and deploy it to Virgo. He finished with explaining the Virgo usecases: from Java EE web profile to embedded environments (where OSGi really shines!).


Don’t get me wrong, I liked the conference very much. The fact that I don’t like OSGi, Equinox, p2 and the rest doesn’t mean that I don’t appreciate the great work done by the teams behind these tools. I also think that we must all thank my colleagues at SAP who made this conference happen: by organizing it and by preparing the awesome talks.

I was a bit disappointed that no other company sent speakers even though there are plenty Eclipse and OSGi developers in Sofia. There were very few attendees as well, despite the fact that the conference was free and that it was announced in the Bulgarian Java User Group.

See you at Java2Days!