diff options
author | Tor Norbye <tnorbye@google.com> | 2012-10-16 17:47:00 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-10-16 18:47:25 -0700 |
commit | 30ac384722bab00f29ca04dc09f15c18faa8c3f2 (patch) | |
tree | 309892b3e3f169da0a7f04c9696888785c22b541 /eclipse/plugins | |
parent | f47ac10fa49e107aee074d42b3b29181dd5f00d8 (diff) | |
download | sdk-30ac384722bab00f29ca04dc09f15c18faa8c3f2.zip sdk-30ac384722bab00f29ca04dc09f15c18faa8c3f2.tar.gz sdk-30ac384722bab00f29ca04dc09f15c18faa8c3f2.tar.bz2 |
Use nine patch capability to drive tvdpi masking
Change-Id: Ibe9ca90540113157d4fdb5554965d626c22581d8
Diffstat (limited to 'eclipse/plugins')
4 files changed, 75 insertions, 13 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ComplementingConfiguration.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ComplementingConfiguration.java index 151301a..7ff0354 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ComplementingConfiguration.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ComplementingConfiguration.java @@ -17,7 +17,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.configuration; import com.android.annotations.NonNull; import com.android.annotations.Nullable; -import com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderPreviewManager; +import com.android.ide.common.rendering.api.Capability; import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; import com.android.resources.Density; import com.android.resources.NightMode; @@ -284,12 +284,15 @@ public class ComplementingConfiguration extends NestedConfiguration { to = biggest + 0.1; } + boolean canScaleNinePatch = supports(Capability.FIXED_SCALABLE_NINE_PATCH); for (Device d : devices) { double size = getScreenSize(d); if (size >= from && size < to) { - if (RenderPreviewManager.HIDE_TVDPI && - getDensity(d) == Density.TV) { - continue; + if (!canScaleNinePatch) { + Density density = getDensity(d); + if (density == Density.TV || density == Density.LOW) { + continue; + } } device = d; 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 3476964..c0b57ac 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 @@ -23,6 +23,7 @@ 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; import com.android.ide.common.resources.configuration.DeviceConfigHelper; @@ -36,6 +37,7 @@ import com.android.ide.common.resources.configuration.ScreenSizeQualifier; import com.android.ide.common.resources.configuration.UiModeQualifier; import com.android.ide.common.resources.configuration.VersionQualifier; import com.android.ide.eclipse.adt.AdtPlugin; +import com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService; import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; import com.android.ide.eclipse.adt.internal.resources.ResourceHelper; import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources; @@ -1063,6 +1065,22 @@ public class Configuration { return null; } + /** + * Returns true if this configuration supports the given rendering + * capability + * + * @param capability the capability to check + * @return true if the capability is supported + */ + public boolean supports(Capability capability) { + IAndroidTarget target = getTarget(); + if (target != null) { + return RenderService.supports(target, capability); + } + + return false; + } + @Override public String toString() { return Objects.toStringHelper(this.getClass()) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java index a7c3e88..f90e9ac 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderPreviewManager.java @@ -74,9 +74,6 @@ import java.util.Set; * managing the image buffer cache, etc */ public class RenderPreviewManager { - /** TODO: Tie this to a {@link Capability} instead */ - public static boolean HIDE_TVDPI = true; - private static double sScale = 1.0; private static final int RENDER_DELAY = 150; private static final int PREVIEW_VGAP = 18; @@ -898,6 +895,7 @@ public class RenderPreviewManager { ConfigurationChooser chooser = getChooser(); List<Device> devices = chooser.getDeviceList(); Configuration configuration = chooser.getConfiguration(); + boolean canScaleNinePatch = configuration.supports(Capability.FIXED_SCALABLE_NINE_PATCH); // Rearrange the devices a bit such that the most interesting devices bubble // to the front @@ -939,11 +937,11 @@ public class RenderPreviewManager { DensityQualifier density = c.getDensityQualifier(); if (density != null) { Density d = density.getValue(); - if (Density.LOW.equals(d)) { + if (d == Density.LOW) { interesting = false; } - if (HIDE_TVDPI && d == Density.TV) { + if (!canScaleNinePatch && d == Density.TV) { interesting = false; } } 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 622a4d4..2a1f3b7 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 @@ -17,10 +17,12 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; import static com.android.SdkConstants.LAYOUT_RESOURCE_PREFIX; +import com.android.annotations.NonNull; import com.android.ide.common.api.IClientRulesEngine; import com.android.ide.common.api.INode; 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.IImageFactory; import com.android.ide.common.rendering.api.ILayoutPullParser; @@ -49,8 +51,13 @@ import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElement import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; 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; @@ -122,8 +129,7 @@ public class RenderService { mProjectCallback = editor.getProjectCallback(true /*reset*/, mLayoutLib); mMinSdkVersion = editor.getMinSdkVersion(); mTargetSdkVersion = editor.getTargetSdkVersion(); - mSoftwareButtons = - config.getDevice().getDefaultHardware().getButtonType() == ButtonType.SOFT; + mSoftwareButtons = getButtonType(config) == ButtonType.SOFT; } private RenderService(GraphicalEditorPart editor, FolderConfiguration configuration, @@ -141,8 +147,7 @@ public class RenderService { mProjectCallback = editor.getProjectCallback(true /*reset*/, mLayoutLib); mMinSdkVersion = editor.getMinSdkVersion(); mTargetSdkVersion = editor.getTargetSdkVersion(); - mSoftwareButtons = - config.getDevice().getDefaultHardware().getButtonType() == ButtonType.SOFT; + mSoftwareButtons = getButtonType(config) == ButtonType.SOFT; // TODO: Look up device etc and offer additional configuration options here? Density density = Density.MEDIUM; @@ -158,6 +163,44 @@ public class RenderService { 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; + } + + /** + * Returns true if this configuration supports the given rendering + * capability + * + * @param target the target to look up the layout library for + * @param capability the capability to check + * @return true if the capability is supported + */ + public static boolean supports( + @NonNull IAndroidTarget target, + @NonNull Capability capability) { + Sdk sdk = Sdk.getCurrent(); + if (sdk != null) { + AndroidTargetData targetData = sdk.getTargetData(target); + if (targetData != null) { + LayoutLibrary layoutLib = targetData.getLayoutLibrary(); + if (layoutLib != null) { + return layoutLib.supports(capability); + } + } + } + + return false; + } + /** * Sets the screen size and density to use for rendering * |