Here you can find the source of getDensity(Context context)
public static float getDensity(Context context)
//package com.java2s; import android.content.Context; import android.util.DisplayMetrics; public class Main { public static float getDensity(Context context) { final DisplayMetrics dm = context.getResources() .getDisplayMetrics();//from w w w. j a v a 2 s . c om return dm.density; } }