Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

public class Main {
    /**
     * Request to hide the soft input window from the context of the window that
     * is currently accepting input.
     * 
     * @param activity
     *            The currently activity, which shows the view receives soft
     *            keyboard input.
     */
    public static void hideKeyboard(Activity activity) {
        if (null == activity) {
            return;
        }
        InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        View v = activity.getCurrentFocus();
        if (v != null) {
            im.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * Request to hide the soft input window from the context of the window that
     * is currently accepting input.
     * 
     * @param view
     *            he currently focused view, which would like to receive soft
     *            keyboard input.
     */
    public static void hideKeyboard(View view) {
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) view.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
}