Search in sources :

Example 1 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class ConstantFieldConverter method getFilteringSet.

@Nullable
private static Set<String> getFilteringSet(@NotNull ConvertContext context) {
    final Module module = context.getModule();
    if (module == null) {
        return null;
    }
    final AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        return null;
    }
    IAndroidTarget target = platform.getTarget();
    final AndroidTargetData targetData = platform.getSdkData().getTargetData(target);
    DomElement element = context.getInvocationElement().getParent();
    if (element instanceof Category) {
        return targetData.getStaticConstantsData().getCategories();
    } else if (element instanceof Action) {
        element = element.getParent();
        if (element instanceof IntentFilter) {
            element = element.getParent();
            if (element instanceof Activity) {
                return targetData.getStaticConstantsData().getActivityActions();
            } else if (element instanceof Service) {
                return targetData.getStaticConstantsData().getServiceActions();
            } else if (element instanceof Receiver) {
                return targetData.getStaticConstantsData().getReceiverActions();
            }
        }
    }
    return null;
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class ResourceResolverCache method getFrameworkResources.

/**
   * Returns a {@link LocalResourceRepository} for the framework resources based on the current configuration selection.
   *
   * @return the framework resources or {@code null} if not found.
   */
@Nullable
public ResourceRepository getFrameworkResources(@NotNull FolderConfiguration configuration, @NotNull IAndroidTarget target) {
    int apiLevel = target.getVersion().getFeatureLevel();
    LocaleQualifier locale = configuration.getLocaleQualifier();
    boolean needLocales = locale != null && !locale.hasFakeValue() || myManager.getLocale() != Locale.ANY;
    AndroidTargetData targetData = myFrameworkResources.get(apiLevel);
    if (targetData == null) {
        AndroidPlatform platform = AndroidPlatform.getInstance(myManager.getModule());
        if (platform == null) {
            return null;
        }
        // uses soft ref
        targetData = platform.getSdkData().getTargetData(target);
        myFrameworkResources.put(apiLevel, targetData);
    }
    try {
        return targetData.getFrameworkResources(needLocales);
    } catch (IOException e) {
        LOG.error(e);
    }
    return null;
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IOException(java.io.IOException) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class EditedStyleItem method isPublicAttribute.

public boolean isPublicAttribute() {
    if (!getSelectedValue().isFrameworkAttr()) {
        return true;
    }
    Configuration configuration = mySourceTheme.getConfiguration();
    IAndroidTarget target = configuration.getRealTarget();
    if (target == null) {
        LOG.error("Unable to get IAndroidTarget.");
        return false;
    }
    AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, configuration.getModule());
    if (androidTargetData == null) {
        LOG.error("Unable to get AndroidTargetData.");
        return false;
    }
    return androidTargetData.isResourcePublic(ResourceType.ATTR.getName(), getName());
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

Example 4 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class ThemeEditorStyle method isPublic.

/**
   * Returns whether this style is public.
   */
public boolean isPublic() {
    if (!isFramework()) {
        return true;
    }
    IAndroidTarget target = myManager.getTarget();
    if (target == null) {
        LOG.error("Unable to get IAndroidTarget.");
        return false;
    }
    AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, myManager.getModule());
    if (androidTargetData == null) {
        LOG.error("Unable to get AndroidTargetData.");
        return false;
    }
    return androidTargetData.isResourcePublic(ResourceType.STYLE.getName(), getName());
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

Example 5 with AndroidTargetData

use of org.jetbrains.android.sdk.AndroidTargetData in project android by JetBrains.

the class RenderErrorContributor method reportTagResourceFormat.

private void reportTagResourceFormat(@NotNull RenderResult result, @NotNull RenderProblem message) {
    Object clientData = message.getClientData();
    if (!(clientData instanceof String[])) {
        return;
    }
    String[] strings = (String[]) clientData;
    if (strings.length != 2) {
        return;
    }
    RenderTask renderTask = result.getRenderTask();
    if (renderTask == null) {
        return;
    }
    IAndroidTarget target = renderTask.getConfiguration().getRealTarget();
    if (target == null) {
        return;
    }
    AndroidPlatform platform = renderTask.getPlatform();
    if (platform == null) {
        return;
    }
    AndroidTargetData targetData = platform.getSdkData().getTargetData(target);
    AttributeDefinitions definitionLookup = targetData.getPublicAttrDefs(result.getFile().getProject());
    final String attributeName = strings[0];
    final String currentValue = strings[1];
    if (definitionLookup == null) {
        return;
    }
    AttributeDefinition definition = definitionLookup.getAttrDefByName(attributeName);
    if (definition == null) {
        return;
    }
    Set<AttributeFormat> formats = definition.getFormats();
    if (formats.contains(AttributeFormat.Flag) || formats.contains(AttributeFormat.Enum)) {
        String[] values = definition.getValues();
        if (values.length > 0) {
            HtmlBuilder builder = new HtmlBuilder();
            builder.add("Change ").add(currentValue).add(" to: ");
            boolean first = true;
            for (String value : values) {
                if (first) {
                    first = false;
                } else {
                    builder.add(", ");
                }
                builder.addLink(value, myLinkManager.createReplaceAttributeValueUrl(attributeName, currentValue, value));
            }
            addRefreshAction(builder);
            addIssue().setSummary("Incorrect resource value format").setHtmlContent(builder).build();
        }
    }
}
Also used : HtmlBuilder(com.android.utils.HtmlBuilder) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) AttributeDefinitions(org.jetbrains.android.dom.attrs.AttributeDefinitions) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData)

Aggregations

AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)11 IAndroidTarget (com.android.sdklib.IAndroidTarget)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)5 Nullable (org.jetbrains.annotations.Nullable)5 Module (com.intellij.openapi.module.Module)3 Configuration (com.android.tools.idea.configurations.Configuration)2 IOException (java.io.IOException)2 AttributeDefinitions (org.jetbrains.android.dom.attrs.AttributeDefinitions)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 LayoutLibrary (com.android.ide.common.rendering.LayoutLibrary)1 ResourceVisibilityLookup (com.android.ide.common.repository.ResourceVisibilityLookup)1 FrameworkResources (com.android.ide.common.resources.FrameworkResources)1 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)1 ResourceType (com.android.resources.ResourceType)1 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)1 HtmlBuilder (com.android.utils.HtmlBuilder)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)1