Implementing a Menu

Android context menu

After getting my RecyclerViews working and doing some optimisation here and there, I finally implemented a main menu in my app. It’s done easily, here is how:

First copy the menu_main.xml from another project into your’s. Here is mine:

Then implement the override-methods to activate the menu and to interpret clicks:

Check out the complete source code on GitHub or load the current beta apk.

RecyclerViews at work

To show the list of weather stations I decided to use two RecyclerViews, one to scroll the list vertically and inside that many horizontal RecyclerViews. The idea behind it is that when I include more weather stations in the future, these stations will provide more data.

This is the code for the StationsAdapter:

Inside the StationsAdapter the MeasurementsAdapter is called. Whats really important here is to tell RecyclerView that data has changed. Its not really great for performance but if this is not done, the wrong data will appear for the stations further down the list.

In line 89 I “repack” the data from the ArrayList containing measurements data into simpler variables. I did this when I was searching for bugs. This could be fixed at a later time to make things easier.

Parcelable nightmares

Well, since I study Android development at Treehouse (referral link), I learn new things every week. This new knowledge I then apply to my first open source Android app “Smog”. Last week I learned to work with RecyclerViews and how to design and implement them.

What took my sleep last night was to implement methods to make the data I have of weather stations parcelable. This means: how to write the methods to transfer them from one activity (main window) to another activity.

Here is part of my code which is implemented into the stations class:

At about 1 in the morning is was completely stuck, at 10 in the morning I solved my problems and at 12 my app finally worked with the new features.

If you are interested in testing the App, let me know. I can provide you with an apk file.

My next step is to clean up the code and unify my FeinstaubStation.class into Station.class which then stores data from other service providers as well. Furthermore I want to implement a second, horizontal RecyclerView to show all the data available from each station.

New UI

My App has a new interface. The idea is to keep things simple: Every measurement of the nearest station is shown as a square. Green when all is good and another color when the air gets dirty. My aim is to dynamically populate the main screen with available data of the nearest stations. Its not yet complete but you will see the general idea on this screenshot:

New user interface.

By the way: I write the German localisation on the fly. That’s why the screenshot is in German.

New approach to the Feinstaub-data

When thinking about how to build the adapter to show all the Feinstaub-data (measurements of particulates) I realised that my initial approach was not very good. To create an adapter I need to have a “flat” structure without extra Arrays within arrays. Therefore I rewrote the classes and changed their name to reflect the heritage of the data, which is the Stuttgart Feinstaub-Project.

Check out their website:

My new classes are online at Github:

My GUI now shows the Data for the nearest station, but I need to contact the project-team about how to interpret the values.

Not yet beautiful… but the Feinstaub-data from the nearest station is visible. Yay!

Parsing “Feinstaub”-Data

Since some weeks I am learning Java at Team Treehouse (referral link). Though it’s not my first time programming, my Java knowledge needed an upgrade. While I am studying online (check out my progress here) I build my first app which I want to see in the Play Store within the year. I called it Smog, because its all about the air quality outside.

Development of this app is going alongside with my Android-Development track at Treehouse. I apply newly learned knowledge while I experiment with my own ideas. At the current stage the app reads Air pollution data from two sources, the Openweathermap API and the Stuttgart Opendata-Project

The data with particulates measurements comes in as a huge JSON file including all the (worldwide) stations’s current data. Here is my current approach to parse it. Suggestions for improvement are welcome.