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 @

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 "com.android.support:support-v4:+"

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.

https://gist.github.com/subinsebastien/b835e062b7fd87f7f9ed

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.

https://gist.github.com/subinsebastien/ecd641326e64660c27cd

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.

image

Happy Hacking!

Reading time | Less than 10 Minutes

This is more or less a learning stage article. I’m learning iOS these days, and as usual I find it challenging. I’m not a very noteworthy developer anyway, but still the learning curve is not so steep. You need the right tools and right amount of passion for learning iOS development. Ofcourse you need a Mac, and XCode running to develop apps for the iOS or the OS-X platform. Check my other iOS article for environment setup.

What we are building?

We are building a very simple weather search application. You may search with a city name, and the app will show you the latest weather information provided by the awesome Open Weather Map API. Openweathermap is free to use for non-commercial purpose. Their API has JSON support, means we can retrieve data from their systems as JSON Object that typically looks something like the following. Please note that JSON is not particularly useful, unless we parse it to an NSDictionary or a NSArray.

https://gist.github.com/subinsebastien/e663825d2624359b9aef

Our app will let the user enter a city name and press a search button that triggers the network query. The GUI is simple, you will just need a Text Field, a Button and a Text View that fills the rest of the area on the screen. The text field will be used to display the result. Dealing with storyboard is easier in XCode’s Assistance View. Connect the Outlets and Action and you are done. Once correctly done, your XXViewController.h will look like the following.

https://gist.github.com/subinsebastien/8802a3e0f42956ffd28b

Now it is the time for implementation. What we basically do is, create a NSURLConnection and make an asynchronous request with it. Once the response is received, which is by the way a JSON object, parse it to an NSDictionary. NSDictionary is further useful if you want to get the value of a particular key in the JSON or for doing such things. The implementation is as follows.

https://gist.github.com/subinsebastien/3b160b4192dd15179b29

The result is just awesome! You enter a city name, and what you get is the complete response displayed in the textview. It is not the world’s most attractive UI, but it is simple and easy get started with. Take a look.

image

Hope this is useful to somebody. Happy Hacking!

0 plays
Cody Martins,
Champion Sound

I need to do better than this, I need to go higher than this
and get in the game.
Try, Try to hold on to now, try to believe for now
Stay in the game

When the lights come on, the beat still remains
The strength inside, glory to gain

The shades of light, merge into one
As the broken skies clear from the sun
We’re the same, you and I
Reaching out to justify
Give me a chance, give me the time
Get in the game

We’re the same, you and I
Pushing through and knowing why
Give me a chance, give me the time
Get in the game

When the lights come on, heartbeat remains
Strength inside, glory to gain
We’re the same, you and I
Reaching out to justify
Give me a chance, give me the time
Get in the game

We’re the same, you and I
Pushing through and knowing why
Give me a chance, give me the time
Get in the game
Get in the game