Search in sources :

Example 41 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class Coordinates method pxToDp.

@AndroidDpCoordinate
public static int pxToDp(@NotNull ScreenView view, @AndroidCoordinate int androidPx) {
    final Configuration configuration = view.getConfiguration();
    final int dpiValue = configuration.getDensity().getDpiValue();
    return Math.round(androidPx * (DEFAULT_DENSITY / dpiValue));
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

Example 42 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class CanvasResizeInteraction method end.

@Override
public void end(@SwingCoordinate int x, @SwingCoordinate int y, @InputEventMask int modifiers, boolean canceled) {
    super.end(x, y, modifiers, canceled);
    ScreenView screenView = myDesignSurface.getCurrentScreenView();
    if (screenView == null) {
        return;
    }
    // Set the surface in resize mode so it doesn't try to re-center the screen views all the time
    screenView.getSurface().setResizeMode(false);
    // When disabling the resize mode, add a render handler to call zoomToFit
    screenView.getModel().addListener(new ModelListener() {

        @Override
        public void modelChanged(@NotNull NlModel model) {
        }

        @Override
        public void modelRendered(@NotNull NlModel model) {
            model.removeListener(this);
        }

        @Override
        public void modelChangedOnLayout(@NotNull NlModel model, boolean animate) {
        // Do nothing
        }
    });
    int androidX = Coordinates.getAndroidX(screenView, x);
    int androidY = Coordinates.getAndroidY(screenView, y);
    if (canceled || androidX < 0 || androidY < 0) {
        Configuration configuration = screenView.getConfiguration();
        configuration.setEffectiveDevice(myOriginalDevice, myOriginalDeviceState);
    } else {
        int snapThreshold = Coordinates.getAndroidDimension(screenView, MAX_MATCH_DISTANCE);
        Device deviceToSnap = snapToDevice(androidX, androidY, snapThreshold);
        if (deviceToSnap != null) {
            State deviceState = deviceToSnap.getState(androidX < androidY ? "Portrait" : "Landscape");
            myDesignSurface.getConfiguration().setEffectiveDevice(deviceToSnap, deviceState);
        } else {
            screenView.getModel().overrideConfigurationScreenSize(androidX, androidY);
        }
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) Device(com.android.sdklib.devices.Device) State(com.android.sdklib.devices.State)

Example 43 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class ScreenView method switchDevice.

public void switchDevice() {
    List<Device> devices = myModel.getFacet().getConfigurationManager().getDevices();
    List<Device> applicable = Lists.newArrayList();
    for (Device device : devices) {
        if (HardwareConfigHelper.isNexus(device)) {
            applicable.add(device);
        }
    }
    Configuration configuration = getConfiguration();
    Device currentDevice = configuration.getDevice();
    for (int i = 0, n = applicable.size(); i < n; i++) {
        if (applicable.get(i) == currentDevice) {
            Device newDevice = applicable.get((i + 1) % applicable.size());
            configuration.setDevice(newDevice, true);
            break;
        }
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) Device(com.android.sdklib.devices.Device)

Example 44 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class LayoutTestUtilities method createScreen.

public static ScreenView createScreen(DesignSurface surface, NlModel model, SelectionModel selectionModel, double scale, @SwingCoordinate int x, @SwingCoordinate int y, Density density) {
    Configuration configuration = mock(Configuration.class);
    when(configuration.getDensity()).thenReturn(density);
    when(configuration.getFile()).thenReturn(model.getFile().getVirtualFile());
    when(configuration.getFullConfig()).thenReturn(new FolderConfiguration());
    ScreenView screenView = mock(ScreenView.class);
    when(screenView.getConfiguration()).thenReturn(configuration);
    when(screenView.getModel()).thenReturn(model);
    when(screenView.getScale()).thenReturn(scale);
    when(screenView.getSelectionModel()).thenReturn(selectionModel);
    when(screenView.getSize()).thenReturn(new Dimension());
    when(screenView.getSurface()).thenReturn(surface);
    when(screenView.getX()).thenReturn(x);
    when(screenView.getY()).thenReturn(y);
    when(surface.getScreenView(anyInt(), anyInt())).thenReturn(screenView);
    return screenView;
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 45 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class RefreshRenderAction method clearCache.

public static void clearCache(EditorDesignSurface surface) {
    ModuleClassLoader.clearCache();
    Configuration configuration = surface.getConfiguration();
    if (configuration != null) {
        // Clear layoutlib bitmap cache (in case files have been modified externally)
        IAndroidTarget target = configuration.getTarget();
        Module module = configuration.getModule();
        if (module != null) {
            ResourceClassRegistry.get(module.getProject()).clearCache();
            if (target != null) {
                AndroidTargetData targetData = AndroidTargetData.getTargetData(target, module);
                if (targetData != null) {
                    targetData.clearLayoutBitmapCache(module);
                }
            }
        }
        AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
        if (facet != null) {
            facet.refreshResources();
        }
        configuration.updated(ConfigurationListener.MASK_RENDERING);
    }
    surface.requestRender();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

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