Android tricks - How to find view's dimensions before displaying the view?

Two days ago I had to work with some views (Surprise! Surprise!). At some point I had to get the actual views’ width and height, before actually displaying the views. Of course, they were included in my XML layout. Thus this made the task a little bit easier. After spending several minutes on Google (ALWAYS do that, when you are in trouble), I found a solution. Code Description: You can see that we can actually obtain the view’s dimensions thanks to the Display class....

December 21, 2016 · 1 min · Todor Kostov

Geo-fencing with MVP Part 3

With the previous two posts, we went through the basic concepts behind the idea of geofencing, why using design patterns and we dived deeper in the main components used in the construction of the example application for these series. Now in the third part, we will go through the classes which are responsible for the core geofencing functionality. I hope you still remember the overall MVP design diagram from the previous post!...

December 18, 2016 · 4 min · Todor Kostov

Android tricks - How to add an icon to your Toolbar?

Today I had to implement something which is not so popular throughout the Android universe. I had to implement a simple Toolbar with a logo on it’s left side. That’s not so popular these days, but from time to time there always will be someone who wants something like that. All in all, the end result had to be similar to the one down below: I ended up with two different solutions based on weather you want your icon to be on the left side of the title, or on the right side....

December 14, 2016 · 2 min · Todor Kostov

Geo-fencing with MVP Part 2

In the previous post, we talked about the idea behind geo-fencing, why is it so useful and what is the reason behind choosing a particular design pattern like MVP. It was most like an introductory step before getting our hands dirty with some actual source code. Thus, in this part of the series, I will try to go through the different layers of the MVP pattern and will try to explain as much as possible the things that are happening there....

December 11, 2016 · 3 min · Todor Kostov

Android tricks - How to prevent AlertDialog from dismissing after onClick event?

Have you noticed that the default behavior of AlertDialog is to disappear after onClick event? I’m sure you have! But there are cases when we actually don’t want to dismiss the dialog. In these situation, the default behavior of the AlertDialog must be overridden. Down below you will find a snippet which is doing exactly that thing. Code description So what exactly is happening in that snippet? You can see that when we are constructing the AlertDialog object by using the Builder Pattern, we are setting null parameters to the methods responsible for setting up the behavior of the positive and the negative buttons....

December 8, 2016 · 2 min · Todor Kostov