package com.lenguyenthanh.nimble.view;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;

public class ViewHelper {
  private ViewHelper() {
  }

  private static ViewHelper instance;

  public synchronized static ViewHelper getInstance() {
    if(instance == null){
      instance = new ViewHelper();
    }
    return instance;
  }

  public Activity getActivity(Context context) {
    while (!(context instanceof Activity) && context instanceof ContextWrapper) {
      context = ((ContextWrapper) context).getBaseContext();
    }
    if (!(context instanceof Activity)) {
      throw new IllegalStateException(
          "Expected an activity context, got " + context.getClass().getSimpleName());
    }
    return (Activity) context;
  }
}

@@ -141,16 +141,22 @@
 %0Apublic 
+final 
 class Vi
@@ -166,16 +166,56 @@
 elper %7B%0A
+%0A  private static ViewHelper instance;%0A%0A
   privat
@@ -235,30 +235,29 @@
 ) %7B%0A  %7D%0A%0A  p
-rivate
+ublic
  static View
@@ -267,27 +267,27 @@
 per 
-i
+getI
 nstance
-;%0A%0A  public
+() %7B%0A   
  syn
@@ -296,23 +296,17 @@
 ronized 
-static 
+(
 ViewHelp
@@ -311,31 +311,27 @@
 lper
- getInstance(
+.class
 ) %7B%0A
+  
     if
+ 
 (ins
@@ -344,18 +344,21 @@
 == null)
+ 
 %7B%0A
+  
       in
@@ -380,24 +380,32 @@
 ewHelper();%0A
+      %7D%0A
     %7D%0A    re
@@ -458,16 +458,22 @@
 ity(
+final 
 Context 
 cont
@@ -468,17 +468,21 @@
 Context 
-c
+viewC
 ontext) 
@@ -479,24 +479,59 @@
 wContext) %7B%0A
+    Context context = viewContext;%0A
     while (!

Fix potential bugs follow PMD