aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-10-17 16:35:09 -0700
committerGerrit Code Review <noreply-gerritcodereview@google.com>2012-10-17 16:35:09 -0700
commitb8bd06476ddbaa2cf745270e1223508407505217 (patch)
tree1553da9ceb4619ed9f7d0d002d20c8130001a650 /eclipse/plugins
parent6e6f84919e31c79b8c51108e791c4a53ad8c413d (diff)
parentc431088d54a4571f5596e6d1da0069eab62f371b (diff)
downloadsdk-b8bd06476ddbaa2cf745270e1223508407505217.zip
sdk-b8bd06476ddbaa2cf745270e1223508407505217.tar.gz
sdk-b8bd06476ddbaa2cf745270e1223508407505217.tar.bz2
Merge "Update Layoutlib_api to use a class for h/w config."
Diffstat (limited to 'eclipse/plugins')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java11
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java94
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java13
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/HardwareConfigHelper.java153
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java6
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java5
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreview.java8
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java162
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlPropertyEditor.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java16
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java1
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationTest.java8
14 files changed, 237 insertions, 248 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java
index 9553bc8..c89a81b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java
@@ -79,7 +79,6 @@ public class UiElementPullParser extends BasePullParser {
private boolean mIncreaseExistingPadding = false;
private LayoutDescriptors mDescriptors;
private final Density mDensity;
- private final float mXdpi;
/**
* Number of pixels to pad views with in exploded-rendering mode.
@@ -114,18 +113,16 @@ public class UiElementPullParser extends BasePullParser {
* nodes are not individually exploded (but they may all be exploded with the
* explodeRendering parameter.
* @param density the density factor for the screen.
- * @param xdpi the screen actual dpi in X
* @param project Project containing this layout.
*/
public UiElementPullParser(UiElementNode top, boolean explodeRendering,
Set<UiElementNode> explodeNodes,
- Density density, float xdpi, IProject project) {
+ Density density, IProject project) {
super();
mRoot = top;
mExplodedRendering = explodeRendering;
mExplodeNodes = explodeNodes;
mDensity = density;
- mXdpi = xdpi;
if (mExplodedRendering) {
// get the layout descriptor
IAndroidTarget target = Sdk.getCurrent().getTarget(project);
@@ -631,13 +628,13 @@ public class UiElementPullParser extends BasePullParser {
f *= (float)mDensity.getDpiValue() / Density.DEFAULT_DENSITY;
break;
case COMPLEX_UNIT_PT:
- f *= mXdpi * (1.0f / 72);
+ f *= mDensity.getDpiValue() * (1.0f / 72);
break;
case COMPLEX_UNIT_IN:
- f *= mXdpi;
+ f *= mDensity.getDpiValue();
break;
case COMPLEX_UNIT_MM:
- f *= mXdpi * (1.0f / 25.4f);
+ f *= mDensity.getDpiValue() * (1.0f / 25.4f);
break;
}
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 c0b57ac..00caccd 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
@@ -22,7 +22,6 @@ import static com.android.SdkConstants.STYLE_RESOURCE_PREFIX;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
-import com.android.ide.common.api.Rect;
import com.android.ide.common.rendering.api.Capability;
import com.android.ide.common.resources.ResourceRepository;
import com.android.ide.common.resources.configuration.DensityQualifier;
@@ -31,8 +30,6 @@ import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.common.resources.configuration.LanguageQualifier;
import com.android.ide.common.resources.configuration.NightModeQualifier;
import com.android.ide.common.resources.configuration.RegionQualifier;
-import com.android.ide.common.resources.configuration.ScreenDimensionQualifier;
-import com.android.ide.common.resources.configuration.ScreenOrientationQualifier;
import com.android.ide.common.resources.configuration.ScreenSizeQualifier;
import com.android.ide.common.resources.configuration.UiModeQualifier;
import com.android.ide.common.resources.configuration.VersionQualifier;
@@ -44,7 +41,6 @@ import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.resources.Density;
import com.android.resources.NightMode;
-import com.android.resources.ScreenOrientation;
import com.android.resources.ScreenSize;
import com.android.resources.UiMode;
import com.android.sdklib.AndroidVersion;
@@ -954,96 +950,6 @@ public class Configuration {
}
/**
- * Returns the current device xdpi.
- *
- * @return the x dpi as a float
- */
- public float getXDpi() {
- Device device = getDevice();
- if (device != null) {
- State currState = getDeviceState();
- if (currState == null) {
- currState = device.getDefaultState();
- }
- float dpi = (float) currState.getHardware().getScreen().getXdpi();
- if (!Float.isNaN(dpi)) {
- return dpi;
- }
- }
-
- // get the pixel density as the density.
- return getDensity().getDpiValue();
- }
-
- /**
- * Returns the current device ydpi.
- *
- * @return the y dpi as a float
- */
- public float getYDpi() {
- Device device = getDevice();
- if (device != null) {
- State currState = getDeviceState();
- if (currState == null) {
- currState = device.getDefaultState();
- }
- float dpi = (float) currState.getHardware().getScreen().getYdpi();
- if (!Float.isNaN(dpi)) {
- return dpi;
- }
- }
-
- // get the pixel density as the density.
- return getDensity().getDpiValue();
- }
-
- /**
- * Returns the bounds of the screen
- *
- * @return the screen bounds
- */
- public Rect getScreenBounds() {
- return getScreenBounds(mFullConfig);
- }
-
- /**
- * Gets the orientation from the given configuration
- *
- * @param config the configuration to look up
- * @return the bounds
- */
- @NonNull
- public static Rect getScreenBounds(FolderConfiguration config) {
- // get the orientation from the given device config
- ScreenOrientationQualifier qual = config.getScreenOrientationQualifier();
- ScreenOrientation orientation = ScreenOrientation.PORTRAIT;
- if (qual != null) {
- orientation = qual.getValue();
- }
-
- // get the device screen dimension
- ScreenDimensionQualifier qual2 = config.getScreenDimensionQualifier();
- int s1, s2;
- if (qual2 != null) {
- s1 = qual2.getValue1();
- s2 = qual2.getValue2();
- } else {
- s1 = 480;
- s2 = 320;
- }
-
- switch (orientation) {
- default:
- case PORTRAIT:
- return new Rect(0, 0, s2, s1);
- case LANDSCAPE:
- return new Rect(0, 0, s1, s2);
- case SQUARE:
- return new Rect(0, 0, s1, s1);
- }
- }
-
- /**
* Get the next cyclical state after the given state
*
* @param from the state to start with
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java
index 9b8eeea..67a890f 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java
@@ -32,6 +32,7 @@ import static com.android.SdkConstants.VALUE_MATCH_PARENT;
import static com.android.SdkConstants.VALUE_WRAP_CONTENT;
import static com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationChooser.NAME_CONFIG_STATE;
import static com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor.viewNeedsPackage;
+
import static org.eclipse.wb.core.controls.flyout.IFlyoutPreferences.DOCK_EAST;
import static org.eclipse.wb.core.controls.flyout.IFlyoutPreferences.DOCK_WEST;
import static org.eclipse.wb.core.controls.flyout.IFlyoutPreferences.STATE_COLLAPSED;
@@ -40,7 +41,6 @@ import static org.eclipse.wb.core.controls.flyout.IFlyoutPreferences.STATE_OPEN;
import com.android.SdkConstants;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
-import com.android.ide.common.api.Rect;
import com.android.ide.common.layout.BaseLayoutRule;
import com.android.ide.common.rendering.LayoutLibrary;
import com.android.ide.common.rendering.StaticRenderSession;
@@ -1316,15 +1316,6 @@ public class GraphicalEditorPart extends EditorPart
}
/**
- * Returns the current bounds of the Android device screen, in canvas control pixels.
- *
- * @return the bounds of the screen, never null
- */
- public Rect getScreenBounds() {
- return mConfigChooser.getConfiguration().getScreenBounds();
- }
-
- /**
* Returns the scale to multiply pixels in the layout coordinate space with to obtain
* the corresponding dip (device independent pixel)
*
@@ -1518,7 +1509,6 @@ public class GraphicalEditorPart extends EditorPart
LayoutLibrary layoutLib) {
LayoutCanvas canvas = getCanvasControl();
Set<UiElementNode> explodeNodes = canvas.getNodesToExplode();
- Rect rect = getScreenBounds();
RenderLogger logger = new RenderLogger(mEditedFile.getName());
RenderingMode renderingMode = RenderingMode.NORMAL;
// FIXME set the rendering mode using ViewRule or something.
@@ -1530,7 +1520,6 @@ public class GraphicalEditorPart extends EditorPart
RenderSession session = RenderService.create(this)
.setModel(model)
- .setSize(rect.w, rect.h)
.setLog(logger)
.setRenderingMode(renderingMode)
.setIncludedWithin(mIncludedWithin)
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/HardwareConfigHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/HardwareConfigHelper.java
new file mode 100644
index 0000000..db1c1f1
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/HardwareConfigHelper.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
+ *
+ * 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.eclipse.adt.internal.editors.layout.gle2;
+
+import com.android.ide.common.rendering.api.HardwareConfig;
+import com.android.resources.ScreenOrientation;
+import com.android.sdklib.devices.ButtonType;
+import com.android.sdklib.devices.Device;
+import com.android.sdklib.devices.Screen;
+
+/**
+ * Helper method to create a {@link HardwareConfig} object.
+ *
+ * The base data comes from a {@link Device} object, with additional data provided on the helper
+ * object.
+ *
+ * Since {@link HardwareConfig} is immutable, this allows creating one in several (optional)
+ * steps more easily.
+ *
+ */
+public class HardwareConfigHelper {
+
+ private final Device mDevice;
+ private ScreenOrientation mScreenOrientation = ScreenOrientation.PORTRAIT;
+
+ // optional
+ private int mMaxRenderWidth = -1;
+ private int mMaxRenderHeight = -1;
+ private int mOverrideRenderWidth = -1;
+ private int mOverrideRenderHeight = -1;
+
+ /**
+ * Creates a new helper for a given device.
+ * @param device the device to provide the base data.
+ */
+ public HardwareConfigHelper(Device device) {
+ mDevice = device;
+ }
+
+ /**
+ * Sets the orientation of the config.
+ * @param screenOrientation the orientation.
+ * @return this (such that chains of setters can be stringed together)
+ */
+ public HardwareConfigHelper setOrientation(ScreenOrientation screenOrientation) {
+ mScreenOrientation = screenOrientation;
+ return this;
+ }
+
+ /**
+ * Overrides the width and height to be used during rendering.
+ *
+ * A value of -1 will make the rendering use the normal width and height coming from the
+ * {@link Device} object.
+ *
+ * @param overrideRenderWidth the width in pixels of the layout to be rendered
+ * @param overrideRenderHeight the height in pixels of the layout to be rendered
+ * @return this (such that chains of setters can be stringed together)
+ */
+ public HardwareConfigHelper setOverrideRenderSize(int overrideRenderWidth,
+ int overrideRenderHeight) {
+ mOverrideRenderWidth = overrideRenderWidth;
+ mOverrideRenderHeight = overrideRenderHeight;
+ return this;
+ }
+
+ /**
+ * Sets the max width and height to be used during rendering.
+ *
+ * A value of -1 will make the rendering use the normal width and height coming from the
+ * {@link Device} object.
+ *
+ * @param maxRenderWidth the max width in pixels of the layout to be rendered
+ * @param maxRenderHeight the max height in pixels of the layout to be rendered
+ * @return this (such that chains of setters can be stringed together)
+ */
+ public HardwareConfigHelper setMaxRenderSize(int maxRenderWidth, int maxRenderHeight) {
+ mMaxRenderWidth = maxRenderWidth;
+ mMaxRenderHeight = maxRenderHeight;
+ return this;
+ }
+
+ /**
+ * Creates and returns the HardwareConfig object.
+ * @return the config
+ */
+ public HardwareConfig getConfig() {
+ Screen screen = mDevice.getDefaultHardware().getScreen();
+
+ // compute width and height to take orientation into account.
+ int x = screen.getXDimension();
+ int y = screen.getYDimension();
+ int width, height;
+
+ if (x > y) {
+ if (mScreenOrientation == ScreenOrientation.LANDSCAPE) {
+ width = x;
+ height = y;
+ } else {
+ width = y;
+ height = x;
+ }
+ } else {
+ if (mScreenOrientation == ScreenOrientation.LANDSCAPE) {
+ width = y;
+ height = x;
+ } else {
+ width = x;
+ height = y;
+ }
+ }
+
+ if (mOverrideRenderHeight != -1) {
+ width = mOverrideRenderWidth;
+ }
+
+ if (mOverrideRenderHeight != -1) {
+ height = mOverrideRenderHeight;
+ }
+
+ if (mMaxRenderWidth != -1) {
+ width = mMaxRenderWidth;
+ }
+
+ if (mMaxRenderHeight != -1) {
+ height = mMaxRenderHeight;
+ }
+
+ return new HardwareConfig(
+ width,
+ height,
+ screen.getPixelDensity(),
+ (float) screen.getXdpi(),
+ (float) screen.getYdpi(),
+ screen.getSize(),
+ mScreenOrientation,
+ mDevice.getDefaultHardware().getButtonType() == ButtonType.SOFT);
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
index d5b46b4..1b1bd23 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
@@ -33,6 +33,8 @@ import com.android.ide.eclipse.adt.internal.editors.layout.gre.NodeProxy;
import com.android.ide.eclipse.adt.internal.editors.layout.gre.RulesEngine;
import com.android.ide.eclipse.adt.internal.lint.EclipseLintClient;
import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs;
+import com.android.sdklib.devices.Device;
+import com.android.sdklib.devices.Screen;
import com.android.sdkuilib.internal.widgets.ResolutionChooserDialog;
import com.google.common.base.Strings;
@@ -708,7 +710,9 @@ public class LayoutActionBar extends Composite {
// compute average dpi of X and Y
ConfigurationChooser chooser = mEditor.getConfigurationChooser();
Configuration config = chooser.getConfiguration();
- float dpi = (config.getXDpi() + config.getYDpi()) / 2.f;
+ Device device = config.getDevice();
+ Screen screen = device.getDefaultHardware().getScreen();
+ double dpi = (screen.getXdpi() + screen.getYdpi()) / 2.;
// get the monitor dpi
float monitor = AdtPrefs.getPrefs().getMonitorDensity();
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java
index ad4b94d..46168b7 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteControl.java
@@ -1000,14 +1000,11 @@ public class PaletteControl extends Composite {
// This is important since when we fill the size of certain views (like
// a SeekBar), we want it to at most be the width of the screen, and for small
// screens the RENDER_WIDTH was wider.
- Rect screenBounds = editor.getScreenBounds();
- int renderWidth = Math.min(screenBounds.w, MAX_RENDER_WIDTH);
- int renderHeight = Math.min(screenBounds.h, MAX_RENDER_HEIGHT);
LayoutLog silentLogger = new LayoutLog();
session = RenderService.create(editor)
.setModel(model)
- .setSize(renderWidth, renderHeight)
+ .setMaxRenderSize(MAX_RENDER_WIDTH, MAX_RENDER_HEIGHT)
.setLog(silentLogger)
.setOverrideBgColor(overrideBgColor)
.setDecorations(false)
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java
index 5ca8e9c..c92ce81 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java
@@ -265,7 +265,7 @@ public class PreviewIconFactory {
session = RenderService.create(editor)
.setModel(model)
- .setSize(width, height)
+ .setOverrideRenderSize(width, height)
.setRenderingMode(RenderingMode.FULL_EXPAND)
.setLog(new RenderLogger("palette"))
.setOverrideBgColor(overrideBgColor)
@@ -440,7 +440,7 @@ public class PreviewIconFactory {
ResourceResolver resources = editor.getResourceResolver();
ResourceValue resourceValue = resources.findItemInTheme(themeItemName);
BufferedImage image = RenderService.create(editor)
- .setSize(100, 100)
+ .setOverrideRenderSize(100, 100)
.renderDrawable(resourceValue);
if (image != null) {
// Use the middle pixel as the color since that works better for gradients;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreview.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreview.java
index 4811235..07f640b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreview.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreview.java
@@ -28,7 +28,6 @@ import static com.android.ide.eclipse.adt.internal.editors.layout.gle2.ImageUtil
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
-import com.android.ide.common.api.Rect;
import com.android.ide.common.rendering.api.RenderSession;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.rendering.api.Result;
@@ -39,7 +38,6 @@ import com.android.ide.common.resources.ResourceResolver;
import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.common.resources.configuration.ScreenDimensionQualifier;
import com.android.ide.common.resources.configuration.ScreenOrientationQualifier;
-import com.android.ide.common.resources.configuration.ScreenSizeQualifier;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.AdtUtils;
import com.android.ide.eclipse.adt.internal.editors.IconFactory;
@@ -529,9 +527,7 @@ public class RenderPreview implements IJobChangeListener {
GraphicalEditorPart editor = mCanvas.getEditorDelegate().getGraphicalEditor();
ResourceResolver resolver = getResourceResolver();
FolderConfiguration config = mConfiguration.getFullConfig();
- RenderService renderService = RenderService.create(editor, config, resolver);
- ScreenSizeQualifier screenSize = config.getScreenSizeQualifier();
- renderService.setScreen(screenSize, mConfiguration.getXDpi(), mConfiguration.getYDpi());
+ RenderService renderService = RenderService.create(editor, mConfiguration, resolver);
if (mIncludedWithin != null) {
renderService.setIncludedWithin(mIncludedWithin);
@@ -569,8 +565,6 @@ public class RenderPreview implements IJobChangeListener {
} else {
renderService.setModel(editor.getModel());
}
- Rect rect = Configuration.getScreenBounds(config);
- renderService.setSize(rect.w, rect.h);
RenderLogger log = new RenderLogger(getDisplayName());
renderService.setLog(log);
RenderSession session = renderService.createRenderSession();
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java
index 2a1f3b7..065e327 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java
@@ -24,6 +24,7 @@ import com.android.ide.common.api.Rect;
import com.android.ide.common.rendering.LayoutLibrary;
import com.android.ide.common.rendering.api.Capability;
import com.android.ide.common.rendering.api.DrawableParams;
+import com.android.ide.common.rendering.api.HardwareConfig;
import com.android.ide.common.rendering.api.IImageFactory;
import com.android.ide.common.rendering.api.ILayoutPullParser;
import com.android.ide.common.rendering.api.LayoutLog;
@@ -34,12 +35,9 @@ import com.android.ide.common.rendering.api.SessionParams;
import com.android.ide.common.rendering.api.SessionParams.RenderingMode;
import com.android.ide.common.rendering.api.ViewInfo;
import com.android.ide.common.resources.ResourceResolver;
-import com.android.ide.common.resources.configuration.DensityQualifier;
import com.android.ide.common.resources.configuration.FolderConfiguration;
-import com.android.ide.common.resources.configuration.ScreenSizeQualifier;
import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.layout.ContextPullParser;
-import com.android.ide.eclipse.adt.internal.editors.layout.ExplodedRenderingHelper;
import com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback;
import com.android.ide.eclipse.adt.internal.editors.layout.UiElementPullParser;
import com.android.ide.eclipse.adt.internal.editors.layout.configuration.Configuration;
@@ -53,11 +51,7 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
-import com.android.resources.Density;
import com.android.sdklib.IAndroidTarget;
-import com.android.sdklib.devices.ButtonType;
-import com.android.sdklib.devices.Device;
-import com.android.sdklib.devices.Hardware;
import org.eclipse.core.resources.IProject;
import org.xmlpull.v1.XmlPullParser;
@@ -89,21 +83,14 @@ public class RenderService {
private final ResourceResolver mResourceResolver;
private final int mMinSdkVersion;
private final int mTargetSdkVersion;
- private final boolean mSoftwareButtons;
private final LayoutLibrary mLayoutLib;
private final IImageFactory mImageFactory;
- private final Density mDensity;
- private float mXdpi;
- private float mYdpi;
- private ScreenSizeQualifier mScreenSize;
+ private final HardwareConfigHelper mHardwareConfigHelper;
// The following fields are optional or configurable using the various chained
// setters:
private UiDocumentNode mModel;
- private int mWidth = -1;
- private int mHeight = -1;
- private boolean mUseExplodeMode;
private Reference mIncludedWithin;
private RenderingMode mRenderingMode = RenderingMode.NORMAL;
private LayoutLog mLogger;
@@ -120,60 +107,37 @@ public class RenderService {
mImageFactory = canvas.getImageOverlay();
ConfigurationChooser chooser = editor.getConfigurationChooser();
Configuration config = chooser.getConfiguration();
- mDensity = config.getDensity();
- mXdpi = config.getXDpi();
- mYdpi = config.getYDpi();
- mScreenSize = chooser.getConfiguration().getFullConfig().getScreenSizeQualifier();
+ FolderConfiguration folderConfig = config.getFullConfig();
+
+ mHardwareConfigHelper = new HardwareConfigHelper(config.getDevice());
+ mHardwareConfigHelper.setOrientation(
+ folderConfig.getScreenOrientationQualifier().getValue());
+
mLayoutLib = editor.getReadyLayoutLib(true /*displayError*/);
mResourceResolver = editor.getResourceResolver();
mProjectCallback = editor.getProjectCallback(true /*reset*/, mLayoutLib);
mMinSdkVersion = editor.getMinSdkVersion();
mTargetSdkVersion = editor.getTargetSdkVersion();
- mSoftwareButtons = getButtonType(config) == ButtonType.SOFT;
}
- private RenderService(GraphicalEditorPart editor, FolderConfiguration configuration,
- ResourceResolver resourceResolver) {
+ private RenderService(GraphicalEditorPart editor,
+ Configuration configuration, ResourceResolver resourceResolver) {
mEditor = editor;
mProject = editor.getProject();
LayoutCanvas canvas = editor.getCanvasControl();
mImageFactory = canvas.getImageOverlay();
- Configuration config = editor.getConfigurationChooser().getConfiguration();
- mXdpi = config.getXDpi();
- mYdpi = config.getYDpi();
+ FolderConfiguration folderConfig = configuration.getFullConfig();
+
+ mHardwareConfigHelper = new HardwareConfigHelper(configuration.getDevice());
+ mHardwareConfigHelper.setOrientation(
+ folderConfig.getScreenOrientationQualifier().getValue());
+
mLayoutLib = editor.getReadyLayoutLib(true /*displayError*/);
mResourceResolver = resourceResolver != null ? resourceResolver : editor.getResourceResolver();
mProjectCallback = editor.getProjectCallback(true /*reset*/, mLayoutLib);
mMinSdkVersion = editor.getMinSdkVersion();
mTargetSdkVersion = editor.getTargetSdkVersion();
- mSoftwareButtons = getButtonType(config) == ButtonType.SOFT;
-
- // TODO: Look up device etc and offer additional configuration options here?
- Density density = Density.MEDIUM;
- DensityQualifier densityQualifier = configuration.getDensityQualifier();
- if (densityQualifier != null) {
- // just a sanity check
- Density d = densityQualifier.getValue();
- if (d != Density.NODPI) {
- density = d;
- }
- }
- mDensity = density;
- mScreenSize = configuration.getScreenSizeQualifier();
- }
-
- @NonNull
- private static ButtonType getButtonType(@NonNull Configuration configuration) {
- Device device = configuration.getDevice();
- if (device != null) {
- Hardware hardware = device.getDefaultHardware();
- if (hardware != null) {
- return hardware.getButtonType();
- }
- }
-
- return ButtonType.SOFT;
}
/**
@@ -202,21 +166,6 @@ public class RenderService {
}
/**
- * Sets the screen size and density to use for rendering
- *
- * @param screenSize the screen size
- * @param xdpi the x density
- * @param ydpi the y density
- * @return this, for constructor chaining
- */
- public RenderService setScreen(ScreenSizeQualifier screenSize, float xdpi, float ydpi) {
- mXdpi = xdpi;
- mYdpi = ydpi;
- mScreenSize = screenSize;
- return this;
- }
-
- /**
* Creates a new {@link RenderService} associated with the given editor.
*
* @param editor the editor to provide configuration data such as the render target
@@ -237,7 +186,7 @@ public class RenderService {
* @return a {@link RenderService} which can perform rendering services
*/
public static RenderService create(GraphicalEditorPart editor,
- FolderConfiguration configuration, ResourceResolver resolver) {
+ Configuration configuration, ResourceResolver resolver) {
RenderService renderService = new RenderService(editor, configuration, resolver);
return renderService;
@@ -287,16 +236,34 @@ public class RenderService {
}
/**
- * Sets the width and height to be used during rendering (which might be adjusted if
+ * Overrides the width and height to be used during rendering (which might be adjusted if
* the {@link #setRenderingMode(RenderingMode)} is {@link RenderingMode#FULL_EXPAND}.
*
- * @param width the width in pixels of the layout to be rendered
- * @param height the height in pixels of the layout to be rendered
+ * A value of -1 will make the rendering use the normal width and height coming from the
+ * {@link Configuration#getDevice()} object.
+ *
+ * @param overrideRenderWidth the width in pixels of the layout to be rendered
+ * @param overrideRenderHeight the height in pixels of the layout to be rendered
+ * @return this (such that chains of setters can be stringed together)
+ */
+ public RenderService setOverrideRenderSize(int overrideRenderWidth, int overrideRenderHeight) {
+ mHardwareConfigHelper.setOverrideRenderSize(overrideRenderWidth, overrideRenderHeight);
+ return this;
+ }
+
+ /**
+ * Sets the max width and height to be used during rendering (which might be adjusted if
+ * the {@link #setRenderingMode(RenderingMode)} is {@link RenderingMode#FULL_EXPAND}.
+ *
+ * A value of -1 will make the rendering use the normal width and height coming from the
+ * {@link Configuration#getDevice()} object.
+ *
+ * @param maxRenderWidth the max width in pixels of the layout to be rendered
+ * @param maxRenderHeight the max height in pixels of the layout to be rendered
* @return this (such that chains of setters can be stringed together)
*/
- public RenderService setSize(int width, int height) {
- mWidth = width;
- mHeight = height;
+ public RenderService setMaxRenderSize(int maxRenderWidth, int maxRenderHeight) {
+ mHardwareConfigHelper.setMaxRenderSize(maxRenderWidth, maxRenderHeight);
return this;
}
@@ -376,7 +343,7 @@ public class RenderService {
* @return the {@link RenderSession} resulting from rendering the current model
*/
public RenderSession createRenderSession() {
- assert mModel != null && mWidth != -1 && mHeight != -1 : "Incomplete service config";
+ assert mModel != null : "Incomplete service config";
finishConfiguration();
if (mResourceResolver == null) {
@@ -384,26 +351,10 @@ public class RenderService {
return null;
}
- int width = mWidth;
- int height = mHeight;
- if (mUseExplodeMode) {
- // compute how many padding in x and y will bump the screen size
- List<UiElementNode> children = mModel.getUiChildren();
- if (children.size() == 1) {
- ExplodedRenderingHelper helper = new ExplodedRenderingHelper(
- children.get(0).getXmlNode(), mProject);
-
- // there are 2 paddings for each view
- // left and right, or top and bottom.
- int paddingValue = ExplodedRenderingHelper.PADDING_VALUE * 2;
-
- width += helper.getWidthPadding() * paddingValue;
- height += helper.getHeightPadding() * paddingValue;
- }
- }
+ HardwareConfig hardwareConfig = mHardwareConfigHelper.getConfig();
UiElementPullParser modelParser = new UiElementPullParser(mModel,
- mUseExplodeMode, mExpandNodes, mDensity, mXdpi, mProject);
+ false, mExpandNodes, hardwareConfig.getDensity(), mProject);
ILayoutPullParser topParser = modelParser;
// Code to support editing included layout
@@ -441,13 +392,11 @@ public class RenderService {
topParser,
mRenderingMode,
mProject /* projectKey */,
- width, height,
- mDensity, mXdpi, mYdpi,
+ hardwareConfig,
mResourceResolver,
mProjectCallback,
mMinSdkVersion,
mTargetSdkVersion,
- mSoftwareButtons,
mLogger);
// Request margin and baseline information.
@@ -469,10 +418,6 @@ public class RenderService {
}
}
- if (mScreenSize != null) {
- params.setConfigScreenSize(mScreenSize.getValue());
- }
-
if (mOverrideBgColor != null) {
params.setOverrideBgColor(mOverrideBgColor.intValue());
}
@@ -508,8 +453,10 @@ public class RenderService {
finishConfiguration();
- DrawableParams params = new DrawableParams(drawableResourceValue, mProject, mWidth, mHeight,
- mDensity, mXdpi, mYdpi, mResourceResolver, mProjectCallback, mMinSdkVersion,
+ HardwareConfig hardwareConfig = mHardwareConfigHelper.getConfig();
+
+ DrawableParams params = new DrawableParams(drawableResourceValue, mProject, hardwareConfig,
+ mResourceResolver, mProjectCallback, mMinSdkVersion,
mTargetSdkVersion, mLogger);
params.setForceNoDecor();
Result result = mLayoutLib.renderDrawable(params);
@@ -534,14 +481,13 @@ public class RenderService {
public Map<INode, Rect> measureChildren(INode parent,
final IClientRulesEngine.AttributeFilter filter) {
finishConfiguration();
-
- int width = parent.getBounds().w;
- int height = parent.getBounds().h;
+ HardwareConfig hardwareConfig = mHardwareConfigHelper.getConfig();
final NodeFactory mNodeFactory = mEditor.getCanvasControl().getNodeFactory();
UiElementNode parentNode = ((NodeProxy) parent).getNode();
UiElementPullParser topParser = new UiElementPullParser(parentNode,
- false, Collections.<UiElementNode>emptySet(), mDensity, mXdpi, mProject) {
+ false, Collections.<UiElementNode>emptySet(), hardwareConfig.getDensity(),
+ mProject) {
@Override
public String getAttributeValue(String namespace, String localName) {
if (filter != null) {
@@ -577,13 +523,11 @@ public class RenderService {
topParser,
RenderingMode.FULL_EXPAND,
mProject /* projectKey */,
- width, height,
- mDensity, mXdpi, mYdpi,
+ hardwareConfig,
mResourceResolver,
mProjectCallback,
mMinSdkVersion,
mTargetSdkVersion,
- mSoftwareButtons,
mLogger);
params.setLayoutOnly();
params.setForceNoDecor();
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlPropertyEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlPropertyEditor.java
index d2d7878..41d4cd1 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlPropertyEditor.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/properties/XmlPropertyEditor.java
@@ -200,7 +200,7 @@ class XmlPropertyEditor extends AbstractTextPropertyEditor {
XmlProperty xmlProperty = (XmlProperty) property;
GraphicalEditorPart graphicalEditor = xmlProperty.getGraphicalEditor();
RenderService service = RenderService.create(graphicalEditor);
- service.setSize(SAMPLE_SIZE, SAMPLE_SIZE);
+ service.setOverrideRenderSize(SAMPLE_SIZE, SAMPLE_SIZE);
BufferedImage drawable = service.renderDrawable(resValue);
if (drawable != null) {
swtImage = SwtUtils.convertToSwt(gc.getDevice(), drawable,
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java
index eeaca0c..afd1df9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java
@@ -166,7 +166,7 @@ public class ResourcePreviewHelper {
if (image == null) {
RenderService renderService = RenderService.create(mEditor);
- renderService.setSize(WIDTH, HEIGHT);
+ renderService.setOverrideRenderSize(WIDTH, HEIGHT);
image = renderService.renderDrawable(drawable);
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
index 7a6eef4..2b364a5 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
@@ -19,6 +19,7 @@ package com.android.ide.eclipse.tests.functests.layoutRendering;
import com.android.SdkConstants;
import com.android.ide.common.rendering.LayoutLibrary;
import com.android.ide.common.rendering.api.AdapterBinding;
+import com.android.ide.common.rendering.api.HardwareConfig;
import com.android.ide.common.rendering.api.ILayoutPullParser;
import com.android.ide.common.rendering.api.IProjectCallback;
import com.android.ide.common.rendering.api.RenderSession;
@@ -250,20 +251,25 @@ public class ApiDemosRenderingTest extends SdkTestCase {
configuredProject, configuredFramework,
"Theme", false /*isProjectTheme*/);
- RenderSession session = layoutLib.createSession(new SessionParams(
- parser,
- RenderingMode.NORMAL,
- null /*projectKey*/,
+ HardwareConfig hardwareConfig = new HardwareConfig(
320,
480,
Density.MEDIUM,
160, //xdpi
160, // ydpi
+ ScreenSize.NORMAL,
+ ScreenOrientation.PORTRAIT,
+ false /*software buttons */);
+
+ RenderSession session = layoutLib.createSession(new SessionParams(
+ parser,
+ RenderingMode.NORMAL,
+ null /*projectKey*/,
+ hardwareConfig,
resolver,
projectCallBack,
1, // minSdkVersion
1, // targetSdkVersion
- false, // softwareButtons
null //logger
));
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java
index 998c166..5cac663 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParserTest.java
@@ -170,7 +170,6 @@ public class UiElementPullParserTest extends TestCase {
false, // explodedView
null, // explodeNodes
Density.MEDIUM, // density (default from ConfigurationComposite)
- Density.MEDIUM.getDpiValue(), // xdpi (default from ConfigurationComposite)
null // iProject
);
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 c14e7f7..726d9c9 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
@@ -18,12 +18,12 @@ 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 com.android.ide.common.api.Rect;
import com.android.ide.common.resources.configuration.FolderConfiguration;
import com.android.ide.common.resources.configuration.LanguageQualifier;
import com.android.resources.Density;
import com.android.sdklib.devices.Device;
import com.android.sdklib.devices.DeviceManager;
+import com.android.sdklib.devices.Screen;
import com.android.utils.StdLogger;
import java.lang.reflect.Constructor;
@@ -97,9 +97,9 @@ public class ConfigurationTest extends TestCase {
configuration.toPersistentString());
assertEquals(Density.MEDIUM, configuration.getDensity());
- assertEquals(145.0f, configuration.getXDpi(), 0.001);
- assertEquals(145.0f, configuration.getYDpi(), 0.001);
- assertEquals(new Rect(0, 0, 320, 480), configuration.getScreenBounds());
+ Screen screen = configuration.getDevice().getDefaultHardware().getScreen();
+ assertEquals(145.0f, screen.getXdpi(), 0.001);
+ assertEquals(145.0f, screen.getYdpi(), 0.001);
}
public void testCopy() throws Exception {