use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ThemeEditorStyle method findToBeCopied.
/**
* Finds best to be copied {@link FolderConfiguration}s
* e.g if style is defined in "port-v8", "port-v18", "port-v22", "night-v20" and desiredApi = 21,
* then result is {"port-v18", "night-v20"}
*
* @param desiredApi new api level of {@link FolderConfiguration}s after being copied
* @return Collection of FolderConfigurations which are going to be copied to version desiredApi
*/
@NotNull
private ImmutableCollection<FolderConfiguration> findToBeCopied(int desiredApi) {
// Keeps closest VersionQualifier to 'desiredApi'
// e.g. desiredApi = 21, "en-port", "en-port-v18", "en-port-v19", "en-port-v22" then
// bestVersionCopyFrom will contain {"en-port" -> v19}, as it is closest one to v21
final HashMap<FolderConfiguration, VersionQualifier> bestVersionCopyFrom = Maps.newHashMap();
for (ResourceItem styleItem : getStyleResourceItems()) {
FolderConfiguration configuration = FolderConfiguration.copyOf(styleItem.getConfiguration());
int styleItemVersion = ThemeEditorUtils.getVersionFromConfiguration(configuration);
// We want to get the best from port-v19 port-v20 port-v23. so we need to remove the version qualifier to compare them
configuration.setVersionQualifier(null);
if (styleItemVersion > desiredApi) {
// Thus, we don't need to copy it, we are going to just modify it.
continue;
}
// If 'version' is closer to 'desiredApi' than we have found
if (!bestVersionCopyFrom.containsKey(configuration) || bestVersionCopyFrom.get(configuration).getVersion() < styleItemVersion) {
bestVersionCopyFrom.put(configuration, new VersionQualifier(styleItemVersion));
}
}
ImmutableList.Builder<FolderConfiguration> toBeCopied = ImmutableList.builder();
for (FolderConfiguration key : bestVersionCopyFrom.keySet()) {
FolderConfiguration configuration = FolderConfiguration.copyOf(key);
VersionQualifier version = bestVersionCopyFrom.get(key);
if (version.getVersion() != -1) {
configuration.setVersionQualifier(version);
}
// Version can't be bigger as we have filtered above
if (version.getVersion() < desiredApi) {
toBeCopied.add(configuration);
}
}
return toBeCopied.build();
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ThemeEditorStyle method getValues.
/**
* @param configuration FolderConfiguration of the style to lookup
* @return all values defined in this style with a FolderConfiguration configuration
*/
@NotNull
public Collection<ItemResourceValue> getValues(@NotNull FolderConfiguration configuration) {
if (isFramework()) {
IAndroidTarget target = myManager.getHighestApiTarget();
assert target != null;
com.android.ide.common.resources.ResourceItem styleItem = myManager.getResolverCache().getFrameworkResources(new FolderConfiguration(), target).getResourceItem(ResourceType.STYLE, getName());
for (ResourceFile file : styleItem.getSourceFileList()) {
if (file.getConfiguration().equals(configuration)) {
StyleResourceValue style = (StyleResourceValue) file.getValue(ResourceType.STYLE, getName());
return style.getValues();
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
for (final ResourceItem styleItem : getStyleResourceItems()) {
if (configuration.equals(styleItem.getConfiguration())) {
StyleResourceValue style = (StyleResourceValue) styleItem.getResourceValue(false);
if (style == null) {
// style might be null if the value fails to parse
continue;
}
return style.getValues();
}
}
throw new IllegalArgumentException("bad folder config " + configuration);
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class AndroidLintNewApiInspection method getApiDetectorFixes.
public static AndroidLintQuickFix[] getApiDetectorFixes(@NotNull Issue issue, @NotNull PsiElement startElement, @SuppressWarnings("UnusedParameters") @NotNull PsiElement endElement, @NotNull String message) {
// TODO: Return one for each parent context (declaration, method, class, outer class(es)
int api = ApiDetector.getRequiredVersion(issue, message, RAW);
if (api != -1) {
List<AndroidLintQuickFix> list = Lists.newArrayList();
PsiFile file = startElement.getContainingFile();
boolean isXml = false;
if (file instanceof XmlFile) {
isXml = true;
ResourceFolderType folderType = ResourceHelper.getFolderType(file);
if (folderType != null) {
FolderConfiguration config = ResourceHelper.getFolderConfiguration(file);
if (config != null) {
config.setVersionQualifier(new VersionQualifier(api));
String folder = config.getFolderName(folderType);
list.add(OverrideResourceAction.createFix(folder));
}
}
}
list.add(new AddTargetVersionCheckQuickFix(api));
list.add(new AddTargetApiQuickFix(api, false, startElement));
ApplicationManager.getApplication().assertReadAccessAllowed();
Project project = startElement.getProject();
if (!isXml && JavaPsiFacade.getInstance(project).findClass(REQUIRES_API_ANNOTATION, GlobalSearchScope.allScope(project)) != null) {
list.add(new AddTargetApiQuickFix(api, true, startElement));
}
return list.toArray(new AndroidLintQuickFix[list.size()]);
}
return AndroidLintQuickFix.EMPTY_ARRAY;
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ResourceDrawablePanel method select.
public void select(@NotNull ResourceChooserItem item) {
myItem = item;
List<String> qualifiers = item.getQualifiers();
//noinspection unchecked
myQualifierCombo.setModel(new DefaultComboBoxModel(ArrayUtil.toStringArray(qualifiers)));
// Select the current item's qualifiers!
//noinspection UnnecessaryLocalVariable
String currentQualifier = DEFAULT_FOLDER_NAME;
ResourceResolver resourceResolver = myDialog.getConfiguration().getResourceResolver();
if (resourceResolver != null) {
ResourceValue resourceValue = resourceResolver.resolveResValue(item.getResourceValue());
if (resourceValue != null) {
String value = resourceValue.getValue();
if (value != null) {
File rendered = new File(value);
if (rendered.exists()) {
File folder = rendered.getParentFile();
if (folder != null) {
String folderName = folder.getName();
FolderConfiguration folderConfig = FolderConfiguration.getConfigForFolder(folderName);
if (folderConfig != null) {
int index = folderName.indexOf('-');
if (index != -1) {
currentQualifier = folderName.substring(index + 1);
}
}
}
}
}
}
}
try {
myIgnoreSelection = true;
myQualifierCombo.setSelectedItem(currentQualifier);
} finally {
myIgnoreSelection = false;
}
show(item);
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class CreateResourceFileDialogBase method setupDeviceConfigurationPanel.
protected DeviceConfiguratorPanel setupDeviceConfigurationPanel(final JTextField directoryNameTextField, final TemplateKindCombo resourceTypeCombo, final JBLabel errorLabel) {
return new DeviceConfiguratorPanel() {
@Override
public void applyEditors() {
try {
doApplyEditors();
final FolderConfiguration config = this.getConfiguration();
final CreateTypedResourceFileAction selectedAction = getSelectedAction(resourceTypeCombo);
errorLabel.setText("");
directoryNameTextField.setText("");
if (selectedAction != null) {
final ResourceFolderType resFolderType = selectedAction.getResourceFolderType();
directoryNameTextField.setText(config.getFolderName(resFolderType));
}
} catch (InvalidOptionValueException e) {
errorLabel.setText(new HtmlBuilder().openHtmlBody().coloredText(JBColor.RED, e.getMessage()).closeHtmlBody().getHtml());
directoryNameTextField.setText("");
}
updateOkAction();
}
};
}
Aggregations