Example usage for android.view View getWindowToken

List of usage examples for android.view View getWindowToken

Introduction

In this page you can find the example usage for android.view View getWindowToken.

Prototype

public IBinder getWindowToken() 

Source Link

Document

Retrieve a unique token identifying the window this view is attached to.

Usage

From source file:com.xabber.android.ui.activity.ChatActivity.java

public static void hideKeyboard(Activity activity) {
    // Check if no view has focus:
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }/* w w  w .  jav a2 s .c  om*/
}

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

public static void hideKeyBroad(Activity activity) {
    try {//  w ww  .  ja va2s .  co m
        View currentView = activity.getCurrentFocus();
        if (currentView == null) {
            throw new Exception("Cannot get current focus");
        }
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(currentView.getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception ignored) {
    }
}

From source file:Main.java

public static void setSoftInputVisible(final View content, boolean visible, int delay) {
    final InputMethodManager imm = (InputMethodManager) content.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    if (visible) {
        if (delay > 0) {
            new Handler().postDelayed(new Runnable() {

                @Override//from  w  ww.  j a va  2 s . c o  m
                public void run() {
                    imm.showSoftInput(content, 0);
                }
            }, delay);
        } else {
            imm.showSoftInput(content, 0);
        }

    } else {
        if (delay > 0) {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    imm.hideSoftInputFromWindow(content.getWindowToken(), 0);
                }
            }, delay);
        } else {
            imm.hideSoftInputFromWindow(content.getWindowToken(), 0);
        }

    }
}

From source file:com.xiaomi.account.utils.SysHelper.java

public static void displaySoftInputIfNeed(Context context, View focusedView, boolean tryDisplay) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService("input_method");
    if (tryDisplay && context.getResources().getConfiguration().orientation == 1) {
        imm.showSoftInput(focusedView, 0);
    } else {//from  w ww. ja v a 2  s  . co m
        imm.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
    }
}

From source file:cc.metapro.openct.utils.ActivityUtils.java

public static AlertDialog addViewToAlertDialog(@NonNull final AlertDialog.Builder builder,
        @NonNull final View view) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);//  w  ww. ja va  2s  . c  o m
    }

    ScrollView scrollView = new ScrollView(builder.getContext());
    scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    scrollView.addView(view);

    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            InputMethodManager imm = (InputMethodManager) builder.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    });

    AlertDialog dialog = builder.setView(scrollView).create();
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
    return dialog;
}

From source file:util.Utils.java

/**
 * /* w ww .  j  a va  2  s  .  c o m*/
 *
 * @param context   Context
 * @param tokenView View
 */
public static void colseInputMethod(Context context, View tokenView) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(tokenView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

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

/**
 * Hide the keyboard//from w  ww.ja  v  a 2  s. 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:util.Utils.java

/**
 * //from   www  . j  a  v a 2 s . c om
 *
 * @param context   Context
 * @param tokenView View
 */
public static void openInputMethod(Context context, View tokenView) {
    tokenView.setFocusable(true);
    tokenView.requestFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInputFromWindow(tokenView.getWindowToken(), 0, InputMethodManager.SHOW_FORCED);
}

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

/**
 * Internal use only./*  w  w  w.  ja v a2  s .co  m*/
 */
public static void hideSoftKeyboard(Context context, View view) {
    if (context != null && view != null) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:org.csware.ee.utils.Tools.java

/**
 * ??//from  w ww . j  av  a2  s.  c  o  m
 */
public static void hideInput(Context context, View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}