RecyclerView “swipe to delete”. No 3rd party lib necessary.

Author is a professional software developer providing android development services. More info here.

Checkout the code at the github repo.

Big shout-out to the guys creating libs for all the stuff Google promotes but doesn’t give us code for just yet, but the fact of the matter is I prefer not to use those libs unless I absolutely have to. The lib you include in your project might be doing a lot more than you need it for and with that comes a burden on your precious method limit count, possibly longer builds, another lib you and your coworkers need to keep in your heads…

The other day I had to implement “swipe to delete” feature. I wasn’t very happy about that since I feel that it’s not very discoverable and that those kind of gesture based actions shouldn’t be the only way to access the feature, but that’s another story. Still remembering how difficult this was couple of years back on a ListView I’ve started googling and soon enough there was a simple SO post with a simple solution and the best part – no 3rd party lib needed! However, it wasn’t to be so easy in the end.

First issue I had was what happens after the swipe? Sure I’d like to draw something below the swiping view, but once the view is swiped and the deed is done, it was kind of anticlimactic :/
issue 1

I wanted just to draw red background over empty space as items are animating to their new positions but I couldn’t do it inside the ItemTouchHelper class. I had to introduce another ItemDecorator in order to do so. The results were satisfying.

issue 1 fix

I was curious if I could easily implement the “undo” option, similar to the one GMail app provides. I had an idea how to do it and sure enough it worked!
undo
But all the time I was seeing a weird issue: When I would swipe delete the row, scroll around and come back, the row above the previously deleted row would be gone. Debugging showed that it was x translated off screen, as a result of the swiping as it turns out. Note how I swipe delete Item 2 but afterwards Item 1 is gone!
issue 2
I’ve sunk several hours into this issue, actually more than I’d like to admit. During that time I found several hacks to make this go away but no proper solution. In the end turns out it’s a regression bug in a recyclerview-v7 support library and the bug is gone in the newest version 3.1.1.

That’s all folks!

Yet another post on Serializable vs Parcelable

Author is a professional software developer providing android development services. More info here.

All my android developing life I’ve used java serialization as a data transfer mechanism between activities. I was vaguely aware of Parcelable and it proclaimed benefits but never really saw any performance issues related to this and thus never had a need to start writing all the parcelable boilerplate in my classes instead of just marking them as Serializable. When I recently started working on an ongoing project I’ve quickly jumped ship since: a) it’s supposed to be an order of magnitude faster and b) there is an awesome code generation library, Parceler, relieving developers of writing the boilerplate while keeping all the performance goodness.

I’ve just finished implementing my first big feature in the app and all was well until our amazing QA guy came to me with an issue – app was crashing on transition from one activity to another – throwing a TransactionTooLargeException (or just logging E: !!! FAILED BINDER TRANSACTION !!! on pre 15 API levels). And he wasn’t even trying to do anything crazy. Quick google search led me to a world of remote procedure calls and binder transaction buffers, a world I was blissfully unaware previously. So there is this binder transaction buffer, and it appears to be limited to 1MB, and it is used by all ongoing transactions simultaneously. I am moving a fairly large object graph through an activity starting intent, and maybe I’m not supposed to be doing that, but surely I can’t be hitting a 1MB limit? Or can I?

Continue reading Yet another post on Serializable vs Parcelable

Designing android apps begginers guide – introduction

Author is a professional software developer providing android development services. More info here.

More often than not, designer I’m working on an any given project had no previous experience with android. That is way I want to write a series of articles as a beginners guide for designers entering the android realm for the first time.

Continue reading Designing android apps begginers guide – introduction

Converting an android app to a library

Author is a professional software developer providing android development services. More info here.

Are you trying to convert your android app to library? It’s very simple, just go, Properties->Android,  thick Is Library and that’s it. At least in theory, but here are couple of advices to make it work in real life as well…

Continue reading Converting an android app to a library

Android build target – a controversy

Author is a professional software developer providing android development services. More info here.

Here is a very good example why are android devs pissed off most of the time (you can find another in this post). Lets find an answer to this simple question: “What version of android should you build your project against?” I claim this should be set to maximum version your app is supporting (the latest existing one obviously)  and a colleague of mine, a respectable senior developer, claims it should be a minimum version your app is supporting. And we are both right because android resources say one thing here and another there.

Continue reading Android build target – a controversy

SVN, Android Pre Compiler and Mac OS X = PITA combination

Author is a professional software developer providing android development services. More info here.

As far as I’m concerned SVN is a thing of the past. In todays market of SCMs my weapon of choice is git and I’m very satisfied ever since I made that transition. That was easy enough for me, a freelance developer, but may not be so easy for a company for reasons both real and imaginary. That’s why I still have to use SVN for time to time whenever I’m consulting for a company with SVN repositories.

Continue reading SVN, Android Pre Compiler and Mac OS X = PITA combination

How to make Android Google Maps v2 work in android emulator

Author is a professional software developer providing android development services. More info here.

Couple of days ago I was in for a nasty surprise. Providing android training in a company here in Belgrade I wanted to present a demo app of location sensors and Google Maps API but when I sat to prepare it I realized that only yesterday new Google Maps API v2 for android has arrived :) Not a problem really since I love learning and keeping up to date with changes but not beeing able to run maps powerd app in an emulator was a really  unpleasent surprise. Read on to see how you can make this happen.

Continue reading How to make Android Google Maps v2 work in android emulator

5 android helper apps for development

Author is a professional software developer providing android development services. More info here.

Android development can be a frustrating endeavor. There is a number of obstacles and difficulties but a large community always finds a way around them at least. Here are 5 apps every developer should have on their work belt.

Continue reading 5 android helper apps for development