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 {
    /**
     * Explicitly request that the current input method's soft input area be
     * shown to the user, if needed.
     * 
     * @param view
     *            The currently focused view, which would like to receive soft
     *            keyboard input.
     */
    public static void showKeyboard(View view) {
        view.requestFocus();
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.RESULT_UNCHANGED_SHOWN);
    }

    /**
     * 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 showKeyboard(Activity activity) {
        if (null == activity) {
            return;
        }
        InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        View v = activity.getCurrentFocus();
        if (v != null) {
            im.showSoftInput(v, InputMethodManager.RESULT_UNCHANGED_SHOWN);
        }
    }
}