Android: Building a re-usable Custom View

You have a group of elements. They interact with each other. This group needs to be repeated within the same Activity or across activities.

This can be done by creating a custom view. A custom view is a class that extends ViewGroup or any other layout class (eg. LinearLayout, FrameLayout etc.,) that extends ViewGroup. The custom view can be instantiated from XML directly or programmatically as well.

Creating a Custom View

Java Class
  1. Decide the root element for your Custom View and extend your class from that.
  2. Add all the elements that your view holds
  3. Define constructors with custom parameters if needed
  4. Define click listeners and other interactions

Example: A view with a Button and a TableLayout

You could pass data to your constructor for using it to build the elements in your view.

XML Layout


Using the View

Now that the custom layout and the view class is defined, we can instantiate that now.

If you need to repeat the custom view for a list of SomeObject, you can do that as well.

What the Rains did to Chennai: In 23 Photos

  1. Near Chennai Central

Near Central Railway Station. Credits -

2. About 4 ft swimming pool

About 4 ft swimming pool. Credits -

3. Free washing

"At first I thought what idiot will leave their clothes out to dry in this weather...then I realized I am the idiot... They have left the clothes to be washed.." Credits -
“At first I thought what idiot will leave their clothes out to dry in this weather…then I realized I am the idiot… They have left the clothes to be washed..”

4. Near Chromepet

Near Chromepet. Credits -

5. In a railway subway

Credits -

6. Vetri theatre (Chromepet)


7. Marina Beach, extended


8. Duraisamy subway (West Mambalam)


9. Gondola to the rescue


10. Neck deep


11. Traveling in Cranes


12. There are some good cops too


13. He had to :)


14. Arumbakkam Metro Station


15. Tidel Park


16. Ascendas Tech Park


17. Sathyabama College


18. Rescue Service




20. Endless traffic (GST Road)


21. College Hostel?


22. Inside MTC AC Bus


23. It’s time for some Cricket


24. And here is a Bonus Video:


Distributed Elixir – Two different machines

For one of my talks on Elixir, I was preparing for a demo. To deploy hot code from one machine to another machine. Doing it within the same machine with two iex sessions is not cool :)

I installed a VM (CentOS) in my Mac. Actual app was running in Mac and I pushed a new code from CentOS. So here are the learnings:

  1. Install the same version of Erlang and Elixir. Mine was 18 and 1.1.1 respectively
  2. Disable firewall in the guest OS (to allow epmd to talk on PORT 4369)
  3. Ensure you keep the same content in the ~/.erlang.cookie file in both the machines
  4. Ensure that you are able to ping from both the machines to the other one
  5. epmd is running in both the machines
  6. Use IP address as long names when using IEx

Setting up Cucumber Android with Android Studio

I was setting up Cucumber for my Android project. Cucumber is a BDD way to write tests.

Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business-readable domain-specific language and serves as documentation, automated tests and development-aid – all rolled into one format.

I use Gradle. This link from the official GitHub account of Cucumber should be your starting point.

  1. Download the latest version of the following files from the public maven Repo:
    • cucumber-android.jar
    • cucumber-core.jar
    • cucumber-html.jar
    • cucumber-java.jar
    • cucumber-junit.jar
    • cucumber-jvm-deps.jar
    • gherkin.jar

2. Put these files into “project-root / app / libs” and add this dependencies block of app/build.gradle

3. Gradle Sync. If you get any errors, check the list of errors below.

4. Add a new AndroidManifest.xml for your androidTest project in this location – project-root / app / src / androidTest / java /

5. Add a new class (eg – CucumberTestCase) that extends AndroidTestCase at “project-root/ app / src / androidTest / java / com / duggout /” with the below code:

6. Add a new class (eg – TestSteps) at “project-root / app / src / androidTest / java / com / duggout / steps /” to write your steps:

7. Write your first feature file at “project-root / app / src / androidTest / java / com / duggout / assets / features / “:

8. Run the feature test within Android Studio using Ctrl + Shift F10.

Screen Shot 2015-09-26 at 2.44.25 PM

I faced the following errors when setting up:

  1. Gradle Sync fails

Error:Execution failed for task ‘:app:preDexDebug’. org.gradle.process.internal.ExecException: Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java” finished with non-zero exit value 1

Since this message is not very helpful, you need to use the gradle command to find the actual cause of this error.

/gradlew clean assembleDebug –info (note the double hyphen)

For me, the issue was with cucumber-jvm-deps.jar (version 1.0.5). It had an incompatible class for Java 8. I downgraded it to 1.0.3 to solve it.

2. Build variants – Open Build Variants Tool Window in Android Studio and set the build type to Instrumentation

