aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/.classpath30
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java63
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java18
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java26
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationMatcher.java24
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManager.java55
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Locale.java171
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java8
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java6
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ConfigurationSelector.java165
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.base/.classpath28
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.ddms/.classpath12
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/.classpath2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java23
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManagerTest.java163
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/LocaleTest.java97
16 files changed, 439 insertions, 452 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/.classpath b/eclipse/plugins/com.android.ide.eclipse.adt/.classpath
index 4476b4c..c5f5919 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/.classpath
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/.classpath
@@ -3,20 +3,20 @@
<classpathentry excluding="Makefile|resources/" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry exported="true" kind="lib" path="libs/ninepatch.jar" sourcepath="/ninepatch"/>
- <classpathentry exported="true" kind="lib" path="libs/sdkuilib.jar" sourcepath="/sdkuilib"/>
- <classpathentry exported="true" kind="lib" path="libs/rule-api.jar" sourcepath="/rule-api"/>
- <classpathentry exported="true" kind="lib" path="libs/lint-api.jar" sourcepath="/lint-api"/>
- <classpathentry exported="true" kind="lib" path="libs/lint-checks.jar" sourcepath="/lint-checks"/>
- <classpathentry exported="true" kind="lib" path="libs/asset-studio.jar" sourcepath="/asset-studio"/>
- <classpathentry exported="true" kind="lib" path="libs/ant-glob.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/freemarker-2.3.20.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/manifest-merger.jar" sourcepath="/ManifestMerger"/>
- <classpathentry exported="true" kind="lib" path="libs/lombok-ast-0.2.2.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/propertysheet.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/asm-5.0.3.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/asm-analysis-5.0.3.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/asm-tree-5.0.3.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/swtmenubar.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/ninepatch.jar" sourcepath="/ninepatch"/>
+ <classpathentry exported="true" kind="lib" path="libs/sdkuilib.jar" sourcepath="/sdkuilib"/>
+ <classpathentry exported="true" kind="lib" path="libs/rule-api.jar" sourcepath="/rule-api"/>
+ <classpathentry exported="true" kind="lib" path="libs/lint-api.jar" sourcepath="/lint-api"/>
+ <classpathentry exported="true" kind="lib" path="libs/lint-checks.jar" sourcepath="/lint-checks"/>
+ <classpathentry exported="true" kind="lib" path="libs/asset-studio.jar" sourcepath="/asset-studio"/>
+ <classpathentry exported="true" kind="lib" path="libs/ant-glob.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/freemarker-2.3.20.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/manifest-merger.jar" sourcepath="/ManifestMerger"/>
+ <classpathentry exported="true" kind="lib" path="libs/lombok-ast-0.2.2.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/propertysheet.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/asm-5.0.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/asm-analysis-5.0.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/asm-tree-5.0.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/swtmenubar.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java
index 56479e7..c4253cd 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java
@@ -29,10 +29,9 @@ import com.android.ide.common.resources.ResourceRepository;
import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.DeviceConfigHelper;
import com.android.ide.common.resources.configuration.FolderConfiguration;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
import com.android.ide.common.resources.configuration.LayoutDirectionQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.NightModeQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
import com.android.ide.common.resources.configuration.ScreenSizeQualifier;
import com.android.ide.common.resources.configuration.UiModeQualifier;
import com.android.ide.common.resources.configuration.VersionQualifier;
@@ -374,7 +373,7 @@ public class Configuration {
* @return if this configuration represents a locale-specific layout
*/
public boolean isLocaleSpecificLayout() {
- return mEditedConfig == null || mEditedConfig.getLanguageQualifier() != null;
+ return mEditedConfig == null || mEditedConfig.getLocaleQualifier() != null;
}
/**
@@ -563,8 +562,7 @@ public class Configuration {
// sync the selected locale
Locale locale = getLocale();
- mFullConfig.setLanguageQualifier(locale.language);
- mFullConfig.setRegionQualifier(locale.region);
+ mFullConfig.setLocaleQualifier(locale.qualifier);
if (!locale.hasLanguage()) {
// Avoid getting the layout library if the locale doesn't have any language.
mFullConfig.setLayoutDirectionQualifier(
@@ -630,11 +628,13 @@ public class Configuration {
}
sb.append(SEP);
Locale locale = getLocale();
- if (isLocaleSpecificLayout() && locale != null) {
+ if (isLocaleSpecificLayout() && locale != null && locale.qualifier.hasLanguage()) {
// locale[0]/[1] can be null sometimes when starting Eclipse
- sb.append(locale.language.getValue());
+ sb.append(locale.qualifier.getLanguage());
sb.append(SEP_LOCALE);
- sb.append(locale.region.getValue());
+ if (locale.qualifier.hasRegion()) {
+ sb.append(locale.qualifier.getRegion());
+ }
}
sb.append(SEP);
// Need to escape the theme: if we write the full theme style, then
@@ -764,17 +764,18 @@ public class Configuration {
if (config != null) {
// Load locale. Note that this can get overwritten by the
// project-wide settings read below.
- LanguageQualifier language = Locale.ANY_LANGUAGE;
- RegionQualifier region = Locale.ANY_REGION;
+ LocaleQualifier locale = Locale.ANY_QUALIFIER;
String locales[] = values[2].split(SEP_LOCALE);
- if (locales.length >= 2) {
- if (locales[0].length() > 0) {
- language = new LanguageQualifier(locales[0]);
- }
- if (locales[1].length() > 0) {
- region = new RegionQualifier(locales[1]);
+ if (locales.length >= 2 && locales[0].length() > 0
+ && !LocaleQualifier.FAKE_VALUE.equals(locales[0])) {
+ String language = locales[0];
+ String region = locales[1];
+ if (region.length() > 0 && !LocaleQualifier.FAKE_VALUE.equals(region)) {
+ locale = LocaleQualifier.getQualifier(language + "-r" + region);
+ } else {
+ locale = new LocaleQualifier(language);
}
- mLocale = Locale.create(language, region);
+ mLocale = Locale.create(locale);
}
// Decode the theme name: See {@link #getData}
@@ -848,19 +849,21 @@ public class Configuration {
String[] values = data.split(SEP);
if (values.length == 2) {
- LanguageQualifier language = Locale.ANY_LANGUAGE;
- RegionQualifier region = Locale.ANY_REGION;
+
+ LocaleQualifier qualifier = Locale.ANY_QUALIFIER;
String locales[] = values[0].split(SEP_LOCALE);
- if (locales.length >= 2) {
- if (locales[0].length() > 0) {
- language = new LanguageQualifier(locales[0]);
- }
- if (locales[1].length() > 0) {
- region = new RegionQualifier(locales[1]);
+ if (locales.length >= 2 && locales[0].length() > 0
+ && !LocaleQualifier.FAKE_VALUE.equals(locales[0])) {
+ String language = locales[0];
+ String region = locales[1];
+ if (region.length() > 0 && !LocaleQualifier.FAKE_VALUE.equals(region)) {
+ locale = Locale.create(LocaleQualifier.getQualifier(language + "-r" + region));
+ } else {
+ locale = Locale.create(new LocaleQualifier(language));
}
+ } else {
+ locale = Locale.ANY;
}
- locale = Locale.create(language, region);
-
if (AdtPrefs.getPrefs().isAutoPickRenderTarget()) {
target = ConfigurationMatcher.findDefaultRenderTarget(chooser);
} else {
@@ -916,9 +919,11 @@ public class Configuration {
Locale locale = getLocale();
if (locale != null) {
// locale[0]/[1] can be null sometimes when starting Eclipse
- sb.append(locale.language.getValue());
+ sb.append(locale.qualifier.getLanguage());
sb.append(SEP_LOCALE);
- sb.append(locale.region.getValue());
+ if (locale.qualifier.hasRegion()) {
+ sb.append(locale.qualifier.getRegion());
+ }
}
sb.append(SEP);
IAndroidTarget target = getTarget();
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java
index 5805390..009b864 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java
@@ -43,8 +43,7 @@ import com.android.ide.common.resources.ResourceFolder;
import com.android.ide.common.resources.ResourceRepository;
import com.android.ide.common.resources.configuration.DeviceConfigHelper;
import com.android.ide.common.resources.configuration.FolderConfiguration;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.ResourceQualifier;
import com.android.ide.common.sdk.LoadStatus;
import com.android.ide.eclipse.adt.AdtPlugin;
@@ -1333,7 +1332,7 @@ public class ConfigurationChooser extends Composite
}
}
- String languageCode = locale.language.getValue();
+ String languageCode = locale.qualifier.getLanguage();
String languageName = LocaleManager.getLanguageName(languageCode);
if (!locale.hasRegion()) {
@@ -1350,7 +1349,7 @@ public class ConfigurationChooser extends Composite
return languageCode;
}
} else {
- String regionCode = locale.region.getValue();
+ String regionCode = locale.qualifier.getRegion();
if (!brief && languageName != null) {
String regionName = LocaleManager.getRegionName(regionCode);
if (regionName != null) {
@@ -1905,18 +1904,19 @@ public class ConfigurationChooser extends Composite
languages = projectRes.getLanguages();
for (String language : languages) {
- LanguageQualifier langQual = new LanguageQualifier(language);
-
// find the matching regions and add them
SortedSet<String> regions = projectRes.getRegions(language);
for (String region : regions) {
- RegionQualifier regionQual = new RegionQualifier(region);
- mLocaleList.add(Locale.create(langQual, regionQual));
+ LocaleQualifier locale = LocaleQualifier.getQualifier(language + "-r" + region);
+ if (locale != null) {
+ mLocaleList.add(Locale.create(locale));
+ }
}
// now the entry for the other regions the language alone
// create a region qualifier that will never be matched by qualified resources.
- mLocaleList.add(Locale.create(langQual));
+ LocaleQualifier locale = new LocaleQualifier(language);
+ mLocaleList.add(Locale.create(locale));
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java
index f7be53d..956ac18 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java
@@ -27,8 +27,7 @@ import com.android.annotations.Nullable;
import com.android.ide.common.resources.ResourceRepository;
import com.android.ide.common.resources.configuration.DeviceConfigHelper;
import com.android.ide.common.resources.configuration.FolderConfiguration;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.ScreenSizeQualifier;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo;
@@ -201,16 +200,19 @@ public class ConfigurationDescription {
if (!localeString.isEmpty()) {
// Load locale. Note that this can get overwritten by the
// project-wide settings read below.
- LanguageQualifier language = Locale.ANY_LANGUAGE;
- RegionQualifier region = Locale.ANY_REGION;
String locales[] = localeString.split(SEP_LOCALE);
- if (locales[0].length() > 0) {
- language = new LanguageQualifier(locales[0]);
- }
- if (locales.length > 1 && locales[1].length() > 0) {
- region = new RegionQualifier(locales[1]);
+ if (locales[0].length() > 0 && !LocaleQualifier.FAKE_VALUE.equals(locales[0])) {
+ String language = locales[0];
+ if (locales.length >= 2 && locales[1].length() > 0 && !LocaleQualifier.FAKE_VALUE.equals(locales[1])) {
+ description.locale = Locale.create(LocaleQualifier.getQualifier(language + "-r" + locales[1]));
+ } else {
+ description.locale = Locale.create(new LocaleQualifier(language));
+ }
+ } else {
+ description.locale = Locale.ANY;
}
- description.locale = Locale.create(language, region);
+
+
}
String activity = element.getAttribute(ATTR_ACTIVITY);
@@ -281,9 +283,9 @@ public class ConfigurationDescription {
if (locale != null && (locale.hasLanguage() || locale.hasRegion())) {
String value;
if (locale.hasRegion()) {
- value = locale.language.getValue() + SEP_LOCALE + locale.region.getValue();
+ value = locale.qualifier.getLanguage() + SEP_LOCALE + locale.qualifier.getRegion();
} else {
- value = locale.language.getValue();
+ value = locale.qualifier.getLanguage();
}
element.setAttribute(ATTR_LOCALE, value);
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationMatcher.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationMatcher.java
index b868f14..9724d40 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationMatcher.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationMatcher.java
@@ -21,9 +21,8 @@ import com.android.ide.common.resources.ResourceFile;
import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.DeviceConfigHelper;
import com.android.ide.common.resources.configuration.FolderConfiguration;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.NightModeQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
import com.android.ide.common.resources.configuration.ResourceQualifier;
import com.android.ide.common.resources.configuration.ScreenOrientationQualifier;
import com.android.ide.common.resources.configuration.ScreenSizeQualifier;
@@ -205,8 +204,8 @@ public class ConfigurationMatcher {
Locale locale = localeList.get(i);
// update the test config with the locale qualifiers
- testConfig.setLanguageQualifier(locale.language);
- testConfig.setRegionQualifier(locale.region);
+ testConfig.setLocaleQualifier(locale.qualifier);
+
if (editedConfig.isMatchFor(testConfig) &&
isCurrentFileBestMatchFor(testConfig)) {
@@ -273,7 +272,7 @@ public class ConfigurationMatcher {
// However, if it doesn't, we don't randomly take the first locale, we take one
// matching the current host locale (making sure it actually exist in the project)
int start, max;
- if (editedConfig.getLanguageQualifier() != null || localeHostMatch == -1) {
+ if (editedConfig.getLocaleQualifier() != null || localeHostMatch == -1) {
// add all the locales
start = 0;
max = localeList.size();
@@ -287,8 +286,7 @@ public class ConfigurationMatcher {
Locale l = localeList.get(i);
ConfigBundle bundle = new ConfigBundle();
- bundle.config.setLanguageQualifier(l.language);
- bundle.config.setRegionQualifier(l.region);
+ bundle.config.setLocaleQualifier(l.qualifier);
bundle.localeIndex = i;
configBundles.add(bundle);
@@ -459,17 +457,15 @@ public class ConfigurationMatcher {
final int count = localeList.size();
for (int l = 0; l < count; l++) {
Locale locale = localeList.get(l);
- LanguageQualifier langQ = locale.language;
- RegionQualifier regionQ = locale.region;
+ LocaleQualifier qualifier = locale.qualifier;
// there's always a ##/Other or ##/Any (which is the same, the region
// contains FAKE_REGION_VALUE). If we don't find a perfect region match
// we take the fake region. Since it's last in the list, this makes the
// test easy.
- if (langQ.getValue().equals(currentLanguage) &&
- (regionQ.getValue().equals(currentRegion) ||
- regionQ.getValue().equals(RegionQualifier.FAKE_REGION_VALUE))) {
- return l;
+ if (qualifier.getLanguage().equals(currentLanguage) &&
+ (qualifier.getRegion() == null || qualifier.getRegion().equals(currentRegion))) {
+ return l;
}
}
@@ -766,7 +762,7 @@ public class ConfigurationMatcher {
*/
private static class PhoneConfigComparator implements Comparator<ConfigMatch> {
- private SparseIntArray mDensitySort = new SparseIntArray(4);
+ private final SparseIntArray mDensitySort = new SparseIntArray(4);
public PhoneConfigComparator() {
// put the sort order for the density.
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManager.java
index 484acb7..15623cf 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManager.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManager.java
@@ -18,10 +18,9 @@ package com.android.ide.eclipse.adt.internal.editors.layout.configuration;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.ide.common.resources.LocaleManager;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
+import com.android.ide.common.resources.configuration.FolderConfiguration;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.eclipse.adt.internal.editors.IconFactory;
-import com.google.common.base.Splitter;
import com.google.common.collect.Maps;
import org.eclipse.swt.graphics.Image;
@@ -62,7 +61,7 @@ public class FlagManager {
}
/** Map from region to flag icon */
- private Map<String, Image> mImageMap = Maps.newHashMap();
+ private final Map<String, Image> mImageMap = Maps.newHashMap();
/**
* Returns the empty flag icon used to indicate an unknown country
@@ -140,16 +139,16 @@ public class FlagManager {
* @param region the region, or null (if null, language must not be null),
* @return a suitable flag icon, or null
*/
- public Image getFlag(LanguageQualifier language, RegionQualifier region) {
- String languageCode = language != null ? language.getValue() : null;
- String regionCode = region != null ? region.getValue() : null;
- if (LanguageQualifier.FAKE_LANG_VALUE.equals(languageCode)) {
+ public Image getFlag(@Nullable LocaleQualifier locale) {
+ if (locale == null) {
+ return null;
+ }
+ String languageCode = locale.getLanguage();
+ String regionCode = locale.getRegion();
+ if (LocaleQualifier.FAKE_VALUE.equals(languageCode)) {
languageCode = null;
- }
- if (RegionQualifier.FAKE_REGION_VALUE.equals(regionCode)) {
- regionCode = null;
- }
- return getFlag(languageCode, regionCode);
+ }
+ return getFlag(languageCode, regionCode);
}
/**
@@ -161,26 +160,28 @@ public class FlagManager {
*/
@Nullable
public Image getFlagForFolderName(@NonNull String folder) {
- RegionQualifier region = null;
- LanguageQualifier language = null;
- for (String qualifier : Splitter.on('-').split(folder)) {
- if (qualifier.length() == 3) {
- region = RegionQualifier.getQualifier(qualifier);
- if (region != null) {
- break;
- }
- } else if (qualifier.length() == 2 && language == null) {
- language = LanguageQualifier.getQualifier(qualifier);
- }
- }
- if (region != null || language != null) {
- return FlagManager.get().getFlag(language, region);
+ FolderConfiguration configuration = FolderConfiguration.getConfigForFolder(folder);
+ if (configuration != null) {
+ return get().getFlag(configuration);
}
return null;
}
/**
+ * Returns the flag for the given folder
+ *
+ * @param configuration the folder configuration
+ * @return a suitable flag icon, or null
+ */
+ @Nullable
+ public Image getFlag(@NonNull FolderConfiguration configuration) {
+ return getFlag(configuration.getLocaleQualifier());
+ }
+
+
+
+ /**
* Returns the flag for the given region.
*
* @param region the 2 letter region code (ISO 3166-1 alpha-2), in upper case
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Locale.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Locale.java
index 879efd7..6cb3963 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Locale.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Locale.java
@@ -16,74 +16,94 @@
package com.android.ide.eclipse.adt.internal.editors.layout.configuration;
-import static com.android.ide.common.resources.configuration.LanguageQualifier.FAKE_LANG_VALUE;
-import static com.android.ide.common.resources.configuration.RegionQualifier.FAKE_REGION_VALUE;
+import static com.android.ide.common.resources.configuration.LocaleQualifier.FAKE_VALUE;
import com.android.annotations.NonNull;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
-import com.google.common.base.Objects;
+import com.android.annotations.Nullable;
+import com.android.ide.common.resources.configuration.FolderConfiguration;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import org.eclipse.swt.graphics.Image;
-/** A language,region pair */
+/**
+ * A language,region pair
+ */
public class Locale {
- /** A special marker region qualifier representing any region */
- public static final RegionQualifier ANY_REGION = new RegionQualifier(FAKE_REGION_VALUE);
-
- /** A special marker language qualifier representing any language */
- public static final LanguageQualifier ANY_LANGUAGE = new LanguageQualifier(FAKE_LANG_VALUE);
-
- /** A locale which matches any language and region */
- public static final Locale ANY = new Locale(ANY_LANGUAGE, ANY_REGION);
+ /**
+ * A special marker region qualifier representing any region
+ */
+ public static final LocaleQualifier ANY_QUALIFIER = new LocaleQualifier(FAKE_VALUE);
- /** The language qualifier, or {@link #ANY_LANGUAGE} if this locale matches any language */
- @NonNull
- public final LanguageQualifier language;
+ /**
+ * A locale which matches any language and region
+ */
+ public static final Locale ANY = new Locale(ANY_QUALIFIER);
- /** The language qualifier, or {@link #ANY_REGION} if this locale matches any region */
+ /**
+ * The locale qualifier, or {@link #ANY_QUALIFIER} if this locale matches
+ * any locale
+ */
@NonNull
- public final RegionQualifier region;
+ public final LocaleQualifier qualifier;
/**
- * Constructs a new {@linkplain Locale} matching a given language in a given locale.
+ * Constructs a new {@linkplain Locale} matching a given language in a given
+ * locale.
*
- * @param language the language
- * @param region the region
+ * @param locale the locale
*/
- private Locale(@NonNull LanguageQualifier language, @NonNull RegionQualifier region) {
- if (language.getValue().equals(FAKE_LANG_VALUE)) {
- language = ANY_LANGUAGE;
- }
- if (region.getValue().equals(FAKE_REGION_VALUE)) {
- region = ANY_REGION;
- }
- this.language = language;
- this.region = region;
+ private Locale(@NonNull
+ LocaleQualifier locale) {
+ qualifier = locale;
}
/**
- * Constructs a new {@linkplain Locale} matching a given language in a given specific locale.
+ * Constructs a new {@linkplain Locale} matching a given language in a given
+ * specific locale.
*
- * @param language the language
- * @param region the region
- * @return a locale with the given language and region
+ * @param locale the locale
+ * @return a locale with the given locale
*/
@NonNull
- public static Locale create(
- @NonNull LanguageQualifier language,
- @NonNull RegionQualifier region) {
- return new Locale(language, region);
+ public static Locale create(@NonNull
+ LocaleQualifier locale) {
+ return new Locale(locale);
}
/**
- * Constructs a new {@linkplain Locale} for the given language, matching any regions.
+ * Constructs a new {@linkplain Locale} for the given folder configuration
*
- * @param language the language
+ * @param folder the folder configuration
* @return a locale with the given language and region
*/
- public static Locale create(@NonNull LanguageQualifier language) {
- return new Locale(language, ANY_REGION);
+ public static Locale create(FolderConfiguration folder) {
+ LocaleQualifier locale = folder.getLocaleQualifier();
+ if (locale == null) {
+ return ANY;
+ } else {
+ return new Locale(locale);
+ }
+ }
+
+ /**
+ * Constructs a new {@linkplain Locale} for the given locale string, e.g.
+ * "zh", "en-rUS", or "b+eng+US".
+ *
+ * @param localeString the locale description
+ * @return the corresponding locale
+ */
+ @NonNull
+ public static Locale create(@NonNull
+ String localeString) {
+ // Load locale. Note that this can get overwritten by the
+ // project-wide settings read below.
+
+ LocaleQualifier qualifier = LocaleQualifier.getQualifier(localeString);
+ if (qualifier != null) {
+ return new Locale(qualifier);
+ } else {
+ return ANY;
+ }
}
/**
@@ -93,19 +113,17 @@ public class Locale {
*/
@NonNull
public Image getFlagImage() {
- Image image = null;
- String languageCode = hasLanguage() ? language.getValue() : null;
- String regionCode = hasRegion() ? region.getValue() : null;
- if (languageCode == null && regionCode == null) {
+ String languageCode = qualifier.hasLanguage() ? qualifier.getLanguage() : null;
+ if (languageCode == null) {
return FlagManager.getGlobeIcon();
- } else {
- FlagManager icons = FlagManager.get();
- image = icons.getFlag(languageCode, regionCode);
- if (image == null) {
- image = FlagManager.getEmptyIcon();
- }
-
+ }
+ String regionCode = hasRegion() ? qualifier.getRegion() : null;
+ FlagManager icons = FlagManager.get();
+ Image image = icons.getFlag(languageCode, regionCode);
+ if (image != null) {
return image;
+ } else {
+ return FlagManager.getGlobeIcon();
}
}
@@ -116,7 +134,7 @@ public class Locale {
* @return true if this locale specifies a specific language
*/
public boolean hasLanguage() {
- return language != ANY_LANGUAGE;
+ return !qualifier.hasFakeValue();
}
/**
@@ -125,20 +143,28 @@ public class Locale {
* @return true if this locale specifies a region
*/
public boolean hasRegion() {
- return region != ANY_REGION;
+ return qualifier.getRegion() != null && !FAKE_VALUE.equals(qualifier.getRegion());
+ }
+
+ /**
+ * Returns the locale formatted as language-region. If region is not set,
+ * language is returned. If language is not set, empty string is returned.
+ */
+ public String toLocaleId() {
+ return qualifier == ANY_QUALIFIER ? "" : qualifier.getTag();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((language == null) ? 0 : language.hashCode());
- result = prime * result + ((region == null) ? 0 : region.hashCode());
+ result = prime * result + qualifier.hashCode();
return result;
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(@Nullable
+ Object obj) {
if (this == obj)
return true;
if (obj == null)
@@ -146,36 +172,13 @@ public class Locale {
if (getClass() != obj.getClass())
return false;
Locale other = (Locale) obj;
- if (language == null) {
- if (other.language != null)
- return false;
- } else if (!language.equals(other.language))
- return false;
- if (region == null) {
- if (other.region != null)
- return false;
- } else if (!region.equals(other.region))
+ if (!qualifier.equals(other.qualifier))
return false;
return true;
}
@Override
public String toString() {
- return Objects.toStringHelper(this).omitNullValues()
- .addValue(language.getValue())
- .addValue(region.getValue())
- .toString();
- }
-
- /**
- * Returns the locale formatted as language-region. If region is not set,
- * language is returned. If language is not set, empty string is returned.
- */
- public String toLocaleId() {
- // Return lang-reg only if both lang and reg are present. Else return
- // lang.
- return hasLanguage() && hasRegion() ?
- language.getValue() + "-" + region.getValue()
- : hasLanguage() ? language.getValue() : "";
+ return qualifier.getTag();
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java
index 9f6c3a2..98dde86 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java
@@ -33,7 +33,7 @@ import com.android.ide.common.rendering.api.Capability;
import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.DeviceConfigHelper;
import com.android.ide.common.resources.configuration.FolderConfiguration;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.ScreenSizeQualifier;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AdtUtils;
@@ -800,10 +800,10 @@ public class RenderPreviewManager {
}
private void createLocaleVariation(ConfigurationChooser chooser, Configuration parent) {
- LanguageQualifier currentLanguage = parent.getLocale().language;
+ LocaleQualifier currentLanguage = parent.getLocale().qualifier;
for (Locale locale : chooser.getLocaleList()) {
- LanguageQualifier language = locale.language;
- if (!language.equals(currentLanguage)) {
+ LocaleQualifier qualifier = locale.qualifier;
+ if (!qualifier.getLanguage().equals(currentLanguage.getLanguage())) {
VaryingConfiguration configuration =
VaryingConfiguration.create(chooser, parent);
configuration.setAlternateLocale(true);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java
index 8da18dd..b0e3d43 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java
@@ -40,13 +40,12 @@ import com.android.ide.common.resources.configuration.CountryCodeQualifier;
import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.common.resources.configuration.KeyboardStateQualifier;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
import com.android.ide.common.resources.configuration.LayoutDirectionQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.NavigationMethodQualifier;
import com.android.ide.common.resources.configuration.NavigationStateQualifier;
import com.android.ide.common.resources.configuration.NetworkCodeQualifier;
import com.android.ide.common.resources.configuration.NightModeQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
import com.android.ide.common.resources.configuration.ResourceQualifier;
import com.android.ide.common.resources.configuration.ScreenDimensionQualifier;
import com.android.ide.common.resources.configuration.ScreenHeightQualifier;
@@ -127,8 +126,7 @@ public class ResourceHelper {
IconFactory factory = IconFactory.getInstance();
sIconMap.put(CountryCodeQualifier.class, factory.getIcon("mcc")); //$NON-NLS-1$
sIconMap.put(NetworkCodeQualifier.class, factory.getIcon("mnc")); //$NON-NLS-1$
- sIconMap.put(LanguageQualifier.class, factory.getIcon("language")); //$NON-NLS-1$
- sIconMap.put(RegionQualifier.class, factory.getIcon("region")); //$NON-NLS-1$
+ sIconMap.put(LocaleQualifier.class, factory.getIcon("language")); //$NON-NLS-1$
sIconMap.put(LayoutDirectionQualifier.class, factory.getIcon("bidi")); //$NON-NLS-1$
sIconMap.put(ScreenSizeQualifier.class, factory.getIcon("size")); //$NON-NLS-1$
sIconMap.put(ScreenRatioQualifier.class, factory.getIcon("ratio")); //$NON-NLS-1$
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ConfigurationSelector.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ConfigurationSelector.java
index b4926b0..44f9082 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ConfigurationSelector.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ConfigurationSelector.java
@@ -22,13 +22,12 @@ import com.android.ide.common.resources.configuration.CountryCodeQualifier;
import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.common.resources.configuration.KeyboardStateQualifier;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
import com.android.ide.common.resources.configuration.LayoutDirectionQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.ide.common.resources.configuration.NavigationMethodQualifier;
import com.android.ide.common.resources.configuration.NavigationStateQualifier;
import com.android.ide.common.resources.configuration.NetworkCodeQualifier;
import com.android.ide.common.resources.configuration.NightModeQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
import com.android.ide.common.resources.configuration.ResourceQualifier;
import com.android.ide.common.resources.configuration.ScreenDimensionQualifier;
import com.android.ide.common.resources.configuration.ScreenHeightQualifier;
@@ -96,7 +95,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
-import java.util.Set;
/**
* Custom UI widget to let user build a Folder configuration.
@@ -174,7 +172,7 @@ public class ConfigurationSelector extends Composite {
@Override
public void verifyText(VerifyEvent e) {
// check for length
- if (e.text.length() - e.end + e.start + ((Combo)e.getSource()).getText().length() > 2) {
+ if (e.text.length() - e.end + e.start + ((Combo)e.getSource()).getText().length() > 6) {
e.doit = false;
return;
}
@@ -182,6 +180,18 @@ public class ConfigurationSelector extends Composite {
// check for lower case only.
for (int i = 0 ; i < e.text.length(); i++) {
char letter = e.text.charAt(i);
+ if (letter == '-') {
+ if (i+e.start != 2) {
+ e.doit = false;
+ return;
+ } else {
+ continue;
+ }
+ }
+ if (i+e.start == 3 && letter != 'r') {
+ e.doit = false;
+ return;
+ }
if ((letter < 'a' || letter > 'z') && (letter < 'A' || letter > 'Z')) {
e.doit = false;
return;
@@ -434,8 +444,7 @@ public class ConfigurationSelector extends Composite {
// ResourceQualifer class.
mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent));
mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent));
- mUiMap.put(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent));
- mUiMap.put(RegionQualifier.class, new RegionEdit(mQualifierEditParent));
+ mUiMap.put(LocaleQualifier.class, new LocaleEdit(mQualifierEditParent));
mUiMap.put(LayoutDirectionQualifier.class,
new LayoutDirectionEdit(mQualifierEditParent));
mUiMap.put(SmallestScreenWidthQualifier.class,
@@ -552,10 +561,6 @@ public class ConfigurationSelector extends Composite {
return ConfigurationState.INVALID_CONFIG;
}
- if (mSelectedConfiguration.checkRegion() == false) {
- return ConfigurationState.REGION_WITHOUT_LANGUAGE;
- }
-
return ConfigurationState.OK;
}
@@ -664,7 +669,7 @@ public class ConfigurationSelector extends Composite {
if (element instanceof ResourceQualifier) {
if (mShowQualifierValue) {
String value = ((ResourceQualifier)element).getShortDisplayValue();
- if (value.length() == 0) {
+ if (value == null || value.length() == 0) {
return String.format("%1$s (?)",
((ResourceQualifier)element).getShortName());
} else {
@@ -731,7 +736,7 @@ public class ConfigurationSelector extends Composite {
*/
private class MCCEdit extends QualifierEditBase {
- private Text mText;
+ private final Text mText;
public MCCEdit(Composite parent) {
super(parent, CountryCodeQualifier.NAME);
@@ -798,7 +803,7 @@ public class ConfigurationSelector extends Composite {
* Edit widget for {@link NetworkCodeQualifier}.
*/
private class MNCEdit extends QualifierEditBase {
- private Text mText;
+ private final Text mText;
public MNCEdit(Composite parent) {
super(parent, NetworkCodeQualifier.NAME);
@@ -863,12 +868,12 @@ public class ConfigurationSelector extends Composite {
/**
* Edit widget for {@link LanguageQualifier}.
*/
- private class LanguageEdit extends QualifierEditBase {
- private Combo mLanguage;
- private Label mName;
+ private class LocaleEdit extends QualifierEditBase {
+ private final Combo mLanguage;
+ private final Label mName;
- public LanguageEdit(Composite parent) {
- super(parent, LanguageQualifier.NAME);
+ public LocaleEdit(Composite parent) {
+ super(parent, LocaleQualifier.NAME);
mLanguage = new Combo(this, SWT.DROP_DOWN);
List<String> codes = LocaleManager.getLanguageCodes();
@@ -895,7 +900,7 @@ public class ConfigurationSelector extends Composite {
}
});
- new Label(this, SWT.NONE).setText("(2 letter code)");
+ new Label(this, SWT.NONE).setText("(2 letter code or language-rRegion)");
mName = new Label(this, SWT.NONE);
mName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -919,19 +924,14 @@ public class ConfigurationSelector extends Composite {
// empty string, means no qualifier.
// Since the qualifier classes are immutable, and we don't want to
// remove the qualifier from the configuration, we create a new default one.
- mSelectedConfiguration.setLanguageQualifier(new LanguageQualifier());
+ mSelectedConfiguration.setLocaleQualifier(new LocaleQualifier());
} else {
- LanguageQualifier qualifier = null;
- String segment = LanguageQualifier.getFolderSegment(value);
- if (segment != null) {
- qualifier = LanguageQualifier.getQualifier(segment);
- }
-
+ LocaleQualifier qualifier = LocaleQualifier.getQualifier(value);
if (qualifier != null) {
- mSelectedConfiguration.setLanguageQualifier(qualifier);
+ mSelectedConfiguration.setLocaleQualifier(qualifier);
} else {
// Failure! Looks like the value is wrong (for instance a one letter string).
- mSelectedConfiguration.setLanguageQualifier(new LanguageQualifier());
+ mSelectedConfiguration.setLocaleQualifier(new LocaleQualifier());
}
}
@@ -941,7 +941,7 @@ public class ConfigurationSelector extends Composite {
@Override
public void setQualifier(ResourceQualifier qualifier) {
- LanguageQualifier q = (LanguageQualifier)qualifier;
+ LocaleQualifier q = (LocaleQualifier)qualifier;
String value = q.getValue();
if (value != null) {
@@ -951,82 +951,11 @@ public class ConfigurationSelector extends Composite {
}
/**
- * Edit widget for {@link RegionQualifier}.
- */
- private class RegionEdit extends QualifierEditBase {
- private Combo mRegion;
-
- public RegionEdit(Composite parent) {
- super(parent, RegionQualifier.NAME);
-
- mRegion = new Combo(this, SWT.DROP_DOWN);
- mRegion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- mRegion.addVerifyListener(new LanguageRegionVerifier());
- mRegion.addSelectionListener(new SelectionListener() {
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- onRegionChange();
- }
- @Override
- public void widgetSelected(SelectionEvent e) {
- onRegionChange();
- }
- });
- mRegion.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent e) {
- onRegionChange();
- }
- });
-
- new Label(this, SWT.NONE).setText("(2 letter code)");
- }
-
- private void onRegionChange() {
- // update the current config
- String value = mRegion.getText();
-
- if (value.length() == 0) {
- // empty string, means no qualifier.
- // Since the qualifier classes are immutable, and we don't want to
- // remove the qualifier from the configuration, we create a new default one.
- mSelectedConfiguration.setRegionQualifier(new RegionQualifier());
- } else {
- RegionQualifier qualifier = null;
- String segment = RegionQualifier.getFolderSegment(value);
- if (segment != null) {
- qualifier = RegionQualifier.getQualifier(segment);
- }
-
- if (qualifier != null) {
- mSelectedConfiguration.setRegionQualifier(qualifier);
- } else {
- // Failure! Looks like the value is wrong (for instance a one letter string).
- mSelectedConfiguration.setRegionQualifier(new RegionQualifier());
- }
- }
-
- // notify of change
- onChange(true /* keepSelection */);
- }
-
- @Override
- public void setQualifier(ResourceQualifier qualifier) {
- RegionQualifier q = (RegionQualifier)qualifier;
-
- String value = q.getValue();
- if (value != null) {
- mRegion.setText(q.getValue());
- }
- }
- }
-
- /**
* Edit widget for {@link LayoutDirectionQualifier}.
*/
private class LayoutDirectionEdit extends QualifierEditBase {
- private Combo mDirection;
+ private final Combo mDirection;
public LayoutDirectionEdit(Composite parent) {
super(parent, LayoutDirectionQualifier.NAME);
@@ -1085,7 +1014,7 @@ public class ConfigurationSelector extends Composite {
*/
private class SmallestScreenWidthEdit extends QualifierEditBase {
- private Text mSize;
+ private final Text mSize;
public SmallestScreenWidthEdit(Composite parent) {
super(parent, SmallestScreenWidthQualifier.NAME);
@@ -1153,7 +1082,7 @@ public class ConfigurationSelector extends Composite {
*/
private class ScreenWidthEdit extends QualifierEditBase {
- private Text mSize;
+ private final Text mSize;
public ScreenWidthEdit(Composite parent) {
super(parent, ScreenWidthQualifier.NAME);
@@ -1219,7 +1148,7 @@ public class ConfigurationSelector extends Composite {
*/
private class ScreenHeightEdit extends QualifierEditBase {
- private Text mSize;
+ private final Text mSize;
public ScreenHeightEdit(Composite parent) {
super(parent, ScreenHeightQualifier.NAME);
@@ -1286,7 +1215,7 @@ public class ConfigurationSelector extends Composite {
*/
private class ScreenSizeEdit extends QualifierEditBase {
- private Combo mSize;
+ private final Combo mSize;
public ScreenSizeEdit(Composite parent) {
super(parent, ScreenSizeQualifier.NAME);
@@ -1344,7 +1273,7 @@ public class ConfigurationSelector extends Composite {
*/
private class ScreenRatioEdit extends QualifierEditBase {
- private Combo mRatio;
+ private final Combo mRatio;
public ScreenRatioEdit(Composite parent) {
super(parent, ScreenRatioQualifier.NAME);
@@ -1402,7 +1331,7 @@ public class ConfigurationSelector extends Composite {
*/
private class OrientationEdit extends QualifierEditBase {
- private Combo mOrientation;
+ private final Combo mOrientation;
public OrientationEdit(Composite parent) {
super(parent, ScreenOrientationQualifier.NAME);
@@ -1460,7 +1389,7 @@ public class ConfigurationSelector extends Composite {
*/
private class UiModeEdit extends QualifierEditBase {
- private Combo mUiMode;
+ private final Combo mUiMode;
public UiModeEdit(Composite parent) {
super(parent, UiModeQualifier.NAME);
@@ -1517,7 +1446,7 @@ public class ConfigurationSelector extends Composite {
*/
private class NightModeEdit extends QualifierEditBase {
- private Combo mNightMode;
+ private final Combo mNightMode;
public NightModeEdit(Composite parent) {
super(parent, NightModeQualifier.NAME);
@@ -1574,7 +1503,7 @@ public class ConfigurationSelector extends Composite {
* Edit widget for {@link DensityQualifier}.
*/
private class DensityEdit extends QualifierEditBase {
- private Combo mDensity;
+ private final Combo mDensity;
public DensityEdit(Composite parent) {
super(parent, DensityQualifier.NAME);
@@ -1632,7 +1561,7 @@ public class ConfigurationSelector extends Composite {
*/
private class TouchEdit extends QualifierEditBase {
- private Combo mTouchScreen;
+ private final Combo mTouchScreen;
public TouchEdit(Composite parent) {
super(parent, TouchScreenQualifier.NAME);
@@ -1689,7 +1618,7 @@ public class ConfigurationSelector extends Composite {
*/
private class KeyboardEdit extends QualifierEditBase {
- private Combo mKeyboardState;
+ private final Combo mKeyboardState;
public KeyboardEdit(Composite parent) {
super(parent, KeyboardStateQualifier.NAME);
@@ -1747,7 +1676,7 @@ public class ConfigurationSelector extends Composite {
*/
private class TextInputEdit extends QualifierEditBase {
- private Combo mTextInput;
+ private final Combo mTextInput;
public TextInputEdit(Composite parent) {
super(parent, TextInputMethodQualifier.NAME);
@@ -1805,7 +1734,7 @@ public class ConfigurationSelector extends Composite {
*/
private class NavigationStateEdit extends QualifierEditBase {
- private Combo mNavigationState;
+ private final Combo mNavigationState;
public NavigationStateEdit(Composite parent) {
super(parent, NavigationStateQualifier.NAME);
@@ -1863,7 +1792,7 @@ public class ConfigurationSelector extends Composite {
*/
private class NavigationEdit extends QualifierEditBase {
- private Combo mNavigation;
+ private final Combo mNavigation;
public NavigationEdit(Composite parent) {
super(parent, NavigationMethodQualifier.NAME);
@@ -1921,8 +1850,8 @@ public class ConfigurationSelector extends Composite {
*/
private class ScreenDimensionEdit extends QualifierEditBase {
- private Text mSize1;
- private Text mSize2;
+ private final Text mSize1;
+ private final Text mSize2;
public ScreenDimensionEdit(Composite parent) {
super(parent, ScreenDimensionQualifier.NAME);
@@ -1996,7 +1925,7 @@ public class ConfigurationSelector extends Composite {
* Edit widget for {@link VersionQualifier}.
*/
private class VersionEdit extends QualifierEditBase {
- private Text mText;
+ private final Text mText;
public VersionEdit(Composite parent) {
super(parent, VersionQualifier.NAME);
diff --git a/eclipse/plugins/com.android.ide.eclipse.base/.classpath b/eclipse/plugins/com.android.ide.eclipse.base/.classpath
index de0e2c8..0281bd9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.base/.classpath
+++ b/eclipse/plugins/com.android.ide.eclipse.base/.classpath
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry exported="true" kind="lib" path="libs/dvlib.jar" sourcepath="/dvlib"/>
- <classpathentry exported="true" kind="lib" path="libs/common.jar" sourcepath="/common"/>
- <classpathentry exported="true" kind="lib" path="libs/commons-codec-1.4.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/commons-compress-1.0.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/commons-logging-1.1.1.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/guava-17.0.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/httpclient-4.1.1.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/httpcore-4.1.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/kxml2-2.3.0.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/layoutlib-api.jar" sourcepath="/layoutlib-api"/>
- <classpathentry exported="true" kind="lib" path="libs/sdklib.jar" sourcepath="/sdklib"/>
- <classpathentry exported="true" kind="lib" path="libs/sdkstats.jar" sourcepath="/sdkstats"/>
- <classpathentry exported="true" kind="lib" path="libs/sdk-common.jar" sourcepath="/sdk-common"/>
- <classpathentry exported="true" kind="lib" path="libs/httpmime-4.1.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/dvlib.jar" sourcepath="/dvlib"/>
+ <classpathentry exported="true" kind="lib" path="libs/common.jar" sourcepath="/common"/>
+ <classpathentry exported="true" kind="lib" path="libs/commons-codec-1.4.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/commons-compress-1.0.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/commons-logging-1.1.1.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/guava-17.0.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/httpclient-4.1.1.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/httpcore-4.1.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/kxml2-2.3.0.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/layoutlib-api.jar" sourcepath="/layoutlib-api"/>
+ <classpathentry exported="true" kind="lib" path="libs/sdklib.jar" sourcepath="/sdklib"/>
+ <classpathentry exported="true" kind="lib" path="libs/sdkstats.jar" sourcepath="/sdkstats"/>
+ <classpathentry exported="true" kind="lib" path="libs/sdk-common.jar" sourcepath="/sdk-common"/>
+ <classpathentry exported="true" kind="lib" path="libs/httpmime-4.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/.classpath b/eclipse/plugins/com.android.ide.eclipse.ddms/.classpath
index d5d21c8..97afc79 100644
--- a/eclipse/plugins/com.android.ide.eclipse.ddms/.classpath
+++ b/eclipse/plugins/com.android.ide.eclipse.ddms/.classpath
@@ -3,11 +3,11 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="lib" path="libs/jfreechart-1.0.9.jar"/>
- <classpathentry kind="lib" path="libs/jcommon-1.0.12.jar"/>
- <classpathentry kind="lib" path="libs/jfreechart-swt-1.0.9.jar"/>
- <classpathentry exported="true" kind="lib" path="libs/ddmlib.jar" sourcepath="/ddmlib"/>
- <classpathentry exported="true" kind="lib" path="libs/ddmuilib.jar" sourcepath="/ddmuilib"/>
- <classpathentry exported="true" kind="lib" path="libs/uiautomatorviewer.jar" sourcepath="/uiautomatorviewer/src"/>
+ <classpathentry kind="lib" path="libs/jfreechart-1.0.9.jar"/>
+ <classpathentry kind="lib" path="libs/jcommon-1.0.12.jar"/>
+ <classpathentry kind="lib" path="libs/jfreechart-swt-1.0.9.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/ddmlib.jar" sourcepath="/ddmlib"/>
+ <classpathentry exported="true" kind="lib" path="libs/ddmuilib.jar" sourcepath="/ddmuilib"/>
+ <classpathentry exported="true" kind="lib" path="libs/uiautomatorviewer.jar" sourcepath="/uiautomatorviewer/src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/.classpath b/eclipse/plugins/com.android.ide.eclipse.tests/.classpath
index af8e888..f760174 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/.classpath
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/.classpath
@@ -17,7 +17,7 @@
<classpathentry kind="lib" path="/plugin-adt/libs/lint-checks.jar" sourcepath="/lint-checks"/>
<classpathentry kind="lib" path="/plugin-base/libs/sdk-common.jar"/>
<classpathentry kind="lib" path="/plugin-adt/libs/lombok-ast-0.2.2.jar"/>
- <classpathentry kind="lib" path="/plugin-adt/libs/asm-5.0.3.3.3.jar"/>
+ <classpathentry kind="lib" path="/plugin-adt/libs/asm-5.0.3.jar"/>
<classpathentry kind="lib" path="/plugin-adt/libs/asm-analysis-5.0.3.jar"/>
<classpathentry kind="lib" path="/plugin-adt/libs/asm-tree-5.0.3.jar"/>
<classpathentry kind="lib" path="/plugin-adt/libs/manifest-merger.jar" sourcepath="/manifest-merger"/>
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java
index a9e39fb..5b07d7b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java
@@ -15,11 +15,10 @@
*/
package com.android.ide.eclipse.adt.internal.editors.layout.configuration;
-import static com.android.ide.common.resources.configuration.LanguageQualifier.FAKE_LANG_VALUE;
-import static com.android.ide.common.resources.configuration.RegionQualifier.FAKE_REGION_VALUE;
+import static com.android.ide.common.resources.configuration.LocaleQualifier.FAKE_VALUE;
import com.android.ide.common.resources.configuration.FolderConfiguration;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import com.android.resources.Density;
import com.android.sdklib.devices.Device;
import com.android.sdklib.devices.DeviceManager;
@@ -62,18 +61,18 @@ public class ConfigurationTest extends TestCase {
// Check syncing
FolderConfiguration folderConfig = configuration.getFullConfig();
- assertEquals(FAKE_LANG_VALUE, folderConfig.getLanguageQualifier().getValue());
- assertEquals(FAKE_REGION_VALUE, folderConfig.getRegionQualifier().getValue());
+ assertEquals(FAKE_VALUE, folderConfig.getLocaleQualifier().getLanguage());
+ assertEquals(FAKE_VALUE, folderConfig.getLocaleQualifier().getRegion());
assertEquals(Locale.ANY, configuration.getLocale());
- Locale language = Locale.create(new LanguageQualifier("nb"));
+ Locale language = Locale.create(new LocaleQualifier("nb"));
configuration.setLocale(language, true /* skipSync */);
- assertEquals(FAKE_LANG_VALUE, folderConfig.getLanguageQualifier().getValue());
- assertEquals(FAKE_REGION_VALUE, folderConfig.getRegionQualifier().getValue());
+ assertEquals(FAKE_VALUE, folderConfig.getLocaleQualifier().getLanguage());
+ assertEquals(FAKE_VALUE, folderConfig.getLocaleQualifier().getRegion());
configuration.setLocale(language, false /* skipSync */);
- assertEquals(FAKE_REGION_VALUE, folderConfig.getRegionQualifier().getValue());
- assertEquals("nb", folderConfig.getLanguageQualifier().getValue());
+ assertEquals(FAKE_VALUE, folderConfig.getLocaleQualifier().getRegion());
+ assertEquals("nb", folderConfig.getLocaleQualifier().getLanguage());
assertEquals("2.7in QVGA::nb-__:+Theme::notnight::", configuration.toPersistentString());
@@ -121,7 +120,7 @@ public class ConfigurationTest extends TestCase {
configuration.setDevice(devices.get(0), false);
configuration.setActivity("foo.bar.FooActivity");
configuration.setTheme("@android:style/Theme.Holo.Light");
- Locale locale = Locale.create(new LanguageQualifier("nb"));
+ Locale locale = Locale.create(new LocaleQualifier("nb"));
configuration.setLocale(locale, false /* skipSync */);
Configuration copy = Configuration.copy(configuration);
@@ -135,7 +134,7 @@ public class ConfigurationTest extends TestCase {
configuration.setTheme("@android:style/Theme.Holo");
configuration.setDevice(devices.get(1), true);
- assertTrue(copy.getFullConfig().getLanguageQualifier().equals(locale.language));
+ assertTrue(copy.getFullConfig().getLocaleQualifier().equals(locale.qualifier));
assertEquals(locale, copy.getLocale());
assertEquals("foo.bar.FooActivity", copy.getActivity());
assertEquals("@android:style/Theme.Holo.Light", copy.getTheme());
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManagerTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManagerTest.java
index c22609f..4286aaa 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManagerTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/FlagManagerTest.java
@@ -16,7 +16,12 @@
package com.android.ide.eclipse.adt.internal.editors.layout.configuration;
+import com.android.SdkConstants;
import com.android.ide.common.resources.LocaleManager;
+import com.google.common.base.Function;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
import org.eclipse.swt.graphics.Image;
@@ -72,103 +77,109 @@ public class FlagManagerTest extends TestCase {
assertSame(ca, manager.getFlagForFolderName("values-en"));
}
- public void testAvailableIcons() {
- // Icons we have in WindowBuilder
+ public void testAvailableImages() {
+ // Images we have from WindowBuilder (which are really the famfamfam
+ // icons;
+ // see http://www.famfamfam.com/lab/icons/flags)
String[] icons = new String[] {
"ad", "ae", "af", "ag", "ai", "al", "am", "ao", "ar", "as", "at", "au", "aw", "ax",
"az", "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo", "br",
- "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck",
- "cl", "cm", "cn", "co", "cr", "cu", "cv", "cx", "cy", "cz", "de", "dj", "dk", "dm",
- "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", "fi", "fj", "fk", "fm", "fo",
- "fr", "ga", "gb", "gd", "ge", "gf", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr",
- "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", "ie", "il",
- "in", "io", "iq", "ir", "is", "it", "jm", "jo", "jp", "ke", "kg", "kh", "ki", "km",
- "kn", "kp", "kr", "kw", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt",
- "lu", "lv", "ly", "ma", "mc", "md", "me", "mg", "mh", "mk", "ml", "mm", "mn", "mo",
- "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "mz", "na", "nc", "ne",
- "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg",
- "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs",
- "ru", "rw", "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm",
- "sn", "so", "sr", "st", "sv", "sy", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk",
- "tl", "tm", "tn", "to", "tr", "tt", "tv", "tw", "tz", "ua", "ug", "um", "us", "uy",
- "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wf", "ws", "ye", "yt", "za", "zm",
- "zw",
+ "bs", "bt", "bv", "bw", "by", "bz", "ca", "catalonia", "cc", "cd", "cf", "cg",
+ "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cx", "cy", "cz", "de",
+ "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "england", "er", "es", "et",
+ "fi", "fj", "fk", "fm", "fo", "fr", "ga", "gb", "gd", "ge", "gf", "gg", "gh", "gi",
+ "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn",
+ "hr", "ht", "hu", "id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", "jm",
+ "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", "la",
+ "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", "ma", "mc", "md", "me",
+ "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv",
+ "mw", "mx", "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr",
+ "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps",
+ "pt", "pw", "py", "qa", "re", "ro", "rs", "ru", "rw", "sa", "sb", "sc", "scotland",
+ "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "ss", "st",
+ "sv", "sy", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to",
+ "tr", "tt", "tv", "tw", "tz", "ua", "ug", "um", "us", "uy", "uz", "va", "vc", "ve",
+ "vg", "vi", "vn", "vu", "wales", "wf", "ws", "ye", "yt", "za", "zm", "zw"
};
- Set<String> sIcons = new HashSet<String>(100);
- Map<String, String> regionNames = LocaleManager.getRegionNamesMap();
- Map<String, String> languageToCountry = LocaleManager.getLanguageToCountryMap();
- Map<String, String> languageNames = LocaleManager.getLanguageNamesMap();
- List<String> unused = new ArrayList<String>();
+
+ Set<String> sImages = new HashSet<String>(100);
for (String code : icons) {
+ if (code.length() > 2) {
+ continue;
+ }
code = code.toUpperCase(Locale.US);
- sIcons.add(code);
+ sImages.add(code);
- String country = regionNames.get(code);
- if (country == null) {
+ if (!LocaleManager.isValidRegionCode(code)) {
System.out.println("No region name found for region code " + code);
}
+ }
- if (!languageToCountry.values().contains(code)) {
- unused.add(code.toLowerCase() + ".png");
+ Set<String> unused = Sets.newHashSet(LocaleManager.getRegionCodes(false));
+ Set<String> reachable = Sets.newHashSet();
+ Multimap<String, String> regionToLanguages = ArrayListMultimap.create();
+ for (String language : LocaleManager.getLanguageCodes(false)) {
+ for (String region : LocaleManager.getRelevantRegions(language)) {
+ reachable.add(region);
+ regionToLanguages.put(region, language);
}
}
- if (!unused.isEmpty()) {
- System.out.println("The following icons are not referenced by any of the " +
- "language to country bindings: " + unused);
+ unused.removeAll(reachable);
+
+ for (String region : reachable) {
+ if (!sImages.contains(region)) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("No icon found for region ").append(region).append(" ")
+ .append(LocaleManager.getRegionName(region));
+ sb.append(", used for languages ");
+
+ for (String language : regionToLanguages.get(region)) {
+ sb.append(language).append("(").append(LocaleManager.getLanguageName(language))
+ .append(") ");
+ }
+ System.out.println(sb.toString());
+ }
}
- // Make sure all our language bindings are languages we have maps for
- for (Map.Entry<String, String> entry : languageToCountry.entrySet()) {
- String language = entry.getKey();
- String region = entry.getValue();
+ // Known regions that we don't have language to region mappings for
+ unused.remove("AQ");
+ unused.remove("VA");
+ unused.remove("GS");
+ unused.remove("TF");
+ unused.remove("BV");
+ unused.remove("HM");
- if (!sIcons.contains(region)) {
- System.out.println("No icon found for region " + region + " "
- + LocaleManager.getRegionName(region) + " (used for language "
- + language + "(" + languageNames.get(language) + "))");
+ if (!unused.isEmpty()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("The following icons are not referenced by any of the "
+ + "language to country bindings:");
+ for (String code : unused) {
+ sb.append(code.toLowerCase(Locale.US)).append(SdkConstants.DOT_PNG).append(" (");
+ sb.append(LocaleManager.getRegionName(code)).append(") ");
}
+ System.out.println(sb.toString());
}
}
- /* Utility useful for identifying strings which must be using \\u in the string names
- * to ensure that they are handled properly during the build (outside of Eclipse,
- * where this source file is marked as using UTF-8.
- public void testPrintable() {
- Set<String> languageCodes = LocaleManager.getLanguageCodes();
- for (String code : languageCodes) {
- String name = LocaleManager.getLanguageName(code);
- assertNotNull(name);
- checkEncoding(name);
- }
+ public void testMissingFlag() {
+ Image icon = FlagManager.get().getFlag("AQ");
+ assertNotNull(icon);
+ assertSame(FlagManager.get().getEmptyIcon(), icon);
- Set<String> regionCodes = LocaleManager.getRegionCodes();
- for (String code : regionCodes) {
- String name = LocaleManager.getRegionName(code);
- assertNotNull(name);
- checkEncoding(name);
- }
+ icon = FlagManager.get().getFlag("AQ");
+ assertNotNull(icon);
+ assertSame(FlagManager.get().getEmptyIcon(), icon);
+
+ icon = FlagManager.get().getFlag("WO"); // Not used in ISO 3166-1
+ assertNotNull(icon);
+ assertSame(FlagManager.get().getEmptyIcon(), icon);
}
- private static void checkEncoding(String s) {
- for (int i = 0, n = s.length(); i < n; i++) {
- char c = s.charAt(i);
- if (c >= 128) {
- System.out.println("Need unicode encoding for '" + s + "'");
- StringBuilder sb = new StringBuilder();
- for (int j = 0, m = s.length(); j < m; j++) {
- char d = s.charAt(j);
- if (d < 128) {
- sb.append(d);
- } else {
- sb.append('\\');
- sb.append('u');
- sb.append(String.format("%04x", (int)d));
- }
- }
- System.out.println(" Replacement=" + sb);
- return;
- }
- }
+ public void testKnownFlag() {
+ Image icon = FlagManager.get().getFlag("US");
+ assertNotNull(icon);
+ assertNotSame(FlagManager.get().getEmptyIcon(), icon);
}
- */
}
+
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/LocaleTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/LocaleTest.java
index 3dcf33a..904ade3 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/LocaleTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/LocaleTest.java
@@ -13,44 +13,87 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.android.ide.eclipse.adt.internal.editors.layout.configuration;
-import com.android.ide.common.resources.configuration.LanguageQualifier;
-import com.android.ide.common.resources.configuration.RegionQualifier;
+import com.android.ide.common.resources.configuration.FolderConfiguration;
+import com.android.ide.common.resources.configuration.LocaleQualifier;
import junit.framework.TestCase;
@SuppressWarnings("javadoc")
public class LocaleTest extends TestCase {
+ public void test1() {
+ Locale locale = Locale.create("en-rUS");
+ assertEquals("en", locale.qualifier.getLanguage());
+ assertEquals("US", locale.qualifier.getRegion());
+ assertTrue(locale.hasLanguage());
+ assertTrue(locale.hasRegion());
+ }
+
+ public void test2() {
+ Locale locale = Locale.create("zh");
+ assertEquals("zh", locale.qualifier.getLanguage());
+ assertNull(locale.qualifier.getRegion());
+ assertTrue(locale.hasLanguage());
+ assertFalse(locale.hasRegion());
+ }
+
+ public void testEquals() {
+ Locale locale = Locale.create("zh");
+ assertEquals("zh", locale.qualifier.getLanguage());
+ assertNull(locale.qualifier.getRegion());
+ assertTrue(locale.hasLanguage());
+ assertFalse(locale.hasRegion());
+ }
+
public void test() {
- LanguageQualifier language1 = new LanguageQualifier("nb");
- LanguageQualifier language2 = new LanguageQualifier("no");
- RegionQualifier region1 = new RegionQualifier("NO");
- RegionQualifier region2 = new RegionQualifier("SE");
+ LocaleQualifier qualifier1 = LocaleQualifier.getQualifier("nb");
+ LocaleQualifier qualifier2 = LocaleQualifier.getQualifier("no");
+ LocaleQualifier qualifier3 = LocaleQualifier.getQualifier("nb-rNO");
+ LocaleQualifier qualifier4 = LocaleQualifier.getQualifier("nb-rSE");
+ LocaleQualifier qualifier5 = LocaleQualifier.getQualifier("no-rSE");
+ assertNotNull(qualifier1);
+ assertNotNull(qualifier2);
+ assertNotNull(qualifier3);
+ assertNotNull(qualifier4);
+ assertNotNull(qualifier5);
assertEquals(Locale.ANY, Locale.ANY);
assertFalse(Locale.ANY.hasLanguage());
assertFalse(Locale.ANY.hasRegion());
- assertFalse(Locale.create(new LanguageQualifier(LanguageQualifier.FAKE_LANG_VALUE),
- new RegionQualifier(RegionQualifier.FAKE_REGION_VALUE)).hasLanguage());
- assertFalse(Locale.create(new LanguageQualifier(LanguageQualifier.FAKE_LANG_VALUE),
- new RegionQualifier(RegionQualifier.FAKE_REGION_VALUE)).hasRegion());
-
- assertEquals(Locale.create(language1), Locale.create(language1));
- assertTrue(Locale.create(language1).hasLanguage());
- assertFalse(Locale.create(language1).hasRegion());
- assertTrue(Locale.create(language1, region1).hasLanguage());
- assertTrue(Locale.create(language1, region1).hasRegion());
-
- assertEquals(Locale.create(language1, region1), Locale.create(language1, region1));
- assertEquals(Locale.create(language1), Locale.create(language1));
- assertTrue(Locale.create(language1).equals(Locale.create(language1)));
- assertTrue(Locale.create(language1, region1).equals(Locale.create(language1, region1)));
- assertFalse(Locale.create(language1, region1).equals(Locale.create(language1, region2)));
- assertFalse(Locale.create(language1).equals(Locale.create(language1, region1)));
- assertFalse(Locale.create(language1).equals(Locale.create(language2)));
- assertFalse(Locale.create(language1, region1).equals(Locale.create(language2, region1)));
- assertEquals("Locale{nb, __}", Locale.create(language1).toString());
- assertEquals("Locale{nb, NO}", Locale.create(language1, region1).toString());
+ // noinspection ConstantConditions
+ assertFalse(Locale.create(new LocaleQualifier(LocaleQualifier.FAKE_VALUE)).hasLanguage());
+ // noinspection ConstantConditions
+ assertFalse(Locale.create(new LocaleQualifier(LocaleQualifier.FAKE_VALUE)).hasRegion());
+
+ assertEquals(Locale.create(qualifier1), Locale.create(qualifier1));
+ assertTrue(Locale.create(qualifier1).hasLanguage());
+ assertFalse(Locale.create(qualifier1).hasRegion());
+ assertTrue(Locale.create(qualifier3).hasLanguage());
+ assertTrue(Locale.create(qualifier3).hasRegion());
+
+ assertEquals(Locale.create(qualifier3), Locale.create(qualifier3));
+ assertEquals(Locale.create(qualifier1), Locale.create(qualifier1));
+ assertTrue(Locale.create(qualifier1).equals(Locale.create(qualifier1)));
+ assertTrue(Locale.create(qualifier3).equals(Locale.create(qualifier3)));
+ assertFalse(Locale.create(qualifier3).equals(Locale.create(qualifier4)));
+ assertFalse(Locale.create(qualifier1).equals(Locale.create(qualifier3)));
+ assertFalse(Locale.create(qualifier1).equals(Locale.create(qualifier2)));
+ assertFalse(Locale.create(qualifier3).equals(Locale.create(qualifier5)));
+ assertEquals("nb", Locale.create(qualifier1).toString());
+ assertEquals("nb-NO", Locale.create(qualifier3).toString());
+
+ assertEquals(Locale.create(qualifier1), Locale.create("b+nb"));
+ assertEquals(Locale.create(qualifier3), Locale.create("b+nb+NO"));
+ }
+
+ public void testFolderConfig() {
+ FolderConfiguration config = new FolderConfiguration();
+ assertEquals(Locale.ANY, Locale.create(config));
+ config.setLocaleQualifier(LocaleQualifier.getQualifier("en"));
+ assertEquals(Locale.create("en"), Locale.create(config));
+ config.setLocaleQualifier(LocaleQualifier.getQualifier("en-rUS"));
+ assertEquals(Locale.create("en-rUS"), Locale.create(config));
}
}