use of com.android.ide.common.rendering.HardwareConfigHelper in project android by JetBrains.
the class GraphicsLayoutRenderer method create.
@VisibleForTesting
@NotNull
static GraphicsLayoutRenderer create(@NotNull AndroidFacet facet, @NotNull AndroidPlatform platform, @NotNull Project project, @NotNull Configuration configuration, @NotNull ILayoutPullParser parser, @Nullable Color backgroundColor, @NotNull SessionParams.RenderingMode renderingMode, boolean useSecurityManager) throws InitializationException {
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
LayoutLibrary layoutLib;
try {
IAndroidTarget latestTarget = configuration.getConfigurationManager().getHighestApiTarget();
if (latestTarget == null) {
throw new UnsupportedLayoutlibException("GraphicsLayoutRenderer requires at least layoutlib version " + MIN_LAYOUTLIB_API_VERSION);
}
layoutLib = platform.getSdkData().getTargetData(latestTarget).getLayoutLibrary(project);
if (layoutLib == null) {
throw new InitializationException("getLayoutLibrary() returned null");
}
} catch (RenderingException e) {
throw new InitializationException(e);
} catch (IOException e) {
throw new InitializationException(e);
}
if (layoutLib.getApiLevel() < MIN_LAYOUTLIB_API_VERSION) {
throw new UnsupportedLayoutlibException("GraphicsLayoutRenderer requires at least layoutlib version " + MIN_LAYOUTLIB_API_VERSION);
}
AppResourceRepository appResources = AppResourceRepository.getAppResources(facet, true);
final Module module = facet.getModule();
// Security token used to disable the security manager. Only objects that have a reference to it are allowed to disable it.
Object credential = new Object();
RenderLogger logger = new RenderLogger("theme_editor", module, credential);
final ActionBarCallback actionBarCallback = new ActionBarCallback();
// TODO: Remove LayoutlibCallback dependency.
//noinspection ConstantConditions
final LayoutlibCallbackImpl layoutlibCallback = new LayoutlibCallbackImpl(null, layoutLib, appResources, module, facet, logger, credential, null) {
@Override
public ActionBarCallback getActionBarCallback() {
return actionBarCallback;
}
};
// Load the local project R identifiers.
boolean loadRResult = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
// half way.
if (module.isDisposed()) {
return false;
}
layoutlibCallback.loadAndParseRClass();
return true;
}
});
if (!loadRResult) {
throw new AlreadyDisposedException("Module was already disposed");
}
IAndroidTarget target = configuration.getTarget();
if (target == null) {
throw new InitializationException("Unable to get IAndroidTarget");
}
Device device = configuration.getDevice();
assert device != null;
HardwareConfigHelper hardwareConfigHelper = new HardwareConfigHelper(device);
DynamicHardwareConfig hardwareConfig = new DynamicHardwareConfig(hardwareConfigHelper.getConfig());
List<ResourceValue> resourceLookupChain = new ArrayList<ResourceValue>();
ResourceResolver resourceResolver = ResourceResolver.copy(configuration.getResourceResolver());
assert resourceResolver != null;
// Create a resource resolver that will save the lookups on the passed List<>
ResourceResolver recordingResourceResolver = resourceResolver.createRecorder(resourceLookupChain);
final SessionParams params = new SessionParams(parser, renderingMode, module, hardwareConfig, recordingResourceResolver, layoutlibCallback, moduleInfo.getMinSdkVersion().getApiLevel(), moduleInfo.getTargetSdkVersion().getApiLevel(), logger, target instanceof CompatibilityRenderTarget ? target.getVersion().getApiLevel() : 0);
params.setForceNoDecor();
params.setAssetRepository(new AssetRepositoryImpl(facet));
// The App Label needs to be not null
params.setAppLabel("");
if (backgroundColor != null) {
params.setOverrideBgColor(backgroundColor.getRGB());
}
RenderSecurityManager mySecurityManager = useSecurityManager ? RenderSecurityManagerFactory.create(module, platform) : null;
return new GraphicsLayoutRenderer(layoutLib, params, mySecurityManager, hardwareConfig, resourceLookupChain, credential);
}
use of com.android.ide.common.rendering.HardwareConfigHelper in project android by JetBrains.
the class ScreenView method getPreferredSize.
/**
* Returns the current preferred size for the view.
* @param dimension optional existing {@link Dimension} instance to be reused. If not null, the values will be set and this instance
* returned.
*/
@NotNull
public Dimension getPreferredSize(@Nullable Dimension dimension) {
if (dimension == null) {
dimension = new Dimension();
}
Configuration configuration = getConfiguration();
Device device = configuration.getDevice();
State state = configuration.getDeviceState();
if (device != null && state != null) {
HardwareConfig config = new HardwareConfigHelper(device).setOrientation(state.getOrientation()).getConfig();
dimension.setSize(config.getScreenWidth(), config.getScreenHeight());
}
return dimension;
}
Aggregations