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 showInputMethod(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        imm.showSoftInput(currentFocus, InputMethodManager.SHOW_IMPLICIT);
    }/*from  w  ww.j  a  v a2  s .  co  m*/

    //        if (imm != null) {
    //            imm.viewClicked(this);
    //        }
    //        if (imm != null && getShowSoftInputOnFocus()) {
    //            imm.showSoftInput(this, 0);
    //        }
}

From source file:Main.java

public static void hiddenKeyboard(Class className, Context context, Activity activity) {
    try {/*from   w ww  .  j  a  v  a 2s  .  c om*/
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

        if (activity.getCurrentFocus() != null) {
            if (activity.getCurrentFocus().getWindowToken() != null) {
                imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.arlib.floatingsearchview.util.Util.java

public static void closeSoftKeyboard(Activity activity) {

    View currentFocusView = activity.getCurrentFocus();
    if (currentFocusView != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0);
    }//w w  w .ja  va 2  s.  co m
}

From source file:Main.java

public static void hidekeyboard(Activity act) {
    InputMethodManager imm = ((InputMethodManager) act.getSystemService(Activity.INPUT_METHOD_SERVICE));
    if (imm.isActive()) {
        View focusView = act.getCurrentFocus();
        if (focusView != null) {
            imm.hideSoftInputFromWindow(focusView.getWindowToken(), 0);
        }/*w  w  w .java 2  s . c o  m*/
    }
}

From source file:Main.java

public static void hideSoftInput(Activity activity) {
    try {/*from  w w  w .  j a v a2 s. co  m*/
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

/**
 * This method hides the keyboard/*from   w w  w  . j av  a2s. c  om*/
 *
 * @param activity
 *         Active activity
 */
public static void hideKeyboard(Activity activity) {
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    View view = activity.getCurrentFocus();
    if (view != null) {
        inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:Main.java

public static void hideSoftKeyborad(Activity context) {
    if (context == null)
        return;/*ww  w .j  a va  2s . c  o m*/
    ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
            context.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void closeInput(Activity context) {

    try {/*from  w  w w . j  a  v  a2s  .c o  m*/
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

        imm.hideSoftInputFromWindow(context.getCurrentFocus().getWindowToken(), 0);

    } catch (Exception e) {

    }
}

From source file:Main.java

/**
 * Dismiss the keyboard for the given activity.
 * @param activity to dismiss associated keyboard for.
 *//*from  w  w  w.  ja  v  a 2  s  .c  om*/
public static void hideKeyboard(@NonNull Activity activity) {
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    View focus = activity.getCurrentFocus();
    if (focus != null) {
        inputManager.hideSoftInputFromWindow(focus.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyboard(android.app.Activity _activity) {
    InputMethodManager inputManager = (InputMethodManager) _activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    if (_activity.getCurrentFocus() != null) {
        inputManager.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } else {/*from ww  w .  j ava2s  . co  m*/
        inputManager.hideSoftInputFromWindow(null, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}