Search in sources :

Example 21 with Configuration

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

the class OverrideResourceAction method forkResourceFile.

/**
   * Create a variation (copy) of a given resource file (of a given type).
   *
   * @param xmlFile     the XML resource file to fork
   * @param myNewFolder the resource folder to create, or null to ask the user
   * @param open        if true, open the file after creating it
   */
public static void forkResourceFile(@NotNull final XmlFile xmlFile, @Nullable String myNewFolder, boolean open) {
    VirtualFile file = xmlFile.getVirtualFile();
    if (file == null) {
        return;
    }
    Module module = AndroidPsiUtils.getModuleSafely(xmlFile);
    if (module == null) {
        return;
    }
    ResourceFolderType folderType = ResourceHelper.getFolderType(xmlFile);
    if (folderType == null || folderType == ResourceFolderType.VALUES) {
        return;
    }
    Configuration configuration = null;
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet != null) {
        configuration = facet.getConfigurationManager().getConfiguration(file);
    }
    forkResourceFile(module.getProject(), folderType, file, xmlFile, myNewFolder, configuration, open);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ResourceFolderType(com.android.resources.ResourceFolderType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 22 with Configuration

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

the class AndroidThemePreviewToolWindowManager method processFileEditorChange.

/**
   * Method called when the current XML editor focus changes to a new one.
   *
   * @param newEditor the new editor, or null if no editor is selected.
   */
private void processFileEditorChange(@Nullable final TextEditor newEditor) {
    if (myToolWindow == null) {
        return;
    }
    if (myActiveEditor == newEditor) {
        return;
    }
    myToolWindowUpdateQueue.cancelAllUpdates();
    if (myActiveEditor != null) {
        myActiveEditor.getEditor().getCaretModel().removeCaretListener(myCaretListener);
        myActiveEditor.getEditor().getDocument().removeDocumentListener(myDocumentListener);
        myActiveEditor = null;
    }
    boolean available = false;
    if (newEditor != null && isApplicableEditor(newEditor)) {
        myActiveEditor = newEditor;
        CaretModel caretModel = myActiveEditor.getEditor().getCaretModel();
        caretModel.addCaretListener(myCaretListener);
        Document document = myActiveEditor.getEditor().getDocument();
        document.addDocumentListener(myDocumentListener);
        PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
        Configuration configuration = getBestConfiguration(psiFile);
        if (configuration != null) {
            if (myThemeEditorContext == null) {
                myThemeEditorContext = new ThemeEditorContext(configuration);
            } else {
                myThemeEditorContext.setConfiguration(configuration);
            }
            // Check if there is a theme at the current offset before enabling the preview
            if (getThemeAtEditorOffset(document, caretModel.getOffset()) != null) {
                available = true;
                updatePreview();
            }
        }
    }
    myToolWindow.setAvailable(available, null);
}
Also used : CaretModel(com.intellij.openapi.editor.CaretModel) Configuration(com.android.tools.idea.configurations.Configuration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document)

Example 23 with Configuration

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

the class Coordinates method dpToPx.

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

Example 24 with Configuration

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

the class Coordinates method dpToPx.

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

Example 25 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)

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