use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class RenderErrorContributorTest method getRenderOutput.
private List<RenderErrorModel.Issue> getRenderOutput(@NotNull VirtualFile file, @Nullable LogOperation logOperation) {
assertNotNull(file);
AndroidFacet facet = AndroidFacet.getInstance(myModule);
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
assertNotNull(psiFile);
assertNotNull(facet);
ConfigurationManager configurationManager = facet.getConfigurationManager();
assertNotNull(configurationManager);
IAndroidTarget target = getTestTarget(configurationManager);
assertNotNull(target);
configurationManager.setTarget(target);
Configuration configuration = configurationManager.getConfiguration(file);
assertSame(target, configuration.getRealTarget());
if (!LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
// TODO: Remove this after http://b.android.com/203392 is released
// If we are using the embedded layoutlib, use a recent theme to avoid missing styles errors.
configuration.setTheme("android:Theme.Material");
}
RenderService renderService = RenderService.get(facet);
RenderLogger logger = renderService.createLogger();
final RenderTask task = renderService.createTask(psiFile, configuration, logger, null);
assertNotNull(task);
task.disableSecurityManager();
RenderResult render = RenderTestBase.renderOnSeparateThread(task);
assertNotNull(render);
if (logOperation != null) {
logOperation.addErrors(logger, render);
}
return RenderErrorModelFactory.createErrorModel(render, null).getIssues().stream().sorted().collect(Collectors.toList());
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class MenuPreviewRendererTest method testLightTheme.
public void testLightTheme() throws IOException {
myFixture.copyFileToProject("menus/strings.xml", "res/menu/strings.xml");
VirtualFile file = myFixture.copyFileToProject("menus/menu1.xml", "res/menu/menu1.xml");
assertNotNull(file);
Configuration configuration = getConfiguration(file, DEFAULT_DEVICE_ID, "@android:style/Theme.Holo.Light");
RenderTask task = createRenderTask(file, configuration);
assertNotNull(task);
if (task.getLayoutLib().supports(Features.ACTION_BAR)) {
checkRendering(task, "menu/menu1-light.png");
} else {
System.err.println("Not running MenuPreviewRendererTest.testLightTheme: Associated layoutlib in test SDK needs " + "to use API 21 or higher");
}
// TODO: Remove the hack below after LayoutLib has been fixed properly.
try {
Field threadInstanceField = task.getLayoutLib().getClassLoader().loadClass("android.view.Choreographer").getDeclaredField("sThreadInstance");
threadInstanceField.setAccessible(true);
((ThreadLocal) threadInstanceField.get(null)).remove();
} catch (Exception ignore) {
// Clearing the field may no longer be necessary if the exception is thrown (updated layoutlib?)
}
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class RenderTaskTest method testCrashReport.
public void testCrashReport() throws Exception {
VirtualFile layoutFile = myFixture.copyFileToProject("xmlpull/simple.xml", "res/layout/foo.xml");
Configuration configuration = getConfiguration(layoutFile, DEFAULT_DEVICE_ID);
RenderLogger logger = mock(RenderLogger.class);
doThrow(new NullPointerException()).when(logger).warning(eq("resources.resolve.theme"), anyString(), any());
CrashReporter mockCrashReporter = mock(CrashReporter.class);
RenderTask task = createRenderTask(layoutFile, configuration, logger);
task.setCrashReporter(mockCrashReporter);
task.render();
verify(mockCrashReporter, times(1)).submit(isNotNull(CrashReport.class));
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class WidgetNavigatorPanel method setSurface.
/**
* Set the DesignSurface to display the minimap from
*
* @param surface
*/
public void setSurface(@Nullable DesignSurface surface) {
updateScreenNumber(surface);
if (surface == myDesignSurface) {
return;
}
// Removing all listener for the oldSurface
if (myDesignSurface != null) {
myDesignSurface.removeListener(this);
myDesignSurface.removePanZoomListener(this);
myDesignSurface.removeAncestorListener(myAncestorListener);
final ScreenView currentScreenView = myDesignSurface.getCurrentScreenView();
if (currentScreenView != null) {
currentScreenView.getModel().removeListener(this);
}
}
myDesignSurface = surface;
if (myDesignSurface == null) {
return;
}
myDesignSurface.addListener(this);
myDesignSurface.addPanZoomListener(this);
myDesignSurface.addAncestorListener(myAncestorListener);
final ScreenView currentScreenView = myDesignSurface.getCurrentScreenView();
if (currentScreenView != null) {
currentScreenView.getModel().addListener(this);
}
final Configuration configuration = myDesignSurface.getConfiguration();
if (configuration != null) {
updateDeviceConfiguration(configuration);
}
}
use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.
the class NlUsageTrackerManagerTest method testBasicLogging.
public void testBasicLogging() {
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);
tracker.logAction(LayoutEditorEvent.LayoutEditorEventType.API_LEVEL_CHANGE);
assertEquals(1, logCalls.size());
AndroidStudioEvent studioEvent = logCalls.getFirst();
assertEquals(AndroidStudioEvent.EventCategory.LAYOUT_EDITOR, studioEvent.getCategory());
assertEquals(AndroidStudioEvent.EventKind.LAYOUT_EDITOR_EVENT, studioEvent.getKind());
assertEquals(LayoutEditorEvent.LayoutEditorEventType.API_LEVEL_CHANGE, studioEvent.getLayoutEditorEvent().getType());
// Verify state
LayoutEditorState state = studioEvent.getLayoutEditorEvent().getState();
assertEquals(LayoutEditorState.Type.LAYOUT, state.getType());
assertEquals(LayoutEditorState.Surfaces.BOTH, state.getSurfaces());
assertEquals(50, state.getConfigZoomLevel());
assertEquals("mock", state.getConfigApiLevel());
assertEquals(LayoutEditorState.Orientation.PORTRAIT, state.getConfigOrientation());
logCalls.clear();
tracker.logAction(LayoutEditorEvent.LayoutEditorEventType.RESTORE_ERROR_PANEL);
assertEquals(1, logCalls.size());
studioEvent = logCalls.getFirst();
assertEquals(LayoutEditorEvent.LayoutEditorEventType.RESTORE_ERROR_PANEL, studioEvent.getLayoutEditorEvent().getType());
}
Aggregations