use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class NlUsageTrackerManagerTest method getConfigurationMock.
private static Configuration getConfigurationMock() {
IAndroidTarget target = mock(IAndroidTarget.class);
when(target.getVersion()).thenReturn(new AndroidVersion(0, "mock"));
State state = mock(State.class);
when(state.getOrientation()).thenReturn(PORTRAIT);
Configuration configuration = mock(Configuration.class);
when(configuration.getTarget()).thenReturn(target);
when(configuration.getDeviceState()).thenReturn(state);
return configuration;
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class NlUsageTrackerManagerTest method testRenderLogging.
public void testRenderLogging() {
UsageTracker usageTracker = mock(UsageTracker.class);
LinkedList<AndroidStudioEvent> logCalls = new LinkedList<>();
doAnswer(invocation -> {
logCalls.add(((AndroidStudioEvent.Builder) invocation.getArguments()[0]).build());
return null;
}).when(usageTracker).log(any());
DesignSurface surface = mock(DesignSurface.class);
when(surface.getLayoutType()).thenReturn(NlLayoutType.LAYOUT);
when(surface.getScreenMode()).thenReturn(DesignSurface.ScreenMode.BOTH);
when(surface.getScale()).thenReturn(0.50);
Configuration configuration = getConfigurationMock();
when(surface.getConfiguration()).thenReturn(configuration);
NlUsageTracker tracker = new NlUsageTrackerManager(SYNC_EXECUTOR, surface, usageTracker) {
@Override
boolean shouldLog(int percent) {
// Log everything in tests
return true;
}
};
Result renderResult = mock(Result.class);
when(renderResult.getStatus()).thenReturn(Result.Status.SUCCESS);
HtmlLinkManager linkManager = mock(HtmlLinkManager.class);
RenderLogger logger = mock(RenderLogger.class);
when(logger.getLinkManager()).thenReturn(linkManager);
ImmutableMap<String, Throwable> brokenClasses = ImmutableMap.of("com.test.mock", new Throwable("mock error"));
when(logger.getBrokenClasses()).thenReturn(brokenClasses);
RenderResult result = mock(RenderResult.class);
ViewInfo rootView = new ViewInfo("ConstraintLayout", null, 0, 0, 50, 50);
rootView.setChildren(ImmutableList.of(new ViewInfo("TextView", null, 0, 0, 30, 20)));
;
when(result.getRootViews()).thenReturn(ImmutableList.of(rootView));
when(result.getRenderResult()).thenReturn(renderResult);
when(result.getLogger()).thenReturn(logger);
when(result.getModule()).thenReturn(new MockModule(getProject(), getTestRootDisposable()));
tracker.logRenderResult(NlModel.ChangeType.EDIT, result, 230);
assertEquals(1, logCalls.size());
AndroidStudioEvent studioEvent = logCalls.getFirst();
LayoutEditorRenderResult loggedResult = studioEvent.getLayoutEditorEvent().getRenderResult();
assertEquals(Result.Status.SUCCESS.ordinal(), loggedResult.getResultCode());
assertEquals(230, loggedResult.getTotalRenderTimeMs());
assertEquals(2, loggedResult.getComponentCount());
assertEquals(1, loggedResult.getTotalIssueCount());
assertEquals(1, loggedResult.getErrorCount());
assertEquals(0, loggedResult.getFidelityWarningCount());
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class CanvasResizeInteraction method updateUnavailableLayer.
private void updateUnavailableLayer(@NotNull ScreenView screenView, boolean forceRecompute) {
Configuration config = screenView.getConfiguration();
//noinspection ConstantConditions
FolderConfiguration currentFolderConfig = FolderConfiguration.getConfigForFolder(config.getFile().getParent().getNameWithoutExtension());
assert currentFolderConfig != null;
if (!forceRecompute && currentFolderConfig.equals(myUnavailableLayer.getCurrentFolderConfig())) {
return;
}
List<Area> configAreas = Lists.newArrayList();
Area totalCoveredArea = new Area();
for (FolderConfiguration configuration : myFolderConfigurations) {
Area configArea = coveredAreaForConfig(configuration, screenView);
configArea.subtract(totalCoveredArea);
if (!configuration.equals(currentFolderConfig)) {
configAreas.add(configArea);
}
totalCoveredArea.add(configArea);
}
myUnavailableLayer.update(configAreas, currentFolderConfig);
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class ScreenView method toggleOrientation.
public void toggleOrientation() {
Configuration configuration = getConfiguration();
configuration.getDeviceState();
State current = configuration.getDeviceState();
State flip = configuration.getNextDeviceState(current);
if (flip != null) {
configuration.setDeviceState(flip);
}
}
use of com.android.tools.idea.configurations.Configuration 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