aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-11-28 16:38:50 -0800
committerXavier Ducrohet <xav@android.com>2012-11-29 12:56:09 -0800
commitd09b8a2d6ce570cc81ec6678b07f40541f4657f4 (patch)
tree08de690cd224142213c60321419dabd699ad97a9
parent79a4aff85957ef993e46dbbbe1f1ae0bab632d90 (diff)
downloadsdk-d09b8a2d6ce570cc81ec6678b07f40541f4657f4.zip
sdk-d09b8a2d6ce570cc81ec6678b07f40541f4657f4.tar.gz
sdk-d09b8a2d6ce570cc81ec6678b07f40541f4657f4.tar.bz2
Add support for layout dir qualifiers.
Change-Id: I6da728d079975fa19f1ae816fa585031a9c6fe75
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/icons/bidi.pngbin0 -> 162 bytes
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ConfigurationSelector.java63
-rw-r--r--layoutlib_api/src/com/android/resources/LayoutDirection.java100
-rw-r--r--sdk_common/src/com/android/ide/common/resources/configuration/FolderConfiguration.java47
-rw-r--r--sdk_common/src/com/android/ide/common/resources/configuration/LayoutDirectionQualifier.java74
-rw-r--r--sdk_common/tests/src/com/android/ide/common/resources/configuration/FolderConfigurationTest.java21
7 files changed, 288 insertions, 19 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/icons/bidi.png b/eclipse/plugins/com.android.ide.eclipse.adt/icons/bidi.png
new file mode 100644
index 0000000..4ffe131
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/icons/bidi.png
Binary files differ
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 6b09b34..9695318 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,6 +40,7 @@ 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.NavigationMethodQualifier;
import com.android.ide.common.resources.configuration.NavigationStateQualifier;
import com.android.ide.common.resources.configuration.NetworkCodeQualifier;
@@ -127,6 +128,7 @@ public class ResourceHelper {
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(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$
sIconMap.put(ScreenOrientationQualifier.class, factory.getIcon("orientation")); //$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 ce36457..15453fb 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,6 +22,7 @@ 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.NavigationMethodQualifier;
import com.android.ide.common.resources.configuration.NavigationStateQualifier;
import com.android.ide.common.resources.configuration.NetworkCodeQualifier;
@@ -44,6 +45,7 @@ import com.android.ide.eclipse.adt.internal.resources.ResourceHelper;
import com.android.resources.Density;
import com.android.resources.Keyboard;
import com.android.resources.KeyboardState;
+import com.android.resources.LayoutDirection;
import com.android.resources.Navigation;
import com.android.resources.NavigationState;
import com.android.resources.NightMode;
@@ -433,6 +435,8 @@ public class ConfigurationSelector extends Composite {
mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent));
mUiMap.put(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent));
mUiMap.put(RegionQualifier.class, new RegionEdit(mQualifierEditParent));
+ mUiMap.put(LayoutDirectionQualifier.class,
+ new LayoutDirectionEdit(mQualifierEditParent));
mUiMap.put(SmallestScreenWidthQualifier.class,
new SmallestScreenWidthEdit(mQualifierEditParent));
mUiMap.put(ScreenWidthQualifier.class, new ScreenWidthEdit(mQualifierEditParent));
@@ -1017,6 +1021,65 @@ public class ConfigurationSelector extends Composite {
}
/**
+ * Edit widget for {@link LayoutDirectionQualifier}.
+ */
+ private class LayoutDirectionEdit extends QualifierEditBase {
+
+ private Combo mDirection;
+
+ public LayoutDirectionEdit(Composite parent) {
+ super(parent, LayoutDirectionQualifier.NAME);
+
+ mDirection = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
+ fillCombo(mDirection, LayoutDirection.values());
+
+ mDirection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ mDirection.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ onDirectionChange();
+ }
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ onDirectionChange();
+ }
+ });
+ }
+
+ protected void onDirectionChange() {
+ // update the current config
+ int index = mDirection.getSelectionIndex();
+
+ if (index != -1) {
+ mSelectedConfiguration.setLayoutDirectionQualifier(new LayoutDirectionQualifier(
+ LayoutDirection.getByIndex(index)));
+ } else {
+ // empty selection, 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.setLayoutDirectionQualifier(
+ new LayoutDirectionQualifier());
+ }
+
+ // notify of change
+ onChange(true /* keepSelection */);
+ }
+
+ @Override
+ public void setQualifier(ResourceQualifier qualifier) {
+ LayoutDirectionQualifier q = (LayoutDirectionQualifier)qualifier;
+
+ LayoutDirection value = q.getValue();
+ if (value == null) {
+ mDirection.clearSelection();
+ } else {
+ mDirection.select(LayoutDirection.getIndex(value));
+ }
+ }
+ }
+
+
+ /**
* Edit widget for {@link SmallestScreenWidthQualifier}.
*/
private class SmallestScreenWidthEdit extends QualifierEditBase {
diff --git a/layoutlib_api/src/com/android/resources/LayoutDirection.java b/layoutlib_api/src/com/android/resources/LayoutDirection.java
new file mode 100644
index 0000000..fbc386d
--- /dev/null
+++ b/layoutlib_api/src/com/android/resources/LayoutDirection.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.resources;
+
+/**
+ * Layout Direction enum.
+ */
+public enum LayoutDirection implements ResourceEnum {
+ LTR("ldltr", "LTR", "Left To Right"), //$NON-NLS-1$
+ RTL("ldrtl", "RTL", "Right To Left"); //$NON-NLS-1$
+
+ private final String mValue;
+ private final String mShortDisplayValue;
+ private final String mLongDisplayValue;
+
+ private LayoutDirection(String value, String shortDisplayValue, String longDisplayValue) {
+ mValue = value;
+ mShortDisplayValue = shortDisplayValue;
+ mLongDisplayValue = longDisplayValue;
+ }
+
+ /**
+ * Returns the enum for matching the provided qualifier value.
+ * @param value The qualifier value.
+ * @return the enum for the qualifier value or null if no matching was found.
+ */
+ public static LayoutDirection getEnum(String value) {
+ for (LayoutDirection orient : values()) {
+ if (orient.mValue.equals(value)) {
+ return orient;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getResourceValue() {
+ return mValue;
+ }
+
+ @Override
+ public String getShortDisplayValue() {
+ return mShortDisplayValue;
+ }
+
+ @Override
+ public String getLongDisplayValue() {
+ return mLongDisplayValue;
+ }
+
+ public static int getIndex(LayoutDirection orientation) {
+ int i = 0;
+ for (LayoutDirection orient : values()) {
+ if (orient == orientation) {
+ return i;
+ }
+
+ i++;
+ }
+
+ return -1;
+ }
+
+ public static LayoutDirection getByIndex(int index) {
+ int i = 0;
+ for (LayoutDirection orient : values()) {
+ if (i == index) {
+ return orient;
+ }
+ i++;
+ }
+
+ return null;
+ }
+
+ @Override
+ public boolean isFakeValue() {
+ return false;
+ }
+
+ @Override
+ public boolean isValidValueForDevice() {
+ return true;
+ }
+}
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 a513c1f..fc83359 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
@@ -48,23 +48,24 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
private final static int INDEX_NETWORK_CODE = 1;
private final static int INDEX_LANGUAGE = 2;
private final static int INDEX_REGION = 3;
- private final static int INDEX_SMALLEST_SCREEN_WIDTH = 4;
- private final static int INDEX_SCREEN_WIDTH = 5;
- private final static int INDEX_SCREEN_HEIGHT = 6;
- private final static int INDEX_SCREEN_LAYOUT_SIZE = 7;
- private final static int INDEX_SCREEN_RATIO = 8;
- private final static int INDEX_SCREEN_ORIENTATION = 9;
- private final static int INDEX_UI_MODE = 10;
- private final static int INDEX_NIGHT_MODE = 11;
- private final static int INDEX_PIXEL_DENSITY = 12;
- private final static int INDEX_TOUCH_TYPE = 13;
- private final static int INDEX_KEYBOARD_STATE = 14;
- private final static int INDEX_TEXT_INPUT_METHOD = 15;
- private final static int INDEX_NAVIGATION_STATE = 16;
- private final static int INDEX_NAVIGATION_METHOD = 17;
- private final static int INDEX_SCREEN_DIMENSION = 18;
- private final static int INDEX_VERSION = 19;
- private final static int INDEX_COUNT = 20;
+ private final static int INDEX_LAYOUTDIR = 4;
+ private final static int INDEX_SMALLEST_SCREEN_WIDTH = 5;
+ private final static int INDEX_SCREEN_WIDTH = 6;
+ private final static int INDEX_SCREEN_HEIGHT = 7;
+ private final static int INDEX_SCREEN_LAYOUT_SIZE = 8;
+ private final static int INDEX_SCREEN_RATIO = 9;
+ private final static int INDEX_SCREEN_ORIENTATION = 10;
+ private final static int INDEX_UI_MODE = 11;
+ private final static int INDEX_NIGHT_MODE = 12;
+ private final static int INDEX_PIXEL_DENSITY = 13;
+ private final static int INDEX_TOUCH_TYPE = 14;
+ private final static int INDEX_KEYBOARD_STATE = 15;
+ private final static int INDEX_TEXT_INPUT_METHOD = 16;
+ private final static int INDEX_NAVIGATION_STATE = 17;
+ private final static int INDEX_NAVIGATION_METHOD = 18;
+ private final static int INDEX_SCREEN_DIMENSION = 19;
+ private final static int INDEX_VERSION = 20;
+ private final static int INDEX_COUNT = 21;
/**
* Creates a {@link FolderConfiguration} matching the folder segments.
@@ -267,6 +268,9 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
} else if (qualifier instanceof RegionQualifier) {
mQualifiers[INDEX_REGION] = qualifier;
+ } else if (qualifier instanceof LayoutDirectionQualifier) {
+ mQualifiers[INDEX_LAYOUTDIR] = qualifier;
+
} else if (qualifier instanceof SmallestScreenWidthQualifier) {
mQualifiers[INDEX_SMALLEST_SCREEN_WIDTH] = qualifier;
@@ -373,6 +377,14 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
return (RegionQualifier)mQualifiers[INDEX_REGION];
}
+ public void setLayoutDirectionQualifier(LayoutDirectionQualifier qualifier) {
+ mQualifiers[INDEX_LAYOUTDIR] = qualifier;
+ }
+
+ public LayoutDirectionQualifier getLayoutDirectionQualifier() {
+ return (LayoutDirectionQualifier)mQualifiers[INDEX_LAYOUTDIR];
+ }
+
public void setSmallestScreenWidthQualifier(SmallestScreenWidthQualifier qualifier) {
mQualifiers[INDEX_SMALLEST_SCREEN_WIDTH] = qualifier;
}
@@ -891,6 +903,7 @@ public final class FolderConfiguration implements Comparable<FolderConfiguration
mQualifiers[INDEX_NETWORK_CODE] = new NetworkCodeQualifier();
mQualifiers[INDEX_LANGUAGE] = new LanguageQualifier();
mQualifiers[INDEX_REGION] = new RegionQualifier();
+ mQualifiers[INDEX_LAYOUTDIR] = new LayoutDirectionQualifier();
mQualifiers[INDEX_SMALLEST_SCREEN_WIDTH] = new SmallestScreenWidthQualifier();
mQualifiers[INDEX_SCREEN_WIDTH] = new ScreenWidthQualifier();
mQualifiers[INDEX_SCREEN_HEIGHT] = new ScreenHeightQualifier();
diff --git a/sdk_common/src/com/android/ide/common/resources/configuration/LayoutDirectionQualifier.java b/sdk_common/src/com/android/ide/common/resources/configuration/LayoutDirectionQualifier.java
new file mode 100644
index 0000000..48498f0
--- /dev/null
+++ b/sdk_common/src/com/android/ide/common/resources/configuration/LayoutDirectionQualifier.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.common.resources.configuration;
+
+import com.android.resources.LayoutDirection;
+import com.android.resources.ResourceEnum;
+
+/**
+ * Resource Qualifier for layout direction. values can be "ltr", or "rtl"
+ */
+public class LayoutDirectionQualifier extends EnumBasedResourceQualifier {
+
+ public static final String NAME = "Layout Direction";
+
+ private LayoutDirection mValue = null;
+
+
+ public LayoutDirectionQualifier() {
+ }
+
+ public LayoutDirectionQualifier(LayoutDirection value) {
+ mValue = value;
+ }
+
+ public LayoutDirection getValue() {
+ return mValue;
+ }
+
+ @Override
+ ResourceEnum getEnumValue() {
+ return mValue;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public String getShortName() {
+ return NAME;
+ }
+
+ @Override
+ public int since() {
+ return 17;
+ }
+
+ @Override
+ public boolean checkAndSet(String value, FolderConfiguration config) {
+ LayoutDirection ld = LayoutDirection.getEnum(value);
+ if (ld != null) {
+ LayoutDirectionQualifier qualifier = new LayoutDirectionQualifier(ld);
+ config.setLayoutDirectionQualifier(qualifier);
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/sdk_common/tests/src/com/android/ide/common/resources/configuration/FolderConfigurationTest.java b/sdk_common/tests/src/com/android/ide/common/resources/configuration/FolderConfigurationTest.java
index 261f9a8..5f29791 100644
--- a/sdk_common/tests/src/com/android/ide/common/resources/configuration/FolderConfigurationTest.java
+++ b/sdk_common/tests/src/com/android/ide/common/resources/configuration/FolderConfigurationTest.java
@@ -55,12 +55,30 @@ public class FolderConfigurationTest extends TestCase {
public void testVersionResMatch() {
runConfigMatchTest(
"en-rUS-w600dp-h1024dp-large-port-mdpi-finger-nokeys-v12",
- 3,
+ 2,
"",
"large",
"w540dp");
}
+ public void testAddQualifier() {
+ FolderConfiguration defaultConfig = new FolderConfiguration();
+ defaultConfig.createDefault();
+
+ final int count = FolderConfiguration.getQualifierCount();
+ for (int i = 0 ; i < count ; i++) {
+ FolderConfiguration empty = new FolderConfiguration();
+
+ ResourceQualifier q = defaultConfig.getQualifier(i);
+
+ empty.addQualifier(q);
+
+ // check it was added
+ assertNotNull(
+ "addQualifier failed for " + q.getClass().getName(), empty.getQualifier(i));
+ }
+ }
+
// --- helper methods
@@ -90,7 +108,6 @@ public class FolderConfigurationTest extends TestCase {
List<? extends Configurable> list = getConfigurable(configs);
Configurable match = reference.findMatchingConfigurable(list);
- System.out.println(match.toString());
assertEquals(resultIndex, list.indexOf(match));
}