use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ConfigurationTest method testListener.
public void testListener() throws Exception {
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertNotNull(facet);
ConfigurationManager manager = facet.getConfigurationManager();
assertNotNull(manager);
assertSame(manager, facet.getConfigurationManager());
Configuration configuration = Configuration.create(manager, null, new FolderConfiguration());
assertNotNull(configuration);
ConfigurationListener listener = new ConfigurationListener() {
@Override
public boolean changed(int flags) {
myFlags = flags;
myChangeCount++;
return true;
}
};
configuration.addListener(listener);
myChangeCount = 0;
myFlags = 0;
configuration.setTheme("@style/MyTheme");
assertEquals(1, myChangeCount);
assertEquals(CFG_THEME, myFlags);
// No firing when no change:
configuration.setTheme("@style/MyTheme");
assertEquals(1, myChangeCount);
assertEquals(CFG_THEME, myFlags);
myChangeCount = 0;
myFlags = 0;
configuration.startBulkEditing();
configuration.setTheme("@style/MyTheme2");
assertEquals(0, myChangeCount);
assertEquals(0, myFlags);
configuration.setActivity("foo.bar.MyActivity");
assertEquals(0, myChangeCount);
assertEquals(0, myFlags);
configuration.finishBulkEditing();
assertEquals(1, myChangeCount);
assertEquals(CFG_THEME | CFG_ACTIVITY, myFlags);
myChangeCount = 0;
myFlags = 0;
configuration.startBulkEditing();
configuration.setTheme("@style/MyTheme3");
configuration.setActivity("foo.bar.MyActivity3");
configuration.setNightMode(NightMode.NIGHT);
configuration.finishBulkEditing();
assertEquals(1, myChangeCount);
assertEquals(CFG_THEME | CFG_ACTIVITY | CFG_NIGHT_MODE, myFlags);
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class OrientationMenuAction method getOrientation.
@NotNull
public static ScreenOrientation getOrientation(@NotNull State state) {
FolderConfiguration config = DeviceConfigHelper.getFolderConfig(state);
ScreenOrientation orientation = null;
if (config != null && config.getScreenOrientationQualifier() != null) {
orientation = config.getScreenOrientationQualifier().getValue();
}
if (orientation == null) {
orientation = ScreenOrientation.PORTRAIT;
}
return orientation;
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class LocaleMenuAction method getRelevantLocales.
/**
* Like {@link ConfigurationManager#getLocales} but filters out locales not compatible
* with language and region qualifiers in the current configuration's folder config
*
* @return the list of relevant locales in the project
*/
@NotNull
private List<Locale> getRelevantLocales() {
List<Locale> locales = new ArrayList<Locale>();
Configuration configuration = myRenderContext.getConfiguration();
if (configuration == null) {
return Collections.emptyList();
}
Module module = configuration.getConfigurationManager().getModule();
LocaleQualifier specificLocale = configuration.getEditedConfig().getLocaleQualifier();
// locale.
if (specificLocale != null) {
List<VirtualFile> variations = ResourceHelper.getResourceVariations(configuration.getFile(), false);
for (VirtualFile variation : variations) {
FolderConfiguration config = FolderConfiguration.getConfigForFolder(variation.getParent().getName());
if (config != null && config.getLocaleQualifier() == null) {
specificLocale = null;
break;
}
}
}
LocalResourceRepository projectResources = ProjectResourceRepository.getProjectResources(module, true);
Set<LocaleQualifier> languages = projectResources != null ? projectResources.getLocales() : Collections.<LocaleQualifier>emptySet();
for (LocaleQualifier l : languages) {
if (specificLocale != null && !specificLocale.isMatchFor(l)) {
continue;
}
locales.add(Locale.create(l));
}
return locales;
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class GraphicalResourceRendererEditor method updateComponentInternal.
/**
* Sets the UI state of the passed {@link ResourceComponent} based on the given {@link EditedStyleItem}
*/
private static void updateComponentInternal(@NotNull ResourceComponent component, @NotNull final EditedStyleItem item) {
final String currentVariantColor = ColorUtil.toHex(ThemeEditorConstants.CURRENT_VARIANT_COLOR);
final String notSelectedVariantColor = ColorUtil.toHex(ThemeEditorConstants.NOT_SELECTED_VARIANT_COLOR);
FolderConfiguration restrictedConfig = RestrictedConfiguration.restrict(item.getSelectedItemResourceValue(), item.getAllConfiguredItems());
String description = String.format(ThemeEditorConstants.CURRENT_VARIANT_TEMPLATE, currentVariantColor, item.getSelectedValueConfiguration().toShortDisplayString());
VariantsComboItem selectedItem = new VariantsComboItem(description, restrictedConfig != null ? restrictedConfig : item.getSelectedValueConfiguration(), item.getSelectedValueConfiguration());
// All the not selected elements are sorted alphabetically
TreeSet<VariantsComboItem> notSelectedItems = Sets.newTreeSet(VARIANTS_COMBO_ITEM_COMPARATOR);
for (ConfiguredElement<ItemResourceValue> configuredItem : item.getNonSelectedItemResourceValues()) {
restrictedConfig = RestrictedConfiguration.restrict(configuredItem, item.getAllConfiguredItems());
if (restrictedConfig == null) {
// This type is not visible
LOG.warn(String.format("For item '%1$s': Folder configuration '%2$s' can never be selected. There are no qualifiers combination that would allow selecting it.", item.getName(), configuredItem.getConfiguration()));
continue;
}
description = String.format(ThemeEditorConstants.NOT_SELECTED_VARIANT_TEMPLATE, notSelectedVariantColor, configuredItem.getConfiguration().toShortDisplayString(), " - " + configuredItem.getElement().getValue());
notSelectedItems.add(new VariantsComboItem(description, restrictedConfig, configuredItem.getConfiguration()));
}
ImmutableList<VariantsComboItem> variantList = ImmutableList.<VariantsComboItem>builder().add(selectedItem).addAll(notSelectedItems).build();
component.setVariantsModel(new CollectionComboBoxModel<VariantsComboItem>(variantList, selectedItem));
}
use of com.android.ide.common.resources.configuration.FolderConfiguration in project android by JetBrains.
the class ThemeAttributeResolver method resolveAll.
@NotNull
private List<EditedStyleItem> resolveAll() {
ThemeEditorStyle theme = new ThemeEditorStyle(myManager, myStyle.getQualifiedName());
for (FolderConfiguration folder : theme.getFolders()) {
resolveFromInheritance(myStyle, folder, new RestrictedConfiguration(), new HashSet<String>());
}
List<EditedStyleItem> result = Lists.newArrayList();
FolderConfiguration configuration = myStyle.getConfiguration().getFullConfig();
for (String key : myItemValueMap.keySet()) {
Collection<ConfiguredElement<ItemResourceValue>> itemValues = myItemValueMap.get(key);
final ConfiguredElement<ItemResourceValue> selectedValue = (ConfiguredElement<ItemResourceValue>) configuration.findMatchingConfigurable(Lists.<Configurable>newArrayList(itemValues));
if (selectedValue == null) {
// TODO: there is NO value for this attribute in the current config,so instead we need to show "no value for current device"
result.add(new EditedStyleItem(itemValues.iterator().next(), itemValues, myStyle));
} else {
itemValues.remove(selectedValue);
assert !itemValues.contains(selectedValue);
result.add(new EditedStyleItem(selectedValue, itemValues, myStyle));
}
}
return result;
}
Aggregations