Code example for Rect

Methods: getWindowVisibleDisplayFrame

0
     
    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    	int height = MeasureSpec.getSize(heightMeasureSpec);
        Activity activity = (Activity)getContext();
        Rect rect = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        int statusBarHeight = rect.top;
        int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight();
        int diff = (screenHeight - statusBarHeight) - height;
        if (listener != null) {
//        	Log.d("Matji", (keyboardState) + ", " + diff+ ", " +  ASSUMED_MINIMUM_KEYBOARD_HEIGHT); 
        	if (keyboardState == KeyboardState.keyboardStateShow && diff <= ASSUMED_MINIMUM_KEYBOARD_HEIGHT) {
        		keyboardState = KeyboardState.keyboardStateHidden;
        		listener.onSoftKeyboardShown(false);	
        	}else if (keyboardState == KeyboardState.keyboardStateHidden && diff > ASSUMED_MINIMUM_KEYBOARD_HEIGHT){
        		keyboardState = KeyboardState.keyboardStateShow;
        		listener.onSoftKeyboardShown(true);
        	} 
             // assume all soft keyboards are at least 128 pixels high 
        }