aboutsummaryrefslogtreecommitdiffstats
path: root/sdk_common
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-09-28 11:55:44 -0700
committerTor Norbye <tnorbye@google.com>2012-10-03 17:42:40 -0700
commitec7301a7433cf89c399fa3c507afe8a147adbcba (patch)
tree7174ca875a10103753c3278fa3eb634042f2b5dc /sdk_common
parent61da3c30c2456c0f4e33fe8c8507e9179d67947a (diff)
downloadsdk-ec7301a7433cf89c399fa3c507afe8a147adbcba.zip
sdk-ec7301a7433cf89c399fa3c507afe8a147adbcba.tar.gz
sdk-ec7301a7433cf89c399fa3c507afe8a147adbcba.tar.bz2
Multi-Configuration Layout Editing
This changeset adds support for previewing other configurations (as well as including contexts) for a layout, with live updates. Change-Id: Iff3523d6f5749b3287716e563330fb18c8576611
Diffstat (limited to 'sdk_common')
-rw-r--r--sdk_common/src/com/android/ide/common/resources/configuration/FolderConfiguration.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/sdk_common/src/com/android/ide/common/resources/configuration/FolderConfiguration.java b/sdk_common/src/com/android/ide/common/resources/configuration/FolderConfiguration.java
index e2fe767..a513c1f 100644
--- a/sdk_common/src/com/android/ide/common/resources/configuration/FolderConfiguration.java
+++ b/sdk_common/src/com/android/ide/common/resources/configuration/FolderConfiguration.java
@@ -22,6 +22,7 @@ import com.android.resources.ResourceFolderType;
import com.android.resources.ScreenOrientation;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
@@ -105,6 +106,52 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
}
/**
+ * Creates a {@link FolderConfiguration} matching the folder segments.
+ * @param folderSegments The segments of the folder name. The first segments should contain
+ * the name of the folder
+ * @return a FolderConfiguration object, or null if the folder name isn't valid..
+ * @see FolderConfiguration#getConfig(String[])
+ */
+ public static FolderConfiguration getConfig(Iterable<String>folderSegments) {
+ FolderConfiguration config = new FolderConfiguration();
+
+ // we are going to loop through the segments, and match them with the first
+ // available qualifier. If the segment doesn't match we try with the next qualifier.
+ // Because the order of the qualifier is fixed, we do not reset the first qualifier
+ // after each successful segment.
+ // If we run out of qualifier before processing all the segments, we fail.
+
+ int qualifierIndex = 0;
+ int qualifierCount = DEFAULT_QUALIFIERS.length;
+
+ Iterator<String> iterator = folderSegments.iterator();
+ if (iterator.hasNext()) {
+ // Skip the first segment: it should be just the base folder, such as "values" or
+ // "layout"
+ iterator.next();
+ }
+ while (iterator.hasNext()) {
+ String seg = iterator.next();
+ if (seg.length() > 0) {
+ while (qualifierIndex < qualifierCount &&
+ DEFAULT_QUALIFIERS[qualifierIndex].checkAndSet(seg, config) == false) {
+ qualifierIndex++;
+ }
+
+ // if we reached the end of the qualifier we didn't find a matching qualifier.
+ if (qualifierIndex == qualifierCount) {
+ return null;
+ }
+
+ } else {
+ return null;
+ }
+ }
+
+ return config;
+ }
+
+ /**
* Returns the number of {@link ResourceQualifier} that make up a Folder configuration.
*/
public static int getQualifierCount() {