private void refreshConfiguration() { Configuration configuration = myContext.getConfiguration(); myAndroidPreviewPanel.updateConfiguration(configuration); // We want the preview to remain the same size even when the device being used to render is // different. // Adjust the scale to the current config. if (configuration.getDeviceState() != null) { double scale = myConstantScalingFactor / configuration .getDeviceState() .getHardware() .getScreen() .getPixelDensity() .getDpiValue(); myAndroidPreviewPanel.setScale(scale); } else { LOG.error("Configuration getDeviceState returned null. Unable to set preview scale."); } }