diff options
Diffstat (limited to 'tools/layoutlib/bridge/src')
5 files changed, 88 insertions, 14 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java index 9b6fb82..d2b6b27 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java @@ -446,6 +446,15 @@ public class Region_Delegate { return region1.mArea.equals(region2.mArea); } + /*package*/ static String nativeToString(int native_region) { + Region_Delegate region = sManager.getDelegate(native_region); + if (region == null) { + return "not found"; + } + + return region.mArea.toString(); + } + // ---- Private delegate/helper methods ---- } diff --git a/tools/layoutlib/bridge/src/android/os/Build_Delegate.java b/tools/layoutlib/bridge/src/android/os/Build_Delegate.java new file mode 100644 index 0000000..f71860f --- /dev/null +++ b/tools/layoutlib/bridge/src/android/os/Build_Delegate.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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 android.os; + +import com.android.layoutlib.bridge.Bridge; +import com.android.layoutlib.bridge.impl.DelegateManager; + +import java.util.Map; + +/** + * Delegate implementing the native methods of android.os.Build + * + * Through the layoutlib_create tool, the original native methods of Build have been replaced + * by calls to methods of the same name in this delegate class. + * + * Because it's a stateless class to start with, there's no need to keep a {@link DelegateManager} + * around to map int to instance of the delegate. + * + */ +public class Build_Delegate { + + /*package*/ static String getString(String property) { + Map<String, String> properties = Bridge.getPlatformProperties(); + String value = properties.get(property); + if (value != null) { + return value; + } + + return Build.UNKNOWN; + } + +} 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 37576b4..0c3aef4 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -93,6 +93,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { new HashMap<String, SoftReference<NinePatchChunk>>(); private static Map<String, Map<String, Integer>> sEnumValueMap; + private static Map<String, String> sPlatformProperties; /** * int[] wrapper to use as keys in maps. @@ -157,10 +158,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { */ private static LayoutLog sCurrentLog = sDefaultLog; - private EnumSet<Capability> mCapabilities; - @Override public int getApiLevel() { return com.android.ide.common.rendering.api.Bridge.API_CURRENT; @@ -172,8 +171,11 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { } @Override - public boolean init(File fontLocation, Map<String, Map<String, Integer>> enumValueMap, + public boolean init(Map<String,String> platformProperties, + File fontLocation, + Map<String, Map<String, Integer>> enumValueMap, LayoutLog log) { + sPlatformProperties = platformProperties; sEnumValueMap = enumValueMap; // don't use EnumSet.allOf(), because the bridge doesn't come with its specific version @@ -429,6 +431,13 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { } /** + * Returns the platform build properties. + */ + public static Map<String, String> getPlatformProperties() { + return sPlatformProperties; + } + + /** * Returns the bitmap for a specific path, from a specific project cache, or from the * framework cache. * @param value the path of the bitmap diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java index bc2301d..3bc0202 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java @@ -30,6 +30,7 @@ import android.view.ViewGroup; import android.view.ViewParent; import java.awt.image.BufferedImage; +import java.util.List; import java.util.Map; /** @@ -55,8 +56,8 @@ public class BridgeRenderSession extends RenderSession { } @Override - public ViewInfo getRootView() { - return mSession.getViewInfo(); + public List<ViewInfo> getRootViews() { + return mSession.getViewInfos(); } @Override 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 63d52e9..d7b7009 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 @@ -116,7 +116,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider { // information being returned through the API private BufferedImage mImage; - private ViewInfo mViewInfo; + private List<ViewInfo> mViewInfoList; private static final class PostInflateException extends Exception { private static final long serialVersionUID = 1L; @@ -478,7 +478,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider { mViewRoot.draw(mCanvas); - mViewInfo = visit(((ViewGroup)mViewRoot).getChildAt(0), mContext); + mViewInfoList = visitAllChildren((ViewGroup)mViewRoot, mContext); // success! return SUCCESS.createResult(); @@ -1101,16 +1101,25 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider { if (view instanceof ViewGroup) { ViewGroup group = ((ViewGroup) view); - List<ViewInfo> children = new ArrayList<ViewInfo>(); - for (int i = 0; i < group.getChildCount(); i++) { - children.add(visit(group.getChildAt(i), context)); - } - result.setChildren(children); + result.setChildren(visitAllChildren(group, context)); } return result; } + private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, BridgeContext context) { + if (viewGroup == null) { + return null; + } + + List<ViewInfo> children = new ArrayList<ViewInfo>(); + for (int i = 0; i < viewGroup.getChildCount(); i++) { + children.add(visit(viewGroup.getChildAt(i), context)); + } + return children; + } + + private void invalidateRenderingSize() { mMeasuredScreenWidth = mMeasuredScreenHeight = -1; } @@ -1119,8 +1128,8 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider { return mImage; } - public ViewInfo getViewInfo() { - return mViewInfo; + public List<ViewInfo> getViewInfos() { + return mViewInfoList; } public Map<String, String> getDefaultProperties(Object viewObject) { |