Skip to content

Instantly share code, notes, and snippets.

@courville
Last active February 3, 2020 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save courville/854ad922f14d9a19c0afb83e2607f49a to your computer and use it in GitHub Desktop.
Save courville/854ad922f14d9a19c0afb83e2607f49a to your computer and use it in GitHub Desktop.
find display modeId that matches currentMode resolution and desired refreshRate
if (Build.VERSION.SDK_INT >= 23) {
Display.Mode[] supportedModes = d.getSupportedModes();
Display.Mode currentMode = d.getMode();
// calculate wantedFps
float wantedFps = (float) ((double) video.fpsRate / (double) video.fpsScale);
int wantedModeId = 0;
// find corresponding wantedModeId for wantedFps
for (int i = 0; i < supportedModes.length; i++) {
if (supportedModes[i].matches(currentMode.getPhysicalWidth(), currentMode.getPhysicalHeight(), wantedFps)) {
wantedModeId = supportedModes[i].getModeId();
}
}
if (wantedModeId != 0) {
lp.preferredDisplayModeId = wantedModeId;
mWindow.setAttributes(lp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment