Menu

SwipeRefreshLayout with ListView done right

Setting up a SwipeRefreshLayout is pretty easy. There are great tutorials out there. Even more if you already played around with other compat components like the DrawerLayout.

You just wrap your ScrollView or ListView, a few wiring here and there, and it's done. Works flawlessly, with just a few lines of code.

But what if you want to use a ListView, but you need something else besides a ListView as SwipeRefreshLayout's only child?

Maybe you want to use an empty view for all those times the list comes up empty. Or you want to put any extra view, like a SmoothProgressBar anywhere. Or a loading spinner at the center of the screen while it's loading.

Image a layout like this one.

<android.support.v4.widget.SwipeRefreshLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/guides_no_results"
            android:id="@+id/empty_view"
            android:gravity="center"
            android:padding="16dp"
            android:fontFamily="sans-serif-light

GitHub Downloader

I have created a new gem, GitHub Downloader, which does basically that: it downloads the source code from GitHub repos, packed in zip files.

Octocat rules!

It's open sourced, of course. You have in there the usage instructions too.

I needed an script for doing that, and well, maybe it works for other people so there you have. It's on RubyGems already, give it a try if you find an use to it!

Tools of choice when crafting Android apps

In this ever changing development world I wanted to take a little snapshot of which ones are my tools of choice when developing Android apps, both at work and at home.

Design and prototyping

Photoshop for design, all along. Though lately I've been experimenting by trying not to use it, and go with Pixelmator instead. I haven't died in the process.

For prototyping and vectorial design I'm loving Sketch. It's not very expensive and IMHO it's very powerful for mobile thingies.

Sketch

IDE

I hate Eclipse. I didn't liked it very much back then, and I really hate it now. The first thing I do when I got to work in a legacy project is creating a new one and importing all the classes by hand.

I switched back then to IntelliJ, and when Android Studio was unveiled it was like a blessing. It doesn't matter the little problems here and there we all developers had since it's birth, it's all worth it.

Android Studio setup

For logcat I use the very nice pidcat util from Jake Wharton, because it makes my life easier - the one embedded in Android Studio is too bloated and I prefer to have it in another screen.

Pidcat

Build

How to style the ActionBar SearchView programmatically

I stumbled upon a problem with the styling of a view at work. I had almost everything solved with a custom theme, but it all came down to style a SearchView widget of an ActionBar.

The unstyled version

That's where the fun begins.

All of this must happen in your onCreateOptionsMenu method. With a reference to your SearchView object in there, you can start doing things.

For example, if you'd like to get a reference to its EditText, you could do it using reflection like in this snippet.

int searchSrcTextId = getResources().getIdentifier("android:id/search_src_text", null, null);  
EditText searchEditText = (EditText) searchView.findViewById(searchSrcTextId);  
searchEditText.setTextColor(Color.WHITE);  
searchEditText.setHintTextColor(Color.LTGRAY);  

For changing the close icon, this one.

int closeButtonId = getResources().getIdentifier("android:id/search_close_btn", null, null);  
ImageView closeButtonImage = (ImageView) searchView.findViewById(closeButtonId);  
closeButtonImage.setImageResource(R.drawable.ic_action_cancel);  

And so on. You can get all the references in either the Android code for SearchView.java, or in its layout. For the lazy ones, here are some of those references that you can retrieve (and play with).

// This excerpt is from Android source code (SearchView.java)
mSearchButton = findViewById(R.id.search_button);  
mSearchEditFrame = findViewById(R.id.search_edit

Rinse and repeat, blog style

So I changed my blog again.

I think all the changes I end up doing to it follow a pattern. It keeps getting simpler.

The first iteration I made, which was a self developed and self hosted blog, was started because I wanted to be more proficient with Ruby on Rails. I built it from scratch and learned a lot about complex ActiveRecord relations. Internally it had a complex admin zone,with URL shortening and even image galleries. The posts were done in Textile markup. It was good and by all means useful to me. But then, like with your two year old smartphone, it happened. I was fed up with it. And because of that I ended up writing less.

So I started a new version of it, but now with Octopress. The idea was fascinating to me: using a repository to have all my posts stored in Markdown, and static pages generation. I was able to store it directly on GitHub pages, as the content was statically generated. I had to extract all the posts, tags and links from the old one, so I programmed an extraction script that translated everything to markdown with the correct file naming

Betrayal Helper for Android

I've been playing a lot lately to the board game Betrayal at the House on the Hill, which is awesome, and I felt I needed to release a little helper app for it - keeping the score with the analogic meter you are provided with the game is a pain because the clips fall off pretty easily.

So, after a busy weekend, it was completed.

App Logo

I released it for free, so if you like board games and happen to have this game, you can check it out in the Play Store.