use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidPropertyFilesUpdater method updateTargetProperty.
private static void updateTargetProperty(@NotNull AndroidFacet facet, @NotNull final PropertiesFile propertiesFile, @NotNull List<Runnable> changes) {
final Project project = facet.getModule().getProject();
final IAndroidTarget androidTarget = facet.getConfiguration().getAndroidTarget();
if (androidTarget != null) {
final String targetPropertyValue = androidTarget.hashString();
final IProperty property = propertiesFile.findPropertyByKey(AndroidUtils.ANDROID_TARGET_PROPERTY);
if (property == null) {
changes.add(new Runnable() {
@Override
public void run() {
propertiesFile.addProperty(createProperty(project, targetPropertyValue));
}
});
} else {
if (!Comparing.equal(property.getValue(), targetPropertyValue)) {
final PsiElement element = property.getPsiElement();
if (element != null) {
changes.add(new Runnable() {
@Override
public void run() {
element.replace(createProperty(project, targetPropertyValue).getPsiElement());
}
});
}
}
}
}
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidThemePreviewToolWindowManager method getBestConfiguration.
@Nullable
private static /*if there is no available configuration that would select the passed file*/
Configuration getBestConfiguration(@Nullable PsiFile psiFile) {
Module module = psiFile != null ? ModuleUtilCore.findModuleForPsiElement(psiFile) : null;
if (module == null) {
return null;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return null;
}
VirtualFile virtualFile = psiFile.getVirtualFile();
ConfigurationManager manager = facet.getConfigurationManager();
List<VirtualFile> variations = ResourceHelper.getResourceVariations(virtualFile, false);
if (variations.isEmpty()) {
return manager.getConfiguration(virtualFile);
}
// There is more than one resource folder available so make sure we select a configuration that only matches the current file.
Collection<FolderConfiguration> incompatible = Collections2.transform(variations, new Function<VirtualFile, FolderConfiguration>() {
@Nullable
@Override
public FolderConfiguration apply(VirtualFile input) {
assert input != null;
return ResourceHelper.getFolderConfiguration(input);
}
});
FolderConfiguration selectedFileFolderConfiguration = ResourceHelper.getFolderConfiguration(psiFile);
if (selectedFileFolderConfiguration == null) {
// This folder probably has invalid qualifiers or they are in the wrong order
return null;
}
RestrictedConfiguration restrictedConfiguration = RestrictedConfiguration.restrict(selectedFileFolderConfiguration, incompatible);
if (restrictedConfiguration == null) {
// Unable to create a configuration that only matches this file
return null;
}
FolderConfiguration restricted = restrictedConfiguration.getAny();
Configuration newConfiguration = Configuration.create(manager, virtualFile, null, restricted);
VersionQualifier newVersionQualifier = restricted.getVersionQualifier();
if (newVersionQualifier != null) {
IAndroidTarget realTarget = manager.getHighestApiTarget() != null ? manager.getHighestApiTarget() : manager.getTarget();
assert realTarget != null;
newConfiguration.setTarget(new CompatibilityRenderTarget(realTarget, newVersionQualifier.getVersion(), null));
}
return newConfiguration;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ResolutionUtils method getAttributeDefinition.
@Nullable
public static AttributeDefinition getAttributeDefinition(@NotNull Module module, @Nullable Configuration configuration, @NotNull String name) {
AttributeDefinitions definitions;
if (name.startsWith(ANDROID_NS_NAME_PREFIX)) {
IAndroidTarget target;
if (configuration == null) {
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
// same as getHighestApiTarget();
target = facet.getConfigurationManager().getDefaultTarget();
} else {
target = configuration.getRealTarget();
}
assert target != null;
AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, module);
assert androidTargetData != null;
definitions = androidTargetData.getAllAttrDefs(module.getProject());
} else {
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null : String.format("Module %s is not an Android module", module.getName());
definitions = facet.getLocalResourceManager().getAttributeDefinitions();
}
if (definitions == null) {
return null;
}
return definitions.getAttrDefByName(getNameFromQualifiedName(name));
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ResourceFolderRepository method bitmapUpdated.
/**
* Called when a bitmap has been changed/deleted. In that case we need to clear out any caches for that
* image held by layout lib.
*/
private void bitmapUpdated() {
ConfigurationManager configurationManager = myFacet.getConfigurationManager(false);
if (configurationManager != null) {
IAndroidTarget target = configurationManager.getTarget();
if (target != null) {
Module module = myFacet.getModule();
AndroidTargetData targetData = AndroidTargetData.getTargetData(target, module);
if (targetData != null) {
targetData.clearLayoutBitmapCache(module);
}
}
}
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class TemplateUtils method getKnownVersions.
/**
* Returns a list of known API names
*
* @return a list of string API names, starting from 1 and up through the
* maximum known versions (with no gaps)
*/
@NotNull
public static String[] getKnownVersions() {
final AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
assert sdkData != null;
int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
IAndroidTarget[] targets = sdkData.getTargets();
SparseArray<IAndroidTarget> apiTargets = null;
for (IAndroidTarget target : targets) {
if (target.isPlatform()) {
AndroidVersion version = target.getVersion();
if (!version.isPreview()) {
int apiLevel = version.getApiLevel();
max = Math.max(max, apiLevel);
if (apiLevel > SdkVersionInfo.HIGHEST_KNOWN_API) {
if (apiTargets == null) {
apiTargets = new SparseArray<IAndroidTarget>();
}
apiTargets.put(apiLevel, target);
}
}
}
}
String[] versions = new String[max];
for (int api = 1; api <= max; api++) {
String name = SdkVersionInfo.getAndroidName(api);
// noinspection ConstantConditions
if (name == null) {
if (apiTargets != null) {
IAndroidTarget target = apiTargets.get(api);
if (target != null) {
name = AndroidSdkUtils.getTargetLabel(target);
}
}
if (name == null) {
name = String.format("API %1$d", api);
}
}
versions[api - 1] = name;
}
return versions;
}
Aggregations