summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAndrew Shulaev <ddrone@google.com>2015-03-04 17:43:19 +0000
committerAndrew Shulaev <ddrone@google.com>2015-03-04 17:43:19 +0000
commit01cdf8b135be3bf67b9386dc929109c3db82c730 (patch)
treebc6e64c7dc08fcbda6e1d65c7423d003426f6d6c /tools
parent63483e17de4d2441acaabcee4185b0bb25e1d94c (diff)
downloadframeworks_base-01cdf8b135be3bf67b9386dc929109c3db82c730.zip
frameworks_base-01cdf8b135be3bf67b9386dc929109c3db82c730.tar.gz
frameworks_base-01cdf8b135be3bf67b9386dc929109c3db82c730.tar.bz2
Revert "Added function to render a drawable in all available states"
This reverts commit 63483e17de4d2441acaabcee4185b0bb25e1d94c. Change-Id: I07fced229759e63d4fa4f94b7dac48b3e9342b18
Diffstat (limited to 'tools')
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java2
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/SessionParamsFlags.java (renamed from tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java)18
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java62
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java6
4 files changed, 20 insertions, 68 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index c6d60f8..4d2c2fc 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -181,7 +181,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
*/
private static LayoutLog sCurrentLog = sDefaultLog;
- private static final int LAST_SUPPORTED_FEATURE = Features.RENDER_ALL_DRAWABLE_STATES;
+ private static final int LAST_SUPPORTED_FEATURE = Features.PREFERENCES_RENDERING;
@Override
public int getApiLevel() {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/SessionParamsFlags.java
index cfc8f40..51a0104 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/SessionParamsFlags.java
@@ -16,24 +16,22 @@
package com.android.layoutlib.bridge.android;
-import com.android.ide.common.rendering.api.SessionParams.Key;
+import com.android.ide.common.rendering.api.SessionParams;
/**
- * This contains all known keys for the {@link RenderParams#getFlag(Key)}.
+ * This contains all known keys for the {@link SessionParams#getFlag(SessionParams.Key)}.
* <p/>
* The IDE has its own copy of this class which may be newer or older than this one.
* <p/>
* Constants should never be modified or removed from this class.
*/
-public final class RenderParamsFlags {
+public final class SessionParamsFlags {
- public static final Key<String> FLAG_KEY_ROOT_TAG =
- new Key<String>("rootTag", String.class);
- public static final Key<Boolean> FLAG_KEY_DISABLE_BITMAP_CACHING =
- new Key<Boolean>("disableBitmapCaching", Boolean.class);
- public static final Key<Boolean> FLAG_KEY_RENDER_ALL_DRAWABLE_STATES =
- new Key<Boolean>("renderAllDrawableStates", Boolean.class);
+ public static final SessionParams.Key<String> FLAG_KEY_ROOT_TAG =
+ new SessionParams.Key<String>("rootTag", String.class);
+ public static final SessionParams.Key<Boolean> FLAG_KEY_DISABLE_BITMAP_CACHING =
+ new SessionParams.Key<Boolean>("disableBitmapCaching", Boolean.class);
// Disallow instances.
- private RenderParamsFlags() {}
+ private SessionParamsFlags() {}
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java
index 3dee1e2..669e6b5 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderDrawable.java
@@ -16,20 +16,20 @@
package com.android.layoutlib.bridge.impl;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN;
+
import com.android.ide.common.rendering.api.DrawableParams;
import com.android.ide.common.rendering.api.HardwareConfig;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.rendering.api.Result;
import com.android.ide.common.rendering.api.Result.Status;
import com.android.layoutlib.bridge.android.BridgeContext;
-import com.android.layoutlib.bridge.android.RenderParamsFlags;
import com.android.resources.ResourceType;
import android.graphics.Bitmap;
import android.graphics.Bitmap_Delegate;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
-import android.graphics.drawable.StateListDrawable;
import android.view.AttachInfo_Accessor;
import android.view.View.MeasureSpec;
import android.widget.FrameLayout;
@@ -38,9 +38,7 @@ import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.io.IOException;
/**
* Action to render a given Drawable provided through {@link DrawableParams#getDrawable()}.
@@ -73,37 +71,11 @@ public class RenderDrawable extends RenderAction<DrawableParams> {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
- Drawable d = ResourceHelper.getDrawable(drawableResource, context);
-
- final Boolean allStates =
- params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
- if (allStates == Boolean.TRUE) {
- final List<BufferedImage> result;
-
- if (d instanceof StateListDrawable) {
- result = new ArrayList<BufferedImage>();
- final StateListDrawable stateList = (StateListDrawable) d;
- for (int i = 0; i < stateList.getStateCount(); i++) {
- final Drawable stateDrawable = stateList.getStateDrawable(i);
- result.add(renderImage(hardwareConfig, stateDrawable, context));
- }
- } else {
- result = Collections.singletonList(renderImage(hardwareConfig, d, context));
- }
-
- return Status.SUCCESS.createResult(result);
- } else {
- BufferedImage image = renderImage(hardwareConfig, d, context);
- return Status.SUCCESS.createResult(image);
- }
- }
-
- private BufferedImage renderImage(HardwareConfig hardwareConfig, Drawable d,
- BridgeContext context) {
// create a simple FrameLayout
FrameLayout content = new FrameLayout(context);
// get the actual Drawable object to draw
+ Drawable d = ResourceHelper.getDrawable(drawableResource, context);
content.setBackground(d);
// set the AttachInfo on the root view.
@@ -111,27 +83,8 @@ public class RenderDrawable extends RenderAction<DrawableParams> {
// measure
- int w = d.getIntrinsicWidth();
- int h = d.getIntrinsicHeight();
-
- final int screenWidth = hardwareConfig.getScreenWidth();
- final int screenHeight = hardwareConfig.getScreenHeight();
-
- if (w == -1 || h == -1) {
- // Use screen size when either intrinsic width or height isn't available
- w = screenWidth;
- h = screenHeight;
- } else if (w > screenWidth || h > screenHeight) {
- // If image wouldn't fit to the screen, resize it to avoid cropping.
-
- // We need to find scale such that scale * w <= screenWidth, scale * h <= screenHeight
- double scale = Math.min((double) screenWidth / w, (double) screenHeight / h);
-
- // scale * w / scale * h = w / h, so, proportions are preserved.
- w = (int) Math.floor(scale * w);
- h = (int) Math.floor(scale * h);
- }
-
+ int w = hardwareConfig.getScreenWidth();
+ int h = hardwareConfig.getScreenHeight();
int w_spec = MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY);
int h_spec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY);
content.measure(w_spec, h_spec);
@@ -155,7 +108,8 @@ public class RenderDrawable extends RenderAction<DrawableParams> {
// and draw
content.draw(canvas);
- return image;
+
+ return Status.SUCCESS.createResult(image);
}
protected BufferedImage getImage(int w, int h) {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 607563a..875cc87 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -50,7 +50,7 @@ import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.layoutlib.bridge.android.BridgeLayoutParamsMapAttributes;
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
-import com.android.layoutlib.bridge.android.RenderParamsFlags;
+import com.android.layoutlib.bridge.android.SessionParamsFlags;
import com.android.layoutlib.bridge.bars.BridgeActionBar;
import com.android.layoutlib.bridge.bars.AppCompatActionBar;
import com.android.layoutlib.bridge.bars.Config;
@@ -400,7 +400,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
// it can instantiate the custom Fragment.
Fragment_Delegate.setProjectCallback(params.getProjectCallback());
- String rootTag = params.getFlag(RenderParamsFlags.FLAG_KEY_ROOT_TAG);
+ String rootTag = params.getFlag(SessionParamsFlags.FLAG_KEY_ROOT_TAG);
boolean isPreference = "PreferenceScreen".equals(rootTag);
View view;
if (isPreference) {
@@ -557,7 +557,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
// This is useful when mImage is just a wrapper of Graphics2D so
// it doesn't get cached.
boolean disableBitmapCaching = Boolean.TRUE.equals(params.getFlag(
- RenderParamsFlags.FLAG_KEY_DISABLE_BITMAP_CACHING));
+ SessionParamsFlags.FLAG_KEY_DISABLE_BITMAP_CACHING));
if (newRenderSize || mCanvas == null || disableBitmapCaching) {
if (params.getImageFactory() != null) {
mImage = params.getImageFactory().getImage(