use of com.android.ide.common.resources.configuration.LocaleQualifier in project android by JetBrains.
the class StringResourceParser method parseUnderReadLock.
@NotNull
private static StringResourceData parseUnderReadLock(AndroidFacet facet, LocalResourceRepository repository) {
List<String> keys = Lists.newArrayList(repository.getItemsOfType(ResourceType.STRING));
Collections.sort(keys);
Map<String, StringResource> keyToResourceMap = new HashMap<>();
Project project = facet.getModule().getProject();
for (String key : keys) {
List<ResourceItem> items = repository.getResourceItem(ResourceType.STRING, key);
if (items == null) {
continue;
}
StringResource stringResource = new StringResource(key);
for (ResourceItem item : items) {
XmlTag tag = LocalResourceRepository.getItemTag(project, item);
if (tag != null && SdkConstants.VALUE_FALSE.equals(tag.getAttributeValue(SdkConstants.ATTR_TRANSLATABLE))) {
stringResource.setTranslatable(false);
}
String itemStringRepresentation = resourceToString(project, item);
FolderConfiguration config = item.getConfiguration();
LocaleQualifier qualifier = config == null ? null : config.getLocaleQualifier();
if (qualifier == null) {
stringResource.setDefaultValue(item, itemStringRepresentation);
} else {
Locale locale = Locale.create(qualifier);
stringResource.putTranslation(locale, item, itemStringRepresentation);
}
}
keyToResourceMap.put(key, stringResource);
}
return new StringResourceData(facet, keyToResourceMap);
}
use of com.android.ide.common.resources.configuration.LocaleQualifier in project android by JetBrains.
the class StringsWriteUtils method getStringResourceItem.
@Nullable
private static ResourceItem getStringResourceItem(@NotNull AndroidFacet facet, @NotNull String key, @Nullable Locale locale) {
LocalResourceRepository repository = facet.getModuleResources(true);
// Ensure that items *just* created are processed by the resource repository
repository.sync();
List<ResourceItem> items = repository.getResourceItem(ResourceType.STRING, key);
if (items == null) {
return null;
}
for (ResourceItem item : items) {
FolderConfiguration config = item.getConfiguration();
LocaleQualifier qualifier = config == null ? null : config.getLocaleQualifier();
if (qualifier == null) {
if (locale == null) {
return item;
} else {
continue;
}
}
Locale l = Locale.create(qualifier);
if (l.equals(locale)) {
return item;
}
}
return null;
}
use of com.android.ide.common.resources.configuration.LocaleQualifier in project android_frameworks_base by crdroidandroid.
the class ConfigGenerator method getFolderConfig.
public FolderConfiguration getFolderConfig() {
FolderConfiguration config = new FolderConfiguration();
config.createDefault();
config.setDensityQualifier(new DensityQualifier(mDensity));
config.setNavigationMethodQualifier(new NavigationMethodQualifier(mNavigation));
if (mScreenWidth > mScreenHeight) {
config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenWidth, mScreenHeight));
} else {
config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenHeight, mScreenWidth));
}
config.setScreenRatioQualifier(new ScreenRatioQualifier(mRatio));
config.setScreenSizeQualifier(new ScreenSizeQualifier(mSize));
config.setTextInputMethodQualifier(new TextInputMethodQualifier(mKeyboard));
config.setTouchTypeQualifier(new TouchScreenQualifier(mTouchScreen));
config.setKeyboardStateQualifier(new KeyboardStateQualifier(mKeyboardState));
config.setScreenOrientationQualifier(new ScreenOrientationQualifier(mOrientation));
config.updateScreenWidthAndHeight();
// some default qualifiers.
config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT));
config.setCountryCodeQualifier(new CountryCodeQualifier());
config.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
config.setNetworkCodeQualifier(new NetworkCodeQualifier());
config.setLocaleQualifier(new LocaleQualifier());
config.setVersionQualifier(new VersionQualifier());
return config;
}
use of com.android.ide.common.resources.configuration.LocaleQualifier in project android_frameworks_base by AOSPA.
the class ConfigGenerator method getFolderConfig.
public FolderConfiguration getFolderConfig() {
FolderConfiguration config = new FolderConfiguration();
config.createDefault();
config.setDensityQualifier(new DensityQualifier(mDensity));
config.setNavigationMethodQualifier(new NavigationMethodQualifier(mNavigation));
if (mScreenWidth > mScreenHeight) {
config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenWidth, mScreenHeight));
} else {
config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenHeight, mScreenWidth));
}
config.setScreenRatioQualifier(new ScreenRatioQualifier(mRatio));
config.setScreenSizeQualifier(new ScreenSizeQualifier(mSize));
config.setTextInputMethodQualifier(new TextInputMethodQualifier(mKeyboard));
config.setTouchTypeQualifier(new TouchScreenQualifier(mTouchScreen));
config.setKeyboardStateQualifier(new KeyboardStateQualifier(mKeyboardState));
config.setScreenOrientationQualifier(new ScreenOrientationQualifier(mOrientation));
config.updateScreenWidthAndHeight();
// some default qualifiers.
config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT));
config.setCountryCodeQualifier(new CountryCodeQualifier());
config.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
config.setNetworkCodeQualifier(new NetworkCodeQualifier());
config.setLocaleQualifier(new LocaleQualifier());
config.setVersionQualifier(new VersionQualifier());
return config;
}
use of com.android.ide.common.resources.configuration.LocaleQualifier in project android by JetBrains.
the class ConfigurationTest method test.
public void test() 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);
configuration.startBulkEditing();
configuration.setDisplayName("myconfig");
configuration.setTheme("@style/Theme1");
configuration.setNightMode(NightMode.NIGHT);
configuration.setActivity("tes.tpkg.MyActivity1");
configuration.setUiMode(UiMode.TELEVISION);
IAndroidTarget target = configuration.getConfigurationManager().getTarget();
Device device = configuration.getConfigurationManager().getDefaultDevice();
State deviceState = device != null ? device.getState("Portrait") : null;
if (target != null) {
configuration.setTarget(target);
}
if (device != null) {
configuration.setDevice(device, false);
assertNotNull(deviceState);
configuration.setDeviceState(deviceState);
}
configuration.setLocale(Locale.create("en-rUS"));
configuration.finishBulkEditing();
assertEquals("myconfig", configuration.getDisplayName());
assertEquals("@style/Theme1", configuration.getTheme());
assertEquals(NightMode.NIGHT, configuration.getNightMode());
assertEquals("tes.tpkg.MyActivity1", configuration.getActivity());
assertEquals(UiMode.TELEVISION, configuration.getUiMode());
assertEquals(Locale.create("en-rUS"), configuration.getLocale());
if (target != null) {
assertSame(target, configuration.getRealTarget());
}
if (device != null) {
assertSame(device, configuration.getDevice());
assertNotNull(deviceState);
assertSame(deviceState, configuration.getDeviceState());
}
FolderConfiguration fullConfig = configuration.getFullConfig();
LocaleQualifier languageQualifier = fullConfig.getLocaleQualifier();
String configDisplayString = fullConfig.toDisplayString();
assertNotNull(configDisplayString, languageQualifier);
assertEquals("en", languageQualifier.getLanguage());
String region = fullConfig.getLocaleQualifier().getRegion();
assertNotNull(configDisplayString, region);
assertEquals("US", region);
assertEquals(UiMode.TELEVISION, fullConfig.getUiModeQualifier().getValue());
assertEquals(NightMode.NIGHT, fullConfig.getNightModeQualifier().getValue());
assertEquals(ScreenOrientation.PORTRAIT, fullConfig.getScreenOrientationQualifier().getValue());
if (device != null) {
State landscape = device.getState("Landscape");
assertNotNull(landscape);
configuration.setDeviceState(landscape);
assertEquals(ScreenOrientation.LANDSCAPE, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
}
Density density = configuration.getDensity();
assertEquals(Density.XHIGH, density);
DensityQualifier qualifier = new DensityQualifier().getNullQualifier();
configuration.getFullConfig().setDensityQualifier(qualifier);
density = configuration.getDensity();
assertEquals(Density.MEDIUM, density);
}
Aggregations