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:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ??/*from  w w  w  .ja  v  a 2 s.  c om*/
 * @param activity
 */
public static void hideKeyBoard(Activity activity) {
    ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
            activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.bt.download.android.gui.util.UIUtils.java

public static void hideKeyboardFromActivity(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    View view = activity.getCurrentFocus();
    if (view == null) {
        view = new View(activity);
    }/*from   ww  w. ja va 2s.c o  m*/
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:com.vinexs.tool.Utility.java

public static void showKeyBroad(Activity activity) {
    try {/*from ww  w.j a  v  a2 s.c  om*/
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(activity.getCurrentFocus(), InputMethodManager.SHOW_IMPLICIT);
    } catch (Exception ignored) {
    }
}

From source file:com.orange.ocara.ui.activity.BaseActivity.java

public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    View focusedView = activity.getCurrentFocus();
    if (focusedView != null) {
        inputMethodManager.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
    }//www .ja  va  2s. com

}

From source file:com.frostwire.android.gui.util.UIUtils.java

public static void hideKeyboardFromActivity(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    View view = activity.getCurrentFocus();
    if (view == null) {
        view = new View(activity);
    }//from ww w .ja  v  a2 s .  co  m
    if (inputMethodManager != null) {
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

public static void clearFocus() {
    try {/*  ww w.  j a  v a2s . c o m*/
        //Log.i(TAG, "clearFocus");
        final Activity activity = IOuyaActivity.GetActivity();
        if (null != activity) {
            Runnable runnable = new Runnable() {
                public void run() {
                    View view = activity.getCurrentFocus();
                    if (null != view) {
                        view.setFocusable(false);
                        view.clearFocus();
                    }
                }
            };
            activity.runOnUiThread(runnable);
        }
    } catch (Exception e) {
        Log.e(TAG, "clearFocus: exception=" + e.toString());
    }
}

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 * Hide the keyboard//from   ww  w.j av  a 2s  .  c  o  m
 */
public static void hideKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:org.vqeg.viqet.activities.MainActivity.java

public static void setupUI(View view, final Activity activity) {

    view.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager inputMethodManager = (InputMethodManager) activity
                    .getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
            return false;
        }//w  w  w .j  a  v  a  2s .  c  o  m

    });
}

From source file:com.apptentive.android.sdk.util.Util.java

public static void showSoftKeyboard(Activity activity, View target) {
    if (activity != null && activity.getCurrentFocus() != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(target, 0);//from w  ww . ja va 2 s .  c om
    }
}

From source file:com.mezcaldev.hotlikeme.ChatActivity.java

public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);

    if (activity.getCurrentFocus() != null) {
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }/*from www  .j a v a 2 s .  c o m*/

}