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 showPanel(View panelLayout) {
    final Activity activity = (Activity) panelLayout.getContext();
    panelLayout.setVisibility(View.VISIBLE);
    if (activity.getCurrentFocus() != null) {
        hideKeyboard(activity.getCurrentFocus());
    }/* w w  w.j ava  2  s . com*/
}

From source file:com.justplay1.shoppist.utils.ViewUtils.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 ww  .  j a v a2s . c o  m
}

From source file:Main.java

public static void hideKeyBoard(Activity aty) {
    ((InputMethodManager) aty.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
            aty.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void hideInputMethodManager(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View v = activity.getCurrentFocus();
    if (imm != null && v != null) {
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }//w  ww.  j av  a  2  s .  c om
}

From source file:Main.java

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

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

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

From source file:Main.java

public static void hideSoftKeyboard(Activity a) {
    InputMethodManager inputMethodManager = (InputMethodManager) a
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (a.getCurrentFocus() != null && a.getCurrentFocus().getWindowToken() != null)
        inputMethodManager.hideSoftInputFromWindow(a.getCurrentFocus().getWindowToken(), 0);
}

From source file:Main.java

public static void colseSoftKeyboard(Activity activity) {
    InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    im.hideSoftInputFromWindow(activity.getCurrentFocus().getApplicationWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

@SuppressWarnings("static-access")
public static void hideSoftInput(Activity activity) {
    InputMethodManager imm = ((InputMethodManager) activity.getSystemService(activity.INPUT_METHOD_SERVICE));
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}