Example usage for android.app Activity getCurrentFocus

List of usage examples for android.app Activity getCurrentFocus

Introduction

In this page you can find the example usage for android.app Activity getCurrentFocus.

Prototype

@Nullable
public View getCurrentFocus() 

Source Link

Document

Calls android.view.Window#getCurrentFocus on the Window of this Activity to return the currently focused view.

Usage

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    if (activity != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }/*from ww  w  . ja va 2  s .c  om*/
}

From source file:Main.java

public static void hideInput(Activity context) {
    InputMethodManager mInputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (mInputMethodManager.isActive())
        mInputMethodManager.hideSoftInputFromWindow(context.getCurrentFocus().getWindowToken(), 0);
}

From source file:Main.java

/**
 * Hide soft input from window.//from  w  ww  . j ava2  s.c o  m
 * @param activity
 */
public static void forceHideSoftInput(Activity activity) {
    try {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {

    }
}

From source file:Main.java

/**
 * Hide soft keyboard//  w ww  .ja v a  2 s  .c  om
 * @param activity The activity
 */
public static void hideSoftKeyboard(Activity activity) {
    final InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    //noinspection ConstantConditions
    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}

From source file:im.neon.activity.MXCActionBarActivity.java

/**
 * Dismiss the soft keyboard if one view in the activity has the focus.
 * @param activity the activity/*from  ww w  .ja v  a2s.  c  om*/
 */
public static void dismissKeyboard(Activity activity) {
    // hide the soft keyboard
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:com.hangulo.powercontact.util.Utils.java

public static void hideSoftKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        view.clearFocus();//from  w  w w .  j  a v a2  s  .com
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    //Find the currently focused view, so we can grab the correct window token from it.
    View view = activity.getCurrentFocus();
    //If no view currently has focus, create a new one, just so we can grab a window token from it
    if (view == null) {
        view = new View(activity);
    }//from   ww  w  . j a va  2s  .c o  m
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

/**
 * hide soft keyboard/*from   w w  w  .  ja  va 2 s .  c  om*/
 * @param activity
 */
public static void hideSoftKeyboard(Activity activity) {
    if (null == activity) {
        return;
    }
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (null != inputMethodManager) {
        View view = activity.getCurrentFocus();
        if (null != view) {
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }

    }
}

From source file:Main.java

/**
 * Close the soft key board/*w  w  w  .ja v  a 2  s.c o  m*/
 */
public static void closeSoftKeyBoard(Activity pActivity) {
    if (pActivity != null) {
        final InputMethodManager inputMethodManager = (InputMethodManager) pActivity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (inputMethodManager != null) {
            final View currentFocus = pActivity.getCurrentFocus();
            if (currentFocus != null) {
                inputMethodManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
            }

        }
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity, EditText edt) {
    final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (edt != null) {
        imm.hideSoftInputFromWindow(edt.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } else {//from  w  w w  . ja va 2  s  . co  m
        if (activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}