You can use this .. without Context
public static int pxToDp(int px) {
return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}
public static int dpToPx(int dp) {
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}
As @Stan mentioned .. using this approach may cause issue if system changes density. So be aware of that!
Personally I am using Context to do that. It's just another approach I wanted to share you with