Search in sources :

Example 61 with Configuration

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());
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) PsiFile(com.intellij.psi.PsiFile) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 62 with Configuration

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?)
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Field(java.lang.reflect.Field) Configuration(com.android.tools.idea.configurations.Configuration) IOException(java.io.IOException)

Example 63 with Configuration

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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) CrashReport(com.android.tools.idea.diagnostics.crash.CrashReport) CrashReporter(com.android.tools.idea.diagnostics.crash.CrashReporter)

Example 64 with Configuration

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);
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Configuration(com.android.tools.idea.configurations.Configuration)

Example 65 with 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());
}
Also used : UsageTracker(com.android.tools.analytics.UsageTracker) DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) Configuration(com.android.tools.idea.configurations.Configuration) AndroidStudioEvent(com.google.wireless.android.sdk.stats.AndroidStudioEvent) LinkedList(java.util.LinkedList) LayoutEditorState(com.google.wireless.android.sdk.stats.LayoutEditorState)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)95 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)23 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)21 ResourceResolver (com.android.ide.common.resources.ResourceResolver)16 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)14 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 Module (com.intellij.openapi.module.Module)9 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Device (com.android.sdklib.devices.Device)7 State (com.android.sdklib.devices.State)7 NotNull (org.jetbrains.annotations.NotNull)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)5 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)4 PsiFile (com.intellij.psi.PsiFile)4 ResourceFolderType (com.android.resources.ResourceFolderType)3