/*
 * Copyright (c) 2015 NECTEC
 *   National Electronics and Computer Technology Center, Thailand
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.tanrabad.survey.utils.android;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

public class SoftKeyboard {

    public static void hideOn(Activity activity) {
        View currentFocus = activity.getCurrentFocus();
        if (currentFocus != null) {
            InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
        }
    }

}

@@ -731,40 +731,8 @@
 ty;%0A
-import android.content.Context;%0A
 impo
@@ -806,16 +806,77 @@
 nager;%0A%0A
+import static android.content.Context.INPUT_METHOD_SERVICE;%0A%0A
 public c
@@ -943,24 +943,100 @@
 activity) %7B%0A
+        // from answer at StackOverflow https://stackoverflow.com/q/7696791%0A
         View
@@ -1108,23 +1108,64 @@
 cus 
-!
+=
 = null)
- %7B
 %0A
+ 
     
+       currentFocus = new View(activity);%0A
     
@@ -1213,17 +1213,16 @@
 Manager)
- 
 activity
@@ -1239,24 +1239,16 @@
 Service(
-Context.
 INPUT_ME
@@ -1262,20 +1262,16 @@
 RVICE);%0A
-    
         
@@ -1337,18 +1337,8 @@
 0);%0A
-        %7D%0A
     

Add Reference