Search in sources :

Example 66 with Configuration

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;
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) State(com.android.sdklib.devices.State) LayoutEditorState(com.google.wireless.android.sdk.stats.LayoutEditorState) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 67 with 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());
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) RenderLogger(com.android.tools.idea.rendering.RenderLogger) Configuration(com.android.tools.idea.configurations.Configuration) RenderResult(com.android.tools.idea.rendering.RenderResult) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) LinkedList(java.util.LinkedList) RenderResult(com.android.tools.idea.rendering.RenderResult) Result(com.android.ide.common.rendering.api.Result) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) UsageTracker(com.android.tools.analytics.UsageTracker) HtmlLinkManager(com.android.tools.idea.rendering.HtmlLinkManager) MockModule(com.intellij.mock.MockModule) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) AndroidStudioEvent(com.google.wireless.android.sdk.stats.AndroidStudioEvent)

Example 68 with Configuration

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);
}
Also used : Area(java.awt.geom.Area) Configuration(com.android.tools.idea.configurations.Configuration)

Example 69 with Configuration

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);
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) State(com.android.sdklib.devices.State)

Example 70 with Configuration

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;
}
Also used : HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) Configuration(com.android.tools.idea.configurations.Configuration) Device(com.android.sdklib.devices.Device) State(com.android.sdklib.devices.State) HardwareConfigHelper(com.android.ide.common.rendering.HardwareConfigHelper) NotNull(org.jetbrains.annotations.NotNull)

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