Example usage for android.content.res Configuration HARDKEYBOARDHIDDEN_NO

List of usage examples for android.content.res Configuration HARDKEYBOARDHIDDEN_NO

Introduction

In this page you can find the example usage for android.content.res Configuration HARDKEYBOARDHIDDEN_NO.

Prototype

int HARDKEYBOARDHIDDEN_NO

To view the source code for android.content.res Configuration HARDKEYBOARDHIDDEN_NO.

Click Source Link

Document

Constant for #hardKeyboardHidden , value corresponding to the physical keyboard being exposed.

Usage

From source file:org.navitproject.navit.Navit.java

/**
 * @brief Shows the native keyboard or other input method.
 * /*from   w  w w .  ja v  a  2 s  . c  o  m*/
 * @return {@code true} if an input method is going to be displayed, {@code false} if not
 */
public int showNativeKeyboard() {
    /*
     * Apologies for the huge mess that this function is, but Android's soft input API is a big
     * nightmare. Its devs have mercifully given us an option to show or hide the keyboard, but
     * there is no reliable way to figure out if it is actually showing, let alone how much of the
     * screen it occupies, so our best bet is guesswork.
     */
    Configuration config = getResources().getConfiguration();
    if ((config.keyboard == Configuration.KEYBOARD_QWERTY)
            && (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))
        /* physical keyboard present, exit */
        return 0;

    /* Use SHOW_FORCED here, else keyboard won't show in landscape mode */
    mgr.showSoftInput(getCurrentFocus(), InputMethodManager.SHOW_FORCED);
    show_soft_keyboard_now_showing = true;

    /* 
     * Crude way to estimate the height occupied by the keyboard: for AOSP on KitKat and Lollipop it
     * is about 62-63% of available screen width (in portrait mode) but no more than slightly above
     * 46% of height (in landscape mode).
     */
    Display display_ = getWindowManager().getDefaultDisplay();
    int width_ = display_.getWidth();
    int height_ = display_.getHeight();
    int maxHeight = height_ * 47 / 100;
    int inputHeight = width_ * 63 / 100;
    if (inputHeight > (maxHeight))
        inputHeight = maxHeight;

    /* the receiver isn't going to fire before the UI thread becomes idle, well after this method returns */
    Log.d(TAG, "showNativeKeyboard:return (assuming true)");
    return inputHeight;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Return TRUE if there is a hardware keyboard and is being made visible.
 * /*from ww  w.j a  va  2 s  .co  m*/
 * @param context
 * @return
 */
public static boolean device_isHardwareKeyboardVisible(Context context) {
    //You can also get some of the features which are not testable by the PackageManager via the Configuration, e.g. the DPAD.
    Configuration c = context.getResources().getConfiguration();
    if (c.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_UNDEFINED
            && c.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
        return true;
    } else {
        return false;
    }
}