1 minute read

I don’t remember since when, but now whenever I upgrade Android Studio from pacman, I cannot open my emulator, with some libGL error: unable to load driver: i965_dri.so error. I tried to follow the solution online but found none of them is working out of the box, because Android Sdk changed some paths. Here is what actualy works now: cd ANDROID_SDK_PATH/emulator/lib64/libstdc++/ mv libstdc++.so.6 libstdc++.so.6.bak ln -s /usr/lib64/libstdc++.so.6 libstdc++.so.6

2 minute read

RxJava Android

In this post we talk about how to use Observable.fromCallable() and Observable.defer() to convert exising functionality into the Rx. Imagine that you have a UserService class, in it there is a getUserFromDb() function. This function is developed before RxJava and cannot be changed. But somehow you need a function which returns a Observable<User>. What could you do? The UserService Example public class UserService { /** * Gets User from database, this should not be run in UI thread.

Android Custom View 101 (Part V)

Learn about Androd Custom View and ViewGroup

2 minute read

Android custom view

In this post, we will discuss how to implement a custom view group by extending an existing one, like a FrameLayout. Let’s assume that we are building a layout for displaying user’s avatar. The requirement is if a user has an avatar, show the avatar picture, if not, show their initials as text. So it would be good if we have some kind of AvatarView and Avatar data class (which contains name and avatar picture).

Android Custom Views 101 (Part IV)

Learn about Androd Custom View and ViewGroup

2 minute read

Android custom view

In this installment, we talk about how to implement custom view group. Custom View VS Custom ViewGroup When we think about a view, it is usually very simple and self contained. View represents, draws and handles interaction for a part of the screen. Whereas ViewGroup is more about a binding relationship between views. ViewGroup is a specialized View that contains other Views. It has children. As discussed before, in order for custom view to work correctly, it has to implement two methods: onDraw() and onMeasure(), and there is no need to implement onLayout() cause there is no children to layout.

Android Custom Views 101 (Part III)

Learn about Androd Custom View and ViewGroup

2 minute read

Android custom view

In this post, we finally gonna take a look at how to implement onMeasure() properly. When implementing a custom view, we should always consider its lower and upper size limit. In this case since the format of the time is fixed (hh:mm:ss). So we just need to get the width and height of it. Suppose we set the MAX_TIME = "00:00:00", then to get its width in pixel we can do: