Java tutorial
//package com.java2s; import android.content.Context; import android.preference.PreferenceManager; public class Main { private static final String DEF_KEYBOARD_HEIGHT_KEY = "def_keyboard_height_key"; private static final int DEF_KEYBOARD_HEIGHT_DP = 300; private static int sDefKeyboardHeight = -1; public static int getDefKeyboardHeight(Context context) { if (sDefKeyboardHeight < 0) { sDefKeyboardHeight = dip2px(context, DEF_KEYBOARD_HEIGHT_DP); } int height = PreferenceManager.getDefaultSharedPreferences(context).getInt(DEF_KEYBOARD_HEIGHT_KEY, 0); return sDefKeyboardHeight = height > 0 && sDefKeyboardHeight != height ? height : sDefKeyboardHeight; } public static int dip2px(Context context, float dipValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); } }