Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.View;

public class Main {
    /**
     * Check whether is keyboard showing or hiding
     * @param rootView
     * @return
     */
    public static boolean isKeyboardShown(View rootView) {
        Rect rect = new Rect();
        rootView.getWindowVisibleDisplayFrame(rect);
        /* 
         * 128dp = 32dp * 4
         * Minimum button height 32dp and generic 4 rows soft keyboard (can be more than 4 rows)
         */
        final int SOFT_KEYBOARD_HEIGHT_DP_THRESHOLD = 128;
        DisplayMetrics dm = rootView.getResources().getDisplayMetrics();
        return dm.heightPixels - rect.bottom > SOFT_KEYBOARD_HEIGHT_DP_THRESHOLD * dm.density;
    }
}