aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-01-12 13:42:05 -0800
committerXavier Ducrohet <xav@android.com>2011-01-12 14:21:34 -0800
commitd94106f0f7824f5dc6d53e65983ff0ad054ff214 (patch)
treeef4e4c23adb6f8f47cf5bedf68773cf742f34c04
parent611737c10b6e8a6c352d5ebfbacb8d95cf831831 (diff)
downloadsdk-d94106f0f7824f5dc6d53e65983ff0ad054ff214.zip
sdk-d94106f0f7824f5dc6d53e65983ff0ad054ff214.tar.gz
sdk-d94106f0f7824f5dc6d53e65983ff0ad054ff214.tar.bz2
Properly select dock/night mode combo when opening a layout.
Change-Id: I3c4f8b875f263970e4c8fc308b466ae14c69c438
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java169
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java12
2 files changed, 129 insertions, 52 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java
index 052d4a5..0e824f1 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java
@@ -852,9 +852,6 @@ public class ConfigurationComposite extends Composite {
targetData = Sdk.getCurrent().getTargetData(mState.target);
} else {
findAndSetCompatibleConfig(false /*favorCurrentConfig*/);
-
- mDockCombo.select(0);
- mNightCombo.select(0);
// We don't want the -first- combobox item, we want the
// default one which is sometimes a different index
//mTargetCombo.select(0);
@@ -875,6 +872,28 @@ public class ConfigurationComposite extends Composite {
return targetData;
}
+ private static class ConfigBundle {
+ FolderConfiguration config;
+ int localeIndex;
+ int dockModeIndex;
+ int nightModeIndex;
+
+ ConfigBundle() {
+ config = new FolderConfiguration();
+ localeIndex = 0;
+ dockModeIndex = 0;
+ nightModeIndex = 0;
+ }
+
+ ConfigBundle(ConfigBundle bundle) {
+ config = new FolderConfiguration();
+ config.set(bundle.config);
+ localeIndex = bundle.localeIndex;
+ dockModeIndex = bundle.dockModeIndex;
+ nightModeIndex = bundle.nightModeIndex;
+ }
+ }
+
/**
* Finds a device/config that can display {@link #mEditedConfig}.
* <p/>Once found the device and config combos are set to the config.
@@ -885,58 +904,64 @@ public class ConfigurationComposite extends Composite {
private void findAndSetCompatibleConfig(boolean favorCurrentConfig) {
LayoutDevice anyDeviceMatch = null; // a compatible device/config/locale
String anyConfigMatchName = null;
- int anyLocaleIndex = -1;
+ ConfigBundle anyConfigBundle = null;
LayoutDevice bestDeviceMatch = null; // an actual best match
String bestConfigMatchName = null;
- int bestLocaleIndex = -1;
+ ConfigBundle bestConfigBundle = null;
FolderConfiguration testConfig = new FolderConfiguration();
// get a locale that match the host locale roughly (may not be exact match on the region.)
- ResourceQualifier[] localeHostMatch = getLocaleMatch();
+ int localeHostMatch = getLocaleMatch();
+
+ // build a list of combinations of non standard qualifiers to add to each device's
+ // qualifier set when testing for a match.
+ // These qualifiers are: locale, nightmode, car dock.
+ List<ConfigBundle> addConfig = new ArrayList<ConfigBundle>();
+
+ // If the edited file has locales, then we have to select a matching locale from
+ // the list.
+ // 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 (mEditedConfig.getLanguageQualifier() != null || localeHostMatch == -1) {
+ // add all the locales
+ start = 0;
+ max = mLocaleList.size();
+ } else {
+ // only add the locale host match
+ start = localeHostMatch;
+ max = localeHostMatch + 1; // test is <
+ }
+
+ for (int i = start ; i < max ; i++) {
+ ResourceQualifier[] l = mLocaleList.get(i);
+
+ ConfigBundle bundle = new ConfigBundle();
+ bundle.config.setLanguageQualifier((LanguageQualifier) l[LOCALE_LANG]);
+ bundle.config.setRegionQualifier((RegionQualifier) l[LOCALE_REGION]);
+
+ bundle.localeIndex = i;
+ addConfig.add(bundle);
+ }
+
+ // add the dock mode to the bundle combinations.
+ addDockModeToBundles(addConfig);
+
+ // add the night mode to the bundle combinations.
+ addNightModeToBundles(addConfig);
mainloop: for (LayoutDevice device : mDeviceList) {
for (DeviceConfig config : device.getConfigs()) {
- testConfig.set(config.getConfig());
- // If the edited file has locales, then we have to select a matching locale from
- // the list.
- // 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)
- if (mEditedConfig.getLanguageQualifier() != null || localeHostMatch == null) {
- // look on the locales.
- for (int i = 0 ; i < mLocaleList.size() ; i++) {
- ResourceQualifier[] locale = mLocaleList.get(i);
-
- // update the test config with the locale qualifiers
- testConfig.setLanguageQualifier((LanguageQualifier)locale[LOCALE_LANG]);
- testConfig.setRegionQualifier((RegionQualifier)locale[LOCALE_REGION]);
-
- if (mEditedConfig.isMatchFor(testConfig)) {
- // this is a basic match. record it in case we don't find a match
- // where the edited file is a best config.
- if (anyDeviceMatch == null) {
- anyDeviceMatch = device;
- anyConfigMatchName = config.getName();
- anyLocaleIndex = i;
- }
+ // loop on the list of qualifier adds
+ for (ConfigBundle bundle : addConfig) {
+ // set the base config. This erase all data in testConfig.
+ testConfig.set(config.getConfig());
- if (isCurrentFileBestMatchFor(testConfig)) {
- // this is what we want.
- bestDeviceMatch = device;
- bestConfigMatchName = config.getName();
- bestLocaleIndex = i;
- break mainloop;
- }
- }
- }
- } else {
- // update the test config with the locale qualifiers
- testConfig.setLanguageQualifier(
- (LanguageQualifier)localeHostMatch[LOCALE_LANG]);
- testConfig.setRegionQualifier(
- (RegionQualifier)localeHostMatch[LOCALE_REGION]);
+ // add on top of it, the extra qualifiers
+ testConfig.add(bundle.config);
if (mEditedConfig.isMatchFor(testConfig)) {
// this is a basic match. record it in case we don't find a match
@@ -944,14 +969,14 @@ public class ConfigurationComposite extends Composite {
if (anyDeviceMatch == null) {
anyDeviceMatch = device;
anyConfigMatchName = config.getName();
- anyLocaleIndex = mLocaleList.indexOf(localeHostMatch);
+ anyConfigBundle = bundle;
}
if (isCurrentFileBestMatchFor(testConfig)) {
// this is what we want.
bestDeviceMatch = device;
bestConfigMatchName = config.getName();
- bestLocaleIndex = mLocaleList.indexOf(localeHostMatch);
+ bestConfigBundle = bundle;
break mainloop;
}
}
@@ -979,7 +1004,9 @@ public class ConfigurationComposite extends Composite {
// select the device anyway.
selectDevice(mState.device = anyDeviceMatch);
fillConfigCombo(anyConfigMatchName);
- mLocaleCombo.select(anyLocaleIndex);
+ mLocaleCombo.select(anyConfigBundle.localeIndex);
+ mDockCombo.select(anyConfigBundle.dockModeIndex);
+ mNightCombo.select(anyConfigBundle.nightModeIndex);
// TODO: display a better warning!
computeCurrentConfig();
@@ -988,7 +1015,7 @@ public class ConfigurationComposite extends Composite {
"'%1$s' is not a best match for any device/locale combination.",
mEditedConfig.toDisplayString()),
String.format(
- "Displaying it with '%1$s'",
+ "Displaying it with '%1$s' which is compatible, but will actually be displayed with another more specific version of the layout.",
mCurrentConfig.toDisplayString()));
} else {
@@ -999,8 +1026,46 @@ public class ConfigurationComposite extends Composite {
} else {
selectDevice(mState.device = bestDeviceMatch);
fillConfigCombo(bestConfigMatchName);
- mLocaleCombo.select(bestLocaleIndex);
+ mLocaleCombo.select(bestConfigBundle.localeIndex);
+ mDockCombo.select(bestConfigBundle.dockModeIndex);
+ mNightCombo.select(bestConfigBundle.nightModeIndex);
+ }
+ }
+
+ private void addDockModeToBundles(List<ConfigBundle> addConfig) {
+ ArrayList<ConfigBundle> list = new ArrayList<ConfigBundle>();
+
+ // loop on each item and for each, add all variations of the dock modes
+ for (ConfigBundle bundle : addConfig) {
+ int index = 0;
+ for (DockMode mode : DockMode.values()) {
+ ConfigBundle b = new ConfigBundle(bundle);
+ b.config.setDockModeQualifier(new DockModeQualifier(mode));
+ b.dockModeIndex = index++;
+ list.add(b);
+ }
}
+
+ addConfig.clear();
+ addConfig.addAll(list);
+ }
+
+ private void addNightModeToBundles(List<ConfigBundle> addConfig) {
+ ArrayList<ConfigBundle> list = new ArrayList<ConfigBundle>();
+
+ // loop on each item and for each, add all variations of the night modes
+ for (ConfigBundle bundle : addConfig) {
+ int index = 0;
+ for (NightMode mode : NightMode.values()) {
+ ConfigBundle b = new ConfigBundle(bundle);
+ b.config.setNightModeQualifier(new NightModeQualifier(mode));
+ b.nightModeIndex = index++;
+ list.add(b);
+ }
+ }
+
+ addConfig.clear();
+ addConfig.addAll(list);
}
/**
@@ -1241,7 +1306,7 @@ public class ConfigurationComposite extends Composite {
}
}
- private ResourceQualifier[] getLocaleMatch() {
+ private int getLocaleMatch() {
Locale locale = Locale.getDefault();
if (locale != null) {
String currentLanguage = locale.getLanguage();
@@ -1260,16 +1325,16 @@ public class ConfigurationComposite extends Composite {
if (langQ.getValue().equals(currentLanguage) &&
(regionQ.getValue().equals(currentRegion) ||
regionQ.getValue().equals(RegionQualifier.FAKE_REGION_VALUE))) {
- return localeArray;
+ return l;
}
}
// if no locale match the current local locale, it's likely that it is
// the default one which is the last one.
- return mLocaleList.get(count - 1);
+ return count - 1;
}
- return null;
+ return -1;
}
/**
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java
index 3a37634..b759e6e 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/configurations/FolderConfiguration.java
@@ -107,6 +107,18 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
}
/**
+ * Adds the non-qualifiers from the given config.
+ * Qualifiers that are null in the given config do not change in the receiver.
+ */
+ public void add(FolderConfiguration config) {
+ for (int i = 0 ; i < INDEX_COUNT ; i++) {
+ if (config.mQualifiers[i] != null) {
+ mQualifiers[i] = config.mQualifiers[i];
+ }
+ }
+ }
+
+ /**
* Returns the first invalid qualifier, or <code>null<code> if they are all valid (or if none
* exists).
*/