Saturday 10 December 2016

IntelliJ: Live Template for generating a single parameter constructor

Here's an IntelliJ / Android Studio Live Template for generating a constructor that takes in a single parameter and sets that parameter into a class field:

@android.support.annotation.NonNull
private final $dependencyClass$ $dependency$;

private $constructorClass$(@NonNull $dependencyClass$ $dependency$){
    this.$dependency$ = $dependency$;
}

Set the "Applicability" of the Live Template to be "Java declarations" and set the "Expression" associated to each of the variables as follows:
  • $dependencyClass$ -> completeSmart()
  • $dependency$ -> suggestVariableName()
  • $constructorClass$ -> className()
Tick the "Skip if defined" option for the $constructorClass$ variable and set the "Abbreviation" and "Description" for the Live Template as you wish and that's it... you're good to go!

Thursday 8 December 2016

IntelliJ: Live Template for generating static nested Factory class

If you find yourself having to create a static nested Factory class time and time again then you'll find the following IntelliJ / Android Studio Live Template handy:

public static class Factory {

    @android.support.annotation.NonNull
    private final $dependencyClass$ $dependency$;

    Factory(@NonNull $dependencyClass$ $dependency$){
        this.$dependency$ = $dependency$;
    }

    @NonNull
    public $createdClass$ create(){
        return new $createdClass$($dependency$);
    }
}

Set the "Applicability" of the Live Template to be "Java declarations" and set the "Expression" associated to each of the variables as follows:
  • $dependencyClass$ -> completeSmart()
  • $dependency$ -> suggestVariableName()
  • $createdClass$ -> className()
Tick the "Skip if defined" option for the $createdClass$ variable and set the "Abbreviation" and "Description" for the Live Template as you wish and that's it... you're good to go!

Monday 2 May 2016

Quran SDK (library) for Android

I've put together a couple of Android apps in my spare time the last few years which make use of verses of the Quran (Hifdh Tracker and Hifdh Tester). I'm in the process of extracting out some of the code in these apps so that it's available in open source. As a first step I've just extracted the database and the helper methods for accessing verses of the Quran out of the apps and into an Android library of its own. You can find the repository for the library here. The README in the repository explains how to incorporate and make use of the library in your own Android apps.