Amazon Gift Cards

Monday, October 3, 2016

Android Links 3

Android round of android links :)

1) Kotlin for Android developers

Why you should consider kotlin as a development language for android

2) ConstraintLayout links
Here are few links that talks about the new layout.
ConstraintLayout, Inside and Out: Part 1
ConstraintLayout, Inside and Out: Part 2

3) MPAndroidChart
This is graphing library which is really useful if you need to add graphs on your app.

4) 80+ Best Resources for Android Developers 2016 (Blogs, Forums & More)
This is a really good list for resource for Android developers.

Wednesday, August 10, 2016

PaperParcel with Kotlin

When I started to code in kotlin, one of the libraries that I found that was really useful is PaperParcel. PaperParcel is a library that would generate Parcelable using annotation. The good thing about it, is that it will reduce the amount of code and mistake you could make if you manually create those classes. Having said that, the library is not purely for Kotlin and it could be used in Java Android project.

To use it in kotlin
You will need to add these to your app build gradle dependencies
compile 'com.github.grandstaish.paperparcel:paperparcel:1.0.0-rc4'
compile 'com.github.grandstaish.paperparcel:paperparcel-kotlin:1.0.0-rc4'
kapt 'com.github.grandstaish.paperparcel:compiler:1.0.0-rc4'
while still in that gradle file, add these before dependencies
kapt {
    generateStubs = true
repositories {
    maven { url '' }

Now the fun part, this is taken from my app Daily Picture Quotes
data class QuoteImage(val id: String = "",
                 val name: String = "",
                 val text_quote: String = "",
                 val url: String = "",
                 val created: String = "",
                 val cursor:String? = "") : PaperParcelable {
    companion object {
        @JvmField val CREATOR = PaperParcelable.Creator(

Thats about it, you can use QuoteImage to pass around Activities or Fragment or use it with your custom class.

Two things you have to remember is that your data class name must be supplied in PaperParcelable.Creator and every time you make changes to this data class (atleast for me) you have to do rebuild project.

If this interest you then have a check on the kotlin usage section of their github page.

Hope this helps :)

Wednesday, August 3, 2016

Easier way of getting your layout view in kotlin

As an Android developer, findViewById is probably one of the most annoying code piece you will keep using. However there are libraries that ease this daunting task, one of which I constantly use in Java is ButterKnife. Where you would have something like
public class MainActivity extends AppCompatActivity{
    protected void onCreate(Bundle savedInstanceState) {
        mTabLayout = (TabLayout) findViewById(;
        mAddBtn = (Button) findViewById(;

to something cleaner and easier to understand
public class MainActivity extends AppCompatActivity{
    @BindView( Button mAddBtn;
    @BindView( TabLayout mTabLayout;

    protected void onCreate(Bundle savedInstanceState) {

Now in kotlin, there are different options that I had encountered so far.
One of which is KotterKnife which is also from Jake Wharton, the creator of ButterKnife. The library has the same awesomeness as ButterKnife, just check out the example on its github page

Another method is anko's find method, I previously blogged about Anko in Android and how you can use it to create UI in code, but anko is more than that. It has a lot of awesome helper functions and one of it is find, which is a shortform for findViewById and the code would look like this
class MainActivity: AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        mTabLayout = find<TabLayout>(
        mAddBtn = find<Button>(

Lastly most probably the lazies solution, but might be not be the most readable one is by using Kotlin Android Extensions. It will automatically bind the views to a class which you will just have to import. To configure it, open your app's gradle file and add on the top
apply plugin: 'kotlin-android-extensions'

Then say you have a layout named activity_main.xml with table_layout and add_btn on it. On your kotlin activity, fragment or custom class just add

And viola, you can already use table_layout and add_btn like this
class MainActivity: AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        add_btn.onClick {
            toast("hello world")

Monday, August 1, 2016

SMS Quotes - Simply Make Sharable Quotes Rewrite in Kotlin

I just rewrite one of my app completely in kotlin, check it out. Simply Make Sharable Quotes
In light of this i'll blog in the following days what I learned from the rewrite :)

Thursday, June 2, 2016

Conference Developer Videos - New App

Announcing my first kotlin android app Conference Developer Videos. It features videos from different languages and technologies, it also have lists for you to add videos into. Please help rate the app. Thank you in advance :)

Incase you don't have Android, it is on the web at

I created a patreon page to those who are willing to help/donate, my plan is that I want it to be my full time job as there are tons of features to include like notifications, make an ios app and a lot more. Help support the site

Tuesday, April 26, 2016

Android Kotlin with Anko

I recently found an interest in Android, this time with Kotlin and Anko. Kotlin is an alternative language to build Android App and it's a more modern language therefore it has its own advantage and possibly cleaner way to program then Java. Jetbrains made an amazing job with IntelliJ in making sure that you can create Android Apps. Having said that, here is a tutorial on how to start your first Kotlin Android App. Getting started with Android and Kotlin.

Incase you encounter an error, open your app's build.gradle and replace the contents with the generated content from kotlin build.gradle generator. Note that this has anko in its dependencies.

So what is Anko? From its github page Anko is a library which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of Android SDK for Java. It's mostly known for its DSL for making UI but there are few view related extensions that are quite helpful in developing new apps.

Let's see how Kotlin and Anko works. Here is an example of a sharing fragment class
class ShareFragment: Fragment() {
    companion object {
        val FACEBOOK_URL = ""

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
 savedInstanceState: Bundle?): View? {
        return UI {
            linearLayout {
                orientation = LinearLayout.VERTICAL
                gravity = Gravity.CENTER_HORIZONTAL

                textView("Share to FB")

                imageButton {
                    imageResource = R.drawable.facebook
                    onClick {

                textView("Sharing to other network will appear later")

Just reading from the UI part you would know that this is a linearLayout with gravity horizontally centered and its children is stacked vertically. The first child is textView with text Share to FB, below it is an imageButton with resource drawable named facebook. Then below it is also a textView with the text Sharing to other network.

You might be wondering what is this, this is called extensions. In kotlin, you can extend base class with your custom functions. With this specific code the owner is a Fragment. So i would have a code like
fun Fragment.gotoUrl(url: String) {
    val intent: Intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))

The advantage of doing this is that if you decided to put a share button in another fragment you wont have to duplicate the code. Kotlin advices to use this approach then using an utility based approach. And for me, this way is a lot cleaner.

You could put the Fragment.gotoUrl at the end of the class or a more organised approach is to create an class with all your view related extensions, i called mine ViewExtensions.kt. Here is a gist.

I have just started to learn kotlin and I found it to be interesting. Hope this helps :)