aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com
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 /eclipse/plugins/com.android.ide.eclipse.tests/unittests/com
parent61da3c30c2456c0f4e33fe8c8507e9179d67947a (diff)
downloadsdk-ec7301a7433cf89c399fa3c507afe8a147adbcba.tar.gz
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 'eclipse/plugins/com.android.ide.eclipse.tests/unittests/com')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java33
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java17
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/IncludeFinderTest.java59
3 files changed, 108 insertions, 1 deletions
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 f55cce475..c14e7f73e 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
@@ -101,4 +101,37 @@ public class ConfigurationTest extends TestCase {
assertEquals(145.0f, configuration.getYDpi(), 0.001);
assertEquals(new Rect(0, 0, 320, 480), configuration.getScreenBounds());
}
+
+ public void testCopy() throws Exception {
+ Configuration configuration = createConfiguration();
+ assertNotNull(configuration);
+ configuration.setTheme("@style/Theme");
+ assertEquals("@style/Theme", configuration.getTheme());
+ DeviceManager deviceManager = new DeviceManager(new StdLogger(StdLogger.Level.VERBOSE));
+ List<Device> devices = deviceManager.getDefaultDevices();
+ assertNotNull(devices);
+ assertTrue(devices.size() > 0);
+ 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"));
+ configuration.setLocale(locale, false /* skipSync */);
+
+ Configuration copy = Configuration.copy(configuration);
+ assertEquals(locale, copy.getLocale());
+ assertEquals("foo.bar.FooActivity", copy.getActivity());
+ assertEquals("@android:style/Theme.Holo.Light", copy.getTheme());
+ assertEquals(devices.get(0), copy.getDevice());
+
+ // Make sure edits to master does not affect the child
+ configuration.setLocale(Locale.ANY, false);
+ configuration.setTheme("@android:style/Theme.Holo");
+ configuration.setDevice(devices.get(1), true);
+
+ assertTrue(copy.getFullConfig().getLanguageQualifier().equals(locale.language));
+ assertEquals(locale, copy.getLocale());
+ assertEquals("foo.bar.FooActivity", copy.getActivity());
+ assertEquals("@android:style/Theme.Holo.Light", copy.getTheme());
+ assertEquals(devices.get(0), copy.getDevice());
+ }
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java
index 9e9c73430..d1c56c233 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageUtilsTest.java
@@ -30,6 +30,7 @@ import java.util.List;
import junit.framework.TestCase;
+@SuppressWarnings("javadoc")
public class ImageUtilsTest extends TestCase {
public void testCropBlank() throws Exception {
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB_PRE);
@@ -339,6 +340,21 @@ public class ImageUtilsTest extends TestCase {
assertEquals(0xFF00FF00, scaled.getRGB(48, 48));
assertEquals(0xFFFF0000, scaled.getRGB(100, 100));
assertEquals(0xFF00FF00, scaled.getRGB(199, 199));
+
+ scaled = ImageUtils.scale(image, 0.25, 0.25);
+ assertEquals(25, scaled.getWidth());
+ assertEquals(25, scaled.getHeight());
+ assertEquals(0xFF00FF00, scaled.getRGB(0, 0));
+ assertEquals(0xFF00FF00, scaled.getRGB(24, 24));
+ assertEquals(0xFFFF0000, scaled.getRGB(13, 13));
+
+ scaled = ImageUtils.scale(image, 0.25, 0.25, 75, 95);
+ assertEquals(100, scaled.getWidth());
+ assertEquals(120, scaled.getHeight());
+ assertEquals(0xFF00FF00, scaled.getRGB(0, 0));
+ assertEquals(0xFF00FF00, scaled.getRGB(24, 24));
+ assertEquals(0xFFFF0000, scaled.getRGB(13, 13));
+
}
public void testCreateColoredImage() throws Exception {
@@ -349,5 +365,4 @@ public class ImageUtilsTest extends TestCase {
assertEquals(0xFFFEFDFC, image.getRGB(50, 50));
assertEquals(0xFFFEFDFC, image.getRGB(119, 109));
}
-
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/IncludeFinderTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/IncludeFinderTest.java
index 24fa0aea7..c86623cd6 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/IncludeFinderTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/IncludeFinderTest.java
@@ -17,9 +17,11 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import junit.framework.TestCase;
+@SuppressWarnings("javadoc")
public class IncludeFinderTest extends TestCase {
public void testEncodeDecode1() throws Exception {
// Test ending with just a key
@@ -66,4 +68,61 @@ public class IncludeFinderTest extends TestCase {
finder.setIncluded("baz", Collections.<String>emptyList(), false);
assertEquals(Collections.emptyList(), finder.getIncludedBy("foo"));
}
+
+ public void testFindIncludes() throws Exception {
+ String xml =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+ "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
+ " android:layout_width=\"match_parent\"\n" +
+ " android:layout_height=\"match_parent\"\n" +
+ " android:orientation=\"vertical\" >\n" +
+ "\n" +
+ " <RadioButton\n" +
+ " android:id=\"@+id/radioButton1\"\n" +
+ " android:layout_width=\"wrap_content\"\n" +
+ " android:layout_height=\"wrap_content\"\n" +
+ " android:text=\"RadioButton\" />\n" +
+ "\n" +
+ " <include\n" +
+ " android:layout_width=\"wrap_content\"\n" +
+ " android:layout_height=\"wrap_content\"\n" +
+ " layout=\"@layout/layout3\" />\n" +
+ "\n" +
+ " <include\n" +
+ " android:layout_width=\"wrap_content\"\n" +
+ " android:layout_height=\"wrap_content\"\n" +
+ " layout=\"@layout/layout4\" />\n" +
+ "\n" +
+ "</LinearLayout>";
+ List<String> includes = IncludeFinder.findIncludes(xml);
+ Collections.sort(includes);
+ assertEquals(Arrays.asList("layout3", "layout4"), includes);
+ }
+
+ public void testFindFragments() throws Exception {
+ String xml =
+ "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
+ " xmlns:tools=\"http://schemas.android.com/tools\"\n" +
+ " android:layout_width=\"match_parent\"\n" +
+ " android:layout_height=\"match_parent\"\n" +
+ " tools:context=\".MainActivity\" >\n" +
+ "\n" +
+ " <fragment\n" +
+ " android:id=\"@+id/fragment1\"\n" +
+ " android:name=\"android.app.ListFragment\"\n" +
+ " android:layout_width=\"wrap_content\"\n" +
+ " android:layout_height=\"wrap_content\"\n" +
+ " android:layout_alignParentLeft=\"true\"\n" +
+ " android:layout_alignParentTop=\"true\"\n" +
+ " android:layout_marginLeft=\"58dp\"\n" +
+ " android:layout_marginTop=\"74dp\"\n" +
+ " tools:layout=\"@layout/myfragment\" />\n" +
+ "\n" +
+ "</RelativeLayout>";
+ List<String> includes = IncludeFinder.findIncludes(xml);
+ Collections.sort(includes);
+ assertEquals(Arrays.asList("myfragment"), includes);
+ }
+
+
}