3. If you get “Undefined step” error, make sure you have created a class that extends AndroidTestCase and added CucumberOptions annotation with necessary parameters

4. If you get “java.lang.RuntimeException: Stub! ” in your JUnit assertEquals method, add junit in testCompile in your build.gradle as the first dependency. Or the 2nd dependency after the compile for libs directory.

5. When running from the command line using ‘./gradlew –info cC’, if you get “cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.”, remove “@RunWith(Cucumber.class)” from the file

#HelloElixir – 5 Reasons to get started


Elixir was started in 2011 by Josè Valim, one of the core contributors to Ruby on Rails. Elixir is not Ruby for Erlang.

  1. Compiled and Scripted

    • Runs on Erlang VM – Elixir is written on top of Erlang. Elixir code is compiled to BEAM code that runs on Erlang VM. So you get the same performance as running an Erlang code. Erlang VM is popular for running low-latency, distributed and fault-tolerant systems.
    • REPL – Elixir can also be run as scripts without the need to compile. It has a REPL named iex (similar to irb for ruby) where you can learn to write simple Elixir code. “Everything is an expression” in Elixir.
    • Interoperate with Erlang modules – You can mix native Erlang modules when Elixir does not have support for something. Just prefix the module name with a colon.
    • Immutability – Everything is immutable in Elixir.
    • Metaprogramming – Elixir supports metaprogramming. Code eval:

      It can also compile code on the fly:
  2. Actor Model and “Shared Nothing”

    • Process-oriented – Every piece of code in Elixir runs under a process. This is different from the processes in OS. Processes in Elixir are light-weight and it is common to have thousands of processes running in a single machine. Even iex is running under a process.

      Processes communicate via messages. Just like your mailboxes. You can send and receive messages in your process. An example to send a message to self.

      I have used pattern matching above to capture the message into the ‘content’ variable. Another example to send a message to a spawned process:

    • Purely functional – There are no .new()/objects/instances in Elixir. The only way to maintain some state is to create a Process and make it respond with state information. Because of this nature, one has to use the Module methods to do an operation on a type. For example, to find the first item in a list:

      When we would want to chain multiple methods, the syntax becomes unreadable. Elixir solves this with the pipeline operator |>. Here is an example from Elixir Express:

      Without Pipeline operator:

      With Pipeline operator:

      Basically, the output of the first expression is passed as the first argument to the second method.

    • Concurrent – Because of it’s process oriented design, it is natural that concurrency is at its heart.
  3. Fault Tolerant and Distributed Programming

    • Supervisors – In a typical Java application, we would do this:

      One of Elixir’s philosophy is “fail fast”. Though Elixir supports try/rescue, it recommends developers to use only when really required. When you invoke a task, you can invoke it via Supervisors. When a child task crashes for some reason, the Supervisor ensures that the child is restarted to the state where it was known to work the last time.

    • Map-Reduce – Elixir let’s you run a CPU/Network intensive task on multiple nodes and aggregate them as tasks are complete. In my example, the reducer task is started only when all map tasks are complete. To parallelize map and reduce, follow this. Let’s pick up the usual task of grouping words by their length:

      I am submitting parallel tasks only for Map. Reduce task runs from the master machine itself. Submitting tasks and getting the output: 

  4. Rails like Web Framework

    • Phoenix Framework built with Elixir – You should check out the site.

      “A productive web framework that does not compromise speed and maintainability”

    • MVC – You know what it is
    • Ecto – Model, Migration, Validators etc.,
    • Channels – Websockets support
    • TDD
    • Build tools
    • Asset Pipeline
    • Screen Shot 2015-08-09 at 3.09.16 PM
      But, can Rails scale? Phoenix can.
  5. Hot Code Reloading and Non Stop Applications

    • What is it?  – Erlang VM can hold two versions of the same module in its memory. When you are making a process call to this module, VM provides the latest version. So the Module with the old version dies automatically when no processes are actually holding it. Read more about it here and here. Imagine an app where you don’t need to upload the new JAR and restart the service.
    • An example – I can update a Module’s definition from another host when the process is running. Here is a GIF that shows two IEx sessions – one updating the code of the other while the session is running:
    • Elixir - Hot code reloading
Ofcourse, there is much more to the list – Pattern matching, rich data structures, Mix tool, OTP, Lazy loading, Streams, Generators etc.,
Elixir is mature enough and the eco system is fairly big enough to be able to use it in Production.
Elixir Community is on Slack.

#HelloElixir – Ruby like binding.pry in Elixir

One of the best debugging tools in Ruby is it’s ability to pause at any point in code using binding.pry. Elixir has a similar one too – IEx.pry.

