aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2011-07-27 16:48:46 -0700
committerAndroid Code Review <code-review@android.com>2011-07-27 16:48:46 -0700
commit587f53c9ecf26b2ca57eaae9c88edf625a2bdf13 (patch)
tree9248de133d7a743ef37c5e0846d2a3f3b999d68f
parent0fda5ec3999f96ad5a5d7622d6b3f08b1b09019d (diff)
parent0881c2eeba39f8aad28310e304338581baeb7250 (diff)
downloadsdk-587f53c9ecf26b2ca57eaae9c88edf625a2bdf13.zip
sdk-587f53c9ecf26b2ca57eaae9c88edf625a2bdf13.tar.gz
sdk-587f53c9ecf26b2ca57eaae9c88edf625a2bdf13.tar.bz2
Merge "18623: Adding ImageView in xml file causes crash of Eclipse"
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/ui/ResourcePreviewHelper.java89
1 files changed, 50 insertions, 39 deletions
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 d26cbae..94bafb5 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
@@ -29,6 +29,7 @@ import com.android.ide.eclipse.adt.internal.editors.layout.gle2.SwtUtils;
import com.android.ide.eclipse.adt.internal.resources.ResourceHelper;
import com.android.resources.ResourceType;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.DialogTray;
import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.swt.SWT;
@@ -122,53 +123,63 @@ public class ResourcePreviewHelper {
}
BufferedImage image = null;
- if (type == ResourceType.COLOR) {
- ResourceResolver resources = mEditor.getResourceResolver();
- ResourceValue value = resources.findResValue(resource, false);
- if (value != null) {
- RGB color = ResourceHelper.resolveColor(resources, value);
- if (color != null) {
- image = ImageUtils.createColoredImage(WIDTH, HEIGHT, color);
+ try {
+ if (type == ResourceType.COLOR) {
+ ResourceResolver resources = mEditor.getResourceResolver();
+ ResourceValue value = resources.findResValue(resource, false);
+ if (value != null) {
+ RGB color = ResourceHelper.resolveColor(resources, value);
+ if (color != null) {
+ image = ImageUtils.createColoredImage(WIDTH, HEIGHT, color);
+ }
}
- }
- } else {
- assert type == ResourceType.DRAWABLE;
-
- ResourceResolver resources = mEditor.getResourceResolver();
- ResourceValue drawable = resources.findResValue(resource, false);
- if (drawable != null) {
- String path = drawable.getValue();
-
- // Special-case image files (other than 9-patch files) and render these
- // directly, in order to provide proper aspect ratio handling and
- // to handle scaling to show the full contents:
- if (ImageUtils.hasImageExtension(path)
- && !endsWithIgnoreCase(path, DOT_9PNG)) {
- File file = new File(path);
- if (file.exists()) {
- try {
- image = ImageIO.read(file);
- int width = image.getWidth();
- int height = image.getHeight();
- if (width > WIDTH || height > HEIGHT) {
- double xScale = WIDTH / (double) width;
- double yScale = HEIGHT / (double) height;
- double scale = Math.min(xScale, yScale);
- image = ImageUtils.scale(image, scale, scale);
+ } else {
+ assert type == ResourceType.DRAWABLE;
+
+ ResourceResolver resources = mEditor.getResourceResolver();
+ ResourceValue drawable = resources.findResValue(resource, false);
+ if (drawable != null) {
+ String path = drawable.getValue();
+
+ // Special-case image files (other than 9-patch files) and render these
+ // directly, in order to provide proper aspect ratio handling and
+ // to handle scaling to show the full contents:
+ if (ImageUtils.hasImageExtension(path)
+ && !endsWithIgnoreCase(path, DOT_9PNG)) {
+ File file = new File(path);
+ if (file.exists()) {
+ try {
+ image = ImageIO.read(file);
+ int width = image.getWidth();
+ int height = image.getHeight();
+ if (width > WIDTH || height > HEIGHT) {
+ double xScale = WIDTH / (double) width;
+ double yScale = HEIGHT / (double) height;
+ double scale = Math.min(xScale, yScale);
+ image = ImageUtils.scale(image, scale, scale);
+ }
+ } catch (IOException e) {
+ AdtPlugin.log(e, "Can't read preview image %1$s", path);
}
- } catch (IOException e) {
- AdtPlugin.log(e, "Can't read preview image %1$s", path);
}
}
- }
- if (image == null) {
- RenderService renderService = RenderService.create(mEditor);
- renderService.setSize(WIDTH, HEIGHT);
- image = renderService.renderDrawable(drawable);
+ if (image == null) {
+ RenderService renderService = RenderService.create(mEditor);
+ renderService.setSize(WIDTH, HEIGHT);
+ image = renderService.renderDrawable(drawable);
+ }
}
}
+ } catch (Throwable t) {
+ // Some kind of rendering error occurred. However, we don't want to use
+ // AdtPlugin.log(t, "Can't generate preview for %1$s", resource);
+ // because if it's a severe type of error (such as an InternalError shown
+ // in issue #18623) then a dialog will pop up and interfere with the
+ // preview, so just log a warning (unfortunately without the trace) instead.
+ AdtPlugin.log(IStatus.WARNING, "Can't generate preview for %1$s", resource);
}
+
Display display = mEditor.getSite().getShell().getDisplay();
if (image != null) {
mPreviewImageControl.setImage(SwtUtils.convertToSwt(display, image, true, -1));