Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pavi2410
Created November 21, 2018 18:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavi2410/df6aad2e2eadeaf15d686e8a5da61e7d to your computer and use it in GitHub Desktop.
Save pavi2410/df6aad2e2eadeaf15d686e8a5da61e7d to your computer and use it in GitHub Desktop.
import android.graphics.*;
import android.view.*;
import android.util.*;
round(n) {
return Math.round(n*100.0)/100.0;
}
WindowManager wm = (WindowManager) ctx.getSystemService("window");
dm = new DisplayMetrics();
wm.defaultDisplay.getRealMetrics(dm);
w = dm.widthPixels;
h = dm.heightPixels;
print(w + "px x " + h + "px");
xd = dm.xdpi;
yd = dm.ydpi;
print(round(xd) + "dpi x " + round(yd) + "dpi");
x = w/xd;
y = h/yd;
print(round(x) + "\" x " + round(y) + "\"");
print(round(Math.sqrt(x*x + y*y)) + "\"");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment