Example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

List of usage examples for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow.

Prototype

public boolean hideSoftInputFromWindow(IBinder windowToken, int flags) 

Source Link

Document

Synonym for #hideSoftInputFromWindow(IBinder,int,ResultReceiver) without a result: request to hide the soft input window from the context of the window that is currently accepting input.

Usage

From source file:com.game.simple.Game3.java

public static void hideKeyboard() {
    if (self.getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) self
                .getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(self.getCurrentFocus().getWindowToken(), 0);
    }/*w w  w  .ja v a 2  s.  com*/
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void animateScanResultFragment() {
    try {/*  ww w  . j av  a 2  s .  c  o  m*/
        final MainActivity app = MainActivity.app;
        if (app == null || scanResultFragmentOn)
            return;
        CustomPagerAdapter.adapter.showFragments(false, app);
        scanResultFragmentOn = true;
        InputMethodManager keyboard = (InputMethodManager) app.getSystemService(Context.INPUT_METHOD_SERVICE);

        try {
            keyboard.hideSoftInputFromWindow(
                    CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        app.setBurgerButtonImage(BRConstants.BACK);
        //Disabled inspection: <Expected resource type anim>
        final FragmentManager fragmentManager = app.getFragmentManager();
        final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        final FragmentScanResult scanResult = new FragmentScanResult();
        fragmentTransaction.replace(R.id.main_layout, scanResult, FragmentScanResult.class.getName());
        fragmentTransaction.commit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                TranslateAnimation trans = new TranslateAnimation(MainActivity.screenParametersPoint.x, 0, 0,
                        0);
                trans.setDuration(500);
                trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                View view = scanResult.getView();
                if (view != null)
                    view.startAnimation(trans);
            }
        }, 1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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/* www. j  a va 2 s.  co 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  w  w  .ja v  a 2  s  . c om*/
        imm.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
    }
}

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);
    }// w  ww.ja  va  2s  .  c o  m
    if (inputMethodManager != null) {
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

/**
 * Animate the transition on burgerButton/MenuButton pressed
 *//* www.  j a v a2 s . c  o m*/
public static void pressMenuButton(final MainActivity context) {
    try {
        if (context == null)
            return;
        ((BreadWalletApp) context.getApplication()).cancelToast();
        final FragmentManager fragmentManager = context.getFragmentManager();
        if (level == 0) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.startServer();
                    }
                }).start();
            level++;
            CustomPagerAdapter.adapter.showFragments(false, context);
            context.setBurgerButtonImage(BRConstants.CLOSE);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            FragmentSettingsAll to = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            if (to == null)
                to = new FragmentSettingsAll();
            fragmentTransaction.add(R.id.main_layout, to, FragmentSettingsAll.class.getName());
            fragmentTransaction.commit();
            final FragmentSettingsAll finalTo = to;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    TranslateAnimation trans = new TranslateAnimation(0, 0, 1920, 0);
                    trans.setDuration(500);
                    trans.setInterpolator(new DecelerateOvershootInterpolator(3f, 0.5f));
                    View view = finalTo.getView();
                    if (view != null)
                        view.startAnimation(trans);
                }
            }, 1);

            InputMethodManager keyboard = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            if (keyboard != null)
                keyboard.hideSoftInputFromWindow(
                        CustomPagerAdapter.adapter.mainFragment.addressEditText.getWindowToken(), 0);
        } else if (level == 1) {
            if (PLATFORM_ON)
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        HTTPServer.stopServer();
                    }
                }).start();

            level--;
            context.setBurgerButtonImage(BRConstants.BURGER);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setCustomAnimations(R.animator.from_top, R.animator.to_bottom);
            FragmentSettingsAll fragmentSettingsAll = (FragmentSettingsAll) fragmentManager
                    .findFragmentByTag(FragmentSettingsAll.class.getName());
            fragmentTransaction.remove(fragmentSettingsAll);
            fragmentTransaction.commit();
            CustomPagerAdapter.adapter.showFragments(true, context);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

/**
 * Hide the keyboard/*from   w  ww  .j ava 2s .co  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:com.apptentive.android.sdk.util.Util.java

/**
 * Internal use only.//from  w w  w. j a  va  2  s.  com
 */
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 www  .ja v a  2 s .  c  om*/
 */
public static void hideInput(Context context, View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:com.lee.sdk.utils.Utils.java

/**
 * Hides the input method.//from   www . j a va 2 s.c  om
 * 
 * @param context context
 * @param view The currently focused view
 * @return success or not.
 */
public static boolean hideInputMethod(Context context, View view) {
    if (context == null || view == null) {
        return false;
    }

    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    return false;
}