use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class StyleItemConverter method getConverter.
@Override
public Converter getConverter(@NotNull GenericDomValue element) {
StyleItem item = (StyleItem) element;
String name = item.getName().getValue();
if (name != null) {
String[] strs = name.split(":");
if (strs.length == 1 || strs.length == 2) {
AndroidFacet facet = AndroidFacet.getInstance(element);
if (facet != null) {
String namespacePrefix = strs.length == 2 ? strs[0] : null;
String localName = strs[strs.length - 1];
return findConverterForAttribute(namespacePrefix, localName, facet, element);
}
}
}
return null;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class TargetApiConverter method getHighestKnownApi.
private static int getHighestKnownApi(@NotNull ConvertContext context) {
Module module = context.getModule();
if (module == null) {
return HIGHEST_KNOWN_API;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return HIGHEST_KNOWN_API;
}
IAndroidTarget apiTarget = facet.getConfigurationManager().getHighestApiTarget();
if (apiTarget == null) {
return HIGHEST_KNOWN_API;
}
return Math.max(apiTarget.getVersion().getApiLevel(), HIGHEST_KNOWN_API);
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidUtils method getDepLibsPackages.
@NotNull
public static Set<String> getDepLibsPackages(Module module) {
final Set<String> result = new HashSet<>();
final HashSet<Module> visited = new HashSet<>();
if (visited.add(module)) {
for (AndroidFacet depFacet : getAllAndroidDependencies(module, true)) {
final Manifest manifest = depFacet.getManifest();
if (manifest != null) {
String aPackage = manifest.getPackage().getValue();
if (aPackage != null) {
result.add(aPackage);
}
}
}
}
return result;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidUtils method addAndroidFacet.
@NotNull
public static AndroidFacet addAndroidFacet(final Module module, @NotNull VirtualFile contentRoot, boolean library) {
final FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel model = facetManager.createModifiableModel();
AndroidFacet facet = model.getFacetByType(AndroidFacet.ID);
if (facet == null) {
facet = facetManager.createFacet(AndroidFacet.getFacetType(), "Android", null);
AndroidFacetConfiguration configuration = facet.getConfiguration();
configuration.init(module, contentRoot);
if (library) {
facet.setProjectType(PROJECT_TYPE_LIBRARY);
}
model.addFacet(facet);
}
model.commit();
return facet;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class ThemeEditorStyle method setValue.
/**
* Sets the value of given attribute in all possible folders where this style is defined. If attribute or value can be used from certain API level,
* folders below that level won't be modified, instead new folder with certain API will be created.
* Note: {@link LocalResourceRepository}'s won't get updated immediately
*
* @param attribute the style attribute name
* @param value the style attribute value
*/
public void setValue(@NotNull final String attribute, @NotNull final String value) {
if (!isProjectStyle()) {
throw new UnsupportedOperationException("Non project styles can not be modified");
}
final Project project = myManager.getProject();
int maxApi = Math.max(ResolutionUtils.getOriginalApiLevel(value, myManager.getProject()), ResolutionUtils.getOriginalApiLevel(attribute, project));
int minSdk = ThemeEditorUtils.getMinApiLevel(myManager.getModule());
// When api level of both attribute and value is not greater that Minimum SDK,
// we should modify every FolderConfiguration, thus we set desiredApi to -1
final int desiredApi = (maxApi <= minSdk) ? -1 : maxApi;
new WriteCommandAction.Simple(project, "Setting value of " + attribute) {
@Override
protected void run() {
// Makes the command global even if only one xml file is modified
// That way, the Undo is always available from the theme editor
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
Collection<FolderConfiguration> toBeCopied = findToBeCopied(desiredApi);
for (FolderConfiguration configuration : toBeCopied) {
XmlTag styleTag = findXmlTagFromConfiguration(configuration);
assert styleTag != null;
ThemeEditorUtils.copyTheme(desiredApi, styleTag);
}
if (!toBeCopied.isEmpty()) {
// We need to refreshResource, to get all copied styles
// Otherwise, LocalResourceRepositories won't get updated, so we won't get copied styles
AndroidFacet facet = AndroidFacet.getInstance(myManager.getModule());
if (facet != null) {
facet.refreshResources();
// This is because the ResourceFolderRepository may initialize through the file instead of Psi.
GradleBuildInvoker.saveAllFilesSafely();
}
}
Collection<ResourceItem> styleItems = getStyleResourceItems();
for (ResourceItem style : styleItems) {
FolderConfiguration configuration = style.getConfiguration();
int version = ThemeEditorUtils.getVersionFromConfiguration(configuration);
// it means than we can modify 'attribute' to value 'value'.
if (version >= desiredApi) {
setValue(configuration, attribute, value);
}
}
}
}.execute();
}
Aggregations