Napster's Experiments with Freedom

Hi There, This is my personal blog. You might see some really personal stuff and more or less technical articles here. I used to fuse all my things together at one place. So, don't take it too seriously. I could not really manage more than one blog or profile at a time. You might think its a little odd to do it in that way. All of the posts here are made on the intention that it would be helpful for you at some point. I have tried to keep it as simple as possible without losing the quality. Thanks for reading.

View Subin Sebastian's profile on LinkedIn

Recent Tweets @
Posts tagged "gui"

Reading time : Less than 10 Minutes

Perhaps one of the most usable widgets released by Google must be the newly added SwipeRefreshLayout. See, I’m not exaggerating but it is really useful. Before this solution was released, if you want to copy the Apple’s patented Pull-Down-To-Refresh UI pattern, you were left with your own implementation or some third-party libraries. Google didn’t appear to be much interested in this pattern either. Even Cyril Mottier had an article describing how Pull-to-refresh is An Anti UI Pattern on Android. Despite all these, a lot of developers were using this UI pattern. Like many others I was using it too. Anyway, now we have SwipeRefreshLayout, an awesome widget which can hold any scrollable views as a child. I have tested with Listviews and Scrollviews and it works smooth.

Now to the peace of mind, Google has included SwipeRefreshLayout in their Support-v4 library. You can use it from any platform level grater than 4. It is easy to use and easy to customise. In this article, I’m explaining a simple example application that does the same. First of all, you need to add the support library dependency to your Gradle script. If you are using other build systems, equivalent of the same is applicable there as well.

compile ""

Once you add the above line, you need to sync Gradle once the system adds the necessary files to your project for this dependency. Now, ahead to the XML. It is fairly simple.

You must implemented SwipeRefreshLayout.OnRefreshListener in your Activity or Fragment. This interface will provide you a callback public void onRefresh(); which is triggered when the user drags the scrollable view and releases it. Check out the simplest version of my activity class. I have changed the color scheme for the SwipeRefreshLayout to make it more attractive. You don’t necessarily need to do this.

The result is pretty attractive. Take a look. Note that, you can do your network fetch or the list update process from inside the onRefresh(); It is called on the UI thread, so if you are doing network requests, make sure it is thread safe.


Happy Hacking!

Reading Time : Less than 20 minutes

After a long effort I made Necessitas working on my machine. I strongly believe I should blog it at the right time. So lets start setting up the development environment with Necessitas. Necessitas provides a custom Qt-Creator release with Android stuff integrated. Even though you can build Qt-Creator and QMake yourself for this purpose, I would suggest you to use the installation script available for download. This article is based on Ubuntu 11.10 and ant version 1.8.4. Lets start creating a new folder for installing Necessitas.

sudo mkdir /opt/necessitas
sudo chmod -R 777 /opt/necessitas

So, we have created a folder in /opt and it is has necessary permissions. Now download the installer and save it under your home folder. Once it is made executable, you can run it.

sudo chmod a+x ~/Downloads/necessitas-<version>-online-sdk-installer-linux
sudo ./necessitas-<version>-online-sdk-installer-linux

You will be guided through a set of steps by the installer. When asked for installtion folder, choose /opt/necessitas. In the component selection page, you can choose to opt out unnecessary API version of Android SDK. This will reduce the download size.

Finally, press Install to begin the installation process. On a windows machine, I got an error message that the installer requires atleast 16GiB of space for temporary files. This might also be applicable to Linux. The installation process would take a few minutes (or even hours on slow speed Internet connections) to complete. Once the installation is complete, open the Qt-Create for Necessitas. Go to Tools > Options and switch to the Android tab, and set android SDK and NDK locations. In my case,

SDK Location : /opt/necessitas/android-sdk
NDK Location : /opt/necessitas/android-ndk-r6b
ANT Location : /usr/bin/ant

Now, click on the Start AVD Manager button, and create an AVD with atleast 1024MiB SD card and HVGA resolution. Finally Start the emulator you have created. Now, jump to the Qt4 tab in the Options window, and make it looking as same as in the following image (To see the image in full resolution, right click on it and select View Image)

Press OK to close the Options window. Close Necessitas Qt-Creator but leave the emulator running. Download the latest Ministro service package for Android from here. Once downloaded, open a terminal and issue the following command.

adb install <full path file name of the ministro apk>

Now, start Qt-Creator for Necessitas. Create a new project and select Qt - Mobile Application as the template. Remove the content of MainWindow::setOrientation() method since it contains some reference to Symbian. You will be greeted with the first class Qt GUI designer. Add a couple of widgets you would like to see on the screen. I have added a QLabel and QPushButton. Click the Run button on the left pane. Now check the emulator and you will see the Necessitas Library download message.

This is a one time process. The download wont happen again for another program which requires the exact same library. Once the library has been loaded, the application will start running. Take a look at my output.

Here in this article, we have not played anything with the source code. So, there will be no functionality at all. In the upcoming articles I would try to introduce more Necessitas stuff. But I hope this would be a great start for you with Necessitas. Also don’t forget to watch a much more professional video here.

//See you in the afterlife
//Subin Sebastian

Reading time : Less than 15 minutes

For most of the advanced users, these two terms will be much familiar. So, this article is for new developers. Most of the today’s desktop programming toolkits are object oriented. Lets take an example of popular X-Window GUI toolkits like GTK+ or Qt, both are object oriented. GTK+ is written in C, and the object-orientation in GTK+ is achieved by using the GLib object system, whereas Qt is written in C++ and is purely object oriented. The main, advantage of object oriented design in widget toolkits is that, they can model entities like windows, widgets, or features etc as objects. By definition as objects should have three properties,

  • Identity, which makes an object unique
  • Attributes, which specifies the state of an object
  • Methods, which defines the behaviour of an object

It is very easier for the toolkit developer to make an exact analogy with a GUI elements like a window or a widget in object oriented programming. Even though it makes the life of the toolkit developers job a bit happier, on the other side, application developers face a minute problem. I’m not sure if I could say it is a problem, but still there is something I would like to point out as an application developer, who extensively uses toolkits. A completely object oriented toolkit always provides a property based API, which means, to do something with an element inside it, we have to do the following steps.

  • Create an object of that element
  • Set required properties to that object to change its state like we do
  • Call one of the methods to get the functionality from the object

It may look simpler to some new programmers since they play with pretty simple tasks most. When it gets a little bit complex, say if you are developing a complex application, you cannot spend that much time to do a simple task in between the actual coding. For example, if you are developing a big ERP system, you cannot always spend much time to show different kind of message boxes in between for different purposes. That will increase the number of lines of code in your application and you get messed up with the logic of the application as a whole.

One of the easy way to manage this is, to create a simple function which can take a number of parameters/arguments, call the required method and finally return a useful value to the developer. In case of a message box, it can take the message text, names of buttons to be shown and finally can return which button the user have clicked on. So, apparently we can tweak the three step process into a one step process, which is just a function call. But this has a scalability issue when the message boxes requires completely different kind of apparances in different occurrences - eventually we will keep on developing our custom function to handle all of the cases, which again causes problems. But, the developers life gets much more happier if the toolkit itself contains those kind of functions! Here comes the concept of Static Functions API. Most of the today’s toolkits has both of these APIs so that developers can use them appropriately according as the situation. A good example I’ve seen is : the Qt Message Box API itself. So that’s all, and I hope, when you look into documentations you will keep this post in mind to choose stuff a little more wisely.

//See you in the afterlife
//Subin Sebastian