For a sample module like this:

Here is how you would use it:

You could evaluate the local variables that were in scope before the pry session was invoked. You could change the value of those variables in the pry session but it will not affect the values of the variables in the original IEx session.

Invoke respawn command to exit the pry session.

Android: Drag to Refresh with ListView

Providing ‘Drag to Refresh’ support for an Activity with only ListView is a problem. Since ListView itself has a scroll functionality, it conflicts with the scroll of SwipeRefreshLayout.

The current behaviour that begins the refresh when we just want to scroll the list to the top:

Scrolling Conflict

To fix this, you need to override the onScrollStateChanged and onScroll of your ListView’s setOnScrollListener.

Build the layout XML of your activity like this:

You will have a root RelativeLayout. It’s only child is a SwipeRefreshLayout. It’s only child again is a LinearLayout which holds your ListView and an optional loading panel.

And in your Activity’s onCreate method:

You will enable the swipeContainer only when the ListView is already scrolled to the top.

See how it is fixed now:


Did this fix the scrolling problem?

Phoenix Framework – Ecto Cheat Sheet

For all the examples below, we are using the following names:
Project name – HelloPhoenix

Model name – Message with two columns – content and owner

1. Create an Ecto Model:

phoenix.gen.model generates only the model.

phoenix.gen.html generates Controllers, Models and Templates.

2. Persist a model in database:

  1. Create a map using the attributes of your model and the values.
  2. Create a changeset using Model.changeset(ModelClass, map). Changeset is an intermediate dataset on which validations are performed.
  3. Repo.insert!(changeset) to do the actual insert.

3. Fire a SELECT query

a. Using a model: Select 10 messages ordered by inserted_at desc.

b. Using raw SQL:

If you do not have a model defined, you can use the table name directly as a string.

generates a SQL: select name from posts where > 0;

For custom raw SQL:

4. Update a model

  1. Get the existing model using Repo.get(ModelClass, primary_key_value)
  2. Mutate the model by applying the new values using | operator.
  3. Update with Repo.update(model)


100 words you should use if you are a ThoughtWorker

  1. Smell
  2. Does it scale?
  3. RESTful
  4. Build
  5. Merge Conflicts
  6. WFH
  7. Pairing
  8. Retro
  9. DevOps
  10. End-Point
  11. Pipeline
  12. Is it covered?
  13. Concurrent
  14. Hack
  15. Agile
  16. CRUD
  17. Microservices
  18. Design Pattern
  19. Devbox
  20. UX
  21. Defect
  22. HackerNews
  23. Sign up
  24. Dev Huddle
  25. PubSub
  26. Feedback
  27. Yoda
  28. Transaction
  29. Release
  30. Standup
  31. Context
  32. Roll off
  33. Is it in Prod?
  34. Expense
  35. Community
  36. Travel
  37. Log
  38. Delivery
  39. Team outing
  40. Bootcamp
  41. People Champion
  42. Clone
  43. Open Culture
  44. In Analysis
  45. MacBook
  46. Catchup
  47. Infrastructure
  48. Ready for Sign off
  49. Recruitment
  50. Fork
  51. Immersion
  52. Flat structure
  53. Intern
  54. Spike
  55. Process
  56. Git Patch
  57. Last Mile
  58. In Dev
  59. Lateral
  60. Global Assignment aka GA
  61. Low latency
  62. Sick Leave
  63. Grad
  64. Customer
  65. Inception
  66. STEP
  67. Campus
  68. Iteration
  69. Scrum
  70. Thought Process
  71. Exit
  72. Culture
  73. Local Market
  74. Callback
  75. Fire and Forget
  76. Benefits
  77. QA
  78. University
  79. Sub Millisecond
  80. Timesheet
  81. Value Add
  82. Vacation
  83. Atomic
  84. Volleyball
  85. Deploy
  86. Meetup
  87. Parked
  88. Black box
  89. Training
  90. Downstream
  91. Go Live
  92. Threads
  93. Away Day
  94. Policy
  95. Conference
  96. DropBox
  97. Check-in
  98. Credibility
  99. Performance
  100. Pass/Pursue
Bonus Words:
  1. Service Boundary
  2. Artifacts


I am happy to announce to public. It was in beta with internal testing with my friends for the past few months. If you watch Cricket, then you should start using the site right away!

Some highlights from the site:

Player Profile, Stats and News, MS Dhoni’s profile:

MS Dhoni - Player profile



Open Cricket Search: Search for anything in Cricket

For example, ask when was the last time south africa chased down 400+ successfully? and you’ll get the answer as “12 March 2006”

when was the last time south africa chased down 400+ successfully?