Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.view.View;

import android.view.inputmethod.InputMethodManager;

public class Main {
    private static Context sCurrentContext;

    /**
     * <pre>
     * Show keyboard, typically in an activity having {@link EditText}.
     * </pre>
     * @param focusedView typically an {@link EditText}
     */
    public static void showKeyboard(View focusedView) {
        focusedView.requestFocus();
        InputMethodManager inputMethodManager = ((InputMethodManager) getCurrentContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE));
        inputMethodManager.showSoftInput(focusedView, InputMethodManager.SHOW_FORCED);
    }

    /**
     * <pre>
     * Get current context of the app. This method resolves the inconvenience of Android which requires context for most of its API.
     * If no activity is resumed, this method returns application context. Otherwise, this method returns last resumed activity.
     * </pre>
     */
    public static Context getCurrentContext() {
        return sCurrentContext;
    }
}